예제 #1
0
        void OnPurchaseUnit(ClientToServerMessage message)
        {
            PurchaseUnitRequest request = message.PurchaseUnitRequest;

            if (request == null)
            {
                throw new ServerClientException("Invalid purchase request");
            }
            if (request.Unit.FactionId != PlayerState.Faction.Id)
            {
                throw new ServerClientException("Tried to purchase a unit from another faction");
            }
            Unit unit = new Unit(PlayerState, Game.GetUnitId(), request.Unit, Server);

            PlayerState.PurchaseUnit(unit);
            // Update the unit ID prior to broadcasting the purchase information
            UnitConfiguration unitConfiguration = request.Unit;

            unitConfiguration.UnitId = unit.Id;
            UnitPurchasedBroadcast unitPurchased = new UnitPurchasedBroadcast(new ReinforcementState(PlayerState), request.Unit);
            ServerToClientMessage  broadcast     = new ServerToClientMessage(unitPurchased);

            BroadcastMessage(broadcast);
        }
예제 #2
0
 public ServerToClientMessage(UnitPurchasedBroadcast unitPurchased)
 {
     Type          = ServerToClientMessageType.UnitPurchased;
     UnitPurchased = unitPurchased;
 }