コード例 #1
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="LogicHitpointComponent" /> class.
 /// </summary>
 public LogicHeroBaseComponent(LogicGameObject gameObject, LogicHeroData data) : base(gameObject)
 {
     this._data = data;
 }
コード例 #2
0
        /// <summary>
        ///     Executes this command.
        /// </summary>
        public override int Execute(LogicLevel level)
        {
            LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this._gameObjectId);

            if (gameObject != null)
            {
                if (gameObject.GetGameObjectType() == 3)
                {
                    LogicObstacle obstacle = (LogicObstacle)gameObject;

                    if (obstacle.GetObstacleData().GetVillageType() == level.GetVillageType())
                    {
                        LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

                        if (obstacle.CanStartClearing())
                        {
                            LogicObstacleData obstacleData = obstacle.GetObstacleData();

                            if (obstacle.GetVillageType() == 1)
                            {
                                int village2TownHallLevel = playerAvatar.GetVillage2TownHallLevel();

                                if (village2TownHallLevel < LogicDataTables.GetGlobals().GetMinVillage2TownHallLevelForDestructObstacle() &&
                                    obstacleData.GetClearTime() > 0)
                                {
                                    return(0);
                                }
                            }

                            LogicResourceData clearResourceData = obstacleData.GetClearResourceData();
                            int clearCost = obstacleData.GetClearCost();

                            if (playerAvatar.HasEnoughResources(clearResourceData, clearCost, true, this, false))
                            {
                                if (obstacleData.GetClearTime() == 0 || level.HasFreeWorkers(this, -1))
                                {
                                    playerAvatar.CommodityCountChangeHelper(0, clearResourceData, -clearCost);
                                    obstacle.StartClearing();

                                    if (obstacle.IsTombstone())
                                    {
                                        int tombGroup = obstacle.GetTombGroup();

                                        if (tombGroup != 2)
                                        {
                                            LogicArrayList <LogicGameObject> gameObjects = level.GetGameObjectManager().GetGameObjects(3);

                                            for (int i = 0; i < gameObjects.Count; i++)
                                            {
                                                LogicObstacle go = (LogicObstacle)gameObjects[i];

                                                if (go.IsTombstone() && go.GetTombGroup() == tombGroup)
                                                {
                                                    go.StartClearing();
                                                }
                                            }
                                        }
                                    }
                                }

                                return(0);
                            }
                        }

                        return(-1);
                    }

                    return(-32);
                }
            }

            return(-1);
        }
コード例 #3
0
        public override int Execute(LogicLevel level)
        {
            if (LogicDataTables.GetGlobals().UseSwapBuildings())
            {
                if (this.m_gameObject1 != this.m_gameObject2)
                {
                    LogicGameObject gameObject1 = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObject1);
                    LogicGameObject gameObject2 = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObject2);

                    if (gameObject1 != null)
                    {
                        if (gameObject2 != null)
                        {
                            LogicGameObjectType gameObjectType1 = gameObject1.GetGameObjectType();

                            if (gameObjectType1 == LogicGameObjectType.BUILDING || gameObjectType1 == LogicGameObjectType.TRAP ||
                                gameObjectType1 == LogicGameObjectType.DECO)
                            {
                                LogicGameObjectType gameObjectType2 = gameObject2.GetGameObjectType();

                                if (gameObjectType2 == LogicGameObjectType.BUILDING || gameObjectType2 == LogicGameObjectType.TRAP ||
                                    gameObjectType2 == LogicGameObjectType.DECO)
                                {
                                    int width1  = gameObject1.GetWidthInTiles();
                                    int width2  = gameObject2.GetWidthInTiles();
                                    int height1 = gameObject1.GetHeightInTiles();
                                    int height2 = gameObject2.GetHeightInTiles();

                                    if (width1 == width2 && height1 == height2)
                                    {
                                        if (gameObject1.GetGameObjectType() == LogicGameObjectType.BUILDING)
                                        {
                                            LogicBuilding building = (LogicBuilding)gameObject1;

                                            if (building.IsLocked())
                                            {
                                                return(-6);
                                            }

                                            if (building.IsWall())
                                            {
                                                return(-7);
                                            }
                                        }

                                        if (gameObject2.GetGameObjectType() == LogicGameObjectType.BUILDING)
                                        {
                                            LogicBuilding building = (LogicBuilding)gameObject2;

                                            if (building.IsLocked())
                                            {
                                                return(-8);
                                            }

                                            if (building.IsWall())
                                            {
                                                return(-9);
                                            }
                                        }

                                        int x1 = gameObject1.GetX();
                                        int y1 = gameObject1.GetY();
                                        int x2 = gameObject2.GetX();
                                        int y2 = gameObject2.GetY();

                                        gameObject1.SetPositionXY(x2, y2);
                                        gameObject2.SetPositionXY(x1, y1);

                                        return(0);
                                    }

                                    return(-5);
                                }

                                return(-4);
                            }

                            return(-3);
                        }

                        return(-2);
                    }

                    return(-1);
                }

                return(-98);
            }

            return(-99);
        }
 public LogicDefenceUnitProductionComponent(LogicGameObject gameObject) : base(gameObject)
 {
     this.m_defenceTroops    = new LogicArrayList <LogicCharacter>();
     this.m_defenceTroopData = new LogicCharacterData[2];
 }
コード例 #5
0
        public override int Execute(LogicLevel level)
        {
            if (this.m_layoutId != 6)
            {
                if (this.m_layoutId != 7)
                {
                    LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObjectId);

                    if (gameObject != null)
                    {
                        LogicGameObjectType gameObjectType = gameObject.GetGameObjectType();

                        if (gameObjectType == LogicGameObjectType.BUILDING ||
                            gameObjectType == LogicGameObjectType.TRAP ||
                            gameObjectType == LogicGameObjectType.DECO)
                        {
                            LogicRect playArea = level.GetPlayArea();

                            if (playArea.IsInside(this.m_x, this.m_y) && playArea.IsInside(this.m_x + gameObject.GetWidthInTiles(), this.m_y + gameObject.GetHeightInTiles()) ||
                                this.m_x == -1 ||
                                this.m_y == -1)
                            {
                                if (gameObjectType == LogicGameObjectType.BUILDING)
                                {
                                    LogicBuilding building = (LogicBuilding)gameObject;

                                    if (building.GetWallIndex() != 0)
                                    {
                                        return(-23);
                                    }
                                }

                                gameObject.SetPositionLayoutXY(this.m_x, this.m_y, this.m_layoutId, true);

                                LogicGlobals globals = LogicDataTables.GetGlobals();

                                if (!globals.NoCooldownFromMoveEditModeActive())
                                {
                                    if (level.GetActiveLayout(level.GetVillageType()) == this.m_layoutId)
                                    {
                                        LogicAvatar homeOwnerAvatar = level.GetHomeOwnerAvatar();

                                        if (homeOwnerAvatar.GetExpLevel() >= globals.GetChallengeBaseCooldownEnabledTownHall())
                                        {
                                            level.SetLayoutCooldownSecs(this.m_layoutId, globals.GetChallengeBaseSaveCooldown());
                                        }
                                    }
                                }

                                return(0);
                            }

                            return(-2); // EditModeOutsideMap
                        }

                        return(-1);
                    }

                    return(-3);
                }

                return(-6);
            }

            return(-5);
        }
コード例 #6
0
 public LogicComponent(LogicGameObject gameObject)
 {
     this.m_parent  = gameObject;
     this.m_enabled = true;
 }
コード例 #7
0
        public override int Execute(LogicLevel level)
        {
            LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

            if (playerAvatar != null)
            {
                if (this.m_unitData != null)
                {
                    if (this.m_unitData.GetVillageType() == 0)
                    {
                        if (!this.m_unitData.IsDonationDisabled())
                        {
                            bool containsUnit = false;
                            int  upgLevel     = playerAvatar.GetUnitUpgradeLevel(this.m_unitData);

                            LogicUnitProductionComponent unitProductionComponent = null;

                            if (this.m_quickDonate)
                            {
                                int cost = this.m_unitData.GetDonateCost();

                                if (!playerAvatar.HasEnoughDiamonds(cost, true, level) || !LogicDataTables.GetGlobals().EnableQuickDonateWar())
                                {
                                    playerAvatar.GetChangeListener().WarDonateFailed(this.m_unitData, upgLevel, this.m_streamId, this.m_quickDonate);
                                    return(0);
                                }
                            }
                            else
                            {
                                LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(0);

                                if (LogicDataTables.GetGlobals().UseNewTraining())
                                {
                                    LogicUnitProduction unitProduction  = gameObjectManager.GetUnitProduction();
                                    LogicUnitProduction spellProduction = gameObjectManager.GetSpellProduction();

                                    if (unitProduction.GetWaitingForSpaceUnitCount(this.m_unitData) > 0)
                                    {
                                        if (unitProduction.GetUnitProductionType() == this.m_unitData.GetDataType())
                                        {
                                            containsUnit = true;
                                        }
                                    }

                                    if (spellProduction.GetWaitingForSpaceUnitCount(this.m_unitData) > 0)
                                    {
                                        if (spellProduction.GetUnitProductionType() == this.m_unitData.GetDataType())
                                        {
                                            containsUnit = true;
                                        }
                                    }
                                }
                                else
                                {
                                    for (int i = 0, c = gameObjectManager.GetNumGameObjects(); i < c; i++)
                                    {
                                        LogicGameObject gameObject = gameObjectManager.GetGameObjectByIndex(i);

                                        if (gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING)
                                        {
                                            LogicBuilding building = (LogicBuilding)gameObject;
                                            LogicUnitProductionComponent component = building.GetUnitProductionComponent();

                                            if (component != null)
                                            {
                                                unitProductionComponent = component;

                                                if (component.ContainsUnit(this.m_unitData))
                                                {
                                                    if (component.GetRemainingSeconds() == 0 && component.GetCurrentlyTrainedUnit() == this.m_unitData)
                                                    {
                                                        containsUnit = true;
                                                    }
                                                }
                                                else
                                                {
                                                    unitProductionComponent = null;
                                                }
                                            }
                                        }
                                    }
                                }

                                if (!containsUnit)
                                {
                                    if (playerAvatar.GetUnitCount(this.m_unitData) <= 0)
                                    {
                                        playerAvatar.GetChangeListener().WarDonateFailed(this.m_unitData, upgLevel, this.m_streamId, this.m_quickDonate);
                                        return(0);
                                    }
                                }
                            }

                            if (this.m_unitData.GetCombatItemType() != LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER)
                            {
                                playerAvatar.XpGainHelper(this.m_unitData.GetHousingSpace() * LogicDataTables.GetGlobals().GetDarkSpellDonationXP());
                                level.GetAchievementManager().AlianceSpellDonated((LogicSpellData)this.m_unitData);
                            }
                            else
                            {
                                playerAvatar.XpGainHelper(((LogicCharacterData)this.m_unitData).GetDonateXP());
                                level.GetAchievementManager().AlianceUnitDonated((LogicCharacterData)this.m_unitData);
                            }

                            playerAvatar.GetChangeListener().WarDonateOk(this.m_unitData, upgLevel, this.m_streamId, this.m_quickDonate);

                            if (this.m_quickDonate)
                            {
                                int cost = this.m_unitData.GetDonateCost();

                                playerAvatar.UseDiamonds(cost);
                                playerAvatar.GetChangeListener().DiamondPurchaseMade(12, this.m_unitData.GetGlobalID(), 0, cost, level.GetVillageType());

                                if (level.GetState() == 1 || level.GetState() == 3 &&
                                    this.m_unitData.GetCombatItemType() == LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER)
                                {
                                    // TODO: Finish this.
                                }
                            }
                            else
                            {
                                if (!containsUnit)
                                {
                                    playerAvatar.CommodityCountChangeHelper(0, this.m_unitData, -1);
                                }

                                LogicResourceData trainingResource = this.m_unitData.GetTrainingResource();
                                int trainingCost = level.GetGameMode().GetCalendar().GetTrainingCost(this.m_unitData, upgLevel);
                                int refund       = playerAvatar.GetTroopDonationRefund() * trainingCost / 100;

                                playerAvatar.CommodityCountChangeHelper(0, trainingResource, LogicMath.Max(refund, 0));

                                if (level.GetState() == 1 || level.GetState() == 3)
                                {
                                    if (containsUnit)
                                    {
                                        if (LogicDataTables.GetGlobals().UseNewTraining())
                                        {
                                            LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(0);
                                            LogicUnitProduction    unitProduction    = this.m_unitData.GetCombatItemType() != LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER
                                                ? gameObjectManager.GetSpellProduction()
                                                : gameObjectManager.GetUnitProduction();

                                            unitProduction.RemoveTrainedUnit(this.m_unitData);
                                        }

                                        if (this.m_unitData.GetCombatItemType() == LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER)
                                        {
                                            LogicBuilding productionHouse = null;

                                            if (unitProductionComponent != null)
                                            {
                                                productionHouse = (LogicBuilding)unitProductionComponent.GetParent();
                                            }
                                            else
                                            {
                                                if (LogicDataTables.GetGlobals().UseTroopWalksOutFromTraining())
                                                {
                                                    LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(0);
                                                    int gameObjectCount = gameObjectManager.GetNumGameObjects();

                                                    for (int i = 0; i < gameObjectCount; i++)
                                                    {
                                                        LogicGameObject gameObject = gameObjectManager.GetGameObjectByIndex(i);

                                                        if (gameObject != null && gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING)
                                                        {
                                                            LogicBuilding tmpBuilding = (LogicBuilding)gameObject;
                                                            LogicUnitProductionComponent tmpComponent = tmpBuilding.GetUnitProductionComponent();

                                                            if (tmpComponent != null)
                                                            {
                                                                if (tmpComponent.GetProductionType() == this.m_unitData.GetCombatItemType())
                                                                {
                                                                    if (tmpBuilding.GetBuildingData().GetProducesUnitsOfType() == this.m_unitData.GetUnitOfType() &&
                                                                        !tmpBuilding.IsUpgrading() &&
                                                                        !tmpBuilding.IsConstructing())
                                                                    {
                                                                        if (this.m_unitData.IsUnlockedForProductionHouseLevel(tmpBuilding.GetUpgradeLevel()))
                                                                        {
                                                                            if (productionHouse != null)
                                                                            {
                                                                                int seed = playerAvatar.GetExpPoints();

                                                                                if (tmpBuilding.Rand(seed) % 1000 > 750)
                                                                                {
                                                                                    productionHouse = tmpBuilding;
                                                                                }
                                                                            }
                                                                            else
                                                                            {
                                                                                productionHouse = tmpBuilding;
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }

                                            if (productionHouse != null)
                                            {
                                                // TODO: Implement listener.
                                            }
                                        }
                                    }
                                    else
                                    {
                                        LogicArrayList <LogicComponent> components = level.GetComponentManagerAt(0).GetComponents(LogicComponentType.UNIT_STORAGE);

                                        for (int i = 0; i < components.Size(); i++)
                                        {
                                            LogicUnitStorageComponent unitStorageComponent = (LogicUnitStorageComponent)components[i];
                                            int idx = unitStorageComponent.GetUnitTypeIndex(this.m_unitData);

                                            if (idx != -1)
                                            {
                                                if (unitStorageComponent.GetUnitCount(idx) > 0)
                                                {
                                                    unitStorageComponent.RemoveUnits(this.m_unitData, 1);

                                                    if (LogicDataTables.GetGlobals().UseNewTraining())
                                                    {
                                                        LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(0);
                                                        LogicUnitProduction    unitProduction    = this.m_unitData.GetCombatItemType() != LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER
                                                            ? gameObjectManager.GetSpellProduction()
                                                            : gameObjectManager.GetUnitProduction();

                                                        unitProduction.MergeSlots();
                                                        unitProduction.UnitRemoved();
                                                    }

                                                    break;
                                                }
                                            }
                                        }
                                    }

                                    // TODO: Finish this.
                                }
                            }

                            return(0);
                        }

                        return(-91);
                    }

                    return(-45);
                }
            }

            return(0);
        }
コード例 #8
0
        /// <summary>
        ///     Executes this command.
        /// </summary>
        public override int Execute(LogicLevel level)
        {
            LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this._gameObjectId);

            if (gameObject != null)
            {
                if (gameObject.GetGameObjectType() == 0)
                {
                    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);
                    }
                }

                if (gameObject.GetGameObjectType() == 3)
                {
                    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);
                    }
                }

                if (gameObject.GetGameObjectType() == 4)
                {
                    LogicTrap trap = (LogicTrap)gameObject;

                    if (trap.IsConstructing())
                    {
                        trap.GetListener().CancelNotification();
                        trap.CancelConstruction();

                        return(0);
                    }
                }
            }

            return(-1);
        }
コード例 #9
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;
                LogicBuildingData buildingData = building.GetBuildingData();

                if (buildingData.GetVillageType() == level.GetVillageType())
                {
                    if (!level.IsBuildingGearUpCapReached(buildingData, true))
                    {
                        if (building.GetGearLevel() == 0)
                        {
                            int upgLevel   = building.GetUpgradeLevel();
                            int gearUpCost = buildingData.GetGearUpCost(upgLevel);

                            if (gearUpCost > 0)
                            {
                                if (upgLevel >= buildingData.GetMinUpgradeLevelForGearUp())
                                {
                                    if (level.GetGameObjectManagerAt(1).GetHighestBuildingLevel(buildingData.GetGearUpBuildingData()) <
                                        buildingData.GetGearUpLevelRequirement())
                                    {
                                        return(-1);
                                    }

                                    LogicResourceData gearUpResource = buildingData.GetGearUpResource();

                                    if (gearUpResource != null)
                                    {
                                        LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

                                        if (playerAvatar.HasEnoughResources(gearUpResource, gearUpCost, true, this, false))
                                        {
                                            if (level.HasFreeWorkers(this, 1))
                                            {
                                                playerAvatar.CommodityCountChangeHelper(0, gearUpResource, -gearUpCost);
                                                building.StartUpgrading(true, true);

                                                return(0);
                                            }
                                        }
                                    }

                                    return(-1);
                                }

                                return(-37);
                            }

                            return(-36);
                        }

                        return(-35);
                    }

                    return(-31);
                }

                return(-32);
            }

            return(-1);
        }
コード例 #10
0
ファイル: LogicTile.cs プロジェクト: NotHuza/Cerberus-v4
        /// <summary>
        ///     Refreshes sub tiles.
        /// </summary>
        public void RefreshSubTiles()
        {
            this._passableFlag &= 0xF0;

            for (int i = 0; i < this._gameObjects.Count; i++)
            {
                LogicGameObject gameObject = this._gameObjects[i];

                this._pathFinderCost = LogicMath.Max(this._pathFinderCost, gameObject.GetPathFinderCost());

                if (!gameObject.IsPassable())
                {
                    int width = gameObject.GetWidthInTiles();

                    if (width == 1)
                    {
                        this._passableFlag |= 0xF0;
                    }
                    else
                    {
                        int tileX  = gameObject.GetTileX();
                        int tileY  = gameObject.GetTileY();
                        int edge   = gameObject.PassableSubtilesAtEdge();
                        int startX = 2 * width - edge;
                        int startY = 2 * width - edge;
                        int endX   = 2 * (width - edge);
                        int endY   = 2 * (width - edge);

                        // RIP

                        /* do
                         * {
                         *     v11 = v20 + v19;
                         *     v12 = -1;
                         *     v13 = v20;
                         *     do
                         *     {
                         *         v14 = 2 * (v28 - v27) + v12 + 1;
                         *         v16 = __OFSUB__(v14, v9);
                         *         v15 = v14 - v9 < 0;
                         *         if ( v14 < v9 )
                         *         {
                         *             v16 = __OFSUB__(v11, v10);
                         *             v15 = v11 - v10 < 0;
                         *         }
                         *         if ( v15 ^ v16 )
                         *         {
                         *             v18 = __OFSUB__(v11, v8);
                         *             v17 = v11 - v8 < 0;
                         *             if ( v11 >= v8 )
                         *             {
                         *                 v18 = __OFSUB__(v14, v8);
                         *                 v17 = v14 - v8 < 0;
                         *             }
                         *              if ( !(v17 ^ v18) )
                         *(_BYTE *)(v1 + 8) |= 1 << v13;
                         *          }
                         ++v12;
                         *          v13 += 2;
                         *     }
                         *     while ( v12 < 1 );
                         *     v19 = v29;
                         *     v16 = __OFSUB__(v20, 1);
                         *     v15 = v20++ - 1 < 0;
                         * }
                         * while ( v15 ^ v16 );
                         */
                    }
                }
            }
        }
コード例 #11
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="LogicCombatComponent" /> class.
 /// </summary>
 public LogicCombatComponent(LogicGameObject gameObject) : base(gameObject)
 {
 }
コード例 #12
0
 public LogicUnitStorageComponent(LogicGameObject gameObject, int capacity) : base(gameObject)
 {
     this.m_slots       = new LogicArrayList <LogicUnitSlot>();
     this.m_maxCapacity = capacity;
     this.SetStorageType(gameObject);
 }
コード例 #13
0
        public void CauseDamage(int damage, int gameObjectId, LogicGameObject gameObject)
        {
            if (damage >= 0 || this.m_hp != 0)
            {
                if (this.m_parent == null)
                {
                    if (damage > 0 && this.m_invulnerabilityTime > 0)
                    {
                        return;
                    }
                }
                else
                {
                    LogicCombatComponent combatComponent = this.m_parent.GetCombatComponent();

                    if (combatComponent != null)
                    {
                        if (combatComponent.GetUndergroundTime() > 0 && damage > 0)
                        {
                            damage = 0;
                        }
                    }

                    if (!this.m_parent.GetLevel().GetInvulnerabilityEnabled())
                    {
                        if (damage > 0 && this.m_invulnerabilityTime > 0)
                        {
                            return;
                        }
                    }
                    else
                    {
                        damage = 0;
                    }

                    if (this.m_parent.GetGameObjectType() == LogicGameObjectType.CHARACTER)
                    {
                        LogicCharacter character = (LogicCharacter)this.m_parent;
                        LogicArrayList <LogicCharacter> childTroops = character.GetChildTroops();

                        if (childTroops != null && childTroops.Size() > 0 || character.GetSpawnDelay() > 0)
                        {
                            return;
                        }
                    }
                }

                if (gameObjectId != 0 && damage < 0)
                {
                    int prevHealingIdx = -1;
                    int healingIdx     = -1;

                    for (int i = 0; i < 8; i++)
                    {
                        if (this.m_healingId[i] == gameObjectId)
                        {
                            prevHealingIdx = i;
                        }
                        else if (healingIdx == -1)
                        {
                            healingIdx = i;

                            if (this.m_healingTime[i] > 0)
                            {
                                healingIdx = -1;
                            }
                        }
                    }

                    if (healingIdx < prevHealingIdx && prevHealingIdx != -1 && healingIdx != -1)
                    {
                        this.m_healingId[healingIdx]       = gameObjectId;
                        this.m_healingTime[healingIdx]     = 1000;
                        this.m_healingId[prevHealingIdx]   = 0;
                        this.m_healingTime[prevHealingIdx] = 0;
                    }
                    else if (prevHealingIdx == -1)
                    {
                        if (healingIdx != -1)
                        {
                            this.m_healingId[healingIdx]   = gameObjectId;
                            this.m_healingTime[healingIdx] = 1000;
                        }
                        else
                        {
                            healingIdx = 8;
                        }
                    }
                    else
                    {
                        healingIdx = prevHealingIdx;
                        this.m_healingTime[prevHealingIdx] = 1000;
                    }

                    damage = damage * LogicDataTables.GetGlobals().GetHealStackPercent(healingIdx) / 100;
                }

                int prevHp         = (this.m_hp + 99) / 100;
                int prevAccurateHp = this.m_hp;
                this.m_hp = LogicMath.Clamp(this.m_hp - damage, 0, this.m_maxHp);
                int hp = (this.m_hp + 99) / 100;

                if (prevHp > hp)
                {
                    LogicResourceStorageComponent resourceStorageComponent =
                        (LogicResourceStorageComponent)this.m_parent.GetComponent(LogicComponentType.RESOURCE_STORAGE);
                    LogicResourceProductionComponent resourceProductionComponent =
                        (LogicResourceProductionComponent)this.m_parent.GetComponent(LogicComponentType.RESOURCE_PRODUCTION);
                    LogicWarResourceStorageComponent warResourceStorageComponent =
                        (LogicWarResourceStorageComponent)this.m_parent.GetComponent(LogicComponentType.WAR_RESOURCE_STORAGE);

                    if (this.m_parent.GetGameObjectType() == LogicGameObjectType.BUILDING)
                    {
                        LogicBuilding building = (LogicBuilding)this.m_parent;

                        if (!building.GetBuildingData().IsLootOnDestruction() || prevAccurateHp > 0 && (this.m_hp == 0 || (uint)this.m_hp >= 0xFFFFFF3A))
                        {
                            if (resourceStorageComponent != null)
                            {
                                resourceStorageComponent.ResourcesStolen(prevHp - hp, prevHp);
                            }
                            if (resourceProductionComponent != null)
                            {
                                resourceProductionComponent.ResourcesStolen(prevHp - hp, prevHp);
                            }
                            if (warResourceStorageComponent != null)
                            {
                                warResourceStorageComponent.ResourcesStolen(prevHp - hp, prevHp);
                            }
                        }
                    }

                    if (this.m_parent.IsWall())
                    {
                        this.m_parent.RefreshPassable();
                    }
                    this.m_lastDamageTime = 0;
                }

                this.UpdateHeroHealthToAvatar(hp);

                if (damage <= 0)
                {
                    if (damage < 0)
                    {
                        // Listener
                    }
                }
                else
                {
                    if (this.m_parent.GetMovementComponent() != null)
                    {
                        this.m_parent.GetMovementComponent().SetPatrolFreeze();
                    }
                }

                if (prevAccurateHp > 0 && this.m_hp == 0)
                {
                    this.m_parent.DeathEvent();
                    this.m_parent.GetLevel().UpdateBattleStatus();

                    if (this.m_parent.IsWall())
                    {
                        this.WallRemoved();
                    }
                }
            }
        }
コード例 #14
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.IsTownHallVillage2())
                    {
                        if (!LogicUpgradeBuildingCommand.CanUpgradeTHV2(level))
                        {
                            return(-76);
                        }
                    }

                    if (buildingData.GetVillageType() == level.GetVillageType())
                    {
                        if (level.GetGameObjectManager().GetAvailableBuildingUpgradeCount(building) <= 0)
                        {
                            return(-34);
                        }

                        if (building.GetWallIndex() == 0)
                        {
                            if (building.CanUpgrade(true))
                            {
                                int nextUpgradeLevel = building.GetUpgradeLevel() + 1;
                                int buildCost        = buildingData.GetBuildCost(nextUpgradeLevel, level);

                                LogicResourceData buildResourceData = this.m_useAltResource
                                    ? buildingData.GetAltBuildResource(nextUpgradeLevel)
                                    : buildingData.GetBuildResource(nextUpgradeLevel);

                                if (buildResourceData != null)
                                {
                                    LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

                                    if (playerAvatar.HasEnoughResources(buildResourceData, buildCost, true, this, false))
                                    {
                                        if (buildingData.GetConstructionTime(nextUpgradeLevel, level, 0) != 0 || LogicDataTables.GetGlobals().WorkerForZeroBuilTime())
                                        {
                                            if (!level.HasFreeWorkers(this, -1))
                                            {
                                                return(-1);
                                            }
                                        }

                                        playerAvatar.CommodityCountChangeHelper(0, buildResourceData, -buildCost);
                                        building.StartUpgrading(true, false);

                                        return(0);
                                    }
                                }
                            }

                            return(-1);
                        }

                        return(-35);
                    }

                    return(-32);
                }

                if (gameObject.GetGameObjectType() == LogicGameObjectType.TRAP)
                {
                    LogicTrap trap = (LogicTrap)gameObject;

                    if (trap.CanUpgrade(true))
                    {
                        LogicTrapData     data = trap.GetTrapData();
                        LogicResourceData buildResourceData = data.GetBuildResource();
                        LogicClientAvatar playerAvatar      = level.GetPlayerAvatar();

                        int buildCost = data.GetBuildCost(trap.GetUpgradeLevel() + 1);

                        if (playerAvatar.HasEnoughResources(buildResourceData, buildCost, true, this, false))
                        {
                            if (data.GetBuildTime(trap.GetUpgradeLevel() + 1) != 0 || LogicDataTables.GetGlobals().WorkerForZeroBuilTime())
                            {
                                if (!level.HasFreeWorkers(this, -1))
                                {
                                    return(-1);
                                }
                            }

                            playerAvatar.CommodityCountChangeHelper(0, buildResourceData, -buildCost);
                            trap.StartUpgrading();

                            return(0);
                        }
                    }
                }
                else if (gameObject.GetGameObjectType() == LogicGameObjectType.VILLAGE_OBJECT)
                {
                    if (!this.m_useAltResource)
                    {
                        LogicVillageObject villageObject = (LogicVillageObject)gameObject;

                        if (villageObject.CanUpgrade(true))
                        {
                            LogicVillageObjectData data = villageObject.GetVillageObjectData();
                            LogicResourceData      buildResourceData = data.GetBuildResource();

                            int buildCost = data.GetBuildCost(villageObject.GetUpgradeLevel() + 1);

                            if (buildResourceData != null)
                            {
                                LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

                                if (playerAvatar.HasEnoughResources(buildResourceData, buildCost, true, this, false))
                                {
                                    if (data.GetBuildTime(villageObject.GetUpgradeLevel() + 1) != 0 || LogicDataTables.GetGlobals().WorkerForZeroBuilTime())
                                    {
                                        if (!level.HasFreeWorkers(this, -1))
                                        {
                                            return(-1);
                                        }
                                    }

                                    playerAvatar.CommodityCountChangeHelper(0, buildResourceData, -buildCost);
                                    villageObject.StartUpgrading(true);

                                    return(0);
                                }
                            }
                        }

                        return(-1);
                    }

                    return(-31);
                }
            }

            return(-1);
        }
コード例 #15
0
        public override int Execute(LogicLevel level)
        {
            LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObjectId);

            if (gameObject != null)
            {
                LogicGameObjectType gameObjectType = gameObject.GetGameObjectType();

                if (gameObjectType == LogicGameObjectType.BUILDING || gameObjectType == LogicGameObjectType.TRAP ||
                    gameObjectType == LogicGameObjectType.DECO)
                {
                    if (gameObjectType != LogicGameObjectType.BUILDING || ((LogicBuildingData)gameObject.GetData()).GetVillageType() == level.GetVillageType())
                    {
                        if (gameObjectType == LogicGameObjectType.BUILDING)
                        {
                            if (((LogicBuilding)gameObject).GetWallIndex() != 0)
                            {
                                return(-21);
                            }
                        }

                        int x      = gameObject.GetTileX();
                        int y      = gameObject.GetTileY();
                        int width  = gameObject.GetWidthInTiles();
                        int height = gameObject.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);
                                }
                            }
                        }

                        if (level.IsValidPlaceForBuilding(this.m_x, this.m_y, width, height, gameObject))
                        {
                            gameObject.SetPositionXY(this.m_x << 9, this.m_y << 9);

                            if (this.m_x != x || this.m_y != y)
                            {
                                LogicAvatar homeOwnerAvatar = level.GetHomeOwnerAvatar();

                                if (homeOwnerAvatar != null)
                                {
                                    if (homeOwnerAvatar.GetTownHallLevel() >= LogicDataTables.GetGlobals().GetChallengeBaseCooldownEnabledTownHall() &&
                                        gameObject.GetGameObjectType() != LogicGameObjectType.DECO)
                                    {
                                        level.SetLayoutCooldownSecs(level.GetActiveLayout(level.GetVillageType()), LogicDataTables.GetGlobals().GetChallengeBaseSaveCooldown());
                                    }
                                }
                            }

                            return(0);
                        }

                        return(-3);
                    }

                    return(-32);
                }

                return(-1);
            }

            return(-2);
        }
コード例 #16
0
        /// <summary>
        ///     Called when the current production is completed.
        /// </summary>
        public bool ProductionCompleted(bool speedUp)
        {
            Boolean success = false;
            Boolean end     = false;

            if (!this._locked)
            {
                LogicComponentFilter filter = new LogicComponentFilter();

                filter.SetComponentType(0);

                while (true)
                {
                    LogicAvatar           homeOwnerAvatar  = this._level.GetHomeOwnerAvatar();
                    LogicComponentManager componentManager = this._level.GetComponentManagerAt(this._villageType);
                    LogicCombatItemData   productionData   = this.GetWaitingForSpaceUnit();

                    if (speedUp)
                    {
                        if (this._slots.Count <= 0)
                        {
                            return(false);
                        }

                        productionData = (LogicCombatItemData)this._slots[0].GetData();
                    }

                    if (productionData == null)
                    {
                        return(false);
                    }

                    Boolean                productionTerminate    = this._slots[0].IsTerminate();
                    LogicBuildingData      buildingProductionData = productionData.GetProductionHouseData();
                    LogicGameObjectManager gameObjectManager      = this._level.GetGameObjectManagerAt(this._villageType);
                    LogicBuilding          productionHouse        = gameObjectManager.GetHighestBuilding(buildingProductionData);

                    if (LogicDataTables.GetGlobals().UseTroopWalksOutFromTraining())
                    {
                        int gameObjectCount = gameObjectManager.GetNumGameObjects();

                        for (int i = 0; i < gameObjectCount; i++)
                        {
                            LogicGameObject gameObject = gameObjectManager.GetGameObjectByIndex(i);

                            if (gameObject != null)
                            {
                                if (gameObject.GetGameObjectType() == 0)
                                {
                                    LogicBuilding building = (LogicBuilding)gameObject;
                                    LogicUnitProductionComponent unitProductionComponent = building.GetUnitProductionComponent();

                                    if (unitProductionComponent != null)
                                    {
                                        if (unitProductionComponent.GetProductionType() == productionData.GetCombatItemType())
                                        {
                                            if (building.GetBuildingData().ProducesUnitsOfType == productionData.GetUnitOfType() &&
                                                !building.IsUpgrading() &&
                                                !building.IsConstructing())
                                            {
                                                if (productionData.IsUnlockedForProductionHouseLevel(building.GetUpgradeLevel()))
                                                {
                                                    if (productionHouse != null)
                                                    {
                                                        int seed = this._level.GetPlayerAvatar().GetExpPoints();

                                                        if (building.Rand(seed) % 1000 > 750)
                                                        {
                                                            productionHouse = building;
                                                        }
                                                    }
                                                    else
                                                    {
                                                        productionHouse = building;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    if (productionHouse != null)
                    {
                        LogicUnitStorageComponent unitStorageComponent =
                            (LogicUnitStorageComponent)componentManager.GetClosestComponent(productionHouse.GetX(), productionHouse.GetY(), filter);

                        if (unitStorageComponent != null)
                        {
                            if (unitStorageComponent.CanAddUnit(productionData))
                            {
                                homeOwnerAvatar.CommodityCountChangeHelper(0, productionData, 1);
                                unitStorageComponent.AddUnit(productionData);

                                if (productionTerminate)
                                {
                                    this.RemoveUnit(productionData, -1);
                                }
                                else
                                {
                                    this.StartProducingNextUnit();
                                }

                                success = true;

                                if (this._slots.Count > 0 && this._slots[0].IsTerminate() && this._slots[0].GetCount() > 0)
                                {
                                    continue;
                                }

                                break;
                            }
                            else
                            {
                                filter.AddIgnoreObject(unitStorageComponent.GetParent());
                                continue;
                            }
                        }
                        else
                        {
                            if (this._timer != null && this._timer.GetRemainingSeconds(this._level.GetLogicTime()) == 0)
                            {
                                success = this.TrainingFinished();
                            }

                            break;
                        }
                    }
                }

                filter.Destruct();

                if (success)
                {
                    this._nextProduction = 0;
                }
                else
                {
                    this._nextProduction = 2000;
                }
            }

            return(success);
        }
コード例 #17
0
        public override int Execute(LogicLevel level)
        {
            int count = this.m_gameObjectIds.Size();

            if (count > 0)
            {
                bool validGameObjects = true;

                if (this.m_xPositions.Size() == count && this.m_xPositions.Size() == count && count <= 500)
                {
                    LogicGameObject[] gameObjects = new LogicGameObject[count];

                    for (int i = 0; i < count; i++)
                    {
                        LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObjectIds[i]);

                        if (gameObject != null)
                        {
                            LogicGameObjectType gameObjectType = gameObject.GetGameObjectType();

                            if (gameObjectType != LogicGameObjectType.BUILDING &&
                                gameObjectType != LogicGameObjectType.TRAP &&
                                gameObjectType != LogicGameObjectType.DECO)
                            {
                                validGameObjects = false;
                            }

                            gameObjects[i] = gameObject;
                        }
                        else
                        {
                            validGameObjects = false;
                        }
                    }

                    if (validGameObjects)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            LogicGameObject gameObject = gameObjects[i];

                            if (gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING && validGameObjects)
                            {
                                LogicBuilding baseWallBlock = (LogicBuilding)gameObject;

                                if (baseWallBlock.GetWallIndex() != 0)
                                {
                                    int x             = this.m_xPositions[i];
                                    int y             = this.m_yPositions[i];
                                    int minX          = 0;
                                    int minY          = 0;
                                    int maxX          = 0;
                                    int maxY          = 0;
                                    int minWallBlockX = 0;
                                    int minWallBlockY = 0;
                                    int maxWallBlockX = 0;
                                    int maxWallBlockY = 0;
                                    int wallBlockCnt  = 0;

                                    bool success = true;

                                    for (int j = 0; j < count; j++)
                                    {
                                        LogicGameObject obj = gameObjects[j];

                                        if (obj.GetGameObjectType() == LogicGameObjectType.BUILDING)
                                        {
                                            LogicBuilding wallBlock = (LogicBuilding)obj;

                                            if (wallBlock.GetWallIndex() == baseWallBlock.GetWallIndex())
                                            {
                                                int tmp1 = x - this.m_xPositions[j];
                                                int tmp2 = y - this.m_yPositions[j];

                                                if ((x & this.m_xPositions[j]) != -1)
                                                {
                                                    success = false;
                                                }

                                                minX = LogicMath.Min(minX, tmp1);
                                                minY = LogicMath.Min(minY, tmp2);
                                                maxX = LogicMath.Max(maxX, tmp1);
                                                maxY = LogicMath.Max(maxY, tmp2);

                                                int wallBlockX = wallBlock.GetBuildingData().GetWallBlockX(wallBlockCnt);
                                                int wallBlockY = wallBlock.GetBuildingData().GetWallBlockY(wallBlockCnt);

                                                minWallBlockX = LogicMath.Min(minWallBlockX, wallBlockX);
                                                minWallBlockY = LogicMath.Min(minWallBlockY, wallBlockY);
                                                maxWallBlockX = LogicMath.Max(maxWallBlockX, wallBlockX);
                                                maxWallBlockY = LogicMath.Max(maxWallBlockY, wallBlockY);

                                                ++wallBlockCnt;
                                            }
                                        }
                                    }

                                    if (baseWallBlock.GetBuildingData().GetWallBlockCount() == wallBlockCnt)
                                    {
                                        int wallBlockSizeX = maxWallBlockX - minWallBlockX;
                                        int wallBlockSizeY = maxWallBlockY - minWallBlockY;
                                        int lengthX        = maxX - minX;
                                        int lengthY        = maxY - minY;

                                        if (wallBlockSizeX != lengthX || wallBlockSizeY != lengthY)
                                        {
                                            if (!success && wallBlockSizeX != lengthX != (wallBlockSizeY != lengthY))
                                            {
                                                validGameObjects = false;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    if (validGameObjects)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            int x = this.m_xPositions[i];
                            int y = this.m_yPositions[i];

                            LogicGameObject gameObject = gameObjects[i];

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

                            int tmp1 = x + width;
                            int tmp2 = y + height;

                            for (int j = 0; j < count; j++)
                            {
                                LogicGameObject gameObject2 = gameObjects[j];

                                if (gameObject2 != gameObject)
                                {
                                    int x2 = this.m_xPositions[j];
                                    int y2 = this.m_yPositions[j];

                                    if (x2 != -1 && y2 != -1)
                                    {
                                        int width2  = gameObject2.GetWidthInTiles();
                                        int height2 = gameObject2.GetHeightInTiles();
                                        int tmp3    = x2 + width2;
                                        int tmp4    = y2 + height2;

                                        if (tmp1 > x2 && tmp2 > y2 && x < tmp3 && y < tmp4)
                                        {
                                            return(0);
                                        }
                                    }
                                }
                            }
                        }

                        bool moved = false;

                        for (int i = 0; i < count; i++)
                        {
                            int x = this.m_xPositions[i];
                            int y = this.m_yPositions[i];

                            LogicGameObject gameObject = gameObjects[i];
                            LogicVector2    position   = gameObject.GetPositionLayout(this.m_layoutId, true);

                            if (position.m_x != -1 && position.m_y != -1)
                            {
                                if (x != position.m_x && y != position.m_y)
                                {
                                    moved = true;
                                }
                            }

                            gameObject.SetPositionLayoutXY(x, y, this.m_layoutId, true);

                            LogicGlobals globals = LogicDataTables.GetGlobals();

                            if (!globals.NoCooldownFromMoveEditModeActive())
                            {
                                if (level.GetActiveLayout(level.GetVillageType()) == this.m_layoutId)
                                {
                                    LogicAvatar homeOwnerAvatar = level.GetHomeOwnerAvatar();

                                    if (homeOwnerAvatar.GetExpLevel() >= globals.GetChallengeBaseCooldownEnabledTownHall())
                                    {
                                        level.SetLayoutCooldownSecs(this.m_layoutId, globals.GetChallengeBaseSaveCooldown());
                                    }
                                }
                            }
                        }

                        if (moved)
                        {
                            LogicAvatar homeOwnerAvatar = level.GetHomeOwnerAvatar();

                            if (homeOwnerAvatar.GetExpLevel() >= LogicDataTables.GetGlobals().GetChallengeBaseCooldownEnabledTownHall())
                            {
                                level.SetLayoutCooldownSecs(this.m_layoutId, LogicDataTables.GetGlobals().GetChallengeBaseSaveCooldown());
                            }
                        }

                        return(0);
                    }
                }
            }

            return(-1);
        }
コード例 #18
0
        /// <summary>
        ///     Executes this command.
        /// </summary>
        public override int Execute(LogicLevel level)
        {
            if (this._gameObjectIds.Count > 0)
            {
                int cost = 0;

                for (int i = 0; i < this._gameObjectIds.Count; i++)
                {
                    LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this._gameObjectIds[i]);

                    if (gameObject != null && gameObject.GetGameObjectType() == 0)
                    {
                        if (gameObject.GetData().GetVillageType() == level.GetVillageType())
                        {
                            LogicBuilding building = (LogicBuilding)gameObject;

                            if (!building.IsLocked())
                            {
                                if (!LogicDataTables.GetGlobals().UseNewTraining() || building.GetUnitProductionComponent() == null)
                                {
                                    if (building.CanBeBoosted())
                                    {
                                        cost += building.GetBoostCost();
                                    }

                                    continue;
                                }

                                return(-3);
                            }

                            return(-4);
                        }

                        return(-32);
                    }

                    return(-5);
                }

                LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

                if (cost > 0)
                {
                    if (!playerAvatar.HasEnoughDiamonds(cost, true, level))
                    {
                        return(-2);
                    }

                    playerAvatar.UseDiamonds(cost);
                }

                for (int i = 0; i < this._gameObjectIds.Count; i++)
                {
                    LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this._gameObjectIds[i]);

                    if (gameObject != null && gameObject.GetGameObjectType() == 0)
                    {
                        LogicBuilding building = (LogicBuilding)gameObject;

                        if (building.GetMaxBoostTime() != 0)
                        {
                            building.Boost();
                        }
                    }
                }

                return(0);
            }

            return(-1);
        }
コード例 #19
0
 public virtual void RemoveGameObjectReferences(LogicGameObject gameObject)
 {
     // RemoveGameObjectReferences.
 }
コード例 #20
0
        /// <summary>
        ///     Executes this command.
        /// </summary>
        public override int Execute(LogicLevel level)
        {
            LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this._gameObjectId);

            if (gameObject != null)
            {
                if (gameObject.GetGameObjectType() == 0)
                {
                    if (gameObject.GetVillageType() == level.GetVillageType())
                    {
                        LogicResourceProductionComponent resourceProductionComponent = gameObject.GetResourceProductionComponent();

                        if (resourceProductionComponent != null)
                        {
                            if (LogicDataTables.GetGlobals().CollectAllResourcesAtOnce())
                            {
                                int baseAvailableResources = resourceProductionComponent.GetResourceCount();
                                int baseCollectedResources = resourceProductionComponent.CollectResources(true);

                                bool storageIsFull = baseAvailableResources > 0 && baseCollectedResources == 0;

                                Debugger.Print("Collected: " + baseCollectedResources);

                                LogicArrayList <LogicComponent> components = level.GetComponentManager().GetComponents(resourceProductionComponent.GetComponentType());

                                for (int i = 0; i < components.Count; i++)
                                {
                                    LogicResourceProductionComponent component = (LogicResourceProductionComponent)components[i];

                                    if (resourceProductionComponent != component && resourceProductionComponent.GetResourceData() == component.GetResourceData())
                                    {
                                        int availableResources = component.GetResourceCount();
                                        int collectedResources = component.CollectResources(!storageIsFull);

                                        if (availableResources > 0)
                                        {
                                            if (collectedResources == 0)
                                            {
                                                storageIsFull = true;
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                resourceProductionComponent.CollectResources(true);
                            }

                            return(0);
                        }

                        return(-1);
                    }

                    return(-3);
                }
            }

            return(-2);
        }
コード例 #21
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="LogicHitpointComponent" /> class.
 /// </summary>
 public LogicWarResourceStorageComponent(LogicGameObject gameObject) : base(gameObject)
 {
     // LogicWarResourceStorageComponent.
 }
コード例 #22
0
        /// <summary>
        ///     Ticks this instance.
        /// </summary>
        public override void Tick()
        {
            LogicArrayList <LogicComponent> components = this._parent.GetComponentManager().GetComponents(15);
            int barrackCount      = this._parent.GetGameObjectManager().GetBarrackCount();
            int barrackFoundCount = 0;

            if (barrackCount > 0)
            {
                int idx = 0;

                do
                {
                    LogicBuilding building = (LogicBuilding)this._parent.GetGameObjectManager().GetBarrack(idx);

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

            this._noBarrack = barrackFoundCount == 0;

            for (int i = 0; i < components.Count; i++)
            {
                LogicVillage2UnitComponent component = (LogicVillage2UnitComponent)components[i];

                if (barrackFoundCount != 0)
                {
                    if (component == this)
                    {
                        break;
                    }
                }

                if (component != null)
                {
                    if (component._unit != null)
                    {
                        if (component._unit.GetData() != null && component._unit.GetCount() == 0)
                        {
                            if (component.GetRemainingSecs() > 0)
                            {
                                if (this._trainingTimer != null)
                                {
                                    this._trainingTimer.StartTimer(this._trainingTimer.GetRemainingSeconds(this._parent.GetLevel().GetLogicTime()),
                                                                   this._parent.GetLevel().GetLogicTime(), false, -1);
                                }

                                return;
                            }
                        }
                    }
                }
            }

            if (this._trainingTimer != null)
            {
                if (this._parent.GetLevel().GetRemainingClockTowerBoostTime() > 0)
                {
                    if (this._parent.GetData().GetDataType() == 0)
                    {
                        if (this._parent.GetData().GetVillageType() == 1)
                        {
                            this._trainingTimer.FastForwardSubticks(4 * LogicDataTables.GetGlobals().GetClockTowerBoostMultiplier() - 4);
                        }
                    }
                }
            }

            if (this.GetParent() != null)
            {
                LogicGameObject gameObject = this.GetParent();

                if (gameObject.GetListener() != null)
                {
                }
            }

            if (this._trainingTimer != null)
            {
                if (this._trainingTimer.GetRemainingSeconds(this._parent.GetLevel().GetLogicTime()) <= 0)
                {
                    if (this._unit != null)
                    {
                        this.TrainingFinished();
                    }
                }
            }
        }
コード例 #23
0
        /// <summary>
        ///     Executes this command.
        /// </summary>
        public override int Execute(LogicLevel level)
        {
            LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this._gameObjectId);

            if (gameObject != null)
            {
                if (gameObject.GetGameObjectType() == 0)
                {
                    LogicBuilding     building     = (LogicBuilding)gameObject;
                    LogicBuildingData buildingData = building.GetBuildingData();

                    if (buildingData.IsTownHallVillage2())
                    {
                        if (!this.UnlockVillage2())
                        {
                            return(-76);
                        }
                    }

                    if (buildingData.GetVillageType() == level.GetVillageType())
                    {
                        if (building.GetWallIndex() == 0)
                        {
                            if (building.CanUpgrade(true))
                            {
                                int nextUpgradeLevel = building.GetUpgradeLevel() + 1;
                                int buildCost        = buildingData.GetBuildCost(nextUpgradeLevel, level);

                                LogicResourceData buildResourceData = this._useAltResources ? buildingData.GetAltBuildResource(nextUpgradeLevel) : buildingData.GetBuildResource(nextUpgradeLevel);

                                if (buildResourceData != null)
                                {
                                    LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

                                    if (playerAvatar.HasEnoughResources(buildResourceData, buildCost, true, this, false))
                                    {
                                        int constructionTime = buildingData.GetConstructionTime(nextUpgradeLevel, level, 0);

                                        if (constructionTime != 0 || LogicDataTables.GetGlobals().WorkerForZeroBuilTime())
                                        {
                                            if (!level.HasFreeWorkers(this, -1))
                                            {
                                                return(-1);
                                            }
                                        }

                                        playerAvatar.CommodityCountChangeHelper(0, buildResourceData, -buildCost);
                                        building.StartUpgrading(true, false);

                                        return(0);
                                    }
                                }
                            }

                            return(-1);
                        }

                        return(-35);
                    }

                    return(-32);
                }
                else if (gameObject.GetGameObjectType() == 4)
                {
                    LogicTrap trap = (LogicTrap)gameObject;

                    if (trap.CanUpgrade(true))
                    {
                        LogicTrapData     data = trap.GetTrapData();
                        LogicResourceData buildResourceData = data.GetBuildResource();
                        LogicClientAvatar playerAvatar      = level.GetPlayerAvatar();

                        int buildCost = data.GetBuildCost(trap.GetUpgradeLevel() + 1);

                        if (playerAvatar.HasEnoughResources(buildResourceData, buildCost, true, this, false))
                        {
                            int constructionTime = data.GetBuildTime(trap.GetUpgradeLevel() + 1);

                            if (constructionTime != 0 || LogicDataTables.GetGlobals().WorkerForZeroBuilTime())
                            {
                                if (!level.HasFreeWorkers(this, -1))
                                {
                                    return(-1);
                                }

                                playerAvatar.CommodityCountChangeHelper(0, buildResourceData, -buildCost);
                                trap.StartUpgrading();

                                return(0);
                            }
                        }
                    }
                }
                else if (gameObject.GetGameObjectType() == 8)
                {
                    if (!this._useAltResources)
                    {
                        LogicVillageObject villageObject = (LogicVillageObject)gameObject;
                        // TODO: Implement upgrade vObjs.
                    }

                    return(-31);
                }
            }

            return(-1);
        }
        public override int Execute(LogicLevel level)
        {
            if (this.m_gameObjectIds.Size() > 0)
            {
                LogicResourceData buildResourceData = null;
                int buildCost = 0;

                for (int i = 0; i < this.m_gameObjectIds.Size(); i++)
                {
                    LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObjectIds[i]);

                    if (gameObject != null && gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING)
                    {
                        LogicBuilding     building     = (LogicBuilding)gameObject;
                        LogicBuildingData buildingData = building.GetBuildingData();

                        if (buildingData.IsTownHallVillage2())
                        {
                            return(-76);
                        }

                        int nextUpgradeLevel = building.GetUpgradeLevel() + 1;

                        if (building.CanUpgrade(false) && buildingData.GetUpgradeLevelCount() > nextUpgradeLevel && buildingData.GetAmountCanBeUpgraded(nextUpgradeLevel) == 0)
                        {
                            buildResourceData = buildingData.GetBuildResource(nextUpgradeLevel);

                            if (this.m_useAltResource)
                            {
                                buildResourceData = buildingData.GetAltBuildResource(nextUpgradeLevel);
                            }

                            buildCost += buildingData.GetBuildCost(nextUpgradeLevel, level);
                        }
                    }
                }

                if (buildResourceData != null)
                {
                    LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

                    if (playerAvatar.HasEnoughResources(buildResourceData, buildCost, true, this, false))
                    {
                        if (level.HasFreeWorkers(this, -1))
                        {
                            bool updateListener = true;

                            for (int i = 0; i < this.m_gameObjectIds.Size(); i++)
                            {
                                LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObjectIds[i]);

                                if (gameObject != null && gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING)
                                {
                                    LogicBuilding     building     = (LogicBuilding)gameObject;
                                    LogicBuildingData buildingData = building.GetBuildingData();

                                    int nextUpgradeLevel = building.GetUpgradeLevel() + 1;

                                    if (building.CanUpgrade(false) && buildingData.GetUpgradeLevelCount() > nextUpgradeLevel &&
                                        buildingData.GetAmountCanBeUpgraded(nextUpgradeLevel) == 0)
                                    {
                                        if (this.m_gameObjectIds.Size() > 6)
                                        {
                                            updateListener = (building.GetTileX() + building.GetTileY()) % (this.m_gameObjectIds.Size() / 4) == 0;
                                        }

                                        building.StartUpgrading(updateListener, false);
                                    }
                                }
                            }

                            playerAvatar.CommodityCountChangeHelper(0, buildResourceData, -buildCost);

                            return(0);
                        }
                    }
                }
            }

            return(-2);
        }
コード例 #25
0
        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);
                }
            }
        }
コード例 #26
0
 public LogicVillage2UnitComponent(LogicGameObject gameObject) : base(gameObject)
 {
 }
コード例 #27
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="LogicBunkerComponent" /> class.
 /// </summary>
 public LogicBunkerComponent(LogicGameObject gameObject, int capacity) : base(gameObject, capacity)
 {
     // LogicBunkerComponent.
 }
コード例 #28
0
        public static void SetBuildingUpgradeLevel(LogicLevel level, int gameObjectId, int upgLevel, int villageType)
        {
            LogicGameObject gameObject = level.GetGameObjectManagerAt(villageType).GetGameObjectByID(gameObjectId);

            if (gameObject != null)
            {
                if (gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING)
                {
                    LogicBuilding     building     = (LogicBuilding)gameObject;
                    LogicBuildingData buildingData = building.GetBuildingData();

                    if (building.GetGearLevel() > 0 || building.IsGearing())
                    {
                        if (buildingData.GetMinUpgradeLevelForGearUp() > upgLevel)
                        {
                            Debugger.HudPrint("Can't downgrade geared up building below gear up limit!");
                            upgLevel = buildingData.GetMinUpgradeLevelForGearUp();
                        }
                    }

                    if (buildingData.IsTownHall())
                    {
                        level.GetPlayerAvatar().SetTownHallLevel(upgLevel);
                    }

                    building.SetUpgradeLevel(LogicMath.Max(upgLevel - 1, 0));
                    building.FinishConstruction(false, true);
                    building.SetUpgradeLevel(upgLevel);

                    if (building.GetListener() != null)
                    {
                        building.GetListener().RefreshState();
                    }
                    if (buildingData.IsTownHall() || buildingData.IsTownHallVillage2())
                    {
                        level.RefreshNewShopUnlocks(buildingData.GetVillageType());
                    }
                }
                else if (gameObject.GetGameObjectType() == LogicGameObjectType.TRAP)
                {
                    LogicTrap trap = (LogicTrap)gameObject;

                    trap.SetUpgradeLevel(LogicMath.Max(upgLevel - 1, 0));
                    trap.FinishConstruction(false);
                    trap.SetUpgradeLevel(upgLevel);
                    trap.RepairTrap();

                    if (trap.GetListener() != null)
                    {
                        trap.GetListener().RefreshState();
                    }
                }
                else if (gameObject.GetGameObjectType() == LogicGameObjectType.VILLAGE_OBJECT)
                {
                    LogicVillageObject villageObject = (LogicVillageObject)gameObject;

                    villageObject.SetUpgradeLevel(LogicMath.Max(upgLevel - 1, 0));
                    villageObject.SetUpgradeLevel(upgLevel);

                    if (villageObject.GetListener() != null)
                    {
                        villageObject.GetListener().RefreshState();
                    }
                }
            }
        }
コード例 #29
0
 public LogicUnitUpgradeComponent(LogicGameObject gameObject) : base(gameObject)
 {
     // LogicUnitUpgradeComponent.
 }
コード例 #30
0
 /// <summary>
 ///     Called when the specified <see cref="LogicGameObject"/> has been removed to <see cref="LogicGameObjectManager"/> instance.
 /// </summary>
 public virtual void RemoveGameObject(LogicGameObject gameObject)
 {
     // RemoveGameObject.
 }