public virtual bool TestGameObject(LogicGameObject gameObject)
        {
            if (this.m_gameObjectTypes != null && !this.m_gameObjectTypes[(int)gameObject.GetGameObjectType()])
            {
                return(false);
            }
            if (this.m_ignoreGameObjects != null && this.m_ignoreGameObjects.IndexOf(gameObject) != -1)
            {
                return(false);
            }

            if (this.m_team != -1)
            {
                LogicHitpointComponent hitpointComponent = gameObject.GetHitpointComponent();

                if (hitpointComponent != null)
                {
                    if (hitpointComponent.GetHitpoints() > 0)
                    {
                        bool isEnemy = hitpointComponent.IsEnemyForTeam(this.m_team);

                        if (isEnemy || !this.m_enemyOnly)
                        {
                            return(this.m_enemyOnly || !isEnemy);
                        }
                    }

                    return(false);
                }
            }

            return(true);
        }
Example #2
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);
                            }
                        }
                    }
                }
            }
        }
Example #3
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;
            }
        }
Example #4
0
        public bool TileOkForTombstone(LogicTile tile)
        {
            if (tile != null && !tile.IsFullyNotPassable())
            {
                for (int i = 0; i < tile.GetGameObjectCount(); i++)
                {
                    LogicGameObject gameObject = tile.GetGameObject(i);

                    if (gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING ||
                        gameObject.GetGameObjectType() == LogicGameObjectType.OBSTACLE ||
                        gameObject.GetGameObjectType() == LogicGameObjectType.TRAP ||
                        gameObject.GetGameObjectType() == LogicGameObjectType.DECO)
                    {
                        return(false);
                    }
                }

                return(true);
            }

            return(false);
        }
        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();
                                }
                            }
                        }
                    }
                }
            }
        }
Example #6
0
        public void UpdateTargetDamage(LogicGameObject target, int damage)
        {
            if (target != null && !this.m_dummy && target.GetHitpointComponent() != null)
            {
                int totalDamage = damage;

                if (LogicCombatComponent.IsPreferredTarget(this.m_preferredTarget, target))
                {
                    totalDamage = damage * this.m_preferredTargetDamageMod / 100;
                }

                if (totalDamage >= 0 || target.GetData().GetDataType() == LogicDataType.HERO &&
                    (totalDamage = totalDamage * LogicDataTables.GetGlobals().GetHeroHealMultiplier() / 100) > 0 || !target.IsPreventsHealing())
                {
                    if (this.m_damageRadius <= 0)
                    {
                        target.GetHitpointComponent().CauseDamage(totalDamage, this.m_groupsId, this.m_groups);
                    }
                    else
                    {
                        this.m_level.AreaDamage(this.m_groupsId, target.GetMidX(), target.GetMidY(), this.m_damageRadius, damage, this.m_preferredTarget,
                                                this.m_preferredTargetDamageMod, this.m_hitEffect, this.m_myTeam, this.m_unk160, this.m_flyingTarget ? 0 : 1, 0, this.m_pushBack,
                                                this.m_gravity, false, 100, 0, this.m_groups, 100, 0);
                    }
                }

                int slowdownDefensePercent = this.GetProjectileData().GetSlowdownDefensePercent();

                if (slowdownDefensePercent > 0 && target.GetGameObjectType() == LogicGameObjectType.BUILDING)
                {
                    LogicCombatComponent combatComponent = target.GetCombatComponent();

                    if (combatComponent != null)
                    {
                        combatComponent.Boost(100, -slowdownDefensePercent, 120);
                    }
                }
            }
        }
Example #7
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);
                                }
                            }
                        }
                    }
                }
            }
        }
Example #8
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.
                            }
                        }
                    }
                }
            }
        }
Example #9
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();
        }
        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);
                                }
                            }
                        }
                    }
                }
            }
        }