Beispiel #1
0
        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);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        /// <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);
        }
Beispiel #4
0
        /// <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);
        }