Esempio n. 1
0
 protected override void UpdateAfterSim(int tick)
 {
     if (!Ready && MyAPIGateway.Session.Player != null)
     {
         Ready = true;
         SetUpdateMethods(UpdateFlags.UPDATE_AFTER_SIM, false);
         PlayerReady?.Invoke();
     }
 }
Esempio n. 2
0
        protected override void ServerOnPlayerReady(int clientId)
        {
            Players[clientId] = Kernel.Get <BasePlayer>();
            Players[clientId].Init(clientId, false);

            SendMotd(clientId);
            SendSettings(clientId);
            PlayerReady?.Invoke(Players[clientId]);
        }
Esempio n. 3
0
 void FireReadyEvent(object sender, ToggleEventArgs e)
 {
     if (e.State == ToggleEventArgs.STATE.UP)
     {
         if (PlayerNotReady != null)
         {
             PlayerNotReady.Invoke(this, EventArgs.Empty);
         }
     }
     else
     {
         if (PlayerReady != null)
         {
             PlayerReady.Invoke(this, EventArgs.Empty);
         }
     }
 }
Esempio n. 4
0
        protected override void NetMsgReady(Chunk packet, UnPacker unPacker, int clientId)
        {
            if (!packet.Flags.HasFlag(SendFlags.Vital))
            {
                return;
            }

            if (Clients[clientId].State != ServerClientState.Connecting)
            {
                return;
            }

            Console.Print(OutputLevel.AddInfo, "server", $"player is ready. ClientId={clientId} addr={NetworkServer.ClientEndPoint(clientId)}");
            Clients[clientId].State = ServerClientState.Ready;
            PlayerReady?.Invoke(clientId);

            var msg = new MsgPacker((int)NetworkMessages.ServerConnectionReady, true);

            SendMsg(msg, MsgFlags.Vital | MsgFlags.Flush, clientId);
        }
Esempio n. 5
0
 void IInitializable.Initialize()
 {
     PlayerReady.Invoke(this);
 }
Esempio n. 6
0
        public void SetShip(long playerid, Place[] coordinates)
        {
            if (!players.ContainsKey(playerid) || players[playerid].IsReady)
            {
                throw new PlayerStatusException("User not in game or he's ready");
            }
            var field = players[playerid].Field;

            if (coordinates.Length == 0)
            {
                throw new ArgumentException("Coordinates length must be more then 1");
            }
            if (coordinates.Length != 1)
            {
                bool         isrow  = false;
                var          row    = coordinates[0].Row;
                var          column = coordinates[0].ColumnInt;
                List <Place> sorted = null;
                if (row == coordinates[1].Row)
                {
                    isrow  = true;
                    sorted = coordinates.OrderBy(c => c.Row).ToList();
                }
                else if (column == coordinates[1].ColumnInt)
                {
                    sorted = coordinates.OrderBy(c => c.ColumnInt).ToList();
                }
                else
                {
                    throw new ArgumentException("Incorrect coordinates");
                }
                for (var i = 1; i < sorted.Count; i++)
                {
                    if (sorted[i].Row != row && sorted[i].ColumnInt != column)
                    {
                        throw new ArgumentException("Incorrect coordinates");
                    }
                    if ((isrow && sorted[i].ColumnInt - sorted[i - 1].ColumnInt != 1) ||
                        (!isrow && sorted[i].Row - sorted[i - 1].Row != 1))
                    {
                        throw new ArgumentException("Incorrect coordinates");
                    }
                    if (!CanPlaceShip(field, sorted[i]))
                    {
                        throw new ArgumentException("Can't place ship here");
                    }
                }
            }
            else
            {
                if (!CanPlaceShip(field, coordinates[0]))
                {
                    throw new ArgumentException("Can't place ship here");
                }
            }
            if (coordinates.Length > 4)
            {
                throw new ArgumentException("Ship is too large");
            }
            if (players[playerid].ShipsAvailableCount[coordinates.Length] == 0)
            {
                throw new ShipNotAvailableException("This type of ship isn't available");
            }
            players[playerid].ShipsAvailableCount[coordinates.Length]--;
            foreach (var place in coordinates)
            {
                field[place.Row, place.ColumnInt] = FieldPoint.Ship;
            }
            if (players[playerid].ShipsAvailableCount.All(s => s.Value == 0))
            {
                players[playerid].IsReady = true;
                var enemyready = players[playerid].Enemy.IsReady;
                PlayerReady?.Invoke(this, new PlayerReadyEventArgs()
                {
                    IsEnemyReady = enemyready,
                    PlayerId     = playerid
                });
                if (enemyready)
                {
                    GameStarted?.Invoke(this,
                                        new GameEventArgs()
                    {
                        FirstPlayerId = players[playerid].Enemy.Id, SecondPlayerId = playerid
                    });
                }
                else
                {
                    players[playerid].IsPlayerStroke = true;
                }
            }
        }