public void SetPosition(int x, int y) { if (this.m_parent != null) { if (!this.m_parent.IsFlying() && !this.m_parent.IsUnderground() && this.m_parent.GetJump() <= 0 && !this.m_ignorePush) { this.ValidatePos(); if (this.m_position.m_x >> 8 == x >> 8) { if ((this.m_position.m_y ^ (uint)y) < 256) { goto set; } } LogicTileMap tileMap = this.m_parent.GetParent().GetLevel().GetTileMap(); int pathFinderX = x >> 8; int pathFinderY = y >> 8; if (!tileMap.IsPassablePathFinder(pathFinderX, pathFinderY)) { LogicTile tile = tileMap.GetTile(pathFinderX / 2, pathFinderY / 2); if (LogicDataTables.GetGlobals().JumpWhenHitJumpable()) { bool allowJump = false; for (int i = 0; i < tile.GetGameObjectCount(); i++) { LogicGameObject gameObject = tile.GetGameObject(i); if (gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding building = (LogicBuilding)gameObject; if (building.GetHitWallDelay() > 0) { allowJump = true; } } } if (allowJump) { this.m_position.m_x = x; this.m_position.m_y = y; this.m_parent.EnableJump(128); return; } } if (LogicDataTables.GetGlobals().SlideAlongObstacles()) { throw new NotImplementedException(); // TODO: Implement this. } else { x = LogicMath.Clamp(x, (int)(this.m_position.m_x & 0xFFFFFF00), this.m_position.m_x | 0xFF); y = LogicMath.Clamp(y, (int)(this.m_position.m_y & 0xFFFFFF00), this.m_position.m_y | 0xFF); } this.m_position.m_x = x; this.m_position.m_y = y; this.ValidatePos(); return; } } } set: this.m_position.m_x = x; this.m_position.m_y = y; }
/// <summary> /// Executes this command. /// </summary> public override int Execute(LogicLevel level) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (playerAvatar != null) { if (this._source == 1) { // listener. } playerAvatar.SetDiamonds(playerAvatar.GetDiamonds() + this._diamondsCount); if (this._freeDiamonds) { int freeDiamonds = playerAvatar.GetFreeDiamonds(); if (this._diamondsCount < 0) { if (freeDiamonds - this._diamondsCount >= 0 && playerAvatar.GetDiamonds() != freeDiamonds) { playerAvatar.SetFreeDiamonds(freeDiamonds + this._diamondsCount); } } else { playerAvatar.SetFreeDiamonds(freeDiamonds + this._diamondsCount); } } else { if (this._billingPackageId > 0) { LogicBillingPackageData billingPackageData = (LogicBillingPackageData)LogicDataTables.GetDataById(this._billingPackageId, 21); if (billingPackageData != null) { if (billingPackageData.RED && !this._bundlePackage) { int redPackageState = playerAvatar.GetRedPackageState(); int newRedPackageState = redPackageState | 0x10; if ((redPackageState & 3) != 3) { newRedPackageState = (int)(newRedPackageState & 0xFFFFFFFC); } playerAvatar.SetRedPackageState(newRedPackageState); } } } level.GetGameListener().DiamondsBought(); playerAvatar.AddCumulativePurchasedDiamonds(this._diamondsCount); } return(0); } return(-1); }
/// <summary> /// Executes this command. /// </summary> public override int Execute(LogicLevel level) { LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this._gameObjectId); if (gameObject != null) { if (gameObject.GetGameObjectType() == 0) { 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); } } if (gameObject.GetGameObjectType() == 3) { 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); } } if (gameObject.GetGameObjectType() == 4) { LogicTrap trap = (LogicTrap)gameObject; if (trap.IsConstructing()) { trap.GetListener().CancelNotification(); trap.CancelConstruction(); return(0); } } } return(-1); }
/// <summary> /// Executes this command. /// </summary> public override int Execute(LogicLevel level) { LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this._gameObjectId); if (gameObject != null) { int gameObjectType = gameObject.GetGameObjectType(); if (gameObjectType <= 6 && gameObjectType != 3) { if (gameObjectType != 0 || ((LogicBuildingData)gameObject.GetData()).GetVillageType() == level.GetVillageType()) { if (gameObjectType == 0) { if (((LogicBuilding)gameObject).GetWallIndex() != 0) { return(-21); } } int x = gameObject.GetTileX(); int y = gameObject.GetTileY(); int width = gameObject.GetWidthInTiles(); int height = gameObject.GetHeightInTiles(); if (gameObject.GetVillageType() != 0) { for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { LogicObstacle tallGrass = level.GetTileMap().GetTile(x + i, y + j).GetTallGrass(); if (tallGrass != null) { level.GetGameObjectManager().RemoveGameObject(tallGrass); } } } } if (level.IsValidPlaceForBuilding(this._x, this._y, width, height, gameObject)) { gameObject.SetPositionXY(this._x << 9, this._y << 9); if (this._x != x || this._y != y) { if (level.GetHomeOwnerAvatar() != null) { LogicAvatar homeOwnerAvatar = level.GetHomeOwnerAvatar(); if (homeOwnerAvatar.GetTownHallLevel() >= LogicDataTables.GetGlobals().GetChallengeBaseCooldownTownHall()) { level.SetLayoutCooldownSecs(level.GetActiveLayout(level.GetVillageType()), LogicDataTables.GetGlobals().GetChallengeBaseSaveCooldown()); } } } return(0); } return(-3); } return(-32); } return(-1); } return(-2); }
private void OnCreateAllianceMessageReceived(CreateAllianceMessage message) { if (!this.CanJoinAlliance()) { AllianceCreateFailedMessage allianceCreateFailedMessage = new AllianceCreateFailedMessage(); allianceCreateFailedMessage.SetReason(AllianceCreateFailedMessage.Reason.GENERIC); this.m_session.SendPiranhaMessage(allianceCreateFailedMessage, 1); return; } LogicClientAvatar playerAvatar = this.m_session.GameMode.GetPlayerAvatar(); if (playerAvatar.GetResourceCount(LogicDataTables.GetGlobals().GetAllianceCreateResourceData()) < LogicDataTables.GetGlobals().GetAllianceCreateCost()) { AllianceCreateFailedMessage allianceCreateFailedMessage = new AllianceCreateFailedMessage(); allianceCreateFailedMessage.SetReason(AllianceCreateFailedMessage.Reason.GENERIC); this.m_session.SendPiranhaMessage(allianceCreateFailedMessage, 1); return; } ServerSocket allianceServer = ServerManager.GetNextSocket(11); if (allianceServer != null) { ServerRequestManager.Create(new CreateAllianceRequestMessage { AllianceName = message.GetAllianceName(), AllianceDescription = message.GetAllianceDescription(), AllianceType = (AllianceType)message.GetAllianceType(), AllianceBadgeId = message.GetAllianceBadgeId(), RequiredScore = message.GetRequiredScore(), RequiredDuelScore = message.GetRequiredDuelScore(), WarFrequency = message.GetWarFrequency(), PublicWarLog = message.GetPublicWarLog(), ArrangedWarEnabled = message.GetArrangedWarEnabled() }, allianceServer).OnComplete = this.OnCreateAlliance; } else { AllianceCreateFailedMessage allianceCreateFailedMessage = new AllianceCreateFailedMessage(); allianceCreateFailedMessage.SetReason(AllianceCreateFailedMessage.Reason.GENERIC); this.m_session.SendPiranhaMessage(allianceCreateFailedMessage, 1); } }
public virtual void Load(LogicJSONObject jsonObject) { if (jsonObject == null) { this.m_errorHandler.Error(this, "Json cannot be null"); } this.m_id = LogicJSONHelper.GetInt(jsonObject, "id", -1); this.m_version = LogicJSONHelper.GetInt(jsonObject, "version", 0); this.m_newTrainingBoostBarracksCost = LogicDataTables.GetGlobals().GetNewTrainingBoostBarracksCost(); this.m_newTrainingBoostSpellCost = LogicDataTables.GetGlobals().GetNewTrainingBoostLaboratoryCost(); this.m_startTime = LogicCalendarEvent.ConvertStringToTimestamp(LogicJSONHelper.GetString(jsonObject, "startTime"), false); this.m_endTime = LogicCalendarEvent.ConvertStringToTimestamp(LogicJSONHelper.GetString(jsonObject, "endTime"), true); if (this.m_startTime >= this.m_endTime) { this.m_errorHandler.ErrorField(this, "endTime", "End time must be after start time."); } LogicJSONString visibleTimeString = jsonObject.GetJSONString("visibleTime"); if (visibleTimeString != null) { this.m_visibleTime = LogicCalendarEvent.ConvertStringToTimestamp(visibleTimeString.GetStringValue(), false); if (this.m_visibleTime > this.m_startTime) { this.m_errorHandler.ErrorField(this, "visibleTime", "Visible time must be before or at start time."); } } else { this.m_visibleTime = 0; } this.m_clashBoxEntryName = jsonObject.GetJSONString("clashBoxEntryName").GetStringValue(); LogicJSONString eventEntryNameString = jsonObject.GetJSONString("eventEntryName"); this.m_eventEntryData = LogicDataTables.GetEventEntryByName(eventEntryNameString.GetStringValue(), null); if (eventEntryNameString.GetStringValue().Length > 0) { if (this.m_eventEntryData == null) { this.m_errorHandler.ErrorField(this, "eventEntryName", string.Format("Invalid event entry name: {0}.", eventEntryNameString.GetStringValue())); } if (this.m_visibleTime == 0) { this.m_errorHandler.ErrorField(this, "visibleTime", "Visible time must be set if event entry name is set."); } } if (this.m_visibleTime != 0) { if (this.m_eventEntryData == null) { this.m_errorHandler.ErrorField(this, "eventEntryName", "Event entry name must be set if visible time is set."); } } this.m_inboxEntryId = LogicJSONHelper.GetInt(jsonObject, "inboxEntryId", -1); this.m_notificationTid = LogicJSONHelper.GetString(jsonObject, "notificationTid"); this.m_image = LogicJSONHelper.GetString(jsonObject, "image"); this.m_sc = LogicJSONHelper.GetString(jsonObject, "sc"); this.m_localization = LogicJSONHelper.GetString(jsonObject, "localization"); LogicJSONObject targetingObject = jsonObject.GetJSONObject("targeting"); if (targetingObject != null) { this.m_targeting = new LogicCalendarTargeting(jsonObject); } LogicJSONArray functionArray = jsonObject.GetJSONArray("functions"); if (functionArray != null) { for (int i = 0; i < functionArray.Size(); i++) { this.m_functions.Add(new LogicCalendarFunction(this, i, functionArray.GetJSONObject(i), this.m_errorHandler)); } } }
/// <summary> /// Gets the data instance by the name. /// </summary> private LogicGlobalData GetGlobalData(string name) { return(LogicDataTables.GetClientGlobalByName(name)); }
public override int Execute(LogicLevel level) { if (this.m_gameObjectIds.Size() > 0) { int cost = 0; for (int i = 0; i < this.m_gameObjectIds.Size(); i++) { LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObjectIds[i]); if (gameObject != null && gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING) { if (gameObject.GetData().GetVillageType() == level.GetVillageType()) { LogicBuilding building = (LogicBuilding)gameObject; if (!building.IsLocked()) { if (!LogicDataTables.GetGlobals().UseNewTraining() || building.GetUnitProductionComponent() == null) { if (building.CanBeBoosted()) { cost += building.GetBoostCost(); } continue; } return(-3); } return(-4); } return(-32); } return(-5); } LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (cost > 0) { if (!playerAvatar.HasEnoughDiamonds(cost, true, level)) { return(-2); } playerAvatar.UseDiamonds(cost); playerAvatar.GetChangeListener().DiamondPurchaseMade(8, 0, 0, cost, level.GetVillageType()); } for (int i = 0; i < this.m_gameObjectIds.Size(); i++) { LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObjectIds[i]); if (gameObject != null && gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding building = (LogicBuilding)gameObject; if (building.GetMaxBoostTime() != 0) { building.Boost(); } } } return(0); } return(-1); }
public void FinishConstruction(bool ignoreState) { int state = this.m_level.GetState(); if (state == 1 || !LogicDataTables.GetGlobals().CompleteConstructionOnlyHome() && ignoreState) { LogicAvatar homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar(); if (homeOwnerAvatar != null && homeOwnerAvatar.IsClientAvatar()) { LogicTrapData data = this.GetTrapData(); if (this.m_constructionTimer != null) { this.m_constructionTimer.Destruct(); this.m_constructionTimer = null; } this.m_level.GetWorkerManagerAt(this.m_data.GetVillageType()).DeallocateWorker(this); if (this.m_upgLevel != 0 || this.m_upgrading) { if (this.m_upgLevel >= data.GetUpgradeLevelCount() - 1) { Debugger.Warning("LogicTrap - Trying to upgrade to level that doesn't exist! - " + data.GetName()); this.m_upgLevel = data.GetUpgradeLevelCount() - 1; } else { this.m_upgLevel += 1; } } if (!ignoreState && !this.m_disarmed) { if (this.GetListener() != null) { // Listener. } } this.XpGainHelper(LogicGamePlayUtil.TimeToExp(data.GetBuildTime(this.m_upgLevel)), homeOwnerAvatar, ignoreState); if (this.m_disarmed) { // Listener. } this.m_fadeTime = 0; this.m_disarmed = false; this.m_upgrading = false; if (this.m_listener != null) { this.m_listener.RefreshState(); } if (state == 1) { this.m_level.GetAchievementManager().RefreshStatus(); } } else { Debugger.Warning("LogicTrap::finishCostruction failed - Avatar is null or not client avatar"); } } }
/// <summary> /// Gets the resource diamond cost. /// </summary> public static int GetResourceDiamondCost(int count, LogicResourceData data) { return(LogicDataTables.GetGlobals().GetResourceDiamondCost(count, data)); }
public override int Execute(LogicLevel level) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (playerAvatar != null) { LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(1); if (gameObjectManager.GetTownHall() == null) { LogicJSONObject jsonObject = level.GetGameListener().ParseCompressedHomeJSON(this.m_compressedHomeJSON, this.m_compressedHomeJSON.Length); level.SetLoadingVillageType(1); this.LoadGameObjectsJsonArray(level, jsonObject.GetJSONArray("buildings2"), 1); this.LoadGameObjectsJsonArray(level, jsonObject.GetJSONArray("obstacles2"), 1); this.LoadGameObjectsJsonArray(level, jsonObject.GetJSONArray("traps2"), 1); this.LoadGameObjectsJsonArray(level, jsonObject.GetJSONArray("decos2"), 1); level.SetLoadingVillageType(-1); if (playerAvatar.GetResourceCount(LogicDataTables.GetGold2Data()) == 0) { playerAvatar.CommodityCountChangeHelper(0, LogicDataTables.GetGold2Data(), LogicDataTables.GetGlobals().GetStartingGold2()); } if (playerAvatar.GetResourceCount(LogicDataTables.GetElixir2Data()) == 0) { playerAvatar.CommodityCountChangeHelper(0, LogicDataTables.GetElixir2Data(), LogicDataTables.GetGlobals().GetStartingElixir2()); } } return(0); } return(-1); }
public void StateChangeConfirmed() { switch (this.m_data.GetMissionType()) { case 1: if (this.m_progress == 0) { this.m_level.GetGameMode().StartDefendState(LogicNpcAvatar.GetNpcAvatar(this.m_data.GetDefendNpcData())); this.m_progress = 1; } break; case 7: case 8: case 9: case 10: case 11: case 20: case 21: this.m_progress = 1; this.Finished(); break; case 16: if (this.m_progress == 0) { // ? } this.m_progress += 1; break; case 19: if (this.m_progress == 1) { LogicClientAvatar playerAvatar = this.m_level.GetPlayerAvatar(); int duelScoreGain = LogicDataTables.GetGlobals().GetVillage2FirstVictoryTrophies(); playerAvatar.AddDuelReward(LogicDataTables.GetGlobals().GetVillage2FirstVictoryGold(), LogicDataTables.GetGlobals().GetVillage2FirstVictoryElixir(), 0, 0, null); playerAvatar.SetDuelScore(playerAvatar.GetDuelScore() + LogicDataTables.GetGlobals().GetVillage2FirstVictoryTrophies()); playerAvatar.GetChangeListener().DuelScoreChanged(playerAvatar.GetAllianceId(), duelScoreGain, -1, false); this.m_progress = 2; this.Finished(); } break; } }
public override void RecalculateAvailableLoot() { LogicAvatar homeOwnerAvatar = this.m_parent.GetLevel().GetHomeOwnerAvatar(); LogicDataTable resourceTable = LogicDataTables.GetTable(LogicDataType.RESOURCE); for (int i = 0; i < this.m_resourceCount.Size(); i++) { LogicResourceData data = (LogicResourceData)resourceTable.GetItemAt(i); if (this.m_parent.GetData() == LogicDataTables.GetAllianceCastleData()) { LogicResourceData refData = data.GetWarResourceReferenceData(); int resourceCount = this.m_resourceCount[i]; if (refData != null) { int warLootPercentage = LogicDataTables.GetGlobals().GetWarLootPercentage(); int lootableResourceCount = 0; if ((this.m_parent.GetLevel().GetMatchType() | 4) != 7 && !this.m_parent.GetLevel().IsArrangedWar()) { lootableResourceCount = (int)((long)resourceCount * warLootPercentage / 100); } int storageLootCap = LogicDataTables.GetTownHallLevel(homeOwnerAvatar.GetTownHallLevel()).GetStorageLootCap(data); int maxResourceCount = LogicMath.Min(homeOwnerAvatar.GetResourceCount(data), homeOwnerAvatar.GetResourceCap(data)); if (maxResourceCount > storageLootCap && maxResourceCount > 0) { int clampedValue; if (storageLootCap < 1000000) { if (storageLootCap < 100000) { if (storageLootCap < 10000) { clampedValue = storageLootCap < 1000 ? (resourceCount * storageLootCap + (maxResourceCount >> 1)) / maxResourceCount : 10 * ((resourceCount * (storageLootCap / 10) + (maxResourceCount >> 1)) / maxResourceCount); } else { clampedValue = 100 * ((resourceCount * (storageLootCap / 100) + (maxResourceCount >> 1)) / maxResourceCount); } } else { clampedValue = 1000 * ((resourceCount * (storageLootCap / 1000) + (maxResourceCount >> 1)) / maxResourceCount); } } else { clampedValue = 40000 * ((resourceCount * (storageLootCap / 40000) + (maxResourceCount >> 1)) / maxResourceCount); } if (lootableResourceCount > clampedValue) { lootableResourceCount = clampedValue; } } if (lootableResourceCount > resourceCount) { lootableResourceCount = resourceCount; } this.m_stealableResourceCount[i] = lootableResourceCount; } } } }
public bool MoveTo(int x, int y, LogicTileMap tileMap, bool defaultEndPoint) { this.ClearPath(); if (this.m_parent != null) { if (this.m_parent.GetParent().IsFrozen()) { return(false); } } this.m_wall = null; this.m_wallCount = 0; this.m_pathStartPosition.m_x = this.m_position.m_x >> 8; this.m_pathStartPosition.m_y = this.m_position.m_y >> 8; this.m_pathEndPosition.m_x = x >> 8; this.m_pathEndPosition.m_y = y >> 8; this.m_pathStartPosition.m_x = LogicMath.Clamp(this.m_pathStartPosition.m_x, 0, 99); this.m_pathStartPosition.m_y = LogicMath.Clamp(this.m_pathStartPosition.m_y, 0, 99); this.m_pathEndPosition.m_x = LogicMath.Clamp(this.m_pathEndPosition.m_x, 0, 99); this.m_pathEndPosition.m_y = LogicMath.Clamp(this.m_pathEndPosition.m_y, 0, 99); LogicPathFinder pathFinder; if (this.m_parent == null) { pathFinder = this.m_pathFinder; pathFinder.ResetCostStrategyToDefault(); } else { bool resetStrategyCost = true; int strategyCost = 256; LogicGameObject parent = this.m_parent.GetParent(); LogicHitpointComponent hitpointComponent = parent.GetHitpointComponent(); if (hitpointComponent != null) { if (hitpointComponent.GetTeam() == 1) { resetStrategyCost = false; strategyCost = 768; } } if (this.m_parent.CanJumpWall()) { resetStrategyCost = false; strategyCost = 16; } if (parent.GetGameObjectType() == LogicGameObjectType.CHARACTER) { LogicCharacter character = (LogicCharacter)parent; if (character.IsWallBreaker()) { resetStrategyCost = false; strategyCost = 128; } } pathFinder = tileMap.GetPathFinder(); if (resetStrategyCost) { pathFinder.ResetCostStrategyToDefault(); } else { pathFinder.SetCostStrategy(true, strategyCost); } pathFinder.FindPath(this.m_pathStartPosition, this.m_pathEndPosition, true); pathFinder.GetPathLength(); int pathLength = pathFinder.GetPathLength(); this.m_path.EnsureCapacity(pathLength + 1); if (pathLength != 0 && defaultEndPoint) { LogicVector2 pathPoint = new LogicVector2(x, y); this.CheckWall(pathPoint); this.m_path.Add(pathPoint); } if (LogicDataTables.GetGlobals().UseNewPathFinder()) { LogicTileMap pathFinderTileMap = pathFinder.GetTileMap(); int width = 2 * pathFinderTileMap.GetSizeX(); int height = 2 * pathFinderTileMap.GetSizeY(); int startTileIdx = this.m_pathStartPosition.m_x + width * this.m_pathStartPosition.m_y; int endTileIdx = this.m_pathEndPosition.m_x + width * this.m_pathEndPosition.m_y; if (!defaultEndPoint) { LogicVector2 pathPoint = new LogicVector2((endTileIdx % width) << 8, (endTileIdx / height) << 8); this.CheckWall(pathPoint); this.m_path.Add(pathPoint); } if (pathLength > 0 && !pathFinder.IsLineOfSightClear()) { int iterationCount = 0; while (endTileIdx != startTileIdx && endTileIdx != -1) { endTileIdx = pathFinder.GetParent(endTileIdx); if (endTileIdx != startTileIdx && endTileIdx != -1) { LogicVector2 pathPoint = new LogicVector2((endTileIdx % width) << 8, (endTileIdx / height) << 8); pathPoint.m_x += 128; pathPoint.m_y += 128; this.CheckWall(pathPoint); this.m_path.Add(pathPoint); if (iterationCount >= 100000) { Debugger.Warning("LMSystem: iteration count > 100000"); break; } } iterationCount += 1; } } } else { for (int i = -pathLength, j = 0; j + i != 0; j++) { LogicVector2 pathPoint = new LogicVector2(); pathFinder.GetPathPoint(pathPoint, i + j); if (i + j == -1 && this.m_pathStartPosition.Equals(pathPoint)) { pathPoint.Destruct(); pathPoint = null; } else { if (j != 0 || !this.m_pathStartPosition.Equals(pathPoint)) { pathPoint.m_x = (pathPoint.m_x << 8) | 128; pathPoint.m_y = (pathPoint.m_y << 8) | 128; } else { pathPoint.m_x = x; pathPoint.m_y = y; } this.CheckWall(pathPoint); this.m_path.Add(pathPoint); } } } } this.CalculatePathLength(); if (this.m_path.Size() > 0) { this.CalculateDirection(this.m_pathDistance); return(true); } return(false); }
/// <summary> /// Executes this command. /// </summary> public override int Execute(LogicLevel level) { if (this._shieldData != null) { int cooldownSecs = level.GetCooldownManager().GetCooldownSeconds(this._shieldData.GetGlobalID()); if (cooldownSecs <= 0) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (this._shieldData.GetScoreLimit() > playerAvatar.GetScore() || this._shieldData.GetScoreLimit() <= 0) { if (playerAvatar.HasEnoughDiamonds(this._shieldData.GetDiamondsCost(), true, level)) { LogicGameMode gameMode = level.GetGameMode(); playerAvatar.UseDiamonds(this._shieldData.GetDiamondsCost()); int shieldTime = gameMode.GetShieldRemainingSeconds() + this._shieldData.TimeH * 3600; int guardTime = gameMode.GetGuardRemainingSeconds(); int maintenanceTime = 0; if (this._shieldData.TimeH <= 0) { if (shieldTime > 0) { return(-2); } guardTime += this._shieldData.GuardTimeH * 3600; } else { LogicLeagueData leagueData = playerAvatar.GetLeagueTypeData(); if (playerAvatar.GetShieldCostAmount() != 0) { playerAvatar.SetShieldCostAmount(0); } guardTime += leagueData.VillageGuardInMins * 60; } if (shieldTime <= 0) { maintenanceTime = LogicMath.Min(LogicDataTables.GetGlobals().GetPersonalBreakLimitSeconds() + this._shieldData.GuardTimeH * 3600, gameMode.GetMaintenanceRemainingSeconds() + this._shieldData.GuardTimeH * 3600); } else { maintenanceTime = shieldTime + LogicDataTables.GetGlobals().GetPersonalBreakLimitSeconds(); } gameMode.SetMaintenanceRemainingSeconds(maintenanceTime); gameMode.SetShieldRemainingSeconds(shieldTime); gameMode.SetGuardRemainingSeconds(guardTime); level.GetCooldownManager().AddCooldown(this._shieldData.GetGlobalID(), this._shieldData.GetCooldownSecs()); return(0); } } } } return(-1); }
public override void FastForwardTime(int secs) { if (this.m_constructionTimer != null) { if (this.m_constructionTimer.GetEndTimestamp() == -1) { int remainingTime = this.m_constructionTimer.GetRemainingSeconds(this.m_level.GetLogicTime()); if (remainingTime > secs) { base.FastForwardTime(secs); this.m_constructionTimer.StartTimer(remainingTime - secs, this.m_level.GetLogicTime(), false, -1); } else { if (LogicDataTables.GetGlobals().CompleteConstructionOnlyHome()) { base.FastForwardTime(secs); this.m_constructionTimer.StartTimer(0, this.m_level.GetLogicTime(), false, -1); } else { base.FastForwardTime(remainingTime); this.FinishConstruction(true); base.FastForwardTime(secs - remainingTime); } return; } } else { this.m_constructionTimer.AdjustEndSubtick(this.m_level); if (this.m_constructionTimer.GetRemainingSeconds(this.m_level.GetLogicTime()) == 0) { if (LogicDataTables.GetGlobals().CompleteConstructionOnlyHome()) { base.FastForwardTime(secs); this.m_constructionTimer.StartTimer(0, this.m_level.GetLogicTime(), false, -1); } else { base.FastForwardTime(0); this.FinishConstruction(true); base.FastForwardTime(secs); } return; } base.FastForwardTime(secs); } int maxClockTowerFastForward = this.m_level.GetUpdatedClockTowerBoostTime(); if (maxClockTowerFastForward > 0 && !this.m_level.IsClockTowerBoostPaused()) { if (this.m_data.GetVillageType() == 1) { this.m_constructionTimer.SetFastForward(this.m_constructionTimer.GetFastForward() + 60 * LogicMath.Min(secs, maxClockTowerFastForward) * (LogicDataTables.GetGlobals().GetClockTowerBoostMultiplier() - 1)); } } } else { base.FastForwardTime(secs); } }
public override int Execute(LogicLevel level) { if (LogicDataTables.GetGlobals().UseSwapBuildings()) { if (this.m_gameObject1 != this.m_gameObject2) { LogicGameObject gameObject1 = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObject1); LogicGameObject gameObject2 = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObject2); if (gameObject1 != null) { if (gameObject2 != null) { LogicGameObjectType gameObjectType1 = gameObject1.GetGameObjectType(); if (gameObjectType1 == LogicGameObjectType.BUILDING || gameObjectType1 == LogicGameObjectType.TRAP || gameObjectType1 == LogicGameObjectType.DECO) { LogicGameObjectType gameObjectType2 = gameObject2.GetGameObjectType(); if (gameObjectType2 == LogicGameObjectType.BUILDING || gameObjectType2 == LogicGameObjectType.TRAP || gameObjectType2 == LogicGameObjectType.DECO) { int width1 = gameObject1.GetWidthInTiles(); int width2 = gameObject2.GetWidthInTiles(); int height1 = gameObject1.GetHeightInTiles(); int height2 = gameObject2.GetHeightInTiles(); if (width1 == width2 && height1 == height2) { if (gameObject1.GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding building = (LogicBuilding)gameObject1; if (building.IsLocked()) { return(-6); } if (building.IsWall()) { return(-7); } } if (gameObject2.GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding building = (LogicBuilding)gameObject2; if (building.IsLocked()) { return(-8); } if (building.IsWall()) { return(-9); } } int x1 = gameObject1.GetPositionLayout(this.m_layoutId, true).m_x; int y1 = gameObject1.GetPositionLayout(this.m_layoutId, true).m_y; int x2 = gameObject2.GetPositionLayout(this.m_layoutId, true).m_x; int y2 = gameObject2.GetPositionLayout(this.m_layoutId, true).m_y; gameObject1.SetPositionLayoutXY(x2, y2, this.m_layoutId, true); gameObject2.SetPositionLayoutXY(x1, y1, this.m_layoutId, true); return(0); } return(-5); } return(-4); } return(-3); } return(-2); } return(-1); } return(-98); } return(-99); }
public override void Tick() { base.Tick(); if (this.m_constructionTimer != null) { if (this.m_level.GetRemainingClockTowerBoostTime() > 0 && this.m_data.GetVillageType() == 1) { this.m_constructionTimer.SetFastForward(this.m_constructionTimer.GetFastForward() + 4 * LogicDataTables.GetGlobals().GetClockTowerBoostMultiplier() - 4); } if (this.m_constructionTimer.GetRemainingSeconds(this.m_level.GetLogicTime()) <= 0) { this.FinishConstruction(false); } } if (this.m_disarmed) { if (this.m_fadeTime >= 0) { this.m_fadeTime = LogicMath.Min(this.m_fadeTime + 64, 1000); } } LogicTriggerComponent triggerComponent = this.GetTriggerComponent(); if (triggerComponent.IsTriggered() && !this.m_disarmed && !this.m_upgrading) { LogicTrapData data = this.GetTrapData(); if (this.m_numSpawns > 0) { if (this.m_spawnInitDelay != 0) { this.m_spawnInitDelay -= 1; } else { this.SpawnUnit(1); this.m_numSpawns -= 1; this.m_spawnInitDelay = this.GetTrapData().GetTimeBetweenSpawnsMS() / 64; } } if (this.m_actionTime >= 0) { this.m_actionTime += 64; } if (this.m_hitTime >= 0) { this.m_hitTime += 64; } if (this.m_actionTime > data.GetActionFrame()) { this.m_hitTime = data.GetHitDelayMS(); this.m_actionTime = -1; } else if (this.m_hitTime > data.GetHitDelayMS()) { if (data.GetSpell() != null) { LogicSpell spell = (LogicSpell)LogicGameObjectFactory.CreateGameObject(data.GetSpell(), this.m_level, this.m_villageType); spell.SetUpgradeLevel(0); spell.SetInitialPosition(this.GetMidX(), this.GetMidY()); spell.SetTeam(1); this.GetGameObjectManager().AddGameObject(spell, -1); } else if (data.GetProjectile(this.m_upgLevel) != null) { this.CreateProjectile(data.GetProjectile(this.m_upgLevel)); } else if (data.GetDamageMod() != 0) { this.m_level.AreaBoost(this.GetMidX(), this.GetMidY(), data.GetDamageRadius(this.m_upgLevel), -data.GetSpeedMod(), -data.GetSpeedMod(), data.GetDamageMod(), 0, data.GetDurationMS() / 16, 0, false); } else if (data.GetEjectVictims()) { if (data.GetThrowDistance() <= 0) { this.EjectCharacters(); } else { this.ThrowCharacters(); } } else { bool defaultMode = true; if (data.GetSpawnedCharAir() != null && data.GetSpawnedCharGround() != null || data.HasAlternativeMode()) { int activeLayout = this.m_level.GetActiveLayout(); if (activeLayout <= 7) { defaultMode = this.m_useAirMode[activeLayout] ^ true; } } this.m_level.AreaDamage(0, this.GetMidX(), this.GetMidY(), data.GetDamageRadius(this.m_upgLevel), data.GetDamage(this.m_upgLevel), data.GetPreferredTarget(), data.GetPreferredTargetDamageMod(), data.GetDamageEffect(), 1, null, defaultMode ? 1 : 0, 0, 100, true, false, 100, 0, this, 100, 0); } this.m_hitTime = 0; this.m_hitCount += 1; if (this.m_hitCount >= data.GetHitCount() && this.m_numSpawns == 0) { this.m_fadeTime = 1; this.m_hitTime = -1; this.m_disarmed = true; this.m_numSpawns = data.GetNumSpawns(this.m_upgLevel); this.m_spawnInitDelay = data.GetSpawnInitialDelayMS() / 64; } } } }
/// <summary> /// Trains the unit with new training. /// </summary> public int NewTrainingUnit(LogicLevel level) { if (LogicDataTables.GetGlobals().UseNewTraining()) { if (this._trainCount <= 100) { LogicUnitProduction unitProduction = this._unitType == 1 ? level.GetGameObjectManagerAt(0).GetSpellProduction() : level.GetGameObjectManagerAt(0).GetUnitProduction(); if (this._trainCount > 0) { if (this._unitData != null) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); Int32 trainingCost = level.GetGameMode().GetCalendar().GetUnitTrainingCost(this._unitData, playerAvatar.GetUnitUpgradeLevel(this._unitData)); for (int i = 0; i < this._trainCount; i++) { if (!unitProduction.CanAddUnitToQueue(this._unitData, false)) { return(-40); } if (true) // unk slot. { if (!playerAvatar.HasEnoughResources(this._unitData.GetTrainingResource(), trainingCost, true, this, false)) { return(-30); } playerAvatar.CommodityCountChangeHelper(0, this._unitData.GetTrainingResource(), -trainingCost); } else { playerAvatar.CommodityCountChangeHelper(9, this._unitData, -1); } if (this._slotId == -1) { this._slotId = unitProduction.GetSlotCount(); } unitProduction.AddUnitToQueue(this._unitData, this._slotId, false); } return(0); } } return(-50); } else { Debugger.Error("LogicTraingUnitCommand - Count is too high"); } return(-20); } return(-99); }
public override void Load(LogicJSONObject jsonObject) { this.LoadUpgradeLevel(jsonObject); LogicTrapData data = this.GetTrapData(); if (data.HasAlternativeMode() || data.GetSpawnedCharAir() != null && data.GetSpawnedCharGround() != null) { LogicLayoutComponent layoutComponent = (LogicLayoutComponent)this.GetComponent(LogicComponentType.LAYOUT); if (layoutComponent != null) { for (int i = 0; i < 8; i++) { LogicJSONBoolean airModeObject = jsonObject.GetJSONBoolean(layoutComponent.GetLayoutVariableNameAirMode(i, false)); if (airModeObject != null) { this.m_useAirMode[i] = airModeObject.IsTrue(); } LogicJSONBoolean draftAirModeObject = jsonObject.GetJSONBoolean(layoutComponent.GetLayoutVariableNameAirMode(i, true)); if (draftAirModeObject != null) { this.m_draftUseAirMode[i] = draftAirModeObject.IsTrue(); } } } LogicTriggerComponent triggerComponent = this.GetTriggerComponent(); int layoutId = this.m_level.GetCurrentLayout(); bool airMode = this.m_useAirMode[layoutId]; triggerComponent.SetAirTrigger(airMode); triggerComponent.SetGroundTrigger(!airMode); } if (data.GetDirectionCount() > 0) { LogicLayoutComponent layoutComponent = (LogicLayoutComponent)this.GetComponent(LogicComponentType.LAYOUT); if (layoutComponent != null) { for (int i = 0; i < 8; i++) { LogicJSONNumber trapDistanceObject = jsonObject.GetJSONNumber(layoutComponent.GetLayoutVariableNameTrapDirection(i, false)); if (trapDistanceObject != null) { this.m_direction[i] = trapDistanceObject.GetIntValue(); } LogicJSONNumber draftTrapDistanceObject = jsonObject.GetJSONNumber(layoutComponent.GetLayoutVariableNameTrapDirection(i, true)); if (draftTrapDistanceObject != null) { this.m_draftDirection[i] = draftTrapDistanceObject.GetIntValue(); } } } } this.m_level.GetWorkerManagerAt(this.m_villageType).DeallocateWorker(this); 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 < data.GetUpgradeLevelCount() - 1) { constTime = LogicMath.Min(constTime, data.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()); } this.m_level.GetWorkerManagerAt(this.m_villageType).AllocateWorker(this); this.m_upgrading = this.m_upgLevel != -1; } LogicJSONBoolean disarmed = jsonObject.GetJSONBoolean("needs_repair"); if (disarmed != null) { this.m_disarmed = disarmed.IsTrue(); } this.SetUpgradeLevel(this.m_upgLevel); base.Load(jsonObject); }
public void CauseDamage(int damage, int gameObjectId, LogicGameObject gameObject) { if (damage >= 0 || this.m_hp != 0) { if (this.m_parent == null) { if (damage > 0 && this.m_invulnerabilityTime > 0) { return; } } else { LogicCombatComponent combatComponent = this.m_parent.GetCombatComponent(); if (combatComponent != null) { if (combatComponent.GetUndergroundTime() > 0 && damage > 0) { damage = 0; } } if (!this.m_parent.GetLevel().GetInvulnerabilityEnabled()) { if (damage > 0 && this.m_invulnerabilityTime > 0) { return; } } else { damage = 0; } if (this.m_parent.GetGameObjectType() == LogicGameObjectType.CHARACTER) { LogicCharacter character = (LogicCharacter)this.m_parent; LogicArrayList <LogicCharacter> childTroops = character.GetChildTroops(); if (childTroops != null && childTroops.Size() > 0 || character.GetSpawnDelay() > 0) { return; } } } if (gameObjectId != 0 && damage < 0) { int prevHealingIdx = -1; int healingIdx = -1; for (int i = 0; i < 8; i++) { if (this.m_healingId[i] == gameObjectId) { prevHealingIdx = i; } else if (healingIdx == -1) { healingIdx = i; if (this.m_healingTime[i] > 0) { healingIdx = -1; } } } if (healingIdx < prevHealingIdx && prevHealingIdx != -1 && healingIdx != -1) { this.m_healingId[healingIdx] = gameObjectId; this.m_healingTime[healingIdx] = 1000; this.m_healingId[prevHealingIdx] = 0; this.m_healingTime[prevHealingIdx] = 0; } else if (prevHealingIdx == -1) { if (healingIdx != -1) { this.m_healingId[healingIdx] = gameObjectId; this.m_healingTime[healingIdx] = 1000; } else { healingIdx = 8; } } else { healingIdx = prevHealingIdx; this.m_healingTime[prevHealingIdx] = 1000; } damage = damage * LogicDataTables.GetGlobals().GetHealStackPercent(healingIdx) / 100; } int prevHp = (this.m_hp + 99) / 100; int prevAccurateHp = this.m_hp; this.m_hp = LogicMath.Clamp(this.m_hp - damage, 0, this.m_maxHp); int hp = (this.m_hp + 99) / 100; if (prevHp > hp) { LogicResourceStorageComponent resourceStorageComponent = (LogicResourceStorageComponent)this.m_parent.GetComponent(LogicComponentType.RESOURCE_STORAGE); LogicResourceProductionComponent resourceProductionComponent = (LogicResourceProductionComponent)this.m_parent.GetComponent(LogicComponentType.RESOURCE_PRODUCTION); LogicWarResourceStorageComponent warResourceStorageComponent = (LogicWarResourceStorageComponent)this.m_parent.GetComponent(LogicComponentType.WAR_RESOURCE_STORAGE); if (this.m_parent.GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding building = (LogicBuilding)this.m_parent; if (!building.GetBuildingData().IsLootOnDestruction() || prevAccurateHp > 0 && (this.m_hp == 0 || (uint)this.m_hp >= 0xFFFFFF3A)) { if (resourceStorageComponent != null) { resourceStorageComponent.ResourcesStolen(prevHp - hp, prevHp); } if (resourceProductionComponent != null) { resourceProductionComponent.ResourcesStolen(prevHp - hp, prevHp); } if (warResourceStorageComponent != null) { warResourceStorageComponent.ResourcesStolen(prevHp - hp, prevHp); } } } if (this.m_parent.IsWall()) { this.m_parent.RefreshPassable(); } this.m_lastDamageTime = 0; } this.UpdateHeroHealthToAvatar(hp); if (damage <= 0) { if (damage < 0) { // Listener } } else { if (this.m_parent.GetMovementComponent() != null) { this.m_parent.GetMovementComponent().SetPatrolFreeze(); } } if (prevAccurateHp > 0 && this.m_hp == 0) { this.m_parent.DeathEvent(); this.m_parent.GetLevel().UpdateBattleStatus(); if (this.m_parent.IsWall()) { this.WallRemoved(); } } } }
public override int Execute(LogicLevel level) { if (level.IsReadyForAttack()) { if (level.GetVillageType() == 0) { if (LogicDataTables.GetGlobals().AllowClanCastleDeployOnObstacles()) { if (!level.GetTileMap().IsValidAttackPos(this.m_x >> 9, this.m_y >> 9)) { return(-2); } } else { LogicTile tile = level.GetTileMap().GetTile(this.m_x >> 9, this.m_y >> 9); if (tile == null) { return(-4); } if (tile.GetPassableFlag() == 0) { return(-3); } } LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (playerAvatar != null) { if (this.m_data != null) { LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(0); if (gameObjectManager.GetGameObjectCountByData(this.m_data) <= 0 && playerAvatar.GetAllianceCastleUsedCapacity() > 0) { LogicAlliancePortal alliancePortal = (LogicAlliancePortal)LogicGameObjectFactory.CreateGameObject(this.m_data, level, level.GetVillageType()); LogicBunkerComponent bunkerComponent = alliancePortal.GetBunkerComponent(); alliancePortal.SetInitialPosition(this.m_x, this.m_y); if (bunkerComponent != null) { bunkerComponent.SetMaxCapacity(playerAvatar.GetAllianceCastleTotalCapacity()); if (level.GetBattleLog() != null) { if (!level.GetBattleLog().HasDeployedUnits() && level.GetTotalAttackerHeroPlaced() == 0) { level.UpdateLastUsedArmy(); } } if (level.GetGameMode().IsInAttackPreparationMode()) { level.GetGameMode().EndAttackPreparation(); } bunkerComponent.RemoveAllUnits(); LogicArrayList <LogicUnitSlot> allianceUnits = playerAvatar.GetAllianceUnits(); for (int i = 0; i < allianceUnits.Size(); i++) { LogicUnitSlot slot = allianceUnits[i]; LogicCombatItemData data = (LogicCombatItemData)slot.GetData(); if (data != null) { int count = slot.GetCount(); if (data.GetCombatItemType() == LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER) { for (int j = 0; j < count; j++) { if (bunkerComponent.GetUnusedCapacity() >= data.GetHousingSpace()) { bunkerComponent.AddUnitImpl(data, slot.GetLevel()); } } } } else { Debugger.Error("LogicPlaceAlliancePortalCommand::execute - NULL alliance character"); } } } gameObjectManager.AddGameObject(alliancePortal, -1); return(0); } } } return(-5); } } return(-1); }
/// <summary> /// Reads a data reference. /// </summary> public static LogicData ReadDataReference(this ByteStream stream) { return(LogicDataTables.GetDataById(stream.ReadInt())); }
/// <summary> /// Executes this instance. /// </summary> public override int Execute(LogicLevel level) { if (LogicDataTables.GetGlobals().UseSwapBuildings()) { if (this._gameObject1 != this._gameObject2) { LogicGameObject gameObject1 = level.GetGameObjectManager().GetGameObjectByID(this._gameObject1); LogicGameObject gameObject2 = level.GetGameObjectManager().GetGameObjectByID(this._gameObject2); if (gameObject1 != null) { if (gameObject2 != null) { int gameObjectType1 = gameObject1.GetGameObjectType(); if (gameObjectType1 <= 6) { if (gameObjectType1 == 0 || gameObjectType1 == 4 || gameObjectType1 == 6) { int gameObjectType2 = gameObject2.GetGameObjectType(); if (gameObjectType2 <= 6) { if (gameObjectType2 == 0 || gameObjectType2 == 4 || gameObjectType2 == 6) { int width1 = gameObject1.GetWidthInTiles(); int width2 = gameObject2.GetWidthInTiles(); int height1 = gameObject1.GetHeightInTiles(); int height2 = gameObject2.GetHeightInTiles(); if (width1 == width2 && height1 == height2) { if (gameObject1.GetGameObjectType() == 0) { if (((LogicBuilding)gameObject1).IsLocked()) { return(-6); } if (gameObject1.IsWall()) { return(-7); } } if (gameObject2.GetGameObjectType() == 0) { if (((LogicBuilding)gameObject2).IsLocked()) { return(-8); } if (gameObject2.IsWall()) { return(-9); } } int x1 = gameObject1.GetX(); int y1 = gameObject1.GetY(); int x2 = gameObject2.GetX(); int y2 = gameObject2.GetY(); gameObject1.SetPositionXY(x2, y2); gameObject2.SetPositionXY(x1, y1); return(0); } return(-5); } } return(-4); } } return(-3); } return(-2); } return(-1); } return(-98); } return(-99); }
public override int Execute(LogicLevel level) { for (int i = 0; i < this.m_unitsCount.Size(); i++) { if (this.m_unitsCount[i] < 0) { return(-1); } } if (LogicDataTables.GetGlobals().EnableTroopDeletion() && level.GetState() == 1 && this.m_unitsData.Size() > 0) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); int removedUnits = 0; for (int i = 0; i < this.m_unitsData.Size(); i++) { LogicCombatItemData data = this.m_unitsData[i]; int unitCount = this.m_unitsCount[i]; if (this.m_removeType[i] != 0) { int upgLevel = this.m_unitsUpgLevel[i]; if (data.GetCombatItemType() != LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER) { if (data.GetCombatItemType() == LogicCombatItemData.COMBAT_ITEM_TYPE_SPELL) { playerAvatar.SetAllianceUnitCount(data, upgLevel, LogicMath.Max(0, playerAvatar.GetAllianceUnitCount(data, upgLevel) - unitCount)); if (unitCount > 0) { do { playerAvatar.GetChangeListener().AllianceUnitRemoved(data, upgLevel); } while (--unitCount != 0); } removedUnits |= 2; } } else { LogicBuilding allianceCastle = level.GetGameObjectManagerAt(0).GetAllianceCastle(); if (allianceCastle != null) { LogicBunkerComponent bunkerComponent = allianceCastle.GetBunkerComponent(); int unitTypeIndex = bunkerComponent.GetUnitTypeIndex(data); if (unitTypeIndex != -1) { int cnt = bunkerComponent.GetUnitCount(unitTypeIndex); if (cnt > 0) { bunkerComponent.RemoveUnits(data, upgLevel, unitCount); playerAvatar.SetAllianceUnitCount(data, upgLevel, LogicMath.Max(0, playerAvatar.GetAllianceUnitCount(data, upgLevel) - unitCount)); removedUnits |= 1; if (unitCount > 0) { do { playerAvatar.GetChangeListener().AllianceUnitRemoved(data, upgLevel); } while (--unitCount != 0); } } } } } } else { if (playerAvatar != null && data != null) { playerAvatar.CommodityCountChangeHelper(0, data, -unitCount); } LogicArrayList <LogicComponent> components = level.GetComponentManager().GetComponents(LogicComponentType.UNIT_STORAGE); for (int j = 0; j < components.Size(); j++) { if (unitCount > 0) { LogicUnitStorageComponent storageComponent = (LogicUnitStorageComponent)components[j]; int unitTypeIndex = storageComponent.GetUnitTypeIndex(data); if (unitTypeIndex != -1) { int cnt = storageComponent.GetUnitCount(unitTypeIndex); if (cnt > 0) { cnt = LogicMath.Min(cnt, unitCount); storageComponent.RemoveUnits(data, cnt); int type = 2; if (data.GetCombatItemType() == LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER) { if (storageComponent.GetParentListener() != null) { LogicGameObjectListener listener = storageComponent.GetParentListener(); for (int k = 0; k < cnt; k++) { listener.UnitRemoved(data); } } type = 1; } unitCount -= cnt; removedUnits |= type; } } } } } } switch (removedUnits) { case 3: if (LogicDataTables.GetGlobals().UseNewTraining()) { level.GetGameObjectManager().GetUnitProduction().MergeSlots(); level.GetGameObjectManager().GetSpellProduction().MergeSlots(); } break; case 2: if (LogicDataTables.GetGlobals().UseNewTraining()) { level.GetGameObjectManager().GetSpellProduction().MergeSlots(); } break; case 1: if (LogicDataTables.GetGlobals().UseNewTraining()) { level.GetGameObjectManager().GetUnitProduction().MergeSlots(); } break; } } return(0); }
/// <summary> /// Validates all troop upgrade levels. /// </summary> public void ValidateTroopUpgradeLevels() { LogicAvatar homeOwnerAvatar = this._level.GetHomeOwnerAvatar(); if (homeOwnerAvatar != null) { if (homeOwnerAvatar.IsClientAvatar()) { int[] laboratoryLevels = new int[2]; for (int i = 0; i < 2; i++) { LogicBuilding laboratory = this._level.GetGameObjectManagerAt(i).GetLaboratory(); if (laboratory != null) { laboratoryLevels[i] = laboratory.GetUpgradeLevel(); } } LogicDataTable characterTable = LogicDataTables.GetTable(3); if (characterTable.GetItemCount() > 0) { int idx = 0; do { LogicCharacterData characterData = (LogicCharacterData)characterTable.GetItemAt(idx); int upgradeLevel = homeOwnerAvatar.GetUnitUpgradeLevel(characterData); int villageType = characterData.GetVillageType(); int newUpgradeLevel = upgradeLevel; if (upgradeLevel >= characterData.GetUpgradeLevelCount()) { newUpgradeLevel = characterData.GetUpgradeLevelCount() - 1; } int laboratoryLevel = laboratoryLevels[villageType]; int requireLaboratoryLevel; do { requireLaboratoryLevel = characterData.GetRequiredLaboratoryLevel(newUpgradeLevel--); } while (newUpgradeLevel >= 0 && requireLaboratoryLevel > laboratoryLevel); newUpgradeLevel += 1; if (upgradeLevel > newUpgradeLevel) { homeOwnerAvatar.SetUnitUpgradeLevel(characterData, newUpgradeLevel); homeOwnerAvatar.GetChangeListener().CommodityCountChanged(1, characterData, newUpgradeLevel); } } while (++idx != characterTable.GetItemCount()); } LogicDataTable spellTable = LogicDataTables.GetTable(25); if (spellTable.GetItemCount() > 0) { int idx = 0; do { LogicSpellData spellData = (LogicSpellData)spellTable.GetItemAt(idx); int upgradeLevel = homeOwnerAvatar.GetUnitUpgradeLevel(spellData); int villageType = spellData.GetVillageType(); int newUpgradeLevel = upgradeLevel; if (upgradeLevel >= spellData.GetUpgradeLevelCount()) { newUpgradeLevel = spellData.GetUpgradeLevelCount() - 1; } int laboratoryLevel = laboratoryLevels[villageType]; int requireLaboratoryLevel; do { requireLaboratoryLevel = spellData.GetRequiredLaboratoryLevel(newUpgradeLevel--); } while (newUpgradeLevel >= 0 && requireLaboratoryLevel > laboratoryLevel); newUpgradeLevel += 1; if (upgradeLevel > newUpgradeLevel) { homeOwnerAvatar.SetUnitUpgradeLevel(spellData, newUpgradeLevel); homeOwnerAvatar.GetChangeListener().CommodityCountChanged(1, spellData, newUpgradeLevel); } } while (++idx != spellTable.GetItemCount()); } } } }
/// <summary> /// Loads this instance from json. /// </summary> public void Load(LogicJSONObject jsonObject) { this._json = jsonObject; if (jsonObject != null) { LogicJSONObject village1Object = jsonObject.GetJSONObject("Village1"); Debugger.DoAssert(village1Object != null, "pVillage1 = NULL!"); LogicJSONString specialObstacleObject = village1Object.GetJSONString("SpecialObstacle"); if (specialObstacleObject != null) { this._specialObstacle = LogicDataTables.GetObstacleByName(specialObstacleObject.GetStringValue()); } LogicJSONObject village2Object = jsonObject.GetJSONObject("Village2"); Debugger.DoAssert(village2Object != null, "pVillage2 = NULL!"); this._maxTownHallLevel = LogicJSONHelper.GetJSONNumber(village2Object, "TownHallMaxLevel"); LogicJSONArray scoreChangeForLosingArray = village2Object.GetJSONArray("ScoreChangeForLosing"); Debugger.DoAssert(scoreChangeForLosingArray != null, "ScoreChangeForLosing array is null"); this._milestoneScoreChangeForLosing = new LogicArrayList <int>(scoreChangeForLosingArray.Size()); this._percentageScoreChangeForLosing = new LogicArrayList <int>(scoreChangeForLosingArray.Size()); for (int i = 0; i < scoreChangeForLosingArray.Size(); i++) { LogicJSONObject obj = scoreChangeForLosingArray.GetJSONObject(i); if (obj != null) { LogicJSONNumber milestoneObject = obj.GetJSONNumber("Milestone"); LogicJSONNumber percentageObject = obj.GetJSONNumber("Percentage"); if (milestoneObject != null && percentageObject != null) { this._milestoneScoreChangeForLosing.Add(milestoneObject.GetIntValue()); this._percentageScoreChangeForLosing.Add(percentageObject.GetIntValue()); } } } LogicJSONArray strengthRangeForScoreArray = village2Object.GetJSONArray("StrengthRangeForScore"); Debugger.DoAssert(strengthRangeForScoreArray != null, "StrengthRangeForScore array is null"); this._milestoneStrengthRangeForScore = new LogicArrayList <int>(strengthRangeForScoreArray.Size()); this._percentageStrengthRangeForScore = new LogicArrayList <int>(strengthRangeForScoreArray.Size()); for (int i = 0; i < strengthRangeForScoreArray.Size(); i++) { LogicJSONObject obj = strengthRangeForScoreArray.GetJSONObject(i); if (obj != null) { LogicJSONNumber milestoneObject = obj.GetJSONNumber("Milestone"); LogicJSONNumber percentageObject = obj.GetJSONNumber("Percentage"); if (milestoneObject != null && percentageObject != null) { this._milestoneStrengthRangeForScore.Add(milestoneObject.GetIntValue()); this._percentageStrengthRangeForScore.Add(percentageObject.GetIntValue()); } } } LogicJSONObject killSwitchesObject = jsonObject.GetJSONObject("KillSwitches"); Debugger.DoAssert(killSwitchesObject != null, "pKillSwitches = NULL!"); this._battleWaitForProjectileDestruction = LogicJSONHelper.GetJSONBoolean(killSwitchesObject, "BattleWaitForProjectileDestruction"); this._battleWaitForDieDamage = LogicJSONHelper.GetJSONBoolean(killSwitchesObject, "BattleWaitForDieDamage"); LogicJSONObject globalsObject = jsonObject.GetJSONObject("Globals"); Debugger.DoAssert(globalsObject != null, "pGlobals = NULL!"); this._giftPackExtension = LogicJSONHelper.GetJSONString(globalsObject, "GiftPackExtension"); this._duelLootLimitCooldownInMinutes = LogicJSONHelper.GetJSONNumber(globalsObject, "DuelLootLimitCooldownInMinutes"); this._duelBonusLimitWinsPerDay = LogicJSONHelper.GetJSONNumber(globalsObject, "DuelBonusLimitWinsPerDay"); this._duelBonusPercentWin = LogicJSONHelper.GetJSONNumber(globalsObject, "DuelBonusPercentWin"); this._duelBonusPercentLose = LogicJSONHelper.GetJSONNumber(globalsObject, "DuelBonusPercentLose"); this._duelBonusPercentDraw = LogicJSONHelper.GetJSONNumber(globalsObject, "DuelBonusPercentDraw"); this._duelBonusMaxDiamondCostPercent = LogicJSONHelper.GetJSONNumber(globalsObject, "DuelBonusMaxDiamondCostPercent"); } else { Debugger.Error("pConfiguration = NULL!"); } }
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; LogicBuildingData buildingData = building.GetBuildingData(); if (buildingData.IsTownHallVillage2()) { if (!LogicUpgradeBuildingCommand.CanUpgradeTHV2(level)) { return(-76); } } if (buildingData.GetVillageType() == level.GetVillageType()) { if (level.GetGameObjectManager().GetAvailableBuildingUpgradeCount(building) <= 0) { return(-34); } if (building.GetWallIndex() == 0) { if (building.CanUpgrade(true)) { int nextUpgradeLevel = building.GetUpgradeLevel() + 1; int buildCost = buildingData.GetBuildCost(nextUpgradeLevel, level); LogicResourceData buildResourceData = this.m_useAltResource ? buildingData.GetAltBuildResource(nextUpgradeLevel) : buildingData.GetBuildResource(nextUpgradeLevel); if (buildResourceData != null) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (playerAvatar.HasEnoughResources(buildResourceData, buildCost, true, this, false)) { if (buildingData.GetConstructionTime(nextUpgradeLevel, level, 0) != 0 || LogicDataTables.GetGlobals().WorkerForZeroBuilTime()) { if (!level.HasFreeWorkers(this, -1)) { return(-1); } } playerAvatar.CommodityCountChangeHelper(0, buildResourceData, -buildCost); building.StartUpgrading(true, false); return(0); } } } return(-1); } return(-35); } return(-32); } if (gameObject.GetGameObjectType() == LogicGameObjectType.TRAP) { LogicTrap trap = (LogicTrap)gameObject; if (trap.CanUpgrade(true)) { LogicTrapData data = trap.GetTrapData(); LogicResourceData buildResourceData = data.GetBuildResource(); LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); int buildCost = data.GetBuildCost(trap.GetUpgradeLevel() + 1); if (playerAvatar.HasEnoughResources(buildResourceData, buildCost, true, this, false)) { if (data.GetBuildTime(trap.GetUpgradeLevel() + 1) != 0 || LogicDataTables.GetGlobals().WorkerForZeroBuilTime()) { if (!level.HasFreeWorkers(this, -1)) { return(-1); } } playerAvatar.CommodityCountChangeHelper(0, buildResourceData, -buildCost); trap.StartUpgrading(); return(0); } } } else if (gameObject.GetGameObjectType() == LogicGameObjectType.VILLAGE_OBJECT) { if (!this.m_useAltResource) { LogicVillageObject villageObject = (LogicVillageObject)gameObject; if (villageObject.CanUpgrade(true)) { LogicVillageObjectData data = villageObject.GetVillageObjectData(); LogicResourceData buildResourceData = data.GetBuildResource(); int buildCost = data.GetBuildCost(villageObject.GetUpgradeLevel() + 1); if (buildResourceData != null) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (playerAvatar.HasEnoughResources(buildResourceData, buildCost, true, this, false)) { if (data.GetBuildTime(villageObject.GetUpgradeLevel() + 1) != 0 || LogicDataTables.GetGlobals().WorkerForZeroBuilTime()) { if (!level.HasFreeWorkers(this, -1)) { return(-1); } } playerAvatar.CommodityCountChangeHelper(0, buildResourceData, -buildCost); villageObject.StartUpgrading(true); return(0); } } } return(-1); } return(-31); } } return(-1); }
public override int Execute(LogicLevel level) { if (this.m_excludeMemberList == null || this.m_excludeMemberList.Size() <= LogicDataTables.GetGlobals().GetWarMaxExcludeMembers()) { LogicAvatar homeOwnerAvatar = level.GetHomeOwnerAvatar(); if (homeOwnerAvatar.IsInAlliance()) { if (homeOwnerAvatar.GetAllianceRole() == LogicAvatarAllianceRole.LEADER || homeOwnerAvatar.GetAllianceRole() == LogicAvatarAllianceRole.CO_LEADER) { homeOwnerAvatar.GetChangeListener().StartWar(this.m_excludeMemberList); return(0); } return(-3); } return(-2); } return(-1); }
public static void CalculateCombatScore(LogicClientAvatar attacker, LogicClientAvatar defender, int stars, bool ignoreLeague, bool revenge, int destructionPercentage, int starBonusMultiplier, bool duelMatch) { int multiplier = stars; if (stars <= 0) { multiplier = LogicDataTables.GetGlobals().GetScoreMultiplierOnAttackLose(); } int attackerScore = attacker.GetScore(); int defenderScore = defender.GetScore(); LogicLeagueData attackerLeagueData = attacker.GetLeagueTypeData(); LogicLeagueData defenderLeagueData = defender.GetLeagueTypeData(); int newAttackerScore; int newDefenderScore; if (LogicDataTables.GetGlobals().EloOffsetDampeningEnabled()) { newAttackerScore = LogicELOMath.CalculateNewRating(stars > 0, attackerScore, defenderScore, 20 * multiplier, LogicDataTables.GetGlobals().GetEloDampeningFactor(), LogicDataTables.GetGlobals().GetEloDampeningLimit(), LogicDataTables.GetGlobals().GetEloDampeningScoreLimit()); newDefenderScore = LogicELOMath.CalculateNewRating(stars <= 0, defenderScore, attackerScore, 20 * multiplier, LogicDataTables.GetGlobals().GetEloDampeningFactor(), LogicDataTables.GetGlobals().GetEloDampeningLimit(), LogicDataTables.GetGlobals().GetEloDampeningScoreLimit()); } else { newAttackerScore = LogicELOMath.CalculateNewRating(stars > 0, attackerScore, defenderScore, 20 * multiplier); newDefenderScore = LogicELOMath.CalculateNewRating(stars <= 0, defenderScore, attackerScore, 20 * multiplier); } int attackerGainCount = newAttackerScore - attackerScore; int defenderGainCount = newDefenderScore - defenderScore; if (attackerScore < 1000 && attackerGainCount < 0) { attackerGainCount = attackerScore * attackerGainCount / 1000; } if (defenderScore < 1000 && defenderGainCount < 0) { defenderGainCount = defenderScore * defenderGainCount / 1000; } if (LogicELOMath.CalculateNewRating(true, attackerScore, defenderScore, 60) > attackerScore) { if (stars <= 0) { if (attackerGainCount >= 0) { attackerGainCount = -1; } } else { if (attackerGainCount <= 0) { attackerGainCount = 1; } if (defenderGainCount >= 0) { defenderGainCount = -1; } } } newAttackerScore = LogicMath.Max(attackerScore + attackerGainCount, 0); newDefenderScore = LogicMath.Max(defenderScore + defenderGainCount, 0); if (!ignoreLeague) { attacker.SetScore(newAttackerScore); defender.SetScore(newDefenderScore); if (LogicDataTables.GetGlobals().EnableLeagues()) { if (!duelMatch) { if (attackerLeagueData != null) { if (stars <= 0) { attacker.SetAttackLoseCount(attacker.GetAttackLoseCount() + 1); } else { attacker.SetAttackWinCount(attacker.GetAttackWinCount() + 1); } } if (defenderLeagueData != null) { if (stars > 0) { defender.SetDefenseLoseCount(defender.GetDefenseLoseCount() + 1); } else { defender.SetDefenseWinCount(defender.GetDefenseLoseCount() + 1); } } if (stars > 0) { if (!revenge || LogicDataTables.GetGlobals().RevengeGiveLeagueBonus()) { int leagueBonusPercentage = LogicDataTables.GetGlobals().GetLeagueBonusPercentage(destructionPercentage); attacker.CommodityCountChangeHelper(0, LogicDataTables.GetGoldData(), attackerLeagueData.GetGoldReward() * leagueBonusPercentage / 100); attacker.CommodityCountChangeHelper(0, LogicDataTables.GetElixirData(), attackerLeagueData.GetElixirReward() * leagueBonusPercentage / 100); if (attacker.IsDarkElixirUnlocked()) { attacker.CommodityCountChangeHelper(0, LogicDataTables.GetDarkElixirData(), attackerLeagueData.GetDarkElixirReward() * leagueBonusPercentage / 100); } } } LogicGamePlayUtil.UpdateLeagueRank(attacker, newAttackerScore, false); LogicGamePlayUtil.UpdateLeagueRank(defender, newDefenderScore, true); } } } attacker.GetChangeListener().ScoreChanged(attacker.GetCurrentHomeId(), attackerGainCount, stars > 0 ? 1 : -1, true, attacker.GetLeagueTypeData(), attackerLeagueData, destructionPercentage); defender.GetChangeListener().ScoreChanged(defender.GetCurrentHomeId(), defenderGainCount, stars > 0 ? -1 : 1, false, defender.GetLeagueTypeData(), defenderLeagueData, destructionPercentage); if (stars > 0 && !ignoreLeague && !duelMatch && (!revenge || LogicDataTables.GetGlobals().RevengeGiveStarBonus()) && !attacker.GetStarBonusCooldown()) { int totalStars = stars + attacker.GetStarBonusCounter(); if (totalStars >= LogicDataTables.GetGlobals().GetStarBonusStarCount()) { LogicLeagueData leagueData = attacker.GetLeagueTypeData(); attacker.AddStarBonusReward(leagueData.GetGoldRewardStarBonus() * starBonusMultiplier, leagueData.GetElixirRewardStarBonus() * starBonusMultiplier, leagueData.GetDarkElixirRewardStarBonus() * starBonusMultiplier); attacker.StarBonusCollected(); if (LogicDataTables.GetGlobals().AllowStarsOverflowInStarBonus() && !attacker.GetStarBonusCooldown()) { totalStars %= LogicDataTables.GetGlobals().GetStarBonusStarCount(); } else { totalStars = 0; } } attacker.SetStarBonusCounter(totalStars); } }