public void ReengageLootCart(int secs) { LogicObstacleData obstacleData = this.GetObstacleData(); LogicLootCartComponent lootCartComponent = (LogicLootCartComponent)this.GetComponent(LogicComponentType.LOOT_CART); LogicBuilding townHall = this.m_level.GetGameObjectManagerAt(0).GetTownHall(); Debugger.DoAssert(obstacleData.IsLootCart(), string.Empty); Debugger.DoAssert(lootCartComponent != null, string.Empty); Debugger.DoAssert(townHall != null, string.Empty); LogicDataTable resourceTable = LogicDataTables.GetTable(LogicDataType.RESOURCE); for (int i = 0; i < resourceTable.GetItemCount(); i++) { LogicResourceData resourceData = (LogicResourceData)resourceTable.GetItemAt(i); LogicTownhallLevelData townhallLevelData = LogicDataTables.GetTownHallLevel(townHall.GetUpgradeLevel()); int cap = secs * townhallLevelData.GetCartLootReengagement(resourceData) / 100; if (cap > lootCartComponent.GetResourceCount(i)) { lootCartComponent.SetResourceCount(i, cap); } } }
public void AddTombstoneIfNeeded() { if (!this.m_ejected && this.m_level.GetTombStoneCount() < 40) { int tileX = this.GetTileX(); int tileY = this.GetTileY(); LogicTileMap tileMap = this.m_level.GetTileMap(); LogicTile tile = tileMap.GetTile(tileX, tileY); if (!this.TileOkForTombstone(tile)) { int minDistance = 0; int closestTileX = -1; int closestTileY = -1; for (int i = -1; i < 2; i++) { int offsetX = ((i + tileX) << 9) | 256; int offsetY = 256 - (tileY << 9); for (int j = -1; j < 2; j++, offsetY -= 512) { tile = tileMap.GetTile(tileX + i, tileY + j); if (this.TileOkForTombstone(tile)) { int distanceX = this.GetX() - offsetX; int distanceY = this.GetY() + offsetY; int distance = distanceX * distanceX + distanceY * distanceY; if (minDistance == 0 || distance < minDistance) { minDistance = distance; closestTileX = tileX + i; closestTileY = tileY + j; } } } } if (minDistance == 0) { return; } tileX = closestTileX; tileY = closestTileY; } LogicObstacleData tombstoneData = this.GetCharacterData().GetTombstone(); if (tombstoneData != null) { LogicObstacle tombstone = (LogicObstacle)LogicGameObjectFactory.CreateGameObject(tombstoneData, this.m_level, this.m_villageType); tombstone.SetInitialPosition(tileX << 9, tileY << 9); this.GetGameObjectManager().AddGameObject(tombstone, -1); } } }
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 void SpawnObstacle(int x, int y, int radius) { int tileX = x >> 9; int tileY = y >> 9; if (!this.TileOkForSpawn(this.m_level.GetTileMap().GetTile(tileX, tileY))) { int minSquare = 0; int minTileX = -1; int minTileY = -1; for (int i = -radius; i <= radius; i++) { int posX = tileX + i; int midX = (posX << 9) | 256; int midY = (radius << 9) - 256 - ((y >> 9) << 9); for (int j = -radius; j <= radius; j++) { int posY = tileY + j; if (this.TileOkForSpawn(this.m_level.GetTileMap().GetTile(posX, posY))) { int goX = this.GetX(); int goY = this.GetY(); int square = (goX - midX) * (goX - midX) + (goY + midY) * (goY + midY); if (minSquare == 0 || square < minSquare) { minSquare = square; minTileX = posX; minTileY = posY; } } midY -= 512; } } if (minSquare == 0) { return; } tileX = minTileX; tileY = minTileY; } LogicObstacleData data = this.GetSpellData().GetSpawnObstacle(); if (data != null) { LogicGameObject gameObject = LogicGameObjectFactory.CreateGameObject(data, this.m_level, this.GetVillageType()); gameObject.SetInitialPosition(tileX << 9, tileY << 9); this.GetGameObjectManager().AddGameObject(gameObject, -1); } }
public int GetFadingOutTime() { LogicObstacleData data = this.GetObstacleData(); if (!data.IsTallGrass()) { return(data.IsLootCart() ? 4000 : 2000); } return(1000); }
public LogicSpawnerComponent(LogicGameObject gameObject, LogicObstacleData spawnData, int radius, int intervalSeconds, int spawnCount, int maxSpawned, int maxLifetimeSpawns) : base(gameObject) { this.m_spawned = new LogicArrayList <int>(); this.m_randomizer = new LogicMersenneTwisterRandom(); this.m_spawnData = spawnData; this.m_radius = radius; this.m_intervalSeconds = intervalSeconds; this.m_spawnCount = spawnCount; this.m_maxSpawned = maxSpawned; this.m_maxLifetimeSpawns = maxLifetimeSpawns; this.m_randomizer.Initialize(this.m_parent.GetGlobalID()); this.m_spawned.EnsureCapacity(maxSpawned); }
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; } } }
/// <summary> /// Called when the clearing of this <see cref="LogicObstacle"/> instance is finished. /// </summary> public void ClearingFinished(bool ignoreState) { int state = this._level.GetState(); if (state == 1 || !LogicDataTables.GetGlobals().CompleteConstructionOnlyHome() && ignoreState) { if (this._level.GetHomeOwnerAvatar().IsClientAvatar()) { LogicClientAvatar homeOwnerAvatar = (LogicClientAvatar)this._level.GetHomeOwnerAvatar(); LogicObstacleData obstacleData = this.GetObstacleData(); LogicResourceData lootResourceData = obstacleData.GetLootResourceData(); int lootCount = obstacleData.GetLootCount(); if (obstacleData.IsLootCart()) { LogicComponent component = this.GetComponent(14); LogicDataTable resourceTable = LogicDataTables.GetTable(2); if (component != null && resourceTable.GetItemCount() > 0) { for (int i = 0; i < resourceTable.GetItemCount(); i++) { // TODO: Implement LootCart. } } } if (!obstacleData.IsTombstone && !obstacleData.IsLootCart()) { this._level.GetAchievementManager().ObstacleCleared(); } this._level.GetWorkerManagerAt(this._villageType).DeallocateWorker(this); this.XpGainHelper(LogicGamePlayUtil.TimeToExp(obstacleData.GetClearTime()), homeOwnerAvatar, ignoreState || state == 1); if (lootResourceData != null && lootCount > 0) { if (homeOwnerAvatar != null) { if (lootResourceData.PremiumCurrency) { int lootMultipler = 1; if (this._lootMultiplyVersion >= 2) { lootMultipler = obstacleData.GetLootMultiplierVersion2(); } int diamondsCount = obstacleData.GetName().Equals("Bonus Gembox") ? lootCount * lootMultipler : this._level.GetGameObjectManagerAt(this._villageType).IncreaseObstacleClearCounter(lootMultipler); if (diamondsCount > 0) { Debugger.Print("LogicObstacle::clearingFinished diamonds reward: " + diamondsCount); homeOwnerAvatar.SetDiamonds(homeOwnerAvatar.GetDiamonds() + diamondsCount); homeOwnerAvatar.SetFreeDiamonds(homeOwnerAvatar.GetFreeDiamonds() + diamondsCount); homeOwnerAvatar.GetChangeListener().FreeDiamondsAdded(diamondsCount); } } 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.GetVillageType() == this._level.GetVillageType()) { // ? } if (this._clearTimer != null) { this._clearTimer.Destruct(); this._clearTimer = null; } this._fadeTime = 1; } } }
/// <summary> /// Creates the data for the specified row. /// </summary> internal LogicData Create(Row row) { LogicData data; switch (this.Index) { case 1: { data = new LogicLocaleData(row, this); break; } case 2: { data = new LogicResourceData(row, this); break; } case 3: { data = new LogicEffectData(row, this); break; } case 4: { data = new LogicParticleEmitterData(row, this); break; } case 5: { data = new LogicGlobalData(row, this); break; } case 6: { data = new LogicQuestData(row, this); break; } case 8: { data = new LogicAchievementData(row, this); break; } case 10: { data = new LogicWorldData(row, this); break; } case 11: { data = new LogicHeroData(row, this); break; } case 12: { data = new LogicExperienceLevelData(row, this); break; } case 13: { data = new LogicLeagueData(row, this); break; } case 21: { data = new LogicAllianceBadgeData(row, this); break; } case 24: { data = new LogicTauntData(row, this); break; } case 25: { data = new LogicDecoData(row, this); break; } case 26: { data = new LogicVariableData(row, this); break; } case 28: { data = new LogicBoosterData(row, this); break; } case 32: { data = new LogicEnergyPackageData(row, this); break; } case 35: { data = new LogicSpellData(row, this); break; } case 36: { data = new LogicObstacleData(row, this); break; } case 37: { data = new LogicItemsData(row, this); break; } default: { data = new LogicData(row, this); break; } } return(data); }
public override int Execute(LogicLevel level) { LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObjectId); if (gameObject != null && gameObject.GetGameObjectType() == LogicGameObjectType.OBSTACLE) { LogicObstacle obstacle = (LogicObstacle)gameObject; if (obstacle.GetObstacleData().GetVillageType() == level.GetVillageType()) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (obstacle.CanStartClearing()) { LogicObstacleData obstacleData = obstacle.GetObstacleData(); if (obstacle.GetVillageType() == 1) { int village2TownHallLevel = playerAvatar.GetVillage2TownHallLevel(); if (village2TownHallLevel < LogicDataTables.GetGlobals().GetMinVillage2TownHallLevelForDestructObstacle() && obstacleData.GetClearCost() > 0) { return(0); } } LogicResourceData clearResourceData = obstacleData.GetClearResourceData(); int clearCost = obstacleData.GetClearCost(); if (playerAvatar.HasEnoughResources(clearResourceData, clearCost, true, this, false)) { if (obstacleData.GetClearTime() == 0 || level.HasFreeWorkers(this, -1)) { playerAvatar.CommodityCountChangeHelper(0, clearResourceData, -clearCost); obstacle.StartClearing(); if (obstacle.IsTombstone()) { int tombGroup = obstacle.GetTombGroup(); if (tombGroup != 2) { LogicArrayList <LogicGameObject> gameObjects = level.GetGameObjectManager().GetGameObjects(LogicGameObjectType.OBSTACLE); for (int i = 0; i < gameObjects.Size(); i++) { LogicObstacle go = (LogicObstacle)gameObjects[i]; if (go.IsTombstone() && go.GetTombGroup() == tombGroup) { go.StartClearing(); } } } } } return(0); } } return(-1); } return(-32); } return(-1); }
public void Load(LogicJSONObject jsonObject) { this.m_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.m_specialObstacle = LogicDataTables.GetObstacleByName(specialObstacleObject.GetStringValue(), null); } LogicJSONObject village2Object = jsonObject.GetJSONObject("Village2"); Debugger.DoAssert(village2Object != null, "pVillage2 = NULL!"); this.m_maxTownHallLevel = LogicJSONHelper.GetInt(village2Object, "TownHallMaxLevel"); LogicJSONArray scoreChangeForLosingArray = village2Object.GetJSONArray("ScoreChangeForLosing"); Debugger.DoAssert(scoreChangeForLosingArray != null, "ScoreChangeForLosing array is null"); this.m_milestoneScoreChangeForLosing = new LogicArrayList <int>(scoreChangeForLosingArray.Size()); this.m_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.m_milestoneScoreChangeForLosing.Add(milestoneObject.GetIntValue()); this.m_percentageScoreChangeForLosing.Add(percentageObject.GetIntValue()); } } } LogicJSONArray strengthRangeForScoreArray = village2Object.GetJSONArray("StrengthRangeForScore"); Debugger.DoAssert(strengthRangeForScoreArray != null, "StrengthRangeForScore array is null"); this.m_milestoneStrengthRangeForScore = new LogicArrayList <int>(strengthRangeForScoreArray.Size()); this.m_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.m_milestoneStrengthRangeForScore.Add(milestoneObject.GetIntValue()); this.m_percentageStrengthRangeForScore.Add(percentageObject.GetIntValue()); } } } LogicJSONObject killSwitchesObject = jsonObject.GetJSONObject("KillSwitches"); Debugger.DoAssert(killSwitchesObject != null, "pKillSwitches = NULL!"); this.m_battleWaitForProjectileDestruction = LogicJSONHelper.GetBool(killSwitchesObject, "BattleWaitForProjectileDestruction"); this.m_battleWaitForDieDamage = LogicJSONHelper.GetBool(killSwitchesObject, "BattleWaitForDieDamage"); LogicJSONObject globalsObject = jsonObject.GetJSONObject("Globals"); Debugger.DoAssert(globalsObject != null, "pGlobals = NULL!"); this.m_giftPackExtension = LogicJSONHelper.GetString(globalsObject, "GiftPackExtension"); this.m_duelLootLimitCooldownInMinutes = LogicJSONHelper.GetInt(globalsObject, "DuelLootLimitCooldownInMinutes"); this.m_duelBonusLimitWinsPerDay = LogicJSONHelper.GetInt(globalsObject, "DuelBonusLimitWinsPerDay"); this.m_duelBonusPercentWin = LogicJSONHelper.GetInt(globalsObject, "DuelBonusPercentWin"); this.m_duelBonusPercentLose = LogicJSONHelper.GetInt(globalsObject, "DuelBonusPercentLose"); this.m_duelBonusPercentDraw = LogicJSONHelper.GetInt(globalsObject, "DuelBonusPercentDraw"); this.m_duelBonusMaxDiamondCostPercent = LogicJSONHelper.GetInt(globalsObject, "DuelBonusMaxDiamondCostPercent"); } else { Debugger.Error("pConfiguration = NULL!"); } }