started working
This commit is contained in:
parent
aea0de1eb6
commit
e77d273b0e
113
Program.cs
113
Program.cs
|
@ -1,113 +0,0 @@
|
|||
using BattleBitAPI;
|
||||
using BattleBitAPI.Common;
|
||||
using BattleBitAPI.Server;
|
||||
using System.Threading.Channels;
|
||||
using System.Xml;
|
||||
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
var listener = new ServerListener<MyPlayer, MyGameServer>();
|
||||
listener.Start(29294);
|
||||
|
||||
Thread.Sleep(-1);
|
||||
}
|
||||
}
|
||||
class MyPlayer : Player<MyPlayer>
|
||||
{
|
||||
public bool IsZombie;
|
||||
}
|
||||
class MyGameServer : GameServer<MyPlayer>
|
||||
{
|
||||
|
||||
public override async Task OnRoundStarted()
|
||||
{
|
||||
}
|
||||
public override async Task OnRoundEnded()
|
||||
{
|
||||
}
|
||||
|
||||
public override async Task OnPlayerConnected(MyPlayer player)
|
||||
{
|
||||
bool anyZombiePlayer = false;
|
||||
foreach (var item in AllPlayers)
|
||||
{
|
||||
if (item.IsZombie)
|
||||
{
|
||||
anyZombiePlayer = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!anyZombiePlayer)
|
||||
{
|
||||
player.IsZombie = true;
|
||||
player.Message("You are the zombie.");
|
||||
player.Kill();
|
||||
}
|
||||
}
|
||||
|
||||
public override async Task OnAPlayerKilledAnotherPlayer(OnPlayerKillArguments<MyPlayer> args)
|
||||
{
|
||||
if (args.Victim.IsZombie)
|
||||
{
|
||||
args.Victim.IsZombie = false;
|
||||
args.Victim.Message("You are no longer zombie");
|
||||
|
||||
AnnounceShort("Choosing new zombie in 5");
|
||||
await Task.Delay(1000);
|
||||
AnnounceShort("Choosing new zombie in 4");
|
||||
await Task.Delay(1000);
|
||||
AnnounceShort("Choosing new zombie in 3");
|
||||
await Task.Delay(1000);
|
||||
AnnounceShort("Choosing new zombie in 2");
|
||||
await Task.Delay(1000);
|
||||
AnnounceShort("Choosing new zombie in 1");
|
||||
await Task.Delay(1000);
|
||||
|
||||
args.Killer.IsZombie = true;
|
||||
args.Killer.SetHeavyGadget(Gadgets.SledgeHammer.ToString(), 0, true);
|
||||
|
||||
var position = args.Killer.GetPosition();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override async Task<OnPlayerSpawnArguments> OnPlayerSpawning(MyPlayer player, OnPlayerSpawnArguments request)
|
||||
{
|
||||
if (player.IsZombie)
|
||||
{
|
||||
request.Loadout.PrimaryWeapon = default;
|
||||
request.Loadout.SecondaryWeapon = default;
|
||||
request.Loadout.LightGadget = null;
|
||||
request.Loadout.HeavyGadget = Gadgets.SledgeHammer;
|
||||
request.Loadout.Throwable = null;
|
||||
}
|
||||
|
||||
return request;
|
||||
}
|
||||
public override async Task OnPlayerSpawned(MyPlayer player)
|
||||
{
|
||||
if(player.IsZombie)
|
||||
{
|
||||
player.SetRunningSpeedMultiplier(2f);
|
||||
player.SetJumpMultiplier(2f);
|
||||
player.SetFallDamageMultiplier(0f);
|
||||
player.SetReceiveDamageMultiplier(0.1f);
|
||||
player.SetGiveDamageMultiplier(4f);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public override async Task OnConnected()
|
||||
{
|
||||
await Console.Out.WriteLineAsync("Current state: " + RoundSettings.State);
|
||||
|
||||
}
|
||||
public override async Task OnGameStateChanged(GameState oldState, GameState newState)
|
||||
{
|
||||
await Console.Out.WriteLineAsync("State changed to -> " + newState);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,108 @@
|
|||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace CommandQueueApp
|
||||
{
|
||||
public class Data
|
||||
{
|
||||
|
||||
}
|
||||
public class Command
|
||||
{
|
||||
public string Action { get; set; }
|
||||
public ulong StreamerID { get; set; }
|
||||
public int Amount { get; set; }
|
||||
|
||||
public string Data { get; set;}
|
||||
|
||||
public string ExecuterName{ get; set; }
|
||||
|
||||
public Data DataHandler( string data, string Action)
|
||||
{
|
||||
return new Data();
|
||||
}
|
||||
}
|
||||
|
||||
public class CommandQueue
|
||||
{
|
||||
private readonly ConcurrentQueue<Command> _queue = new ConcurrentQueue<Command>();
|
||||
|
||||
public void Enqueue(Command command)
|
||||
{
|
||||
_queue.Enqueue(command);
|
||||
}
|
||||
|
||||
public Command Dequeue()
|
||||
{
|
||||
_queue.TryDequeue(out Command command);
|
||||
return command;
|
||||
}
|
||||
|
||||
public bool IsEmpty(){
|
||||
return _queue.IsEmpty;
|
||||
}
|
||||
}
|
||||
|
||||
public class Startup
|
||||
{
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<CommandQueue>();
|
||||
services.AddControllers();
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
}
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapControllers();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class CommandController : ControllerBase
|
||||
{
|
||||
private readonly CommandQueue _commandQueue;
|
||||
|
||||
public CommandController(CommandQueue commandQueue)
|
||||
{
|
||||
_commandQueue = commandQueue;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult PostCommand([FromBody] Command command)
|
||||
{
|
||||
_commandQueue.Enqueue(command);
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
CreateHostBuilder(args).Build().Run();
|
||||
}
|
||||
|
||||
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||
Host.CreateDefaultBuilder(args)
|
||||
.ConfigureWebHostDefaults(webBuilder =>
|
||||
{
|
||||
webBuilder.UseStartup<Startup>();
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,108 @@
|
|||
using BattleBitAPI;
|
||||
using BattleBitAPI.Common;
|
||||
using BattleBitAPI.Server;
|
||||
using CommandQueueApp;
|
||||
using System.Threading.Channels;
|
||||
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
var listener = new ServerListener<MyPlayer, MyGameServer>();
|
||||
listener.Start(29294);
|
||||
listener.OnPlayerConnected += HandlePlayerConnected;
|
||||
listener.OnTick += HandleTick;
|
||||
Thread.Sleep(-1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static async Task<bool> HandleTick(){
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static async Task<bool> HandlePlayerConnected(MyPlayer player)
|
||||
{
|
||||
MyGameServer server = player.GameServer;
|
||||
if(!listed_streamers.contains(player.SteamID)){
|
||||
return true;
|
||||
}
|
||||
if(server.connected_streamers.contains(player.SteamID)){
|
||||
return true;
|
||||
}
|
||||
server.connected_streamers.Add(player);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
class MyPlayer : Player<MyPlayer>
|
||||
{
|
||||
|
||||
}
|
||||
class MyGameServer : GameServer<MyPlayer>
|
||||
{
|
||||
public CommandQueue queue = new();
|
||||
public List<MyPlayer> connectedStreamers = new List<MyPlayer>();
|
||||
public List<string> ChatMessages = new List<string>();
|
||||
|
||||
public override async Task<bool> OnPlayerTypedMessage(MyPlayer player, ChatChannel channel, string msg)
|
||||
{
|
||||
var c = new Command();
|
||||
c.Action.set("heal");
|
||||
c.Amount.set(10);
|
||||
c.ExecuterName.set("Tester");
|
||||
HandleCommand(c);
|
||||
return true;
|
||||
}
|
||||
public override async Task OnConnected()
|
||||
{
|
||||
await Console.Out.WriteLineAsync(this.GameIP + " Connected");
|
||||
}
|
||||
public override async Task OnDisconnected()
|
||||
{
|
||||
await Console.Out.WriteLineAsync(this.GameIP + " Disconnected");
|
||||
}
|
||||
|
||||
public override async Task OnTick()
|
||||
{
|
||||
while(!queue.IsEmpty()){
|
||||
Command c = queue.Dequeue();
|
||||
HandleCommand(c);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task HandleCommand(Command c){
|
||||
foreach(MyPlayer player in connectedStreamers){
|
||||
if(player.SteamID != c.StreamerID){
|
||||
continue;
|
||||
}
|
||||
switch (c.Action)
|
||||
{
|
||||
case "heal":{
|
||||
player.Heal(c.Amount); //Not yet in API
|
||||
player.Message($"{c.ExecuterName} has healed you for {c.Amount}");
|
||||
}
|
||||
case "kill":{
|
||||
player.Kill();
|
||||
player.Message($"{c.ExecuterName} has killed you");
|
||||
}
|
||||
case "grenade":{
|
||||
//can't get player pos right now
|
||||
player.Message($"{c.ExecuterName} has spawned a grenade on you");
|
||||
}
|
||||
case "teleport":{
|
||||
//relative teleport????
|
||||
player.Message($"{c.ExecuterName} has teleported you {c.Data}");
|
||||
}
|
||||
case "speed":{
|
||||
player.setRunningSpeedMultiplyer(c.Amount);
|
||||
player.Message($"{c.ExecuterName} has set your speed to {c.Amount}x");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue