예제 #1
0
        public void RemoveLoot(IBattleManager battleManager, int attackIndex, ICombatObject attacker, ICombatObject defender, out Resource actualLoot)
        {
            if (attackIndex != 0)
            {
                actualLoot = new Resource();
                return;
            }

            var loot = battleFormulas.GetRewardResource(attacker, defender);

            barbarianTribe.BeginUpdate();
            barbarianTribe.Resource.Subtract(loot, out actualLoot);
            barbarianTribe.EndUpdate();
        }
예제 #2
0
        private bool Remove(IBarbarianTribe barbarianTribe)
        {
            if (barbarianTribe.Battle != null || barbarianTribe.Worker.PassiveActions.Any() || barbarianTribe.Worker.ActiveActions.Any())
            {
                return(false);
            }

            IBarbarianTribe obj;

            if (!barbarianTribes.TryRemove(barbarianTribe.ObjectId, out obj))
            {
                return(false);
            }

            barbarianTribe.CampRemainsChanged -= BarbarianTribeOnCampRemainsChanged;

            if (barbarianTribe.InWorld)
            {
                barbarianTribe.BeginUpdate();
                regionManager.Remove(barbarianTribe);
                barbarianTribe.EndUpdate();
            }

            dbManager.Delete(barbarianTribe);

            return(true);
        }
예제 #3
0
        private void Add(IBarbarianTribe barbarianTribe)
        {
            barbarianTribes.AddOrUpdate(barbarianTribe.ObjectId, barbarianTribe, (id, old) => barbarianTribe);

            barbarianTribe.BeginUpdate();
            regionManager.Add(barbarianTribe);
            barbarianTribe.EndUpdate();

            barbarianTribe.CampRemainsChanged += BarbarianTribeOnCampRemainsChanged;
        }
예제 #4
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;
        }