public override int Execute(LogicLevel level) { if (this.m_decoData != null) { if (this.m_decoData.GetVillageType() == level.GetVillageType()) { if (level.IsValidPlaceForBuilding(this.m_x, this.m_y, this.m_decoData.GetWidth(), this.m_decoData.GetHeight(), null)) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); LogicResourceData buildResourceData = this.m_decoData.GetBuildResource(); int buildCost = this.m_decoData.GetBuildCost(); if (playerAvatar.HasEnoughResources(buildResourceData, buildCost, true, this, false) && !level.IsDecoCapReached(this.m_decoData, true)) { if (buildResourceData.IsPremiumCurrency()) { playerAvatar.UseDiamonds(buildCost); playerAvatar.GetChangeListener().DiamondPurchaseMade(1, this.m_decoData.GetGlobalID(), 0, buildCost, level.GetVillageType()); } else { playerAvatar.CommodityCountChangeHelper(0, buildResourceData, -buildCost); } LogicDeco deco = (LogicDeco)LogicGameObjectFactory.CreateGameObject(this.m_decoData, level, level.GetVillageType()); deco.SetInitialPosition(this.m_x << 9, this.m_y << 9); level.GetGameObjectManager().AddGameObject(deco, -1); int width = deco.GetWidthInTiles(); int height = deco.GetHeightInTiles(); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { LogicObstacle tallGrass = level.GetTileMap().GetTile(this.m_x + i, this.m_y + j).GetTallGrass(); if (tallGrass != null) { level.GetGameObjectManager().RemoveGameObject(tallGrass); } } } return(0); } } return(-1); } return(-32); } return(-1); }
public override int Execute(LogicLevel level) { LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObjectId); if (gameObject != null) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding building = (LogicBuilding)gameObject; if (building.CanSell()) { playerAvatar.CommodityCountChangeHelper(0, building.GetSellResource(), building.GetSellPrice()); building.OnSell(); level.GetGameObjectManager().RemoveGameObject(building); return(0); } } else if (gameObject.GetGameObjectType() == LogicGameObjectType.DECO) { LogicDeco deco = (LogicDeco)gameObject; LogicDecoData data = deco.GetDecoData(); LogicResourceData buildResourceData = data.GetBuildResource(); int sellPrice = data.GetSellPrice(); if (buildResourceData.IsPremiumCurrency()) { playerAvatar.SetDiamonds(playerAvatar.GetDiamonds() + sellPrice); playerAvatar.SetFreeDiamonds(playerAvatar.GetFreeDiamonds() + sellPrice); playerAvatar.GetChangeListener().FreeDiamondsAdded(sellPrice, 6); } else { playerAvatar.CommodityCountChangeHelper(0, buildResourceData, sellPrice); } level.GetGameObjectManager().RemoveGameObject(deco); return(0); } } return(-1); }
public void DivideAvatarResourcesToStorages() { LogicAvatar homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar(); if (homeOwnerAvatar != null) { LogicArrayList <LogicComponent> resourceStorageComponents = this.m_components[(int)LogicComponentType.RESOURCE_STORAGE]; LogicArrayList <LogicComponent> warResourceStorageComponents = this.m_components[(int)LogicComponentType.WAR_RESOURCE_STORAGE]; LogicDataTable resourceTable = LogicDataTables.GetTable(LogicDataType.RESOURCE); for (int i = 0; i < resourceTable.GetItemCount(); i++) { LogicResourceData data = (LogicResourceData)resourceTable.GetItemAt(i); if (!data.IsPremiumCurrency()) { if (data.GetWarResourceReferenceData() != null) { Debugger.DoAssert(warResourceStorageComponents.Size() < 2, "Too many war storage components"); for (int j = 0; j < warResourceStorageComponents.Size(); j++) { LogicWarResourceStorageComponent warResourceStorageComponent = (LogicWarResourceStorageComponent)warResourceStorageComponents[j]; warResourceStorageComponent.SetCount(i, homeOwnerAvatar.GetResourceCount(data)); } } else { for (int j = 0; j < resourceStorageComponents.Size(); j++) { ((LogicResourceStorageComponent)resourceStorageComponents[j]).SetCount(i, 0); } int resourceCount = homeOwnerAvatar.GetResourceCount(data); if (this.m_level.GetBattleLog() != null && data.GetVillageType() == 1) { resourceCount = LogicMath.Max(resourceCount - this.m_level.GetBattleLog().GetCostCount(data), 0); } this.AddResources(i, resourceCount, true); } } } } }
public override void Save(LogicJSONObject jsonObject, int villageType) { LogicDataTable resourceTable = LogicDataTables.GetTable(LogicDataType.RESOURCE); for (int i = 0; i < resourceTable.GetItemCount(); i++) { LogicResourceData resourceData = (LogicResourceData)resourceTable.GetItemAt(i); if (!resourceData.IsPremiumCurrency() && resourceData.GetWarResourceReferenceData() == null) { if (LogicDataTables.GetGoldData() == resourceData) { int count = this.GetResourceCount(i); if (count > 0) { jsonObject.Put("defg", new LogicJSONNumber(count)); } } else if (LogicDataTables.GetElixirData() == resourceData) { int count = this.GetResourceCount(i); if (count > 0) { jsonObject.Put("defe", new LogicJSONNumber(count)); } } else if (LogicDataTables.GetDarkElixirData() == resourceData) { int count = this.GetResourceCount(i); if (count > 0) { jsonObject.Put("defde", new LogicJSONNumber(count)); } } } } }
public override void Load(LogicJSONObject jsonObject) { LogicDataTable resourceTable = LogicDataTables.GetTable(LogicDataType.RESOURCE); for (int i = 0; i < resourceTable.GetItemCount(); i++) { LogicResourceData resourceData = (LogicResourceData)resourceTable.GetItemAt(i); if (!resourceData.IsPremiumCurrency() && resourceData.GetWarResourceReferenceData() == null) { if (LogicDataTables.GetGoldData() == resourceData) { LogicJSONNumber count = jsonObject.GetJSONNumber("defg"); if (count != null) { this.SetResourceCount(i, count.GetIntValue()); } } else if (LogicDataTables.GetElixirData() == resourceData) { LogicJSONNumber count = jsonObject.GetJSONNumber("defe"); if (count != null) { this.SetResourceCount(i, count.GetIntValue()); } } else if (LogicDataTables.GetDarkElixirData() == resourceData) { LogicJSONNumber count = jsonObject.GetJSONNumber("defde"); if (count != null) { this.SetResourceCount(i, count.GetIntValue()); } } } } }
public LogicObstacle(LogicGameObjectData data, LogicLevel level, int villageType) : base(data, level, villageType) { LogicObstacleData obstacleData = this.GetObstacleData(); if (obstacleData.GetSpawnObstacle() != null) { this.AddComponent(new LogicSpawnerComponent(this, obstacleData.GetSpawnObstacle(), obstacleData.GetSpawnRadius(), obstacleData.GetSpawnIntervalSeconds(), obstacleData.GetSpawnCount(), obstacleData.GetMaxSpawned(), obstacleData.GetMaxLifetimeSpawns())); } if (obstacleData.IsLootCart()) { LogicLootCartComponent logicLootCartComponent = new LogicLootCartComponent(this); LogicDataTable resourceTable = LogicDataTables.GetTable(LogicDataType.RESOURCE); LogicBuilding townHall = this.GetGameObjectManager().GetTownHall(); LogicArrayList <int> capacityCount = new LogicArrayList <int>(); for (int i = 0, cap = 0; i < resourceTable.GetItemCount(); i++, cap = 0) { LogicResourceData resourceData = (LogicResourceData)resourceTable.GetItemAt(i); if (townHall != null) { if (!resourceData.IsPremiumCurrency() && resourceData.GetWarResourceReferenceData() == null) { cap = LogicDataTables.GetTownHallLevel(townHall.GetUpgradeLevel()).GetCartLootCap(resourceData); } } capacityCount.Add(cap); } logicLootCartComponent.SetCapacityCount(capacityCount); this.AddComponent(logicLootCartComponent); } }
public void ClearingFinished(bool ignoreState) { int state = this.m_level.GetState(); if (state == 1 || !LogicDataTables.GetGlobals().CompleteConstructionOnlyHome() && ignoreState) { if (this.m_level.GetHomeOwnerAvatar().IsClientAvatar()) { LogicClientAvatar homeOwnerAvatar = (LogicClientAvatar)this.m_level.GetHomeOwnerAvatar(); LogicObstacleData obstacleData = this.GetObstacleData(); LogicResourceData lootResourceData = obstacleData.GetLootResourceData(); int lootCount = obstacleData.GetLootCount(); if (obstacleData.IsLootCart()) { LogicLootCartComponent lootCartComponent = (LogicLootCartComponent)this.GetComponent(LogicComponentType.LOOT_CART); if (lootCartComponent != null) { LogicDataTable resourceTable = LogicDataTables.GetTable(LogicDataType.RESOURCE); bool empty = true; for (int i = 0; i < resourceTable.GetItemCount(); i++) { LogicResourceData resourceData = (LogicResourceData)resourceTable.GetItemAt(i); if (!resourceData.IsPremiumCurrency() && resourceData.GetWarResourceReferenceData() == null) { int resourceCount = lootCartComponent.GetResourceCount(i); int rewardCount = LogicMath.Min(homeOwnerAvatar.GetUnusedResourceCap(resourceData), resourceCount); int remainingCount = resourceCount - rewardCount; if (rewardCount > 0) { homeOwnerAvatar.CommodityCountChangeHelper(0, resourceData, rewardCount); lootCartComponent.SetResourceCount(i, remainingCount); } if (remainingCount > 0) { empty = false; } } } if (!empty) { return; } } } if (!obstacleData.IsTombstone() && !obstacleData.IsLootCart()) { this.m_level.GetAchievementManager().ObstacleCleared(); } this.m_level.GetWorkerManagerAt(this.m_villageType).DeallocateWorker(this); this.XpGainHelper(LogicGamePlayUtil.TimeToExp(obstacleData.GetClearTime()), homeOwnerAvatar, ignoreState || state == 1); if (lootResourceData != null && lootCount > 0) { if (homeOwnerAvatar != null) { if (lootResourceData.IsPremiumCurrency()) { int lootMultipler = 1; if (this.m_lootMultiplyVersion >= 2) { lootMultipler = obstacleData.GetLootMultiplierVersion2(); } int diamondsCount = obstacleData.GetName().Equals("Bonus Gembox") ? lootCount * lootMultipler : this.m_level.GetGameObjectManagerAt(this.m_villageType).IncreaseObstacleClearCounter(lootMultipler); if (diamondsCount > 0) { homeOwnerAvatar.SetDiamonds(homeOwnerAvatar.GetDiamonds() + diamondsCount); homeOwnerAvatar.SetFreeDiamonds(homeOwnerAvatar.GetFreeDiamonds() + diamondsCount); homeOwnerAvatar.GetChangeListener().FreeDiamondsAdded(diamondsCount, 6); } } else { int gainCount = LogicMath.Min(homeOwnerAvatar.GetUnusedResourceCap(lootResourceData), lootCount); if (gainCount > 0) { homeOwnerAvatar.CommodityCountChangeHelper(0, lootResourceData, gainCount); } } } else { Debugger.Error("LogicObstacle::clearingFinished - Home owner avatar is NULL!"); } } if (obstacleData.IsEnabledInVillageType(this.m_level.GetVillageType())) { // ? } if (this.m_clearTimer != null) { this.m_clearTimer.Destruct(); this.m_clearTimer = null; } this.m_fadeTime = 1; } } }
public virtual void RecalculateAvailableLoot() { int matchType = this.m_parent.GetLevel().GetMatchType(); LogicAvatar homeOwnerAvatar = this.m_parent.GetLevel().GetHomeOwnerAvatar(); LogicAvatar visitorAvatar = this.m_parent.GetLevel().GetVisitorAvatar(); LogicDataTable resourceTable = LogicDataTables.GetTable(LogicDataType.RESOURCE); for (int i = 0; i < this.m_resourceCount.Size(); i++) { LogicResourceData data = (LogicResourceData)resourceTable.GetItemAt(i); int resourceCount = this.m_resourceCount[i]; if (!homeOwnerAvatar.IsNpcAvatar()) { if (matchType == 5 && this.m_parent.GetLevel().IsArrangedWar()) { if (resourceCount >= 0) { resourceCount = 0; } } else if (LogicDataTables.GetGlobals().UseTownHallLootPenaltyInWar() || matchType != 5) { if (matchType != 8 && matchType != 9) { int multiplier = 100; int calculateAvailableLootCount = 0; if (homeOwnerAvatar != null && homeOwnerAvatar.IsClientAvatar() && visitorAvatar != null && visitorAvatar.IsClientAvatar()) { multiplier = LogicDataTables.GetGlobals().GetLootMultiplierByTownHallDiff(visitorAvatar.GetTownHallLevel(), homeOwnerAvatar.GetTownHallLevel()); } if (this.m_parent.GetData() == LogicDataTables.GetTownHallData() && LogicDataTables.GetGlobals().GetTownHallLootPercentage() != -1) { calculateAvailableLootCount = resourceCount * (multiplier * LogicDataTables.GetGlobals().GetTownHallLootPercentage() / 100) / 100; } else if (!data.IsPremiumCurrency()) { int townHallLevel = homeOwnerAvatar.GetTownHallLevel(); int lootableResourceCount = 0; if (matchType != 3) { if (matchType == 5) { lootableResourceCount = resourceCount; } else if (matchType != 7) { lootableResourceCount = (int)((long)resourceCount * LogicDataTables.GetTownHallLevel(townHallLevel).GetStorageLootPercentage(data) / 100); } } int storageLootCap = LogicDataTables.GetTownHallLevel(townHallLevel).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) { if (storageLootCap < 1000) { clampedValue = (resourceCount * storageLootCap + (maxResourceCount >> 1)) / maxResourceCount; } else { if (!LogicDataTables.GetGlobals().UseMoreAccurateLootCap()) { clampedValue = 100 * ((resourceCount * (storageLootCap / 100) + (maxResourceCount >> 1)) / maxResourceCount); } else { if (resourceCount / 100 > maxResourceCount / storageLootCap) { clampedValue = 100 * ((resourceCount * (storageLootCap / 100) + (maxResourceCount >> 1)) / maxResourceCount); } else { clampedValue = (resourceCount * storageLootCap + (maxResourceCount >> 1)) / maxResourceCount; } } } } else { if (!LogicDataTables.GetGlobals().UseMoreAccurateLootCap()) { clampedValue = 1000 * ((resourceCount * (storageLootCap / 1000) + (maxResourceCount >> 1)) / maxResourceCount); } else { if (resourceCount / 1000 > maxResourceCount / storageLootCap) { clampedValue = 1000 * ((resourceCount * (storageLootCap / 1000) + (maxResourceCount >> 1)) / maxResourceCount); } else { if (resourceCount / 100 > maxResourceCount / storageLootCap) { clampedValue = 100 * ((resourceCount * (storageLootCap / 100) + (maxResourceCount >> 1)) / maxResourceCount); } else { clampedValue = (resourceCount * storageLootCap + (maxResourceCount >> 1)) / maxResourceCount; } } } } } else { if (!LogicDataTables.GetGlobals().UseMoreAccurateLootCap()) { clampedValue = 10000 * ((resourceCount * (storageLootCap / 10000) + (maxResourceCount >> 1)) / maxResourceCount); } else { if (resourceCount / 10000 > maxResourceCount / storageLootCap) { clampedValue = 10000 * ((resourceCount * (storageLootCap / 10000) + (maxResourceCount >> 1)) / maxResourceCount); } else { if (resourceCount / 1000 > maxResourceCount / storageLootCap) { clampedValue = 1000 * ((resourceCount * (storageLootCap / 1000) + (maxResourceCount >> 1)) / maxResourceCount); } else { if (resourceCount / 100 > maxResourceCount / storageLootCap) { clampedValue = 100 * ((resourceCount * (storageLootCap / 100) + (maxResourceCount >> 1)) / maxResourceCount); } else { clampedValue = (resourceCount * storageLootCap + (maxResourceCount >> 1)) / maxResourceCount; } } } } } } else { clampedValue = 40000 * ((resourceCount * (storageLootCap / 40000) + (maxResourceCount >> 1)) / maxResourceCount); } if (lootableResourceCount > clampedValue) { lootableResourceCount = clampedValue; } } calculateAvailableLootCount = multiplier * lootableResourceCount / 100; } if (calculateAvailableLootCount <= resourceCount) { resourceCount = calculateAvailableLootCount; } } } } this.m_stealableResourceCount[i] = resourceCount; } }
public override int Execute(LogicLevel level) { int villageType = level.GetVillageType(); if (this.m_buildingData.GetVillageType() == villageType) { if (this.m_buildingData.GetWallBlockCount() <= 1 && this.m_buildingData.GetBuildingClass().CanBuy()) { if (level.IsValidPlaceForBuilding(this.m_x, this.m_y, this.m_buildingData.GetWidth(), this.m_buildingData.GetHeight(), null) && !level.IsBuildingCapReached(this.m_buildingData, true)) { if (level.GetCalendar().IsEnabled(this.m_buildingData)) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); LogicResourceData buildResourceData = this.m_buildingData.GetBuildResource(0); int buildResourceCost = this.m_buildingData.GetBuildCost(0, level); if (playerAvatar.HasEnoughResources(buildResourceData, buildResourceCost, true, this, false)) { if (this.m_buildingData.IsWorkerBuilding() || this.m_buildingData.GetConstructionTime(0, level, 0) <= 0 && !LogicDataTables.GetGlobals().WorkerForZeroBuilTime() || level.HasFreeWorkers(this, -1)) { if (buildResourceData.IsPremiumCurrency()) { playerAvatar.UseDiamonds(buildResourceCost); playerAvatar.GetChangeListener().DiamondPurchaseMade(1, this.m_buildingData.GetGlobalID(), 0, buildResourceCost, villageType); } else { playerAvatar.CommodityCountChangeHelper(0, buildResourceData, -buildResourceCost); } LogicBuilding building = (LogicBuilding)LogicGameObjectFactory.CreateGameObject(this.m_buildingData, level, villageType); building.SetInitialPosition(this.m_x << 9, this.m_y << 9); level.GetGameObjectManager().AddGameObject(building, -1); building.StartConstructing(false); if (this.m_buildingData.IsWall() && level.IsBuildingCapReached(this.m_buildingData, false)) { level.GetGameListener().BuildingCapReached(this.m_buildingData); } int width = building.GetWidthInTiles(); int height = building.GetHeightInTiles(); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { LogicObstacle tallGrass = level.GetTileMap().GetTile(this.m_x + i, this.m_y + j).GetTallGrass(); if (tallGrass != null) { level.GetGameObjectManager().RemoveGameObject(tallGrass); } } } } } return(0); } } } return(-33); } return(-32); }
public void SetBattleOver() { if (this.m_battleOver) { return; } this.m_level.GetBattleLog().SetBattleEnded(LogicDataTables.GetGlobals().GetAttackLengthSecs() - this.GetRemainingAttackSeconds()); this.m_level.GetMissionManager().Tick(); LogicArrayList <LogicComponent> components = this.m_level.GetComponentManager().GetComponents(LogicComponentType.COMBAT); for (int i = 0; i < components.Size(); i++) { ((LogicCombatComponent)components[i]).Boost(0, 0, 0); } bool duelMatch = (this.m_level.GetMatchType() & 0xFFFFFFFE) == 8; if (duelMatch) { LogicAvatar avatar = this.m_level.GetVisitorAvatar(); if (avatar != null && avatar.IsClientAvatar()) { ((LogicClientAvatar)avatar).RemoveUnitsVillage2(); } } if (this.m_state == 3) { this.EndDefendState(); } else { LogicBattleLog battleLog = this.m_level.GetBattleLog(); if (battleLog.GetBattleStarted()) { LogicAvatar visitorAvatar = this.m_level.GetVisitorAvatar(); LogicAvatar homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar(); int stars = battleLog.GetStars(); if (!this.m_level.GetVisitorAvatar().IsClientAvatar() || !this.m_level.GetHomeOwnerAvatar().IsClientAvatar()) { if (visitorAvatar.IsClientAvatar() && homeOwnerAvatar.IsNpcAvatar()) { LogicNpcAvatar npcAvatar = (LogicNpcAvatar)homeOwnerAvatar; LogicNpcData npcData = npcAvatar.GetNpcData(); int npcStars = visitorAvatar.GetNpcStars(npcData); if (stars > npcStars && npcData.IsSinglePlayer()) { visitorAvatar.SetNpcStars(npcData, stars); visitorAvatar.GetChangeListener().CommodityCountChanged(0, npcData, stars); } // TODO: LogicBattleLog::sendNpcAttackEndEvents. } } else { LogicClientAvatar attacker = (LogicClientAvatar)visitorAvatar; LogicClientAvatar defender = (LogicClientAvatar)homeOwnerAvatar; int originalAttackerScore = attacker.GetScore(); int originalDefenderScore = defender.GetScore(); int matchType = this.m_level.GetMatchType(); if (matchType == 1 || !LogicDataTables.GetGlobals().ScoringOnlyFromMatchedMode() && (matchType == 0 || matchType == 2 || matchType == 4 || matchType == 6)) { LogicGamePlayUtil.CalculateCombatScore(attacker, defender, stars, false, matchType == 4, battleLog.GetDestructionPercentage(), this.m_calendar.GetStarBonusMultiplier(), duelMatch); if (!duelMatch && homeOwnerAvatar.GetTownHallLevel() >= LogicDataTables.GetGlobals().GetLootCartEnabledTownHall()) { LogicDataTable resourceTable = LogicDataTables.GetTable(LogicDataType.RESOURCE); if (resourceTable.GetItemCount() > 0) { bool hasStolen = false; for (int i = 0; i < resourceTable.GetItemCount(); i++) { LogicResourceData data = (LogicResourceData)resourceTable.GetItemAt(i); if (!data.IsPremiumCurrency()) { if (battleLog.GetStolenResources(data) > 0) { hasStolen = true; } } } if (hasStolen) { LogicGameObjectManager gameObjectManager = this.m_level.GetGameObjectManagerAt(0); LogicObstacle lootCart = gameObjectManager.GetLootCart(); if (lootCart == null) { gameObjectManager.AddLootCart(); lootCart = gameObjectManager.GetLootCart(); } if (lootCart != null) { LogicLootCartComponent lootCartComponent = lootCart.GetLootCartComponent(); if (lootCartComponent != null) { for (int i = 0; i < resourceTable.GetItemCount(); i++) { LogicResourceData data = (LogicResourceData)resourceTable.GetItemAt(i); if (!data.IsPremiumCurrency() && data.GetWarResourceReferenceData() == null) { int lootPercentage = lootCart.GetObstacleData().GetLootDefensePercentage(); int lootCount = battleLog.GetStolenResources(data) * lootPercentage / 100; lootCartComponent.SetResourceCount(i, LogicMath.Min(LogicMath.Max(lootCount, lootCartComponent.GetResourceCount(i)), lootCartComponent.GetCapacityCount(i))); } } } } } } } this.m_level.UpdateBattleShieldStatus(false); if (stars > 0) { LogicArrayList <LogicDataSlot> castedUnits = battleLog.GetCastedUnits(); LogicArrayList <LogicDataSlot> castedSpells = battleLog.GetCastedSpells(); LogicArrayList <LogicUnitSlot> castedAllianceUnits = battleLog.GetCastedAllianceUnits(); LogicArrayList <LogicDataSlot> placedUnits = new LogicArrayList <LogicDataSlot>(castedUnits.Size()); for (int i = 0; i < castedUnits.Size(); i++) { placedUnits.Add(new LogicDataSlot(castedUnits[i].GetData(), castedUnits[i].GetCount())); } for (int i = 0; i < castedSpells.Size(); i++) { int idx = -1; for (int j = 0; j < placedUnits.Size(); j++) { if (placedUnits[j].GetData() == castedSpells[i].GetData()) { idx = j; break; } } if (idx != -1) { placedUnits[idx].SetCount(placedUnits[idx].GetCount() + castedSpells[i].GetCount()); } else { placedUnits.Add(new LogicDataSlot(castedSpells[i].GetData(), castedSpells[i].GetCount())); } } for (int i = 0; i < castedAllianceUnits.Size(); i++) { placedUnits.Add(new LogicDataSlot(castedAllianceUnits[i].GetData(), castedAllianceUnits[i].GetCount())); } for (int i = 0; i < placedUnits.Size(); i++) { LogicCombatItemData data = (LogicCombatItemData)placedUnits[i].GetData(); LogicCalendarUseTroop calendarUseTroopEvent = this.m_calendar.GetUseTroopEvents(data); if (calendarUseTroopEvent != null) { int count = attacker.GetEventUnitCounterCount(data); if (placedUnits[i].GetCount() >= count >> 16) { int progressCount = (short)count + 1; int eventCounter = progressCount | (int)(count & 0xFFFF0000); attacker.SetCommodityCount(6, data, eventCounter); attacker.GetChangeListener().CommodityCountChanged(6, data, eventCounter); if (calendarUseTroopEvent.GetParameter(0) == progressCount) { int diamonds = calendarUseTroopEvent.GetParameter(2); int xp = calendarUseTroopEvent.GetParameter(3); attacker.XpGainHelper(xp); attacker.SetDiamonds(attacker.GetDiamonds() + diamonds); attacker.SetFreeDiamonds(attacker.GetFreeDiamonds() + diamonds); attacker.GetChangeListener().FreeDiamondsAdded(diamonds, 9); Debugger.HudPrint(string.Format("USE TROOP Event: Awarding XP: {0} GEMS {1}", xp, diamonds)); } } } } for (int i = 0; i < placedUnits.Size(); i++) { placedUnits[i].Destruct(); } placedUnits.Destruct(); } } if (this.m_state != 5 && this.m_level.GetDefenseShieldActivatedHours() == 0 && battleLog.GetDestructionPercentage() > 0) { int defenseVillageGuardCounter = defender.GetDefenseVillageGuardCounter() + 1; defender.SetDefenseVillageGuardCounter(defenseVillageGuardCounter); defender.GetChangeListener().DefenseVillageGuardCounterChanged(defenseVillageGuardCounter); int villageGuardMins = (defenseVillageGuardCounter & 0xFFFFFF) == 3 * ((defenseVillageGuardCounter & 0xFFFFFF) / 3) ? defender.GetLeagueTypeData().GetVillageGuardInMins() : LogicDataTables.GetGlobals().GetDefaultDefenseVillageGuard(); this.m_level.GetHome().GetChangeListener().GuardActivated(60 * villageGuardMins); Debugger.HudPrint(string.Format("Battle end. No Shield, Village Guard for defender: {0}", villageGuardMins)); } battleLog.SetAttackerScore(attacker.GetScore() - originalAttackerScore); battleLog.SetDefenderScore(defender.GetScore() - originalDefenderScore); battleLog.SetOriginalAttackerScore(originalAttackerScore); battleLog.SetOriginalDefenderScore(originalDefenderScore); if (this.m_state != 5) { if (stars != 0) { if (matchType != 3 && matchType != 7 && matchType != 8 && matchType != 9) { if (matchType == 5) { if (stars > this.m_level.GetPreviousAttackStars() && !this.m_level.GetIgnoreAttack()) { this.m_level.GetAchievementManager().IncreaseWarStars(stars); } } else { this.m_level.GetAchievementManager().PvpAttackWon(); } } } else if (matchType > 9 || matchType == 3 || matchType == 5 || matchType == 7 || matchType == 8 || matchType == 9) { this.m_level.GetAchievementManager().PvpDefenseWon(); } } } } } this.m_battleOver = true; }
public override int Execute(LogicLevel level) { if (level.GetVillageType() == 1) { if (this.m_buildingData != null && this.m_buildingData.GetBuildingClass().CanBuy() && this.m_buildingData.IsWall()) { if (this.m_buildingData.GetWallBlockCount() != 0) { if (this.m_buildingData.GetWallBlockCount() == this.m_position.Size()) { if (this.m_position.Size() <= 10) { for (int i = 0, nIdx = -1; i < this.m_position.Size(); i++) { LogicVector2 firstPosition = this.m_position[0]; LogicVector2 position = this.m_position[i]; if (i > 0) { int shapeIdx = this.m_buildingData.GetWallBlockIndex(position.m_x - firstPosition.m_x, position.m_y - firstPosition.m_y, i); if (nIdx == -1) { nIdx = shapeIdx; } if (shapeIdx == -1 || shapeIdx != nIdx) { Debugger.Error("LogicBuyWallBlockCommand shape incorrect"); return(-4); } nIdx = shapeIdx; } if (!level.IsValidPlaceForBuilding(position.m_x, position.m_y, this.m_buildingData.GetWidth(), this.m_buildingData.GetHeight(), null)) { Debugger.Error("LogicBuyWallBlockCommand invalid place."); return(-5); } } if (!level.IsBuildingCapReached(this.m_buildingData, true)) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); LogicResourceData buildResource = this.m_buildingData.GetBuildResource(0); int buildCost = this.m_buildingData.GetBuildCost(0, level); if (playerAvatar.HasEnoughResources(buildResource, buildCost, true, this, false)) { if (this.m_buildingData.IsWorkerBuilding() || this.m_buildingData.GetConstructionTime(0, level, 0) <= 0 && !LogicDataTables.GetGlobals().WorkerForZeroBuilTime() || level.HasFreeWorkers(this, -1)) { if (buildResource.IsPremiumCurrency()) { playerAvatar.UseDiamonds(buildCost); playerAvatar.GetChangeListener().DiamondPurchaseMade(1, this.m_buildingData.GetGlobalID(), 0, buildCost, level.GetVillageType()); } else { playerAvatar.CommodityCountChangeHelper(0, buildResource, -buildCost); } LogicGameObjectManager gameObjectManager = level.GetGameObjectManager(); int wallIndex = gameObjectManager.GetHighestWallIndex(this.m_buildingData); for (int i = 0; i < this.m_position.Size(); i++) { LogicVector2 position = this.m_position[i]; LogicBuilding building = (LogicBuilding)LogicGameObjectFactory.CreateGameObject(this.m_buildingData, level, level.GetVillageType()); building.StartConstructing(false); building.SetInitialPosition(position.m_x << 9, position.m_y << 9); building.SetWallObjectId(wallIndex, i, i == 0); gameObjectManager.AddGameObject(building, -1); int width = building.GetWidthInTiles(); int height = building.GetHeightInTiles(); for (int j = 0; j < width; j++) { for (int k = 0; k < height; k++) { LogicObstacle tallGrass = level.GetTileMap().GetTile(position.m_x + j, position.m_y + k).GetTallGrass(); if (tallGrass != null) { level.GetGameObjectManager().RemoveGameObject(tallGrass); } } } } } } } return(0); } return(-3); } return(-2); } return(-1); } return(0); } return(-32); }