Exemplo n.º 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);
        }
        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();
                    }
                }
            }
        }