public bool IsLineOfSightClearImpl(int xA, int yA, int xB, int yB)
        {
            int directionX = xB > xA ? 1 : -1;
            int directionY = yB > yA ? 1 : -1;

            int distanceX = LogicMath.Abs(xB - xA);
            int distanceY = LogicMath.Abs(yB - yA);
            int direction = distanceX - distanceY;

            int subTileDistanceX = distanceX * 2;
            int subTileDistanceY = distanceY * 2;

            for (int i = distanceX + distanceY, posX = xA, posY = yA; i >= 0; i--)
            {
                if (this.IsCollision(posX, posY))
                {
                    return(false);
                }

                if (direction > 0)
                {
                    direction -= subTileDistanceY;
                    posX      += directionX;
                }
                else
                {
                    direction += subTileDistanceX;
                    posY      += directionY;
                }
            }

            return(true);
        }
示例#2
0
        public void CalculateRandomOffset(int randCount)
        {
            this.m_randomOffset.m_x = 0;
            this.m_randomOffset.m_y = 0;

            int randomRadius = this.GetSpellData().GetRandomRadius(this.m_upgradeLevel);

            if (randomRadius > 0)
            {
                for (int i = 0; i < randCount; i++)
                {
                    int prevX = this.m_randomOffset.m_x;
                    int prevY = this.m_randomOffset.m_y;

                    int yPosSeed    = 7 * randCount + 9;
                    int xEnableSeed = 5 * randCount + 3;
                    int yEnableSeed = 11 * randCount + 32;

                    for (int j = 0; j < 100; j++)
                    {
                        this.m_randomOffset.m_x = (this.Rand(randCount + j) % randomRadius) * (2 * (this.Rand(xEnableSeed) & 1) - 1);
                        this.m_randomOffset.m_y = (this.Rand(yPosSeed) % randomRadius) * (2 * (this.Rand(yEnableSeed) & 1) - 1);

                        if (LogicMath.Abs(prevY - prevX + this.m_randomOffset.m_x - this.m_randomOffset.m_y) > (int)(randomRadius / 3u))
                        {
                            break;
                        }

                        yPosSeed    += 7;
                        xEnableSeed += 4;
                        yEnableSeed += 15;
                    }
                }
            }
        }
        public static int GetAngle(int x, int y)
        {
            if (x == 0 && y == 0)
            {
                return(0);
            }

            if (x > 0 && y >= 0)
            {
                if (y >= x)
                {
                    return(90 - LogicMath.ATAN_TABLE[(x << 7) / y]);
                }

                return(LogicMath.ATAN_TABLE[(y << 7) / x]);
            }

            int num = LogicMath.Abs(x);

            if (x <= 0 && y > 0)
            {
                if (num < y)
                {
                    return(90 + LogicMath.ATAN_TABLE[(num << 7) / y]);
                }

                return(180 - LogicMath.ATAN_TABLE[(y << 7) / num]);
            }

            int num2 = LogicMath.Abs(y);

            if (x < 0 && y <= 0)
            {
                if (num2 >= num)
                {
                    if (num2 == 0)
                    {
                        return(0);
                    }

                    return(270 - LogicMath.ATAN_TABLE[(num << 7) / num2]);
                }

                return(180 + LogicMath.ATAN_TABLE[(num2 << 7) / num]);
            }

            if (num < num2)
            {
                return(270 + LogicMath.ATAN_TABLE[(num << 7) / num2]);
            }

            if (num == 0)
            {
                return(0);
            }

            return(LogicMath.NormalizeAngle360(360 - LogicMath.ATAN_TABLE[(num2 << 7) / num]));
        }
        public static int GetRadius(int x, int y)
        {
            x = LogicMath.Abs(x);
            y = LogicMath.Abs(y);
            int maxValue = LogicMath.Max(x, y);
            int minValue = LogicMath.Min(x, y);

            return(maxValue + (53 * minValue >> 7));
        }
示例#5
0
        public void ApplyExtraHealthPermil(int x, int y, int radius, int team, int extraHealthPermil, int extraHealthMin, int extraHealthMax, int time, int targetType)
        {
            LogicArrayList <LogicComponent> components = this.GetComponentManager().GetComponents(LogicComponentType.HITPOINT);

            for (int i = 0; i < components.Size(); i++)
            {
                LogicHitpointComponent hitpointComponent = (LogicHitpointComponent)components[i];
                LogicGameObject        parent            = hitpointComponent.GetParent();

                if (!parent.IsHidden() && hitpointComponent.GetHitpoints() != 0 && hitpointComponent.GetTeam() == team)
                {
                    LogicMovementComponent movementComponent = parent.GetMovementComponent();

                    if (movementComponent != null)
                    {
                        if (parent.GetGameObjectType() == LogicGameObjectType.CHARACTER)
                        {
                            LogicCharacter character = (LogicCharacter)parent;

                            if (character.GetCharacterData().GetAuraSpell(character.GetUpgradeLevel()) == this.m_data)
                            {
                                continue;
                            }
                        }

                        if (parent.IsFlying())
                        {
                            if (targetType != 1)
                            {
                                continue;
                            }
                        }
                        else if (targetType == 0)
                        {
                            continue;
                        }

                        int distanceX = x - parent.GetMidX();
                        int distanceY = y - parent.GetMidY();

                        if (LogicMath.Abs(distanceX) <= radius &&
                            LogicMath.Abs(distanceY) <= radius &&
                            distanceX * distanceX + distanceY * distanceY < (uint)(radius * radius))
                        {
                            int hp = hitpointComponent.GetOriginalHitpoints() +
                                     LogicMath.Clamp(extraHealthPermil * hitpointComponent.GetOriginalHitpoints() / 1000, 100 * extraHealthMin, 100 * extraHealthMax);

                            if (hp >= hitpointComponent.GetMaxHitpoints())
                            {
                                hitpointComponent.SetExtraHealth(hp, time);
                            }
                        }
                    }
                }
            }
        }
        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);
        }
        public void EjectCharacters()
        {
            LogicArrayList <LogicComponent> components = this.GetComponentManager().GetComponents(LogicComponentType.MOVEMENT);

            int ejectHousingSpace = this.GetTrapData().GetEjectHousingLimit(this.m_upgLevel);
            int radius            = this.GetTrapData().GetTriggerRadius();

            for (int i = 0; i < components.Size(); i++)
            {
                LogicMovementComponent movementComponent = (LogicMovementComponent)components[i];
                LogicGameObject        parent            = movementComponent.GetParent();

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

                    if (character.GetHitpointComponent() != null && character.GetHitpointComponent().GetTeam() == 0 &&
                        character.GetCharacterData().GetHousingSpace() <= ejectHousingSpace)
                    {
                        int distanceX = character.GetX() - this.GetMidX();
                        int distanceY = character.GetY() - this.GetMidY();

                        if (LogicMath.Abs(distanceX) <= radius &&
                            LogicMath.Abs(distanceY) <= radius)
                        {
                            if (character.GetCombatComponent() == null || character.GetCombatComponent().GetUndergroundTime() <= 0)
                            {
                                int distanceSquared = distanceX * distanceX + distanceY * distanceY;

                                if (distanceSquared < (uint)(radius * radius))
                                {
                                    character.Eject(null);
                                    ejectHousingSpace -= character.GetCharacterData().GetHousingSpace();
                                }
                            }
                        }
                    }
                }
            }
        }
示例#8
0
        private static GameAvatar FindEnemy(MatchmakingEntry entry, Dictionary <long, GameAvatar> documents)
        {
            GameAvatar        document      = entry.Session.GameAvatar;
            LogicClientAvatar playerAvatar1 = document.LogicClientAvatar;

            int totalSecs       = TimeUtil.GetTimestamp() - entry.Timestamp;
            int strength1       = GameMatchmakingManager.CalculateStrength(playerAvatar1);
            int maxStrengthDiff = 50 + LogicMath.Clamp(totalSecs * 150 / 60, 0, 150);

            foreach (GameAvatar enemy in documents.Values)
            {
                LogicClientAvatar playerAvatar2 = enemy.LogicClientAvatar;

#if DEBUG
                if (ServerCore.Random.Rand(100) <= 95)
                {
                    continue;
                }
#else
                if (playerAvatar1.IsInAlliance() && playerAvatar2.IsInAlliance() && playerAvatar1.GetAllianceId().Equals(playerAvatar2.GetAllianceId()))
                {
                    continue;
                }

                int strength2 = GameMatchmakingManager.CalculateStrength(playerAvatar2);

                if (LogicMath.Abs(strength1 - strength2) >= maxStrengthDiff)
                {
                    continue;
                }
                if (document.HasRecentlyMatchedWithEnemy(enemy.Id))
                {
                    continue;
                }
#endif
                return(enemy);
            }

            return(null);
        }
示例#9
0
        public void ObjectClose(LogicGameObject gameObject)
        {
            LogicHitpointComponent hitpointComponent = gameObject.GetHitpointComponent();

            if (hitpointComponent == null || hitpointComponent.GetTeam() != 1)
            {
                if (gameObject.GetGameObjectType() == LogicGameObjectType.CHARACTER)
                {
                    LogicCharacter     character = (LogicCharacter)gameObject;
                    LogicCharacterData data      = character.GetCharacterData();

                    if (data.GetHousingSpace() < this.m_minTriggerHousingLimit)
                    {
                        return;
                    }
                }

                LogicCombatComponent combatComponent = gameObject.GetCombatComponent();

                if (combatComponent == null || combatComponent.GetUndergroundTime() <= 0)
                {
                    if ((!gameObject.IsFlying() || this.m_airTrigger) && (gameObject.IsFlying() || this.m_groundTrigger))
                    {
                        if (this.m_healerTrigger || combatComponent == null || !combatComponent.IsHealer())
                        {
                            int distanceX = gameObject.GetX() - this.m_parent.GetMidX();
                            int distanceY = gameObject.GetY() - this.m_parent.GetMidY();

                            if (LogicMath.Abs(distanceX) <= this.m_triggerRadius &&
                                LogicMath.Abs(distanceY) <= this.m_triggerRadius &&
                                distanceX * distanceX + distanceY * distanceY < (uint)(this.m_triggerRadius * this.m_triggerRadius))
                            {
                                this.Trigger();
                            }
                        }
                    }
                }
            }
        }
        public static float GetCharacterStrength(LogicCharacterData data, int upgLevel)
        {
            if (data.IsProductionEnabled())
            {
                float attackStrength = data.GetHitpoints(upgLevel) * 0.04f +
                                       LogicMath.Abs(data.GetAttackerItemData(upgLevel).GetDamagePerMS(0, false)) * 0.2f;

                if (data.GetUnitsInCamp(upgLevel) > 0 && data.GetUnitsInCamp(0) > 0)
                {
                    attackStrength = (float)data.GetUnitsInCamp(upgLevel) / data.GetUnitsInCamp(0) * attackStrength;
                }

                for (int i = data.GetSpecialAbilityLevel(upgLevel); i > 0; i--)
                {
                    attackStrength *= 1.1f;
                }

                return(attackStrength * 0.01f * data.GetStrengthWeight(upgLevel) / data.GetHousingSpace() * 10f);
            }

            return(0f);
        }
示例#11
0
        public void UpdatePenetrating(int damageMultiplier)
        {
            LogicVector2 pos1 = new LogicVector2((this.m_targetPosition.m_x >> 3) - this.m_unk248.m_x, (this.m_targetPosition.m_y >> 3) - this.m_unk248.m_y);

            pos1.Normalize(512);

            LogicVector2 pos2 = new LogicVector2(-pos1.m_y, pos1.m_x);

            int distance = ((200 - this.m_areaShieldDelay) * (8 * this.GetSpeed() - 8 * this.m_areaShieldSpeed) / 200 + 8 * this.m_areaShieldSpeed) >> 3;

            LogicArrayList <LogicComponent> components = this.GetComponentManager().GetComponents(LogicComponentType.MOVEMENT);

            for (int i = 0, damage = damageMultiplier * this.m_damage / 100; i < components.Size(); i++)
            {
                LogicMovementComponent component         = (LogicMovementComponent)components[i];
                LogicGameObject        parent            = component.GetParent();
                LogicHitpointComponent hitpointComponent = parent.GetHitpointComponent();

                if (!parent.IsHidden() && hitpointComponent.GetTeam() != this.m_myTeam && hitpointComponent.GetHitpoints() > 0)
                {
                    int distanceX = parent.GetMidX() - this.GetMidX();
                    int distanceY = parent.GetMidY() - this.GetMidY();

                    if (parent.GetGameObjectType() == LogicGameObjectType.CHARACTER)
                    {
                        distanceX += parent.GetWidthInTiles() << 8;
                        distanceY += parent.GetHeightInTiles() << 8;
                    }

                    if ((!component.IsFlying() || this.m_flyingTarget) &&
                        LogicMath.Abs(distanceX) <= this.m_penetratingRadius &&
                        LogicMath.Abs(distanceY) <= this.m_penetratingRadius &&
                        distanceX * distanceX + distanceY * distanceY <= (uint)(this.m_penetratingRadius * this.m_penetratingRadius))
                    {
                        LogicVector2 position = new LogicVector2();

                        if (parent.GetGameObjectType() == LogicGameObjectType.CHARACTER && hitpointComponent.GetMaxHitpoints() <= damage)
                        {
                            int rnd = (byte)this.Rand(parent.GetGlobalID());

                            if (rnd > 170u)
                            {
                                position.Set((pos1.m_x >> 2) + pos2.m_x, (pos1.m_y >> 2) + pos2.m_y);
                            }
                            else
                            {
                                if (rnd > 85)
                                {
                                    position.Set(pos1.m_x, pos1.m_y);
                                }
                                else
                                {
                                    position.Set((pos1.m_x >> 2) - pos2.m_x, (pos1.m_y >> 2) - pos2.m_y);
                                }
                            }

                            if (hitpointComponent.GetInvulnerabilityTime() <= 0)
                            {
                                ((LogicCharacter)parent).Eject(position);
                            }

                            position.Destruct();
                        }
                        else
                        {
                            position.Set(pos1.m_x, pos1.m_y);
                            position.Normalize(distance);

                            if (parent.GetMovementComponent().GetMovementSystem().ManualPushTrap(position, 150, this.m_globalId) || parent.IsHero())
                            {
                                this.UpdateTargetDamage(parent, damage);
                            }
                        }
                    }
                }
            }

            pos1.Destruct();
            pos2.Destruct();
        }
示例#12
0
        public override void SubTick()
        {
            base.SubTick();

            LogicSpellData data = this.GetSpellData();

            if (!this.m_preDeployEffectPlayed)
            {
                this.GetListener().PlayEffect(data.GetPreDeployEffect(this.m_upgradeLevel));
                this.m_preDeployEffectPlayed = true;
            }

            if (++this.m_deployTime >= data.GetDeployTimeMS() * 60 / 1000)
            {
                if (!this.m_deployed)
                {
                    this.GetListener().PlayEffect(this.m_team != 0 && data.GetEnemyDeployEffect(this.m_upgradeLevel) != null
                                                      ? data.GetEnemyDeployEffect(this.m_upgradeLevel)
                                                      : data.GetDeployEffect(this.m_upgradeLevel), this.m_playEffectOffsetX, this.m_playEffectOffsetY);

                    this.m_deployEffect2Cooldown = data.GetDeployEffect2Delay();

                    if (this.m_deployEffect2Cooldown <= 0)
                    {
                        this.GetListener().PlayEffect(data.GetDeployEffect2(this.m_upgradeLevel), this.m_playEffectOffsetX, this.m_playEffectOffsetY);
                        this.m_deployEffect2Cooldown = 0;
                    }

                    this.m_deployed = true;
                }

                if (++this.m_chargingTime >= (data.GetChargingTimeMS() * 60 / 1000) +
                    this.m_chargingCount * (data.GetTimeBetweenHitsMS(this.m_upgradeLevel) * 60 / 1000) &&
                    this.m_chargingCount < data.GetNumberOfHits(this.m_upgradeLevel))
                {
                    this.CalculateRandomOffset(this.m_chargingCount);
                    this.GetListener().PlayTargetedEffect(data.GetChargingEffect(this.m_upgradeLevel), this, this.m_randomOffset);
                    ++this.m_chargingCount;
                }

                if (++this.m_hitTime >= (data.GetHitTimeMS() * 60 / 1000) +
                    this.m_hitCount * (data.GetTimeBetweenHitsMS(this.m_upgradeLevel) * 60 / 1000) &&
                    this.m_hitCount < data.GetNumberOfHits(this.m_upgradeLevel))
                {
                    this.CalculateRandomOffset(this.m_hitCount);
                    this.GetListener().PlayTargetedEffect(data.GetHitEffect(this.m_upgradeLevel), this, this.m_randomOffset);

                    int randomRadiusX = 0;
                    int randomRadiusY = 0;

                    if (!data.GetRandomRadiusAffectsOnlyGfx())
                    {
                        randomRadiusX = this.m_randomOffset.m_x;
                        randomRadiusY = this.m_randomOffset.m_y;
                    }

                    int damage = data.GetDamage(this.m_upgradeLevel);

                    if (damage != 0 && data.IsScaleByTownHall())
                    {
                        int scaledDamage = damage * (700 * this.m_level.GetPlayerAvatar().GetTownHallLevel() / (LogicDataTables.GetTownHallLevelCount() - 1) / 10 + 30) / 100;

                        damage = 1;

                        if (scaledDamage > 0)
                        {
                            damage = scaledDamage;
                        }
                    }

                    if (damage != 0 && data.GetRadius(this.m_upgradeLevel) > 0)
                    {
                        int areaDamageX = randomRadiusX + this.GetMidX();
                        int areaDamageY = randomRadiusY + this.GetMidY();
                        int preferredTargetDamagePercent = 100 * data.GetPreferredTargetDamageMod();

                        if (data.GetTroopsOnly())
                        {
                            this.m_level.AreaDamage(0, areaDamageX, areaDamageY, data.GetRadius(this.m_upgradeLevel), damage, data.GetPreferredTarget(),
                                                    preferredTargetDamagePercent, null, this.m_team, null, 2, 2, 0, true, damage < 0, data.GetHeroDamageMultiplier(),
                                                    data.GetMaxUnitsHit(this.m_upgradeLevel), null, data.GetDamageTHPercent(), data.GetPauseCombatComponentMs());
                        }
                        else
                        {
                            this.m_level.AreaDamage(0, areaDamageX, areaDamageY, data.GetRadius(this.m_upgradeLevel), damage, data.GetPreferredTarget(),
                                                    preferredTargetDamagePercent, null, this.m_team, null, 2, 1, 0, true, damage < 0, data.GetHeroDamageMultiplier(),
                                                    data.GetMaxUnitsHit(this.m_upgradeLevel), null, data.GetDamageTHPercent(), data.GetPauseCombatComponentMs());
                        }
                    }

                    if (data.GetDuplicateHousing(this.m_upgradeLevel) != 0 && data.GetRadius(this.m_upgradeLevel) > 0)
                    {
                        this.SelectDuplicableCharacters();
                        this.DuplicateCharacter();
                    }

                    if ((data.GetBuildingDamagePermil(this.m_upgradeLevel) != 0 || data.GetTroopDamagePermil(this.m_upgradeLevel) != 0) && data.GetRadius(this.m_upgradeLevel) > 0)
                    {
                        this.ApplyDamagePermil(randomRadiusX + this.GetMidX(), randomRadiusY + this.GetMidY(), 0, this.m_team, 0, 2, 1, 0,
                                               data.GetTroopDamagePermil(this.m_upgradeLevel) < 0);
                    }

                    if (data.GetPoisonDamage(this.m_upgradeLevel) != 0 && data.GetRadius(this.m_upgradeLevel) > 0)
                    {
                        int areaDamageX  = randomRadiusX + this.GetMidX();
                        int areaDamageY  = randomRadiusY + this.GetMidY();
                        int poisonDamage = data.GetPoisonDamage(this.m_upgradeLevel);

                        if (data.GetTroopsOnly())
                        {
                            this.m_level.AreaPoison(0, areaDamageX, areaDamageY, data.GetRadius(this.m_upgradeLevel), data.GetPoisonDamage(this.m_upgradeLevel), null,
                                                    0, null, this.m_team, null, data.GetPoisonAffectAir() ? 2 : 1, 2, 0, poisonDamage < 0, data.GetHeroDamageMultiplier(),
                                                    data.GetPoisonIncreaseSlowly());
                        }
                        else
                        {
                            this.m_level.AreaPoison(0, areaDamageX, areaDamageY, data.GetRadius(this.m_upgradeLevel), data.GetPoisonDamage(this.m_upgradeLevel), null,
                                                    0, null, this.m_team, null, data.GetPoisonAffectAir() ? 2 : 1, 1, 0, poisonDamage < 0, data.GetHeroDamageMultiplier(),
                                                    data.GetPoisonIncreaseSlowly());
                        }
                    }

                    if (data.GetSpeedBoost(this.m_upgradeLevel) != 0 || data.GetAttackSpeedBoost(this.m_upgradeLevel) != 0)
                    {
                        this.m_level.AreaBoost(randomRadiusX + this.GetMidX(), randomRadiusY + this.GetMidY(), data.GetRadius(this.m_upgradeLevel),
                                               data.GetSpeedBoost(this.m_upgradeLevel), data.GetSpeedBoost2(this.m_upgradeLevel), data.GetDamageBoostPercent(this.m_upgradeLevel),
                                               data.GetAttackSpeedBoost(this.m_upgradeLevel), 60 * data.GetBoostTimeMS(this.m_upgradeLevel) / 1000,
                                               data.GetBoostDefenders() ? this.m_team != 1 ? 1 : 0 : this.m_team, data.GetBoostLinkedToPoison());
                    }

                    if (data.GetJumpBoostMS(this.m_upgradeLevel) != 0)
                    {
                        if (this.m_team == 0)
                        {
                            this.m_level.AreaJump(randomRadiusX + this.GetMidX(), randomRadiusY + this.GetMidY(), data.GetRadius(this.m_upgradeLevel),
                                                  data.GetJumpBoostMS(this.m_upgradeLevel), data.GetJumpHousingLimit(this.m_upgradeLevel), this.m_team);

                            if (this.m_hitCount == 0)
                            {
                                if (LogicDataTables.GetGlobals().UseWallWeightsForJumpSpell())
                                {
                                    int numberOfHits      = data.GetNumberOfHits(this.m_upgradeLevel);
                                    int timeBetweenHitsMS = data.GetTimeBetweenHitsMS(this.m_upgradeLevel);
                                    int radius            = data.GetRadius(this.m_upgradeLevel);
                                    int jumpTime          = numberOfHits * timeBetweenHitsMS - LogicDataTables.GetGlobals().GetForgetTargetTime();

                                    LogicArrayList <LogicGameObject> buildings = this.GetGameObjectManager().GetGameObjects(LogicGameObjectType.BUILDING);

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

                                        if (building.IsWall() && building.IsAlive())
                                        {
                                            int distanceX = this.GetMidX() - building.GetMidX();
                                            int distanceY = this.GetMidY() - building.GetMidY();

                                            if (LogicMath.Abs(distanceX) < radius &&
                                                LogicMath.Abs(distanceY) < radius &&
                                                distanceX * distanceX + distanceY * distanceY < (uint)(radius * radius))
                                            {
                                                building.SetHitWallDelay(jumpTime);
                                            }
                                        }
                                    }

                                    this.m_level.GetTileMap().GetPathFinder().InvalidateCache();

                                    LogicArrayList <LogicComponent> components = this.GetComponentManager().GetComponents(LogicComponentType.MOVEMENT);

                                    for (int i = 0; i < components.Size(); i++)
                                    {
                                        LogicMovementComponent movementComponent = (LogicMovementComponent)components[i];
                                        LogicGameObject        parent            = movementComponent.GetParent();
                                        LogicCombatComponent   combatComponent   = parent.GetCombatComponent();

                                        if (combatComponent != null && combatComponent.GetTarget(0) != null)
                                        {
                                            if (combatComponent.GetTarget(0).IsWall())
                                            {
                                                combatComponent.ForceNewTarget();
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    if (data.GetShrinkReduceSpeedRatio() != 0 || data.GetShrinkHitpointsRatio() != 0)
                    {
                        this.m_level.AreaShrink(randomRadiusX + this.GetMidX(), randomRadiusY + this.GetMidY(), data.GetRadius(this.m_upgradeLevel),
                                                data.GetShrinkReduceSpeedRatio(),
                                                data.GetShrinkHitpointsRatio(), 1000 * LogicDataTables.GetGlobals().GetShrinkSpellDurationSeconds() / 64, this.m_team);
                    }

                    if (data.GetFreezeTimeMS(this.m_upgradeLevel) != 0)
                    {
                        this.m_level.AreaFreeze(randomRadiusX + this.GetMidX(), randomRadiusY + this.GetMidY(), data.GetRadius(this.m_upgradeLevel),
                                                60 * data.GetFreezeTimeMS(this.m_upgradeLevel) / 1000, this.m_team);
                    }

                    if (data.GetBuildingDamageBoostPercent(this.m_upgradeLevel) != 0)
                    {
                        this.m_level.AreaBoost(randomRadiusX + this.GetMidX(), randomRadiusY + this.GetMidY(), data.GetRadius(this.m_upgradeLevel),
                                               data.GetBuildingDamageBoostPercent(this.m_upgradeLevel), 0, 60 * data.GetBoostTimeMS(this.m_upgradeLevel) / 1000);
                    }

                    if (data.GetSummonTroop() != null)
                    {
                        this.SpawnSummon(randomRadiusX + this.GetMidX(), randomRadiusY + this.GetMidY());
                    }

                    if (data.GetSpawnObstacle() != null)
                    {
                        this.SpawnObstacle(randomRadiusX + this.GetMidX(), randomRadiusY + this.GetMidY(), 5);
                    }

                    if (data.GetExtraHealthPermil(this.m_upgradeLevel) != 0)
                    {
                        this.ApplyExtraHealthPermil(randomRadiusX + this.GetMidX(), randomRadiusY + this.GetMidY(), data.GetRadius(this.m_upgradeLevel), this.m_team,
                                                    data.GetExtraHealthPermil(this.m_upgradeLevel), data.GetExtraHealthMin(this.m_upgradeLevel),
                                                    data.GetExtraHealthMax(this.m_upgradeLevel),
                                                    data.GetHitTimeMS() + 64, 2);
                    }

                    if (data.GetInvulnerabilityTime(this.m_upgradeLevel) != 0)
                    {
                        this.m_level.AreaShield(randomRadiusX + this.GetMidX(), randomRadiusY + this.GetMidY(), data.GetRadius(this.m_upgradeLevel),
                                                data.GetInvulnerabilityTime(this.m_upgradeLevel), this.m_team);
                    }

                    if (++this.m_hitCount >= data.GetNumberOfHits(this.m_upgradeLevel))
                    {
                        this.m_hitsCompleted = true;
                        this.m_level.UpdateBattleStatus();
                    }
                }
            }
        }
        public void ThrowCharacters()
        {
            LogicArrayList <LogicComponent> components = this.GetComponentManager().GetComponents(LogicComponentType.MOVEMENT);

            int ejectHousingSpace = this.GetTrapData().GetEjectHousingLimit(this.m_upgLevel);
            int radius            = this.GetTrapData().GetTriggerRadius();

            for (int i = 0; i < components.Size(); i++)
            {
                LogicMovementComponent movementComponent = (LogicMovementComponent)components[i];
                LogicGameObject        parent            = movementComponent.GetParent();

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

                    if (character.GetHitpointComponent() != null && character.GetHitpointComponent().GetTeam() == 0 &&
                        character.GetCharacterData().GetHousingSpace() <= ejectHousingSpace)
                    {
                        int distanceX = character.GetX() - this.GetMidX();
                        int distanceY = character.GetY() - this.GetMidY();

                        if (LogicMath.Abs(distanceX) <= radius &&
                            LogicMath.Abs(distanceY) <= radius)
                        {
                            if (character.GetCombatComponent() == null || character.GetCombatComponent().GetUndergroundTime() <= 0)
                            {
                                int distanceSquared = distanceX * distanceX + distanceY * distanceY;

                                if (distanceSquared < (uint)(radius * radius))
                                {
                                    int activeLayout = this.m_level.GetActiveLayout();
                                    int direction    = activeLayout <= 7 ? this.m_direction[activeLayout] : 0;
                                    int pushBackX    = 0;
                                    int pushBackY    = 0;

                                    switch (direction)
                                    {
                                    case 0:
                                        pushBackX = 256;
                                        break;

                                    case 1:
                                        pushBackY = 256;
                                        break;

                                    case 2:
                                        pushBackX = -256;
                                        break;

                                    case 3:
                                        pushBackY = -256;
                                        break;
                                    }

                                    this.m_level.AreaPushBack(this.GetMidX(), this.GetMidY(), 600, 1000, 1, 1, pushBackX, pushBackY, this.GetTrapData().GetThrowDistance(),
                                                              ejectHousingSpace);
                                }
                            }
                        }
                    }
                }
            }
        }
示例#14
0
        public void ApplyDamagePermil(int x, int y, int unk1, int team, int unk2, int targetType, int damageType, int unk3, bool healing)
        {
            LogicSpellData spellData = this.GetSpellData();

            int radius                   = spellData.GetRadius(this.m_upgradeLevel);
            int troopDamagePermil        = spellData.GetTroopDamagePermil(this.m_upgradeLevel);
            int buildingDamagePermil     = spellData.GetBuildingDamagePermil(this.m_upgradeLevel);
            int executeHealthPermil      = spellData.GetExecuteHealthPermil(this.m_upgradeLevel);
            int damagePermilMin          = spellData.GetDamagePermilMin(this.m_upgradeLevel);
            int preferredTargetDamageMod = spellData.GetPreferredTargetDamageMod();
            int preferredDamagePermilMin = spellData.GetPreferredDamagePermilMin(this.m_upgradeLevel);

            LogicData preferredTarget = spellData.GetPreferredTarget();

            LogicVector2 pushBackPosition = new LogicVector2();
            LogicArrayList <LogicComponent> components = this.GetComponentManager().GetComponents(LogicComponentType.HITPOINT);

            int tmp = troopDamagePermil + 2 * buildingDamagePermil;

            for (int i = 0; i < components.Size(); i++)
            {
                LogicHitpointComponent hitpointComponent = (LogicHitpointComponent)components[i];
                LogicGameObject        parent            = hitpointComponent.GetParent();

                if (!parent.IsHidden() && hitpointComponent.GetHitpoints() != 0)
                {
                    if (hitpointComponent.GetTeam() == team)
                    {
                        if (tmp > 0 || tmp < 0 && parent.IsPreventsHealing())
                        {
                            continue;
                        }
                    }
                    else if (tmp < 0)
                    {
                        continue;
                    }

                    if (damageType == 2 && parent.GetGameObjectType() != LogicGameObjectType.CHARACTER)
                    {
                        continue;
                    }

                    int parentX;
                    int parentY;

                    LogicMovementComponent movementComponent = parent.GetMovementComponent();

                    if (movementComponent != null || parent.IsFlying())
                    {
                        if (parent.IsFlying())
                        {
                            if (targetType == 1)
                            {
                                continue;
                            }
                        }
                        else if (targetType == 0)
                        {
                            continue;
                        }

                        parentX = parent.GetMidX();
                        parentY = parent.GetMidY();
                    }
                    else
                    {
                        int posX = parent.GetX();
                        int posY = parent.GetY();

                        parentX = LogicMath.Clamp(x, posX, posX + (parent.GetWidthInTiles() << 9));
                        parentY = LogicMath.Clamp(y, posY, posY + (parent.GetHeightInTiles() << 9));
                    }

                    int distanceX = x - parentX;
                    int distanceY = y - parentY;

                    if (LogicMath.Abs(distanceX) <= radius &&
                        LogicMath.Abs(distanceY) <= radius &&
                        distanceX * distanceX + distanceY * distanceY < (uint)(radius * radius))
                    {
                        if (damageType == 1 && parent.GetGameObjectType() == LogicGameObjectType.BUILDING)
                        {
                            LogicBuilding building = (LogicBuilding)parent;

                            if (building.GetResourceStorageComponentComponent() != null &&
                                !building.GetBuildingData().IsTownHall() &&
                                !building.GetBuildingData().IsTownHallVillage2())
                            {
                                parent.SetDamageTime(10);
                                continue;
                            }
                        }

                        if (parent.GetGameObjectType() == LogicGameObjectType.BUILDING || parent.GetGameObjectType() == LogicGameObjectType.CHARACTER)
                        {
                            int dataDamagePermil = parent.GetGameObjectType() == LogicGameObjectType.BUILDING ? buildingDamagePermil : troopDamagePermil;

                            if (dataDamagePermil != 0)
                            {
                                int permil = 10 * hitpointComponent.GetMaxHitpoints() * dataDamagePermil / 10000;

                                if (10 * hitpointComponent.GetMaxHitpoints() * dataDamagePermil <= -10000)
                                {
                                    if (parent.IsHero())
                                    {
                                        permil = LogicDataTables.GetGlobals().GetHeroHealMultiplier() * permil / 100;
                                    }
                                }

                                bool isPreferredTarget = LogicCombatComponent.IsPreferredTarget(preferredTarget, parent);

                                int numberOfHits    = spellData.GetNumberOfHits(this.m_upgradeLevel);
                                int completePermil  = hitpointComponent.GetDamagePermilCount() / spellData.GetNumberOfHits(this.m_upgradeLevel);
                                int calculateDamage = isPreferredTarget
                                    ? permil / (completePermil + 1) + preferredTargetDamageMod * hitpointComponent.GetMaxHitpoints() / (100 * numberOfHits) * completePermil *
                                                      completePermil
                                    : permil / (2 * completePermil + 1);
                                int permilMin = isPreferredTarget ? preferredDamagePermilMin : damagePermilMin;
                                int damage    = hitpointComponent.GetMaxHitpoints() * permilMin / 10000;

                                if (calculateDamage >= damage)
                                {
                                    damage = calculateDamage;
                                }

                                if (executeHealthPermil > 0 && 1000 * (hitpointComponent.GetHitpoints() - damage) <= executeHealthPermil)
                                {
                                    damage = hitpointComponent.GetHitpoints();
                                }

                                hitpointComponent.CauseDamagePermil(damage);

                                if (healing)
                                {
                                    // Listener.
                                }

                                if ((distanceX | distanceX) == 0)
                                {
                                    distanceX = 1;
                                }

                                pushBackPosition.m_x = -distanceX;
                                pushBackPosition.m_y = -distanceY;

                                pushBackPosition.Normalize(512);

                                if (unk3 > 0 && movementComponent != null)
                                {
                                    movementComponent.GetMovementSystem().PushBack(pushBackPosition, damage, unk3, 0, false, true);
                                }
                            }
                        }
                    }
                }
            }
        }
示例#15
0
        public void SelectDuplicableCharacters()
        {
            if (this.m_duplicableCharacters == null)
            {
                this.m_duplicableCharacters = new LogicArrayList <LogicGameObject>(20);
            }

            if (this.m_duplicateCharacters == null)
            {
                this.m_duplicateCharacters = new LogicArrayList <LogicGameObject>(20);
            }

            int radius = this.GetSpellData().GetRadius(this.m_upgradeLevel);

            LogicArrayList <LogicComponent> components = this.GetComponentManager().GetComponents(LogicComponentType.MOVEMENT);

            for (int i = 0; i < components.Size(); i++)
            {
                LogicMovementComponent movementComponent = (LogicMovementComponent)components[i];
                LogicGameObject        parent            = movementComponent.GetParent();

                if (parent.GetGameObjectType() == LogicGameObjectType.CHARACTER)
                {
                    LogicCharacter         character         = (LogicCharacter)parent;
                    LogicCharacterData     characterData     = character.GetCharacterData();
                    LogicHitpointComponent hitpointComponent = character.GetHitpointComponent();

                    if (hitpointComponent != null && hitpointComponent.GetTeam() == 0 && character.IsAlive() && !character.IsHero() &&
                        characterData.GetHousingSpace() <= this.m_duplicateHousingSpace)
                    {
                        int distanceX = character.GetPosition().m_x - this.GetMidX();
                        int distanceY = character.GetPosition().m_y - this.GetMidY();

                        if (LogicMath.Abs(distanceX) <= radius &&
                            LogicMath.Abs(distanceY) <= radius &&
                            distanceX * distanceX + distanceY * distanceY < (uint)(radius * radius))
                        {
                            int idx = -1;

                            for (int j = 0, size = this.m_duplicableCharacters.Size(); j < size; j++)
                            {
                                if (this.m_duplicableCharacters[j] == character)
                                {
                                    idx = j;
                                    break;
                                }
                            }

                            if (idx == -1)
                            {
                                this.m_duplicateCharacterData         = characterData;
                                this.m_duplicateCharacterUpgradeLevel = character.GetUpgradeLevel();

                                this.m_duplicableCharacters.Add(character);

                                // Listener.
                            }
                        }
                    }
                }
            }
        }
        public bool GetPassablePositionInLine(int startX, int startY, int endX, int endY, int radius, LogicVector2 output)
        {
            int distanceX = endX - startX;
            int distanceY = endY - startY;
            int moveStepX;
            int moveStepY;
            int length;

            if (LogicMath.Abs(distanceY) < LogicMath.Abs(distanceX))
            {
                moveStepX = distanceX > 0 ? 64 : -64;
                moveStepY = (distanceY << 6) / LogicMath.Abs(distanceX);
                length    = distanceX / moveStepX;
            }
            else if (LogicMath.Abs(distanceX) >= LogicMath.Abs(distanceY))
            {
                moveStepX = distanceX >= 0 && endX != startX ? 64 : -64;
                moveStepY = distanceY > 0 ? 64 : -64;
                length    = distanceX / moveStepX;
            }
            else
            {
                moveStepX = (distanceX << 6) / LogicMath.Abs(distanceY);
                moveStepY = distanceY > 0 ? 64 : -64;
                length    = distanceY / moveStepY;
            }

            int x = startX;
            int y = startY;

            for (int i = 0, l = 0; i < length; i++)
            {
                if (this.IsPassablePathFinder(x >> 8, y >> 8))
                {
                    output.m_x = x;
                    output.m_y = y;

                    return(true);
                }

                l += moveStepX * moveStepX + moveStepY * moveStepY;

                if (l > radius * radius)
                {
                    return(false);
                }

                x += moveStepX;
                y += moveStepY;
            }

            if (this.IsPassablePathFinder(endX >> 8, endY >> 8))
            {
                output.m_x = endX;
                output.m_y = endY;

                return(true);
            }

            return(false);
        }
        public bool GetWallInPassableLine(int startX, int startY, int endX, int endY, LogicVector2 output)
        {
            int distanceX = endX - startX;
            int distanceY = endY - startY;
            int moveStepX;
            int moveStepY;
            int length;

            int wallX = 0;
            int wallY = 0;

            bool hasWall = false;

            if (LogicMath.Abs(distanceY) < LogicMath.Abs(distanceX))
            {
                moveStepX = distanceX > 0 ? 256 : -256;
                moveStepY = (distanceY << 8) / LogicMath.Abs(distanceX);
                length    = distanceX / moveStepX;
            }
            else if (LogicMath.Abs(distanceX) >= LogicMath.Abs(distanceY))
            {
                moveStepX = distanceX > 0 ? 256 : -256;
                moveStepY = distanceY > 0 ? 256 : -256;
                length    = distanceX / moveStepX;
            }
            else
            {
                moveStepX = (distanceX << 8) / LogicMath.Abs(distanceY);
                moveStepY = distanceY > 0 ? 256 : -256;
                length    = distanceY / moveStepY;
            }

            LogicTile tile;

            for (int i = 0, posX = startX, posY = startY; i < length; i++)
            {
                int tileX = posX >> 9;
                int tileY = posY >> 9;

                tile = this.GetTile(tileX, tileY);

                if (tile != null)
                {
                    hasWall = tile.HasWall();

                    if (hasWall)
                    {
                        goto RESULT;
                    }
                }

                wallX = posX;
                wallY = posY;
                posX += moveStepX;
                posY += moveStepY;
            }

            int endTileX = endX >> 9;
            int endTileY = endY >> 9;

            tile = this.GetTile(endTileX, endTileY);

            if (tile != null)
            {
                hasWall = tile.HasWall();

                if (hasWall)
                {
                    goto RESULT;
                }
            }

            wallX = endX;
            wallY = endY;

RESULT:

            output.m_x = wallX;
            output.m_y = wallY;

            return(hasWall);
        }
 public static int GetAngleBetween(int angle1, int angle2)
 {
     return(LogicMath.Abs(LogicMath.NormalizeAngle180(angle1 - angle2)));
 }
示例#19
0
        public void UpdateShockwavePush(int team, int targetType)
        {
            LogicVector2 position = new LogicVector2(this.GetMidX() - this.m_unk248.m_x, this.GetMidY() - this.m_unk248.m_y);
            int          length   = position.GetLength();

            if (length >= this.m_minAttackRange)
            {
                int maxRangeDistance = length - this.m_maxAttackRange;
                int maxRadius        = length;
                int minRadius        = length - 512;

                if (minRadius < this.m_minAttackRange)
                {
                    minRadius = this.m_minAttackRange;
                }

                uint minRadiusSquared = (uint)(minRadius * minRadius);
                uint maxRadiusSquared = (uint)(maxRadius * maxRadius);

                int boostSpeed         = this.m_speedMod * maxRangeDistance / this.m_maxAttackRange;
                int boostTime          = this.m_statusEffectTime * maxRangeDistance / (16 * this.m_maxAttackRange);
                int shockwaveArcLength = this.GetShockwaveArcLength();

                LogicArrayList <LogicComponent> components = this.GetComponentManager().GetComponents(LogicComponentType.MOVEMENT);
                LogicVector2 pushBackPosition = new LogicVector2();

                for (int i = 0; i < components.Size(); i++)
                {
                    LogicMovementComponent movementComponent = (LogicMovementComponent)components[i];
                    LogicGameObject        parent            = movementComponent.GetParent();
                    LogicHitpointComponent hitpointComponent = parent.GetHitpointComponent();

                    if (!parent.IsHidden())
                    {
                        if (hitpointComponent == null || hitpointComponent.GetTeam() != team)
                        {
                            if (hitpointComponent != null && hitpointComponent.GetParent().IsFlying())
                            {
                                if (targetType == 1)
                                {
                                    continue;
                                }
                            }
                            else if (targetType == 0)
                            {
                                continue;
                            }

                            int distanceX = parent.GetMidX() - this.m_unk248.m_x;
                            int distanceY = parent.GetMidY() - this.m_unk248.m_y;

                            if (LogicMath.Abs(distanceX) <= maxRadius &&
                                LogicMath.Abs(distanceY) <= maxRadius)
                            {
                                int distance = distanceX * distanceX + distanceY * distanceY;

                                if (distance <= maxRadiusSquared && distance >= minRadiusSquared)
                                {
                                    if ((distanceX | distanceY) == 0)
                                    {
                                        distanceX = 1;
                                    }

                                    pushBackPosition.Set(distanceX, distanceY);

                                    int pushBackLength = pushBackPosition.Normalize(512);
                                    int angle          =
                                        LogicMath.Abs(LogicMath.NormalizeAngle180(LogicMath.NormalizeAngle180(pushBackPosition.GetAngle()) -
                                                                                  LogicMath.NormalizeAngle180(this.m_shockwaveAngle)));

                                    if (angle < shockwaveArcLength / 2)
                                    {
                                        int pushBack = 100 * (this.m_maxAttackRange + 256 - pushBackLength) / 512;

                                        if (pushBack > this.m_shockwavePushStrength)
                                        {
                                            pushBack = this.m_shockwavePushStrength;
                                        }

                                        movementComponent.GetMovementSystem().ManualPushBack(pushBackPosition, pushBack, 750, this.m_globalId);

                                        if (boostSpeed != 0)
                                        {
                                            movementComponent.GetMovementSystem().Boost(boostSpeed, boostTime);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
示例#20
0
        public override void SubTick()
        {
            base.SubTick();

            this.m_areaShieldSpeed = 0;

            bool isInAreaShield   = false;
            int  damagePercentage = 100;

            if (this.m_myTeam == 1)
            {
                LogicVector2 areaShield = new LogicVector2();

                if (this.m_level.GetAreaShield(this.GetMidX(), this.GetMidY(), areaShield))
                {
                    this.m_areaShieldSpeed = areaShield.m_x;

                    isInAreaShield   = true;
                    damagePercentage = 0;
                }
            }

            if (this.m_targetReached)
            {
                if (this.m_damageTime > 0)
                {
                    this.UpdateDamage(damagePercentage);
                }
            }
            else
            {
                if (this.m_targetGroups)
                {
                    if (this.m_target != null && this.m_groups != null)
                    {
                        LogicCombatComponent combatComponent = this.m_groups.GetCombatComponent();

                        if (combatComponent != null && !combatComponent.IsInRange(this.m_target))
                        {
                            this.m_target = null;
                        }
                    }
                }

                if (isInAreaShield)
                {
                    this.m_areaShieldDelay = LogicMath.Min(this.m_areaShieldDelay + 16, 200);
                }
                else if (this.m_areaShieldDelay > 0)
                {
                    this.m_areaShieldDelay = LogicMath.Max(this.m_areaShieldDelay - 4, 0);
                }

                if (this.m_areaShieldDelay == 0)
                {
                    if (this.m_target != null && this.m_target.GetMovementComponent() != null)
                    {
                        this.m_targetPosition.Set(this.m_target.GetMidX() * 8, this.m_target.GetMidY() * 8);
                        this.m_targetPosition.Add(this.m_unk168);
                    }
                }
                else if (this.m_target != null && this.m_target.GetMovementComponent() != null)
                {
                    int x = this.m_unk168.m_x + this.m_target.GetMidX() * 8;
                    int y = this.m_unk168.m_y + this.m_target.GetMidY() * 8;

                    LogicVector2 tmp1 = new LogicVector2(x - this.m_unk276.m_x, y - this.m_unk276.m_y);
                    LogicVector2 tmp2 = new LogicVector2(this.m_unk152.m_x, this.m_unk152.m_y);

                    int length1 = tmp1.Normalize(512);
                    int length2 = tmp2.Normalize(512);

                    int angle1 = tmp1.GetAngle();
                    int angle2 = tmp2.GetAngle();

                    if (LogicMath.Abs(LogicMath.NormalizeAngle180(angle1 - angle2)) <= 30)
                    {
                        this.m_targetPosition.m_x += LogicMath.Clamp(x - this.m_targetPosition.m_x, length1 / -500, length1 / 500);
                        this.m_targetPosition.m_y += LogicMath.Clamp(y - this.m_targetPosition.m_y, length1 / -500, length1 / 500);
                    }
                    else
                    {
                        this.m_target = null;
                    }
                }

                this.m_unk144.m_x = this.m_targetPosition.m_x - this.m_unk276.m_x;
                this.m_unk144.m_y = this.m_targetPosition.m_y - this.m_unk276.m_y;

                int distance = (200 - this.m_areaShieldDelay) * (8 * this.GetSpeed() - 8 * this.m_areaShieldSpeed) / 200 + 8 * this.m_areaShieldSpeed;

                if (distance * distance >= this.m_unk144.GetDistanceSquaredTo(0, 0))
                {
                    this.TargetReached(damagePercentage);
                }
                else
                {
                    this.m_unk152.m_x = this.m_unk144.m_x;
                    this.m_unk152.m_y = this.m_unk144.m_y;

                    this.m_unk144.Normalize(distance);

                    this.m_unk276.m_x += this.m_unk144.m_x;
                    this.m_unk276.m_y += this.m_unk144.m_y;

                    this.SetPositionXY(this.m_unk276.m_x >> 3, this.m_unk276.m_y >> 3);

                    this.m_unk160.m_x = this.m_unk144.m_x >> 3;
                    this.m_unk160.m_y = this.m_unk144.m_y >> 3;
                }

                if (this.m_shockwavePushStrength > 0)
                {
                    this.UpdateShockwavePush(this.m_myTeam, this.m_flyingTarget ? 0 : 1);
                }

                if (this.m_penetrating)
                {
                    this.UpdatePenetrating(damagePercentage);
                }

                this.m_travelTime += 16;
            }
        }
示例#21
0
        public void PushTrap(LogicVector2 position, int time, int id, bool ignorePrevPush, bool verifyPushPosition)
        {
            if (this.m_pushTime <= 0 || ignorePrevPush)
            {
                if (this.m_parent != null && this.m_parent.GetJump() <= 0 && !this.m_parent.GetParent().IsHero())
                {
                    LogicGameObject parent = this.m_parent.GetParent();

                    if (!parent.IsHero())
                    {
                        if (id != 0 && !ignorePrevPush)
                        {
                            int idx = -1;

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

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

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

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

                        this.m_pushTime     = time;
                        this.m_pushInitTime = time;
                        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 + position.m_x;
                        this.m_pushBackEndPosition.m_y   = this.m_position.m_y + position.m_y;

                        if (verifyPushPosition)
                        {
                            int pushBackEndPositionX = this.m_pushBackEndPosition.m_x;
                            int pushBackEndPositionY = this.m_pushBackEndPosition.m_y;

                            if (LogicMath.Max(LogicMath.Abs(position.m_x), LogicMath.Abs(position.m_y)) != 0)
                            {
                                LogicTileMap tileMap = parent.GetLevel().GetTileMap();

                                if (!tileMap.IsPassablePathFinder(pushBackEndPositionX >> 8, pushBackEndPositionY >> 8))
                                {
                                    LogicVector2 pos = new LogicVector2();
                                    LogicRandom  rnd = new LogicRandom(pushBackEndPositionX + pushBackEndPositionY);

                                    tileMap.GetNearestPassablePosition(pushBackEndPositionX + rnd.Rand(512) - 256,
                                                                       pushBackEndPositionY + rnd.Rand(512) - 256, pos, 2048);

                                    pushBackEndPositionX = pos.m_x;
                                    pushBackEndPositionY = pos.m_y;
                                }

                                if (!tileMap.IsPassablePathFinder(pushBackEndPositionX >> 8, pushBackEndPositionY >> 8))
                                {
                                    Debugger.Warning("PushTrap->ended on inmovable");
                                }
                            }

                            this.m_pushBackEndPosition.m_x = pushBackEndPositionX;
                            this.m_pushBackEndPosition.m_y = pushBackEndPositionY;
                        }

                        this.m_ignorePush = verifyPushPosition;

                        int angle = position.GetAngle();
                        this.m_direction = angle + (angle <= 180 ? 180 : -180);
                    }
                }
            }
        }