Exemple #1
0
        private void CreateUnit(NetworkMessage netMsg)
        {
            var msg     = netMsg.ReadMessage <CreateUnitMsg>();
            var newUnit = UnitExtensions.InstantiateUnitFromMsg(msg);

            newUnit.PlayerId    = _connectionPlayerMapping[netMsg.conn.connectionId];
            newUnit.CurrentTile = GameState.AllTiles[msg.TileId];
            newUnit.UnitId      = GameState.GenerateId();
            GameState.AllTiles[msg.TileId].OccupyUnit = newUnit;
            GameState.AllUnits.Add(newUnit.UnitId, newUnit);

            var msgToBroadcast = CreateUnitMsg.CopyMessage(msg, newUnit);

            NetworkServer.SendToAll(Messages.CreateUnit, msgToBroadcast);
        }
Exemple #2
0
        //"Well gee, Tymko, that seems awfully redundant!", you might say.
        //You're totally right. I'm just lazy, and this is useful in the server CreateUnit handler.
        public static CreateUnitMsg CopyMessage(CreateUnitMsg msg, Unit unit)
        {
            var result = new CreateUnitMsg
            {
                PlayerId  = unit.PlayerId,
                TileId    = msg.TileId,
                UnitId    = unit.UnitId,
                MaxHealth = msg.MaxHealth,
                MaxMoves  = msg.MaxMoves,
                OnDeath   = msg.OnDeath,
                Sprite    = msg.Sprite,
                Abilities = msg.Abilities,
                MoveCost  = msg.MoveCost
            };

            return(result);
        }