Migrate to new version
This commit is contained in:
parent
3b844211ee
commit
348ecefc5b
|
@ -1,5 +1,5 @@
|
|||
using System.Numerics;
|
||||
using CommunityServerAPI.BattleBitAPI.Server;
|
||||
using BattleBitAPI.Server;
|
||||
|
||||
namespace BattleBitAPI.Common
|
||||
{
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
using BattleBitAPI.Common;
|
||||
using CommunityServerAPI.BattleBitAPI.Server;
|
||||
using BattleBitAPI.Server;
|
||||
|
||||
namespace BattleBitAPI.Server
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using CommunityServerAPI.BattleBitAPI.Server;
|
||||
using BattleBitAPI.Server;
|
||||
|
||||
namespace BattleBitAPI.Server
|
||||
{
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
using BattleBitAPI.Common;
|
||||
using CommunityServerAPI.BattleBitAPI.Server;
|
||||
using BattleBitAPI.Server;
|
||||
|
||||
namespace BattleBitAPI.Server
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using CommunityServerAPI.BattleBitAPI.Server;
|
||||
using BattleBitAPI.Server;
|
||||
|
||||
namespace BattleBitAPI.Server
|
||||
{
|
||||
|
|
|
@ -9,7 +9,7 @@ using BattleBitAPI.Common.Extentions;
|
|||
using BattleBitAPI.Common.Serialization;
|
||||
using BattleBitAPI.Networking;
|
||||
using CommunityServerAPI.BattleBitAPI;
|
||||
using CommunityServerAPI.BattleBitAPI.Server;
|
||||
using BattleBitAPI.Server;
|
||||
|
||||
namespace BattleBitAPI.Server
|
||||
{
|
||||
|
|
72
Program.cs
72
Program.cs
|
@ -1,8 +1,6 @@
|
|||
using BattleBitAPI;
|
||||
using BattleBitAPI.Common;
|
||||
using BattleBitAPI.Server;
|
||||
using System.Threading.Channels;
|
||||
using System.Xml;
|
||||
|
||||
class Program
|
||||
{
|
||||
|
@ -10,24 +8,24 @@ class Program
|
|||
{
|
||||
var listener = new ServerListener<MyPlayer, MyGameServer>();
|
||||
listener.Start(30001);
|
||||
|
||||
|
||||
Console.WriteLine("API started!");
|
||||
|
||||
Thread.Sleep(-1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
class MyPlayer : Player<MyPlayer>
|
||||
{
|
||||
public int Kills;
|
||||
public int Deaths;
|
||||
public List<MyPlayer> players;
|
||||
}
|
||||
|
||||
class MyGameServer : GameServer<MyPlayer>
|
||||
{
|
||||
private List<MyPlayer> players;
|
||||
|
||||
|
||||
public override async Task OnConnected()
|
||||
{
|
||||
Console.WriteLine($"Gameserver connected! {this.GameIP}:{this.GamePort}");
|
||||
|
@ -35,7 +33,7 @@ class MyGameServer : GameServer<MyPlayer>
|
|||
ServerSettings.BleedingEnabled = false;
|
||||
ServerSettings.SpectatorEnabled = false;
|
||||
}
|
||||
|
||||
|
||||
public override async Task OnDisconnected()
|
||||
{
|
||||
Console.WriteLine($"Gameserver disconnected! {this.GameIP}:{this.GamePort}");
|
||||
|
@ -44,23 +42,26 @@ class MyGameServer : GameServer<MyPlayer>
|
|||
public override async Task OnReconnected()
|
||||
{
|
||||
Console.WriteLine($"Gameserver reconnected! {this.GameIP}:{this.GamePort}");
|
||||
|
||||
|
||||
ServerSettings.BleedingEnabled = false;
|
||||
ServerSettings.SpectatorEnabled = false;
|
||||
}
|
||||
|
||||
public override async Task OnGameStateChanged(GameState oldState, GameState newState)
|
||||
{
|
||||
await Console.Out.WriteLineAsync("Giveup: " + player);
|
||||
await Console.Out.WriteLineAsync("State changed to -> " + newState);
|
||||
}
|
||||
|
||||
public override async Task OnPlayerDied(MyPlayer player)
|
||||
{
|
||||
await Console.Out.WriteLineAsync("Died: " + player);
|
||||
}
|
||||
|
||||
public override async Task OnAPlayerRevivedAnotherPlayer(MyPlayer from, MyPlayer to)
|
||||
{
|
||||
await Console.Out.WriteLineAsync(from + " revived " + to);
|
||||
}
|
||||
|
||||
public override async Task OnPlayerDisconnected(MyPlayer player)
|
||||
{
|
||||
await Console.Out.WriteLineAsync("Disconnected: " + player);
|
||||
|
@ -71,10 +72,10 @@ class MyGameServer : GameServer<MyPlayer>
|
|||
var top5 = players.OrderByDescending(x => x.Kills / x.Deaths).Take(5).ToList();
|
||||
var topPlayersInfo = top5.Select((p, index) => $"{index + 1}. {p.Name} - {p.Kills / p.Deaths}");
|
||||
var announcement = $"<align=\"center\">--- Top 5 Players ---\n{string.Join("\n", topPlayersInfo)}</align>";
|
||||
|
||||
|
||||
AnnounceShort(announcement);
|
||||
}
|
||||
|
||||
|
||||
private MyPlayer FindPlayerByIdentifier(string identifier)
|
||||
{
|
||||
ulong.TryParse(identifier, out ulong steamid);
|
||||
|
@ -91,64 +92,65 @@ class MyGameServer : GameServer<MyPlayer>
|
|||
switch (words[0])
|
||||
{
|
||||
case "/tp":
|
||||
// /tp <steamid/name>
|
||||
// /tp <steamid/name> <steamid/name> or /tp <steamid/name> (tp executor to target)
|
||||
var tpTarget = FindPlayerByIdentifier(words[1]);
|
||||
|
||||
if (tpTarget == null)
|
||||
var tpDestination = FindPlayerByIdentifier(words.Length > 2 ? words[2] : player.Name);
|
||||
|
||||
if (tpTarget == null || tpDestination == null)
|
||||
{
|
||||
player.Message("Player not found!");
|
||||
return false;
|
||||
}
|
||||
|
||||
player.Message("Not implemented yet!");
|
||||
|
||||
tpTarget.Teleport(tpDestination.Position);
|
||||
break;
|
||||
|
||||
|
||||
case "/kill":
|
||||
// /kill <steamid/name>
|
||||
var killTarget = FindPlayerByIdentifier(words[1]);
|
||||
|
||||
|
||||
if (killTarget == null)
|
||||
{
|
||||
player.Message("Player not found!");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
killTarget.Kill();
|
||||
break;
|
||||
|
||||
|
||||
case "/heal":
|
||||
// /heal <steamid/name> <amount>
|
||||
var healTarget = FindPlayerByIdentifier(words[1]);
|
||||
|
||||
|
||||
if (healTarget == null)
|
||||
{
|
||||
player.Message("Player not found!");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
var healAmount = words.Length > 2 ? int.Parse(words[2]) : 100;
|
||||
healTarget.Heal(healAmount);
|
||||
break;
|
||||
|
||||
|
||||
case "/kick":
|
||||
// /kick <steamid/name> <reason>
|
||||
var kickTarget = FindPlayerByIdentifier(words[1]);
|
||||
|
||||
|
||||
if (kickTarget == null)
|
||||
{
|
||||
player.Message("Player not found!");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
var kickReason = words.Length > 2 ? string.Join(" ", words.Skip(2)) : "No reason provided";
|
||||
|
||||
|
||||
kickTarget.Kick(kickReason);
|
||||
break;
|
||||
default:
|
||||
player.Message("Unknown command!");
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -170,7 +172,7 @@ class MyGameServer : GameServer<MyPlayer>
|
|||
player.Deaths = 0;
|
||||
}
|
||||
|
||||
public override Task<PlayerStats> OnGetPlayerStats(ulong steamID, PlayerStats officialStats)
|
||||
public override Task OnPlayerJoiningToServer(ulong steamID, PlayerJoiningArguments args)
|
||||
{
|
||||
var stats = new PlayerStats();
|
||||
|
||||
|
@ -181,21 +183,23 @@ class MyGameServer : GameServer<MyPlayer>
|
|||
{
|
||||
stats.Roles = Roles.Admin;
|
||||
}
|
||||
|
||||
|
||||
return Task.FromResult(stats);
|
||||
}
|
||||
public override async Task OnAPlayerKilledAnotherPlayer(OnPlayerKillArguments<MyPlayer> args)
|
||||
|
||||
public override async Task OnAPlayerDownedAnotherPlayer(OnPlayerKillArguments<MyPlayer> args)
|
||||
{
|
||||
args.Victim.Kill();
|
||||
args.Killer.Heal(100);
|
||||
args.Killer.Kills++;
|
||||
args.Victim.Deaths++;
|
||||
}
|
||||
|
||||
public override async Task <bool> OnPlayerRequestingToChangeRole(MyPlayer player, GameRole role)
|
||||
public override async Task<bool> OnPlayerRequestingToChangeRole(MyPlayer player, GameRole role)
|
||||
{
|
||||
if (role == GameRole.Assault)
|
||||
return true;
|
||||
|
||||
|
||||
player.GameServer.AnnounceShort("You can only play as Assault!");
|
||||
return false;
|
||||
}
|
||||
|
@ -213,9 +217,9 @@ class MyGameServer : GameServer<MyPlayer>
|
|||
|
||||
return request;
|
||||
}
|
||||
|
||||
|
||||
public override async Task OnPlayerSpawned(MyPlayer player)
|
||||
{
|
||||
player.SetGiveDamageMultiplier(0.25f);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue