public override int Execute(LogicLevel level) { if (level.GetVillageType() == 0) { LogicGameMode gameMode = level.GetGameMode(); if (gameMode.GetShieldRemainingSeconds() <= 0) { gameMode.SetShieldRemainingSeconds(0); gameMode.SetGuardRemainingSeconds(0); gameMode.GetLevel().GetHome().GetChangeListener().ShieldActivated(0, 0); } else { int guardTime = gameMode.GetGuardRemainingSeconds(); gameMode.SetShieldRemainingSeconds(0); gameMode.SetGuardRemainingSeconds(guardTime); gameMode.SetPersonalBreakCooldownSeconds(LogicDataTables.GetGlobals().GetPersonalBreakLimitSeconds()); level.GetHome().GetChangeListener().ShieldActivated(0, guardTime); } return(0); } return(-32); }
private void Trigger() { if (!this.m_triggered) { Debugger.Print(string.Format("LogicTriggerComponent::trigger() -> {0}", this.m_parent.GetLevel().GetLogicTime().GetTick())); if (LogicDataTables.GetGlobals().UseTrapTriggerCommand()) { if (!this.m_cmdTriggered) { if (this.m_parent.GetLevel().GetState() != 5) { LogicTriggerComponentTriggeredCommand triggerComponentTriggeredCommand = new LogicTriggerComponentTriggeredCommand(this.m_parent); triggerComponentTriggeredCommand.SetExecuteSubTick(this.m_parent.GetLevel().GetLogicTime().GetTick() + 1); this.m_parent.GetLevel().GetGameMode().GetCommandManager().AddCommand(triggerComponentTriggeredCommand); } this.m_cmdTriggered = true; } } else { this.m_triggered = true; } } }
public void IncrementCastedSpells(LogicSpellData data, int count) { this.m_deployedHousingSpace += LogicDataTables.GetGlobals().GetSpellHousingCostMultiplier() * data.GetHousingSpace() * count / 100; this.m_armyDeploymentPercentage = (100000 * this.m_deployedHousingSpace / LogicDataTables.GetTownHallLevel(this.m_level.GetTownHallLevel(0)).GetMaxHousingSpace() + 50) / 100; int index = -1; for (int i = 0; i < this.m_castedSpellCount.Size(); i++) { if (this.m_castedSpellCount[i].GetData() == data) { index = i; break; } } if (index != -1) { this.m_castedSpellCount[index].SetCount(this.m_castedSpellCount[index].GetCount() + count); } else { this.m_castedSpellCount.Add(new LogicDataSlot(data, count)); } }
public int SpeedUpNewTrainingUnit(LogicLevel level) { if (LogicDataTables.GetGlobals().UseNewTraining()) { LogicUnitProduction unitProduction = this.m_spellProduction ? level.GetGameObjectManager().GetSpellProduction() : level.GetGameObjectManager().GetUnitProduction(); LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); int remainingSecs = unitProduction.GetTotalRemainingSeconds(); int speedUpCost = LogicGamePlayUtil.GetSpeedUpCost(remainingSecs, this.m_spellProduction ? 1 : 4, level.GetVillageType()); if (!level.GetMissionManager().IsTutorialFinished()) { if (speedUpCost > 0 && LogicDataTables.GetGlobals().GetTutorialTrainingSpeedUpCost() >= 0) { speedUpCost = LogicDataTables.GetGlobals().GetTutorialTrainingSpeedUpCost(); } } if (playerAvatar.HasEnoughDiamonds(speedUpCost, true, level)) { playerAvatar.UseDiamonds(speedUpCost); unitProduction.SpeedUp(); playerAvatar.GetChangeListener().DiamondPurchaseMade(unitProduction.GetUnitProductionType() == LogicDataType.CHARACTER ? 2 : 7, 0, 0, speedUpCost, level.GetVillageType()); return(0); } return(-1); } return(-99); }
public bool IsDonationLimitReached(int allianceLevel) { int totalUnitDonation = 0; int totalSpellDonation = 0; for (int i = 0; i < this.m_donationData.Size(); i++) { if (this.m_donationData[i].GetCombatItemType() == LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER) { ++totalUnitDonation; } } if (totalUnitDonation >= this.GetDonationLimit(allianceLevel)) { for (int i = 0; i < this.m_donationData.Size(); i++) { if (this.m_donationData[i].GetCombatItemType() == LogicCombatItemData.COMBAT_ITEM_TYPE_SPELL) { ++totalSpellDonation; } } return(totalSpellDonation >= LogicDataTables.GetGlobals().GetMaxSpellDonationCount()); } return(false); }
/// <summary> /// Trains the unit with new training. /// </summary> public int NewTrainingUnit(LogicLevel level) { if (LogicDataTables.GetGlobals().UseNewTraining()) { LogicUnitProduction unitProduction = this._spellProduction ? level.GetGameObjectManager().GetSpellProduction() : level.GetGameObjectManager().GetUnitProduction(); LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); Int32 remainingSecs = unitProduction.GetTotalRemainingSeconds(); Int32 speedUpCost = LogicGamePlayUtil.GetSpeedUpCost(remainingSecs, this._spellProduction ? 1 : 4, level.GetVillageType()); if (!level.GetMissionManager().IsTutorialFinished()) { if (speedUpCost > 0 && LogicDataTables.GetGlobals().GetTutorialTrainingSpeedUpCost() > 0) { speedUpCost = LogicDataTables.GetGlobals().GetTutorialTrainingSpeedUpCost(); } } if (playerAvatar.HasEnoughDiamonds(speedUpCost, true, level)) { playerAvatar.UseDiamonds(speedUpCost); unitProduction.SpeedUp(); return(0); } return(-1); } return(-99); }
/// <summary> /// Gets the cost of the speed up. /// </summary> public static int GetSpeedUpCost(int time, int speedUpType, int villageType) { int multiplier = 100; switch (speedUpType) { case 1: multiplier = LogicDataTables.GetGlobals().UseNewTraining() ? LogicDataTables.GetGlobals().GetSpellTrainingCostMultiplier() : LogicDataTables.GetGlobals().GetSpellSpeedUpCostMultiplier(); break; case 2: multiplier = LogicDataTables.GetGlobals().GetHeroHealthSpeedUpCostMultipler(); break; case 3: multiplier = LogicDataTables.GetGlobals().GetTroopRequestSpeedUpCostMultiplier(); break; case 4: multiplier = LogicDataTables.GetGlobals().GetTroopTrainingCostMultiplier(); break; case 5: multiplier = LogicDataTables.GetGlobals().GetSpeedUpBoostCooldownCostMultiplier(); break; case 6: multiplier = LogicDataTables.GetGlobals().GetClockTowerSpeedUpMultiplier(); break; } return(LogicDataTables.GetGlobals().GetSpeedUpCost(time, multiplier, villageType)); }
public void IncrementDeployedAllianceUnits(LogicCombatItemData data, int count, int upgLevel) { int multiplier = data.GetCombatItemType() != LogicCombatItemData.COMBAT_ITEM_TYPE_HERO ? LogicDataTables.GetGlobals().GetUnitHousingCostMultiplier() : LogicDataTables.GetGlobals().GetHeroHousingCostMultiplier(); int maxHousingSpace = LogicDataTables.GetTownHallLevel(this.m_level.GetTownHallLevel(0)).GetMaxHousingSpace(); if (maxHousingSpace > 0) { this.m_armyDeploymentPercentage = (100000 * this.m_deployedHousingSpace / maxHousingSpace + 50) / 100; } this.m_deployedHousingSpace += multiplier * data.GetHousingSpace() * count / 100; int index = -1; for (int i = 0; i < this.m_castedAllianceUnitCount.Size(); i++) { if (this.m_castedAllianceUnitCount[i].GetData() == data && this.m_castedAllianceUnitCount[i].GetLevel() == upgLevel) { index = i; break; } } if (index != -1) { this.m_castedAllianceUnitCount[index].SetCount(this.m_castedAllianceUnitCount[index].GetCount() + count); } else { this.m_castedAllianceUnitCount.Add(new LogicUnitSlot(data, upgLevel, count)); } }
public override void Tick() { if (this.m_parent.IsAlive()) { if (LogicDataTables.GetGlobals().GuardPostNotFunctionalUnderUpgrade()) { if (this.m_parent.GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding building = (LogicBuilding)this.m_parent; if (building.IsConstructing()) { return; } } } if (this.m_maxDefenceTroopCount > this.m_defenceTroopCount) { if (this.m_spawnCooldownTimer == null || this.m_spawnCooldownTimer.GetRemainingSeconds(this.m_parent.GetLevel().GetLogicTime()) <= 0) { this.SpawnCharacter(this.m_parent.GetX(), this.m_parent.GetY() + (this.m_parent.GetHeightInTiles() << 8)); if (this.m_maxDefenceTroopCount > this.m_defenceTroops.Size()) { this.StartSpawnCooldownTimer(); } } } } }
private void OnAddAllianceBookmarkMessageReceived(AddAllianceBookmarkMessage message) { if (this.m_session.GameAvatar.AllianceBookmarksList.Size() < LogicDataTables.GetGlobals().GetBookmarksMaxAlliances()) { this.m_session.GameAvatar.AddAllianceBookmark(message.GetAllianceId()); } }
/// <summary> /// Called when the loading of this <see cref="LogicObstacle"/> instance is finished. /// </summary> public override void LoadingFinished() { base.LoadingFinished(); if (LogicDataTables.GetGlobals().ClampBuildingTimes()) { if (this._constructionTimer != null) { if (this._upgLevel < this.GetTrapData().GetUpgradeLevelCount() - 1) { int remainingSecs = this._constructionTimer.GetRemainingSeconds(this._level.GetLogicTime()); int totalSecs = this.GetTrapData().GetBuildTime(this._upgLevel + 1); if (remainingSecs > totalSecs) { this._constructionTimer.StartTimer(totalSecs, this._level.GetLogicTime(), true, this._level.GetGameMode().GetCurrentTimestamp()); } } } } if (this._listener != null) { this._listener.LoadedFromJSON(); } }
/// <summary> /// Adjusts the end subtick of timer. /// </summary> public void AdjustEndSubtick(LogicLevel level) { if (this._endTimestamp != -1) { int currentTime = LogicDataTables.GetGlobals().AdjustEndSubtickUseCurrentTime() ? level.GetGameMode().GetActiveTimestamp() : level.GetGameMode().GetCurrentTimestamp(); if (currentTime != -1) { int passedTime = this._endTimestamp - currentTime; int clamp = LogicDataTables.GetGlobals().GetClampLongTimeStampsToDays(); if (clamp * 86400 > 0) { if (passedTime > 86400 * clamp) { passedTime = 86400 * clamp; } else if (passedTime < -86400 * clamp) { passedTime = -86400 * clamp; } } this._remainingTime = level.GetLogicTime() + (LogicDataTables.GetGlobals().MoreAccurateTime() ? (int)(1000L * passedTime / 16) : 60 * passedTime); } } }
public override void FastForwardTime(int time) { base.FastForwardTime(time); if (this.m_clearTimer != null) { int remainingSeconds = this.m_clearTimer.GetRemainingSeconds(this.m_level.GetLogicTime()); if (remainingSeconds <= time) { if (LogicDataTables.GetGlobals().CompleteConstructionOnlyHome()) { this.m_clearTimer.StartTimer(0, this.m_level.GetLogicTime(), false, -1); } else { this.ClearingFinished(true); } } else { this.m_clearTimer.StartTimer(remainingSeconds - time, this.m_level.GetLogicTime(), false, -1); } } }
public void AddDefendingHero() { LogicAvatar visitorAvatar = this.m_parent.GetLevel().GetVisitorAvatar(); LogicAvatar homeOwnerAvatar = this.m_parent.GetLevel().GetHomeOwnerAvatar(); int randomPatrolPoint = visitorAvatar != null ? (int)(((visitorAvatar.GetResourceCount(LogicDataTables.GetGoldData()) + 10 * this.m_hero.GetGlobalID()) & 0x7FFFFFFFu) % this.m_patrolPath.Size()) : 0; int upgLevel = homeOwnerAvatar.GetUnitUpgradeLevel(this.m_hero); int heroHitpoints = this.m_hero.GetHeroHitpoints(homeOwnerAvatar.GetHeroHealth(this.m_hero), upgLevel); if (this.m_hero.HasEnoughHealthForAttack(heroHitpoints, upgLevel)) { LogicVector2 patrolPoint = this.m_patrolPath[randomPatrolPoint]; LogicCharacter hero = (LogicCharacter)LogicGameObjectFactory.CreateGameObject(this.m_hero, this.m_parent.GetLevel(), this.m_parent.GetVillageType()); hero.GetMovementComponent().SetBaseBuilding((LogicBuilding)this.m_parent); hero.GetHitpointComponent().SetTeam(1); hero.SetUpgradeLevel(upgLevel); hero.GetHitpointComponent().SetHitpoints(heroHitpoints); hero.SetInitialPosition(patrolPoint.m_x, patrolPoint.m_y); this.m_parent.GetGameObjectManager().AddGameObject(hero, -1); hero.GetCombatComponent().SetSearchRadius(this.m_hero.GetMaxSearchRadiusForDefender() / 512); if (LogicDataTables.GetGlobals().EnableDefendingAllianceTroopJump()) { hero.GetMovementComponent().EnableJump(3600000); } } }
public void EndAttackPreparation() { if (this.m_battleTimer != null) { int attackLength = LogicDataTables.GetGlobals().GetAttackLengthSecs(); int battleRemainingSecs = this.m_battleTimer.GetRemainingSeconds(this.m_level.GetLogicTime()); if (battleRemainingSecs > attackLength) { int remainingPrepSecs = battleRemainingSecs - attackLength; if (this.m_replay != null) { this.m_replay.RecordPreparationSkipTime(remainingPrepSecs); } this.m_skipPreparationSecs = remainingPrepSecs; this.m_battleTimer.StartTimer(attackLength, this.m_level.GetLogicTime(), false, -1); } if (this.m_level.GetPlayerAvatar() != null) { LogicClientAvatar playerAvatar = this.m_level.GetPlayerAvatar(); if (playerAvatar.GetChangeListener() != null) { playerAvatar.GetChangeListener().BattleFeedback(5, 0); } } } }
/// <summary> /// Gets the boost multiplier. /// </summary> public int GetBoostMultiplier() { if (this._unitProductionType == 25) { if (LogicDataTables.GetGlobals().UseNewTraining()) { return(LogicDataTables.GetGlobals().GetSpellFactoryBoostNewMultiplier()); } return(LogicDataTables.GetGlobals().GetSpellFactoryBoostMultiplier()); } else { if (this._unitProductionType != 3) { return(1); } if (LogicDataTables.GetGlobals().UseNewTraining()) { return(LogicDataTables.GetGlobals().GetBarracksBoostNewMultiplier()); } return(LogicDataTables.GetGlobals().GetBarracksBoostMultiplier()); } }
public void AdjustEndSubtick(LogicLevel level) { if (this.m_endTimestamp != -1) { int currentTime = LogicDataTables.GetGlobals().AdjustEndSubtickUseCurrentTime() ? level.GetGameMode().GetServerTimeInSecondsSince1970() : level.GetGameMode().GetStartTime(); if (currentTime != -1) { int remainingSecs = this.m_endTimestamp - currentTime; int clamp = LogicDataTables.GetGlobals().GetClampLongTimeStampsToDays(); if (clamp * 86400 > 0) { if (remainingSecs > 86400 * clamp) { remainingSecs = 86400 * clamp; } else if (remainingSecs < -86400 * clamp) { remainingSecs = -86400 * clamp; } } this.m_remainingTime = level.GetLogicTime().GetTick() + LogicTime.GetSecondsInTicks(remainingSecs); } } }
/// <summary> /// Executes this command. /// </summary> public override int Execute(LogicLevel level) { if (LogicDataTables.GetGlobals().UseNewTraining()) { if (level.GetVillageType() == 0) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); LogicUnitProduction unitProduction = this._productionType == 1 ? level.GetGameObjectManager().GetSpellProduction() : level.GetGameObjectManager().GetUnitProduction(); if (unitProduction.CanBeBoosted()) { int cost = unitProduction.GetBoostCost(); if (playerAvatar.HasEnoughDiamonds(cost, true, level)) { playerAvatar.UseDiamonds(cost); unitProduction.Boost(); return(0); } return(-2); } return(-1); } return(-32); } return(-99); }
private void OnDonateAllianceUnitMessageReceived(DonateAllianceUnitMessage message) { if (this.m_session.Alliance != null) { Alliance alliance = this.m_session.Alliance; LogicCombatItemData unitData = message.GetAllianceUnitData(); if (!unitData.IsDonationDisabled()) { if (message.UseQuickDonate()) { if (!LogicDataTables.GetGlobals().EnableQuickDonate() || this.m_session.LogicClientAvatar.GetDiamonds() < unitData.GetDonateCost()) { return; } } else { if (this.m_session.LogicClientAvatar.GetUnitCount(unitData) <= 0) { return; } } if (alliance.StreamEntryList.IndexOf(message.GetStreamId()) != -1) { StreamEntry streamEntry = StreamManager.GetAllianceStream(message.GetStreamId()); if (streamEntry.GetStreamEntryType() == StreamEntryType.DONATE) { DonateStreamEntry donateStreamEntry = (DonateStreamEntry)streamEntry; if (donateStreamEntry.CanAddDonation(this.m_session.AccountId, message.GetAllianceUnitData(), alliance.Header.GetAllianceLevel())) { donateStreamEntry.AddDonation(this.m_session.AccountId, unitData, this.m_session.LogicClientAvatar.GetUnitUpgradeLevel(unitData)); donateStreamEntry.SetDonationPendingRequestCount(donateStreamEntry.GetDonationPendingRequestCount() + 1); StreamManager.Save(donateStreamEntry); alliance.UpdateStreamEntry(donateStreamEntry); if (message.UseQuickDonate()) { this.m_session.LogicClientAvatar.CommodityCountChangeHelper(0, unitData, -1); } LogicDonateAllianceUnitCommand logicDonateAllianceUnitCommand = new LogicDonateAllianceUnitCommand(); logicDonateAllianceUnitCommand.SetData(unitData, streamEntry.GetId(), message.UseQuickDonate()); ServerMessageManager.SendMessage(new GameAllowServerCommandMessage { AccountId = this.m_session.AccountId, ServerCommand = logicDonateAllianceUnitCommand }, 9); } } } } } }
public override int Execute(LogicLevel level) { LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObjectId); if (gameObject != null) { if (gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding building = (LogicBuilding)gameObject; if (!LogicDataTables.GetGlobals().AllowCancelBuildingConstruction() && building.GetUpgradeLevel() == 0 && building.IsConstructing()) { if (!building.IsUpgrading()) { return(-2); } } if (building.IsConstructing()) { building.GetListener().CancelNotification(); building.CancelConstruction(); return(0); } } else if (gameObject.GetGameObjectType() == LogicGameObjectType.OBSTACLE) { LogicObstacle obstacle = (LogicObstacle)gameObject; if (obstacle.IsClearingOnGoing()) { LogicObstacleData data = obstacle.GetObstacleData(); LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); playerAvatar.CommodityCountChangeHelper(0, data.GetClearResourceData(), data.GetClearCost()); obstacle.CancelClearing(); return(0); } } else if (gameObject.GetGameObjectType() == LogicGameObjectType.TRAP) { LogicTrap trap = (LogicTrap)gameObject; if (trap.IsConstructing()) { trap.GetListener().CancelNotification(); trap.CancelConstruction(); return(0); } } } return(-1); }
public override void Load(LogicJSONObject jsonObject) { this.LoadUpgradeLevel(jsonObject); if (this.m_constructionTimer != null) { this.m_constructionTimer.Destruct(); this.m_constructionTimer = null; } LogicJSONNumber constTimeObject = jsonObject.GetJSONNumber("const_t"); if (constTimeObject != null) { int constTime = constTimeObject.GetIntValue(); if (!LogicDataTables.GetGlobals().ClampBuildingTimes()) { if (this.m_upgLevel < this.GetVillageObjectData().GetUpgradeLevelCount() - 1) { constTime = LogicMath.Min(constTime, this.GetVillageObjectData().GetBuildTime(this.m_upgLevel + 1)); } } this.m_constructionTimer = new LogicTimer(); this.m_constructionTimer.StartTimer(constTime, this.m_level.GetLogicTime(), false, -1); LogicJSONNumber constTimeEndObject = jsonObject.GetJSONNumber("const_t_end"); if (constTimeEndObject != null) { this.m_constructionTimer.SetEndTimestamp(constTimeEndObject.GetIntValue()); } LogicJSONNumber conffObject = jsonObject.GetJSONNumber("con_ff"); if (conffObject != null) { this.m_constructionTimer.SetFastForward(conffObject.GetIntValue()); } LogicVillageObjectData villageObjectData = this.GetVillageObjectData(); if (villageObjectData.IsRequiresBuilder() && !villageObjectData.IsAutomaticUpgrades()) { this.m_level.GetWorkerManagerAt(this.m_villageType).AllocateWorker(this); } this.m_upgrading = this.m_upgLevel != -1; } this.m_upgLevel = LogicMath.Clamp(this.m_upgLevel, 0, this.GetVillageObjectData().GetUpgradeLevelCount() - 1); base.Load(jsonObject); this.SetPositionXY((this.GetVillageObjectData().GetTileX100() << 9) / 100, (this.GetVillageObjectData().GetTileY100() << 9) / 100); }
public static int GetTicksInSeconds(int tick) { if (LogicDataTables.GetGlobals().MoreAccurateTime()) { return((int)(16L * tick / 1000)); } return(tick / 60); }
public void StartArrangedWarCooldownTime() { if (this.m_arrangeWarCooldownTimer == null) { this.m_arrangeWarCooldownTimer = new LogicTimer(); } this.m_arrangeWarCooldownTimer.StartTimer(LogicDataTables.GetGlobals().GetArrangeWarCooldown(), this.m_parent.GetLevel().GetLogicTime(), false, -1); }
/// <summary> /// Executes this command. /// </summary> public override int Execute(LogicLevel level) { if (!LogicDataTables.GetGlobals().UseNewTraining()) { return(-1); // TODO: Implement this. } return(this.NewTrainingUnit(level)); }
public override int Execute(LogicLevel level) { if (!LogicDataTables.GetGlobals().UseNewTraining()) { throw new NotImplementedException(); // TODO: Implement this. } return(this.NewTrainingUnit(level)); }
/// <summary> /// Gets the milliseconds in ticks. /// </summary> public static int GetMSInTicks(int time) { if (LogicDataTables.GetGlobals().MoreAccurateTime()) { return(16 * time); } return((int)(1000L * time / 60)); }
public static int GetMSInTicks(int time) { if (LogicDataTables.GetGlobals().MoreAccurateTime()) { return(time / 16); } return(time * 60 / 1000); }
public static int GetCooldownTicksInSeconds(int time) { if (LogicDataTables.GetGlobals().MoreAccurateTime()) { return((int)(((long)time << 6) / 1000)); } return(time / 15); }
public static int GetSecondsInTicks(int time) { if (LogicDataTables.GetGlobals().MoreAccurateTime()) { return((int)(1000L * time / 16L)); } return(time * 60); }
public static int GetCooldownSecondsInTicks(int time) { if (LogicDataTables.GetGlobals().MoreAccurateTime()) { return((int)(1000L * time / 64)); } return(time * 15); }