Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added player based Pickup event controlling #319

Merged
merged 3 commits into from
Jun 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/SampSharp.GameMode/BaseMode.callbacks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,9 @@ internal bool OnPlayerPickUpPickup(int playerid, int pickupid)
if (pickup == null)
return true;

OnPlayerPickUpPickup(pickup, new PlayerEventArgs(BasePlayer.FindOrCreate(playerid)));
var player = BasePlayer.FindOrCreate(playerid);

OnPlayerPickUpPickup(player, new PickUpPickupEventArgs(player, pickup));

return true;
}
Expand Down
12 changes: 6 additions & 6 deletions src/SampSharp.GameMode/BaseMode.events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,10 @@ public abstract partial class BaseMode
public event EventHandler<EventArgs> PlayerObjectMoved;

/// <summary>
/// Occurs when the <see cref="OnPlayerPickUpPickup(Pickup,PlayerEventArgs)" /> callback is being called.
/// Occurs when the <see cref="OnPlayerPickUpPickup(BasePlayer,PickUpPickupEventArgs)" /> callback is being called.
/// Called when a player picks up a pickup created with <see cref="Pickup" />.
/// </summary>
public event EventHandler<PlayerEventArgs> PlayerPickUpPickup;
public event EventHandler<PickUpPickupEventArgs> PlayerPickUpPickup;

/// <summary>
/// Occurs when the <see cref="OnVehicleMod(BaseVehicle,VehicleModEventArgs)" /> callback is being called.
Expand Down Expand Up @@ -692,11 +692,11 @@ protected virtual void OnPlayerObjectMoved(PlayerObject playerObject, EventArgs
/// <summary>
/// Raises the <see cref="PlayerPickUpPickup" /> event.
/// </summary>
/// <param name="pickup">The pickup triggering the event.</param>
/// <param name="e">An <see cref="PlayerEventArgs" /> that contains the event data. </param>
protected virtual void OnPlayerPickUpPickup(Pickup pickup, PlayerEventArgs e)
/// <param name="player">The player triggering the event.</param>
/// <param name="e">An <see cref="PickUpPickupEventArgs" /> that contains the event data. </param>
protected virtual void OnPlayerPickUpPickup(BasePlayer player, PickUpPickupEventArgs e)
{
PlayerPickUpPickup?.Invoke(pickup, e);
PlayerPickUpPickup?.Invoke(player, e);
}

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions src/SampSharp.GameMode/Controllers/BasePlayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public virtual void RegisterEvents(BaseMode gameMode)
gameMode.PlayerSelectPlayerObject +=
(sender, args) => (sender as BasePlayer)?.OnSelectPlayerObject(args);
gameMode.PlayerWeaponShot += (sender, args) => (sender as BasePlayer)?.OnWeaponShot(args);
gameMode.PlayerPickUpPickup += (sender, args) => (sender as BasePlayer)?.OnPickUpPickup(args);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/SampSharp.GameMode/Controllers/PickupController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class PickupController : Disposable, IEventListener, ITypeProvider
/// <param name="gameMode">The running GameMode.</param>
public virtual void RegisterEvents(BaseMode gameMode)
{
gameMode.PlayerPickUpPickup += (sender, args) => (sender as Pickup)?.OnPickUp(args);
gameMode.PlayerPickUpPickup += (sender, args) => args.Pickup?.OnPickUp(args);
}

/// <summary>
Expand Down
46 changes: 46 additions & 0 deletions src/SampSharp.GameMode/Events/PickUpPickupEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// SampSharp
// Copyright 2017 Tim Potze
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using SampSharp.GameMode.World;

namespace SampSharp.GameMode.Events
{
/// <summary>
/// Provides data for the <see cref="Pickup.PickUp" /> event.
/// </summary>
public class PickUpPickupEventArgs : EventArgs
{
/// <summary>
/// Initializes a new instance of the <see cref="PickUpPickupEventArgs" /> class.
/// </summary>
/// <param name="player">The player.</param>
/// <param name="pickup">The pickup.</param>
public PickUpPickupEventArgs(BasePlayer player, Pickup pickup)
{
Player = player;
Pickup = pickup;
}

/// <summary>
/// Gets the player.
/// </summary>
public BasePlayer Player { get; private set; }

/// <summary>
/// Gets the pickup.
/// </summary>
public Pickup Pickup { get; private set; }
}
}
2 changes: 1 addition & 1 deletion src/SampSharp.GameMode/Events/PlayerEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace SampSharp.GameMode.Events
/// <see cref="BaseMode.VehicleDamageStatusUpdated" />, <see cref="BaseMode.PlayerStreamIn" />,
/// <see cref="BaseMode.PlayerStreamOut" />, <see cref="BaseMode.VehicleStreamIn" />,
/// <see cref="BaseMode.VehicleStreamOut" />, <see cref="BasePlayer.StreamIn" />, <see cref="BasePlayer.StreamOut" />,
/// <see cref="BaseVehicle.StreamIn" />, <see cref="BaseVehicle.StreamOut" /> or <see cref="Pickup.PickUp" /> event.
/// <see cref="BaseVehicle.StreamIn" /> or <see cref="BaseVehicle.StreamOut" /> event.
/// </summary>
public class PlayerEventArgs : EventArgs
{
Expand Down
15 changes: 15 additions & 0 deletions src/SampSharp.GameMode/World/BasePlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,12 @@ public virtual string GPCI
/// </remarks>
public event EventHandler<WeaponShotEventArgs> WeaponShot;

/// <summary>
/// Occurs when the <see cref="OnPickUpPickup" /> is being called.
/// This callback is called when a player picks up a pickup.
/// </summary>
public event EventHandler<PickUpPickupEventArgs> PickUpPickup;

#endregion

#region Players natives
Expand Down Expand Up @@ -2542,6 +2548,15 @@ public virtual void OnWeaponShot(WeaponShotEventArgs e)
WeaponShot?.Invoke(this, e);
}

/// <summary>
/// Raises the <see cref="PickUpPickup" /> event.
/// </summary>
/// <param name="e">An <see cref="PickUpPickupEventArgs" /> that contains the event data. </param>
public virtual void OnPickUpPickup(PickUpPickupEventArgs e)
{
PickUpPickup?.Invoke(this, e);
}

#endregion
}
}
6 changes: 3 additions & 3 deletions src/SampSharp.GameMode/World/Pickup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public partial class Pickup : IdentifiedPool<Pickup>, IWorldObject
/// Occurs when the <see cref="OnPickUp" /> is being called.
/// Called when a player picks up a pickup created with <see cref="Create" />
/// </summary>
public event EventHandler<PlayerEventArgs> PickUp;
public event EventHandler<PickUpPickupEventArgs> PickUp;

/// <summary>
/// Creates a <see cref="Pickup" />.
Expand Down Expand Up @@ -118,8 +118,8 @@ protected override void Dispose(bool disposing)
/// <summary>
/// Raises the <see cref="PickUp" /> event.
/// </summary>
/// <param name="e">An <see cref="PlayerEventArgs" /> that contains the event data. </param>
public virtual void OnPickUp(PlayerEventArgs e)
/// <param name="e">An <see cref="PickUpPickupEventArgs" /> that contains the event data. </param>
public virtual void OnPickUp(PickUpPickupEventArgs e)
{
PickUp?.Invoke(this, e);
}
Expand Down