예제 #1
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);
        }
예제 #2
0
        public BarbarianTribeCombatUnit[] CreateBarbarianTribeCombatUnit(IBattleManager battleManager,
                                                                         IBarbarianTribe barbarianTribe,
                                                                         ushort type,
                                                                         byte level,
                                                                         ushort count)
        {
            var groupSize = kernel.Get <UnitFactory>().GetUnitStats(type, level).Battle.GroupSize;
            var units     = new BarbarianTribeCombatUnit[(count - 1) / groupSize + 1];
            int i         = 0;

            do
            {
                ushort size = (groupSize > count ? count : groupSize);

                var newUnit = CreateBarbarianTribeCombatUnit(battleManager.GetNextCombatObjectId(),
                                                             battleManager.BattleId,
                                                             type,
                                                             level,
                                                             size,
                                                             barbarianTribe);

                units[i++] = newUnit;
                count     -= size;
            }while (count > 0);
            return(units);
        }
예제 #3
0
        public bool CreateBarbarianTribeNear(byte level, int campCount, uint x, uint y, byte radius)
        {
            Position barbarianCampPosition;

            int tries = 0;

            do
            {
                tileLocator.RandomPoint(new Position(x, y), radius, true, out barbarianCampPosition);

                if (barbarianTribeConfigurator.IsLocationAvailable(barbarianCampPosition))
                {
                    break;
                }

                if (tries++ > 150)
                {
                    return(false);
                }

                if (tries > 0 && radius == 0)
                {
                    return(false);
                }
            }while (true);

            IBarbarianTribe barbarianTribe = barbarianTribeFactory.CreateBarbarianTribe(idGenerator.GetNext(), level, barbarianCampPosition, campCount);

            if (barbarianTribe != null)
            {
                Add(barbarianTribe);
            }

            return(true);
        }
예제 #4
0
        private void SetLootedResources(IBarbarianTribe barbarianTribe, IBattleManager battle, ITroopObject troopObject, ICombatGroup combatGroup)
        {
            if (!battle.BattleStarted)
            {
                return;
            }

            // Calculate bonus
            Resource resource = battleFormula.GetBonusResources(troopObject,
                                                                originalUnitCount,
                                                                troopObject.Stub.TotalCount);

            // Add barbarian tribe bonus
            resource.Add(formula.BarbarianTribeBonus(barbarianTribe.Lvl, battle, combatGroup, barbarianTribe));

            // Copy looted resources since we'll be modifying the troop's loot variable
            var looted = new Resource(troopObject.Stats.Loot);

            // Add bonus to troop object
            Resource returning;
            Resource actual;
            Resource cap = new Resource(troopObject.Stub.Carry / 1,
                                        troopObject.Stub.Carry / 2,
                                        troopObject.Stub.Carry / Config.battle_loot_resource_iron_ratio,
                                        troopObject.Stub.Carry / 1,
                                        troopObject.Stub.Carry / Config.battle_loot_resource_labor_ratio);

            troopObject.Stats.Loot.Add(resource, cap, out actual, out returning);

            // Update battle report view with actual received bonus
            battle.BattleReport.SetLootedResources(combatGroup.Owner, combatGroup.Id, battle.BattleId, looted, actual);
        }
예제 #5
0
        public void DbLoaderAdd(IBarbarianTribe barbarianTribe)
        {
            idGenerator.Set(barbarianTribe.ObjectId);

            barbarianTribes.AddOrUpdate(barbarianTribe.ObjectId, barbarianTribe, (id, old) => barbarianTribe);
            regionManager.DbLoaderAdd(barbarianTribe);
            barbarianTribe.CampRemainsChanged += BarbarianTribeOnCampRemainsChanged;
        }
예제 #6
0
        private void Add(IBarbarianTribe barbarianTribe)
        {
            barbarianTribes.AddOrUpdate(barbarianTribe.ObjectId, barbarianTribe, (id, old) => barbarianTribe);

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

            barbarianTribe.CampRemainsChanged += BarbarianTribeOnCampRemainsChanged;
        }
예제 #7
0
        public void Add(params object[] objects)
        {
            foreach (var o in objects)
            {
                ICity city = o as ICity;
                if (city != null)
                {
                    cities.Add(city.Id, city);
                }

                IPlayer player = o as IPlayer;
                if (player != null)
                {
                    players.Add(player.PlayerId, player);
                }

                ITribe tribe = o as ITribe;
                if (tribe != null)
                {
                    tribes.Add(tribe.Id, tribe);
                }

                IBattleManager battle = o as IBattleManager;
                if (battle != null)
                {
                    battles.Add(battle.BattleId, battle);
                }

                IStronghold stronghold = o as IStronghold;
                if (stronghold != null)
                {
                    strongholds.Add(stronghold.ObjectId, stronghold);
                }

                IBarbarianTribe barbarianTribe = o as IBarbarianTribe;
                if (barbarianTribe != null)
                {
                    barbarianTribes.Add(barbarianTribe.ObjectId, barbarianTribe);
                }

                IGameObject gameObject = o as IGameObject;
                if (gameObject != null)
                {
                    gameObjects.Add(new Tuple <uint, uint>(gameObject.GroupId, gameObject.ObjectId), gameObject);
                }
            }
        }
예제 #8
0
        public virtual Resource BarbarianTribeResources(IBarbarianTribe barbarianTribe)
        {
            int seed;

            unchecked
            {
                seed = (int)(barbarianTribe.ObjectId +
                             barbarianTribe.PrimaryPosition.X +
                             barbarianTribe.PrimaryPosition.Y +
                             2 ^ barbarianTribe.CampRemains);
            }

            var rand = new Random(seed);

            barbarianTribeCropCalculator = barbarianTribeCropCalculator ??
                                           new SlotMachineCalculator(new[] { 92, 208, 461, 864, 1423, 2142, 3027, 4081, 5308, 6709 },
                                                                     new[] { 138, 311, 692, 1296, 2134, 3213, 4540, 6122, 7961, 10064 },
                                                                     new[] { 1.0, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
                                                                     new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 });

            barbarianTribeWoodCalculator = barbarianTribeWoodCalculator ??
                                           new SlotMachineCalculator(new[] { 92, 208, 461, 864, 1423, 2142, 3027, 4081, 5308, 6709 },
                                                                     new[] { 138, 311, 692, 1296, 2134, 3213, 4540, 6122, 7961, 10064 },
                                                                     new[] { 1.0, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
                                                                     new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 });

            barbarianTribeGoldCalculator = barbarianTribeGoldCalculator ??
                                           new SlotMachineCalculator(new[] { 1, 1, 1, 207, 279, 314, 264, 498, 578, 531 },
                                                                     new[] { 50, 75, 100, 257, 379, 464, 464, 748, 888, 921 },
                                                                     new[] { 0.01, 0.05, 0.1, 0.25, 0.35, 0.45, 0.55, 0.65, 0.75, 0.95 },
                                                                     new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 });

            barbarianTribeIronCalculator = barbarianTribeIronCalculator ??
                                           new SlotMachineCalculator(new[] { 1, 1, 1, 1, 1, 18, 16, 27, 40, 65 },
                                                                     new[] { 20, 30, 50, 50, 50, 28, 32, 57, 80, 135 },
                                                                     new[] { 0.0001, 0.001, 0.01, 0.05, 0.1, 0.3, 0.5, 0.6, 0.75, 0.9 },
                                                                     new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 });

            return(new Resource(barbarianTribeCropCalculator.Roll(barbarianTribe.Lvl, rand),
                                barbarianTribeGoldCalculator.Roll(barbarianTribe.Lvl, rand),
                                barbarianTribeIronCalculator.Roll(barbarianTribe.Lvl, rand),
                                barbarianTribeWoodCalculator.Roll(barbarianTribe.Lvl, rand)));
        }
예제 #9
0
        public BarbarianTribeCombatUnit CreateBarbarianTribeCombatUnit(uint id,
                                                                       uint battleId,
                                                                       ushort type,
                                                                       byte level,
                                                                       ushort count,
                                                                       IBarbarianTribe barbarianTribe)
        {
            var unitFactory = kernel.Get <UnitFactory>();

            return(new BarbarianTribeCombatUnit(id,
                                                battleId,
                                                type,
                                                level,
                                                count,
                                                unitFactory.GetUnitStats(type, level),
                                                barbarianTribe,
                                                kernel.Get <IBattleFormulas>(),
                                                kernel.Get <Formula>(),
                                                kernel.Get <IDbManager>()));
        }
예제 #10
0
        public BarbarianTribeCombatUnit(uint id,
                                        uint battleId,
                                        ushort type,
                                        byte lvl,
                                        ushort count,
                                        IBaseUnitStats unitBaseStats,
                                        IBarbarianTribe barbarianTribe,
                                        IBattleFormulas battleFormulas,
                                        Formula formula,
                                        IDbManager dbManager)
            : base(id, battleId, battleFormulas, dbManager)
        {
            BarbarianTribe = barbarianTribe;
            this.type      = type;
            this.count     = count;
            this.lvl       = lvl;
            this.formula   = formula;

            baseStats   = unitBaseStats;
            battleStats = new BattleStats(unitBaseStats.Battle);

            LeftOverHp = baseStats.Battle.MaxHp;
        }
예제 #11
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;
        }
예제 #12
0
        public IBattleManager CreateBarbarianBattleManager(uint battleId,
                                                           BattleLocation battleLocation,
                                                           BattleOwner battleOwner,
                                                           IBarbarianTribe barbarianTribe)
        {
            var battleRandom = new BattleRandom(battleId);

            var bm = new PublicBattleManager(battleId,
                                             battleLocation,
                                             battleOwner,
                                             kernel.Get <IRewardStrategyFactory>().CreateBarbarianTribeRewardStrategy(barbarianTribe),
                                             kernel.Get <IDbManager>(),
                                             kernel.Get <IBattleReport>(),
                                             kernel.Get <ICombatListFactory>(),
                                             kernel.Get <IBattleFormulas>(),
                                             new BattleOrder(battleRandom),
                                             battleRandom);

            // ReSharper disable once ObjectCreationAsStatement
            new BattleChannel(bm, kernel.Get <IChannel>());

            bm.BattleReport.Battle = bm;
            return(bm);
        }
예제 #13
0
        public virtual ICombatGroup AddBarbarianTribeUnitsToBattle(IBattleManager battle, IBarbarianTribe barbarianTribe, IEnumerable <Unit> units)
        {
            var barbarianCombatGroup = combatGroupFactory.CreateBarbarianTribeCombatGroup(battle.BattleId, battle.GetNextGroupId(), barbarianTribe);

            foreach (var unit in units)
            {
                var combatUnits = combatUnitFactory.CreateBarbarianTribeCombatUnit(battle,
                                                                                   barbarianTribe,
                                                                                   unit.Type,
                                                                                   (byte)Math.Max(1, barbarianTribe.Lvl / 2),
                                                                                   unit.Count);
                foreach (var obj in combatUnits)
                {
                    barbarianCombatGroup.Add(obj);
                }
            }

            battle.Add(barbarianCombatGroup, BattleManager.BattleSide.Defense, false);

            return(barbarianCombatGroup);
        }
예제 #14
0
 public BarbarianTribeCombatGroup(uint battleId, uint id, IBarbarianTribe barbarianTribe, IDbManager dbManager)
     : base(battleId, id, dbManager)
 {
     this.barbarianTribe = barbarianTribe;
     owner = new BattleOwner(BattleOwnerType.BarbarianTribe, barbarianTribe.ObjectId);
 }
예제 #15
0
        public IBattleManager CreateBarbarianBattleManager(BattleLocation battleLocation, BattleOwner battleOwner, IBarbarianTribe barbarianTribe)
        {
            var battleId = BattleReport.BattleIdGenerator.GetNext();

            return(CreateBarbarianBattleManager(battleId, battleLocation, battleOwner, barbarianTribe));
        }
예제 #16
0
 private void DeregisterBattleListeners(IBarbarianTribe barbarianTribe)
 {
     barbarianTribe.Battle.GroupKilled      -= BattleGroupKilled;
     barbarianTribe.Battle.WithdrawAttacker -= BattleWithdrawAttacker;
 }
예제 #17
0
 public BarbarianTribeCombatGroup CreateBarbarianTribeCombatGroup(uint battleId, uint id, IBarbarianTribe barbarianTribe)
 {
     return(new BarbarianTribeCombatGroup(battleId, id, barbarianTribe, kernel.Get <IDbManager>()));
 }
예제 #18
0
 public bool TryGetBarbarianTribe(uint id, out IBarbarianTribe barbarianTribe)
 {
     return(barbarianTribes.TryGetValue(id, out barbarianTribe));
 }
예제 #19
0
 public bool TryGetObjects(uint barbarianTribeId, out IBarbarianTribe barbarianTribe)
 {
     return(barbarianTribeManager.TryGetBarbarianTribe(barbarianTribeId, out barbarianTribe));
 }
예제 #20
0
 public bool RelocateBarbarianTribe(IBarbarianTribe barbarianTribe)
 {
     return(multiObjectLockFactory().Lock(new ILockable[] { barbarianTribe })
            .Do(() => Remove(barbarianTribe)));
 }
예제 #21
0
 public bool TryGetObjects(uint barbarianTribeId, out IBarbarianTribe barbarianTribe)
 {
     return(barbarianTribes.TryGetValue(barbarianTribeId, out barbarianTribe));
 }
예제 #22
0
 public BarbarianTribeRewardStrategy(IBarbarianTribe barbarianTribe, IBattleFormulas battleFormulas)
 {
     this.barbarianTribe = barbarianTribe;
     this.battleFormulas = battleFormulas;
 }
예제 #23
0
        public virtual Resource BarbarianTribeBonus(byte level, IBattleManager battle, ICombatGroup combatGroup, IBarbarianTribe barbarianTribe)
        {
            var bonusAmt = new[] { 15, 34, 75, 141, 232, 349, 493, 665, 865, 1094 };

            // Get nothing if they didnt defeat the camp
            if (battle.Defenders.UpkeepExcludingWaitingToJoinBattle > 0)
            {
                return(new Resource());
            }

            decimal total =
                battle.Attackers.AllCombatObjects()
                .Sum(combatObj => combatObj.Upkeep * combatObj.RoundsParticipated * combatObj.RoundsParticipated);

            decimal myTotal = combatGroup.Sum(combatObj => combatObj.Upkeep * combatObj.RoundsParticipated * combatObj.RoundsParticipated);

            if (total == 0 || myTotal == 0)
            {
                return(new Resource());
            }

            var myPercentage = myTotal / total;

            var bonus = new Resource(wood: bonusAmt[level - 1], crop: bonusAmt[level - 1]) * (double)myPercentage;

            // Add remaining barb resources as well
            bonus.Add(barbarianTribe.Resource * (double)myPercentage);

            return(bonus);
        }
예제 #24
0
 public virtual short GetStamina(ITroopStub stub, IBarbarianTribe barbarianTribe)
 {
     return((short)Config.battle_stamina_initial);
 }
예제 #25
0
 public BarbarianTribeRewardStrategy CreateBarbarianTribeRewardStrategy(IBarbarianTribe barbarianTribe)
 {
     return(new BarbarianTribeRewardStrategy(barbarianTribe, kernel.Get <IBattleFormulas>()));
 }