예제 #1
0
        public Unit(PlayerState owner, int id, UnitConfiguration configuration, Server server)
        {
            Owner = owner;
            Id = id;
            Faction = server.GetFaction(configuration.FactionId);
            Type = Faction.GetUnitType(configuration.UnitTypeId);
            Upgrades = new List<UnitUpgrade>();
            _Points = Type.Points;
            UpgradeSlotsOccupied = new HashSet<int>();
            foreach (var upgradeId in configuration.UpgradeIds)
                AddUpgrade(GetUpgrade(upgradeId));

            Hex = null;
            Strength = GameConstants.FullUnitStrength;

            Entrenched = false;

            AttritionDuration = 0;

            UpdateStats();
            ResetUnitForNewTurn();

            // Only air units are automatically "deployed" since they don't need to be placed on the map
            Deployed = Stats.Flags.Contains(UnitFlag.Air);
        }
예제 #2
0
        public ServerClient(Stream stream, Server server)
        {
            Stream = stream;
            Server = server;

            SendEvent = new ManualResetEvent(false);
            SendQueue = new List<ServerToClientMessage>();

            ShuttingDown = false;

            MessageHandlerMap = new Dictionary<ClientToServerMessageType, MessageHandler>();

            InitialiseMessageHandlerMap();

            _Name = null;

            _PlayerState = null;
            ConnectedState();
        }
예제 #3
0
 void OnJoinGameRequest(ClientToServerMessage message)
 {
     JoinGameRequest request = message.JoinGameRequest;
     if (request == null)
         throw new ServerClientException("Invalid join game request");
     // Defaults to false so lazy/afk players lose the first turn privilege
     _RequestedFirstTurn = false;
     InitialiseArmy(request.Army);
     Faction faction = Server.GetFaction(request.Army.FactionId);
     bool success = Server.OnJoinGameRequest(this, request, out _Game);
     if (success)
     {
         _PlayerState = new PanzerKontrol.PlayerState(Game, faction, PlayerIdentifier.Player2);
         InGameState(PlayerStateType.DeployingUnits, ClientToServerMessageType.InitialDeployment);
     }
     else
     {
         ServerToClientMessage reply = new ServerToClientMessage(ServerToClientMessageType.NoSuchGame);
         QueueMessage(reply);
     }
     Game.OnOpponentFound(this);
 }
예제 #4
0
 void OnCreateGameRequest(ClientToServerMessage message)
 {
     CreateGameRequest request = message.CreateGameRequest;
     if (request == null)
         throw new ServerClientException("Invalid game creation request");
     // Defaults to false so lazy/afk players lose the first turn privilege
     _RequestedFirstTurn = false;
     InitialiseArmy(request.Army);
     Faction faction = Server.GetFaction(request.Army.FactionId);
     CreateGameReply reply = Server.OnCreateGameRequest(this, request, out _Game);
     QueueMessage(new ServerToClientMessage(reply));
     _PlayerState = new PanzerKontrol.PlayerState(Game, faction, PlayerIdentifier.Player1);
     WaitingForOpponentState();
 }
예제 #5
0
        void LoggedInState()
        {
            _State = ClientState.LoggedIn;
            SetExpectedMessageTypes(ClientToServerMessageType.CreateGameRequest, ClientToServerMessageType.ViewPublicGamesRequest, ClientToServerMessageType.JoinGameRequest);

            _PlayerState = null;
        }