Esempio n. 1
0
 public async Task SendDead()
 {
     var rnd = new Random();
     if (IsEnd) return;
     var buffer = new byte[1];
     try
     {
         if (!MainGame.Settings.autoRespawn)
         {
             State = BotState.IsDead;
             buffer[0] = (byte)Message.m_dead;
             Console.WriteLine($"Bot {bot.Name} is dead!");
             await webSocket.SendAsync(new ArraySegment<byte>(buffer, 0, buffer.Length), WebSocketMessageType.Binary, true, CancellationToken.None);
         }
         else
         {
             var rand_number = rnd.Next(MainGame.respawnList_X.Count-1);
             bot.Energy = MainGame.Settings.EnergyStart;
             buffer[0] = (byte)Message.m_Respawn;
             BattleLogger.logger.info($"Bot {bot.Name} will respawn soon!");
             await webSocket.SendAsync(new ArraySegment<byte>(buffer, 0, buffer.Length), WebSocketMessageType.Binary, true, CancellationToken.None);
             MapXY xy = MainGame.SearchRespawnCase();
             bot.X = xy.X;
             bot.Y = xy.Y;
             State = BotState.IsRespawned;
             }
         }
     }
Esempio n. 2
0
        public async Task SendDead()
        {
            if (IsEnd)
            {
                return;
            }
            var rnd = new Random();

            var buffer = new byte[1];

            try
            {
                if (!MainGame.Settings.autoRespawn)
                {
                    State     = BotState.IsDead;
                    buffer[0] = (byte)Message.m_dead;
                    BattleLogger.logger.info($"Bot {bot.Name} is dead!");
                    await webSocket.SendAsync(new ArraySegment <byte>(buffer, 0, buffer.Length), WebSocketMessageType.Binary, true, CancellationToken.None);
                }
                else
                {
                    bot.Energy = MainGame.Settings.EnergyStart;
                    BattleLogger.logger.info($"Bot {bot.Name} will respawn soon!");
                    buffer[0] = (byte)Message.m_Respawn;
                    await webSocket.SendAsync(new ArraySegment <byte>(buffer, 0, buffer.Length), WebSocketMessageType.Binary, true, CancellationToken.None);

                    byte  oldx = bot.X;
                    byte  oldy = bot.Y;
                    MapXY xy   = MainGame.SearchRespawnCase();
                    bot.X = xy.X;
                    bot.Y = xy.Y;
                    MainGame.TheMap[oldx, oldy] = CaseState.Empty;
                    State = BotState.Ready;
                    MainGame.ViewerMovePlayer(oldx, oldy, bot.X, bot.Y);
                    MainGame.RefreshViewer();
                    SendChangeInfo();
                }
            }
            catch (Exception err)
            {
                Console.WriteLine($"[ERROR] {err.Message}");
                State = BotState.Error;
            }
            if (MainGame.TheMap[bot.X, bot.Y] == CaseState.Ennemy)
            {
                MainGame.TheMap[bot.X, bot.Y] = CaseState.Energy;
            }
            MainGame.SendCockpitInfo(bot.GUID, new ArraySegment <byte>(buffer, 0, buffer.Length));
        }