Esempio n. 1
0
 public StrongholdCommandsModule(IStrongholdManager strongholdManager, IWorld world, ILocker locker, IThemeManager themeManager)
 {
     this.strongholdManager = strongholdManager;
     this.world             = world;
     this.locker            = locker;
     this.themeManager      = themeManager;
 }
Esempio n. 2
0
        public void Callback_WhenNoStrongholdsAreInactive_ShouldNotThrowExceptionAndShouldUpdateNeutralCheckTime(
            [Frozen] ISystemVariableManager systemVariableManager,
            [Frozen] IStrongholdManager strongholdManager,
            [Frozen] IDbManager dbManager,
            IStronghold sh1,
            IStronghold sh2,
            IFixture fixture)
        {
            sh1.StrongholdState.Returns(StrongholdState.Occupied);
            sh2.StrongholdState.Returns(StrongholdState.Occupied);

            var lastCheckTime = Substitute.For <SystemVariable>();

            lastCheckTime.Value.Returns(SystemClock.Now.AddHours(-8));
            systemVariableManager["Stronghold.neutral_check"].Returns(lastCheckTime);

            var locker = new LockerStub();

            fixture.Register <ILocker>(() => locker);

            strongholdManager.GetEnumerator().Returns(_ => new List <IStronghold> {
                sh1, sh2
            }.GetEnumerator());

            var checker = fixture.Create <StrongholdActivationChecker>();

            checker.Invoking(c => c.Callback(null)).ShouldNotThrow();

            lastCheckTime.Received().Value = SystemClock.Now;
            dbManager.Received(1).Save(lastCheckTime);
        }
Esempio n. 3
0
        public void Callback_WhenHasNeutralStronghold_ShouldNotActivateAStronghold(
            [Frozen] ISystemVariableManager systemVariableManager,
            [Frozen] IStrongholdActivationCondition activationCondition,
            [Frozen] IStrongholdManager strongholdManager,
            IStronghold sh1,
            IStronghold sh2,
            IFixture fixture)
        {
            sh1.StrongholdState.Returns(StrongholdState.Inactive);
            sh2.StrongholdState.Returns(StrongholdState.Neutral);

            var lastCheckTime = Substitute.For <SystemVariable>();

            lastCheckTime.Value.Returns(SystemClock.Now.AddHours(-8));
            systemVariableManager["Stronghold.neutral_check"].Returns(lastCheckTime);

            var locker = new LockerStub();

            fixture.Register <ILocker>(() => locker);

            strongholdManager.GetEnumerator().Returns(_ => new List <IStronghold> {
                sh1, sh2
            }.GetEnumerator());

            var checker = fixture.Create <StrongholdActivationChecker>();

            checker.Callback(null);

            strongholdManager.DidNotReceive().Activate(sh2);
            strongholdManager.DidNotReceive().Activate(sh1);
        }
Esempio n. 4
0
 public StrongholdChecker(IStrongholdManager strongholdManager, IDbManager dbManager, IScheduler scheduler, ILocker locker)
 {
     this.strongholdManager = strongholdManager;
     this.dbManager         = dbManager;
     this.scheduler         = scheduler;
     this.locker            = locker;
 }
Esempio n. 5
0
 public Tribe(IPlayer owner,
              string name,
              Procedure procedure,
              IDbManager dbManager,
              Formula formula,
              IAssignmentFactory assignmentFactory,
              ICityManager cityManager,
              IStrongholdManager strongholdManager,
              ITileLocator tileLocator,
              IChannel channel)
     : this(
         owner : owner,
         name : name,
         desc : string.Empty,
         level : 1,
         victoryPoints : 0,
         attackPoints : 0,
         defensePoints : 0,
         resource : new Resource(),
         created : SystemClock.Now,
         procedure : procedure,
         dbManager : dbManager,
         formula : formula,
         assignmentFactory : assignmentFactory,
         cityManager : cityManager,
         strongholdManager : strongholdManager,
         tileLocator : tileLocator,
         channel : channel)
 {
 }
Esempio n. 6
0
        public SystemVariablesUpdater(IWorld world,
                                      ITribeManager tribeManager,
                                      IDbManager dbManager,
                                      IScheduler scheduler,
                                      IStrongholdManager strongholdManager,
                                      IForestManager forestManager,
                                      ISystemVariableManager systemVariableManager,
                                      INetworkServer networkServer,
                                      IChannel channel,
                                      BlockingBufferManager bufferManager,
                                      SocketAwaitablePool socketAwaitablePool)
        {
            this.world                 = world;
            this.tribeManager          = tribeManager;
            this.dbManager             = dbManager;
            this.scheduler             = scheduler;
            this.strongholdManager     = strongholdManager;
            this.forestManager         = forestManager;
            this.systemVariableManager = systemVariableManager;
            this.networkServer         = networkServer;
            this.channel               = channel;
            this.bufferManager         = bufferManager;
            this.socketAwaitablePool   = socketAwaitablePool;

            if (!string.IsNullOrEmpty(Config.api_id))
            {
                graphiteKeyPrefix = string.Format("servers.{0}_tribalhero_com.tribalhero.", Config.api_id);
            }
        }
Esempio n. 7
0
 public TribeCommandsModule(IStrongholdManager strongholdManager,
                            IWorld world,
                            ITribeManager tribeManager,
                            ILocker locker)
 {
     this.strongholdManager = strongholdManager;
     this.world             = world;
     this.tribeManager      = tribeManager;
     this.locker            = locker;
 }
Esempio n. 8
0
 public AssignmentCommandsModule(BattleProcedure battleProcedure,
                                 IGameObjectLocator gameObjectLocator,
                                 ILocker locker,
                                 IStrongholdManager strongholdManager,
                                 ICityManager cityManager)
 {
     this.battleProcedure   = battleProcedure;
     this.gameObjectLocator = gameObjectLocator;
     this.locker            = locker;
     this.strongholdManager = strongholdManager;
     this.cityManager       = cityManager;
 }
Esempio n. 9
0
 public TribeManager(IDbManager dbManager,
                     IStrongholdManager strongholdManager,
                     IActionFactory actionFactory,
                     ITribeFactory tribeFactory,
                     ITribeLogger tribeLogger, ITroopObjectInitializerFactory troopInitializerFactory)
 {
     Tribes                       = new ConcurrentDictionary <uint, ITribe>();
     this.dbManager               = dbManager;
     this.strongholdManager       = strongholdManager;
     this.actionFactory           = actionFactory;
     this.tribeFactory            = tribeFactory;
     this.tribeLogger             = tribeLogger;
     this.troopInitializerFactory = troopInitializerFactory;
 }
Esempio n. 10
0
 public StrongholdActivationChecker(IStrongholdManager strongholdManager,
                                    IStrongholdActivationCondition strongholdActivationCondition,
                                    IScheduler scheduler,
                                    ILocker locker,
                                    ITileLocator tileLocator,
                                    ISystemVariableManager systemVariableManager,
                                    IDbManager dbManager)
 {
     this.strongholdManager             = strongholdManager;
     this.strongholdActivationCondition = strongholdActivationCondition;
     this.scheduler             = scheduler;
     this.locker                = locker;
     this.tileLocator           = tileLocator;
     this.systemVariableManager = systemVariableManager;
     this.dbManager             = dbManager;
 }
Esempio n. 11
0
 public MapDataExport(IStrongholdManager strongholdManager,
                      ICityManager cityManager,
                      IForestManager forestManager,
                      IBarbarianTribeManager barbarianTribeManager,
                      ITribeManager tribeManager,
                      IWorld world,
                      IScheduler scheduler)
 {
     this.strongholdManager     = strongholdManager;
     this.cityManager           = cityManager;
     this.forestManager         = forestManager;
     this.barbarianTribeManager = barbarianTribeManager;
     this.tribeManager          = tribeManager;
     this.world     = world;
     this.scheduler = scheduler;
 }
Esempio n. 12
0
 public TribesmanCommandsModule(IActionFactory actionFactory,
                                IStructureCsvFactory structureCsvFactory,
                                ILocker locker,
                                IWorld world,
                                IDbManager dbManager,
                                IStrongholdManager strongholdManager,
                                ITribeManager tribeManager)
 {
     this.actionFactory       = actionFactory;
     this.structureCsvFactory = structureCsvFactory;
     this.locker            = locker;
     this.world             = world;
     this.dbManager         = dbManager;
     this.strongholdManager = strongholdManager;
     this.tribeManager      = tribeManager;
 }
Esempio n. 13
0
 public StrongholdCommandLineModule(ITribeManager tribeManager,
                                    IWorld world,
                                    ILocker locker,
                                    IStrongholdManager strongholdManager,
                                    MapFactory mapFactory,
                                    Formula formula,
                                    ITileLocator tileLocator)
 {
     this.tribeManager      = tribeManager;
     this.world             = world;
     this.locker            = locker;
     this.strongholdManager = strongholdManager;
     this.mapFactory        = mapFactory;
     this.formula           = formula;
     this.tileLocator       = tileLocator;
 }
Esempio n. 14
0
 public World(IRoadManager roadManager,
              IStrongholdManager strongholdManager,
              ICityManager cityManager,
              IRegionManager regionManager,
              ITribeManager tribeManager,
              IBarbarianTribeManager barbarianTribeManager,
              IDbManager dbManager)
 {
     this.barbarianTribeManager = barbarianTribeManager;
     this.dbManager             = dbManager;
     Roads       = roadManager;
     strongholds = strongholdManager;
     Cities      = cityManager;
     Regions     = regionManager;
     Tribes      = tribeManager;
     Battles     = new Dictionary <uint, IBattleManager>();
     Lock        = new object();
     Players     = new ConcurrentDictionary <uint, IPlayer>();
 }
Esempio n. 15
0
        public void Callback_WhenInactiveStrongholdsHaveSameScore_ShouldActivateClosestToCenter(
            [Frozen] ISystemVariableManager systemVariableManager,
            [Frozen] IStrongholdActivationCondition activationCondition,
            [Frozen] IStrongholdManager strongholdManager,
            [Frozen] ITileLocator tileLocator,
            IStronghold sh1,
            IStronghold sh2,
            IFixture fixture)
        {
            sh1.StrongholdState.Returns(StrongholdState.Inactive);
            sh1.PrimaryPosition.Returns(new Position(10, 20));

            sh2.StrongholdState.Returns(StrongholdState.Inactive);
            sh2.PrimaryPosition.Returns(new Position(30, 40));

            activationCondition.Score(null).ReturnsForAnyArgs(0);

            tileLocator.TileDistance(sh1.PrimaryPosition, 1, Arg.Any <Position>(), 1)
            .Returns(10);

            tileLocator.TileDistance(sh2.PrimaryPosition, 1, Arg.Any <Position>(), 1)
            .Returns(5);

            var lastCheckTime = Substitute.For <SystemVariable>();

            lastCheckTime.Value.Returns(SystemClock.Now.AddHours(-8));
            systemVariableManager["Stronghold.neutral_check"].Returns(lastCheckTime);

            var locker = new LockerStub();

            fixture.Register <ILocker>(() => locker);

            strongholdManager.GetEnumerator().Returns(_ => new List <IStronghold> {
                sh1, sh2
            }.GetEnumerator());

            var checker = fixture.Create <StrongholdActivationChecker>();

            checker.Callback(null);

            strongholdManager.Received().Activate(sh2);
            strongholdManager.DidNotReceive().Activate(sh1);
        }
Esempio n. 16
0
 public Engine(INetworkServer server,
               IPolicyServer policyServer,
               TServer thriftServer,
               DbLoader dbLoader,
               IPlayerSelectorFactory playerSelector,
               IPlayersRemoverFactory playersRemoverFactory,
               IStrongholdManager strongholdManager,
               IBarbarianTribeManager barbarianTribeManager,
               IWorld world,
               SystemVariablesUpdater systemVariablesUpdater,
               IScheduler scheduler,
               IDbManager dbManager,
               StrongholdActivationChecker strongholdActivationChecker,
               StrongholdChecker strongholdChecker,
               BarbarianTribeChecker barbarianTribeChecker,
               ICityChannel cityChannel,
               IStrongholdManagerLogger strongholdManagerLogger,
               StoreSync storeSync,
               IQueueListener queueListener,
               MapDataExport mapDataExport)
 {
     this.server                = server;
     this.policyServer          = policyServer;
     this.thriftServer          = thriftServer;
     this.dbLoader              = dbLoader;
     this.playerSelector        = playerSelector;
     this.playersRemoverFactory = playersRemoverFactory;
     this.strongholdManager     = strongholdManager;
     this.barbarianTribeManager = barbarianTribeManager;
     this.world = world;
     this.systemVariablesUpdater = systemVariablesUpdater;
     this.scheduler = scheduler;
     this.dbManager = dbManager;
     this.strongholdActivationChecker = strongholdActivationChecker;
     this.strongholdChecker           = strongholdChecker;
     this.barbarianTribeChecker       = barbarianTribeChecker;
     this.cityChannel             = cityChannel;
     this.strongholdManagerLogger = strongholdManagerLogger;
     this.storeSync     = storeSync;
     this.queueListener = queueListener;
     this.mapDataExport = mapDataExport;
 }
Esempio n. 17
0
 public StrongholdMainBattlePassiveAction(BattleProcedure battleProcedure,
                                          StrongholdBattleProcedure strongholdBattleProcedure,
                                          ILocker locker,
                                          IGameObjectLocator gameObjectLocator,
                                          IDbManager dbManager,
                                          Formula formula,
                                          IWorld world,
                                          IStrongholdManager strongholdManager,
                                          IActionFactory actionFactory,
                                          ITroopObjectInitializerFactory troopInitializerFactory)
 {
     this.battleProcedure           = battleProcedure;
     this.strongholdBattleProcedure = strongholdBattleProcedure;
     this.locker                  = locker;
     this.gameObjectLocator       = gameObjectLocator;
     this.dbManager               = dbManager;
     this.formula                 = formula;
     this.world                   = world;
     this.strongholdManager       = strongholdManager;
     this.actionFactory           = actionFactory;
     this.troopInitializerFactory = troopInitializerFactory;
 }
Esempio n. 18
0
        public Tribe(IPlayer owner,
                     string name,
                     string desc,
                     byte level,
                     decimal victoryPoints,
                     int attackPoints,
                     int defensePoints,
                     Resource resource,
                     DateTime created,
                     Procedure procedure,
                     IDbManager dbManager,
                     Formula formula,
                     IAssignmentFactory assignmentFactory,
                     ICityManager cityManager,
                     IStrongholdManager strongholdManager,
                     ITileLocator tileLocator,
                     IChannel channel)
        {
            LeavingTribesmates = new List <LeavingTribesmate>();

            this.procedure         = procedure;
            this.dbManager         = dbManager;
            this.formula           = formula;
            this.assignmentFactory = assignmentFactory;
            this.cityManager       = cityManager;
            this.strongholdManager = strongholdManager;
            this.tileLocator       = tileLocator;
            this.channel           = channel;
            Owner        = owner;
            Level        = level;
            Resource     = resource;
            Description  = desc;
            Name         = name;
            VictoryPoint = victoryPoints;
            AttackPoint  = attackPoints;
            DefensePoint = defensePoints;
            Created      = created;
        }
Esempio n. 19
0
        public StrongholdMainBattlePassiveAction(uint strongholdId,
                                                 BattleProcedure battleProcedure,
                                                 StrongholdBattleProcedure strongholdBattleProcedure,
                                                 ILocker locker,
                                                 IGameObjectLocator gameObjectLocator,
                                                 IDbManager dbManager,
                                                 Formula formula,
                                                 IWorld world,
                                                 IStrongholdManager strongholdManager,
                                                 IActionFactory actionFactory,
                                                 ITroopObjectInitializerFactory troopInitializerFactory)
            : this(battleProcedure, strongholdBattleProcedure, locker, gameObjectLocator, dbManager, formula, world, strongholdManager, actionFactory, troopInitializerFactory)
        {
            this.strongholdId = strongholdId;

            IStronghold stronghold;

            if (!gameObjectLocator.TryGetObjects(strongholdId, out stronghold))
            {
                throw new Exception("Did not find stronghold that was supposed to be having a battle");
            }

            RegisterBattleListeners(stronghold);
        }
Esempio n. 20
0
 public void Listen(IStrongholdManager strongholdManager)
 {
     strongholdManager.StrongholdGained += StrongholdManager_StrongholdGained;
     strongholdManager.StrongholdLost   += StrongholdManager_StrongholdLost;
 }
Esempio n. 21
0
        public static void AddTribeInfo(IStrongholdManager strongholdManager,
                                        ITribeManager tribeManager,
                                        Session session,
                                        ITribe tribe,
                                        Packet packet)
        {
            if (session.Player.IsInTribe && tribe.Id == session.Player.Tribesman.Tribe.Id)
            {
                packet.AddByte(1);
                packet.AddUInt32(tribe.Id);
                packet.AddUInt32(tribe.Owner.PlayerId);
                packet.AddByte(tribe.Level);
                packet.AddString(tribe.Name);
                packet.AddString(tribe.Description);
                packet.AddString(tribe.PublicDescription);
                packet.AddFloat((float)tribe.VictoryPoint);
                packet.AddUInt32(UnixDateTime.DateTimeToUnix(tribe.Created));
                AddToPacket(tribe.Resource, packet);

                packet.AddInt16((short)tribe.Count);
                foreach (var tribesman in tribe.Tribesmen)
                {
                    packet.AddUInt32(tribesman.Player.PlayerId);
                    packet.AddString(tribesman.Player.Name);
                    packet.AddInt32(tribesman.Player.GetCityCount());
                    packet.AddByte(tribesman.Rank.Id);
                    packet.AddUInt32(tribesman.Player.IsLoggedIn ? 0 : UnixDateTime.DateTimeToUnix(tribesman.Player.LastLogin));
                    AddToPacket(tribesman.Contribution, packet);
                }

                // Incoming List
                var incomingList = tribeManager.GetIncomingList(tribe).ToList();
                packet.AddInt16((short)incomingList.Count());
                foreach (var incoming in incomingList)
                {
                    AddToPacket(incoming.Target, packet);
                    AddToPacket(incoming.Source, packet);

                    packet.AddUInt32(UnixDateTime.DateTimeToUnix(incoming.EndTime.ToUniversalTime()));
                }

                // Assignment List
                packet.AddInt16(tribe.AssignmentCount);
                foreach (var assignment in tribe.Assignments)
                {
                    AddToPacket(assignment, packet);
                }

                // Strongholds
                var strongholds = strongholdManager.StrongholdsForTribe(tribe).ToList();
                packet.AddInt16((short)strongholds.Count);
                foreach (var stronghold in strongholds)
                {
                    packet.AddUInt32(stronghold.ObjectId);
                    packet.AddString(stronghold.Name);
                    packet.AddByte((byte)stronghold.StrongholdState);
                    packet.AddByte(stronghold.Lvl);
                    packet.AddFloat((float)stronghold.Gate);
                    packet.AddInt32(stronghold.GateMax);
                    packet.AddUInt32(stronghold.PrimaryPosition.X);
                    packet.AddUInt32(stronghold.PrimaryPosition.Y);
                    packet.AddInt32(stronghold.Troops.StationedHere().Sum(x => x.Upkeep));
                    packet.AddFloat((float)stronghold.VictoryPointRate);
                    packet.AddUInt32(UnixDateTime.DateTimeToUnix(stronghold.DateOccupied.ToUniversalTime()));
                    packet.AddUInt32(stronghold.GateOpenTo == null ? 0 : stronghold.GateOpenTo.Id);
                    packet.AddString(stronghold.GateOpenTo == null ? string.Empty : stronghold.GateOpenTo.Name);
                    if (stronghold.GateBattle != null)
                    {
                        packet.AddByte(1);
                        packet.AddUInt32(stronghold.GateBattle.BattleId);
                    }
                    else if (stronghold.MainBattle != null)
                    {
                        packet.AddByte(2);
                        packet.AddUInt32(stronghold.MainBattle.BattleId);
                    }
                    else
                    {
                        packet.AddByte(0);
                    }
                }

                // Attackable Strongholds
                strongholds = strongholdManager.OpenStrongholdsForTribe(tribe).ToList();
                packet.AddInt16((short)strongholds.Count);
                foreach (var stronghold in strongholds)
                {
                    packet.AddUInt32(stronghold.ObjectId);
                    packet.AddString(stronghold.Name);
                    packet.AddUInt32(stronghold.Tribe == null ? 0 : stronghold.Tribe.Id);
                    packet.AddString(stronghold.Tribe == null ? string.Empty : stronghold.Tribe.Name);
                    packet.AddByte((byte)stronghold.StrongholdState);
                    packet.AddByte(stronghold.Lvl);
                    packet.AddUInt32(stronghold.PrimaryPosition.X);
                    packet.AddUInt32(stronghold.PrimaryPosition.Y);
                    if (stronghold.GateBattle != null)
                    {
                        packet.AddByte(1);
                        packet.AddUInt32(stronghold.GateBattle.BattleId);
                    }
                    else if (stronghold.MainBattle != null)
                    {
                        packet.AddByte(2);
                        packet.AddUInt32(stronghold.MainBattle.BattleId);
                    }
                    else
                    {
                        packet.AddByte(0);
                    }
                }
            }
            else
            {
                packet.AddByte(0);
                packet.AddUInt32(tribe.Id);
                packet.AddString(tribe.Name);
                packet.AddString(tribe.PublicDescription);
                packet.AddByte(tribe.Level);
                packet.AddUInt32(UnixDateTime.DateTimeToUnix(tribe.Created));

                packet.AddByte((byte)tribe.Ranks.Count());
                foreach (var rank in tribe.Ranks)
                {
                    packet.AddString(rank.Name);
                }

                packet.AddInt16((short)tribe.Count);
                foreach (var tribesman in tribe.Tribesmen)
                {
                    packet.AddUInt32(tribesman.Player.PlayerId);
                    packet.AddString(tribesman.Player.Name);
                    packet.AddInt32(tribesman.Player.GetCityCount());
                    packet.AddByte(tribesman.Rank.Id);
                }

                var strongholds = strongholdManager.StrongholdsForTribe(tribe).ToList();
                packet.AddInt16((short)strongholds.Count);
                foreach (var stronghold in strongholds)
                {
                    packet.AddUInt32(stronghold.ObjectId);
                    packet.AddString(stronghold.Name);
                    packet.AddByte(stronghold.Lvl);
                    packet.AddUInt32(stronghold.PrimaryPosition.X);
                    packet.AddUInt32(stronghold.PrimaryPosition.Y);
                }
            }
        }