Beispiel #1
0
        public void CheckSummons()
        {
            for (int i = 0; i < this.m_summonTroops.Size(); i++)
            {
                LogicCharacter character = this.m_summonTroops[i];

                if (!character.IsAlive())
                {
                    this.m_summonTroops.Remove(i--);
                }
                else
                {
                    if (character.m_spawnTime > 0 && !this.IsAlive())
                    {
                        this.m_summonTroops.Remove(i--);
                        this.m_hasSpawnDelay = false;

                        LogicHitpointComponent hitpointComponent = character.GetHitpointComponent();

                        if (hitpointComponent != null)
                        {
                            hitpointComponent.SetHitpoints(0);
                        }

                        this.m_level.UpdateBattleStatus();
                    }
                }
            }
        }
        public void CreateProjectile(LogicProjectileData data)
        {
            LogicTrapData trapData = this.GetTrapData();

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

            LogicGameObject closestGameObject = null;

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

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

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

                                int lengthSquared = position.GetLengthSquared();

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

            position.Destruct();

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

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

                this.GetGameObjectManager().AddGameObject(projectile, -1);
            }
        }
Beispiel #3
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);
                            }
                        }
                    }
                }
            }
        }
Beispiel #4
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;
            }
        }
Beispiel #5
0
        public void SetTroopChild(LogicCharacter character, int idx)
        {
            this.m_parent = character;

            if (character != null)
            {
                this.m_troopChildX = (character.GetCharacterData().GetChildTroopX(idx) << 9) / 100;
                this.m_troopChildY = (character.GetCharacterData().GetChildTroopY(idx) << 9) / 100;
                this.m_troopChild  = true;
            }
        }
Beispiel #6
0
        public void UpdateAutoMerge()
        {
            if (this.m_autoMergeTime > 0)
            {
                int autoMergeGroupSize = this.GetCharacterData().GetAutoMergeGroupSize();
                int autoMergeDistance  = this.GetCharacterData().GetAutoMergeDistance();

                if (autoMergeGroupSize > 0)
                {
                    LogicArrayList <LogicGameObject> characters = this.GetGameObjectManager().GetGameObjects(LogicGameObjectType.CHARACTER);
                    LogicCharacter closestCharacter             = null;

                    for (int i = 0; i < characters.Size(); i++)
                    {
                        LogicCharacter character = (LogicCharacter)characters[i];

                        if (character != this)
                        {
                            if (character.GetData() == this.GetData())
                            {
                                if (this.m_autoMergeSize == 0 && character.m_autoMergeSize >= autoMergeGroupSize)
                                {
                                    if (character.GetHitpointComponent().GetTeam() == this.GetHitpointComponent().GetTeam() && character.IsAlive())
                                    {
                                        if (character.m_autoMergeTime > 0)
                                        {
                                            int distanceSquared = this.GetPosition().GetDistanceSquared(character.GetPosition());

                                            if (distanceSquared <= autoMergeDistance * autoMergeDistance)
                                            {
                                                closestCharacter = character;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    if (closestCharacter != null)
                    {
                        closestCharacter.m_autoMergeSize += 1;
                        closestCharacter.GetCombatComponent().SetMergeDamage(90 * closestCharacter.m_autoMergeSize);
                        closestCharacter.GetHitpointComponent()
                        .SetMaxHitpoints(closestCharacter.GetCharacterData().GetHitpoints(this.m_upgradeLevel) * (closestCharacter.m_autoMergeSize + 1));
                        closestCharacter.GetHitpointComponent()
                        .SetHitpoints(closestCharacter.GetCharacterData().GetHitpoints(this.m_upgradeLevel) * (closestCharacter.m_autoMergeSize + 1));

                        this.GetGameObjectManager().RemoveGameObject(this);
                    }
                }
            }
        }
Beispiel #7
0
        public static LogicGameObject CreateGameObject(LogicGameObjectData data, LogicLevel level, int villageType)
        {
            LogicGameObject gameObject = null;

            switch (data.GetDataType())
            {
            case LogicDataType.BUILDING:
                gameObject = new LogicBuilding(data, level, villageType);
                break;

            case LogicDataType.CHARACTER:
            case LogicDataType.HERO:
                gameObject = new LogicCharacter(data, level, villageType);
                break;

            case LogicDataType.PROJECTILE:
                gameObject = new LogicProjectile(data, level, villageType);
                break;

            case LogicDataType.OBSTACLE:
                gameObject = new LogicObstacle(data, level, villageType);
                break;

            case LogicDataType.TRAP:
                gameObject = new LogicTrap(data, level, villageType);
                break;

            case LogicDataType.ALLIANCE_PORTAL:
                gameObject = new LogicAlliancePortal(data, level, villageType);
                break;

            case LogicDataType.DECO:
                gameObject = new LogicDeco(data, level, villageType);
                break;

            case LogicDataType.SPELL:
                gameObject = new LogicSpell(data, level, villageType);
                break;

            case LogicDataType.VILLAGE_OBJECT:
                gameObject = new LogicVillageObject(data, level, villageType);
                break;

            default:
            {
                Debugger.Warning("Trying to create game object with data that does not inherit LogicGameObjectData. GlobalId=" + data.GetGlobalID());
                break;
            }
            }

            return(gameObject);
        }
Beispiel #8
0
        public override void DeathEvent()
        {
            LogicHitpointComponent hitpointComponent = this.GetHitpointComponent();
            LogicCharacterData     data = this.GetCharacterData();

            if (hitpointComponent != null && hitpointComponent.GetTeam() == 1 && !this.IsHero() && !data.IsSecondaryTroop() &&
                this.m_level.GetVillageType() == 0 && this.m_allianceUnit)
            {
                LogicAvatar homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar();

                homeOwnerAvatar.RemoveAllianceUnit(data, this.m_upgradeLevel);
                homeOwnerAvatar.GetChangeListener().AllianceUnitRemoved(data, this.m_upgradeLevel);
            }

            if (data.GetSpecialAbilityType() != LogicCharacterData.SPECIAL_ABILITY_TYPE_RESPAWN_AS_CANNON ||
                data.GetSpecialAbilityLevel(this.m_upgradeLevel) <= 0)
            {
                if (data.GetSpecialAbilityType() == LogicCharacterData.SPECIAL_ABILITY_TYPE_SPAWN_UNITS)
                {
                    if (data.GetSpecialAbilityLevel(this.m_upgradeLevel) > 0)
                    {
                        this.CheckSpawning(null, data.GetSpecialAbilityAttribute(this.m_upgradeLevel), 0, 0);
                    }
                }
                else if (data.GetSecondaryTroop() != null)
                {
                    this.CheckSpawning(null, 0, 0, 0);
                }
            }
            else if (!this.m_ejected)
            {
                this.CheckSpawning(LogicDataTables.GetCharacterByName("MovingCannonSecondary", null), 1, data.GetSpecialAbilityAttribute(this.m_upgradeLevel), 500);
            }

            this.AddTombstoneIfNeeded();

            if (this.m_parent != null)
            {
                this.m_parent.RemoveChildren(this);
                this.m_parent = null;
            }

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

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

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

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

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

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

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

                position.Destruct();
            }
        }
        public 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();
                                }
                            }
                        }
                    }
                }
            }
        }
Beispiel #11
0
        public bool DuplicateCharacter()
        {
            if (this.m_duplicateHousingSpace < 0)
            {
                this.m_duplicateHousingSpace = this.GetSpellData().GetDuplicateHousing(this.m_upgradeLevel);
            }

            if (this.m_duplicableCharacters != null)
            {
                if (this.m_duplicableCharacters.Size() > 0)
                {
                    int minHousingSpace = ((LogicCharacter)this.m_duplicableCharacters[0]).GetCharacterData().GetHousingSpace();

                    for (int i = 0; i < this.m_duplicableCharacters.Size(); i++)
                    {
                        LogicCharacter     character = (LogicCharacter)this.m_duplicableCharacters[(i + this.m_duplicateCharacterOffset) % this.m_duplicableCharacters.Size()];
                        LogicCharacterData data      = character.GetCharacterData();

                        int housingSpace = data.GetHousingSpace();

                        if (minHousingSpace > housingSpace)
                        {
                            minHousingSpace = housingSpace;
                        }

                        if (this.DuplicateCharacter(data, character.GetUpgradeLevel()))
                        {
                            return(true);
                        }
                    }

                    return(false);
                }

                return(this.DuplicateCharacter(this.m_duplicateCharacterData, this.m_duplicateCharacterUpgradeLevel));
            }

            return(this.m_duplicateCharacterData != null && this.DuplicateCharacter(this.m_duplicateCharacterData, this.m_duplicateCharacterUpgradeLevel));
        }
Beispiel #12
0
        public void RemoveChildren(LogicCharacter children)
        {
            if (this.m_childrens.Size() > 0)
            {
                int idx = this.m_childrens.IndexOf(children);

                if (idx != -1)
                {
                    this.m_childrens.Remove(idx);

                    if (this.m_childrens.Size() != 0)
                    {
                        int childTroopLost = this.GetCharacterData().GetChildTroopCount() - this.m_childrens.Size();
                        this.GetMovementComponent().GetMovementSystem()
                        .SetSpeed(this.GetCharacterData().GetSpeed() - this.GetCharacterData().GetSpeedDecreasePerChildTroopLost() * childTroopLost);
                    }
                    else
                    {
                        this.GetHitpointComponent().Kill();
                    }
                }
            }
        }
Beispiel #13
0
        public LogicCharacter(LogicGameObjectData data, LogicLevel level, int villageType) : base(data, level, villageType)
        {
            LogicCharacterData characterData = (LogicCharacterData)data;

            this.m_flying = characterData.IsFlying();

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

            int childTroopCount = characterData.GetChildTroopCount();

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

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

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

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

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

            if (characterData.IsUnderground())
            {
                this.GetCombatComponent().SetUndergroundTime(3600000);
            }
        }
Beispiel #14
0
        public LogicCharacter CreateDuplicateCharacter(LogicCharacterData data, int upgLevel, int x, int y)
        {
            LogicCharacter character = (LogicCharacter)LogicGameObjectFactory.CreateGameObject(data, this.m_level, this.m_villageType);

            character.SetUpgradeLevel(upgLevel);
            character.SetDuplicate(true, this.GetSpellData().GetDuplicateLifetime(this.m_upgradeLevel) / 64 + 1);
            character.SetInitialPosition(x, y);

            if (data.IsJumper())
            {
                character.GetMovementComponent().EnableJump(3600000);
                character.GetCombatComponent().RefreshTarget(true);
            }

            if (data.IsUnderground())
            {
                LogicCombatComponent combatComponent = character.GetCombatComponent();

                combatComponent.SetUndergroundTime(3600000);
                combatComponent.RefreshTarget(true);
            }

            if (LogicDataTables.IsSkeleton(data))
            {
                LogicCombatComponent combatComponent = character.GetCombatComponent();

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

            this.GetGameObjectManager().AddGameObject(character, -1);
            // Listener.
            return(character);
        }
Beispiel #15
0
        public void SpawnSummon(int x, int y)
        {
            LogicSpellData     data       = this.GetSpellData();
            LogicCharacterData summonData = data.GetSummonTroop();
            LogicVector2       position   = new LogicVector2();

            int summonCount        = data.GetUnitsToSpawn(this.m_upgradeLevel);
            int spawnDuration      = data.GetSpawnDuration(this.m_upgradeLevel);
            int totalSpawnDuration = -(spawnDuration * data.GetSpawnFirstGroupSize());

            for (int i = 0, k = 0, angle = y + 7 * x; i < summonCount; i++, k += 7, angle += 150, totalSpawnDuration += spawnDuration)
            {
                if (!summonData.IsFlying())
                {
                    if (!this.m_level.GetTileMap().GetNearestPassablePosition(this.GetX(), this.GetY(), position, 1536))
                    {
                        return;
                    }
                }
                else
                {
                    position.m_x = x + LogicMath.GetRotatedX(summonData.GetSecondarySpawnOffset(), 0, angle);
                    position.m_y = y + LogicMath.GetRotatedY(summonData.GetSecondarySpawnOffset(), 0, angle);
                }

                LogicCharacter summon = (LogicCharacter)LogicGameObjectFactory.CreateGameObject(summonData, this.m_level, this.m_villageType);

                summon.GetHitpointComponent().SetTeam(0);
                summon.SetInitialPosition(position.m_x, position.m_y);

                LogicRandom random = new LogicRandom(k + this.m_globalId);

                int rnd = ((random.Rand(150) << 9) + 38400) / 100;

                position.Set(LogicMath.Cos(angle, rnd),
                             LogicMath.Sin(angle, rnd));

                int pushBackSpeed = summonData.GetPushbackSpeed() > 0 ? summonData.GetPushbackSpeed() : 1;
                int pushBackTime  = 2 * rnd / (3 * pushBackSpeed);
                int spawnDelay    = pushBackTime + totalSpawnDuration / summonCount;

                if (data.GetSpawnFirstGroupSize() > 0)
                {
                    spawnDelay = LogicMath.Max(200, spawnDelay);
                }

                summon.SetSpawnTime(spawnDelay);
                summon.GetMovementComponent().GetMovementSystem().PushTrap(position, pushBackTime, 0, false, false);

                if (summon.GetCharacterData().IsJumper())
                {
                    summon.GetMovementComponent().EnableJump(3600000);
                    summon.GetCombatComponent().RefreshTarget(true);
                }

                LogicCombatComponent combatComponent = summon.GetCombatComponent();

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

                this.GetGameObjectManager().AddGameObject(summon, -1);
            }
        }
Beispiel #16
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.
                            }
                        }
                    }
                }
            }
        }
Beispiel #17
0
        public void CheckSpawning(LogicCharacterData spawnCharacterData, int spawnCount, int spawnUpgradeLevel, int invulnerabilityTime)
        {
            LogicCharacterData data = this.GetCharacterData();

            if (spawnCharacterData == null)
            {
                spawnCharacterData = data.GetSecondaryTroop();

                if (spawnCharacterData == null)
                {
                    spawnCharacterData = data.GetAttackerItemData(this.m_upgradeLevel).GetSummonTroop();

                    if (spawnCharacterData == null)
                    {
                        return;
                    }
                }
            }

            if (spawnCharacterData.IsSecondaryTroop() || this.IsHero())
            {
                int totalSpawnCount = spawnCount;
                int upgLevel        = this.m_upgradeLevel;

                if (upgLevel >= spawnCharacterData.GetUpgradeLevelCount())
                {
                    upgLevel = spawnCharacterData.GetUpgradeLevelCount() - 1;
                }

                if (this.IsHero())
                {
                    if (this.m_summonSpawnCount >= spawnCount)
                    {
                        return;
                    }

                    upgLevel        = spawnUpgradeLevel;
                    totalSpawnCount = LogicMath.Max(0, LogicMath.Min(3, spawnCount - this.m_summonSpawnCount));
                }
                else
                {
                    if (data.GetSecondaryTroopCount(this.m_upgradeLevel) != 0)
                    {
                        totalSpawnCount = data.GetSecondaryTroopCount(this.m_upgradeLevel);
                    }
                    else if (spawnCount == 0)
                    {
                        totalSpawnCount = data.GetAttackerItemData(this.m_upgradeLevel).GetSummonTroopCount();

                        if (this.m_summonTroops.Size() + totalSpawnCount > data.GetAttackerItemData(this.m_upgradeLevel).GetSummonLimit())
                        {
                            totalSpawnCount = data.GetAttackerItemData(this.m_upgradeLevel).GetSummonLimit() - this.m_summonTroops.Size();
                        }
                    }
                }

                if (totalSpawnCount > 0)
                {
                    LogicVector2 position = new LogicVector2();
                    LogicRandom  random   = new LogicRandom(this.m_globalId);

                    int  team = this.GetHitpointComponent().GetTeam();
                    bool randomizeSecSpawnDist = this.GetCharacterData().GetRandomizeSecSpawnDist();

                    for (int i = 0, j = 0, k = 0; i < totalSpawnCount; i++, j += 360, k += 100)
                    {
                        int seed = j / totalSpawnCount;

                        if (this.IsHero())
                        {
                            seed = 360 * (i + this.m_summonSpawnCount) / LogicMath.Max(1, LogicMath.Min(6, spawnCount));
                        }

                        int rnd = 59 * this.m_globalId % 360 + seed;

                        if (spawnCharacterData.IsFlying())
                        {
                            LogicCharacterData parentData = this.GetCharacterData();

                            position.Set(this.GetX() + LogicMath.GetRotatedX(parentData.GetSecondarySpawnOffset(), 0, rnd),
                                         this.GetY() + LogicMath.GetRotatedY(parentData.GetSecondarySpawnOffset(), 0, rnd));
                        }
                        else if (spawnCharacterData.GetSpeed() == 0)
                        {
                            position.Set(this.GetX(), this.GetY());
                        }
                        else
                        {
                            if (!this.m_level.GetTileMap().GetNearestPassablePosition(this.GetX(), this.GetY(), position, 1536))
                            {
                                continue;
                            }
                        }

                        LogicCharacter spawnGameObject = (LogicCharacter)LogicGameObjectFactory.CreateGameObject(spawnCharacterData, this.m_level, this.m_villageType);

                        if (this.GetCharacterData().GetAttackerItemData(this.m_upgradeLevel).GetSummonTroop() != null || this.IsHero())
                        {
                            this.m_summonTroops.Add(spawnGameObject);
                        }

                        spawnGameObject.GetHitpointComponent().SetTeam(team);
                        spawnGameObject.SetUpgradeLevel(upgLevel);

                        spawnGameObject.SetInitialPosition(position.m_x, position.m_y);

                        if (this.m_duplicate)
                        {
                            spawnGameObject.m_duplicateLifeTime = this.m_duplicateLifeTime;
                            spawnGameObject.m_duplicate         = true;
                        }

                        if (!this.IsHero())
                        {
                            spawnGameObject.m_summoner = (LogicCharacterData)this.m_data;
                        }

                        if (invulnerabilityTime > 0)
                        {
                            spawnGameObject.GetHitpointComponent().SetInvulnerabilityTime(invulnerabilityTime);
                        }

                        int secondarySpawnDistance = this.IsHero() ? 768 : this.GetCharacterData().GetSecondarySpawnDistance();

                        if (secondarySpawnDistance > 0)
                        {
                            if (randomizeSecSpawnDist)
                            {
                                secondarySpawnDistance = (int)(random.Rand(secondarySpawnDistance) + ((uint)secondarySpawnDistance >> 1));
                            }

                            position.Set(LogicMath.Cos(rnd, secondarySpawnDistance),
                                         LogicMath.Sin(rnd, secondarySpawnDistance));

                            int pushBackSpeed = spawnGameObject.GetCharacterData().GetPushbackSpeed();

                            if (pushBackSpeed <= 0)
                            {
                                pushBackSpeed = 1;
                            }

                            int pushBackTime = 2 * secondarySpawnDistance / (3 * pushBackSpeed);

                            if (this.GetHitpointComponent().GetHitpoints() > 0)
                            {
                                if (this.GetAttackerItemData().GetSummonTroop() != null)
                                {
                                    spawnGameObject.SetSpawnTime(pushBackTime);
                                }
                                else if (this.IsHero())
                                {
                                    spawnGameObject.SetSpawnTime(pushBackTime + k);
                                }
                            }

                            spawnGameObject.GetMovementComponent().GetMovementSystem().PushTrap(position, pushBackTime, 0, false, false);
                        }

                        if (team == 1 || spawnGameObject.GetCharacterData().IsJumper())
                        {
                            spawnGameObject.GetMovementComponent().EnableJump(3600000);
                            spawnGameObject.GetCombatComponent().RefreshTarget(true);
                        }

                        if (team == 1)
                        {
                            if (LogicDataTables.GetGlobals().AllianceTroopsPatrol())
                            {
                                spawnGameObject.GetCombatComponent().SetSearchRadius(LogicDataTables.GetGlobals().GetClanCastleRadius() >> 9);

                                if (this.GetMovementComponent().GetBaseBuilding() != null)
                                {
                                    spawnGameObject.GetMovementComponent().SetBaseBuilding(this.GetMovementComponent().GetBaseBuilding());
                                }
                            }
                        }

                        this.GetGameObjectManager().AddGameObject(spawnGameObject, -1);

                        if (this.IsHero())
                        {
                            ++this.m_summonSpawnCount;
                        }
                    }

                    position.Destruct();
                }
            }
            else
            {
                Debugger.Warning("checkSpawning: trying to spawn normal troops!");
            }
        }
        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);
                                }
                            }
                        }
                    }
                }
            }
        }