Beispiel #1
0
        public virtual void JoinOrCreateCityBattle(ICity targetCity,
                                                   ITroopObject attackerTroopObject,
                                                   IDbManager dbManager,
                                                   out ICombatGroup combatGroup,
                                                   out uint battleId)
        {
            // If battle already exists, then we just join it in also bringing any new units
            if (targetCity.Battle != null)
            {
                AddLocalUnitsToBattle(targetCity.Battle, targetCity);
                AddLocalStructuresToBattle(targetCity.Battle, targetCity, attackerTroopObject);
                combatGroup = battleProcedure.AddAttackerToBattle(targetCity.Battle, attackerTroopObject);
            }
            // Otherwise, the battle has to be created
            else
            {
                targetCity.Battle = battleManagerFactory.CreateBattleManager(new BattleLocation(BattleLocationType.City, targetCity.Id),
                                                                             new BattleOwner(BattleOwnerType.City, targetCity.Id),
                                                                             targetCity);

                var battlePassiveAction = actionFactory.CreateCityBattlePassiveAction(targetCity.Id);

                AddLocalStructuresToBattle(targetCity.Battle, targetCity, attackerTroopObject);
                combatGroup = battleProcedure.AddAttackerToBattle(targetCity.Battle, attackerTroopObject);

                Error result = targetCity.Worker.DoPassive(targetCity, battlePassiveAction, false);
                if (result != Error.Ok)
                {
                    throw new Exception(string.Format("Failed to start a battle due to error {0}", result));
                }

                // send message to player telling them to build tower and basement
                if (targetCity.Owner.NeverAttacked)
                {
                    const string warnMessage =
                        @"Now that you are out of newbie protection, other players are able to attack you. Someone has just finished attacking your town and has probably taken some resources from you. You can see how strong the attack was and how much resources they took in the battle report that was generated for this battle. 
You have several things you can do to help protect your city from attacks. The first is to build a basement which can be done from your lumbermill. Basements will protect up to a certain amount of resources from being looted. If you plan on going offline for a while, your basements can also build temporary basements which will extend the amount of protected resources. 
Another option is increase your city's defenses. The best way to do this early in the game is to build some towers. Towers are built from the training ground or barrack and provide defense for structures within its radius. Any units in your city will also join the battle but be careful since an attacker may kill your entire army in a battle. You can hide your units if you don't want them to defend your town when you get attacked.
Good luck and feel free to ask for help in the chat if you have any questions.";

                    targetCity.Owner.SendSystemMessage(null, "Your city has been attacked", warnMessage);
                    targetCity.Owner.NeverAttacked = false;
                    dbManager.Save(targetCity.Owner);
                }
            }

            battleId = targetCity.Battle.BattleId;
        }
Beispiel #2
0
        public virtual void JoinOrCreateStrongholdMainBattle(IStronghold targetStronghold,
                                                             ITroopObject attackerTroopObject,
                                                             out ICombatGroup combatGroup,
                                                             out uint battleId)
        {
            // If battle already exists, then we just join it in also bringing any new units
            if (targetStronghold.MainBattle != null)
            {
                combatGroup = battleProcedure.AddAttackerToBattle(targetStronghold.MainBattle, attackerTroopObject);
            }
            // Otherwise, the battle has to be created
            else
            {
                var battleOwner = targetStronghold.Tribe == null
                                          ? new BattleOwner(BattleOwnerType.Stronghold, targetStronghold.ObjectId)
                                          : new BattleOwner(BattleOwnerType.Tribe, targetStronghold.Tribe.Id);

                targetStronghold.MainBattle =
                    battleManagerFactory.CreateStrongholdMainBattleManager(
                        new BattleLocation(BattleLocationType.Stronghold, targetStronghold.ObjectId),
                        battleOwner,
                        targetStronghold);

                targetStronghold.MainBattle.SetProperty("defense_stronghold_meter", formula.StrongholdMainBattleMeter(targetStronghold.Lvl));
                targetStronghold.MainBattle.SetProperty("offense_stronghold_meter", formula.StrongholdMainBattleMeter(targetStronghold.Lvl));

                combatGroup = battleProcedure.AddAttackerToBattle(targetStronghold.MainBattle, attackerTroopObject);

                var   battlePassiveAction = actionFactory.CreateStrongholdMainBattlePassiveAction(targetStronghold.ObjectId);
                Error result = targetStronghold.Worker.DoPassive(targetStronghold, battlePassiveAction, false);
                if (result != Error.Ok)
                {
                    throw new Exception(string.Format("Failed to start a battle due to error {0}", result));
                }
            }

            battleId = targetStronghold.MainBattle.BattleId;
        }
Beispiel #3
0
        public virtual void JoinOrCreateBarbarianTribeBattle(IBarbarianTribe barbarianTribe,
                                                             ITroopObject attackerTroopObject,
                                                             out ICombatGroup combatGroup,
                                                             out uint battleId)
        {
            // If battle already exists, then we just join it in also bringing any new units
            if (barbarianTribe.Battle != null)
            {
                combatGroup = battleProcedure.AddAttackerToBattle(barbarianTribe.Battle, attackerTroopObject);
            }
            // Otherwise, the battle has to be created
            else
            {
                var battleOwner = new BattleOwner(BattleOwnerType.BarbarianTribe, barbarianTribe.ObjectId);

                barbarianTribe.Battle =
                    battleManagerFactory.CreateBarbarianBattleManager(new BattleLocation(BattleLocationType.BarbarianTribe, barbarianTribe.ObjectId),
                                                                      battleOwner,
                                                                      barbarianTribe);

                combatGroup = battleProcedure.AddAttackerToBattle(barbarianTribe.Battle, attackerTroopObject);

                var   battlePassiveAction = actionFactory.CreateBarbarianTribeBattlePassiveAction(barbarianTribe.ObjectId);
                Error result = barbarianTribe.Worker.DoPassive(barbarianTribe, battlePassiveAction, false);
                if (result != Error.Ok)
                {
                    throw new Exception(string.Format("Failed to start a battle due to error {0}", result));
                }

                barbarianTribe.BeginUpdate();
                barbarianTribe.LastAttacked = DateTime.UtcNow;
                barbarianTribe.State        = GameObjectStateFactory.BattleState(barbarianTribe.Battle.BattleId);
                barbarianTribe.EndUpdate();
            }

            battleId = barbarianTribe.Battle.BattleId;
        }