Пример #1
0
        private void MainBattleOnAboutToExitBattle(IBattleManager battle, ICombatList attackers, ICombatList defenders)
        {
            IStronghold stronghold;

            if (!gameObjectLocator.TryGetObjects(strongholdId, out stronghold))
            {
                throw new Exception("Stronghold not found");
            }

            var defensiveMeter = battle.GetProperty <decimal>("defense_stronghold_meter");
            // Transfer stronghold if
            // - defensive meter is 0
            // - occupied state and there is no one left defending it
            // - neutral state and the attacker killed the main group

            var hasDefendingUnitsLeft = stronghold.Troops.StationedHere().Any(p => p.TotalCount > 0);

            if (defensiveMeter <= 0 ||
                (stronghold.StrongholdState == StrongholdState.Occupied && !hasDefendingUnitsLeft) ||
                (stronghold.StrongholdState == StrongholdState.Neutral && npcGroupKilled))
            {
                strongholdManager.TransferTo(stronghold, stronghold.GateOpenTo);
            }
            else
            {
                strongholdManager.TribeFailedToTakeStronghold(stronghold, stronghold.GateOpenTo);
            }
        }
Пример #2
0
        private string CmdStrongholdTransfer(Session session, string[] parms)
        {
            bool   help           = false;
            string strongholdName = string.Empty;
            string tribeName      = string.Empty;

            try
            {
                var p = new OptionSet
                {
                    { "?|help|h", v => help = true },
                    { "stronghold=", v => strongholdName = v.TrimMatchingQuotes() },
                    { "tribe=", v => tribeName = v.TrimMatchingQuotes() },
                };
                p.Parse(parms);
            }
            catch (Exception)
            {
                help = true;
            }

            if (help || string.IsNullOrEmpty(strongholdName) || string.IsNullOrEmpty(tribeName))
            {
                return("StrongholdTransfer --stronghold=stronghold_name --tribe=tribe_name");
            }

            uint tribeId;

            if (!tribeManager.FindTribeId(tribeName, out tribeId))
            {
                return("Tribe not found");
            }

            ITribe tribe;

            if (!world.TryGetObjects(tribeId, out tribe))
            {
                return("Tribe not found");
            }

            IStronghold stronghold;

            if (!strongholdManager.TryGetStronghold(strongholdName, out stronghold))
            {
                return("Stronghold not found");
            }

            locker.Lock(custom => stronghold.LockList().ToArray(), null, tribe, stronghold)
            .Do(() => strongholdManager.TransferTo(stronghold, tribe));

            return("OK!");
        }