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 bool FinishTaskOfOneWorker() { LogicGameObject gameObject = this.GetShortestTaskGO(); if (gameObject != null) { switch (gameObject.GetGameObjectType()) { case LogicGameObjectType.BUILDING: LogicBuilding building = (LogicBuilding)gameObject; if (building.IsConstructing()) { return(building.SpeedUpConstruction()); } if (building.GetHeroBaseComponent() != null) { return(building.GetHeroBaseComponent().SpeedUp()); } break; case LogicGameObjectType.OBSTACLE: LogicObstacle obstacle = (LogicObstacle)gameObject; if (obstacle.IsClearingOnGoing()) { return(obstacle.SpeedUpClearing()); } break; case LogicGameObjectType.TRAP: LogicTrap trap = (LogicTrap)gameObject; if (trap.IsConstructing()) { return(trap.SpeedUpConstruction()); } break; case LogicGameObjectType.VILLAGE_OBJECT: LogicVillageObject villageObject = (LogicVillageObject)gameObject; if (villageObject.IsConstructing()) { return(villageObject.SpeedUpCostruction()); } break; } } return(false); }
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); }
/// <summary> /// Finishes the task of one worker. /// </summary> public bool FinishTaskOfOneWorker() { LogicGameObject gameObject = this.GetShortestTaskGO(); if (gameObject != null) { switch (gameObject.GetGameObjectType()) { case 0: LogicBuilding building = (LogicBuilding)gameObject; if (building.IsConstructing()) { return(building.SpeedUpConstruction()); } if (building.GetHeroBaseComponent() != null) { // TODO: Implement LogicHeroBaseComponent::speedUpUpgrade. } break; case 3: LogicObstacle obstacle = (LogicObstacle)gameObject; if (obstacle.IsClearingOnGoing()) { return(obstacle.SpeedUpClearing()); } break; case 4: LogicTrap trap = (LogicTrap)gameObject; if (trap.IsConstructing()) { return(trap.SpeedUpConstruction()); } break; case 8: LogicVillageObject villageObject = (LogicVillageObject)gameObject; break; } } return(false); }
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> /// Gets the shortest task. /// </summary> public LogicGameObject GetShortestTaskGO() { LogicGameObject gameObject = null; for (int i = 0, minRemaining = -1, tmpRemaining = 0; i < this._constructions.Count; i++, tmpRemaining = 0) { LogicGameObject tmp = this._constructions[i]; switch (this._constructions[i].GetGameObjectType()) { case 0: LogicBuilding building = (LogicBuilding)tmp; if (building.IsConstructing()) { tmpRemaining = building.GetRemainingConstructionTime(); } else { LogicHeroBaseComponent heroBaseComponent = building.GetHeroBaseComponent(); if (heroBaseComponent == null) { Debugger.Warning("LogicWorkerManager - Worker allocated to altar/herobase without hero upgrading"); } else { if (heroBaseComponent.IsUpgrading()) { tmpRemaining = heroBaseComponent.GetRemainingUpgradeSeconds(); } else { Debugger.Warning("LogicWorkerManager - Worker allocated to building with remaining construction time 0"); } } } break; case 3: LogicObstacle obstacle = (LogicObstacle)tmp; if (obstacle.IsClearingOnGoing()) { tmpRemaining = obstacle.GetRemainingClearingTime(); } else { Debugger.Warning("LogicWorkerManager - Worker allocated to obstacle with remaining clearing time 0"); } break; case 4: LogicTrap trap = (LogicTrap)tmp; if (trap.IsConstructing()) { tmpRemaining = trap.GetRemainingConstructionTime(); } else { Debugger.Warning("LogicWorkerManager - Worker allocated to trap with remaining construction time 0"); } break; case 8: break; } if (gameObject == null || minRemaining > tmpRemaining) { gameObject = tmp; minRemaining = tmpRemaining; } } return(gameObject); }