public virtual void Destruct()
        {
            if (this.m_level != null)
            {
                this.m_level.GetTileMap().RemoveGameObject(this);
            }

            for (int i = 0; i < LogicComponent.COMPONENT_TYPE_COUNT; i++)
            {
                if (this.m_components[i] != null)
                {
                    this.m_components[i].Destruct();
                    this.m_components[i] = null;
                }
            }

            if (this.m_position != null)
            {
                this.m_position.Destruct();
                this.m_position = null;
            }

            if (this.m_listener != null)
            {
                this.m_listener.Destruct();
                this.m_listener = null;
            }
        }
Exemple #2
0
        /// <summary>
        ///     Destructs this instance.
        /// </summary>
        public virtual void Destruct()
        {
            this._level.GetTileMap().RemoveGameObject(this);

            for (int i = 0; i < this._components.Count; i++)
            {
                if (this._components[i] != null)
                {
                    this._components[i].Destruct();
                    this._components[i].RemoveGameObjectReferences(this);
                }
            }

            if (this._position != null)
            {
                this._position.Destruct();
                this._position = null;
            }

            if (this._listener != null)
            {
                this._listener.Destruct();
                this._listener = null;
            }

            this._data  = null;
            this._level = null;
        }
Exemple #3
0
        public int GetShockwaveArcLength()
        {
            LogicVector2 pos = new LogicVector2(this.GetMidX() - (this.m_targetPosition.m_x >> 3), this.GetMidY() - (this.m_targetPosition.m_y >> 3));

            int length          = pos.GetLength();
            int shockwaveLength = this.m_maxAttackRange - length;

            if (shockwaveLength >= this.m_minAttackRange)
            {
                int arcLength         = (this.m_shockwaveArcLength << 9) / 100;
                int expandedArcLength = LogicMath.Clamp(shockwaveLength * arcLength / ((this.m_shockwaveExpandRadius << 9) / 100), 0, arcLength);

                if (expandedArcLength < 0)
                {
                    expandedArcLength = arcLength;
                }

                if (expandedArcLength > arcLength)
                {
                    expandedArcLength = arcLength;
                }

                int calculateArcLength = 18000 * expandedArcLength / (314 * shockwaveLength);

                if (calculateArcLength < 180)
                {
                    return(calculateArcLength);
                }

                return(180);
            }

            return(0);
        }
Exemple #4
0
        public override void Save(LogicJSONObject jsonObject, int villageType)
        {
            LogicLevel level = this.m_parent.GetLevel();

            int activeLayout = this.m_parent.GetLevel().GetActiveLayout(villageType);

            for (int i = 0; i < 8; i++)
            {
                LogicVector2 pos = this.m_editModeLayoutPosition[i];

                if (pos.m_x != -1 && pos.m_y != -1)
                {
                    if (level.GetLayoutState(i, villageType) == 1)
                    {
                        jsonObject.Put(this.GetLayoutVariableNameX(i, true), new LogicJSONNumber(pos.m_x));
                        jsonObject.Put(this.GetLayoutVariableNameY(i, true), new LogicJSONNumber(pos.m_y));
                    }
                }
            }

            for (int i = 0; i < 8; i++)
            {
                if (i != activeLayout)
                {
                    LogicVector2 pos = this.m_layoutPosition[i];

                    if (pos.m_x != -1 && pos.m_y != -1)
                    {
                        jsonObject.Put(this.GetLayoutVariableNameX(i, false), new LogicJSONNumber(pos.m_x));
                        jsonObject.Put(this.GetLayoutVariableNameY(i, false), new LogicJSONNumber(pos.m_y));
                    }
                }
            }
        }
Exemple #5
0
        public LogicPathFinderNew(LogicTileMap tileMap) : base(tileMap)
        {
            this.m_pathStartX = -1;
            this.m_pathStartY = -1;

            if (tileMap != null)
            {
                this.m_mapWidth  = tileMap.GetSizeX();
                this.m_mapHeight = tileMap.GetSizeY();
            }
            else
            {
                this.m_mapWidth  = 3;
                this.m_mapHeight = 4;
            }

            this.m_savedPaths = new LogicSavedPath[LogicPathFinderNew.SAVED_PATHS];

            for (int i = 0, j = this.m_mapWidth * 4; i < LogicPathFinderNew.SAVED_PATHS; i++)
            {
                this.m_savedPaths[i] = new LogicSavedPath(j);
            }

            int size = 4 * this.m_mapWidth * this.m_mapHeight;

            this.m_pathState    = new int[size];
            this.m_heapBuffer   = new int[size];
            this.m_parentBuffer = new int[size];
            this.m_pathBuffer   = new int[size];
            this.m_pathCost     = new int[size];

            this.m_pathPointOutput = new LogicVector2();

            this.ResetCostStrategyToDefault();
        }
Exemple #6
0
        public override void GetPathPointSubTile(LogicVector2 position, int idx)
        {
            if ((uint)idx >= this.m_pathLength)
            {
                Debugger.Error("illegal path index");
            }

            LogicTile tile = this.m_tileMap.GetTile(position.m_x, position.m_y);

            position.m_x *= 2;
            position.m_y *= 2;

            if (tile.IsPassablePathFinder(3))
            {
                if (tile.IsPassablePathFinder(2))
                {
                    if (tile.IsPassablePathFinder(1))
                    {
                        ++position.m_x;
                    }
                }

                ++position.m_y;
            }
        }
        public void AddDefendingHero()
        {
            LogicAvatar visitorAvatar   = this.m_parent.GetLevel().GetVisitorAvatar();
            LogicAvatar homeOwnerAvatar = this.m_parent.GetLevel().GetHomeOwnerAvatar();

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

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

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

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

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

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

                if (LogicDataTables.GetGlobals().EnableDefendingAllianceTroopJump())
                {
                    hero.GetMovementComponent().EnableJump(3600000);
                }
            }
        }
Exemple #8
0
        public void CheckWall(LogicVector2 position)
        {
            if (this.m_parent != null)
            {
                LogicGameObject gameObject = this.m_parent.GetParent();
                LogicTile       tile       = gameObject.GetLevel().GetTileMap().GetTile(position.m_x >> 9, position.m_y >> 9);

                if (tile != null)
                {
                    for (int i = 0; i < tile.GetGameObjectCount(); i++)
                    {
                        LogicGameObject go = tile.GetGameObject(i);

                        if (go.IsWall() &&
                            go.IsAlive())
                        {
                            this.m_wall = go;

                            if (((LogicBuilding)go).GetHitWallDelay() <= 0)
                            {
                                ++this.m_wallCount;
                            }
                        }
                    }
                }
            }
        }
        public static bool FindPoint(LogicTileMap tileMap, LogicVector2 pos1, LogicVector2 pos2, LogicVector2 pos3, LogicVector2 pos4)
        {
            pos1.Set(pos2.m_x, pos2.m_y);
            pos1.Substract(pos3);

            int length = pos1.GetLength();

            pos1.m_x = (pos1.m_x << 7) / length;
            pos1.m_y = (pos1.m_y << 7) / length;

            pos4.Set(pos3.m_x, pos3.m_y);

            int radius = LogicMath.Clamp(length / 128, 10, 25);

            for (int i = 0; i < radius; i++)
            {
                if (tileMap.IsPassablePathFinder(pos4.m_x >> 8, pos4.m_y >> 8))
                {
                    pos4.m_x = (int)((pos4.m_x & 0xFFFFFF00) | 128);
                    pos4.m_y = (int)((pos4.m_y & 0xFFFFFF00) | 128);

                    return(true);
                }

                pos4.Add(pos1);
            }

            return(false);
        }
Exemple #10
0
        public int GetSpeed()
        {
            LogicProjectileData projectileData = this.GetProjectileData();

            if (projectileData.GetFixedTravelTime() != 0)
            {
                LogicVector2 position = new LogicVector2();

                position.m_x = (this.m_targetPosition.m_x - this.m_unk276.m_x) >> 3;
                position.m_y = (this.m_targetPosition.m_y - this.m_unk276.m_y) >> 3;

                int remMS = projectileData.GetFixedTravelTime() - this.m_travelTime;
                int speed = position.GetLength();

                if (remMS <= 0)
                {
                    remMS = 1000;
                    speed = projectileData.GetSpeed();
                }

                return(16 * speed / remMS);
            }

            return((int)(16L * projectileData.GetSpeed() / 1000L));
        }
Exemple #11
0
        public override void SubTick()
        {
            base.SubTick();

            LogicCombatComponent   combatComponent   = this.GetCombatComponent();
            LogicMovementComponent movementComponent = this.GetMovementComponent();

            if (combatComponent != null)
            {
                combatComponent.SubTick();
            }

            if (movementComponent != null)
            {
                movementComponent.SubTick();

                LogicMovementSystem movementSystem   = movementComponent.GetMovementSystem();
                LogicVector2        movementPosition = movementSystem.GetPosition();

                this.SetPositionXY(movementPosition.m_x, movementPosition.m_y);
            }
            else if (this.m_troopChild)
            {
                LogicVector2 tmp = new LogicVector2(this.m_troopChildX, this.m_troopChildY);

                tmp.Rotate(this.m_parent.GetDirection());

                LogicMovementSystem movementSystem = this.m_parent.GetMovementComponent().GetMovementSystem();
                LogicVector2        position       = movementSystem.GetPosition();

                this.SetPositionXY(tmp.m_x + position.m_x, tmp.m_y + position.m_y);
            }

            if (this.m_childrens != null)
            {
                for (int i = 0; i < this.m_childrens.Size(); i++)
                {
                    this.m_childrens[i].SubTick();
                }
            }

            int distanceX = this.GetX() + (this.GetWidthInTiles() << 8);
            int distanceY = this.GetY() + (this.GetHeightInTiles() << 8);

            if (this.m_auraSpell != null)
            {
                this.m_auraSpell.SetPositionXY(distanceX, distanceY);
            }

            if (this.m_abilitySpell != null)
            {
                this.m_abilitySpell.SetPositionXY(distanceX, distanceY);
            }

            if (this.m_retributionSpell != null)
            {
                this.m_retributionSpell.SetPositionXY(distanceX, distanceY);
            }
        }
Exemple #12
0
 public LogicSpell(LogicGameObjectData data, LogicLevel level, int villageType) : base(data, level, villageType)
 {
     this.m_allowDestruction      = true;
     this.m_randomOffset          = new LogicVector2();
     this.m_duplicateHousingSpace = -1;
     this.m_playEffectOffsetX     = 100;
     this.m_playEffectOffsetY     = 100;
 }
        public void CreateProjectile(LogicProjectileData data)
        {
            LogicTrapData trapData = this.GetTrapData();

            LogicVector2 position = new LogicVector2();
            LogicArrayList <LogicGameObject> characters = this.GetGameObjectManager().GetGameObjects(LogicGameObjectType.CHARACTER);

            LogicGameObject closestGameObject = null;

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

                if (hitpointComponent != null && hitpointComponent.GetTeam() == 0)
                {
                    if (character.IsFlying() && character.IsAlive())
                    {
                        int housingSpace = character.GetCharacterData().GetHousingSpace();

                        if (housingSpace >= trapData.GetMinTriggerHousingLimit() && character.GetChildTroops() == null)
                        {
                            if (trapData.GetHealerTrigger() || character.GetCombatComponent() == null || !character.GetCombatComponent().IsHealer())
                            {
                                position.m_x = character.GetPosition().m_x - this.GetMidX();
                                position.m_y = character.GetPosition().m_y - this.GetMidY();

                                int lengthSquared = position.GetLengthSquared();

                                if (minDistance == 0 || lengthSquared < minDistance)
                                {
                                    minDistance       = lengthSquared;
                                    closestGameObject = character;
                                }
                            }
                        }
                    }
                }
            }

            position.Destruct();

            if (closestGameObject != null)
            {
                LogicProjectile projectile = (LogicProjectile)LogicGameObjectFactory.CreateGameObject(data, this.m_level, this.m_villageType);

                projectile.SetInitialPosition(null, this.GetMidX(), this.GetMidY());
                projectile.SetTarget(this.GetMidX(), this.GetMidY(), 0, closestGameObject, data.GetRandomHitPosition());
                projectile.SetDamage(trapData.GetDamage(this.m_upgLevel));
                projectile.SetDamageRadius(trapData.GetDamageRadius(this.m_upgLevel));
                projectile.SetPushBack(trapData.GetPushback(), !trapData.GetDoNotScalePushByDamage());
                projectile.SetMyTeam(1);
                projectile.SetHitEffect(trapData.GetDamageEffect(), null);

                this.GetGameObjectManager().AddGameObject(projectile, -1);
            }
        }
Exemple #14
0
        public void CalculateDirection(LogicVector2 pos)
        {
            LogicVector2 nextPath = this.m_path[this.m_path.Size() - 1];

            pos.m_x = nextPath.m_x - this.m_position.m_x;
            pos.m_y = nextPath.m_y - this.m_position.m_y;

            this.m_direction = pos.GetAngle();
        }
        public override void GetPathPoint(LogicVector2 position, int idx)
        {
            if (idx < 0 || this.m_pathLength <= idx)
            {
                Debugger.Error("illegal path index");
            }

            position.m_x = this.m_pathBuffer[idx] % this.m_mapWidth;
            position.m_y = this.m_pathBuffer[idx] / this.m_mapWidth;
        }
Exemple #16
0
        public void SetTarget(int x, int y, int randomHitRange, LogicGameObject target, bool randomHitPosition)
        {
            this.m_target             = target;
            this.m_targetPosition.m_x = target.GetMidX() * 8;
            this.m_targetPosition.m_y = target.GetMidY() * 8;

            if (target.GetGameObjectType() == LogicGameObjectType.CHARACTER)
            {
                LogicCharacter character = (LogicCharacter)target;

                if (character.IsFlying())
                {
                    LogicCombatComponent combatComponent = target.GetCombatComponent();

                    this.m_randomHitRange = combatComponent != null && combatComponent.IsHealer() ? 200 : 1000;
                    this.m_flyingTarget   = true;
                }

                if (randomHitPosition)
                {
                    LogicVector2 pos = new LogicVector2(this.m_targetPosition.m_x >> 3, this.m_targetPosition.m_y >> 3);

                    int distance = pos.GetDistance(this.GetPosition());

                    this.m_unk168.m_x = this.m_targetPosition.m_x - 8 * this.GetMidX();
                    this.m_unk168.m_y = this.m_targetPosition.m_y - 8 * this.GetMidY();

                    this.m_unk168.Rotate(90);
                    this.m_unk168.Normalize(64);

                    int rnd = ((distance / 10) & this.Rand(randomHitRange)) - distance / 20;

                    this.m_unk168.m_x = this.m_unk168.m_x * rnd / 64;
                    this.m_unk168.m_y = this.m_unk168.m_y * rnd / 64;

                    pos.Destruct();
                }
            }
            else
            {
                int range = target.IsWall() ? 1016 : 2040;

                this.m_unk168.m_x = 8 * x - this.m_targetPosition.m_x;
                this.m_unk168.m_y = 8 * y - this.m_targetPosition.m_y;

                this.m_unk168.Normalize(((target.GetWidthInTiles() - target.PassableSubtilesAtEdge()) << 12) / 3);

                this.m_unk168.m_x += (range & this.Rand(randomHitRange)) * (2 * (this.Rand(randomHitRange + 1) & 1) - 1);
                this.m_unk168.m_y += (range & this.Rand(randomHitRange + 2)) * (2 * (this.Rand(randomHitRange + 3) & 1) - 1);

                this.m_targetPosition.Add(this.m_unk168);

                this.m_randomHitRange = 150;
            }
        }
        public LogicGameObject(LogicGameObjectData data, LogicLevel level, int villageType)
        {
            Debugger.DoAssert(villageType < 2, "VillageType not set! Game object has not been added to LogicGameObjectManager.");

            this.m_data        = data;
            this.m_level       = level;
            this.m_villageType = villageType;

            this.m_position   = new LogicVector2();
            this.m_listener   = new LogicGameObjectListener();
            this.m_components = new LogicComponent[LogicComponent.COMPONENT_TYPE_COUNT];
        }
Exemple #18
0
        public void SetBouncePosition(LogicVector2 pos)
        {
            this.m_bounceProjectile = true;

            for (int i = 0; i < this.m_bouncePositions.Length; i++)
            {
                if (this.m_bouncePositions[i] == null)
                {
                    this.m_bouncePositions[i] = pos;
                    break;
                }
            }
        }
        public LogicArrayList <LogicVector2> CreatePatrolPath()
        {
            int parentWidth  = this.m_parent.GetWidthInTiles() << 8;
            int parentHeight = this.m_parent.GetHeightInTiles() << 8;
            int patrolRadius = this.m_hero.GetPatrolRadius();

            if (patrolRadius * patrolRadius >= parentWidth * parentWidth + parentHeight * parentHeight)
            {
                LogicVector2 tmp1 = new LogicVector2();
                LogicVector2 tmp2 = new LogicVector2();
                LogicVector2 tmp3 = new LogicVector2();
                LogicVector2 tmp4 = new LogicVector2();

                int parentMidX = this.m_parent.GetMidX();
                int parentMidY = this.m_parent.GetMidY();

                tmp2.Set(parentMidX, parentMidY);

                LogicArrayList <LogicVector2> wayPoints = new LogicArrayList <LogicVector2>(LogicHeroBaseComponent.PATROL_PATHS);

                for (int i = 0, j = 22; i < LogicHeroBaseComponent.PATROL_PATHS; i++, j += 45)
                {
                    tmp1.Set(parentMidX + LogicMath.Cos(j, patrolRadius), parentMidY + LogicMath.Sin(j, patrolRadius));
                    LogicHeroBaseComponent.FindPoint(this.m_parent.GetLevel().GetTileMap(), tmp3, tmp2, tmp1, tmp4);
                    wayPoints.Add(new LogicVector2(tmp4.m_x, tmp4.m_y));
                }

                tmp1.Destruct();
                tmp2.Destruct();
                tmp3.Destruct();
                tmp4.Destruct();

                return(wayPoints);
            }
            else
            {
                int startX = this.m_parent.GetX() + (this.m_parent.GetWidthInTiles() << 9) - 128;
                int startY = this.m_parent.GetY() + (this.m_parent.GetWidthInTiles() << 9) - 128;
                int endX   = this.m_parent.GetX() + 128;
                int endY   = this.m_parent.GetY() + 128;

                LogicArrayList <LogicVector2> wayPoints = new LogicArrayList <LogicVector2>(4);

                wayPoints.Add(new LogicVector2(startX, startY));
                wayPoints.Add(new LogicVector2(endX, startY));
                wayPoints.Add(new LogicVector2(endX, endY));
                wayPoints.Add(new LogicVector2(startX, endY));

                return(wayPoints);
            }
        }
Exemple #20
0
        public LogicProjectile(LogicGameObjectData data, LogicLevel level, int villageType) : base(data, level, villageType)
        {
            this.m_myTeam         = -1;
            this.m_targetPosition = new LogicVector2();
            this.m_unk144         = new LogicVector2();
            this.m_unk152         = new LogicVector2();
            this.m_unk160         = new LogicVector2();
            this.m_unk168         = new LogicVector2();
            this.m_unk248         = new LogicVector2();
            this.m_unk276         = new LogicVector2();

            this.m_bounceTargets   = new LogicGameObject[LogicProjectile.MAX_BOUNCES];
            this.m_bouncePositions = new LogicVector2[LogicProjectile.MAX_BOUNCES];
        }
Exemple #21
0
        public bool ManualPushTrap(LogicVector2 position, int time, int id)
        {
            if (this.m_parent != null)
            {
                if (this.m_parent.GetJump() <= 0 && !this.m_parent.GetParent().IsHero())
                {
                    if (id != 0)
                    {
                        int idx = -1;

                        for (int k = 0; k < 3; k++)
                        {
                            if (this.m_preventsPushId[k] == id)
                            {
                                return(false);
                            }

                            if (this.m_preventsPushTime[k] == 0)
                            {
                                idx = k;
                            }
                        }

                        if (idx == -1)
                        {
                            return(false);
                        }

                        this.m_preventsPushId[idx]   = id;
                        this.m_preventsPushTime[idx] = 1500;
                    }

                    LogicVector2 pushForce = new LogicVector2(time * position.m_x / 32, time * position.m_y / 32);

                    this.m_pushTime     = time - 16;
                    this.m_pushInitTime = time;

                    this.m_ignorePush = false;

                    this.m_pushBackStartPosition.m_x = this.m_position.m_x;
                    this.m_pushBackStartPosition.m_y = this.m_position.m_y;
                    this.m_pushBackEndPosition.m_x   = this.m_position.m_x + pushForce.m_x;
                    this.m_pushBackEndPosition.m_y   = this.m_position.m_y + pushForce.m_y;

                    return(true);
                }
            }

            return(false);
        }
Exemple #22
0
        /// <summary>
        ///     Gets the path point.
        /// </summary>
        public override LogicVector2 GetPathPoint(LogicVector2 position, int idx)
        {
            if (idx < 0 || this._pathLength <= idx)
            {
                Debugger.Error("illegal path index");
            }
            else
            {
                int sizeX = this._sizeX;
                int point = this._pathBuffer[idx];

                return(new LogicVector2(point % sizeX, point / sizeX));
            }

            return(null);
        }
Exemple #23
0
        public void Eject(LogicVector2 pos)
        {
            if (!this.IsFlying())
            {
                if (pos != null)
                {
                    this.m_ejectPosition.Set(pos.m_x, pos.m_y);
                }
                else
                {
                    this.m_ejectPosition.Set(0, 0);
                }

                this.m_ejected = true;
                this.GetHitpointComponent().Kill();
            }
        }
Exemple #24
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="LogicGameObject" /> class.
        /// </summary>
        public LogicGameObject(LogicData data, LogicLevel level, int villageType)
        {
            Debugger.DoAssert(villageType < 2, "VillageType not set! Game object has not been added to LogicGameObjectManager.");

            this._data        = data;
            this._level       = level;
            this._villageType = villageType;
            this._globalId    = -1;

            this._position   = new LogicVector2();
            this._listener   = new LogicGameObjectListener();
            this._components = new LogicArrayList <LogicComponent>(21);

            for (int i = 0; i < 17; i++)
            {
                this._components.Add(null);
            }
        }
Exemple #25
0
        public LogicMovementSystem()
        {
            this.m_pushBackStartPosition = new LogicVector2();
            this.m_pushBackEndPosition   = new LogicVector2();
            this.m_position          = new LogicVector2();
            this.m_moveDistance      = new LogicVector2();
            this.m_pathDistance      = new LogicVector2();
            this.m_pathStartPosition = new LogicVector2();
            this.m_pathEndPosition   = new LogicVector2();
            this.m_wayPoints         = new LogicArrayList <LogicVector2>();
            this.m_path = new LogicArrayList <LogicVector2>();

            this.m_preventsPushId   = new int[3];
            this.m_preventsPushTime = new int[3];
            this.m_boostTime        = new int[2];
            this.m_boostSpeed       = new int[2];

            this.m_pushInitTime = 500;
        }
Exemple #26
0
        public override void Destruct()
        {
            base.Destruct();

            for (int i = 0; i < LogicPathFinderNew.SAVED_PATHS; i++)
            {
                if (this.m_savedPaths[i] != null)
                {
                    this.m_savedPaths[i].Destruct();
                    this.m_savedPaths[i] = null;
                }
            }

            if (this.m_pathPointOutput != null)
            {
                this.m_pathPointOutput.Destruct();
                this.m_pathPointOutput = null;
            }
        }
        public void SpawnUnit(int count)
        {
            LogicTrapData      data      = this.GetTrapData();
            LogicCharacterData spawnData = this.m_useAirMode[this.m_level.GetActiveLayout(this.m_villageType)] ? data.GetSpawnedCharAir() : data.GetSpawnedCharGround();

            if (spawnData != null)
            {
                LogicVector2 position = new LogicVector2();

                for (int i = 0, j = 59, k = 0, l = 0; i < count; i++, j += 59, k += 128, l += 360)
                {
                    int random  = l / data.GetNumSpawns(this.m_upgLevel) + j * this.m_numSpawns % 360;
                    int randomX = (byte)(k & 0x80) ^ 0x180;
                    int posX    = this.GetMidX() + LogicMath.GetRotatedX(randomX, 0, random);
                    int posY    = this.GetMidY() + LogicMath.GetRotatedY(randomX, 0, random);

                    if (spawnData.IsFlying())
                    {
                        position.m_x = posX;
                        position.m_y = posY;
                    }
                    else
                    {
                        if (!this.m_level.GetTileMap().GetNearestPassablePosition(posX, posY, position, 1536))
                        {
                            continue;
                        }
                    }

                    LogicCharacter character = (LogicCharacter)LogicGameObjectFactory.CreateGameObject(spawnData, this.m_level, this.m_villageType);

                    character.GetHitpointComponent().SetTeam(1);
                    character.GetMovementComponent().EnableJump(3600000);
                    character.SetInitialPosition(position.m_x, position.m_y);
                    character.SetSpawnTime(200);

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

                position.Destruct();
            }
        }
        public bool GetNearestPassablePosition(int x, int y, LogicVector2 output, int radius)
        {
            int minDistance = -1;

            int startTileX = (x - radius) >> 8;
            int endTileX   = (x + radius) >> 8;

            while (startTileX <= endTileX)
            {
                int startTileY = (y - radius) >> 8;
                int endTileY   = (y + radius) >> 8;

                int posX  = (startTileX << 8);
                int posY  = (startTileY << 8);
                int distX = x - (startTileX << 8);
                int distY = y - (startTileY << 8);

                while (startTileY <= endTileY)
                {
                    if (this.IsPassablePathFinder(startTileX, startTileY))
                    {
                        int dist = LogicMath.Max(LogicMath.Abs(distX), LogicMath.Abs(distY));

                        if (minDistance < 0 || dist < minDistance)
                        {
                            minDistance = dist;
                            output.m_x  = posX;
                            output.m_y  = posY;
                        }
                    }

                    posY       += 256;
                    distY      -= 256;
                    startTileY += 1;
                }

                startTileX += 1;
            }

            return(minDistance > -1);
        }
Exemple #29
0
        public void ClearPatrolArea()
        {
            if (this.m_wayPoints != null)
            {
                while (this.m_wayPoints.Size() > 0)
                {
                    LogicVector2 wayPoint = this.m_wayPoints[this.m_wayPoints.Size() - 1];

                    if (wayPoint == null)
                    {
                        Debugger.Error("LogicMovementSystem::calculatePatrolArea: removed waypoint is NULL");
                    }

                    wayPoint.Destruct();

                    this.m_wayPoints.Remove(this.m_wayPoints.Size() - 1);
                }
            }

            this.m_wayPoints = null;
        }
Exemple #30
0
        public LogicCharacter(LogicGameObjectData data, LogicLevel level, int villageType) : base(data, level, villageType)
        {
            LogicCharacterData characterData = (LogicCharacterData)data;

            this.m_flying = characterData.IsFlying();

            this.AddComponent(new LogicHitpointComponent(this, characterData.GetHitpoints(0), 0));
            this.AddComponent(new LogicCombatComponent(this));
            this.AddComponent(new LogicMovementComponent(this, characterData.GetSpeed(), characterData.IsFlying(), characterData.IsUnderground()));
            this.SetUpgradeLevel(0);

            int childTroopCount = characterData.GetChildTroopCount();

            if (childTroopCount > 0)
            {
                this.m_childrens = new LogicArrayList <LogicCharacter>(childTroopCount);

                for (int i = 0; i < childTroopCount; i++)
                {
                    LogicCharacter character = new LogicCharacter(characterData.GetChildTroop(), level, villageType);

                    character.SetTroopChild(this, i);
                    character.GetCombatComponent().SetTroopChild(true);

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

            this.m_ejectPosition = new LogicVector2();
            this.m_summonTroops  = new LogicArrayList <LogicCharacter>();

            if (characterData.IsUnderground())
            {
                this.GetCombatComponent().SetUndergroundTime(3600000);
            }
        }