Beispiel #1
0
        void OnAttackUnit(ClientToServerMessage message)
        {
            AttackUnitRequest request = message.AttackUnitRequest;

            if (request == null)
            {
                throw new ServerClientException("Invalid attack unit request");
            }
            Unit attacker = PlayerState.GetUnit(request.AttackerUnitId);

            if (attacker == null)
            {
                throw new ServerClientException("Encountered an invalid attacking unit ID in an attack request");
            }
            Unit defender = Opponent.PlayerState.GetUnit(request.DefenderUnitId);

            if (defender == null)
            {
                throw new ServerClientException("Encountered an invalid target unit ID in an attack request");
            }
            PlayerState.AttackUnit(attacker, defender);
            UnitCasualties        attackerCasualties = new UnitCasualties(attacker.Id, attacker.Strength);
            UnitCasualties        defenderCasualties = new UnitCasualties(defender.Id, defender.Strength);
            UnitCombatBroadcast   casualties         = new UnitCombatBroadcast(attackerCasualties, defenderCasualties);
            ServerToClientMessage broadcast          = new ServerToClientMessage(casualties);

            BroadcastMessage(broadcast);
            AnnihilationCheck();
        }
Beispiel #2
0
 public ServerToClientMessage(UnitCombatBroadcast attack)
 {
     Type       = ServerToClientMessageType.UnitAttack;
     UnitAttack = attack;
 }