public int GetMaxMiniSpellForgeLevel() { LogicArrayList <LogicComponent> components = this.m_components[(int)LogicComponentType.UNIT_PRODUCTION]; if (components.Size() > 0) { int maxUpgLevel = -1; int idx = 0; do { LogicUnitProductionComponent component = (LogicUnitProductionComponent)components[idx]; if (component.GetProductionType() != 0) { if (component.GetParent().GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding parent = (LogicBuilding)component.GetParent(); if (parent.GetBuildingData().GetProducesUnitsOfType() == 2 && (!parent.IsConstructing() || parent.IsUpgrading())) { maxUpgLevel = LogicMath.Max(parent.GetUpgradeLevel(), maxUpgLevel); } } } } while (++idx != components.Size()); return(maxUpgLevel); } return(-1); }
/// <summary> /// Gets the max spell forge level. /// </summary> public int GetMaxSpellForgeLevel() { LogicArrayList <LogicComponent> components = this._components[3]; if (components.Count > 0) { int maxUpgLevel = -1; int idx = 0; do { LogicUnitProductionComponent component = (LogicUnitProductionComponent)components[idx]; if (component.GetProductionType() != 0) { if (component.GetParent().GetGameObjectType() == 0) { LogicBuilding parent = (LogicBuilding)component.GetParent(); if (parent.GetBuildingData().GetProducesUnitsOfType() == 1 && (!parent.IsConstructing() || parent.IsUpgrading())) { maxUpgLevel = LogicMath.Max(parent.GetUpgradeLevel(), maxUpgLevel); } } } } while (++idx != components.Count); return(maxUpgLevel); } return(-1); }
public bool IsValidAttackPos(int x, int y) { for (int i = 0, posX = x - 1; i < 2; i++, posX++) { for (int j = 0, posY = y - 1; j < 2; j++, posY++) { LogicTile tile = this.GetTile(posX + i, posY + j); if (tile != null) { for (int k = 0; k < tile.GetGameObjectCount(); k++) { LogicGameObject gameObject = tile.GetGameObject(k); if (!gameObject.IsPassable()) { if (gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding building = (LogicBuilding)gameObject; if (!building.GetBuildingData().IsHidden()) { return(false); } } } } } } } return(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) { 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.GetGearUpBuildingData() == null || building.GetGearLevel() != 0) { if (building.GetAttackerItemData().HasAlternativeAttackMode()) { LogicCombatComponent combatComponent = building.GetCombatComponent(false); if (combatComponent != null) { combatComponent.ToggleAttackMode(this.m_layout, this.m_draftMode); if (this.m_updateListener) { } return(0); } } return(-1); } return(-95); } if (gameObject.GetGameObjectType() == LogicGameObjectType.TRAP) { LogicTrap trap = (LogicTrap)gameObject; if (trap.HasAirMode()) { trap.ToggleAirMode(this.m_layout, this.m_draftMode); if (this.m_updateListener) { } return(0); } } } return(-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; LogicBuildingData buildingData = building.GetBuildingData(); LogicCombatComponent combatComponent = building.GetCombatComponent(false); if (combatComponent != null && combatComponent.GetAttackerItemData().GetTargetingConeAngle() != 0) { if (this.m_baseLayout == -1) { combatComponent.ToggleAimAngle(buildingData.GetAimRotateStep(), this.m_layout, this.m_draftLayout); } else { int draftAngle = combatComponent.GetAimAngle(this.m_baseLayout, this.m_baseDraftLayout); int currentAngle = combatComponent.GetAimAngle(this.m_layout, this.m_draftLayout); combatComponent.ToggleAimAngle(draftAngle - currentAngle, this.m_layout, this.m_draftLayout); } return(0); } } else if (gameObject.GetGameObjectType() == LogicGameObjectType.TRAP) { LogicTrap trap = (LogicTrap)gameObject; if (trap.GetTrapData().GetDirectionCount() > 0) { if (this.m_baseLayout == -1) { trap.ToggleDirection(this.m_layout, this.m_draftLayout); } else { trap.SetDirection(this.m_layout, this.m_draftLayout, trap.GetDirection(this.m_baseLayout, this.m_baseDraftLayout)); } return(0); } return(-21); } } return(-1); }
public void UpdateHeroHealthToAvatar(int hitpoint) { LogicAvatar avatar = this.m_team == 1 ? this.m_parent.GetLevel().GetHomeOwnerAvatar() : this.m_parent.GetLevel().GetVisitorAvatar(); LogicHeroData data = null; int upgLevel = 0; if (this.m_parent.IsHero()) { LogicCharacter character = (LogicCharacter)this.m_parent; data = (LogicHeroData)character.GetCharacterData(); upgLevel = character.GetUpgradeLevel(); } else if (this.m_parent.GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding building = (LogicBuilding)this.m_parent; LogicHeroBaseComponent heroBaseComponent = building.GetHeroBaseComponent(); if (heroBaseComponent == null) { return; } LogicBuildingData buildingData = building.GetBuildingData(); if (!buildingData.GetShareHeroCombatData()) { return; } LogicCombatComponent combatComponent = building.GetCombatComponent(); if (combatComponent == null || !combatComponent.IsEnabled()) { return; } data = buildingData.GetHeroData(); upgLevel = avatar.GetUnitUpgradeLevel(data); } if (data != null) { int secs = LogicMath.Min(data.GetSecondsToFullHealth(hitpoint, upgLevel), data.GetFullRegenerationTimeSec(upgLevel)); if (avatar != null) { avatar.GetChangeListener().CommodityCountChanged(0, data, secs); avatar.SetHeroHealth(data, secs); } } }
public bool CanAddUnitToQueue(LogicCombatItemData data, bool ignoreCapacity) { if (data != null) { if (data.GetDataType() == this.m_unitProductionType) { LogicGameObjectManager gameObjectManager = this.m_level.GetGameObjectManagerAt(0); LogicBuilding productionHouse = gameObjectManager.GetHighestBuilding(data.GetProductionHouseData()); if (productionHouse != null) { if (!data.IsUnlockedForProductionHouseLevel(productionHouse.GetUpgradeLevel())) { return(false); } if (data.GetUnitOfType() != productionHouse.GetBuildingData().GetProducesUnitsOfType()) { return(false); } } if (this.m_level.GetMissionManager().IsTutorialFinished() || this.m_level.GetHomeOwnerAvatar().GetUnitsTotalCapacity() + this.GetTotalCount() < LogicUnitProduction.TUTORIAL_MAX_CAPACITY) { if (ignoreCapacity) { return(true); } LogicAvatar avatar = this.m_level.GetHomeOwnerAvatar(); LogicComponentManager componentManager = this.m_level.GetComponentManagerAt(this.m_villageType); int totalMaxHousing = componentManager.GetTotalMaxHousing(this.m_unitProductionType != LogicDataType.CHARACTER ? 1 : 0) * 2; int totalUsedCapacity = this.GetTotalCount() + data.GetHousingSpace() + (this.m_unitProductionType == LogicDataType.CHARACTER ? avatar.GetUnitsTotalCapacity() : avatar.GetSpellsTotalCapacity()); return(totalMaxHousing >= totalUsedCapacity); } } else { Debugger.Error("Trying to add wrong unit type to UnitProduction"); } } else { Debugger.Error("Trying to add NULL troop to UnitProduction"); } return(false); }
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 void UpdateProductionHouseListeners(LogicLevel level) { LogicArrayList <LogicGameObject> gameObjects = level.GetGameObjectManager().GetGameObjects(LogicGameObjectType.BUILDING); for (int i = 0; i < gameObjects.Size(); i++) { LogicBuilding building = (LogicBuilding)gameObjects[i]; if (building.GetBuildingData().GetUnitProduction(0) > 0) { building.GetListener().RefreshState(); } } }
private void SpawnCharacter(int x, int y) { int idx = this.m_defenceTroopCount % 2; if (this.m_defenceTroopData[idx] == null) { idx = 0; } LogicBuilding building = (LogicBuilding)this.m_parent; LogicBuildingData buildingData = building.GetBuildingData(); if (buildingData.IsEnabledInVillageType(this.m_parent.GetLevel().GetVillageType()) && this.m_parent.GetLevel().GetState() != 1 && this.m_parent.GetLevel().GetState() != 4) { LogicCharacterData data = this.m_defenceTroopData[idx]; LogicCharacter character = (LogicCharacter)LogicGameObjectFactory.CreateGameObject(data, this.m_parent.GetLevel(), this.m_parent.GetVillageType()); character.SetInitialPosition(x, y); character.SetUpgradeLevel(this.m_defenceTroopUpgradeLevel - 1); character.GetHitpointComponent()?.SetTeam(1); if (LogicDataTables.GetGlobals().EnableDefendingAllianceTroopJump()) { character.GetMovementComponent().EnableJump(3600000); } this.m_parent.GetGameObjectManager().AddGameObject(character, -1); character.GetCombatComponent().SetSearchRadius(LogicDataTables.GetGlobals().GetClanCastleRadius() >> 9); character.GetMovementComponent().GetMovementSystem().CreatePatrolArea(this.m_parent, this.m_parent.GetLevel(), true, this.m_defenceTroopCount); LogicDefenceUnitProductionComponent defenceUnitProductionComponent = building.GetDefenceUnitProduction(); if (defenceUnitProductionComponent != null) { defenceUnitProductionComponent.m_defenceTroops.Add(character); } ++this.m_defenceTroopCount; } }
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; bool success = building.SpeedUpBoostCooldown(); if (building.GetBuildingData().IsClockTower()) { building.GetListener().RefreshState(); } return(success ? 0 : -2); } return(-1); }
public static float GetDefenseStrength(LogicArrayList <LogicGameObject> buildings, LogicArrayList <LogicGameObject> traps, LogicArrayList <LogicHeroData> heroes, int[] heroUpgLevel) { float heroStrength = 0f; float buildingStrength = 0f; float trapStrength = 0; for (int i = 0; i < heroes.Size(); i++) { heroStrength += LogicStrengthUtil.GetHeroStrength(heroes[i], heroUpgLevel[i], true); } for (int i = 0; i < buildings.Size(); i++) { LogicBuilding building = (LogicBuilding)buildings[i]; if (!building.IsLocked()) { if (!building.IsConstructing() || building.IsUpgrading()) { buildingStrength += LogicStrengthUtil.GetBuildingStrength(building.GetBuildingData(), building.GetUpgradeLevel()); } } } for (int i = 0; i < traps.Size(); i++) { LogicTrap trap = (LogicTrap)traps[i]; if (!trap.IsConstructing() || trap.IsUpgrading()) { trapStrength += LogicStrengthUtil.GetTrapStrength(trap.GetTrapData(), trap.GetUpgradeLevel()); } } return(buildingStrength + trapStrength + heroStrength); }
/// <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) { 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 bool ProductionCompleted(bool speedUp) { bool success = false; if (!this.m_locked) { LogicComponentFilter filter = new LogicComponentFilter(); filter.SetComponentType(0); while (true) { LogicAvatar homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar(); LogicComponentManager componentManager = this.m_level.GetComponentManagerAt(this.m_villageType); LogicCombatItemData productionData = this.GetWaitingForSpaceUnit(); if (speedUp) { if (this.m_slots.Size() <= 0) { return(false); } productionData = (LogicCombatItemData)this.m_slots[0].GetData(); } if (productionData == null) { filter.Destruct(); return(false); } bool productionTerminate = this.m_slots[0].IsTerminate(); LogicBuildingData buildingProductionData = productionData.GetProductionHouseData(); LogicGameObjectManager gameObjectManager = this.m_level.GetGameObjectManagerAt(this.m_villageType); LogicBuilding productionHouse = gameObjectManager.GetHighestBuilding(buildingProductionData); if (LogicDataTables.GetGlobals().UseTroopWalksOutFromTraining()) { int gameObjectCount = gameObjectManager.GetNumGameObjects(); for (int i = 0; i < gameObjectCount; i++) { LogicGameObject gameObject = gameObjectManager.GetGameObjectByIndex(i); if (gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding building = (LogicBuilding)gameObject; LogicUnitProductionComponent unitProductionComponent = building.GetUnitProductionComponent(); if (unitProductionComponent != null) { if (unitProductionComponent.GetProductionType() == productionData.GetCombatItemType()) { if (building.GetBuildingData().GetProducesUnitsOfType() == productionData.GetUnitOfType() && !building.IsUpgrading() && !building.IsConstructing()) { if (productionData.IsUnlockedForProductionHouseLevel(building.GetUpgradeLevel())) { if (productionHouse != null) { int seed = this.m_level.GetPlayerAvatar().GetExpPoints(); if (building.Rand(seed) % 1000 > 750) { productionHouse = building; } } else { productionHouse = building; } } } } } } } } if (productionHouse != null) { LogicUnitStorageComponent unitStorageComponent = (LogicUnitStorageComponent)componentManager.GetClosestComponent(productionHouse.GetX(), productionHouse.GetY(), filter); if (unitStorageComponent != null) { if (unitStorageComponent.CanAddUnit(productionData)) { homeOwnerAvatar.CommodityCountChangeHelper(0, productionData, 1); unitStorageComponent.AddUnit(productionData); if (productionTerminate) { this.RemoveUnit(productionData, -1); } else { this.StartProducingNextUnit(); } success = true; if (this.m_slots.Size() > 0 && this.m_slots[0].IsTerminate() && this.m_slots[0].GetCount() > 0) { continue; } break; } filter.AddIgnoreObject(unitStorageComponent.GetParent()); } else { if (this.m_timer != null && this.m_timer.GetRemainingSeconds(this.m_level.GetLogicTime()) == 0) { success = this.TrainingFinished(); } break; } } else { break; } } filter.Destruct(); if (success) { this.m_nextProduction = 0; } else { this.m_nextProduction = 2000; } } return(success); }
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); }
/// <summary> /// Gets the unit training time. /// </summary> public int GetTrainingTime(int index, LogicLevel level, int additionalBarrackCount) { int trainingTime = this._trainingTime[index]; if (this.GetVillageType() != 1 && LogicDataTables.GetGlobals().UseNewTraining() && this.GetCombatItemType() == 0) { if (level != null) { LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(0); if (this._unitType != 0) { if (this._unitType == 1) { int barrackCount = gameObjectManager.GetBarrackCount(); int barrackFound = 0; if (barrackCount > 0) { int productionLevel = this.GetRequiredProductionHouseLevel(); int idx = 0; do { LogicBuilding barrack = (LogicBuilding)gameObjectManager.GetBarrack(idx); if (barrack != null) { if (barrack.GetBuildingData().GetProducesUnitsOfType() == this.GetUnitOfType()) { if (barrack.GetUpgradeLevel() >= productionLevel) { if (!barrack.IsConstructing()) { barrackFound += 1; } } } } } while (++idx != barrackCount); } if (barrackFound + additionalBarrackCount <= 0) { return(trainingTime); } int[] barrackDivisor = LogicDataTables.GetGlobals().GetBarrackReduceTrainingDevisor(); int divisor = barrackDivisor[LogicMath.Min(barrackDivisor.Length - 1, barrackFound + additionalBarrackCount - 1)]; if (divisor > 0) { return(trainingTime / divisor); } return(trainingTime); } if (this.GetUnitOfType() == 2) { int barrackCount = gameObjectManager.GetDarkBarrackCount(); int barrackFound = 0; if (barrackCount > 0) { int productionLevel = this.GetRequiredProductionHouseLevel(); int idx = 0; do { LogicBuilding barrack = (LogicBuilding)gameObjectManager.GetDarkBarrack(idx); if (barrack != null) { if (barrack.GetBuildingData().GetProducesUnitsOfType() == this.GetCombatItemType()) { if (barrack.GetUpgradeLevel() >= productionLevel) { if (!barrack.IsConstructing()) { barrackFound += 1; } } } } } while (++idx != barrackCount); } if (barrackCount + additionalBarrackCount <= 0) { return(trainingTime); } int[] barrackDivisor = LogicDataTables.GetGlobals().GetDarkBarrackReduceTrainingDevisor(); int divisor = barrackDivisor[LogicMath.Min(barrackDivisor.Length - 1, barrackCount + additionalBarrackCount - 1)]; if (divisor > 0) { return(trainingTime / divisor); } return(trainingTime); } } Debugger.Error("invalid type for unit"); } else { Debugger.Error("level was null in getTrainingTime()"); } } return(trainingTime); }
public void ApplyDamagePermil(int x, int y, int unk1, int team, int unk2, int targetType, int damageType, int unk3, bool healing) { LogicSpellData spellData = this.GetSpellData(); int radius = spellData.GetRadius(this.m_upgradeLevel); int troopDamagePermil = spellData.GetTroopDamagePermil(this.m_upgradeLevel); int buildingDamagePermil = spellData.GetBuildingDamagePermil(this.m_upgradeLevel); int executeHealthPermil = spellData.GetExecuteHealthPermil(this.m_upgradeLevel); int damagePermilMin = spellData.GetDamagePermilMin(this.m_upgradeLevel); int preferredTargetDamageMod = spellData.GetPreferredTargetDamageMod(); int preferredDamagePermilMin = spellData.GetPreferredDamagePermilMin(this.m_upgradeLevel); LogicData preferredTarget = spellData.GetPreferredTarget(); LogicVector2 pushBackPosition = new LogicVector2(); LogicArrayList <LogicComponent> components = this.GetComponentManager().GetComponents(LogicComponentType.HITPOINT); int tmp = troopDamagePermil + 2 * buildingDamagePermil; for (int i = 0; i < components.Size(); i++) { LogicHitpointComponent hitpointComponent = (LogicHitpointComponent)components[i]; LogicGameObject parent = hitpointComponent.GetParent(); if (!parent.IsHidden() && hitpointComponent.GetHitpoints() != 0) { if (hitpointComponent.GetTeam() == team) { if (tmp > 0 || tmp < 0 && parent.IsPreventsHealing()) { continue; } } else if (tmp < 0) { continue; } if (damageType == 2 && parent.GetGameObjectType() != LogicGameObjectType.CHARACTER) { continue; } int parentX; int parentY; LogicMovementComponent movementComponent = parent.GetMovementComponent(); if (movementComponent != null || parent.IsFlying()) { if (parent.IsFlying()) { if (targetType == 1) { continue; } } else if (targetType == 0) { continue; } parentX = parent.GetMidX(); parentY = parent.GetMidY(); } else { int posX = parent.GetX(); int posY = parent.GetY(); parentX = LogicMath.Clamp(x, posX, posX + (parent.GetWidthInTiles() << 9)); parentY = LogicMath.Clamp(y, posY, posY + (parent.GetHeightInTiles() << 9)); } int distanceX = x - parentX; int distanceY = y - parentY; if (LogicMath.Abs(distanceX) <= radius && LogicMath.Abs(distanceY) <= radius && distanceX * distanceX + distanceY * distanceY < (uint)(radius * radius)) { if (damageType == 1 && parent.GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding building = (LogicBuilding)parent; if (building.GetResourceStorageComponentComponent() != null && !building.GetBuildingData().IsTownHall() && !building.GetBuildingData().IsTownHallVillage2()) { parent.SetDamageTime(10); continue; } } if (parent.GetGameObjectType() == LogicGameObjectType.BUILDING || parent.GetGameObjectType() == LogicGameObjectType.CHARACTER) { int dataDamagePermil = parent.GetGameObjectType() == LogicGameObjectType.BUILDING ? buildingDamagePermil : troopDamagePermil; if (dataDamagePermil != 0) { int permil = 10 * hitpointComponent.GetMaxHitpoints() * dataDamagePermil / 10000; if (10 * hitpointComponent.GetMaxHitpoints() * dataDamagePermil <= -10000) { if (parent.IsHero()) { permil = LogicDataTables.GetGlobals().GetHeroHealMultiplier() * permil / 100; } } bool isPreferredTarget = LogicCombatComponent.IsPreferredTarget(preferredTarget, parent); int numberOfHits = spellData.GetNumberOfHits(this.m_upgradeLevel); int completePermil = hitpointComponent.GetDamagePermilCount() / spellData.GetNumberOfHits(this.m_upgradeLevel); int calculateDamage = isPreferredTarget ? permil / (completePermil + 1) + preferredTargetDamageMod * hitpointComponent.GetMaxHitpoints() / (100 * numberOfHits) * completePermil * completePermil : permil / (2 * completePermil + 1); int permilMin = isPreferredTarget ? preferredDamagePermilMin : damagePermilMin; int damage = hitpointComponent.GetMaxHitpoints() * permilMin / 10000; if (calculateDamage >= damage) { damage = calculateDamage; } if (executeHealthPermil > 0 && 1000 * (hitpointComponent.GetHitpoints() - damage) <= executeHealthPermil) { damage = hitpointComponent.GetHitpoints(); } hitpointComponent.CauseDamagePermil(damage); if (healing) { // Listener. } if ((distanceX | distanceX) == 0) { distanceX = 1; } pushBackPosition.m_x = -distanceX; pushBackPosition.m_y = -distanceY; pushBackPosition.Normalize(512); if (unk3 > 0 && movementComponent != null) { movementComponent.GetMovementSystem().PushBack(pushBackPosition, damage, unk3, 0, false, true); } } } } } } }
public override int Execute(LogicLevel level) { int count = this.m_gameObjectIds.Size(); if (count > 0) { bool validGameObjects = true; if (this.m_xPositions.Size() == count && this.m_xPositions.Size() == count && count <= 500) { LogicGameObject[] gameObjects = new LogicGameObject[count]; for (int i = 0; i < count; i++) { LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObjectIds[i]); if (gameObject != null) { LogicGameObjectType gameObjectType = gameObject.GetGameObjectType(); if (gameObjectType != LogicGameObjectType.BUILDING && gameObjectType != LogicGameObjectType.TRAP && gameObjectType != LogicGameObjectType.DECO) { validGameObjects = false; } gameObjects[i] = gameObject; } else { validGameObjects = false; } } if (validGameObjects) { for (int i = 0; i < count; i++) { LogicGameObject gameObject = gameObjects[i]; if (gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING && validGameObjects) { LogicBuilding baseWallBlock = (LogicBuilding)gameObject; if (baseWallBlock.GetWallIndex() != 0) { int x = this.m_xPositions[i]; int y = this.m_yPositions[i]; int minX = 0; int minY = 0; int maxX = 0; int maxY = 0; int minWallBlockX = 0; int minWallBlockY = 0; int maxWallBlockX = 0; int maxWallBlockY = 0; int wallBlockCnt = 0; bool success = true; for (int j = 0; j < count; j++) { LogicGameObject obj = gameObjects[j]; if (obj.GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding wallBlock = (LogicBuilding)obj; if (wallBlock.GetWallIndex() == baseWallBlock.GetWallIndex()) { int tmp1 = x - this.m_xPositions[j]; int tmp2 = y - this.m_yPositions[j]; if ((x & this.m_xPositions[j]) != -1) { success = false; } minX = LogicMath.Min(minX, tmp1); minY = LogicMath.Min(minY, tmp2); maxX = LogicMath.Max(maxX, tmp1); maxY = LogicMath.Max(maxY, tmp2); int wallBlockX = wallBlock.GetBuildingData().GetWallBlockX(wallBlockCnt); int wallBlockY = wallBlock.GetBuildingData().GetWallBlockY(wallBlockCnt); minWallBlockX = LogicMath.Min(minWallBlockX, wallBlockX); minWallBlockY = LogicMath.Min(minWallBlockY, wallBlockY); maxWallBlockX = LogicMath.Max(maxWallBlockX, wallBlockX); maxWallBlockY = LogicMath.Max(maxWallBlockY, wallBlockY); ++wallBlockCnt; } } } if (baseWallBlock.GetBuildingData().GetWallBlockCount() == wallBlockCnt) { int wallBlockSizeX = maxWallBlockX - minWallBlockX; int wallBlockSizeY = maxWallBlockY - minWallBlockY; int lengthX = maxX - minX; int lengthY = maxY - minY; if (wallBlockSizeX != lengthX || wallBlockSizeY != lengthY) { if (!success && wallBlockSizeX != lengthX != (wallBlockSizeY != lengthY)) { validGameObjects = false; } } } } } } } if (validGameObjects) { for (int i = 0; i < count; i++) { int x = this.m_xPositions[i]; int y = this.m_yPositions[i]; LogicGameObject gameObject = gameObjects[i]; int width = gameObject.GetWidthInTiles(); int height = gameObject.GetHeightInTiles(); int tmp1 = x + width; int tmp2 = y + height; for (int j = 0; j < count; j++) { LogicGameObject gameObject2 = gameObjects[j]; if (gameObject2 != gameObject) { int x2 = this.m_xPositions[j]; int y2 = this.m_yPositions[j]; if (x2 != -1 && y2 != -1) { int width2 = gameObject2.GetWidthInTiles(); int height2 = gameObject2.GetHeightInTiles(); int tmp3 = x2 + width2; int tmp4 = y2 + height2; if (tmp1 > x2 && tmp2 > y2 && x < tmp3 && y < tmp4) { return(0); } } } } } bool moved = false; for (int i = 0; i < count; i++) { int x = this.m_xPositions[i]; int y = this.m_yPositions[i]; LogicGameObject gameObject = gameObjects[i]; LogicVector2 position = gameObject.GetPositionLayout(this.m_layoutId, true); if (position.m_x != -1 && position.m_y != -1) { if (x != position.m_x && y != position.m_y) { moved = true; } } gameObject.SetPositionLayoutXY(x, y, this.m_layoutId, true); LogicGlobals globals = LogicDataTables.GetGlobals(); if (!globals.NoCooldownFromMoveEditModeActive()) { if (level.GetActiveLayout(level.GetVillageType()) == this.m_layoutId) { LogicAvatar homeOwnerAvatar = level.GetHomeOwnerAvatar(); if (homeOwnerAvatar.GetExpLevel() >= globals.GetChallengeBaseCooldownEnabledTownHall()) { level.SetLayoutCooldownSecs(this.m_layoutId, globals.GetChallengeBaseSaveCooldown()); } } } } if (moved) { LogicAvatar homeOwnerAvatar = level.GetHomeOwnerAvatar(); if (homeOwnerAvatar.GetExpLevel() >= LogicDataTables.GetGlobals().GetChallengeBaseCooldownEnabledTownHall()) { level.SetLayoutCooldownSecs(this.m_layoutId, LogicDataTables.GetGlobals().GetChallengeBaseSaveCooldown()); } } return(0); } } } return(-1); }
public int GetTrainingTime(int index, LogicLevel level, int additionalBarrackCount) { int trainingTime = this.m_trainingTime[index]; if (LogicDataTables.GetGlobals().UseNewTraining() && this.GetVillageType() != 1 && this.GetCombatItemType() == LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER) { if (level != null) { LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(0); switch (this.m_unitType) { case 1: int barrackCount = gameObjectManager.GetBarrackCount(); int productionLevel = this.GetRequiredProductionHouseLevel(); int barrackFound = 0; for (int i = 0; i < barrackCount; i++) { LogicBuilding barrack = (LogicBuilding)gameObjectManager.GetBarrack(i); if (barrack != null) { if (barrack.GetBuildingData().GetProducesUnitsOfType() == this.GetUnitOfType()) { if (barrack.GetUpgradeLevel() >= productionLevel) { if (!barrack.IsConstructing()) { barrackFound += 1; } } } } } if (barrackFound + additionalBarrackCount <= 0) { return(trainingTime); } int[] barrackDivisor = LogicDataTables.GetGlobals().GetBarrackReduceTrainingDevisor(); int divisor = barrackDivisor[LogicMath.Min(barrackDivisor.Length - 1, barrackFound + additionalBarrackCount - 1)]; if (divisor > 0) { return(trainingTime / divisor); } return(trainingTime); case 2: barrackCount = gameObjectManager.GetDarkBarrackCount(); productionLevel = this.GetRequiredProductionHouseLevel(); barrackFound = 0; for (int i = 0; i < barrackCount; i++) { LogicBuilding barrack = (LogicBuilding)gameObjectManager.GetDarkBarrack(i); if (barrack != null) { if (barrack.GetBuildingData().GetProducesUnitsOfType() == this.GetUnitOfType()) { if (barrack.GetUpgradeLevel() >= productionLevel) { if (!barrack.IsConstructing()) { barrackFound += 1; } } } } } if (barrackFound + additionalBarrackCount <= 0) { return(trainingTime); } barrackDivisor = LogicDataTables.GetGlobals().GetDarkBarrackReduceTrainingDevisor(); divisor = barrackDivisor[LogicMath.Min(barrackDivisor.Length - 1, barrackFound + additionalBarrackCount - 1)]; if (divisor > 0) { return(trainingTime / divisor); } return(trainingTime); default: Debugger.Error("invalid type for unit"); break; } } else { Debugger.Error("level was null in getTrainingTime()"); } } return(trainingTime); }
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) { LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObjectId); if (gameObject != null && gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding building = (LogicBuilding)gameObject; LogicBuildingData buildingData = building.GetBuildingData(); if (buildingData.GetVillageType() == level.GetVillageType()) { if (!level.IsBuildingGearUpCapReached(buildingData, true)) { if (building.GetGearLevel() == 0) { int upgLevel = building.GetUpgradeLevel(); int gearUpCost = buildingData.GetGearUpCost(upgLevel); if (gearUpCost > 0) { if (upgLevel >= buildingData.GetMinUpgradeLevelForGearUp()) { if (level.GetGameObjectManagerAt(1).GetHighestBuildingLevel(buildingData.GetGearUpBuildingData()) < buildingData.GetGearUpLevelRequirement()) { return(-1); } LogicResourceData gearUpResource = buildingData.GetGearUpResource(); if (gearUpResource != null) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (playerAvatar.HasEnoughResources(gearUpResource, gearUpCost, true, this, false)) { if (level.HasFreeWorkers(this, 1)) { playerAvatar.CommodityCountChangeHelper(0, gearUpResource, -gearUpCost); building.StartUpgrading(true, true); return(0); } } } return(-1); } return(-37); } return(-36); } return(-35); } return(-31); } return(-32); } return(-1); }
public override int Execute(LogicLevel level) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (playerAvatar != null) { if (this.m_unitData != null) { if (this.m_unitData.GetVillageType() == 0) { if (!this.m_unitData.IsDonationDisabled()) { bool containsUnit = false; int upgLevel = playerAvatar.GetUnitUpgradeLevel(this.m_unitData); LogicUnitProductionComponent unitProductionComponent = null; if (this.m_quickDonate) { int cost = this.m_unitData.GetDonateCost(); if (!playerAvatar.HasEnoughDiamonds(cost, true, level) || !LogicDataTables.GetGlobals().EnableQuickDonateWar()) { playerAvatar.GetChangeListener().WarDonateFailed(this.m_unitData, upgLevel, this.m_streamId, this.m_quickDonate); return(0); } } else { LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(0); if (LogicDataTables.GetGlobals().UseNewTraining()) { LogicUnitProduction unitProduction = gameObjectManager.GetUnitProduction(); LogicUnitProduction spellProduction = gameObjectManager.GetSpellProduction(); if (unitProduction.GetWaitingForSpaceUnitCount(this.m_unitData) > 0) { if (unitProduction.GetUnitProductionType() == this.m_unitData.GetDataType()) { containsUnit = true; } } if (spellProduction.GetWaitingForSpaceUnitCount(this.m_unitData) > 0) { if (spellProduction.GetUnitProductionType() == this.m_unitData.GetDataType()) { containsUnit = true; } } } else { for (int i = 0, c = gameObjectManager.GetNumGameObjects(); i < c; i++) { LogicGameObject gameObject = gameObjectManager.GetGameObjectByIndex(i); if (gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding building = (LogicBuilding)gameObject; LogicUnitProductionComponent component = building.GetUnitProductionComponent(); if (component != null) { unitProductionComponent = component; if (component.ContainsUnit(this.m_unitData)) { if (component.GetRemainingSeconds() == 0 && component.GetCurrentlyTrainedUnit() == this.m_unitData) { containsUnit = true; } } else { unitProductionComponent = null; } } } } } if (!containsUnit) { if (playerAvatar.GetUnitCount(this.m_unitData) <= 0) { playerAvatar.GetChangeListener().WarDonateFailed(this.m_unitData, upgLevel, this.m_streamId, this.m_quickDonate); return(0); } } } if (this.m_unitData.GetCombatItemType() != LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER) { playerAvatar.XpGainHelper(this.m_unitData.GetHousingSpace() * LogicDataTables.GetGlobals().GetDarkSpellDonationXP()); level.GetAchievementManager().AlianceSpellDonated((LogicSpellData)this.m_unitData); } else { playerAvatar.XpGainHelper(((LogicCharacterData)this.m_unitData).GetDonateXP()); level.GetAchievementManager().AlianceUnitDonated((LogicCharacterData)this.m_unitData); } playerAvatar.GetChangeListener().WarDonateOk(this.m_unitData, upgLevel, this.m_streamId, this.m_quickDonate); if (this.m_quickDonate) { int cost = this.m_unitData.GetDonateCost(); playerAvatar.UseDiamonds(cost); playerAvatar.GetChangeListener().DiamondPurchaseMade(12, this.m_unitData.GetGlobalID(), 0, cost, level.GetVillageType()); if (level.GetState() == 1 || level.GetState() == 3 && this.m_unitData.GetCombatItemType() == LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER) { // TODO: Finish this. } } else { if (!containsUnit) { playerAvatar.CommodityCountChangeHelper(0, this.m_unitData, -1); } LogicResourceData trainingResource = this.m_unitData.GetTrainingResource(); int trainingCost = level.GetGameMode().GetCalendar().GetTrainingCost(this.m_unitData, upgLevel); int refund = playerAvatar.GetTroopDonationRefund() * trainingCost / 100; playerAvatar.CommodityCountChangeHelper(0, trainingResource, LogicMath.Max(refund, 0)); if (level.GetState() == 1 || level.GetState() == 3) { if (containsUnit) { if (LogicDataTables.GetGlobals().UseNewTraining()) { LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(0); LogicUnitProduction unitProduction = this.m_unitData.GetCombatItemType() != LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER ? gameObjectManager.GetSpellProduction() : gameObjectManager.GetUnitProduction(); unitProduction.RemoveTrainedUnit(this.m_unitData); } if (this.m_unitData.GetCombatItemType() == LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER) { LogicBuilding productionHouse = null; if (unitProductionComponent != null) { productionHouse = (LogicBuilding)unitProductionComponent.GetParent(); } else { if (LogicDataTables.GetGlobals().UseTroopWalksOutFromTraining()) { LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(0); int gameObjectCount = gameObjectManager.GetNumGameObjects(); for (int i = 0; i < gameObjectCount; i++) { LogicGameObject gameObject = gameObjectManager.GetGameObjectByIndex(i); if (gameObject != null && gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding tmpBuilding = (LogicBuilding)gameObject; LogicUnitProductionComponent tmpComponent = tmpBuilding.GetUnitProductionComponent(); if (tmpComponent != null) { if (tmpComponent.GetProductionType() == this.m_unitData.GetCombatItemType()) { if (tmpBuilding.GetBuildingData().GetProducesUnitsOfType() == this.m_unitData.GetUnitOfType() && !tmpBuilding.IsUpgrading() && !tmpBuilding.IsConstructing()) { if (this.m_unitData.IsUnlockedForProductionHouseLevel(tmpBuilding.GetUpgradeLevel())) { if (productionHouse != null) { int seed = playerAvatar.GetExpPoints(); if (tmpBuilding.Rand(seed) % 1000 > 750) { productionHouse = tmpBuilding; } } else { productionHouse = tmpBuilding; } } } } } } } } } if (productionHouse != null) { // TODO: Implement listener. } } } else { LogicArrayList <LogicComponent> components = level.GetComponentManagerAt(0).GetComponents(LogicComponentType.UNIT_STORAGE); for (int i = 0; i < components.Size(); i++) { LogicUnitStorageComponent unitStorageComponent = (LogicUnitStorageComponent)components[i]; int idx = unitStorageComponent.GetUnitTypeIndex(this.m_unitData); if (idx != -1) { if (unitStorageComponent.GetUnitCount(idx) > 0) { unitStorageComponent.RemoveUnits(this.m_unitData, 1); if (LogicDataTables.GetGlobals().UseNewTraining()) { LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(0); LogicUnitProduction unitProduction = this.m_unitData.GetCombatItemType() != LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER ? gameObjectManager.GetSpellProduction() : gameObjectManager.GetUnitProduction(); unitProduction.MergeSlots(); unitProduction.UnitRemoved(); } break; } } } } // TODO: Finish this. } } return(0); } return(-91); } return(-45); } } return(0); }
public override int Execute(LogicLevel level) { if (this.m_layoutId != -1) { if (level.GetTownHallLevel(level.GetVillageType()) >= level.GetRequiredTownHallLevelForLayout(this.m_layoutId, -1)) { if ((this.m_layoutId & 0xFFFFFFFE) != 6) { if (this.m_layoutType != 0) { if (this.m_layoutId != 1 && this.m_layoutId != 4 && this.m_layoutId != 5) { return(-5); } } else { if (this.m_layoutId != 0 && this.m_layoutId != 2 && this.m_layoutId != 3) { return(-4); } } } LogicGameObjectFilter filter = new LogicGameObjectFilter(); LogicArrayList <LogicGameObject> gameObjects = new LogicArrayList <LogicGameObject>(500); filter.AddGameObjectType(LogicGameObjectType.BUILDING); filter.AddGameObjectType(LogicGameObjectType.TRAP); filter.AddGameObjectType(LogicGameObjectType.DECO); level.GetGameObjectManager().GetGameObjects(gameObjects, filter); for (int i = 0; i < gameObjects.Size(); i++) { LogicGameObject gameObject = gameObjects[i]; LogicVector2 position = gameObject.GetPositionLayout(this.m_layoutId, false); if ((this.m_layoutId & 0xFFFFFFFE) != 6 && (position.m_x == -1 || position.m_y == -1)) { return(-2); } } LogicGameObjectManager gameObjectManager = level.GetGameObjectManager(); LogicArrayList <LogicGameObject> buildings = gameObjectManager.GetGameObjects(LogicGameObjectType.BUILDING); LogicArrayList <LogicGameObject> obstacles = gameObjectManager.GetGameObjects(LogicGameObjectType.OBSTACLE); for (int i = 0; i < gameObjects.Size(); i++) { LogicGameObject gameObject = gameObjects[i]; LogicVector2 position = gameObject.GetPositionLayout(this.m_layoutId, false); int minX = position.m_x; int minY = position.m_y; int maxX = minX + gameObject.GetWidthInTiles(); int maxY = minY + gameObject.GetHeightInTiles(); for (int j = 0; j < obstacles.Size(); j++) { LogicObstacle obstacle = (LogicObstacle)obstacles[j]; int minX2 = obstacle.GetTileX(); int minY2 = obstacle.GetTileY(); int maxX2 = minX2 + obstacle.GetWidthInTiles(); int maxY2 = minY2 + obstacle.GetHeightInTiles(); if (maxX > minX2 && maxY > minY2 && minX < maxX2 && minY < maxY2) { if ((this.m_layoutId & 0xFFFFFFFE) != 6) { return(-2); } gameObjectManager.RemoveGameObject(obstacle); j -= 1; } } } for (int i = 0; i < buildings.Size(); i++) { LogicBuilding baseWallBlock = (LogicBuilding)buildings[i]; if (baseWallBlock.GetWallIndex() != 0) { int x = baseWallBlock.GetTileX(); int y = baseWallBlock.GetTileY(); int minX = 0; int minY = 0; int maxX = 0; int maxY = 0; int minWallBlockX = 0; int minWallBlockY = 0; int maxWallBlockX = 0; int maxWallBlockY = 0; int wallBlockCnt = 0; for (int j = 0; j < buildings.Size(); j++) { LogicBuilding wallBlock = (LogicBuilding)buildings[j]; if (wallBlock.GetWallIndex() == baseWallBlock.GetWallIndex()) { int tmp1 = x - wallBlock.GetTileX(); int tmp2 = y - wallBlock.GetTileY(); minX = LogicMath.Min(minX, tmp1); minY = LogicMath.Min(minY, tmp2); maxX = LogicMath.Max(maxX, tmp1); maxY = LogicMath.Max(maxY, tmp2); int wallBlockX = wallBlock.GetBuildingData().GetWallBlockX(wallBlockCnt); int wallBlockY = wallBlock.GetBuildingData().GetWallBlockY(wallBlockCnt); minWallBlockX = LogicMath.Min(minWallBlockX, wallBlockX); minWallBlockY = LogicMath.Min(minWallBlockY, wallBlockY); maxWallBlockX = LogicMath.Max(maxWallBlockX, wallBlockX); maxWallBlockY = LogicMath.Max(maxWallBlockY, wallBlockY); ++wallBlockCnt; } } if (baseWallBlock.GetBuildingData().GetWallBlockCount() != wallBlockCnt) { return(-24); } int wallBlockSizeX = maxWallBlockX - minWallBlockX; int wallBlockSizeY = maxWallBlockY - minWallBlockY; int lengthX = maxX - minX; int lengthY = maxY - minY; if (wallBlockSizeX != lengthX || wallBlockSizeY != lengthY) { if (wallBlockSizeX != lengthX != (wallBlockSizeY != lengthY)) { return(-25); } } } } if (this.m_layoutType != 0) { if (level.IsWarBase()) { level.SetWarBase(true); } level.SetActiveWarLayout(this.m_layoutId); } else { level.SetActiveLayout(this.m_layoutId, level.GetVillageType()); for (int i = 0; i < gameObjects.Size(); i++) { LogicGameObject gameObject = gameObjects[i]; LogicVector2 position = gameObject.GetPositionLayout(this.m_layoutId, false); gameObject.SetPositionXY(position.m_x << 9, position.m_y << 9); } } return(0); } } return(-10); }
public override int Execute(LogicLevel level) { int count = this.m_gameObjectIds.Size(); if (count > 0) { bool validGameObjectType = true; if (this.m_xPositions.Size() == count && this.m_xPositions.Size() == count && count <= 500) { LogicGameObject[] gameObjects = new LogicGameObject[count]; for (int i = 0; i < count; i++) { LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObjectIds[i]); if (gameObject != null) { LogicGameObjectType gameObjectType = gameObject.GetGameObjectType(); if (gameObjectType != LogicGameObjectType.BUILDING && gameObjectType != LogicGameObjectType.TRAP && gameObjectType != LogicGameObjectType.DECO) { validGameObjectType = false; } gameObjects[i] = gameObject; } else { validGameObjectType = false; } } if (validGameObjectType) { for (int i = 0; i < count; i++) { LogicGameObject gameObject = gameObjects[i]; if (gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING && validGameObjectType) { LogicBuilding baseWallBlock = (LogicBuilding)gameObject; if (baseWallBlock.GetWallIndex() != 0) { int x = this.m_xPositions[i]; int y = this.m_yPositions[i]; int minX = 0; int minY = 0; int maxX = 0; int maxY = 0; int minWallBlockX = 0; int minWallBlockY = 0; int maxWallBlockX = 0; int maxWallBlockY = 0; int wallBlockCnt = 0; bool success = true; for (int j = 0; j < count; j++) { LogicGameObject obj = gameObjects[j]; if (obj.GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding wallBlock = (LogicBuilding)obj; if (wallBlock.GetWallIndex() == baseWallBlock.GetWallIndex()) { int tmp1 = x - this.m_xPositions[j]; int tmp2 = y - this.m_yPositions[j]; if ((x & this.m_xPositions[j]) != -1) { success = false; } minX = LogicMath.Min(minX, tmp1); minY = LogicMath.Min(minY, tmp2); maxX = LogicMath.Max(maxX, tmp1); maxY = LogicMath.Max(maxY, tmp2); int wallBlockX = wallBlock.GetBuildingData().GetWallBlockX(wallBlockCnt); int wallBlockY = wallBlock.GetBuildingData().GetWallBlockY(wallBlockCnt); minWallBlockX = LogicMath.Min(minWallBlockX, wallBlockX); minWallBlockY = LogicMath.Min(minWallBlockY, wallBlockY); maxWallBlockX = LogicMath.Max(maxWallBlockX, wallBlockX); maxWallBlockY = LogicMath.Max(maxWallBlockY, wallBlockY); ++wallBlockCnt; } } } if (baseWallBlock.GetBuildingData().GetWallBlockCount() == wallBlockCnt) { int wallBlockSizeX = maxWallBlockX - minWallBlockX; int wallBlockSizeY = maxWallBlockY - minWallBlockY; int lengthX = maxX - minX; int lengthY = maxY - minY; if (wallBlockSizeX != lengthX || wallBlockSizeY != lengthY) { if (!success && wallBlockSizeX != lengthX != (wallBlockSizeY != lengthY)) { validGameObjectType = false; } } } } } } } else { Debugger.Warning("EditModeInvalidGameObjectType"); return(-1); } if (validGameObjectType) { for (int i = 0; i < count; i++) { int x = this.m_xPositions[i]; int y = this.m_yPositions[i]; LogicGameObject gameObject = gameObjects[i]; int maxX = x + gameObject.GetWidthInTiles(); int maxY = y + gameObject.GetHeightInTiles(); for (int j = 0; j < count; j++) { LogicGameObject gameObject2 = gameObjects[j]; if (gameObject2 != gameObject) { int x2 = this.m_xPositions[j]; int y2 = this.m_yPositions[j]; int maxX2 = x2 + gameObject2.GetWidthInTiles(); int maxY2 = y2 + gameObject2.GetHeightInTiles(); if (maxX > x2 && maxY > y2 && x < maxX2 && y < maxY2) { Debugger.Warning("EditModeObjectsOverlap"); return(-1); } } } } } if (validGameObjectType) { for (int i = 0; i < count; i++) { int x = this.m_xPositions[i]; int y = this.m_yPositions[i]; LogicGameObject gameObject = gameObjects[i]; int width = gameObject.GetWidthInTiles(); int height = gameObject.GetHeightInTiles(); if (!level.IsValidPlaceForBuildingWithIgnoreList(x, y, width, height, gameObjects, count)) { Debugger.Warning("EditModeInvalidPosition"); return(-1); } } } if (validGameObjectType) { for (int i = 0; i < count; i++) { int x = this.m_xPositions[i]; int y = this.m_yPositions[i]; LogicGameObject gameObject = gameObjects[i]; gameObject.SetPositionXY(x << 9, y << 9); } for (int i = 0; i < count; i++) { int x = this.m_xPositions[i]; int y = this.m_yPositions[i]; LogicGameObject gameObject = gameObjects[i]; int width = gameObject.GetWidthInTiles(); int height = gameObject.GetHeightInTiles(); for (int j = 0; j < width; j++) { for (int k = 0; k < height; k++) { LogicObstacle tallGrass = level.GetTileMap().GetTile(x + j, y + k).GetTallGrass(); if (tallGrass != null) { level.GetGameObjectManager().RemoveGameObject(tallGrass); } } } } if (level.GetHomeOwnerAvatar() != null) { LogicAvatar homeOwnerAvatar = level.GetHomeOwnerAvatar(); if (homeOwnerAvatar.GetTownHallLevel() >= LogicDataTables.GetGlobals().GetChallengeBaseCooldownEnabledTownHall()) { level.SetLayoutCooldownSecs(level.GetActiveLayout(level.GetVillageType()), LogicDataTables.GetGlobals().GetChallengeBaseSaveCooldown()); } } return(0); } } else { Debugger.Warning("EditModeSizeMismatch"); } return(-1); } return(-92); }
/// <summary> /// Refreshes the mission progress. /// </summary> public void RefreshProgress() { LogicGameObjectManager gameObjectManager = this._level.GetGameObjectManager(); switch (this._data.GetMissionType()) { case 0: case 5: this._progress = 0; if (this._level.GetState() == 1) { LogicArrayList <LogicGameObject> gameObjects = gameObjectManager.GetGameObjects(0); for (int i = 0; i < gameObjects.Count; i++) { LogicBuilding building = (LogicBuilding)gameObjects[i]; if (building.GetBuildingData() == this._data.GetBuildBuildingData()) { if (!building.IsConstructing() || building.IsUpgrading()) { if (building.GetUpgradeLevel() >= this._data.GetBuildBuildingLevel()) { ++this._progress; } } } } } break; case 4: this._progress = this._level.GetPlayerAvatar().GetUnitsTotalCapacity(); break; case 6: this._progress = this._level.GetPlayerAvatar().GetNameSetByUser() ? 1 : 0; break; case 13: this._progress = 0; if (this._level.GetState() == 1) { LogicArrayList <LogicGameObject> gameObjects = gameObjectManager.GetGameObjects(8); for (int i = 0; i < gameObjects.Count; i++) { LogicVillageObject villageObject = (LogicVillageObject)gameObjects[i]; if (villageObject.GetVillageObjectData() == this._data.GetFixVillageObjectData() && villageObject.GetUpgradeLevel() >= this._data.GetBuildBuildingLevel()) { ++this._progress; } } } break; case 14: this._progress = 0; if (this._level.GetState() == 1 && this._level.GetVillageType() == 1) { ++this._progress; } break; case 15: this._progress = 0; if (this._level.GetState() == 1) { LogicArrayList <LogicGameObject> gameObjects = gameObjectManager.GetGameObjects(0); for (int i = 0; i < gameObjects.Count; i++) { LogicBuilding building = (LogicBuilding)gameObjects[i]; if (building.GetBuildingData() == this._data.GetBuildBuildingData()) { if (!building.IsLocked()) { ++this._progress; } } } } break; case 17: this._progress = 0; if (this._level.GetState() == 1 && this._level.GetVillageType() == 1) { if (this._level.GetPlayerAvatar().GetUnitUpgradeLevel(this._data.GetCharacterData()) > 0) { ++this._progress; } } break; } if (this._progress >= this._requireProgress) { this._progress = this._requireProgress; this.Finished(); } }
public static void SetBuildingUpgradeLevel(LogicLevel level, int gameObjectId, int upgLevel, int villageType) { LogicGameObject gameObject = level.GetGameObjectManagerAt(villageType).GetGameObjectByID(gameObjectId); if (gameObject != null) { if (gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding building = (LogicBuilding)gameObject; LogicBuildingData buildingData = building.GetBuildingData(); if (building.GetGearLevel() > 0 || building.IsGearing()) { if (buildingData.GetMinUpgradeLevelForGearUp() > upgLevel) { Debugger.HudPrint("Can't downgrade geared up building below gear up limit!"); upgLevel = buildingData.GetMinUpgradeLevelForGearUp(); } } if (buildingData.IsTownHall()) { level.GetPlayerAvatar().SetTownHallLevel(upgLevel); } building.SetUpgradeLevel(LogicMath.Max(upgLevel - 1, 0)); building.FinishConstruction(false, true); building.SetUpgradeLevel(upgLevel); if (building.GetListener() != null) { building.GetListener().RefreshState(); } if (buildingData.IsTownHall() || buildingData.IsTownHallVillage2()) { level.RefreshNewShopUnlocks(buildingData.GetVillageType()); } } else if (gameObject.GetGameObjectType() == LogicGameObjectType.TRAP) { LogicTrap trap = (LogicTrap)gameObject; trap.SetUpgradeLevel(LogicMath.Max(upgLevel - 1, 0)); trap.FinishConstruction(false); trap.SetUpgradeLevel(upgLevel); trap.RepairTrap(); if (trap.GetListener() != null) { trap.GetListener().RefreshState(); } } else if (gameObject.GetGameObjectType() == LogicGameObjectType.VILLAGE_OBJECT) { LogicVillageObject villageObject = (LogicVillageObject)gameObject; villageObject.SetUpgradeLevel(LogicMath.Max(upgLevel - 1, 0)); villageObject.SetUpgradeLevel(upgLevel); if (villageObject.GetListener() != null) { villageObject.GetListener().RefreshState(); } } } }
/// <summary> /// Executes this command. /// </summary> public override int Execute(LogicLevel level) { int count = this._gameObjectIds.Count; if (count > 0) { bool validSize = true; bool validGameObjects = true; if (this._xPositions.Count != count || this._xPositions.Count != count || count > 500) { validSize = false; } if (validSize) { LogicGameObject[] gameObjects = new LogicGameObject[count]; for (int i = 0; i < count; i++) { LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this._gameObjectIds[i]); if (gameObject != null) { int gameObjectType = gameObject.GetGameObjectType(); if (gameObjectType > 6 || gameObjectType == 3) { validGameObjects = false; } gameObjects[i] = gameObject; } else { validGameObjects = false; } } if (validGameObjects) { bool validWallBlock = true; for (int i = 0; i < count; i++) { LogicGameObject gameObject = gameObjects[i]; if (gameObject.GetGameObjectType() == 0 && ((LogicBuilding)gameObject).GetWallIndex() != 0 && validWallBlock) { LogicBuilding baseWallBlock = (LogicBuilding)gameObject; int x = this._xPositions[i]; int y = this._yPositions[i]; int minX = 0; int minY = 0; int maxX = 0; int maxY = 0; int minWallBlockX = 0; int minWallBlockY = 0; int maxWallBlockX = 0; int maxWallBlockY = 0; bool success = true; int wallBlockCnt = -1; for (int j = 0; j < count; j++) { LogicGameObject obj = gameObjects[j]; if (obj.GetGameObjectType() == 0 && ((LogicBuilding)obj).GetWallIndex() == baseWallBlock.GetWallIndex()) { LogicBuilding wallBlock = (LogicBuilding)obj; int tmp1 = x - this._xPositions[j]; int tmp2 = y - this._yPositions[j]; if ((x & this._xPositions[j]) != -1) { success = false; } minX = LogicMath.Min(minX, tmp1); minY = LogicMath.Min(minY, tmp2); maxX = LogicMath.Max(maxX, tmp1); maxY = LogicMath.Max(maxY, tmp2); int wallBlockX = wallBlock.GetBuildingData().GetWallBlockX(j); int wallBlockY = wallBlock.GetBuildingData().GetWallBlockY(j); minWallBlockX = LogicMath.Min(minWallBlockX, wallBlockX); minWallBlockY = LogicMath.Min(minWallBlockY, wallBlockY); maxWallBlockX = LogicMath.Min(maxWallBlockX, wallBlockX); maxWallBlockY = LogicMath.Min(maxWallBlockY, wallBlockY); ++wallBlockCnt; } } if (baseWallBlock.GetBuildingData().GetWallBlockCount() == wallBlockCnt) { int wallBlockSizeX = maxWallBlockX - minWallBlockX; int wallBlockSizeY = maxWallBlockY - minWallBlockY; int lengthX = maxX - minX; int lengthY = maxY - minY; if (wallBlockSizeX != lengthX || wallBlockSizeY != lengthY) { if (!success && (wallBlockSizeX != lengthX) != (wallBlockSizeY != lengthY)) { validGameObjects = false; } } } } } } else { // EditmodeInvalidGameObjectType. } bool objectsOverlap = false; if (validGameObjects) { int idx = 0; while (idx < count) { int x = this._xPositions[idx]; int y = this._yPositions[idx]; LogicGameObject gameObject = gameObjects[idx]; int width = gameObject.GetWidthInTiles(); int height = gameObject.GetHeightInTiles(); int tmp1 = x + width; int tmp2 = y + height; for (int i = 0; i < count; i++) { LogicGameObject gameObject2 = gameObjects[idx]; if (gameObject2 != gameObject) { int x2 = this._xPositions[i]; int y2 = this._yPositions[i]; int width2 = gameObject2.GetWidthInTiles(); int height2 = gameObject2.GetHeightInTiles(); int tmp3 = x + width2; int tmp4 = y + height2; if (tmp1 > x2 && tmp2 > y2 && x2 < tmp3 && y2 < tmp4) { objectsOverlap = true; return(0); } } } ++idx; } } if (validGameObjects) { for (int i = 0; i < count; i++) { int x = this._xPositions[i]; int y = this._yPositions[i]; LogicGameObject gameObject = gameObjects[i]; int width = gameObject.GetWidthInTiles(); int height = gameObject.GetHeightInTiles(); if (!level.IsValidPlaceForBuildingWithIgnoreList(x, y, width, height, gameObjects, count)) { if (validGameObjects) { // EditmodeInvalidPosition. } validGameObjects = false; } } } if (validGameObjects) { for (int i = 0; i < count; i++) { int x = this._xPositions[i]; int y = this._yPositions[i]; LogicGameObject gameObject = gameObjects[i]; gameObject.SetPositionXY(x << 9, y << 9); } for (int i = 0; i < count; i++) { int x = this._xPositions[i]; int y = this._yPositions[i]; LogicGameObject gameObject = gameObjects[i]; int width = gameObject.GetWidthInTiles(); int height = gameObject.GetHeightInTiles(); for (int j = 0; j < width; j++) { for (int k = 0; k < height; k++) { LogicObstacle tallGrass = level.GetTileMap().GetTile(x + j, y + k).GetTallGrass(); if (tallGrass != null) { level.GetGameObjectManager().RemoveGameObject(tallGrass); } } } } if (validGameObjects) { 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(-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); }