mirror of
https://github.com/MrOkiDoki/BattleBit-Community-Server-API.git
synced 2025-01-09 19:27:31 -03:00
OnPlayer killed arguments passed to a struct
This commit is contained in:
parent
39b7322a44
commit
caf7ff6ea8
18 changed files with 88 additions and 25 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
17
BattleBitAPI/Common/Arguments/OnPlayerKillArguments.cs
Normal file
17
BattleBitAPI/Common/Arguments/OnPlayerKillArguments.cs
Normal file
|
@ -0,0 +1,17 @@
|
|||
using System.Numerics;
|
||||
|
||||
namespace BattleBitAPI.Common
|
||||
{
|
||||
public struct OnPlayerKillArguments<TPlayer> where TPlayer : Player
|
||||
{
|
||||
public TPlayer Killer;
|
||||
public Vector3 KillerPosition;
|
||||
|
||||
public TPlayer Victim;
|
||||
public Vector3 VictimPosition;
|
||||
|
||||
public string KillerTool;
|
||||
public PlayerBody BodyPart;
|
||||
public ReasonOfDamage SourceOfDamage;
|
||||
}
|
||||
}
|
27
BattleBitAPI/Common/Enums/DamageReason.cs
Normal file
27
BattleBitAPI/Common/Enums/DamageReason.cs
Normal file
|
@ -0,0 +1,27 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BattleBitAPI.Common
|
||||
{
|
||||
public enum ReasonOfDamage : byte
|
||||
{
|
||||
Server = 0,
|
||||
Weapon = 1,
|
||||
Bleeding = 2,
|
||||
Fall = 3,
|
||||
HelicopterBlade = 4,
|
||||
VehicleExplosion = 5,
|
||||
Explosion = 6,
|
||||
vehicleRunOver = 7,
|
||||
BuildingCollapsing = 8,
|
||||
SledgeHammer = 9,
|
||||
TreeFall = 10,
|
||||
CountAsKill = 11,
|
||||
Suicide = 12,
|
||||
HelicopterCrash = 13,
|
||||
BarbedWire = 14,
|
||||
}
|
||||
}
|
15
BattleBitAPI/Common/Enums/PlayerBody.cs
Normal file
15
BattleBitAPI/Common/Enums/PlayerBody.cs
Normal file
|
@ -0,0 +1,15 @@
|
|||
namespace BattleBitAPI.Common
|
||||
{
|
||||
public enum PlayerBody : byte
|
||||
{
|
||||
None = 0,
|
||||
Head = 2,
|
||||
Neck = 3,
|
||||
Shoulder = 4,
|
||||
Arm = 5,
|
||||
Leg = 6,
|
||||
Foot = 7,
|
||||
Chest = 10,
|
||||
}
|
||||
|
||||
}
|
|
@ -102,13 +102,9 @@ namespace BattleBitAPI.Server
|
|||
/// </summary>
|
||||
///
|
||||
/// <remarks>
|
||||
/// Player: The killer player<br/>
|
||||
/// Vector3: The position of killer<br/>
|
||||
/// Player: The target player that got killed<br/>
|
||||
/// Vector3: The target player's position<br/>
|
||||
/// string - Tool: The tool user to kill the player<br/>
|
||||
/// OnPlayerKillArguments: Details about the kill<br/>
|
||||
/// </remarks>
|
||||
public Func<TPlayer, Vector3, TPlayer, Vector3, string, Task> OnAPlayerKilledAnotherPlayer { get; set; }
|
||||
public Func<OnPlayerKillArguments<TPlayer>, Task> OnAPlayerKilledAnotherPlayer { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Fired when game server requests the stats of a player, this function should return in 3000ms or player will not able to join to server.
|
||||
|
@ -826,7 +822,7 @@ namespace BattleBitAPI.Server
|
|||
}
|
||||
case NetworkCommuncation.OnPlayerKilledAnotherPlayer:
|
||||
{
|
||||
if (stream.CanRead(8 + 12 + 8 + 12 + 2))
|
||||
if (stream.CanRead(8 + 12 + 8 + 12 + 2 + 1 + 1))
|
||||
{
|
||||
ulong killer = stream.ReadUInt64();
|
||||
Vector3 killerPos = new Vector3(stream.ReadFloat(), stream.ReadFloat(), stream.ReadFloat());
|
||||
|
@ -836,10 +832,31 @@ namespace BattleBitAPI.Server
|
|||
|
||||
if (stream.TryReadString(out var tool))
|
||||
{
|
||||
PlayerBody body = (PlayerBody)stream.ReadInt8();
|
||||
ReasonOfDamage source = (ReasonOfDamage)stream.ReadInt8();
|
||||
|
||||
if (resources.TryGetPlayer(killer, out var killerClient))
|
||||
{
|
||||
if (resources.TryGetPlayer(victim, out var victimClient))
|
||||
{
|
||||
if (OnAPlayerKilledAnotherPlayer != null)
|
||||
await OnAPlayerKilledAnotherPlayer.Invoke((TPlayer)killerClient, killerPos, (TPlayer)victimClient, victimPos, tool);
|
||||
{
|
||||
var args = new OnPlayerKillArguments<TPlayer>()
|
||||
{
|
||||
Killer = (TPlayer)killerClient,
|
||||
KillerPosition = killerPos,
|
||||
Victim = (TPlayer)victimClient,
|
||||
VictimPosition = victimPos,
|
||||
BodyPart = body,
|
||||
SourceOfDamage = source,
|
||||
KillerTool = tool,
|
||||
};
|
||||
|
||||
await OnAPlayerKilledAnotherPlayer.Invoke(args);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
19
Program.cs
19
Program.cs
|
@ -13,27 +13,14 @@ class Program
|
|||
var listener = new ServerListener<MyPlayer>();
|
||||
listener.Start(29294);
|
||||
|
||||
listener.OnPlayerTypedMessage += OnPlayerTypedMessage;
|
||||
listener.OnAPlayerKilledAnotherPlayer += OnAPlayerKilledAnotherPlayer;
|
||||
|
||||
Thread.Sleep(-1);
|
||||
}
|
||||
|
||||
private static async Task<bool> OnPlayerTypedMessage(MyPlayer player, ChatChannel ch, string msg)
|
||||
private static async Task OnAPlayerKilledAnotherPlayer(OnPlayerKillArguments<MyPlayer> arg)
|
||||
{
|
||||
if (msg == "nword")
|
||||
{
|
||||
player.NumberOfNWord++;
|
||||
if (player.NumberOfNWord > 4)
|
||||
{
|
||||
player.Kick("N word is not accepted!");
|
||||
}
|
||||
else
|
||||
{
|
||||
player.Message("Do not type nword, this is your " + player.NumberOfNWord + "th warning");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
await Console.Out.WriteLineAsync(arg.Killer + " killed " + arg.Victim + " with " + arg.KillerTool + " (" + arg.BodyPart + ")");
|
||||
}
|
||||
}
|
||||
class MyPlayer : Player
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -1 +1 @@
|
|||
d1f232126136336fb7f4efeeb67c0c5982544fe4
|
||||
8f0a13b55a78de27b4bd6f14afc4adfc26b55b80
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in a new issue