Ejemplo n.º 1
0
        private void AttackBarbarianTribe(Session session, Packet packet)
        {
            uint        cityId;
            uint        targetBarbarianTribeId;
            ISimpleStub simpleStub;
            AttackMode  mode;

            try
            {
                mode   = (AttackMode)packet.GetByte();
                cityId = packet.GetUInt32();
                targetBarbarianTribeId = packet.GetUInt32();
                simpleStub             = PacketHelper.ReadStub(packet, FormationType.Attack);
            }
            catch (Exception)
            {
                ReplyError(session, packet, Error.Unexpected);
                return;
            }

            IBarbarianTribe barbarianTribe;

            if (!gameObjectLocator.TryGetObjects(targetBarbarianTribeId, out barbarianTribe))
            {
                ReplyError(session, packet, Error.Unexpected);
                return;
            }

            locker.Lock(session.Player, barbarianTribe).Do(() =>
            {
                var city = session.Player.GetCity(cityId);
                if (city == null)
                {
                    ReplyError(session, packet, Error.Unexpected);
                    return;
                }

                var troopObjectInitializer = troopObjectInitializerFactory.CreateCityTroopObjectInitializer(cityId, simpleStub, TroopBattleGroup.Attack, mode);

                var attackAction = actionFactory.CreateBarbarianTribeAttackChainAction(cityId, targetBarbarianTribeId, troopObjectInitializer);

                var result = city.Worker.DoPassive(city, attackAction, true);

                ReplyWithResult(session, packet, result);
            });
        }