Exemple #1
0
        public void Activate(IStronghold stronghold)
        {
            stronghold.BeginUpdate();
            stronghold.StrongholdState = StrongholdState.Neutral;
            regionManager.Add(stronghold);
            stronghold.EndUpdate();

            chat.SendSystemChat("STRONGHOLD_ACTIVE", stronghold.Name);
        }
Exemple #2
0
        public Error SetStrongholdTheme(IStronghold stronghold, IPlayer player, string id)
        {
            if (!HasTheme(player, id))
            {
                return(Error.ThemeNotPurchased);
            }

            stronghold.BeginUpdate();
            stronghold.Theme = id;
            stronghold.EndUpdate();

            return(Error.Ok);
        }
Exemple #3
0
        public void TransferTo(IStronghold stronghold, ITribe tribe)
        {
            if (tribe == null)
            {
                return;
            }

            ITribe oldTribe = stronghold.Tribe;

            stronghold.BeginUpdate();
            if (stronghold.StrongholdState == StrongholdState.Occupied)
            {
                stronghold.BonusDays = ((decimal)SystemClock.Now.Subtract(stronghold.DateOccupied).TotalDays + stronghold.BonusDays) * .75m;
            }

            stronghold.StrongholdState = StrongholdState.Occupied;
            stronghold.Tribe           = tribe;
            stronghold.GateOpenTo      = null;
            stronghold.GateMax         = (int)formula.StrongholdGateLimit(stronghold.Lvl);
            stronghold.Gate            = stronghold.GateMax;
            stronghold.DateOccupied    = DateTime.UtcNow;
            stronghold.EndUpdate();
            MarkIndexDirty();

            RetreatUnits(stronghold);

            if (oldTribe != null)
            {
                chat.SendSystemChat("STRONGHOLD_TAKEN_OVER", stronghold.Name, tribe.Name, oldTribe.Name);
                StrongholdGained.Raise(this, new StrongholdGainedEventArgs {
                    Tribe = tribe, OwnBy = oldTribe, Stronghold = stronghold
                });
                StrongholdLost.Raise(this, new StrongholdLostEventArgs {
                    Tribe = oldTribe, AttackedBy = tribe, Stronghold = stronghold
                });
                oldTribe.SendUpdate();
            }
            else
            {
                chat.SendSystemChat("STRONGHOLD_NEUTRAL_TAKEN_OVER", stronghold.Name, tribe.Name);
                StrongholdGained.Raise(this, new StrongholdGainedEventArgs {
                    Tribe = tribe, Stronghold = stronghold
                });
            }
        }
Exemple #4
0
        public Error UpdateGate(IStronghold stronghold)
        {
            if (stronghold.MainBattle != null || stronghold.GateBattle != null)
            {
                return(Error.StrongholdNotUpdatableInBattle);
            }

            var newMax = formula.StrongholdGateLimit(stronghold.Lvl);

            if (newMax != stronghold.GateMax)
            {
                stronghold.BeginUpdate();
                var percentHp = stronghold.Gate / stronghold.GateMax;
                stronghold.GateMax = Convert.ToInt32(newMax);
                stronghold.Gate    = stronghold.GateMax * percentHp;
                stronghold.EndUpdate();
            }

            return(Error.Ok);
        }
Exemple #5
0
        public virtual void JoinOrCreateStrongholdGateBattle(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.GateBattle != null)
            {
                combatGroup = battleProcedure.AddAttackerToBattle(targetStronghold.GateBattle, 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.GateBattle =
                    battleManagerFactory.CreateStrongholdGateBattleManager(
                        new BattleLocation(BattleLocationType.StrongholdGate,
                                           targetStronghold.ObjectId),
                        battleOwner,
                        targetStronghold);

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

                var   battlePassiveAction = actionFactory.CreateStrongholdGateBattlePassiveAction(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));
                }
                targetStronghold.BeginUpdate();
                targetStronghold.State = GameObjectStateFactory.BattleState(targetStronghold.GateBattle.BattleId);
                targetStronghold.EndUpdate();
            }

            battleId = targetStronghold.GateBattle.BattleId;
        }
Exemple #6
0
        public Error RepairGate(IStronghold stronghold)
        {
            if (stronghold.Tribe == null)
            {
                return(Error.StrongholdNotOccupied);
            }

            if (stronghold.MainBattle != null || stronghold.GateBattle != null)
            {
                return(Error.StrongholdNotRepairableInBattle);
            }

            var diff = formula.StrongholdGateLimit(stronghold.Lvl) - stronghold.Gate;

            if (diff <= 0)
            {
                return(Error.StrongholdGateFull);
            }

            var cost = formula.StrongholdGateRepairCost(diff);

            if (!stronghold.Tribe.Resource.HasEnough(cost))
            {
                return(Error.ResourceNotEnough);
            }

            stronghold.Tribe.Resource.Subtract(cost);
            dbManager.Save(stronghold.Tribe);

            stronghold.BeginUpdate();
            stronghold.Gate    = formula.StrongholdGateLimit(stronghold.Lvl);
            stronghold.GateMax = Convert.ToInt32(stronghold.Gate);
            stronghold.EndUpdate();

            return(Error.Ok);
        }