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 override int Execute(LogicLevel level) { LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObjectId); if (gameObject != null && gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding building = (LogicBuilding)gameObject; if (this.m_unitData != null) { LogicUnitUpgradeComponent unitUpgradeComponent = building.GetUnitUpgradeComponent(); if (unitUpgradeComponent != null && unitUpgradeComponent.CanStartUpgrading(this.m_unitData)) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); int upgradeLevel = playerAvatar.GetUnitUpgradeLevel(this.m_unitData); int upgradeCost = this.m_unitData.GetUpgradeCost(upgradeLevel); LogicResourceData upgradeResourceData = this.m_unitData.GetUpgradeResource(upgradeLevel); if (playerAvatar.HasEnoughResources(upgradeResourceData, upgradeCost, true, this, false)) { playerAvatar.CommodityCountChangeHelper(0, upgradeResourceData, -upgradeCost); unitUpgradeComponent.StartUpgrading(this.m_unitData); return(0); } } } } return(-1); }
public void AddUnitsToQueue(LogicCombatItemData data, int count) { LogicCalendar calendar = this.m_level.GetCalendar(); LogicAvatar homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar(); LogicClientAvatar playerAvatar = this.m_level.GetPlayerAvatar(); LogicGameObjectManager gameObjectManager = this.m_level.GetGameObjectManagerAt(0); LogicUnitProduction production = gameObjectManager.GetUnitProduction(); if (data.GetCombatItemType() != LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER) { if (data.GetCombatItemType() != LogicCombatItemData.COMBAT_ITEM_TYPE_SPELL) { return; } production = gameObjectManager.GetSpellProduction(); } if (production != null) { int trainCost = calendar.GetTrainingCost(data, homeOwnerAvatar.GetUnitUpgradeLevel(data)); for (int i = 0; i < count; i++) { if (production.CanAddUnitToQueue(data, true) && playerAvatar.HasEnoughResources(data.GetTrainingResource(), trainCost, false, null, false)) { playerAvatar.CommodityCountChangeHelper(0, data.GetTrainingResource(), -trainCost); production.AddUnitToQueue(data, production.GetSlotCount(), true); } } } }
public override int Execute(LogicLevel level) { LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObjectId); if (gameObject != null && gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding building = (LogicBuilding)gameObject; if (building.IsLocked()) { if (building.GetUpgradeLevel() == 0 && building.CanUnlock(true)) { LogicBuildingData buildingData = building.GetBuildingData(); if (buildingData.GetConstructionTime(0, level, 0) == 0 || level.HasFreeWorkers(this, -1)) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); LogicResourceData buildResource = buildingData.GetBuildResource(0); int buildCost = buildingData.GetBuildCost(0, level); if (playerAvatar.HasEnoughResources(buildResource, buildCost, true, this, false)) { playerAvatar.CommodityCountChangeHelper(0, buildResource, -buildCost); building.StartConstructing(true); building.GetListener().RefreshState(); return(0); } } } } } return(-1); }
public override int Execute(LogicLevel level) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (level.GetVillageType() == 1) { LogicGameMode gameMode = level.GetGameMode(); if (!gameMode.IsInAttackPreparationMode()) { if (gameMode.GetState() != 5) { return(-9); } } if (this.m_oldUnitData != null && this.m_newUnitData != null && gameMode.GetCalendar().IsProductionEnabled(this.m_newUnitData)) { if (!this.m_newUnitData.IsUnlockedForBarrackLevel(playerAvatar.GetVillage2BarrackLevel())) { if (gameMode.GetState() != 7) { return(-7); } } int oldUnitCount = playerAvatar.GetUnitCountVillage2(this.m_oldUnitData); int oldUnitsInCamp = this.m_oldUnitData.GetUnitsInCamp(playerAvatar.GetUnitUpgradeLevel(this.m_oldUnitData)); if (oldUnitCount >= oldUnitsInCamp) { int newUnitCount = playerAvatar.GetUnitCountVillage2(this.m_newUnitData); int newUnitsInCamp = this.m_newUnitData.GetUnitsInCamp(playerAvatar.GetUnitUpgradeLevel(this.m_newUnitData)); playerAvatar.SetUnitCountVillage2(this.m_oldUnitData, oldUnitCount - oldUnitsInCamp); playerAvatar.SetUnitCountVillage2(this.m_newUnitData, newUnitCount + newUnitsInCamp); LogicArrayList <LogicDataSlot> unitsNew = playerAvatar.GetUnitsNewVillage2(); for (int i = 0; i < unitsNew.Size(); i++) { LogicDataSlot slot = unitsNew[i]; if (slot.GetCount() > 0) { playerAvatar.CommodityCountChangeHelper(8, slot.GetData(), -slot.GetCount()); } } return(0); } return(-23); } return(-7); } return(-10); }
public int CollectResources() { int collected = -1; if (this.m_parent.GetLevel().GetHomeOwnerAvatar().IsClientAvatar()) { collected = 0; LogicClientAvatar playerAvatar = (LogicClientAvatar)this.m_parent.GetLevel().GetHomeOwnerAvatar(); LogicDataTable table = LogicDataTables.GetTable(LogicDataType.RESOURCE); for (int i = 0; i < table.GetItemCount(); i++) { LogicResourceData data = (LogicResourceData)table.GetItemAt(i); if (data.GetWarResourceReferenceData() != null) { int count = playerAvatar.GetResourceCount(data); if (count > 0) { int unusedResourceCap = playerAvatar.GetUnusedResourceCap(data.GetWarResourceReferenceData()); if (unusedResourceCap != 0) { if (count > unusedResourceCap) { count = unusedResourceCap; } if (data.GetName().Equals("WarGold")) { this.m_parent.GetLevel().GetAchievementManager().IncreaseWarGoldResourceLoot(count); } collected = count; playerAvatar.CommodityCountChangeHelper(0, data.GetWarResourceReferenceData(), count); playerAvatar.CommodityCountChangeHelper(0, data, -count); } } } } } return(collected); }
public override int Execute(LogicLevel level) { LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObjectId); if (gameObject != null) { if (gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding building = (LogicBuilding)gameObject; if (!LogicDataTables.GetGlobals().AllowCancelBuildingConstruction() && building.GetUpgradeLevel() == 0 && building.IsConstructing()) { if (!building.IsUpgrading()) { return(-2); } } if (building.IsConstructing()) { building.GetListener().CancelNotification(); building.CancelConstruction(); return(0); } } else if (gameObject.GetGameObjectType() == LogicGameObjectType.OBSTACLE) { LogicObstacle obstacle = (LogicObstacle)gameObject; if (obstacle.IsClearingOnGoing()) { LogicObstacleData data = obstacle.GetObstacleData(); LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); playerAvatar.CommodityCountChangeHelper(0, data.GetClearResourceData(), data.GetClearCost()); obstacle.CancelClearing(); return(0); } } else if (gameObject.GetGameObjectType() == LogicGameObjectType.TRAP) { LogicTrap trap = (LogicTrap)gameObject; if (trap.IsConstructing()) { trap.GetListener().CancelNotification(); trap.CancelConstruction(); return(0); } } } return(-1); }
public override 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) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); LogicGameObjectManager gameObjectManager = level.GetGameObjectManager(); LogicResourceData repairResourceData = null; int repairCost = 0; for (int i = 0; i < this.m_gameObjectIds.Size(); i++) { LogicGameObject gameObject = gameObjectManager.GetGameObjectByID(this.m_gameObjectIds[i]); if (gameObject != null && gameObject.GetGameObjectType() == LogicGameObjectType.TRAP) { LogicTrap trap = (LogicTrap)gameObject; if (trap.IsDisarmed() && !trap.IsConstructing()) { LogicTrapData data = trap.GetTrapData(); repairResourceData = data.GetBuildResource(); repairCost += data.GetRearmCost(trap.GetUpgradeLevel()); } } } if (repairResourceData != null && repairCost != 0) { if (playerAvatar.HasEnoughResources(repairResourceData, repairCost, true, this, false)) { playerAvatar.CommodityCountChangeHelper(0, repairResourceData, -repairCost); for (int i = 0; i < this.m_gameObjectIds.Size(); i++) { LogicGameObject gameObject = gameObjectManager.GetGameObjectByID(this.m_gameObjectIds[i]); if (gameObject != null && gameObject.GetGameObjectType() == LogicGameObjectType.TRAP) { LogicTrap trap = (LogicTrap)gameObject; if (trap.IsDisarmed() && !trap.IsConstructing()) { trap.RepairTrap(); } } } return(0); } return(-2); } return(-1); }
public override int Execute(LogicLevel level) { if (level.GetVillageType() == 1) { if (this.m_gameObjectId != 0) { LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(1); LogicGameObject gameObject = gameObjectManager.GetGameObjectByID(this.m_gameObjectId); if (gameObject != null && gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding building = (LogicBuilding)gameObject; if (this.m_unitData != null && level.GetGameMode().GetCalendar().IsProductionEnabled(this.m_unitData)) { if (this.m_unitData.GetVillageType() == 1) { LogicVillage2UnitComponent village2UnitComponent = building.GetVillage2UnitComponent(); if (village2UnitComponent != null) { if (this.m_unitData.IsUnlockedForProductionHouseLevel(gameObjectManager.GetHighestBuildingLevel(this.m_unitData.GetProductionHouseData(), true)) ) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); LogicResourceData trainResource = this.m_unitData.GetTrainingResource(); int trainCost = this.m_unitData.GetTrainingCost(playerAvatar.GetUnitUpgradeLevel(this.m_unitData)); if (playerAvatar.HasEnoughResources(trainResource, trainCost, true, this, false)) { village2UnitComponent.TrainUnit(this.m_unitData); playerAvatar.CommodityCountChangeHelper(0, trainResource, -trainCost); } return(0); } return(-7); } return(-4); } return(-8); } } return(-5); } return(-1); } return(-10); }
/// <summary> /// Executes this command. /// </summary> public override int Execute(LogicLevel level) { int villageType = level.GetVillageType(); if (this._buildingData.GetVillageType() == villageType) { if (this._buildingData.GetBuildingClass().CanBuy) { if (level.IsValidPlaceForBuilding(this._x, this._y, this._buildingData.GetWidth(), this._buildingData.GetHeight(), null)) { if (!level.IsBuildingCapReached(this._buildingData, true)) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); LogicResourceData buildResourceData = this._buildingData.GetBuildResource(0); int buildResourceCost = this._buildingData.GetBuildCost(0, level); if (playerAvatar.HasEnoughResources(buildResourceData, buildResourceCost, true, this, false)) { if (this._buildingData.IsWorkerBuilding() || this._buildingData.GetConstructionTime(0, level, 0) <= 0 && !LogicDataTables.GetGlobals().WorkerForZeroBuilTime() || level.HasFreeWorkers(this, -1)) { if (buildResourceData.PremiumCurrency) { playerAvatar.UseDiamonds(buildResourceCost); } else { playerAvatar.CommodityCountChangeHelper(0, buildResourceData, -buildResourceCost); } LogicBuilding building = (LogicBuilding)LogicGameObjectFactory.CreateGameObject(this._buildingData, level, villageType); building.SetPositionXY(this._x << 9, this._y << 9); level.GetGameObjectManager().AddGameObject(building, -1); building.StartConstructing(false); if (this._buildingData.IsWall() && level.IsBuildingCapReached(this._buildingData, false)) { level.GetGameListener().BuildingCapReached(this._buildingData); } } } return(0); } } } return(-33); } return(-32); }
public int CollectResources(bool updateListener) { if (this.m_parent.GetLevel().GetHomeOwnerAvatar() != null) { int resourceCount = this.GetResourceCount(); if (this.m_parent.GetLevel().GetHomeOwnerAvatar().IsNpcAvatar()) { Debugger.Error("LogicResourceProductionComponent::collectResources() called for Npc avatar"); } else { LogicClientAvatar clientAvatar = (LogicClientAvatar)this.m_parent.GetLevel().GetHomeOwnerAvatar(); if (resourceCount != 0) { if (this.m_resourceData.IsPremiumCurrency()) { this.DecreaseResources(resourceCount); clientAvatar.SetDiamonds(clientAvatar.GetDiamonds() + resourceCount); clientAvatar.SetFreeDiamonds(clientAvatar.GetFreeDiamonds() + resourceCount); clientAvatar.GetChangeListener().FreeDiamondsAdded(resourceCount, 10); } else { int unusedResourceCap = clientAvatar.GetUnusedResourceCap(this.m_resourceData); if (unusedResourceCap != 0) { if (resourceCount > unusedResourceCap) { resourceCount = unusedResourceCap; } this.DecreaseResources(resourceCount); clientAvatar.CommodityCountChangeHelper(0, this.m_resourceData, resourceCount); } else { resourceCount = 0; } } return(resourceCount); } } } return(0); }
public void AddRewardUnits() { LogicCharacterData characterData = this.m_data.GetRewardCharacterData(); if (characterData != null) { int characterCount = this.m_data.GetRewardCharacterCount(); if (characterCount > 0) { LogicClientAvatar playerAvatar = this.m_level.GetPlayerAvatar(); LogicComponentFilter filter = new LogicComponentFilter(); for (int i = 0; i < characterCount; i++) { filter.RemoveAllIgnoreObjects(); while (true) { LogicUnitStorageComponent component = (LogicUnitStorageComponent)this.m_level.GetComponentManagerAt(this.m_level.GetVillageType()).GetClosestComponent(0, 0, filter); if (component != null) { if (component.CanAddUnit(characterData)) { playerAvatar.CommodityCountChangeHelper(0, characterData, 1); component.AddUnit(characterData); if (this.m_level.GetState() == 1 || this.m_level.GetState() == 3) { if (component.GetParentListener() != null) { component.GetParentListener().ExtraCharacterAdded(characterData, null); } } break; } filter.AddIgnoreObject(component.GetParent()); } else { break; } } } } } }
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); }
/// <summary> /// Trains the unit with new training. /// </summary> public int NewTrainingUnit(LogicLevel level) { if (LogicDataTables.GetGlobals().UseNewTraining()) { if (this._unitData != null) { LogicUnitProduction unitProduction = this._unitData.GetCombatItemType() == 1 ? level.GetGameObjectManager().GetSpellProduction() : level.GetGameObjectManager().GetUnitProduction(); if (!unitProduction.IsLocked()) { if (this._unitCount > 0) { if (this._unitData.GetDataType() == unitProduction.GetUnitProductionType()) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); LogicResourceData trainingResourceData = this._unitData.GetTrainingResource(); Int32 trainingCost = level.GetGameMode().GetCalendar().GetUnitTrainingCost(this._unitData, playerAvatar.GetUnitUpgradeLevel(this._unitData)); Int32 refundCount = LogicMath.Max(trainingCost * (this._unitData.GetDataType() != 3 ? LogicDataTables.GetGlobals().GetSpellCancelMultiplier() : LogicDataTables.GetGlobals().GetTrainCancelMultiplier()) / 100, 0); while (unitProduction.RemoveUnit(this._unitData, this._slotId)) { playerAvatar.CommodityCountChangeHelper(0, trainingResourceData, refundCount); if (--this._unitCount <= 0) { break; } } return(0); } } return(-1); } return(-23); } return(-1); } return(-99); }
public override int Execute(LogicLevel level) { if (level.GetVillageType() == 0) { if (level.GetState() == 2 || level.GetState() == 1) { if (this.m_buyResourceData != null) { if (this.m_buyResourceCount > 0 && !this.m_buyResourceData.IsPremiumCurrency()) { int cost = LogicGamePlayUtil.GetResourceDiamondCost(this.m_buyResourceCount, this.m_buyResourceData); LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (playerAvatar.GetUnusedResourceCap(this.m_buyResourceData) >= this.m_buyResourceCount) { if (playerAvatar.HasEnoughDiamonds(cost, true, level)) { playerAvatar.UseDiamonds(cost); playerAvatar.GetChangeListener() .DiamondPurchaseMade(5, this.m_buyResourceData.GetGlobalID(), this.m_buyResourceCount, cost, level.GetVillageType()); playerAvatar.CommodityCountChangeHelper(0, this.m_buyResourceData, this.m_buyResourceCount); } else { return(-2); } } else { return(-1); } } } level.GetGameListener().MatchmakingCommandExecuted(); return(0); } return(-3); } return(-32); }
public override int Execute(LogicLevel level) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (playerAvatar != null) { if (this.m_allianceCreate) { LogicGlobals globals = LogicDataTables.GetGlobals(); LogicResourceData resource = globals.GetAllianceCreateResourceData(); int removeCount = LogicMath.Min(globals.GetAllianceCreateCost(), playerAvatar.GetResourceCount(resource)); playerAvatar.CommodityCountChangeHelper(0, resource, -removeCount); } playerAvatar.SetAllianceId(this.m_allianceId.Clone()); playerAvatar.SetAllianceName(this.m_allianceName); playerAvatar.SetAllianceBadgeId(this.m_allianceBadgeId); playerAvatar.SetAllianceLevel(this.m_allianceExpLevel); playerAvatar.SetAllianceRole(this.m_allianceCreate ? LogicAvatarAllianceRole.LEADER : LogicAvatarAllianceRole.MEMBER); playerAvatar.GetChangeListener().AllianceJoined(playerAvatar.GetAllianceId(), this.m_allianceName, this.m_allianceBadgeId, this.m_allianceExpLevel, playerAvatar.GetAllianceRole()); LogicGameListener gameListener = level.GetGameListener(); if (gameListener != null) { if (this.m_allianceCreate) { gameListener.AllianceCreated(); } else { gameListener.AllianceJoined(); } } return(0); } return(-1); }
public override int Execute(LogicLevel level) { if (level.GetVillageType() == 1) { if (level.IsUnitsTrainedVillage2()) { if (level.GetState() == 1) { if (this.m_buyResourceCount > 0) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (playerAvatar.GetUnusedResourceCap(LogicDataTables.GetGold2Data()) < this.m_buyResourceCount) { return(-1); } int buyResourceCost = LogicGamePlayUtil.GetResourceDiamondCost(this.m_buyResourceCount, LogicDataTables.GetGold2Data()); if (playerAvatar.HasEnoughDiamonds(buyResourceCost, true, level)) { return(-2); } playerAvatar.UseDiamonds(buyResourceCost); playerAvatar.GetChangeListener().DiamondPurchaseMade(5, LogicDataTables.GetGold2Data().GetGlobalID(), this.m_buyResourceCount, buyResourceCost, level.GetVillageType()); playerAvatar.CommodityCountChangeHelper(0, LogicDataTables.GetGold2Data(), this.m_buyResourceCount); } level.GetGameListener().MatchmakingVillage2CommandExecuted(); return(0); } return(-3); } return(-24); } return(-32); }
public override int Execute(LogicLevel level) { LogicBuilding building = (LogicBuilding)level.GetGameObjectManager().GetGameObjectByID(this.m_gameObjectId); if (!building.IsLocked()) { if (building.GetBuildingData().GetVillageType() == level.GetVillageType()) { LogicHeroBaseComponent heroBaseComponent = building.GetHeroBaseComponent(); if (heroBaseComponent != null && heroBaseComponent.CanStartUpgrading(true)) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); LogicHeroData heroData = building.GetBuildingData().GetHeroData(); int upgLevel = playerAvatar.GetUnitUpgradeLevel(heroData); int upgradeCost = heroData.GetUpgradeCost(upgLevel); LogicResourceData upgradeResourceData = heroData.GetUpgradeResource(upgLevel); if (playerAvatar.HasEnoughResources(upgradeResourceData, upgradeCost, true, this, false)) { if (level.HasFreeWorkers(this, -1)) { playerAvatar.CommodityCountChangeHelper(0, upgradeResourceData, -upgradeCost); heroBaseComponent.StartUpgrading(); return(0); } } } return(-1); } return(-32); } return(-23); }
public override int Execute(LogicLevel level) { LogicGameObjectManager gameObjectManager = level.GetGameObjectManager(); LogicGameObject gameObject = gameObjectManager.GetGameObjectByID(this.m_gameObjectId); if (gameObject != null && gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding building = (LogicBuilding)gameObject; LogicVillage2UnitComponent village2UnitComponent = building.GetVillage2UnitComponent(); if (village2UnitComponent != null) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); playerAvatar.CommodityCountChangeHelper(7, village2UnitComponent.GetUnitData(), -village2UnitComponent.GetUnitCount()); village2UnitComponent.RemoveUnits(); return(0); } } return(-1); }
/// <summary> /// Executes this command. /// </summary> public override int Execute(LogicLevel level) { if (this._resourceData != null && this._resourceCount > 0 && !this._resourceData.PremiumCurrency) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (this._resource2Data != null && this._resource2Count > 0) { int resourceCost = LogicGamePlayUtil.GetResourceDiamondCost(this._resourceCount, this._resourceData); int resourceCost2 = LogicGamePlayUtil.GetResourceDiamondCost(this._resource2Count, this._resource2Data); if (playerAvatar.GetUnusedResourceCap(this._resourceData) >= this._resourceCount && playerAvatar.GetUnusedResourceCap(this._resource2Data) >= this._resource2Count) { if (playerAvatar.HasEnoughDiamonds(resourceCost + resourceCost2, true, level)) { playerAvatar.UseDiamonds(resourceCost + resourceCost2); playerAvatar.CommodityCountChangeHelper(0, this._resourceData, this._resourceCount); playerAvatar.CommodityCountChangeHelper(0, this._resource2Data, this._resource2Count); Debugger.Print("LogicBuyResourcesCommand::execute buy resources: " + (resourceCost + resourceCost2)); if (this._command != null) { int cmdType = this._command.GetCommandType(); if (cmdType < 1000) { if (cmdType >= 500 && cmdType < 700) { this._command.Execute(level); } } } return(0); } } } else { int resourceCost = LogicGamePlayUtil.GetResourceDiamondCost(this._resourceCount, this._resourceData); if (playerAvatar.GetUnusedResourceCap(this._resourceData) >= this._resourceCount) { if (playerAvatar.HasEnoughDiamonds(resourceCost, true, level)) { playerAvatar.UseDiamonds(resourceCost); playerAvatar.CommodityCountChangeHelper(0, this._resourceData, this._resourceCount); Debugger.Print("LogicBuyResourcesCommand::execute buy resources: " + resourceCost); if (this._command != null) { int cmdType = this._command.GetCommandType(); if (cmdType < 1000) { if (cmdType >= 500 && cmdType < 700) { this._command.Execute(level); } } } return(0); } } } } return(-1); }
/// <summary> /// Executes this command. /// </summary> public override int Execute(LogicLevel level) { if (this._gameObjectIds.Count > 0) { LogicResourceData buildResourceData = null; int buildCost = 0; for (int i = 0; i < this._gameObjectIds.Count; i++) { LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this._gameObjectIds[i]); if (gameObject != null && gameObject.GetGameObjectType() == 0) { LogicBuilding building = (LogicBuilding)gameObject; LogicBuildingData buildingData = building.GetBuildingData(); int upgradeLevel = building.GetUpgradeLevel(); if (buildingData.IsTownHallVillage2()) { return(-76); } if (building.CanUpgrade(false) && buildingData.GetUpgradeLevelCount() > upgradeLevel + 1 && buildingData.GetAmountCanBeUpgraded(0) == 0) { buildResourceData = buildingData.GetBuildResource(upgradeLevel + 1); if (this._useAltResources) { buildResourceData = buildingData.GetAltBuildResource(upgradeLevel + 1); } buildCost += buildingData.GetBuildCost(upgradeLevel + 1, level); } } } if (buildResourceData != null) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (playerAvatar.HasEnoughResources(buildResourceData, buildCost, true, this, false)) { if (level.HasFreeWorkers(this, -1)) { bool ignoreState = true; for (int i = 0; i < this._gameObjectIds.Count; i++) { LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this._gameObjectIds[i]); if (gameObject != null && gameObject.GetGameObjectType() == 0) { LogicBuilding building = (LogicBuilding)gameObject; LogicBuildingData buildingData = building.GetBuildingData(); int upgradeLevel = building.GetUpgradeLevel(); if (building.CanUpgrade(false) && buildingData.GetUpgradeLevelCount() > upgradeLevel + 1 && buildingData.GetAmountCanBeUpgraded(0) == 0) { if (this._gameObjectIds.Count > 6) { ignoreState = (building.GetTileX() + building.GetTileY()) % (this._gameObjectIds.Count / 4) == 0; } building.StartUpgrading(ignoreState, false); } } } playerAvatar.CommodityCountChangeHelper(0, buildResourceData, -buildCost); return(0); } } } } return(-2); }
public override int Execute(LogicLevel level) { if (this.m_gameObjectIds.Size() > 0) { LogicResourceData ammoResourceData = null; int ammoCost = 0; int idx = 0; do { LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObjectIds[idx]); if (gameObject != null && gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding building = (LogicBuilding)gameObject; if (building.GetData().GetVillageType() == level.GetVillageType()) { LogicCombatComponent combatComponent = building.GetCombatComponent(false); if (combatComponent != null && combatComponent.UseAmmo()) { if (combatComponent.GetAmmoCount() < combatComponent.GetMaxAmmo() && !building.IsUpgrading()) { LogicBuildingData buildingData = building.GetBuildingData(); ammoResourceData = buildingData.GetAmmoResourceData(0); ammoCost += buildingData.GetAmmoCost(building.GetUpgradeLevel(), combatComponent.GetMaxAmmo() - combatComponent.GetAmmoCount()); } } } else { return(-32); } } } while (++idx < this.m_gameObjectIds.Size()); if (ammoResourceData != null && ammoCost > 0) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (playerAvatar.HasEnoughResources(ammoResourceData, ammoCost, true, this, false)) { 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; LogicCombatComponent combatComponent = building.GetCombatComponent(false); if (combatComponent != null && combatComponent.UseAmmo()) { if (combatComponent.GetAmmoCount() < combatComponent.GetMaxAmmo()) { int upgradeLevel = building.GetUpgradeLevel(); LogicBuildingData buildingData = building.GetBuildingData(); LogicResourceData loadAmmoResourceData = buildingData.GetAmmoResourceData(upgradeLevel); int loadAmmoCost = buildingData.GetAmmoCost(upgradeLevel, combatComponent.GetMaxAmmo() - combatComponent.GetAmmoCount()); if (playerAvatar.HasEnoughResources(loadAmmoResourceData, loadAmmoCost, true, this, false)) { playerAvatar.CommodityCountChangeHelper(0, loadAmmoResourceData, -loadAmmoCost); combatComponent.LoadAmmo(); continue; } } } } break; } return(0); } return(-2); } } return(-1); }
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> /// Executes this command. /// </summary> public override int Execute(LogicLevel level) { if (this._trapData != null) { if (this._trapData.GetVillageType() == level.GetVillageType()) { if (level.IsValidPlaceForBuilding(this._x, this._y, this._trapData.GetWidth(), this._trapData.GetHeight(), null)) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); LogicResourceData buildResourceData = this._trapData.GetBuildResource(); int buildCost = this._trapData.GetBuildCost(0); if (playerAvatar.HasEnoughResources(buildResourceData, buildCost, true, this, false) && !level.IsTrapCapReached(this._trapData, true)) { if (buildResourceData.PremiumCurrency) { playerAvatar.UseDiamonds(buildCost); } else { playerAvatar.CommodityCountChangeHelper(0, buildResourceData, -buildCost); } LogicTrap trap = (LogicTrap)LogicGameObjectFactory.CreateGameObject(this._trapData, level, level.GetVillageType()); if (this._trapData.GetBuildTime(0) == 0) { trap.FinishConstruction(false); } trap.SetInitialPosition(this._x << 9, this._y << 9); level.GetGameObjectManager().AddGameObject(trap, -1); if (level.IsTrapCapReached(this._trapData, false)) { level.GetGameListener().TrapCapReached(this._trapData); } if (trap.GetVillageType() != 0) { int x = trap.GetTileX(); int y = trap.GetTileY(); int width = trap.GetWidthInTiles(); int height = trap.GetHeightInTiles(); 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); } } } } return(0); } } return(-1); } return(-32); } 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; LogicBuildingData buildingData = building.GetBuildingData(); if (buildingData.IsTownHallVillage2()) { if (!this.UnlockVillage2()) { return(-76); } } if (buildingData.GetVillageType() == level.GetVillageType()) { if (building.GetWallIndex() == 0) { if (building.CanUpgrade(true)) { int nextUpgradeLevel = building.GetUpgradeLevel() + 1; int buildCost = buildingData.GetBuildCost(nextUpgradeLevel, level); LogicResourceData buildResourceData = this._useAltResources ? buildingData.GetAltBuildResource(nextUpgradeLevel) : buildingData.GetBuildResource(nextUpgradeLevel); if (buildResourceData != null) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (playerAvatar.HasEnoughResources(buildResourceData, buildCost, true, this, false)) { int constructionTime = buildingData.GetConstructionTime(nextUpgradeLevel, level, 0); if (constructionTime != 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); } else if (gameObject.GetGameObjectType() == 4) { 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)) { int constructionTime = data.GetBuildTime(trap.GetUpgradeLevel() + 1); if (constructionTime != 0 || LogicDataTables.GetGlobals().WorkerForZeroBuilTime()) { if (!level.HasFreeWorkers(this, -1)) { return(-1); } playerAvatar.CommodityCountChangeHelper(0, buildResourceData, -buildCost); trap.StartUpgrading(); return(0); } } } } else if (gameObject.GetGameObjectType() == 8) { if (!this._useAltResources) { LogicVillageObject villageObject = (LogicVillageObject)gameObject; // TODO: Implement upgrade vObjs. } return(-31); } } return(-1); }
public int NewTrainingUnit(LogicLevel level) { if (LogicDataTables.GetGlobals().UseNewTraining()) { if (this.m_trainCount <= 100) { LogicUnitProduction unitProduction = this.m_unitType == 1 ? level.GetGameObjectManagerAt(0).GetSpellProduction() : level.GetGameObjectManagerAt(0).GetUnitProduction(); if (this.m_trainCount > 0) { if (this.m_unitData != null) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); bool firstLoopExecuted = false; int trainingCost = level.GetGameMode().GetCalendar().GetTrainingCost(this.m_unitData, playerAvatar.GetUnitUpgradeLevel(this.m_unitData)); for (int i = 0; i < this.m_trainCount; i++) { if (!unitProduction.CanAddUnitToQueue(this.m_unitData, false)) { if (firstLoopExecuted) { break; } return(-40); } if (!playerAvatar.HasEnoughResources(this.m_unitData.GetTrainingResource(), trainingCost, true, this, false)) { if (firstLoopExecuted) { break; } return(-30); } playerAvatar.CommodityCountChangeHelper(0, this.m_unitData.GetTrainingResource(), -trainingCost); if (this.m_slotId == -1) { this.m_slotId = unitProduction.GetSlotCount(); } unitProduction.AddUnitToQueue(this.m_unitData, this.m_slotId, false); firstLoopExecuted = true; } return(0); } } return(-50); } Debugger.Error("LogicTraingUnitCommand - Count is too high"); return(-20); } return(-99); }
/// <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; } } }
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 override int Execute(LogicLevel level) { if (this.m_layoutId == 7) { return(-21); } if (this.m_village2) { if (this.m_layoutId != 0 && this.m_layoutId != 2 && this.m_layoutId != 3) { return(-22); } } if (LogicDataTables.GetGlobals().UseVersusBattle()) { int villageType = this.m_village2 ? 1 : 0; if (level.GetTownHallLevel(villageType) < level.GetRequiredTownHallLevelForLayout(this.m_layoutId, villageType)) { return(-3); } if (level.GetPlayerAvatar() == null) { return(-10); } LogicArrayList <LogicGameObject> gameObjects = new LogicArrayList <LogicGameObject>(500); LogicGameObjectFilter filter = new LogicGameObjectFilter(); filter.AddGameObjectType(LogicGameObjectType.BUILDING); filter.AddGameObjectType(LogicGameObjectType.TRAP); filter.AddGameObjectType(LogicGameObjectType.DECO); level.GetGameObjectManagerAt(this.m_village2 ? 1 : 0).GetGameObjects(gameObjects, filter); for (int i = 0; i < gameObjects.Size(); i++) { LogicVector2 position = gameObjects[i].GetPositionLayout(this.m_layoutId, false); if ((this.m_layoutId & 0xFFFFFFFE) != 6 && (position.m_x == -1 || position.m_y == -1)) { return(-5); } } gameObjects.Destruct(); filter.Destruct(); if (!this.m_village2) { LogicAvatar homeOwnerAvatar = level.GetHomeOwnerAvatar(); if (homeOwnerAvatar == null || homeOwnerAvatar.IsChallengeStarted()) { if (level.GetLayoutCooldown(this.m_layoutId) > 0) { return(-7); } } } LogicBuilding allianceCastle = level.GetGameObjectManagerAt(0).GetAllianceCastle(); if (allianceCastle != null) { LogicBunkerComponent bunkerComponent = allianceCastle.GetBunkerComponent(); if (bunkerComponent == null || bunkerComponent.GetChallengeCooldownTime() != 0) { return(-6); } LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (!this.m_challenge) { if (playerAvatar.GetChallengeId() != null) { int challengeState = playerAvatar.GetChallengeState(); if (challengeState != 2 && challengeState != 4) { Debugger.Warning("chal state: " + challengeState); return(-8); } } } int friendlyCost = LogicDataTables.GetGlobals().GetFriendlyBattleCost(playerAvatar.GetTownHallLevel()); if (friendlyCost != 0) { if (!playerAvatar.HasEnoughResources(LogicDataTables.GetGoldData(), friendlyCost, true, this, false)) { return(0); } if (friendlyCost > 0) { playerAvatar.CommodityCountChangeHelper(0, LogicDataTables.GetGoldData(), friendlyCost); } } bunkerComponent.StartChallengeCooldownTime(); bool warLayout = this.m_layoutId == 1 || this.m_layoutId == 4 || this.m_layoutId == 5; if (this.m_village2) { if (this.m_challenge) { playerAvatar.GetChangeListener().SendChallengeRequest(this.m_message, this.m_layoutId, warLayout, villageType); } else { playerAvatar.GetChangeListener().SendFriendlyBattleRequest(this.m_message, this.m_battleId, this.m_layoutId, warLayout, villageType); } } else { this.SaveChallengeLayout(level, warLayout); if (this.m_challenge) { playerAvatar.GetChangeListener().SendChallengeRequest(this.m_message, this.m_layoutId, warLayout, villageType); } else { playerAvatar.GetChangeListener().SendFriendlyBattleRequest(this.m_message, this.m_battleId, this.m_layoutId, warLayout, villageType); } playerAvatar.SetVariableByName("ChallengeStarted", 1); } return(0); } return(-3); } return(2); }