private static LogicGameObject CreateGameObjectIfAnyPlaceExist(LogicGameObjectData data, LogicLevel level, int width, int height, int villageType, int x = 0, int y = 0)
        {
            int levelEndX = level.GetPlayArea().GetEndX();
            int levelEndY = level.GetPlayArea().GetEndY();

            if (x == 0 && y == 0)
            {
                x = level.GetPlayArea().GetStartX();
                y = level.GetPlayArea().GetStartY();
            }

            while (true)
            {
                if (level.IsValidPlaceForBuilding(x, y, width, height, null))
                {
                    LogicGameObject gameObject = LogicGameObjectFactory.CreateGameObject(data, level, villageType);
                    gameObject.SetInitialPosition(x << 9, y << 9);
                    level.GetGameObjectManagerAt(villageType).AddGameObject(gameObject, -1);
                    return(gameObject);
                }

                if (++x + width > levelEndX)
                {
                    if (++y + height > levelEndY)
                    {
                        break;
                    }
                    x = level.GetPlayArea().GetStartX();
                }
            }

            return(null);
        }
        public static LogicCharacter PlaceHero(LogicHeroData data, LogicLevel level, int x, int y, int hitpoints, int upgLevel)
        {
            LogicCharacter character = (LogicCharacter)LogicGameObjectFactory.CreateGameObject(data, level, level.GetVillageType());

            character.SetUpgradeLevel(upgLevel);
            character.GetHitpointComponent().SetHitpoints(hitpoints);
            character.SetInitialPosition(x, y);

            if (data.IsJumper())
            {
                character.GetMovementComponent().EnableJump(3600000);
                character.GetCombatComponent().RefreshTarget(true);
            }

            level.GetGameObjectManager().AddGameObject(character, -1);
            level.GetGameListener().AttackerPlaced(data);

            LogicBattleLog battleLog = level.GetBattleLog();

            if (battleLog != null)
            {
                battleLog.IncrementDeployedAttackerUnits(data, 1);
                battleLog.SetCombatItemLevel(data, upgLevel);
            }

            return(character);
        }
        public void AddDefendingHero()
        {
            LogicAvatar visitorAvatar   = this.m_parent.GetLevel().GetVisitorAvatar();
            LogicAvatar homeOwnerAvatar = this.m_parent.GetLevel().GetHomeOwnerAvatar();

            int randomPatrolPoint = visitorAvatar != null
                ? (int)(((visitorAvatar.GetResourceCount(LogicDataTables.GetGoldData()) + 10 * this.m_hero.GetGlobalID()) & 0x7FFFFFFFu) % this.m_patrolPath.Size())
                : 0;
            int upgLevel      = homeOwnerAvatar.GetUnitUpgradeLevel(this.m_hero);
            int heroHitpoints = this.m_hero.GetHeroHitpoints(homeOwnerAvatar.GetHeroHealth(this.m_hero), upgLevel);

            if (this.m_hero.HasEnoughHealthForAttack(heroHitpoints, upgLevel))
            {
                LogicVector2   patrolPoint = this.m_patrolPath[randomPatrolPoint];
                LogicCharacter hero        = (LogicCharacter)LogicGameObjectFactory.CreateGameObject(this.m_hero, this.m_parent.GetLevel(), this.m_parent.GetVillageType());

                hero.GetMovementComponent().SetBaseBuilding((LogicBuilding)this.m_parent);
                hero.GetHitpointComponent().SetTeam(1);
                hero.SetUpgradeLevel(upgLevel);
                hero.GetHitpointComponent().SetHitpoints(heroHitpoints);

                hero.SetInitialPosition(patrolPoint.m_x, patrolPoint.m_y);

                this.m_parent.GetGameObjectManager().AddGameObject(hero, -1);

                hero.GetCombatComponent().SetSearchRadius(this.m_hero.GetMaxSearchRadiusForDefender() / 512);

                if (LogicDataTables.GetGlobals().EnableDefendingAllianceTroopJump())
                {
                    hero.GetMovementComponent().EnableJump(3600000);
                }
            }
        }
Exemple #4
0
        public static LogicSpell CastSpell(LogicAvatar avatar, LogicSpellData spellData, bool allianceSpell, int upgLevel, LogicLevel level, int x, int y)
        {
            if (allianceSpell)
            {
                avatar.RemoveAllianceUnit(spellData, upgLevel);
            }
            else
            {
                avatar.CommodityCountChangeHelper(0, spellData, -1);
            }

            if (!allianceSpell)
            {
                upgLevel = avatar.GetUnitUpgradeLevel(spellData);
            }

            LogicSpell spell = (LogicSpell)LogicGameObjectFactory.CreateGameObject(spellData, level, level.GetVillageType());

            spell.SetUpgradeLevel(upgLevel);
            spell.SetInitialPosition(x, y);
            level.GetGameObjectManager().AddGameObject(spell, -1);
            level.GetGameListener().AttackerPlaced(spellData);

            LogicBattleLog battleLog = level.GetBattleLog();

            if (battleLog != null)
            {
                battleLog.IncrementCastedSpells(spellData, 1);
                battleLog.SetCombatItemLevel(spellData, upgLevel);
            }

            return(spell);
        }
Exemple #5
0
        public override int Execute(LogicLevel level)
        {
            if (this.m_decoData != null)
            {
                if (this.m_decoData.GetVillageType() == level.GetVillageType())
                {
                    if (level.IsValidPlaceForBuilding(this.m_x, this.m_y, this.m_decoData.GetWidth(), this.m_decoData.GetHeight(), null))
                    {
                        LogicClientAvatar playerAvatar      = level.GetPlayerAvatar();
                        LogicResourceData buildResourceData = this.m_decoData.GetBuildResource();

                        int buildCost = this.m_decoData.GetBuildCost();

                        if (playerAvatar.HasEnoughResources(buildResourceData, buildCost, true, this, false) && !level.IsDecoCapReached(this.m_decoData, true))
                        {
                            if (buildResourceData.IsPremiumCurrency())
                            {
                                playerAvatar.UseDiamonds(buildCost);
                                playerAvatar.GetChangeListener().DiamondPurchaseMade(1, this.m_decoData.GetGlobalID(), 0, buildCost, level.GetVillageType());
                            }
                            else
                            {
                                playerAvatar.CommodityCountChangeHelper(0, buildResourceData, -buildCost);
                            }

                            LogicDeco deco = (LogicDeco)LogicGameObjectFactory.CreateGameObject(this.m_decoData, level, level.GetVillageType());

                            deco.SetInitialPosition(this.m_x << 9, this.m_y << 9);
                            level.GetGameObjectManager().AddGameObject(deco, -1);

                            int width  = deco.GetWidthInTiles();
                            int height = deco.GetHeightInTiles();

                            for (int i = 0; i < width; i++)
                            {
                                for (int j = 0; j < height; j++)
                                {
                                    LogicObstacle tallGrass = level.GetTileMap().GetTile(this.m_x + i, this.m_y + j).GetTallGrass();

                                    if (tallGrass != null)
                                    {
                                        level.GetGameObjectManager().RemoveGameObject(tallGrass);
                                    }
                                }
                            }

                            return(0);
                        }
                    }

                    return(-1);
                }

                return(-32);
            }

            return(-1);
        }
        public static void LoadDebugJSONArray(LogicLevel level, LogicJSONArray jsonArray, LogicGameObjectType gameObjectType, int villageType)
        {
            if (jsonArray != null)
            {
                LogicGameObjectManager           gameObjectManager = level.GetGameObjectManagerAt(villageType);
                LogicArrayList <LogicGameObject> prevGameObjects   = new LogicArrayList <LogicGameObject>();

                prevGameObjects.AddAll(gameObjectManager.GetGameObjects(gameObjectType));

                for (int i = 0; i < prevGameObjects.Size(); i++)
                {
                    gameObjectManager.RemoveGameObject(prevGameObjects[i]);
                }

                for (int i = 0; i < jsonArray.Size(); i++)
                {
                    LogicJSONObject  jsonObject    = jsonArray.GetJSONObject(i);
                    LogicJSONNumber  dataNumber    = jsonObject.GetJSONNumber("data");
                    LogicJSONNumber  lvlNumber     = jsonObject.GetJSONNumber("lvl");
                    LogicJSONBoolean lockedBoolean = jsonObject.GetJSONBoolean("locked");
                    LogicJSONNumber  xNumber       = jsonObject.GetJSONNumber("x");
                    LogicJSONNumber  yNumber       = jsonObject.GetJSONNumber("y");

                    if (dataNumber != null && xNumber != null && yNumber != null)
                    {
                        LogicGameObjectData data = (LogicGameObjectData)LogicDataTables.GetDataById(dataNumber.GetIntValue());

                        if (data != null)
                        {
                            LogicGameObject gameObject = LogicGameObjectFactory.CreateGameObject(data, level, villageType);

                            if (gameObjectType == LogicGameObjectType.BUILDING)
                            {
                                ((LogicBuilding)gameObject).StartConstructing(true);
                            }

                            if (lockedBoolean != null && lockedBoolean.IsTrue())
                            {
                                ((LogicBuilding)gameObject).Lock();
                            }

                            gameObject.Load(jsonObject);
                            gameObjectManager.AddGameObject(gameObject, -1);

                            if (lvlNumber != null)
                            {
                                LogicDebugUtil.SetBuildingUpgradeLevel(level, gameObject.GetGlobalID(), lvlNumber.GetIntValue(), villageType);
                            }
                        }
                    }
                }
            }
        }
Exemple #7
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);
        }
        /// <summary>
        ///     Casts the specified spell.
        /// </summary>
        public static LogicSpell CastSpell(LogicAvatar avatar, LogicSpellData spellData, bool allianceSpell, int upgLevel, LogicLevel level, int x, int y)
        {
            if (allianceSpell)
            {
                avatar.RemoveAllianceUnit(spellData, upgLevel);
            }
            else
            {
                avatar.CommodityCountChangeHelper(0, spellData, -1);
            }

            LogicSpell spell = (LogicSpell)LogicGameObjectFactory.CreateGameObject(spellData, level, level.GetVillageType());

            spell.SetUpgradeLevel(upgLevel);
            return(spell);
        }
Exemple #9
0
        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)
                {
                    if (gameObject.GetGameObjectType() == LogicGameObjectType.TRAP)
                    {
                        LogicTrap trap = (LogicTrap)gameObject;
                        LogicGameObjectManagerListener listener = level.GetGameObjectManager().GetListener();

                        listener.AddGameObject(gameObject);

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

                        LogicTriggerComponent triggerComponent = trap.GetTriggerComponent();

                        if (triggerComponent != null)
                        {
                            triggerComponent.SetTriggered();
                        }
                    }

                    return(0);
                }

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

            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);
        }
        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;
            }
        }
Exemple #12
0
        public static LogicCharacter PlaceAttacker(LogicAvatar avatar, LogicCharacterData characterData, LogicLevel level, int x, int y)
        {
            avatar.CommodityCountChangeHelper(level.GetVillageType() == 1 ? 7 : 0, characterData, -1);

            LogicCharacter character    = (LogicCharacter)LogicGameObjectFactory.CreateGameObject(characterData, level, level.GetVillageType());
            int            upgradeLevel = avatar.GetUnitUpgradeLevel(characterData);

            if (level.GetMissionManager().GetMissionByCategory(2) != null && level.GetVillageType() == 1 && level.GetHomeOwnerAvatar() != null)
            {
                LogicAvatar homeOwnerAvatar = level.GetHomeOwnerAvatar();

                if (homeOwnerAvatar.IsNpcAvatar())
                {
                    upgradeLevel = LogicMath.Clamp(LogicDataTables.GetGlobals().GetVillage2StartUnitLevel(), 0, characterData.GetUpgradeLevelCount() - 1);
                }
            }

            character.SetUpgradeLevel(upgradeLevel);
            character.SetInitialPosition(x, y);

            if (characterData.IsJumper())
            {
                character.GetMovementComponent().EnableJump(3600000);
                character.GetCombatComponent().RefreshTarget(true);
            }

            level.GetGameObjectManager().AddGameObject(character, -1);
            level.GetGameListener().AttackerPlaced(characterData);

            LogicBattleLog battleLog = level.GetBattleLog();

            if (battleLog != null)
            {
                battleLog.IncrementDeployedAttackerUnits(characterData, 1);
                battleLog.SetCombatItemLevel(characterData, upgradeLevel);
            }

            character.UpdateAutoMerge();
            return(character);
        }
        private static LogicGameObject CreateAndPlaceRandomlyGameObject(LogicGameObjectData data, LogicLevel level, int width, int height, int villageType)
        {
            int levelEndX = level.GetPlayArea().GetEndX();
            int levelEndY = level.GetPlayArea().GetEndY();
            int midX      = levelEndX / 2;
            int midY      = levelEndY / 2;

            int passCount = 1;

            while (true)
            {
                int startX = LogicMath.Max(midX - passCount, 0);
                int startY = LogicMath.Max(midY - passCount, 0);
                int endX   = LogicMath.Min(midX + passCount, levelEndX);
                int endY   = LogicMath.Min(midY + passCount, levelEndY);

                int possibility = LogicMath.Min((endX - startX) * (endY - startY), 20);

                for (int i = 0; i < possibility; i++)
                {
                    int x = startX + GameBaseGenerator.m_random.Rand(endX - startX);
                    int y = startY + GameBaseGenerator.m_random.Rand(endY - startY);

                    if (level.IsValidPlaceForBuilding(x, y, width, height, null))
                    {
                        LogicGameObject gameObject = LogicGameObjectFactory.CreateGameObject(data, level, villageType);
                        gameObject.SetInitialPosition(x << 9, y << 9);
                        level.GetGameObjectManagerAt(villageType).AddGameObject(gameObject, -1);
                        return(gameObject);
                    }
                }

                if (startX == 0 && startY == 0)
                {
                    return(null);
                }

                passCount += 2;
            }
        }
        /// <summary>
        ///     Places the specified attacker.
        /// </summary>
        public static LogicCharacter PlaceAttacker(LogicAvatar avatar, LogicCharacterData characterData, LogicLevel level, int x, int y)
        {
            avatar.CommodityCountChangeHelper(level.GetVillageType() == 1 ? 7 : 0, characterData, -1);

            LogicCharacter character    = (LogicCharacter)LogicGameObjectFactory.CreateGameObject(characterData, level, level.GetVillageType());
            Int32          upgradeLevel = avatar.GetUnitUpgradeLevel(characterData);

            if (level.GetMissionManager().GetMissionByCategory(2) != null && level.GetVillageType() == 1 && level.GetHomeOwnerAvatar() != null)
            {
                LogicAvatar homeOwnerAvatar = level.GetHomeOwnerAvatar();

                if (homeOwnerAvatar.IsNpcAvatar())
                {
                    upgradeLevel = LogicMath.Clamp(LogicDataTables.GetGlobals().GetVillage2StartUnitLevel(), 0, characterData.GetUpgradeLevelCount());
                }
            }

            character.SetUpgradeLevel(upgradeLevel);
            character.SetInitialPosition(x, y);

            return(character);
        }
        public void LoadGameObjectsJsonArray(LogicLevel level, LogicJSONArray array, int villageType)
        {
            if (array != null)
            {
                for (int i = 0; i < array.Size(); i++)
                {
                    LogicJSONObject jsonObject = array.GetJSONObject(i);

                    if (jsonObject != null)
                    {
                        LogicGameObjectData data = (LogicGameObjectData)LogicDataTables.GetDataById(jsonObject.GetJSONNumber("data").GetIntValue());

                        if (data != null)
                        {
                            LogicGameObject gameObject = LogicGameObjectFactory.CreateGameObject(data, level, villageType);
                            gameObject.Load(jsonObject);
                            level.GetGameObjectManagerAt(1).AddGameObject(gameObject, -1);
                        }
                    }
                }
            }
        }
Exemple #16
0
        /// <summary>
        ///     Executes this command.
        /// </summary>
        public override int Execute(LogicLevel level)
        {
            if (this._trapData != null)
            {
                if (this._trapData.GetVillageType() == level.GetVillageType())
                {
                    if (level.IsValidPlaceForBuilding(this._x, this._y, this._trapData.GetWidth(), this._trapData.GetHeight(), null))
                    {
                        LogicClientAvatar playerAvatar      = level.GetPlayerAvatar();
                        LogicResourceData buildResourceData = this._trapData.GetBuildResource();

                        int buildCost = this._trapData.GetBuildCost(0);

                        if (playerAvatar.HasEnoughResources(buildResourceData, buildCost, true, this, false) && !level.IsTrapCapReached(this._trapData, true))
                        {
                            if (buildResourceData.PremiumCurrency)
                            {
                                playerAvatar.UseDiamonds(buildCost);
                            }
                            else
                            {
                                playerAvatar.CommodityCountChangeHelper(0, buildResourceData, -buildCost);
                            }

                            LogicTrap trap = (LogicTrap)LogicGameObjectFactory.CreateGameObject(this._trapData, level, level.GetVillageType());

                            if (this._trapData.GetBuildTime(0) == 0)
                            {
                                trap.FinishConstruction(false);
                            }

                            trap.SetInitialPosition(this._x << 9, this._y << 9);
                            level.GetGameObjectManager().AddGameObject(trap, -1);

                            if (level.IsTrapCapReached(this._trapData, false))
                            {
                                level.GetGameListener().TrapCapReached(this._trapData);
                            }

                            if (trap.GetVillageType() != 0)
                            {
                                int x      = trap.GetTileX();
                                int y      = trap.GetTileY();
                                int width  = trap.GetWidthInTiles();
                                int height = trap.GetHeightInTiles();

                                for (int i = 0; i < width; i++)
                                {
                                    for (int j = 0; j < height; j++)
                                    {
                                        LogicObstacle tallGrass = level.GetTileMap().GetTile(x + i, y + j).GetTallGrass();

                                        if (tallGrass != null)
                                        {
                                            level.GetGameObjectManager().RemoveGameObject(tallGrass);
                                        }
                                    }
                                }
                            }

                            return(0);
                        }
                    }

                    return(-1);
                }

                return(-32);
            }

            return(-1);
        }
Exemple #17
0
        public override int Execute(LogicLevel level)
        {
            if (level.GetVillageType() == 1)
            {
                if (this.m_buildingData != null && this.m_buildingData.GetBuildingClass().CanBuy() && this.m_buildingData.IsWall())
                {
                    if (this.m_buildingData.GetWallBlockCount() != 0)
                    {
                        if (this.m_buildingData.GetWallBlockCount() == this.m_position.Size())
                        {
                            if (this.m_position.Size() <= 10)
                            {
                                for (int i = 0, nIdx = -1; i < this.m_position.Size(); i++)
                                {
                                    LogicVector2 firstPosition = this.m_position[0];
                                    LogicVector2 position      = this.m_position[i];

                                    if (i > 0)
                                    {
                                        int shapeIdx = this.m_buildingData.GetWallBlockIndex(position.m_x - firstPosition.m_x, position.m_y - firstPosition.m_y, i);

                                        if (nIdx == -1)
                                        {
                                            nIdx = shapeIdx;
                                        }

                                        if (shapeIdx == -1 || shapeIdx != nIdx)
                                        {
                                            Debugger.Error("LogicBuyWallBlockCommand shape incorrect");
                                            return(-4);
                                        }

                                        nIdx = shapeIdx;
                                    }

                                    if (!level.IsValidPlaceForBuilding(position.m_x, position.m_y, this.m_buildingData.GetWidth(), this.m_buildingData.GetHeight(), null))
                                    {
                                        Debugger.Error("LogicBuyWallBlockCommand invalid place.");
                                        return(-5);
                                    }
                                }

                                if (!level.IsBuildingCapReached(this.m_buildingData, true))
                                {
                                    LogicClientAvatar playerAvatar  = level.GetPlayerAvatar();
                                    LogicResourceData buildResource = this.m_buildingData.GetBuildResource(0);

                                    int buildCost = this.m_buildingData.GetBuildCost(0, level);

                                    if (playerAvatar.HasEnoughResources(buildResource, buildCost, true, this, false))
                                    {
                                        if (this.m_buildingData.IsWorkerBuilding() ||
                                            this.m_buildingData.GetConstructionTime(0, level, 0) <= 0 && !LogicDataTables.GetGlobals().WorkerForZeroBuilTime() ||
                                            level.HasFreeWorkers(this, -1))
                                        {
                                            if (buildResource.IsPremiumCurrency())
                                            {
                                                playerAvatar.UseDiamonds(buildCost);
                                                playerAvatar.GetChangeListener().DiamondPurchaseMade(1, this.m_buildingData.GetGlobalID(), 0, buildCost, level.GetVillageType());
                                            }
                                            else
                                            {
                                                playerAvatar.CommodityCountChangeHelper(0, buildResource, -buildCost);
                                            }

                                            LogicGameObjectManager gameObjectManager = level.GetGameObjectManager();
                                            int wallIndex = gameObjectManager.GetHighestWallIndex(this.m_buildingData);

                                            for (int i = 0; i < this.m_position.Size(); i++)
                                            {
                                                LogicVector2  position = this.m_position[i];
                                                LogicBuilding building =
                                                    (LogicBuilding)LogicGameObjectFactory.CreateGameObject(this.m_buildingData, level, level.GetVillageType());

                                                building.StartConstructing(false);
                                                building.SetInitialPosition(position.m_x << 9, position.m_y << 9);
                                                building.SetWallObjectId(wallIndex, i, i == 0);

                                                gameObjectManager.AddGameObject(building, -1);

                                                int width  = building.GetWidthInTiles();
                                                int height = building.GetHeightInTiles();

                                                for (int j = 0; j < width; j++)
                                                {
                                                    for (int k = 0; k < height; k++)
                                                    {
                                                        LogicObstacle tallGrass = level.GetTileMap().GetTile(position.m_x + j, position.m_y + k).GetTallGrass();

                                                        if (tallGrass != null)
                                                        {
                                                            level.GetGameObjectManager().RemoveGameObject(tallGrass);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }

                                return(0);
                            }

                            return(-3);
                        }

                        return(-2);
                    }

                    return(-1);
                }

                return(0);
            }

            return(-32);
        }
Exemple #18
0
        public override int Execute(LogicLevel level)
        {
            if (level.IsReadyForAttack())
            {
                if (level.GetVillageType() == 0)
                {
                    if (LogicDataTables.GetGlobals().AllowClanCastleDeployOnObstacles())
                    {
                        if (!level.GetTileMap().IsValidAttackPos(this.m_x >> 9, this.m_y >> 9))
                        {
                            return(-2);
                        }
                    }
                    else
                    {
                        LogicTile tile = level.GetTileMap().GetTile(this.m_x >> 9, this.m_y >> 9);

                        if (tile == null)
                        {
                            return(-4);
                        }

                        if (tile.GetPassableFlag() == 0)
                        {
                            return(-3);
                        }
                    }

                    LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

                    if (playerAvatar != null)
                    {
                        if (this.m_data != null)
                        {
                            LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(0);

                            if (gameObjectManager.GetGameObjectCountByData(this.m_data) <= 0 && playerAvatar.GetAllianceCastleUsedCapacity() > 0)
                            {
                                LogicAlliancePortal  alliancePortal  = (LogicAlliancePortal)LogicGameObjectFactory.CreateGameObject(this.m_data, level, level.GetVillageType());
                                LogicBunkerComponent bunkerComponent = alliancePortal.GetBunkerComponent();

                                alliancePortal.SetInitialPosition(this.m_x, this.m_y);

                                if (bunkerComponent != null)
                                {
                                    bunkerComponent.SetMaxCapacity(playerAvatar.GetAllianceCastleTotalCapacity());

                                    if (level.GetBattleLog() != null)
                                    {
                                        if (!level.GetBattleLog().HasDeployedUnits() && level.GetTotalAttackerHeroPlaced() == 0)
                                        {
                                            level.UpdateLastUsedArmy();
                                        }
                                    }

                                    if (level.GetGameMode().IsInAttackPreparationMode())
                                    {
                                        level.GetGameMode().EndAttackPreparation();
                                    }

                                    bunkerComponent.RemoveAllUnits();

                                    LogicArrayList <LogicUnitSlot> allianceUnits = playerAvatar.GetAllianceUnits();

                                    for (int i = 0; i < allianceUnits.Size(); i++)
                                    {
                                        LogicUnitSlot       slot = allianceUnits[i];
                                        LogicCombatItemData data = (LogicCombatItemData)slot.GetData();

                                        if (data != null)
                                        {
                                            int count = slot.GetCount();

                                            if (data.GetCombatItemType() == LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER)
                                            {
                                                for (int j = 0; j < count; j++)
                                                {
                                                    if (bunkerComponent.GetUnusedCapacity() >= data.GetHousingSpace())
                                                    {
                                                        bunkerComponent.AddUnitImpl(data, slot.GetLevel());
                                                    }
                                                }
                                            }
                                        }
                                        else
                                        {
                                            Debugger.Error("LogicPlaceAlliancePortalCommand::execute - NULL alliance character");
                                        }
                                    }
                                }

                                gameObjectManager.AddGameObject(alliancePortal, -1);

                                return(0);
                            }
                        }
                    }

                    return(-5);
                }
            }

            return(-1);
        }
        private void Spawn()
        {
            int free = LogicMath.Min(LogicMath.Min(this.m_spawnCount, this.m_maxSpawned - this.m_spawned.Size()), this.m_maxLifetimeSpawns - this.m_lifeTimeSpawns);

            if (free > 0)
            {
                int x           = this.m_parent.GetX();
                int y           = this.m_parent.GetY();
                int tileX       = this.m_parent.GetTileX();
                int tileY       = this.m_parent.GetTileY();
                int width       = this.m_parent.GetWidthInTiles();
                int height      = this.m_parent.GetHeightInTiles();
                int levelWidth  = this.m_parent.GetLevel().GetWidthInTiles();
                int levelHeight = this.m_parent.GetLevel().GetHeightInTiles();

                int startTileX = LogicMath.Clamp(tileX - this.m_radius, 0, levelWidth);
                int startTileY = LogicMath.Clamp(tileY - this.m_radius, 0, levelHeight);
                int endTileX   = LogicMath.Clamp(tileX + this.m_radius + width, 0, levelWidth);
                int endTileY   = LogicMath.Clamp(tileY + this.m_radius + height, 0, levelHeight);

                int radius      = (this.m_radius << 9) * (this.m_radius << 9);
                int possibility = (endTileX - startTileX) * (endTileY - startTileY);

                LogicArrayList <LogicTile> spawnPoints = new LogicArrayList <LogicTile>(possibility);
                LogicTileMap tileMap = this.m_parent.GetLevel().GetTileMap();

                int spawnPointUpStartX = x + (width << 9);
                int spawnPointUpStartY = y + (height << 9);

                int tmp4 = y - 256 - (startTileY << 9);

                int startMidX = (startTileX << 9) | 256;
                int startMidY = (startTileY << 9) | 256;

                for (int i = startTileX, j = startMidX; i < endTileX; i++, j += 512)
                {
                    int tmp1 = j >= spawnPointUpStartX ? -spawnPointUpStartX + j + 1 : 0;
                    int tmp2 = j >= x ? tmp1 : x - j;

                    tmp2 *= tmp2;

                    for (int k = startTileY, l = startMidY, m = tmp4; k < endTileY; k++, l += 512, m -= 512)
                    {
                        LogicTile tile = tileMap.GetTile(i, k);

                        if (tile.GetGameObjectCount() == 0)
                        {
                            int tmp3 = y <= l ? l < spawnPointUpStartY ? 0 : -spawnPointUpStartY + l + 1 : m;

                            tmp3 *= tmp3;

                            if (tmp2 + tmp3 <= radius)
                            {
                                spawnPoints.Add(tile);
                            }
                        }
                    }
                }

                for (int i = free; i > 0 && spawnPoints.Size() > 0; i--, ++this.m_lifeTimeSpawns)
                {
                    int idx = this.m_randomizer.Rand(spawnPoints.Size());

                    LogicTile       tile       = spawnPoints[idx];
                    LogicGameObject gameObject = LogicGameObjectFactory.CreateGameObject(this.m_spawnData, this.m_parent.GetLevel(), this.m_parent.GetVillageType());

                    gameObject.SetInitialPosition(tile.GetX() << 9, tile.GetY() << 9);

                    this.m_parent.GetGameObjectManager().AddGameObject(gameObject, -1);
                    this.m_spawned.Add(gameObject.GetGlobalID());

                    spawnPoints.Remove(idx);
                }
            }
        }
Exemple #20
0
        public override void Tick()
        {
            LogicAvatar homeOwnerAvatar = this.m_parent.GetLevel().GetHomeOwnerAvatar();

            if (homeOwnerAvatar != null)
            {
                this.m_updateAvatarCooldown += 64;

                if (this.m_updateAvatarCooldown > 1000)
                {
                    homeOwnerAvatar.UpdateStarBonusLimitCooldown();
                    homeOwnerAvatar.UpdateLootLimitCooldown();

                    this.m_updateAvatarCooldown -= 1000;
                }
            }

            if (this.m_parent.IsAlive())
            {
                if (!this.IsEmpty())
                {
                    if (this.m_bunkerSearchTime > 0)
                    {
                        this.m_bunkerSearchTime -= 64;
                    }
                    else
                    {
                        bool airTriggered = false;
                        bool groundLocked = false;

                        if (this.m_team == 1)
                        {
                            bool inAirDistance    = false;
                            bool inGroundDistance = false;

                            int clanCastleRadius = LogicDataTables.GetGlobals().GetClanCastleRadius();

                            if (LogicDataTables.GetGlobals().CastleTroopTargetFilter())
                            {
                                LogicCharacter closestGroundAttacker = this.ClosestAttacker(false);
                                LogicCharacter closestAirAttacker    = this.ClosestAttacker(true);

                                if (closestAirAttacker != null)
                                {
                                    inAirDistance = closestAirAttacker.GetPosition().GetDistanceSquaredTo(this.m_parent.GetX(), this.m_parent.GetY()) <
                                                    clanCastleRadius * clanCastleRadius;
                                }

                                if (closestGroundAttacker != null)
                                {
                                    inGroundDistance = closestGroundAttacker.GetPosition().GetDistanceSquaredTo(this.m_parent.GetX(), this.m_parent.GetY()) <
                                                       clanCastleRadius * clanCastleRadius;
                                }
                            }
                            else
                            {
                                LogicCharacter closestAttacker =
                                    (LogicCharacter)this.m_parent.GetLevel().GetGameObjectManager()
                                    .GetClosestGameObject(this.m_parent.GetX(), this.m_parent.GetY(), this.m_filter);

                                if (closestAttacker != null)
                                {
                                    inAirDistance = inGroundDistance = closestAttacker.GetPosition().GetDistanceSquaredTo(this.m_parent.GetX(), this.m_parent.GetY()) <
                                                                       clanCastleRadius * clanCastleRadius;
                                }
                            }

                            groundLocked = !inGroundDistance;
                            airTriggered = inAirDistance;

                            if (!airTriggered && groundLocked)
                            {
                                this.m_bunkerSearchTime = LogicDataTables.GetGlobals().GetBunkerSearchTime();
                                return;
                            }
                        }
                        else
                        {
                            airTriggered = true;
                        }

                        LogicCharacterData spawnData = null;
                        int spawnLevel = -1;

                        for (int i = 0; i < this.GetUnitTypeCount(); i++)
                        {
                            LogicCombatItemData data = this.GetUnitType(i);

                            if (data != null)
                            {
                                int count = this.GetUnitCount(i);

                                if (count > 0)
                                {
                                    int upgLevel = this.GetUnitLevel(i);

                                    if (data.GetCombatItemType() == LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER)
                                    {
                                        LogicCharacterData    characterData    = (LogicCharacterData)data;
                                        LogicAttackerItemData attackerItemData = characterData.GetAttackerItemData(upgLevel);

                                        if (!(airTriggered & groundLocked) || attackerItemData.GetTrackAirTargets(false))
                                        {
                                            if (airTriggered | groundLocked || attackerItemData.GetTrackGroundTargets(false))
                                            {
                                                this.RemoveUnits(data, upgLevel, 1);

                                                spawnData  = characterData;
                                                spawnLevel = upgLevel;
                                            }
                                        }
                                    }
                                }
                            }

                            if (spawnData != null)
                            {
                                break;
                            }
                        }

                        if (spawnData != null)
                        {
                            LogicCharacter character =
                                (LogicCharacter)LogicGameObjectFactory.CreateGameObject(spawnData, this.m_parent.GetLevel(), this.m_parent.GetVillageType());

                            character.GetHitpointComponent().SetTeam(this.m_team);

                            if (character.GetChildTroops() != null)
                            {
                                LogicArrayList <LogicCharacter> childrens = character.GetChildTroops();

                                for (int i = 0; i < childrens.Size(); i++)
                                {
                                    childrens[i].GetHitpointComponent().SetTeam(this.m_team);
                                }
                            }

                            character.SetUpgradeLevel(spawnLevel == -1 ? 0 : spawnLevel);
                            character.SetAllianceUnit();

                            if (character.GetCharacterData().IsJumper())
                            {
                                character.GetMovementComponent().EnableJump(3600000);
                            }

                            if (this.m_team == 1)
                            {
                                if (LogicDataTables.GetGlobals().EnableDefendingAllianceTroopJump())
                                {
                                    character.GetMovementComponent().EnableJump(3600000);
                                }

                                if (LogicDataTables.GetGlobals().AllianceTroopsPatrol())
                                {
                                    character.GetCombatComponent().SetSearchRadius(LogicDataTables.GetGlobals().GetClanCastleRadius() >> 9);

                                    if (this.m_parent.GetGameObjectType() == LogicGameObjectType.BUILDING)
                                    {
                                        character.GetMovementComponent().SetBaseBuilding((LogicBuilding)this.m_parent);
                                    }
                                }
                            }
                            else
                            {
                                LogicAvatar visitorAvatar = this.m_parent.GetLevel().GetVisitorAvatar();

                                visitorAvatar.RemoveAllianceUnit(spawnData, spawnLevel);
                                visitorAvatar.GetChangeListener().AllianceUnitRemoved(spawnData, spawnLevel);

                                LogicBattleLog battleLog = this.m_parent.GetLevel().GetBattleLog();

                                battleLog.IncrementDeployedAllianceUnits(spawnData, 1, spawnLevel);
                                battleLog.SetAllianceUsed(true);
                            }

                            if (this.m_team == 1)
                            {
                                int spawnOffsetX = 0;
                                int spawnOffsetY = 0;

                                switch (this.m_troopSpawnOffset)
                                {
                                case 0:
                                    spawnOffsetX = 1;
                                    spawnOffsetY = 0;
                                    break;

                                case 1:
                                    spawnOffsetX = -1;
                                    spawnOffsetY = 0;
                                    break;

                                case 2:
                                    spawnOffsetX = 0;
                                    spawnOffsetY = 1;
                                    break;

                                case 3:
                                    spawnOffsetX = 0;
                                    spawnOffsetY = -1;
                                    break;
                                }

                                character.SetInitialPosition(this.m_parent.GetMidX() + ((this.m_parent.GetWidthInTiles() << 8) - 128) * spawnOffsetX,
                                                             this.m_parent.GetMidY() + ((this.m_parent.GetHeightInTiles() << 8) - 128) * spawnOffsetY);

                                if (++this.m_troopSpawnOffset > 3)
                                {
                                    this.m_troopSpawnOffset = 0;
                                }
                            }
                            else if (LogicDataTables.GetGlobals().AllowClanCastleDeployOnObstacles())
                            {
                                int posX = this.m_parent.GetX() + (this.m_parent.GetWidthInTiles() << 9) - 128;
                                int posY = this.m_parent.GetY() + (this.m_parent.GetHeightInTiles() << 8);

                                if (LogicGamePlayUtil.GetNearestValidAttackPos(this.m_parent.GetLevel(), posX, posY, out int outputX, out int outputY))
                                {
                                    character.SetInitialPosition(outputX, outputY);
                                }
                                else
                                {
                                    character.SetInitialPosition(posX, posY);
                                }
                            }
                            else
                            {
                                character.SetInitialPosition(this.m_parent.GetX() + (this.m_parent.GetWidthInTiles() << 9) - 128,
                                                             this.m_parent.GetY() + (this.m_parent.GetHeightInTiles() << 8));
                            }

                            this.m_parent.GetGameObjectManager().AddGameObject(character, -1);
                        }

                        this.m_bunkerSearchTime = LogicDataTables.GetGlobals().GetBunkerSearchTime();
                    }
                }
            }
Exemple #21
0
        public override int Execute(LogicLevel level)
        {
            int villageType = level.GetVillageType();

            if (this.m_buildingData.GetVillageType() == villageType)
            {
                if (this.m_buildingData.GetWallBlockCount() <= 1 && this.m_buildingData.GetBuildingClass().CanBuy())
                {
                    if (level.IsValidPlaceForBuilding(this.m_x, this.m_y, this.m_buildingData.GetWidth(), this.m_buildingData.GetHeight(), null) &&
                        !level.IsBuildingCapReached(this.m_buildingData, true))
                    {
                        if (level.GetCalendar().IsEnabled(this.m_buildingData))
                        {
                            LogicClientAvatar playerAvatar      = level.GetPlayerAvatar();
                            LogicResourceData buildResourceData = this.m_buildingData.GetBuildResource(0);

                            int buildResourceCost = this.m_buildingData.GetBuildCost(0, level);

                            if (playerAvatar.HasEnoughResources(buildResourceData, buildResourceCost, true, this, false))
                            {
                                if (this.m_buildingData.IsWorkerBuilding() ||
                                    this.m_buildingData.GetConstructionTime(0, level, 0) <= 0 && !LogicDataTables.GetGlobals().WorkerForZeroBuilTime() ||
                                    level.HasFreeWorkers(this, -1))
                                {
                                    if (buildResourceData.IsPremiumCurrency())
                                    {
                                        playerAvatar.UseDiamonds(buildResourceCost);
                                        playerAvatar.GetChangeListener().DiamondPurchaseMade(1, this.m_buildingData.GetGlobalID(), 0, buildResourceCost, villageType);
                                    }
                                    else
                                    {
                                        playerAvatar.CommodityCountChangeHelper(0, buildResourceData, -buildResourceCost);
                                    }

                                    LogicBuilding building = (LogicBuilding)LogicGameObjectFactory.CreateGameObject(this.m_buildingData, level, villageType);

                                    building.SetInitialPosition(this.m_x << 9, this.m_y << 9);
                                    level.GetGameObjectManager().AddGameObject(building, -1);
                                    building.StartConstructing(false);

                                    if (this.m_buildingData.IsWall() && level.IsBuildingCapReached(this.m_buildingData, false))
                                    {
                                        level.GetGameListener().BuildingCapReached(this.m_buildingData);
                                    }

                                    int width  = building.GetWidthInTiles();
                                    int height = building.GetHeightInTiles();

                                    for (int i = 0; i < width; i++)
                                    {
                                        for (int j = 0; j < height; j++)
                                        {
                                            LogicObstacle tallGrass = level.GetTileMap().GetTile(this.m_x + i, this.m_y + j).GetTallGrass();

                                            if (tallGrass != null)
                                            {
                                                level.GetGameObjectManager().RemoveGameObject(tallGrass);
                                            }
                                        }
                                    }
                                }
                            }

                            return(0);
                        }
                    }
                }

                return(-33);
            }

            return(-32);
        }
        public override int Execute(LogicLevel level)
        {
            if (this.m_gameObjectData != null && level.GetUnplacedObjectCount(this.m_gameObjectData) > 0)
            {
                if (level.GetVillageType() == this.m_gameObjectData.GetVillageType())
                {
                    LogicDataType dataType = this.m_gameObjectData.GetDataType();

                    if (dataType == LogicDataType.BUILDING)
                    {
                        LogicBuildingData buildingData = (LogicBuildingData)this.m_gameObjectData;

                        if (level.IsValidPlaceForBuilding(this.m_x, this.m_y, buildingData.GetWidth(), buildingData.GetHeight(), null))
                        {
                            if (!level.RemoveUnplacedObject(this.m_gameObjectData, this.m_upgradeLevel))
                            {
                                return(-63);
                            }

                            LogicBuilding building = (LogicBuilding)LogicGameObjectFactory.CreateGameObject(this.m_gameObjectData, level, level.GetVillageType());

                            building.SetPositionXY(this.m_x << 9, this.m_y << 9);
                            level.GetGameObjectManager().AddGameObject(building, -1);
                            building.FinishConstruction(false, true);
                            building.SetUpgradeLevel(this.m_upgradeLevel);
                        }

                        return(0);
                    }

                    if (dataType == LogicDataType.TRAP)
                    {
                        LogicTrapData trapData = (LogicTrapData)this.m_gameObjectData;

                        if (level.IsValidPlaceForBuilding(this.m_x, this.m_y, trapData.GetWidth(), trapData.GetHeight(), null))
                        {
                            if (!level.RemoveUnplacedObject(this.m_gameObjectData, this.m_upgradeLevel))
                            {
                                return(-64);
                            }

                            LogicTrap trap = (LogicTrap)LogicGameObjectFactory.CreateGameObject(this.m_gameObjectData, level, level.GetVillageType());

                            trap.SetPositionXY(this.m_x << 9, this.m_y << 9);
                            trap.FinishConstruction(false);
                            trap.SetUpgradeLevel(this.m_upgradeLevel);
                            level.GetGameObjectManager().AddGameObject(trap, -1);
                        }

                        return(0);
                    }

                    if (dataType == LogicDataType.DECO)
                    {
                        LogicDecoData decoData = (LogicDecoData)this.m_gameObjectData;

                        if (level.IsValidPlaceForBuilding(this.m_x, this.m_y, decoData.GetWidth(), decoData.GetHeight(), null))
                        {
                            if (!level.RemoveUnplacedObject(this.m_gameObjectData, this.m_upgradeLevel))
                            {
                                return(-65);
                            }

                            LogicDeco deco = (LogicDeco)LogicGameObjectFactory.CreateGameObject(this.m_gameObjectData, level, level.GetVillageType());

                            deco.SetPositionXY(this.m_x << 9, this.m_y << 9);
                            level.RemoveUnplacedObject(this.m_gameObjectData, this.m_upgradeLevel);
                            level.GetGameObjectManager().AddGameObject(deco, -1);
                        }

                        return(0);
                    }

                    return(-3);
                }

                return(-35);
            }

            return(0);
        }