mirror of
https://github.com/MrOkiDoki/BattleBit-Community-Server-API.git
synced 2025-01-25 02:33:08 -03:00
Ability to change weapons - gadgets runtime.
This commit is contained in:
parent
120b94c5f9
commit
aa32ced799
8 changed files with 546 additions and 272 deletions
|
@ -126,224 +126,223 @@
|
||||||
this.HeavyGadgetExtra = ser.ReadInt8();
|
this.HeavyGadgetExtra = ser.ReadInt8();
|
||||||
this.ThrowableExtra = ser.ReadInt8();
|
this.ThrowableExtra = ser.ReadInt8();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
public struct WeaponItem
|
||||||
|
{
|
||||||
|
public string ToolName;
|
||||||
|
public string MainSightName;
|
||||||
|
public string TopSightName;
|
||||||
|
public string CantedSightName;
|
||||||
|
public string BarrelName;
|
||||||
|
public string SideRailName;
|
||||||
|
public string UnderRailName;
|
||||||
|
public string BoltActionName;
|
||||||
|
public byte SkinIndex;
|
||||||
|
public byte MagazineIndex;
|
||||||
|
|
||||||
public struct WeaponItem
|
public Weapon Tool
|
||||||
{
|
{
|
||||||
public string ToolName;
|
get
|
||||||
public string MainSightName;
|
{
|
||||||
public string TopSightName;
|
if (Weapons.TryFind(ToolName, out var weapon))
|
||||||
public string CantedSightName;
|
return weapon;
|
||||||
public string BarrelName;
|
return null;
|
||||||
public string SideRailName;
|
}
|
||||||
public string UnderRailName;
|
set
|
||||||
public string BoltActionName;
|
{
|
||||||
public byte SkinIndex;
|
if (value == null)
|
||||||
public byte MagazineIndex;
|
this.ToolName = "none";
|
||||||
|
else
|
||||||
|
this.ToolName = value.Name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public Attachment MainSight
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (Attachments.TryFind(MainSightName, out var attachment))
|
||||||
|
return attachment;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value == null)
|
||||||
|
this.MainSightName = "none";
|
||||||
|
else
|
||||||
|
this.MainSightName = value.Name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public Attachment TopSight
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (Attachments.TryFind(TopSightName, out var attachment))
|
||||||
|
return attachment;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value == null)
|
||||||
|
this.TopSightName = "none";
|
||||||
|
else
|
||||||
|
this.TopSightName = value.Name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public Attachment CantedSight
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (Attachments.TryFind(CantedSightName, out var attachment))
|
||||||
|
return attachment;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value == null)
|
||||||
|
this.CantedSightName = "none";
|
||||||
|
else
|
||||||
|
this.CantedSightName = value.Name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public Attachment Barrel
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (Attachments.TryFind(BarrelName, out var attachment))
|
||||||
|
return attachment;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value == null)
|
||||||
|
this.BarrelName = "none";
|
||||||
|
else
|
||||||
|
this.BarrelName = value.Name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public Attachment SideRail
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (Attachments.TryFind(SideRailName, out var attachment))
|
||||||
|
return attachment;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value == null)
|
||||||
|
this.SideRailName = "none";
|
||||||
|
else
|
||||||
|
this.SideRailName = value.Name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public Attachment UnderRail
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (Attachments.TryFind(UnderRailName, out var attachment))
|
||||||
|
return attachment;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value == null)
|
||||||
|
this.UnderRailName = "none";
|
||||||
|
else
|
||||||
|
this.UnderRailName = value.Name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public Attachment BoltAction
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (Attachments.TryFind(BoltActionName, out var attachment))
|
||||||
|
return attachment;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value == null)
|
||||||
|
this.BoltActionName = "none";
|
||||||
|
else
|
||||||
|
this.BoltActionName = value.Name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Weapon Tool
|
public bool HasAttachment(Attachment attachment)
|
||||||
|
{
|
||||||
|
switch (attachment.AttachmentType)
|
||||||
{
|
{
|
||||||
get
|
case AttachmentType.MainSight:
|
||||||
{
|
return this.MainSight == attachment;
|
||||||
if (Weapons.TryFind(ToolName, out var weapon))
|
case AttachmentType.TopSight:
|
||||||
return weapon;
|
return this.TopSight == attachment;
|
||||||
return null;
|
case AttachmentType.CantedSight:
|
||||||
}
|
return this.CantedSight == attachment;
|
||||||
set
|
case AttachmentType.Barrel:
|
||||||
{
|
return this.Barrel == attachment;
|
||||||
if (value == null)
|
case AttachmentType.UnderRail:
|
||||||
this.ToolName = "none";
|
return this.Barrel == attachment;
|
||||||
else
|
case AttachmentType.SideRail:
|
||||||
this.ToolName = value.Name;
|
return this.SideRail == attachment;
|
||||||
}
|
case AttachmentType.Bolt:
|
||||||
|
return this.BoltAction == attachment;
|
||||||
}
|
}
|
||||||
public Attachment MainSight
|
return false;
|
||||||
|
}
|
||||||
|
public void SetAttachment(Attachment attachment)
|
||||||
|
{
|
||||||
|
switch (attachment.AttachmentType)
|
||||||
{
|
{
|
||||||
get
|
case AttachmentType.MainSight:
|
||||||
{
|
this.MainSight = attachment;
|
||||||
if (Attachments.TryFind(MainSightName, out var attachment))
|
break;
|
||||||
return attachment;
|
case AttachmentType.TopSight:
|
||||||
return null;
|
this.TopSight = attachment;
|
||||||
}
|
break;
|
||||||
set
|
case AttachmentType.CantedSight:
|
||||||
{
|
this.CantedSight = attachment;
|
||||||
if (value == null)
|
break;
|
||||||
this.MainSightName = "none";
|
case AttachmentType.Barrel:
|
||||||
else
|
this.Barrel = attachment;
|
||||||
this.MainSightName = value.Name;
|
break;
|
||||||
}
|
case AttachmentType.UnderRail:
|
||||||
}
|
this.Barrel = attachment;
|
||||||
public Attachment TopSight
|
break;
|
||||||
{
|
case AttachmentType.SideRail:
|
||||||
get
|
this.SideRail = attachment;
|
||||||
{
|
break;
|
||||||
if (Attachments.TryFind(TopSightName, out var attachment))
|
case AttachmentType.Bolt:
|
||||||
return attachment;
|
this.BoltAction = attachment;
|
||||||
return null;
|
break;
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (value == null)
|
|
||||||
this.TopSightName = "none";
|
|
||||||
else
|
|
||||||
this.TopSightName = value.Name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public Attachment CantedSight
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (Attachments.TryFind(CantedSightName, out var attachment))
|
|
||||||
return attachment;
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (value == null)
|
|
||||||
this.CantedSightName = "none";
|
|
||||||
else
|
|
||||||
this.CantedSightName = value.Name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public Attachment Barrel
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (Attachments.TryFind(BarrelName, out var attachment))
|
|
||||||
return attachment;
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (value == null)
|
|
||||||
this.BarrelName = "none";
|
|
||||||
else
|
|
||||||
this.BarrelName = value.Name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public Attachment SideRail
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (Attachments.TryFind(SideRailName, out var attachment))
|
|
||||||
return attachment;
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (value == null)
|
|
||||||
this.SideRailName = "none";
|
|
||||||
else
|
|
||||||
this.SideRailName = value.Name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public Attachment UnderRail
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (Attachments.TryFind(UnderRailName, out var attachment))
|
|
||||||
return attachment;
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (value == null)
|
|
||||||
this.UnderRailName = "none";
|
|
||||||
else
|
|
||||||
this.UnderRailName = value.Name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public Attachment BoltAction
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (Attachments.TryFind(BoltActionName, out var attachment))
|
|
||||||
return attachment;
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (value == null)
|
|
||||||
this.BoltActionName = "none";
|
|
||||||
else
|
|
||||||
this.BoltActionName = value.Name;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public bool HasAttachment(Attachment attachment)
|
public void Write(Common.Serialization.Stream ser)
|
||||||
{
|
{
|
||||||
switch (attachment.AttachmentType)
|
ser.WriteStringItem(this.ToolName);
|
||||||
{
|
ser.WriteStringItem(this.MainSightName);
|
||||||
case AttachmentType.MainSight:
|
ser.WriteStringItem(this.TopSightName);
|
||||||
return this.MainSight == attachment;
|
ser.WriteStringItem(this.CantedSightName);
|
||||||
case AttachmentType.TopSight:
|
ser.WriteStringItem(this.BarrelName);
|
||||||
return this.TopSight == attachment;
|
ser.WriteStringItem(this.SideRailName);
|
||||||
case AttachmentType.CantedSight:
|
ser.WriteStringItem(this.UnderRailName);
|
||||||
return this.CantedSight == attachment;
|
ser.WriteStringItem(this.BoltActionName);
|
||||||
case AttachmentType.Barrel:
|
ser.Write(this.SkinIndex);
|
||||||
return this.Barrel == attachment;
|
ser.Write(this.MagazineIndex);
|
||||||
case AttachmentType.UnderRail:
|
}
|
||||||
return this.Barrel == attachment;
|
public void Read(Common.Serialization.Stream ser)
|
||||||
case AttachmentType.SideRail:
|
{
|
||||||
return this.SideRail == attachment;
|
ser.TryReadString(out this.ToolName);
|
||||||
case AttachmentType.Bolt:
|
ser.TryReadString(out this.MainSightName);
|
||||||
return this.BoltAction == attachment;
|
ser.TryReadString(out this.TopSightName);
|
||||||
}
|
ser.TryReadString(out this.CantedSightName);
|
||||||
return false;
|
ser.TryReadString(out this.BarrelName);
|
||||||
}
|
ser.TryReadString(out this.SideRailName);
|
||||||
public void SetAttachment(Attachment attachment)
|
ser.TryReadString(out this.UnderRailName);
|
||||||
{
|
ser.TryReadString(out this.BoltActionName);
|
||||||
switch (attachment.AttachmentType)
|
this.SkinIndex = ser.ReadInt8();
|
||||||
{
|
this.MagazineIndex = ser.ReadInt8();
|
||||||
case AttachmentType.MainSight:
|
|
||||||
this.MainSight = attachment;
|
|
||||||
break;
|
|
||||||
case AttachmentType.TopSight:
|
|
||||||
this.TopSight = attachment;
|
|
||||||
break;
|
|
||||||
case AttachmentType.CantedSight:
|
|
||||||
this.CantedSight = attachment;
|
|
||||||
break;
|
|
||||||
case AttachmentType.Barrel:
|
|
||||||
this.Barrel = attachment;
|
|
||||||
break;
|
|
||||||
case AttachmentType.UnderRail:
|
|
||||||
this.Barrel = attachment;
|
|
||||||
break;
|
|
||||||
case AttachmentType.SideRail:
|
|
||||||
this.SideRail = attachment;
|
|
||||||
break;
|
|
||||||
case AttachmentType.Bolt:
|
|
||||||
this.BoltAction = attachment;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Write(Common.Serialization.Stream ser)
|
|
||||||
{
|
|
||||||
ser.WriteStringItem(this.ToolName);
|
|
||||||
ser.WriteStringItem(this.MainSightName);
|
|
||||||
ser.WriteStringItem(this.TopSightName);
|
|
||||||
ser.WriteStringItem(this.CantedSightName);
|
|
||||||
ser.WriteStringItem(this.BarrelName);
|
|
||||||
ser.WriteStringItem(this.SideRailName);
|
|
||||||
ser.WriteStringItem(this.UnderRailName);
|
|
||||||
ser.WriteStringItem(this.BoltActionName);
|
|
||||||
ser.Write(this.SkinIndex);
|
|
||||||
ser.Write(this.MagazineIndex);
|
|
||||||
}
|
|
||||||
public void Read(Common.Serialization.Stream ser)
|
|
||||||
{
|
|
||||||
ser.TryReadString(out this.ToolName);
|
|
||||||
ser.TryReadString(out this.MainSightName);
|
|
||||||
ser.TryReadString(out this.TopSightName);
|
|
||||||
ser.TryReadString(out this.CantedSightName);
|
|
||||||
ser.TryReadString(out this.BarrelName);
|
|
||||||
ser.TryReadString(out this.SideRailName);
|
|
||||||
ser.TryReadString(out this.UnderRailName);
|
|
||||||
ser.TryReadString(out this.BoltActionName);
|
|
||||||
this.SkinIndex = ser.ReadInt8();
|
|
||||||
this.MagazineIndex = ser.ReadInt8();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,10 +99,10 @@ namespace BattleBitAPI.Common.Serialization
|
||||||
}
|
}
|
||||||
public unsafe void Write(double value)
|
public unsafe void Write(double value)
|
||||||
{
|
{
|
||||||
EnsureWriteBufferSize(16);
|
EnsureWriteBufferSize(8);
|
||||||
fixed (byte* ptr = &Buffer[WritePosition])
|
fixed (byte* ptr = &Buffer[WritePosition])
|
||||||
*((double*)ptr) = value;
|
*((double*)ptr) = value;
|
||||||
WritePosition += 16;
|
WritePosition += 8;
|
||||||
}
|
}
|
||||||
public unsafe void Write(float value)
|
public unsafe void Write(float value)
|
||||||
{
|
{
|
||||||
|
@ -423,7 +423,7 @@ namespace BattleBitAPI.Common.Serialization
|
||||||
{
|
{
|
||||||
value = *((double*)ptr);
|
value = *((double*)ptr);
|
||||||
}
|
}
|
||||||
ReadPosition += 16;
|
ReadPosition += 8;
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,9 @@
|
||||||
SpawnPlayer = 12,
|
SpawnPlayer = 12,
|
||||||
SetNewRoomSettings = 13,
|
SetNewRoomSettings = 13,
|
||||||
RespondPlayerMessage = 14,
|
RespondPlayerMessage = 14,
|
||||||
|
SetNewRoundState = 15,
|
||||||
|
SetPlayerWeapon = 16,
|
||||||
|
SetPlayerGadget = 17,
|
||||||
|
|
||||||
PlayerConnected = 50,
|
PlayerConnected = 50,
|
||||||
PlayerDisconnected = 51,
|
PlayerDisconnected = 51,
|
||||||
|
@ -30,5 +33,6 @@
|
||||||
OnPlayerDie = 64,
|
OnPlayerDie = 64,
|
||||||
NotifyNewMapRotation = 65,
|
NotifyNewMapRotation = 65,
|
||||||
NotifyNewGamemodeRotation = 66,
|
NotifyNewGamemodeRotation = 66,
|
||||||
|
NotifyNewRoundState = 67,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using BattleBitAPI.Common;
|
using BattleBitAPI.Common;
|
||||||
|
using BattleBitAPI.Networking;
|
||||||
using BattleBitAPI.Server;
|
using BattleBitAPI.Server;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
|
@ -83,7 +84,62 @@ namespace BattleBitAPI
|
||||||
{
|
{
|
||||||
GameServer.SpawnPlayer(this, loadout, wearings, position, lookDirection, stand, spawnProtection);
|
GameServer.SpawnPlayer(this, loadout, wearings, position, lookDirection, stand, spawnProtection);
|
||||||
}
|
}
|
||||||
|
public void SetHP(float newHP)
|
||||||
|
{
|
||||||
|
GameServer.SetHP(this, newHP);
|
||||||
|
}
|
||||||
|
public void GiveDamage(float damage)
|
||||||
|
{
|
||||||
|
GameServer.GiveDamage(this, damage);
|
||||||
|
}
|
||||||
|
public void Heal(float hp)
|
||||||
|
{
|
||||||
|
GameServer.Heal(this, hp);
|
||||||
|
}
|
||||||
|
public void SetRunningSpeedMultiplier(float value)
|
||||||
|
{
|
||||||
|
GameServer.SetRunningSpeedMultiplier(this, value);
|
||||||
|
}
|
||||||
|
public void SetReceiveDamageMultiplier(float value)
|
||||||
|
{
|
||||||
|
GameServer.SetReceiveDamageMultiplier(this, value);
|
||||||
|
}
|
||||||
|
public void SetGiveDamageMultiplier(float value)
|
||||||
|
{
|
||||||
|
GameServer.SetGiveDamageMultiplier(this, value);
|
||||||
|
}
|
||||||
|
public void SetJumpMultiplier(float value)
|
||||||
|
{
|
||||||
|
GameServer.SetJumpMultiplier(this, value);
|
||||||
|
}
|
||||||
|
public void SetFallDamageMultiplier(float value)
|
||||||
|
{
|
||||||
|
GameServer.SetFallDamageMultiplier(this, value);
|
||||||
|
}
|
||||||
|
public void SetPrimaryWeapon(WeaponItem item, int extraMagazines,bool clear=false)
|
||||||
|
{
|
||||||
|
GameServer.SetPrimaryWeapon(this, item, extraMagazines, clear);
|
||||||
|
}
|
||||||
|
public void SetSecondaryWeapon(WeaponItem item, int extraMagazines, bool clear = false)
|
||||||
|
{
|
||||||
|
GameServer.SetSecondaryWeapon(this, item, extraMagazines, clear);
|
||||||
|
}
|
||||||
|
public void SetFirstAidGadget(string item, int extra, bool clear = false)
|
||||||
|
{
|
||||||
|
GameServer.SetFirstAid(this, item, extra, clear);
|
||||||
|
}
|
||||||
|
public void SetLightGadget(string item, int extra, bool clear = false)
|
||||||
|
{
|
||||||
|
GameServer.SetLightGadget(this, item, extra, clear);
|
||||||
|
}
|
||||||
|
public void SetHeavyGadget(string item, int extra, bool clear = false)
|
||||||
|
{
|
||||||
|
GameServer.SetHeavyGadget(this, item, extra, clear);
|
||||||
|
}
|
||||||
|
public void SetThrowable(string item, int extra, bool clear = false)
|
||||||
|
{
|
||||||
|
GameServer.SetThrowable(this, item, extra, clear);
|
||||||
|
}
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return this.Name + " (" + this.SteamID + ")";
|
return this.Name + " (" + this.SteamID + ")";
|
||||||
|
|
|
@ -88,6 +88,18 @@ namespace BattleBitAPI.Server
|
||||||
}
|
}
|
||||||
this.ExecuteCommand(this.mInternal.mBuilder.ToString());
|
this.ExecuteCommand(this.mInternal.mBuilder.ToString());
|
||||||
}
|
}
|
||||||
|
if (this.mInternal.IsDirtyRoundSettings)
|
||||||
|
{
|
||||||
|
this.mInternal.IsDirtyRoundSettings = false;
|
||||||
|
|
||||||
|
//Send new round settings
|
||||||
|
using (var pck = Common.Serialization.Stream.Get())
|
||||||
|
{
|
||||||
|
pck.Write((byte)NetworkCommuncation.SetNewRoundState);
|
||||||
|
this.mInternal._RoundSettings.Write(pck);
|
||||||
|
WriteToSocket(pck);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -299,6 +311,18 @@ namespace BattleBitAPI.Server
|
||||||
public virtual async Task OnPlayerReported(TPlayer from, TPlayer to, ReportReason reason, string additional)
|
public virtual async Task OnPlayerReported(TPlayer from, TPlayer to, ReportReason reason, string additional)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
public virtual async Task OnGameStateChanged(GameState oldState, GameState newState)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
public virtual async Task OnRoundStarted()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
public virtual async Task OnRoundEnded()
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- Functions ----
|
// ---- Functions ----
|
||||||
|
@ -469,6 +493,179 @@ namespace BattleBitAPI.Server
|
||||||
{
|
{
|
||||||
SpawnPlayer(player.SteamID, loadout, wearings, position, lookDirection, stand, spawnProtection);
|
SpawnPlayer(player.SteamID, loadout, wearings, position, lookDirection, stand, spawnProtection);
|
||||||
}
|
}
|
||||||
|
public void SetHP(ulong steamID, float newHP)
|
||||||
|
{
|
||||||
|
ExecuteCommand("sethp " + steamID + " " + newHP);
|
||||||
|
}
|
||||||
|
public void SetHP(Player<TPlayer> player, float newHP)
|
||||||
|
{
|
||||||
|
SetHP(player.SteamID, newHP);
|
||||||
|
}
|
||||||
|
public void GiveDamage(ulong steamID, float damage)
|
||||||
|
{
|
||||||
|
ExecuteCommand("givedamage " + steamID + " " + damage);
|
||||||
|
}
|
||||||
|
public void GiveDamage(Player<TPlayer> player, float damage)
|
||||||
|
{
|
||||||
|
GiveDamage(player.SteamID, damage);
|
||||||
|
}
|
||||||
|
public void Heal(ulong steamID, float heal)
|
||||||
|
{
|
||||||
|
ExecuteCommand("heal " + steamID + " " + heal);
|
||||||
|
}
|
||||||
|
public void Heal(Player<TPlayer> player, float heal)
|
||||||
|
{
|
||||||
|
Heal(player.SteamID, heal);
|
||||||
|
}
|
||||||
|
public void SetRunningSpeedMultiplier(ulong steamID, float value)
|
||||||
|
{
|
||||||
|
ExecuteCommand("setrunningspeed " + steamID + " " + value);
|
||||||
|
}
|
||||||
|
public void SetRunningSpeedMultiplier(Player<TPlayer> player, float value)
|
||||||
|
{
|
||||||
|
SetRunningSpeedMultiplier(player.SteamID, value);
|
||||||
|
}
|
||||||
|
public void SetReceiveDamageMultiplier(ulong steamID, float value)
|
||||||
|
{
|
||||||
|
ExecuteCommand("setreceivedamagemultiplier " + steamID + " " + value);
|
||||||
|
}
|
||||||
|
public void SetReceiveDamageMultiplier(Player<TPlayer> player, float value)
|
||||||
|
{
|
||||||
|
SetReceiveDamageMultiplier(player.SteamID, value);
|
||||||
|
}
|
||||||
|
public void SetGiveDamageMultiplier(ulong steamID, float value)
|
||||||
|
{
|
||||||
|
ExecuteCommand("setgivedamagemultiplier " + steamID + " " + value);
|
||||||
|
}
|
||||||
|
public void SetGiveDamageMultiplier(Player<TPlayer> player, float value)
|
||||||
|
{
|
||||||
|
SetGiveDamageMultiplier(player.SteamID, value);
|
||||||
|
}
|
||||||
|
public void SetJumpMultiplier(ulong steamID, float value)
|
||||||
|
{
|
||||||
|
ExecuteCommand("setjumpmultiplier " + steamID + " " + value);
|
||||||
|
}
|
||||||
|
public void SetJumpMultiplier(Player<TPlayer> player, float value)
|
||||||
|
{
|
||||||
|
SetJumpMultiplier(player.SteamID, value);
|
||||||
|
}
|
||||||
|
public void SetFallDamageMultiplier(ulong steamID, float value)
|
||||||
|
{
|
||||||
|
ExecuteCommand("setfalldamagemultiplier " + steamID + " " + value);
|
||||||
|
}
|
||||||
|
public void SetFallDamageMultiplier(Player<TPlayer> player, float value)
|
||||||
|
{
|
||||||
|
SetFallDamageMultiplier(player.SteamID, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetPrimaryWeapon(ulong steamID, WeaponItem item, int extraMagazines, bool clear = false)
|
||||||
|
{
|
||||||
|
using (var packet = Common.Serialization.Stream.Get())
|
||||||
|
{
|
||||||
|
packet.Write((byte)NetworkCommuncation.SetPlayerWeapon);
|
||||||
|
packet.Write(steamID);
|
||||||
|
packet.Write((byte)0);//Primary
|
||||||
|
item.Write(packet);
|
||||||
|
packet.Write((byte)extraMagazines);
|
||||||
|
packet.Write(clear);
|
||||||
|
|
||||||
|
WriteToSocket(packet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void SetPrimaryWeapon(Player<TPlayer> player, WeaponItem item, int extraMagazines, bool clear = false)
|
||||||
|
{
|
||||||
|
SetPrimaryWeapon(player.SteamID, item, extraMagazines, clear);
|
||||||
|
}
|
||||||
|
public void SetSecondaryWeapon(ulong steamID, WeaponItem item, int extraMagazines, bool clear = false)
|
||||||
|
{
|
||||||
|
using (var packet = Common.Serialization.Stream.Get())
|
||||||
|
{
|
||||||
|
packet.Write((byte)NetworkCommuncation.SetPlayerWeapon);
|
||||||
|
packet.Write(steamID);
|
||||||
|
packet.Write((byte)1);//Secondary
|
||||||
|
item.Write(packet);
|
||||||
|
packet.Write((byte)extraMagazines);
|
||||||
|
packet.Write(clear);
|
||||||
|
|
||||||
|
WriteToSocket(packet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void SetSecondaryWeapon(Player<TPlayer> player, WeaponItem item, int extraMagazines, bool clear = false)
|
||||||
|
{
|
||||||
|
SetSecondaryWeapon(player.SteamID, item, extraMagazines, clear);
|
||||||
|
}
|
||||||
|
public void SetFirstAid(ulong steamID, string tool, int extra, bool clear = false)
|
||||||
|
{
|
||||||
|
using (var packet = Common.Serialization.Stream.Get())
|
||||||
|
{
|
||||||
|
packet.Write((byte)NetworkCommuncation.SetPlayerGadget);
|
||||||
|
packet.Write(steamID);
|
||||||
|
packet.Write((byte)2);//first aid
|
||||||
|
packet.Write(tool);
|
||||||
|
packet.Write((byte)extra);
|
||||||
|
packet.Write(clear);
|
||||||
|
|
||||||
|
WriteToSocket(packet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void SetFirstAid(Player<TPlayer> player, string tool, int extra, bool clear = false)
|
||||||
|
{
|
||||||
|
SetFirstAid(player.SteamID, tool, extra, clear);
|
||||||
|
}
|
||||||
|
public void SetLightGadget(ulong steamID, string tool, int extra, bool clear = false)
|
||||||
|
{
|
||||||
|
using (var packet = Common.Serialization.Stream.Get())
|
||||||
|
{
|
||||||
|
packet.Write((byte)NetworkCommuncation.SetPlayerGadget);
|
||||||
|
packet.Write(steamID);
|
||||||
|
packet.Write((byte)3);//Tool A
|
||||||
|
packet.Write(tool);
|
||||||
|
packet.Write((byte)extra);
|
||||||
|
packet.Write(clear);
|
||||||
|
|
||||||
|
WriteToSocket(packet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void SetLightGadget(Player<TPlayer> player, string tool, int extra, bool clear = false)
|
||||||
|
{
|
||||||
|
SetLightGadget(player.SteamID, tool, extra, clear);
|
||||||
|
}
|
||||||
|
public void SetHeavyGadget(ulong steamID, string tool, int extra, bool clear = false)
|
||||||
|
{
|
||||||
|
using (var packet = Common.Serialization.Stream.Get())
|
||||||
|
{
|
||||||
|
packet.Write((byte)NetworkCommuncation.SetPlayerGadget);
|
||||||
|
packet.Write(steamID);
|
||||||
|
packet.Write((byte)4);//Tool A
|
||||||
|
packet.Write(tool);
|
||||||
|
packet.Write((byte)extra);
|
||||||
|
packet.Write(clear);
|
||||||
|
|
||||||
|
WriteToSocket(packet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void SetHeavyGadget(Player<TPlayer> player, string tool, int extra, bool clear = false)
|
||||||
|
{
|
||||||
|
SetHeavyGadget(player.SteamID, tool, extra, clear);
|
||||||
|
}
|
||||||
|
public void SetThrowable(ulong steamID, string tool, int extra, bool clear = false)
|
||||||
|
{
|
||||||
|
using (var packet = Common.Serialization.Stream.Get())
|
||||||
|
{
|
||||||
|
packet.Write((byte)NetworkCommuncation.SetPlayerGadget);
|
||||||
|
packet.Write(steamID);
|
||||||
|
packet.Write((byte)5);//Tool A
|
||||||
|
packet.Write(tool);
|
||||||
|
packet.Write((byte)extra);
|
||||||
|
packet.Write(clear);
|
||||||
|
|
||||||
|
WriteToSocket(packet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void SetThrowable(Player<TPlayer> player, string tool, int extra, bool clear = false)
|
||||||
|
{
|
||||||
|
SetThrowable(player.SteamID, tool, extra,clear);
|
||||||
|
}
|
||||||
|
|
||||||
// ---- Closing ----
|
// ---- Closing ----
|
||||||
public void CloseConnection(string additionInfo = "")
|
public void CloseConnection(string additionInfo = "")
|
||||||
|
@ -739,44 +936,42 @@ namespace BattleBitAPI.Server
|
||||||
}
|
}
|
||||||
public class mRoundSettings
|
public class mRoundSettings
|
||||||
{
|
{
|
||||||
|
public const int Size = 1 + 8 + 8 + 8 + 4 + 4;
|
||||||
|
|
||||||
public GameState State = GameState.WaitingForPlayers;
|
public GameState State = GameState.WaitingForPlayers;
|
||||||
public int TeamATickets = 0;
|
public double TeamATickets = 0;
|
||||||
public int TeamAMaxTickets = 1;
|
public double TeamBTickets = 0;
|
||||||
public int TeamBTickets = 0;
|
public double MaxTickets = 1;
|
||||||
public int TeamBMaxTickets = 1;
|
|
||||||
public int PlayersToStart = 16;
|
public int PlayersToStart = 16;
|
||||||
public int SecondsLeftToEndOfRound = 60;
|
public int SecondsLeft = 60;
|
||||||
|
|
||||||
public void Write(Common.Serialization.Stream ser)
|
public void Write(Common.Serialization.Stream ser)
|
||||||
{
|
{
|
||||||
ser.Write((byte)this.State);
|
ser.Write((byte)this.State);
|
||||||
ser.Write(this.TeamATickets);
|
ser.Write(this.TeamATickets);
|
||||||
ser.Write(this.TeamAMaxTickets);
|
|
||||||
ser.Write(this.TeamBTickets);
|
ser.Write(this.TeamBTickets);
|
||||||
ser.Write(this.TeamBMaxTickets);
|
ser.Write(this.MaxTickets);
|
||||||
ser.Write(this.PlayersToStart);
|
ser.Write(this.PlayersToStart);
|
||||||
ser.Write(this.SecondsLeftToEndOfRound);
|
ser.Write(this.SecondsLeft);
|
||||||
}
|
}
|
||||||
public void Read(Common.Serialization.Stream ser)
|
public void Read(Common.Serialization.Stream ser)
|
||||||
{
|
{
|
||||||
this.State = (GameState)ser.ReadInt8();
|
this.State = (GameState)ser.ReadInt8();
|
||||||
this.TeamATickets = ser.ReadInt32();
|
this.TeamATickets = ser.ReadDouble();
|
||||||
this.TeamAMaxTickets = ser.ReadInt32();
|
this.TeamBTickets = ser.ReadDouble();
|
||||||
this.TeamBTickets = ser.ReadInt32();
|
this.MaxTickets = ser.ReadDouble();
|
||||||
this.TeamBMaxTickets = ser.ReadInt32();
|
|
||||||
this.PlayersToStart = ser.ReadInt32();
|
this.PlayersToStart = ser.ReadInt32();
|
||||||
this.SecondsLeftToEndOfRound = ser.ReadInt32();
|
this.SecondsLeft = ser.ReadInt32();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Reset()
|
public void Reset()
|
||||||
{
|
{
|
||||||
this.State = GameState.WaitingForPlayers;
|
this.State = GameState.WaitingForPlayers;
|
||||||
this.TeamATickets = 0;
|
this.TeamATickets = 0;
|
||||||
this.TeamAMaxTickets = 1;
|
|
||||||
this.TeamBTickets = 0;
|
this.TeamBTickets = 0;
|
||||||
this.TeamBMaxTickets = 1;
|
this.MaxTickets = 1;
|
||||||
this.PlayersToStart = 16;
|
this.PlayersToStart = 16;
|
||||||
this.SecondsLeftToEndOfRound = 60;
|
this.SecondsLeft = 60;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ namespace BattleBitAPI.Server
|
||||||
{
|
{
|
||||||
get => this.mResources._RoundSettings.State;
|
get => this.mResources._RoundSettings.State;
|
||||||
}
|
}
|
||||||
public int TeamATickets
|
public double TeamATickets
|
||||||
{
|
{
|
||||||
get => this.mResources._RoundSettings.TeamATickets;
|
get => this.mResources._RoundSettings.TeamATickets;
|
||||||
set
|
set
|
||||||
|
@ -23,16 +23,7 @@ namespace BattleBitAPI.Server
|
||||||
this.mResources.IsDirtyRoundSettings = true;
|
this.mResources.IsDirtyRoundSettings = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public int TeamAMaxTickets
|
public double TeamBTickets
|
||||||
{
|
|
||||||
get => this.mResources._RoundSettings.TeamAMaxTickets;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
this.mResources._RoundSettings.TeamAMaxTickets = value;
|
|
||||||
this.mResources.IsDirtyRoundSettings = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public int TeamBTickets
|
|
||||||
{
|
{
|
||||||
get => this.mResources._RoundSettings.TeamBTickets;
|
get => this.mResources._RoundSettings.TeamBTickets;
|
||||||
set
|
set
|
||||||
|
@ -41,12 +32,12 @@ namespace BattleBitAPI.Server
|
||||||
this.mResources.IsDirtyRoundSettings = true;
|
this.mResources.IsDirtyRoundSettings = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public int TeamBMaxTickets
|
public double MaxTickets
|
||||||
{
|
{
|
||||||
get => this.mResources._RoundSettings.TeamBMaxTickets;
|
get => this.mResources._RoundSettings.MaxTickets;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
this.mResources._RoundSettings.TeamBTickets = value;
|
this.mResources._RoundSettings.MaxTickets = value;
|
||||||
this.mResources.IsDirtyRoundSettings = true;
|
this.mResources.IsDirtyRoundSettings = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,12 +50,12 @@ namespace BattleBitAPI.Server
|
||||||
this.mResources.IsDirtyRoundSettings = true;
|
this.mResources.IsDirtyRoundSettings = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public int SecondsLeftToEndOfRound
|
public int SecondsLeft
|
||||||
{
|
{
|
||||||
get => this.mResources._RoundSettings.SecondsLeftToEndOfRound;
|
get => this.mResources._RoundSettings.SecondsLeft;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
this.mResources._RoundSettings.SecondsLeftToEndOfRound = value;
|
this.mResources._RoundSettings.SecondsLeft = value;
|
||||||
this.mResources.IsDirtyRoundSettings = true;
|
this.mResources.IsDirtyRoundSettings = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -385,6 +385,14 @@ namespace BattleBitAPI.Server
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Round Settings
|
||||||
|
{
|
||||||
|
readStream.Reset();
|
||||||
|
if (!await networkStream.TryRead(readStream, GameServer<TPlayer>.mRoundSettings.Size, source.Token))
|
||||||
|
throw new Exception("Unable to read the round settings");
|
||||||
|
resources._RoundSettings.Read(readStream);
|
||||||
|
}
|
||||||
|
|
||||||
//Client Count
|
//Client Count
|
||||||
int clientCount = 0;
|
int clientCount = 0;
|
||||||
{
|
{
|
||||||
|
@ -979,6 +987,26 @@ namespace BattleBitAPI.Server
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case NetworkCommuncation.NotifyNewRoundState:
|
||||||
|
{
|
||||||
|
if (stream.CanRead(GameServer<TPlayer>.mRoundSettings.Size))
|
||||||
|
{
|
||||||
|
var oldState = resources._RoundSettings.State;
|
||||||
|
resources._RoundSettings.Read(stream);
|
||||||
|
var newState = resources._RoundSettings.State;
|
||||||
|
|
||||||
|
if (newState != oldState)
|
||||||
|
{
|
||||||
|
server.OnGameStateChanged(oldState, newState);
|
||||||
|
|
||||||
|
if (newState == GameState.Playing)
|
||||||
|
server.OnRoundStarted();
|
||||||
|
else if (newState == GameState.EndingGame)
|
||||||
|
server.OnRoundEnded();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
51
Program.cs
51
Program.cs
|
@ -2,6 +2,7 @@
|
||||||
using BattleBitAPI.Common;
|
using BattleBitAPI.Common;
|
||||||
using BattleBitAPI.Server;
|
using BattleBitAPI.Server;
|
||||||
using System.Threading.Channels;
|
using System.Threading.Channels;
|
||||||
|
using System.Xml;
|
||||||
|
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
|
@ -15,38 +16,38 @@ class Program
|
||||||
}
|
}
|
||||||
class MyPlayer : Player<MyPlayer>
|
class MyPlayer : Player<MyPlayer>
|
||||||
{
|
{
|
||||||
|
public int NumberOfKills;
|
||||||
}
|
}
|
||||||
class MyGameServer : GameServer<MyPlayer>
|
class MyGameServer : GameServer<MyPlayer>
|
||||||
{
|
{
|
||||||
public List<string> ChatMessages = new List<string>();
|
public WeaponItem[] WeaponList = new WeaponItem[]
|
||||||
|
|
||||||
public override async Task<bool> OnPlayerTypedMessage(MyPlayer player, ChatChannel channel, string msg)
|
|
||||||
{
|
{
|
||||||
return true;
|
new WeaponItem(){ Tool = Weapons.M4A1, MainSight = Attachments._6xScope},
|
||||||
}
|
new WeaponItem(){ Tool = Weapons.SVD, MainSight = Attachments._6xScope},
|
||||||
public override async Task OnConnected()
|
new WeaponItem(){ Tool = Weapons.SCARH, MainSight = Attachments._6xScope},
|
||||||
{
|
new WeaponItem(){ Tool = Weapons.ScorpionEVO, MainSight = Attachments._6xScope},
|
||||||
await Console.Out.WriteLineAsync(this.GameIP + " Connected");
|
new WeaponItem(){ Tool = Weapons.M249, MainSight = Attachments._6xScope},
|
||||||
}
|
new WeaponItem(){ Tool = Weapons.Groza, MainSight = Attachments._6xScope},
|
||||||
public override async Task OnDisconnected()
|
new WeaponItem(){ Tool = Weapons.Glock18, MainSight = Attachments._6xScope},
|
||||||
{
|
};
|
||||||
await Console.Out.WriteLineAsync(this.GameIP + " Disconnected");
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task OnTick()
|
public override async Task OnTick()
|
||||||
{
|
{
|
||||||
if (RoundSettings.State == GameState.WaitingForPlayers)
|
if (this.RoundSettings.State == GameState.WaitingForPlayers)
|
||||||
{
|
ForceStartGame();
|
||||||
int numberOfPeopleInServer = this.CurrentPlayers;
|
|
||||||
if (numberOfPeopleInServer > 4)
|
|
||||||
{
|
|
||||||
ForceStartGame();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (RoundSettings.State == GameState.Playing)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
await Task.Delay(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task<OnPlayerSpawnArguments> OnPlayerSpawning(MyPlayer player, OnPlayerSpawnArguments request)
|
||||||
|
{
|
||||||
|
request.Loadout.PrimaryWeapon = WeaponList[player.NumberOfKills];
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task OnAPlayerKilledAnotherPlayer(OnPlayerKillArguments<MyPlayer> args)
|
||||||
|
{
|
||||||
|
args.Killer.NumberOfKills++;
|
||||||
|
args.Killer.SetPrimaryWeapon(WeaponList[args.Killer.NumberOfKills], 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue