Ejemplo n.º 1
0
        public override int Execute(LogicLevel level)
        {
            LogicAvatarAllianceRole allianceRole = level.GetHomeOwnerAvatar().GetAllianceRole();

            if (allianceRole == LogicAvatarAllianceRole.LEADER || allianceRole == LogicAvatarAllianceRole.CO_LEADER)
            {
                LogicBuilding allianceCastle = level.GetGameObjectManagerAt(0).GetAllianceCastle();

                if (allianceCastle != null)
                {
                    LogicBunkerComponent bunkerComponent = allianceCastle.GetBunkerComponent();

                    if (bunkerComponent != null && bunkerComponent.GetClanMailCooldownTime() == 0)
                    {
                        bunkerComponent.StartClanMailCooldownTime();
                        level.GetHomeOwnerAvatar().GetChangeListener().SendClanMail(this.m_message);

                        return(0);
                    }
                }

                return(-2);
            }

            return(-1);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }
        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);
        }
Ejemplo n.º 5
0
        public override int Execute(LogicLevel level)
        {
            LogicBuilding allianceCastle = level.GetGameObjectManagerAt(0).GetAllianceCastle();

            if (allianceCastle != null)
            {
                LogicBunkerComponent bunkerComponent = allianceCastle.GetBunkerComponent();

                if (bunkerComponent != null && bunkerComponent.GetRequestCooldownTime() == 0)
                {
                    LogicAvatar homeOwnerAvatar = level.GetHomeOwnerAvatar();

                    homeOwnerAvatar.GetChangeListener().RequestAllianceUnits(allianceCastle.GetUpgradeLevel(),
                                                                             bunkerComponent.GetUsedCapacity(),
                                                                             bunkerComponent.GetMaxCapacity(),
                                                                             homeOwnerAvatar.GetAllianceCastleUsedSpellCapacity(),
                                                                             homeOwnerAvatar.GetAllianceCastleTotalSpellCapacity(),
                                                                             this.m_message);

                    bunkerComponent.StartRequestCooldownTime();

                    return(0);
                }
            }

            return(-1);
        }
        public void ReengageLootCart(int secs)
        {
            LogicObstacleData      obstacleData      = this.GetObstacleData();
            LogicLootCartComponent lootCartComponent = (LogicLootCartComponent)this.GetComponent(LogicComponentType.LOOT_CART);
            LogicBuilding          townHall          = this.m_level.GetGameObjectManagerAt(0).GetTownHall();

            Debugger.DoAssert(obstacleData.IsLootCart(), string.Empty);
            Debugger.DoAssert(lootCartComponent != null, string.Empty);
            Debugger.DoAssert(townHall != null, string.Empty);

            LogicDataTable resourceTable = LogicDataTables.GetTable(LogicDataType.RESOURCE);

            for (int i = 0; i < resourceTable.GetItemCount(); i++)
            {
                LogicResourceData      resourceData      = (LogicResourceData)resourceTable.GetItemAt(i);
                LogicTownhallLevelData townhallLevelData = LogicDataTables.GetTownHallLevel(townHall.GetUpgradeLevel());

                int cap = secs * townhallLevelData.GetCartLootReengagement(resourceData) / 100;

                if (cap > lootCartComponent.GetResourceCount(i))
                {
                    lootCartComponent.SetResourceCount(i, cap);
                }
            }
        }
        public override int Execute(LogicLevel level)
        {
            LogicBuilding allianceCastle = level.GetGameObjectManagerAt(0).GetAllianceCastle();

            if (allianceCastle != null)
            {
                LogicBunkerComponent bunkerComponent = allianceCastle.GetBunkerComponent();

                if (bunkerComponent != null)
                {
                    if (bunkerComponent.GetReplayShareCooldownTime() == 0)
                    {
                        bunkerComponent.StartReplayShareCooldownTime();

                        if (this.m_duelReplay)
                        {
                            level.GetGameListener().DuelReplayShared(this.m_battleEntryId);
                            level.GetHomeOwnerAvatar().GetChangeListener().ShareDuelReplay(this.m_battleEntryId, this.m_message);
                        }
                        else
                        {
                            level.GetHomeOwnerAvatar().GetChangeListener().ShareReplay(this.m_battleEntryId, this.m_message);
                        }

                        return(0);
                    }
                }
            }

            return(-1);
        }
Ejemplo n.º 8
0
        /// <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);
        }
Ejemplo n.º 9
0
        public override int Execute(LogicLevel level)
        {
            LogicAvatar             homeOwnerAvatar = level.GetHomeOwnerAvatar();
            LogicAvatarAllianceRole allianceRole    = homeOwnerAvatar.GetAllianceRole();

            if (allianceRole != LogicAvatarAllianceRole.MEMBER)
            {
                if (allianceRole == LogicAvatarAllianceRole.LEADER || allianceRole == LogicAvatarAllianceRole.CO_LEADER)
                {
                    level.GetHomeOwnerAvatar().GetChangeListener().KickPlayer(this.m_playerId, this.m_message);
                    return(0);
                }

                LogicBuilding allianceCastle = level.GetGameObjectManagerAt(0).GetAllianceCastle();

                if (allianceCastle != null)
                {
                    LogicBunkerComponent bunkerComponent = allianceCastle.GetBunkerComponent();

                    if (bunkerComponent != null)
                    {
                        if (bunkerComponent.GetElderCooldownTime() == 0)
                        {
                            bunkerComponent.StartElderKickCooldownTime();
                            level.GetHomeOwnerAvatar().GetChangeListener().KickPlayer(this.m_playerId, this.m_message);
                            return(0);
                        }
                    }
                }

                return(-2);
            }

            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 (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 void Tick()
        {
            if (this.m_parent.IsAlive())
            {
                if (LogicDataTables.GetGlobals().GuardPostNotFunctionalUnderUpgrade())
                {
                    if (this.m_parent.GetGameObjectType() == LogicGameObjectType.BUILDING)
                    {
                        LogicBuilding building = (LogicBuilding)this.m_parent;

                        if (building.IsConstructing())
                        {
                            return;
                        }
                    }
                }

                if (this.m_maxDefenceTroopCount > this.m_defenceTroopCount)
                {
                    if (this.m_spawnCooldownTimer == null || this.m_spawnCooldownTimer.GetRemainingSeconds(this.m_parent.GetLevel().GetLogicTime()) <= 0)
                    {
                        this.SpawnCharacter(this.m_parent.GetX(), this.m_parent.GetY() + (this.m_parent.GetHeightInTiles() << 8));

                        if (this.m_maxDefenceTroopCount > this.m_defenceTroops.Size())
                        {
                            this.StartSpawnCooldownTimer();
                        }
                    }
                }
            }
        }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
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);
        }
Ejemplo n.º 14
0
        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);
        }
Ejemplo n.º 15
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;
                    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);
        }
Ejemplo n.º 16
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;
                    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);
        }
Ejemplo n.º 17
0
        /// <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 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);
                }
            }
        }
Ejemplo n.º 19
0
        public static LogicGameObject CreateGameObject(LogicGameObjectData data, LogicLevel level, int villageType)
        {
            LogicGameObject gameObject = null;

            switch (data.GetDataType())
            {
            case LogicDataType.BUILDING:
                gameObject = new LogicBuilding(data, level, villageType);
                break;

            case LogicDataType.CHARACTER:
            case LogicDataType.HERO:
                gameObject = new LogicCharacter(data, level, villageType);
                break;

            case LogicDataType.PROJECTILE:
                gameObject = new LogicProjectile(data, level, villageType);
                break;

            case LogicDataType.OBSTACLE:
                gameObject = new LogicObstacle(data, level, villageType);
                break;

            case LogicDataType.TRAP:
                gameObject = new LogicTrap(data, level, villageType);
                break;

            case LogicDataType.ALLIANCE_PORTAL:
                gameObject = new LogicAlliancePortal(data, level, villageType);
                break;

            case LogicDataType.DECO:
                gameObject = new LogicDeco(data, level, villageType);
                break;

            case LogicDataType.SPELL:
                gameObject = new LogicSpell(data, level, villageType);
                break;

            case LogicDataType.VILLAGE_OBJECT:
                gameObject = new LogicVillageObject(data, level, villageType);
                break;

            default:
            {
                Debugger.Warning("Trying to create game object with data that does not inherit LogicGameObjectData. GlobalId=" + data.GetGlobalID());
                break;
            }
            }

            return(gameObject);
        }
Ejemplo n.º 20
0
        public bool CanStartUpgrading(LogicCombatItemData data)
        {
            if (data != null && this.m_unit == null)
            {
                if (this.m_parent.GetLevel().GetGameMode().GetCalendar().IsProductionEnabled(data))
                {
                    if (data.GetCombatItemType() != LogicCombatItemData.COMBAT_ITEM_TYPE_HERO)
                    {
                        if (this.m_parent.GetVillageType() == data.GetVillageType())
                        {
                            int upgLevel = this.m_parent.GetLevel().GetHomeOwnerAvatar().GetUnitUpgradeLevel(data);

                            if (data.GetUpgradeLevelCount() - 1 > upgLevel)
                            {
                                int maxProductionHouseLevel;

                                if (data.GetVillageType() == 1)
                                {
                                    maxProductionHouseLevel = this.m_parent.GetComponentManager().GetMaxBarrackLevel();
                                }
                                else
                                {
                                    LogicComponentManager componentManager = this.m_parent.GetComponentManager();

                                    if (data.GetCombatItemType() == LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER)
                                    {
                                        maxProductionHouseLevel = data.GetUnitOfType() != 1 ? componentManager.GetMaxDarkBarrackLevel() : componentManager.GetMaxBarrackLevel();
                                    }
                                    else
                                    {
                                        maxProductionHouseLevel =
                                            data.GetUnitOfType() == 1 ? componentManager.GetMaxSpellForgeLevel() : componentManager.GetMaxMiniSpellForgeLevel();
                                    }
                                }

                                if (maxProductionHouseLevel >= data.GetRequiredProductionHouseLevel())
                                {
                                    LogicBuilding building = (LogicBuilding)this.m_parent;

                                    if (!building.IsLocked())
                                    {
                                        return(building.GetUpgradeLevel() >= data.GetRequiredLaboratoryLevel(upgLevel + 1));
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 21
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);
        }
Ejemplo n.º 22
0
        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);
        }
Ejemplo n.º 23
0
        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();
                }
            }
        }
        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);
        }
Ejemplo n.º 25
0
        public bool IsBuildingUnlocked(LogicBuildingData buildingData)
        {
            LogicArrayList <LogicGameObject> gameObjects =
                this.m_level.GetGameObjectManagerAt(buildingData.GetVillageType()).GetGameObjects(LogicGameObjectType.BUILDING);

            for (int i = 0; i < gameObjects.Size(); i++)
            {
                LogicBuilding building = (LogicBuilding)gameObjects[i];

                if (building.GetData() == buildingData && !building.IsLocked())
                {
                    return(true);
                }
            }

            return(false);
        }
        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;
                LogicHeroBaseComponent heroBaseComponent = building.GetHeroBaseComponent();

                if (heroBaseComponent != null && (uint)this.m_mode <= 1)
                {
                    return(heroBaseComponent.SetHeroMode(this.m_mode) ? 0 : -2);
                }
            }

            return(-1);
        }
Ejemplo n.º 27
0
        public override void FastForwardTime(int secs)
        {
            LogicArrayList <LogicComponent> components = this.m_parent.GetComponentManager().GetComponents(LogicComponentType.VILLAGE2_UNIT);

            int barrackCount      = this.m_parent.GetGameObjectManager().GetBarrackCount();
            int barrackFoundCount = 0;

            for (int i = 0; i < barrackCount; i++)
            {
                LogicBuilding building = (LogicBuilding)this.m_parent.GetGameObjectManager().GetBarrack(i);

                if (building != null && !building.IsConstructing())
                {
                    barrackFoundCount += 1;
                }
            }

            if (components.Size() <= 0 || barrackFoundCount != 0 && components[0] == this)
            {
                LogicLevel level = this.m_parent.GetLevel();

                int clockTowerBoostTime = level.GetUpdatedClockTowerBoostTime();
                int boostTime           = 0;

                if (clockTowerBoostTime > 0 &&
                    !level.IsClockTowerBoostPaused())
                {
                    LogicGameObjectData data = this.m_parent.GetData();

                    if (data.GetDataType() == LogicDataType.BUILDING)
                    {
                        if (data.GetVillageType() == 1)
                        {
                            boostTime = LogicMath.Min(secs, clockTowerBoostTime) * (LogicDataTables.GetGlobals().GetClockTowerBoostMultiplier() - 1);
                        }
                    }
                }

                int remainingSecs = secs + boostTime;

                for (int i = 0; i < components.Size(); i++)
                {
                    remainingSecs = LogicMath.Max(0, remainingSecs - ((LogicVillage2UnitComponent)components[i]).FastForwardProduction(remainingSecs));
                }
            }
        }
        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;
                LogicUnitUpgradeComponent unitUpgradeComponent = building.GetUnitUpgradeComponent();

                if (unitUpgradeComponent.GetCurrentlyUpgradedUnit() != null)
                {
                    return(unitUpgradeComponent.SpeedUp() ? 0 : -2);
                }
            }

            return(-1);
        }
Ejemplo n.º 29
0
        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;
                LogicHeroBaseComponent heroBaseComponent = building.GetHeroBaseComponent();

                if (heroBaseComponent != null)
                {
                    heroBaseComponent.CancelUpgrade();
                    return(0);
                }
            }

            return(-1);
        }
        public override int Execute(LogicLevel level)
        {
            if (level != null)
            {
                LogicGameObject gameObject;

                if (level.GetState() == 5)
                {
                    gameObject = LogicGameObjectFactory.CreateGameObject(this.m_data, level, level.GetVillageType());
                    gameObject.Load(this.m_json);
                    level.GetGameObjectManager().AddGameObject(gameObject, -1);
                }
                else
                {
                    gameObject = level.GetGameObjectManager().GetGameObjectByID(this.m_id);
                }

                if (gameObject != null && gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING)
                {
                    if (gameObject.IsHidden())
                    {
                        LogicBuilding building = (LogicBuilding)gameObject;
                        LogicGameObjectManagerListener listener = level.GetGameObjectManager().GetListener();

                        listener.AddGameObject(gameObject);

                        gameObject.LoadingFinished();
                        gameObject.GetListener().RefreshState();

                        building.Trigger();

                        return(0);
                    }

                    Debugger.Warning("PGO building not hidden");
                    return(-3);
                }

                Debugger.Warning("PGO == NULL in LogicTriggerTeslaCommand");
                return(-2);
            }

            return(-1);
        }