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); }
public IBattleManager CreateStrongholdMainBattleManager(uint battleId, BattleLocation battleLocation, BattleOwner battleOwner, IStronghold stronghold) { var battleRandom = new BattleRandom(battleId); var bm = new StrongholdMainBattleManager(battleId, battleLocation, battleOwner, kernel.Get <IRewardStrategyFactory>().CreateStrongholdRewardStrategy(stronghold), kernel.Get <IDbManager>(), kernel.Get <IBattleReport>(), kernel.Get <ICombatListFactory>(), kernel.Get <IGameObjectLocator>(), new BattleOrder(battleRandom), kernel.Get <IBattleFormulas>(), battleRandom); // ReSharper disable once ObjectCreationAsStatement new BattleChannel(bm, kernel.Get <IChannel>()); bm.BattleReport.Battle = bm; return(bm); }
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); }
public void RetreatUnits_RetreatsStationedUnitsThatAreNotInTribeThatOwnsStronghold( IStronghold stronghold, [FrozenMock] IActionFactory actionFactory, [FrozenMock] ITroopObjectInitializerFactory troopInitializerFactory, ITroopObjectInitializer troopInitializer, ITroopStub stub, ITribe tribe, ITribe shTribe, RetreatChainAction retreatAction, StrongholdManager strongholdManager) { stub.State.Returns(TroopState.Stationed); stub.City.Owner.IsInTribe.Returns(true); stub.City.Id.Returns<uint>(1234); stub.TroopId.Returns<ushort>(2); stub.City.Owner.Tribesman.Tribe.Returns(tribe); stronghold.MainBattle.Returns((IBattleManager)null); stronghold.Tribe.Returns(shTribe); stronghold.Troops.StationedHere().Returns(new[] { stub }); troopInitializerFactory.CreateStationedTroopObjectInitializer(stub).Returns(troopInitializer); actionFactory.CreateRetreatChainAction(stub.City.Id, troopInitializer).Returns(retreatAction); strongholdManager.RetreatUnits(stronghold); stub.City.Worker.Received(1).DoPassive(stub.City, retreatAction, true); }
public void Generate(int count) { for (var i = 0; i < count; ++i) { string name; byte level; uint x, y; if (!strongholdConfigurator.Next(i, count, out name, out level, out x, out y)) { break; } var limit = formula.StrongholdGateLimit(level); IStronghold stronghold = strongholdFactory.CreateStronghold(idGenerator.GetNext(), name, level, x, y, limit, Convert.ToInt32(limit), Theme.DEFAULT_THEME_ID); using (dbManager.GetThreadTransaction()) { Add(stronghold); } } }
public void CanWatchBattle_WhenPlayerIsNotPartOfTribe_ShouldReturnError( IPlayer player, IStronghold stronghold, IFixture fixture) { player.IsInTribe.Returns(false); stronghold.StrongholdState.Returns(StrongholdState.Occupied); stronghold.Tribe.Id.Returns <uint>(212); stronghold.GateOpenTo.Id.Returns <uint>(123); fixture.Register(() => new BattleLocation(BattleLocationType.Stronghold, 100)); var gameObjectLocator = fixture.Freeze <IGameObjectLocator>(); IStronghold outStronghold; gameObjectLocator.TryGetObjects(100, out outStronghold).Returns(args => { args[1] = stronghold; return(true); }); var battleManager = fixture.Create <StrongholdMainBattleManager>(); IEnumerable <string> errorParams; battleManager.CanWatchBattle(player, out errorParams).Should().Be(Error.BattleNotViewable); }
public virtual Error CanStrongholdBeAttacked(ICity city, IStronghold stronghold, bool forceAttack) { if (stronghold.StrongholdState == StrongholdState.Inactive) { return(Error.StrongholdStillInactive); } if (!city.Owner.IsInTribe) { return(Error.TribesmanNotPartOfTribe); } if (!forceAttack) { if (city.Owner.Tribesman.Tribe == stronghold.Tribe) { return(Error.StrongholdCantAttackSelf); } if (stronghold.GateOpenTo != null && stronghold.GateOpenTo != city.Owner.Tribesman.Tribe) { return(Error.StrongholdGateNotOpenToTribe); } } return(Error.Ok); }
private void Add(IStronghold stronghold) { strongholds.AddOrUpdate(stronghold.ObjectId, stronghold, (id, old) => stronghold); RegisterEvents(stronghold); dbManager.Save(stronghold); MarkIndexDirty(); }
public void CanWatchBattle_WhenPlayerIsTribesmateFromOwningTribe_ShouldReturnErrorOk( IPlayer player, IStronghold stronghold, IFixture fixture) { player.IsInTribe.Returns(true); player.Tribesman.Tribe.Id.Returns <uint>(123); stronghold.StrongholdState = StrongholdState.Occupied; stronghold.BelongsTo(player.Tribesman.Tribe).Returns(true); fixture.Register(() => new BattleLocation(BattleLocationType.Stronghold, 100)); var gameObjectLocator = fixture.Freeze <IGameObjectLocator>(); IStronghold outStronghold; gameObjectLocator.TryGetObjects(100, out outStronghold).Returns(args => { args[1] = stronghold; return(true); }); var battleManager = fixture.Create <StrongholdMainBattleManager>(); IEnumerable <string> errorParams; battleManager.CanWatchBattle(player, out errorParams).Should().Be(Error.Ok); }
public StrongholdCombatUnit[] CreateStrongholdCombatUnit(IBattleManager battleManager, IStronghold stronghold, ushort type, byte level, ushort count) { var groupSize = kernel.Get <UnitFactory>().GetUnitStats(type, level).Battle.GroupSize; var units = new StrongholdCombatUnit[(count - 1) / groupSize + 1]; int i = 0; do { ushort size = (groupSize > count ? count : groupSize); StrongholdCombatUnit newUnit = new StrongholdCombatUnit(battleManager.GetNextCombatObjectId(), battleManager.BattleId, type, level, size, stronghold, kernel.Get <UnitFactory>(), kernel.Get <IBattleFormulas>(), kernel.Get <Formula>(), kernel.Get <IDbManager>()); units[i++] = newUnit; count -= size; }while (count > 0); return(units); }
public IBattleManager CreateStrongholdGateBattleManager(BattleLocation battleLocation, BattleOwner battleOwner, IStronghold stronghold) { var battleId = BattleReport.BattleIdGenerator.GetNext(); return(CreateStrongholdGateBattleManager(battleId, battleLocation, battleOwner, stronghold)); }
public virtual double GetGateBattleInterval(IStronghold stronghold) { if (Config.battle_gate_turn_interval > 0) { return(Config.battle_gate_turn_interval); } double[] interval = { 0, 30.6, 27.1, 24.0, 21.2, 18.8, 16.6, 14.7, 13.0, 11.5, 10.2, 9.0, 8.1, 7.1, 6.2, 5.5, 4.9, 4.3, 3.8, 3.4, 3.0 }; return(interval[stronghold.Lvl]); }
private void RegisterBattleListeners(IStronghold stronghold) { stronghold.MainBattle.UnitCountDecreased += MainBattleOnUnitKilled; stronghold.MainBattle.GroupKilled += MainBattleOnGroupKilled; stronghold.MainBattle.AboutToExitBattle += MainBattleOnAboutToExitBattle; stronghold.MainBattle.ActionAttacked += MainBattleOnActionAttacked; stronghold.MainBattle.ExitTurn += MainBattleOnExitTurn; stronghold.MainBattle.EnterBattle += MainBattleOnEnterBattle; }
public void Activate(IStronghold stronghold) { stronghold.BeginUpdate(); stronghold.StrongholdState = StrongholdState.Neutral; regionManager.Add(stronghold); stronghold.EndUpdate(); chat.SendSystemChat("STRONGHOLD_ACTIVE", stronghold.Name); }
public bool TryGetStronghold(string name, out IStronghold stronghold) { lock (indexLock) { ReindexIfNeeded(); return(nameIndex.TryGetValue(name.ToLowerInvariant(), out stronghold)); } }
private void AttackStronghold(Session session, Packet packet) { uint cityId; uint targetStrongholdId; ISimpleStub simpleStub; AttackMode mode; try { mode = (AttackMode)packet.GetByte(); cityId = packet.GetUInt32(); targetStrongholdId = packet.GetUInt32(); simpleStub = PacketHelper.ReadStub(packet, FormationType.Attack); } catch (Exception) { ReplyError(session, packet, Error.Unexpected); return; } IStronghold stronghold = null; ICity city = null; locker.Lock(session.Player).Do(() => { city = session.Player.GetCity(cityId); if (city == null) { ReplyError(session, packet, Error.Unexpected); return; } if (!gameObjectLocator.TryGetObjects(targetStrongholdId, out stronghold)) { ReplyError(session, packet, Error.Unexpected); } }); if (city == null || stronghold == null) { return; } locker.Lock(city, stronghold).Do(() => { var troopInitializer = troopObjectInitializerFactory.CreateCityTroopObjectInitializer(cityId, simpleStub, TroopBattleGroup.Attack, mode); var attackAction = actionFactory.CreateStrongholdAttackChainAction(cityId, troopInitializer, targetStrongholdId, forceAttack: false); var result = city.Worker.DoPassive(city, attackAction, true); ReplyWithResult(session, packet, result); }); }
public virtual decimal StrongholdVictoryPoint(IStronghold stronghold) { if (stronghold.StrongholdState != StrongholdState.Occupied) { return(0); } var serverUptime = (decimal)SystemClock.Now.Subtract((DateTime)SystemVariableManager["Server.date"].Value).TotalDays; var daysOccupied = (decimal)SystemClock.Now.Subtract(stronghold.DateOccupied).TotalDays; return(((daysOccupied + stronghold.BonusDays) / 2m + serverUptime / 5 + 10) * (5 + stronghold.Lvl * 5m)); }
protected bool IsStrongholdFriendly(IStronghold stronghold) { var isLoyal = stronghold.OccupyingRace != Race.Doomguard; if (_engine.Scenario is RevengeScenario) { var ddrStronghold = stronghold as IRevengeStronghold; isLoyal = ddrStronghold !.Loyalty == Luxor.Loyalty; } return(isLoyal); }
public void DbLoaderAdd(IStronghold stronghold) { strongholds.AddOrUpdate(stronghold.ObjectId, stronghold, (id, old) => stronghold); RegisterEvents(stronghold); MarkIndexDirty(); if (stronghold.StrongholdState != StrongholdState.Inactive) { stronghold.InWorld = true; regionManager.DbLoaderAdd(stronghold); } }
private void StationTroopInStronghold(ITroopObject troopObject, IStronghold stronghold, TroopState stubState = TroopState.Stationed) { procedure.TroopObjectStation(troopObject, stronghold); if (troopObject.Stub.State != stubState) { troopObject.Stub.BeginUpdate(); troopObject.Stub.State = stubState; troopObject.Stub.EndUpdate(); } StateChange(ActionState.Completed); }
public StrongholdCombatGate(uint id, uint battleId, ushort type, byte lvl, decimal hp, IStronghold stronghold, IStructureCsvFactory structureCsvFactory, IBattleFormulas battleFormulas, IDbManager dbManager) : base(id, battleId, type, lvl, hp, stronghold, structureCsvFactory, battleFormulas, dbManager) { }
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); }
public void TribeFailedToTakeStronghold(IStronghold stronghold, ITribe attackingTribe) { switch (stronghold.StrongholdState) { case StrongholdState.Neutral: chat.SendSystemChat("STRONGHOLD_FAILED_NEUTRAL_TAKEOVER", stronghold.Name, attackingTribe.Name); break; case StrongholdState.Occupied: chat.SendSystemChat("STRONGHOLD_FAILED_OCCUPIED_TAKEOVER", stronghold.Name, attackingTribe.Name, stronghold.Tribe.Name); break; } }
public void UpdateGate_WhenMaxDidNotChanged([FrozenMock] Formula formula, IStronghold stronghold, StrongholdManager strongholdManager) { formula.StrongholdGateLimit(0).ReturnsForAnyArgs(5000); stronghold.GateMax = 5000; stronghold.MainBattle.Returns((IBattleManager)null); stronghold.GateBattle.Returns((IBattleManager)null); strongholdManager.UpdateGate(stronghold).Should().Be(Error.Ok); stronghold.Received(0).BeginUpdate(); stronghold.GateMax.Should().Be(5000); }
public virtual ICombatGroup AddStrongholdGateToBattle(IBattleManager battle, IStronghold stronghold) { var strongholdCombatGroup = combatGroupFactory.CreateStrongholdCombatGroup(battle.BattleId, battle.GetNextGroupId(), stronghold); if (stronghold.Gate == 0) { throw new Exception("Dead gate trying to join the battle"); } strongholdCombatGroup.Add(combatUnitFactory.CreateStrongholdGateStructure(battle, stronghold, stronghold.Gate)); battle.Add(strongholdCombatGroup, BattleManager.BattleSide.Defense, false); return(strongholdCombatGroup); }
public IEnumerable <Unit> GenerateNeutralStub(IStronghold stronghold) { ISimpleStub simpleStub; int upkeep; byte unitLevel; formula.StrongholdUpkeep(stronghold.Lvl, out upkeep, out unitLevel); simpleStubGenerator.Generate(stronghold.Lvl, upkeep, unitLevel, Config.stronghold_npc_randomness, (int)stronghold.ObjectId, out simpleStub); return(simpleStub.ToUnitList(FormationType.Normal)); }
public void RetreatUnits_WhenStubIsNotStationedState_ShouldNotRetreatUnits( IStronghold stronghold, [Frozen] IActionFactory actionFactory, ITroopStub stub, StrongholdManager strongholdManager) { stronghold.MainBattle.Returns((IBattleManager)null); stronghold.Troops.StationedHere().Returns(new[] { stub }); stub.State.Returns(TroopState.BattleStationed); stub.City.Owner.IsInTribe.Returns(false); strongholdManager.RetreatUnits(stronghold); stub.City.Worker.DidNotReceiveWithAnyArgs().DoPassive(null, null, false); }
public StrongholdCombatStructure CreateStrongholdGateStructure(IBattleManager battleManager, IStronghold stronghold, decimal hp) { var objectTypeFactory = kernel.Get <IObjectTypeFactory>(); return(new StrongholdCombatGate(battleManager.GetNextCombatObjectId(), battleManager.BattleId, (ushort)objectTypeFactory.GetTypes("StrongholdGateStructureType")[0], stronghold.Lvl, hp, stronghold, kernel.Get <IStructureCsvFactory>(), kernel.Get <IBattleFormulas>(), kernel.Get <IDbManager>())); }
public void Lock_StrongholdId_WhenStrongholdIsNotFound_ShouldReturnEmptyLockObject( [Frozen] IGameObjectLocator locator, IStronghold stronghold, DefaultLocker locker) { IStronghold outStronghold; locator.TryGetObjects(1, out outStronghold).Returns(false); IStronghold lockedStronghold; var multiObjLock = locker.Lock(1, out lockedStronghold); lockedStronghold.Should().BeNull(); multiObjLock.Received(1) .Lock(Arg.Is <ILockable[]>(itemsLocked => !itemsLocked.Any())); }
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); } } }