コード例 #1
0
        public static void LoadDebugJSONArray(LogicLevel level, LogicJSONArray jsonArray, LogicGameObjectType gameObjectType, int villageType)
        {
            if (jsonArray != null)
            {
                LogicGameObjectManager           gameObjectManager = level.GetGameObjectManagerAt(villageType);
                LogicArrayList <LogicGameObject> prevGameObjects   = new LogicArrayList <LogicGameObject>();

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

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

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

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

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

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

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

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

                            if (lvlNumber != null)
                            {
                                LogicDebugUtil.SetBuildingUpgradeLevel(level, gameObject.GetGlobalID(), lvlNumber.GetIntValue(), villageType);
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
        public LogicCharacter ClosestAttacker(bool flyingTroop)
        {
            LogicGameObjectManager           gameObjectManager = this.m_parent.GetLevel().GetGameObjectManagerAt(0);
            LogicArrayList <LogicGameObject> gameObjects       = gameObjectManager.GetGameObjects(LogicGameObjectType.CHARACTER);

            int            closestDistance  = 0x7fffffff;
            LogicCharacter closestCharacter = null;

            for (int i = 0; i < gameObjects.Size(); i++)
            {
                LogicCharacter         character         = (LogicCharacter)gameObjects[i];
                LogicHitpointComponent hitpointComponent = character.GetHitpointComponent();
                LogicCombatComponent   combatComponent   = character.GetCombatComponent();

                bool deployTime = combatComponent != null && combatComponent.GetUndergroundTime() > 0;

                if (!deployTime && (LogicDataTables.GetGlobals().SkeletonOpenClanCastle() || !LogicDataTables.IsSkeleton(character.GetCharacterData())))
                {
                    if (hitpointComponent != null)
                    {
                        if (character.IsAlive() && character.IsFlying() == flyingTroop && hitpointComponent.GetTeam() == 0)
                        {
                            int distance = character.GetPosition().GetDistanceSquaredTo(this.m_parent.GetMidX(), this.m_parent.GetMidY());

                            if (distance < closestDistance)
                            {
                                closestDistance  = distance;
                                closestCharacter = character;
                            }
                        }
                    }
                }
            }

            return(closestCharacter);
        }
コード例 #3
0
ファイル: LogicMission.cs プロジェクト: NotHuza/Cerberus-v4
        /// <summary>
        ///     Refreshes the mission progress.
        /// </summary>
        public void RefreshProgress()
        {
            LogicGameObjectManager gameObjectManager = this._level.GetGameObjectManager();

            switch (this._data.GetMissionType())
            {
            case 0:
            case 5:
                this._progress = 0;

                if (this._level.GetState() == 1)
                {
                    LogicArrayList <LogicGameObject> gameObjects = gameObjectManager.GetGameObjects(0);

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

                        if (building.GetBuildingData() == this._data.GetBuildBuildingData())
                        {
                            if (!building.IsConstructing() || building.IsUpgrading())
                            {
                                if (building.GetUpgradeLevel() >= this._data.GetBuildBuildingLevel())
                                {
                                    ++this._progress;
                                }
                            }
                        }
                    }
                }

                break;

            case 4:
                this._progress = this._level.GetPlayerAvatar().GetUnitsTotalCapacity();
                break;

            case 6:
                this._progress = this._level.GetPlayerAvatar().GetNameSetByUser() ? 1 : 0;
                break;

            case 13:
                this._progress = 0;

                if (this._level.GetState() == 1)
                {
                    LogicArrayList <LogicGameObject> gameObjects = gameObjectManager.GetGameObjects(8);

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

                        if (villageObject.GetVillageObjectData() == this._data.GetFixVillageObjectData() &&
                            villageObject.GetUpgradeLevel() >= this._data.GetBuildBuildingLevel())
                        {
                            ++this._progress;
                        }
                    }
                }

                break;

            case 14:
                this._progress = 0;

                if (this._level.GetState() == 1 && this._level.GetVillageType() == 1)
                {
                    ++this._progress;
                }

                break;

            case 15:
                this._progress = 0;

                if (this._level.GetState() == 1)
                {
                    LogicArrayList <LogicGameObject> gameObjects = gameObjectManager.GetGameObjects(0);

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

                        if (building.GetBuildingData() == this._data.GetBuildBuildingData())
                        {
                            if (!building.IsLocked())
                            {
                                ++this._progress;
                            }
                        }
                    }
                }

                break;

            case 17:
                this._progress = 0;

                if (this._level.GetState() == 1 && this._level.GetVillageType() == 1)
                {
                    if (this._level.GetPlayerAvatar().GetUnitUpgradeLevel(this._data.GetCharacterData()) > 0)
                    {
                        ++this._progress;
                    }
                }

                break;
            }

            if (this._progress >= this._requireProgress)
            {
                this._progress = this._requireProgress;
                this.Finished();
            }
        }
コード例 #4
0
        public override int Execute(LogicLevel level)
        {
            if (this.m_layoutId != -1)
            {
                if (level.GetTownHallLevel(level.GetVillageType()) >= level.GetRequiredTownHallLevelForLayout(this.m_layoutId, -1))
                {
                    if ((this.m_layoutId & 0xFFFFFFFE) != 6)
                    {
                        if (this.m_layoutType != 0)
                        {
                            if (this.m_layoutId != 1 && this.m_layoutId != 4 && this.m_layoutId != 5)
                            {
                                return(-5);
                            }
                        }
                        else
                        {
                            if (this.m_layoutId != 0 && this.m_layoutId != 2 && this.m_layoutId != 3)
                            {
                                return(-4);
                            }
                        }
                    }

                    LogicGameObjectFilter            filter      = new LogicGameObjectFilter();
                    LogicArrayList <LogicGameObject> gameObjects = new LogicArrayList <LogicGameObject>(500);

                    filter.AddGameObjectType(LogicGameObjectType.BUILDING);
                    filter.AddGameObjectType(LogicGameObjectType.TRAP);
                    filter.AddGameObjectType(LogicGameObjectType.DECO);

                    level.GetGameObjectManager().GetGameObjects(gameObjects, filter);

                    for (int i = 0; i < gameObjects.Size(); i++)
                    {
                        LogicGameObject gameObject = gameObjects[i];
                        LogicVector2    position   = gameObject.GetPositionLayout(this.m_layoutId, false);

                        if ((this.m_layoutId & 0xFFFFFFFE) != 6 && (position.m_x == -1 || position.m_y == -1))
                        {
                            return(-2);
                        }
                    }

                    LogicGameObjectManager           gameObjectManager = level.GetGameObjectManager();
                    LogicArrayList <LogicGameObject> buildings         = gameObjectManager.GetGameObjects(LogicGameObjectType.BUILDING);
                    LogicArrayList <LogicGameObject> obstacles         = gameObjectManager.GetGameObjects(LogicGameObjectType.OBSTACLE);

                    for (int i = 0; i < gameObjects.Size(); i++)
                    {
                        LogicGameObject gameObject = gameObjects[i];
                        LogicVector2    position   = gameObject.GetPositionLayout(this.m_layoutId, false);

                        int minX = position.m_x;
                        int minY = position.m_y;
                        int maxX = minX + gameObject.GetWidthInTiles();
                        int maxY = minY + gameObject.GetHeightInTiles();

                        for (int j = 0; j < obstacles.Size(); j++)
                        {
                            LogicObstacle obstacle = (LogicObstacle)obstacles[j];

                            int minX2 = obstacle.GetTileX();
                            int minY2 = obstacle.GetTileY();
                            int maxX2 = minX2 + obstacle.GetWidthInTiles();
                            int maxY2 = minY2 + obstacle.GetHeightInTiles();

                            if (maxX > minX2 && maxY > minY2 && minX < maxX2 && minY < maxY2)
                            {
                                if ((this.m_layoutId & 0xFFFFFFFE) != 6)
                                {
                                    return(-2);
                                }

                                gameObjectManager.RemoveGameObject(obstacle);
                                j -= 1;
                            }
                        }
                    }

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

                        if (baseWallBlock.GetWallIndex() != 0)
                        {
                            int x             = baseWallBlock.GetTileX();
                            int y             = baseWallBlock.GetTileY();
                            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;

                            for (int j = 0; j < buildings.Size(); j++)
                            {
                                LogicBuilding wallBlock = (LogicBuilding)buildings[j];

                                if (wallBlock.GetWallIndex() == baseWallBlock.GetWallIndex())
                                {
                                    int tmp1 = x - wallBlock.GetTileX();
                                    int tmp2 = y - wallBlock.GetTileY();

                                    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)
                            {
                                return(-24);
                            }

                            int wallBlockSizeX = maxWallBlockX - minWallBlockX;
                            int wallBlockSizeY = maxWallBlockY - minWallBlockY;
                            int lengthX        = maxX - minX;
                            int lengthY        = maxY - minY;

                            if (wallBlockSizeX != lengthX || wallBlockSizeY != lengthY)
                            {
                                if (wallBlockSizeX != lengthX != (wallBlockSizeY != lengthY))
                                {
                                    return(-25);
                                }
                            }
                        }
                    }

                    if (this.m_layoutType != 0)
                    {
                        if (level.IsWarBase())
                        {
                            level.SetWarBase(true);
                        }

                        level.SetActiveWarLayout(this.m_layoutId);
                    }
                    else
                    {
                        level.SetActiveLayout(this.m_layoutId, level.GetVillageType());

                        for (int i = 0; i < gameObjects.Size(); i++)
                        {
                            LogicGameObject gameObject = gameObjects[i];
                            LogicVector2    position   = gameObject.GetPositionLayout(this.m_layoutId, false);

                            gameObject.SetPositionXY(position.m_x << 9, position.m_y << 9);
                        }
                    }

                    return(0);
                }
            }

            return(-10);
        }
コード例 #5
0
        private void SimulateEndAttackState()
        {
            LogicLevel                       level              = this.m_logicGameMode.GetLevel();
            LogicGameObjectManager           gameObjectManager  = level.GetGameObjectManager();
            LogicArrayList <LogicGameObject> characterList      = gameObjectManager.GetGameObjects(LogicGameObjectType.CHARACTER);
            LogicArrayList <LogicGameObject> projectileList     = gameObjectManager.GetGameObjects(LogicGameObjectType.PROJECTILE);
            LogicArrayList <LogicGameObject> spellList          = gameObjectManager.GetGameObjects(LogicGameObjectType.SPELL);
            LogicArrayList <LogicGameObject> alliancePortalList = gameObjectManager.GetGameObjects(LogicGameObjectType.ALLIANCE_PORTAL);

            this.m_logicWatch.Start();

            while (!this.m_logicGameMode.IsBattleOver())
            {
                bool canStopBattle = !this.m_logicGameMode.GetConfiguration().GetBattleWaitForProjectileDestruction() || projectileList.Size() == 0;

                for (int i = 0; i < characterList.Size(); i++)
                {
                    LogicCharacter         character         = (LogicCharacter)characterList[i];
                    LogicHitpointComponent hitpointComponent = character.GetHitpointComponent();

                    if (hitpointComponent != null && hitpointComponent.GetTeam() == 0)
                    {
                        LogicAttackerItemData data = character.GetAttackerItemData();

                        if (data.GetDamage(0, false) > 0 &&
                            (hitpointComponent.GetHitpoints() > 0 || this.m_logicGameMode.GetConfiguration().GetBattleWaitForDieDamage() && character.GetWaitDieDamage()))
                        {
                            canStopBattle = false;
                        }
                    }
                }

                for (int i = 0; i < spellList.Size(); i++)
                {
                    LogicSpell spell = (LogicSpell)spellList[i];

                    if (!spell.GetHitsCompleted() && (spell.GetSpellData().IsDamageSpell() || spell.GetSpellData().GetSummonTroop() != null))
                    {
                        canStopBattle = false;
                    }
                }

                for (int i = 0; i < alliancePortalList.Size(); i++)
                {
                    LogicAlliancePortal alliancePortal = (LogicAlliancePortal)alliancePortalList[i];

                    if (alliancePortal.GetBunkerComponent().GetTeam() == 0 && !alliancePortal.GetBunkerComponent().IsEmpty())
                    {
                        canStopBattle = false;
                    }
                }

                bool isEnded = canStopBattle || this.m_logicWatch.ElapsedMilliseconds >= 10000;

                if (isEnded)
                {
                    LogicEndCombatCommand logicEndCombatCommand = new LogicEndCombatCommand();
                    logicEndCombatCommand.SetExecuteSubTick(this.m_logicGameMode.GetLevel().GetLogicTime().GetTick());
                    this.m_logicGameMode.GetCommandManager().AddCommand(logicEndCombatCommand);
                }

                this.m_logicGameMode.UpdateOneSubTick();

                if (isEnded)
                {
                    break;
                }
            }

            this.m_logicWatch.Reset();

            if (!this.m_logicGameMode.IsBattleOver())
            {
                this.m_logicGameMode.SetBattleOver();
            }
            if (this.m_liveReplayId != null)
            {
                this.UpdateLiveReplay(this.m_logicGameMode.GetLevel().GetLogicTime().GetTick(), null);
            }
        }