Example #1
0
        public void AddTombstoneIfNeeded()
        {
            if (!this.m_ejected && this.m_level.GetTombStoneCount() < 40)
            {
                int tileX = this.GetTileX();
                int tileY = this.GetTileY();

                LogicTileMap tileMap = this.m_level.GetTileMap();
                LogicTile    tile    = tileMap.GetTile(tileX, tileY);

                if (!this.TileOkForTombstone(tile))
                {
                    int minDistance  = 0;
                    int closestTileX = -1;
                    int closestTileY = -1;

                    for (int i = -1; i < 2; i++)
                    {
                        int offsetX = ((i + tileX) << 9) | 256;
                        int offsetY = 256 - (tileY << 9);

                        for (int j = -1; j < 2; j++, offsetY -= 512)
                        {
                            tile = tileMap.GetTile(tileX + i, tileY + j);

                            if (this.TileOkForTombstone(tile))
                            {
                                int distanceX = this.GetX() - offsetX;
                                int distanceY = this.GetY() + offsetY;
                                int distance  = distanceX * distanceX + distanceY * distanceY;

                                if (minDistance == 0 || distance < minDistance)
                                {
                                    minDistance  = distance;
                                    closestTileX = tileX + i;
                                    closestTileY = tileY + j;
                                }
                            }
                        }
                    }

                    if (minDistance == 0)
                    {
                        return;
                    }

                    tileX = closestTileX;
                    tileY = closestTileY;
                }

                LogicObstacleData tombstoneData = this.GetCharacterData().GetTombstone();

                if (tombstoneData != null)
                {
                    LogicObstacle tombstone = (LogicObstacle)LogicGameObjectFactory.CreateGameObject(tombstoneData, this.m_level, this.m_villageType);
                    tombstone.SetInitialPosition(tileX << 9, tileY << 9);
                    this.GetGameObjectManager().AddGameObject(tombstone, -1);
                }
            }
        }
Example #2
0
        public void SpawnObstacle(int x, int y, int radius)
        {
            int tileX = x >> 9;
            int tileY = y >> 9;

            if (!this.TileOkForSpawn(this.m_level.GetTileMap().GetTile(tileX, tileY)))
            {
                int minSquare = 0;
                int minTileX  = -1;
                int minTileY  = -1;

                for (int i = -radius; i <= radius; i++)
                {
                    int posX = tileX + i;
                    int midX = (posX << 9) | 256;
                    int midY = (radius << 9) - 256 - ((y >> 9) << 9);

                    for (int j = -radius; j <= radius; j++)
                    {
                        int posY = tileY + j;

                        if (this.TileOkForSpawn(this.m_level.GetTileMap().GetTile(posX, posY)))
                        {
                            int goX = this.GetX();
                            int goY = this.GetY();

                            int square = (goX - midX) * (goX - midX) + (goY + midY) * (goY + midY);

                            if (minSquare == 0 || square < minSquare)
                            {
                                minSquare = square;
                                minTileX  = posX;
                                minTileY  = posY;
                            }
                        }

                        midY -= 512;
                    }
                }

                if (minSquare == 0)
                {
                    return;
                }

                tileX = minTileX;
                tileY = minTileY;
            }

            LogicObstacleData data = this.GetSpellData().GetSpawnObstacle();

            if (data != null)
            {
                LogicGameObject gameObject = LogicGameObjectFactory.CreateGameObject(data, this.m_level, this.GetVillageType());
                gameObject.SetInitialPosition(tileX << 9, tileY << 9);
                this.GetGameObjectManager().AddGameObject(gameObject, -1);
            }
        }
        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);
            }
        }
Example #4
0
        public void StartAbility()
        {
            if (this.IsHero())
            {
                LogicHeroData heroData = (LogicHeroData)this.m_data;

                this.m_abilityCooldown    = 60 * heroData.GetAbilityCooldown() / 4000;
                this.m_abilityTriggerTime = 5;
                this.m_abilityTime        = 60 * heroData.GetAbilityTime(this.m_upgradeLevel) / 20000;
                this.m_summonSpawnCount   = 0;

                this.GetHitpointComponent().CauseDamage(-100 * heroData.GetAbilityHealthIncrease(this.m_upgradeLevel), 0, this);

                this.m_abilityAttackCount = this.GetCombatComponent().GetHitCount() + heroData.GetAbilityAttackCount(this.m_upgradeLevel);

                if (heroData.GetAbilityDelay() > 0)
                {
                    this.GetCombatComponent().SetAttackDelay(0, heroData.GetAbilityDelay());
                    // Listener.
                }

                LogicSpellData abilitySpellData = heroData.GetAbilitySpell(this.m_upgradeLevel);

                if (abilitySpellData != null)
                {
                    this.m_abilitySpell = (LogicSpell)LogicGameObjectFactory.CreateGameObject(abilitySpellData, this.m_level, this.m_villageType);
                    this.m_abilitySpell.SetUpgradeLevel(heroData.GetAbilitySpellLevel(this.m_upgradeLevel));
                    this.m_abilitySpell.SetInitialPosition(this.GetX(), this.GetY());
                    this.m_abilitySpell.AllowDestruction(false);

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

                if (heroData.GetActivationTime() > 0)
                {
                    this.m_activationTimeState = 1;
                    this.m_activationTime      = heroData.GetActivationTime();

                    this.GetMovementComponent().GetMovementSystem().SetFreezeTime(this.m_activationTime);
                    this.GetCombatComponent().SetActivationTime(this.m_activationTime);

                    // Listener.
                }

                this.m_abilityUsed = true;
            }
        }
        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();
            }
        }
Example #6
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);
        }
Example #7
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);
            }
        }
Example #8
0
        public override void Tick()
        {
            base.Tick();

            LogicCharacterData data = this.GetCharacterData();

            if (!this.IsAlive())
            {
                if (!this.IsHero())
                {
                    int dieDamageDelay = this.GetCharacterData().GetDieDamageDelay();
                    int prevDieTime    = this.m_dieTime;

                    this.m_dieTime += 64;

                    if (dieDamageDelay >= prevDieTime && dieDamageDelay < this.m_dieTime && (!this.m_duplicate || this.m_duplicateLifeTime >= 0))
                    {
                        this.CheckDieDamage(data.GetDieDamage(this.m_upgradeLevel), data.GetDieDamageRadius());
                        this.m_level.UpdateBattleStatus();
                    }
                }

                this.m_spawnTime     = 0;
                this.m_spawnIdleTime = 0;

                if (this.m_auraSpell != null)
                {
                    this.GetGameObjectManager().RemoveGameObject(this.m_auraSpell);
                    this.m_auraSpell = null;
                }

                if (this.m_abilitySpell != null)
                {
                    this.GetGameObjectManager().RemoveGameObject(this.m_abilitySpell);
                    this.m_abilitySpell = null;
                }

                if (this.m_retributionSpell != null)
                {
                    this.GetGameObjectManager().RemoveGameObject(this.m_retributionSpell);
                    this.m_retributionSpell = null;
                }
            }
            else
            {
                if (data.GetLoseHpPerTick() > 0)
                {
                    this.m_loseHpTime += 64;

                    if (this.m_loseHpTime > data.GetLoseHpInterval())
                    {
                        LogicHitpointComponent hitpointComponent = this.GetHitpointComponent();

                        if (hitpointComponent != null)
                        {
                            hitpointComponent.CauseDamage(100 * data.GetLoseHpPerTick(), this.m_globalId, this);
                            // Listener.
                        }

                        this.m_loseHpTime = 0;
                    }
                }

                if (data.GetAttackCount(this.m_upgradeLevel) > 0 && this.GetCombatComponent() != null && this.GetHitpointComponent() != null &&
                    this.GetCombatComponent().GetHitCount() >= data.GetAttackCount(this.m_upgradeLevel))
                {
                    this.GetHitpointComponent().Kill();
                }

                this.m_spawnTime     = LogicMath.Max(this.m_spawnTime - 64, 0);
                this.m_spawnIdleTime = LogicMath.Max(this.m_spawnIdleTime - 64, 0);

                if (this.m_spawnTime == 0 && this.m_hasSpawnDelay)
                {
                    this.m_spawnIdleTime = LogicMath.Max(10, data.GetSpawnIdle());
                    this.m_hasSpawnDelay = false;
                }

                if (data.GetBoostedIfAlone() || data.GetSpecialAbilityType() == LogicCharacterData.SPECIAL_ABILITY_TYPE_RAGE_ALONE && this.GetSpecialAbilityAvailable())
                {
                    if (++this.m_rageAloneTime >= 5)
                    {
                        this.m_level.AreaBoostAlone(this, 6);
                        this.m_rageAloneTime = 0;
                    }
                }

                if (this.IsHero())
                {
                    LogicHeroData heroData = (LogicHeroData)data;

                    if (this.m_abilityTime > 0)
                    {
                        if (heroData.GetAbilityAttackCount(this.m_upgradeLevel) > 0 && this.GetCombatComponent().GetHitCount() >= this.m_abilityAttackCount)
                        {
                            Debugger.HudPrint("Hero ability: No more attacks left!");

                            this.m_abilityTime        = 0;
                            this.m_abilityTriggerTime = 0;
                            this.m_activationTime     = 0;
                        }
                        else
                        {
                            if (++this.m_abilityTriggerTime >= 5)
                            {
                                this.m_abilityTime       -= 1;
                                this.m_abilityTriggerTime = 0;

                                this.m_level.AreaAbilityBoost(this, 5);
                            }
                        }
                    }

                    if (this.m_abilityCooldown > 0)
                    {
                        this.m_abilityCooldown -= 1;
                    }

                    if (this.m_abilitySpell != null && this.m_abilitySpell.GetHitsCompleted())
                    {
                        this.GetGameObjectManager().RemoveGameObject(this.m_abilitySpell);
                        this.m_abilitySpell = null;
                    }
                }

                if (this.m_auraSpell == null || this.m_auraSpell.GetHitsCompleted())
                {
                    if (this.m_auraSpell != null)
                    {
                        this.GetGameObjectManager().RemoveGameObject(this.m_auraSpell);
                        this.m_auraSpell = null;
                    }

                    if (data.GetAuraSpell(this.m_upgradeLevel) != null)
                    {
                        LogicHitpointComponent hitpointComponent = this.GetHitpointComponent();

                        if (hitpointComponent != null && hitpointComponent.GetTeam() == 0)
                        {
                            this.m_auraSpell = (LogicSpell)LogicGameObjectFactory.CreateGameObject(data.GetAuraSpell(this.m_upgradeLevel), this.m_level, this.m_villageType);
                            this.m_auraSpell.SetUpgradeLevel(data.GetAuraSpellLevel(this.m_upgradeLevel));
                            this.m_auraSpell.SetInitialPosition(this.GetX(), this.GetY());
                            this.m_auraSpell.AllowDestruction(false);
                            this.m_auraSpell.SetTeam(hitpointComponent.GetTeam());

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

                if (!this.m_retributionSpellCreated)
                {
                    if (data.GetRetributionSpell(this.m_upgradeLevel) != null)
                    {
                        LogicHitpointComponent hitpointComponent = this.GetHitpointComponent();

                        if (hitpointComponent.GetHitpoints() <=
                            hitpointComponent.GetMaxHitpoints() * data.GetRetributionSpellTriggerHealth(this.m_upgradeLevel) / 100)
                        {
                            this.m_retributionSpellCreated = true;
                            this.m_retributionSpell        =
                                (LogicSpell)LogicGameObjectFactory.CreateGameObject(data.GetRetributionSpell(this.m_upgradeLevel), this.m_level, this.m_villageType);
                            this.m_retributionSpell.SetUpgradeLevel(data.GetRetributionSpellLevel(this.m_upgradeLevel));
                            this.m_retributionSpell.SetPositionXY(this.GetX(), this.GetY());
                            this.m_retributionSpell.AllowDestruction(false);
                            this.m_retributionSpell.SetTeam(hitpointComponent.GetTeam());

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

                if (this.m_activationTimeState == 2)
                {
                    this.m_activationTime -= 64;

                    if (this.m_activationTime < 0)
                    {
                        this.m_activationTimeState = 0;
                        this.m_activationTime      = 0;
                    }
                }
                else if (this.m_activationTimeState == 1)
                {
                    this.m_activationTime -= 64;

                    if (this.m_activationTime < 0)
                    {
                        this.m_activationTimeState = 2;
                        this.m_activationTime      = ((LogicHeroData)this.m_data).GetActiveDuration();
                    }
                }
            }

            this.CheckSummons();

            if (this.IsAlive())
            {
                if (data.GetAutoMergeDistance() > 0)
                {
                    this.m_autoMergeTime = LogicMath.Max(this.m_autoMergeTime - 64, 0);
                }

                if (data.GetInvisibilityRadius() > 0)
                {
                    this.m_level.AreaInvisibility(this.GetMidX(), this.GetMidY(), data.GetInvisibilityRadius(), 4, this.GetHitpointComponent().GetTeam());
                }

                if (data.GetHealthReductionPerSecond() > 0)
                {
                    this.GetHitpointComponent().CauseDamage(100 * data.GetHealthReductionPerSecond() / 15, 0, this);
                }
            }

            if (this.m_duplicate)
            {
                if (this.m_duplicateLifeTime-- <= 0)
                {
                    LogicHitpointComponent hitpointComponent = this.GetHitpointComponent();

                    if (hitpointComponent != null)
                    {
                        hitpointComponent.SetHitpoints(0);
                        this.m_level.UpdateBattleStatus();
                    }
                }
            }
        }
Example #9
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!");
            }
        }
Example #10
0
        public void TargetReached(int damagePercent)
        {
            this.m_damageTime = this.GetProjectileData().GetDamageDelay();
            this.UpdateDamage(damagePercent);
            this.m_targetReached = true;

            if (!this.m_dummy)
            {
                if (this.m_hitEffect != null)
                {
                    if (this.m_target != null)
                    {
                        LogicHitpointComponent hitpointComponent = this.m_target.GetHitpointComponent();

                        if (hitpointComponent != null)
                        {
                            if (!this.m_bounceProjectile)
                            {
                                // Listener.
                            }
                        }
                    }
                    else if (!this.m_penetrating && this.m_shockwavePushStrength == 0)
                    {
                        // Listener.
                    }
                }

                if (this.m_hitEffect2 != null)
                {
                    if (this.m_target != null)
                    {
                        LogicHitpointComponent hitpointComponent = this.m_target.GetHitpointComponent();

                        if (hitpointComponent != null)
                        {
                            if (!this.m_bounceProjectile)
                            {
                                // Listener.
                            }
                        }
                    }
                    else if (!this.m_penetrating && this.m_shockwavePushStrength == 0)
                    {
                        // Listener.
                    }
                }

                if (this.m_target != null)
                {
                    if (this.m_bounceCount > 0)
                    {
                        this.m_bounceTargets[this.m_bounceCount - 1] = this.m_target;
                        this.UpdateBounces();
                    }
                }

                LogicSpellData hitSpell = this.GetProjectileData().GetHitSpell();

                if (hitSpell != null)
                {
                    LogicSpell spell = (LogicSpell)LogicGameObjectFactory.CreateGameObject(hitSpell, this.m_level, this.m_villageType);

                    spell.SetUpgradeLevel(this.GetProjectileData().GetHitSpellLevel());
                    spell.SetInitialPosition(this.GetMidX(), this.GetMidY());
                    spell.SetTeam(1);

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

                if (this.m_bounceProjectile)
                {
                    int idx = -1;

                    for (int i = 0; i < LogicProjectile.MAX_BOUNCES; i++)
                    {
                        if (this.m_bouncePositions[i] != null)
                        {
                            idx = i;
                            break;
                        }
                    }

                    if (idx != -1)
                    {
                        LogicVector2 bouncePosition = this.m_bouncePositions[idx];

                        this.m_bouncePositions[idx] = null;
                        this.m_target = null;

                        LogicEffectData bounceEffect = this.GetProjectileData().GetBounceEffect();

                        if (bounceEffect != null)
                        {
                            this.m_listener.PlayEffect(bounceEffect);
                        }

                        this.m_targetPosition.m_x = 8 * bouncePosition.m_x;
                        this.m_targetPosition.m_y = 8 * bouncePosition.m_y;

                        this.m_randomHitRange = this.m_flyingTarget ? 1000 : 0;

                        // Listener.

                        this.m_targetReached = false;
                        this.m_travelTime    = 0;

                        bouncePosition.Destruct();
                    }
                    else
                    {
                        this.m_target = null;
                    }
                }

                if (this.m_targetReached)
                {
                    LogicEffectData destroyedEffect = this.GetProjectileData().GetDestroyedEffect();

                    if (destroyedEffect != null)
                    {
                        // Listener.
                    }
                }
            }
        }
        public override void Tick()
        {
            base.Tick();

            if (this.m_constructionTimer != null)
            {
                if (this.m_level.GetRemainingClockTowerBoostTime() > 0 &&
                    this.m_data.GetVillageType() == 1)
                {
                    this.m_constructionTimer.SetFastForward(this.m_constructionTimer.GetFastForward() + 4 * LogicDataTables.GetGlobals().GetClockTowerBoostMultiplier() - 4);
                }

                if (this.m_constructionTimer.GetRemainingSeconds(this.m_level.GetLogicTime()) <= 0)
                {
                    this.FinishConstruction(false);
                }
            }

            if (this.m_disarmed)
            {
                if (this.m_fadeTime >= 0)
                {
                    this.m_fadeTime = LogicMath.Min(this.m_fadeTime + 64, 1000);
                }
            }

            LogicTriggerComponent triggerComponent = this.GetTriggerComponent();

            if (triggerComponent.IsTriggered() && !this.m_disarmed && !this.m_upgrading)
            {
                LogicTrapData data = this.GetTrapData();

                if (this.m_numSpawns > 0)
                {
                    if (this.m_spawnInitDelay != 0)
                    {
                        this.m_spawnInitDelay -= 1;
                    }
                    else
                    {
                        this.SpawnUnit(1);
                        this.m_numSpawns     -= 1;
                        this.m_spawnInitDelay = this.GetTrapData().GetTimeBetweenSpawnsMS() / 64;
                    }
                }

                if (this.m_actionTime >= 0)
                {
                    this.m_actionTime += 64;
                }

                if (this.m_hitTime >= 0)
                {
                    this.m_hitTime += 64;
                }

                if (this.m_actionTime > data.GetActionFrame())
                {
                    this.m_hitTime    = data.GetHitDelayMS();
                    this.m_actionTime = -1;
                }
                else if (this.m_hitTime > data.GetHitDelayMS())
                {
                    if (data.GetSpell() != null)
                    {
                        LogicSpell spell = (LogicSpell)LogicGameObjectFactory.CreateGameObject(data.GetSpell(), this.m_level, this.m_villageType);

                        spell.SetUpgradeLevel(0);
                        spell.SetInitialPosition(this.GetMidX(), this.GetMidY());
                        spell.SetTeam(1);

                        this.GetGameObjectManager().AddGameObject(spell, -1);
                    }
                    else if (data.GetProjectile(this.m_upgLevel) != null)
                    {
                        this.CreateProjectile(data.GetProjectile(this.m_upgLevel));
                    }
                    else if (data.GetDamageMod() != 0)
                    {
                        this.m_level.AreaBoost(this.GetMidX(), this.GetMidY(), data.GetDamageRadius(this.m_upgLevel), -data.GetSpeedMod(), -data.GetSpeedMod(), data.GetDamageMod(),
                                               0, data.GetDurationMS() / 16, 0, false);
                    }
                    else if (data.GetEjectVictims())
                    {
                        if (data.GetThrowDistance() <= 0)
                        {
                            this.EjectCharacters();
                        }
                        else
                        {
                            this.ThrowCharacters();
                        }
                    }
                    else
                    {
                        bool defaultMode = true;

                        if (data.GetSpawnedCharAir() != null && data.GetSpawnedCharGround() != null || data.HasAlternativeMode())
                        {
                            int activeLayout = this.m_level.GetActiveLayout();

                            if (activeLayout <= 7)
                            {
                                defaultMode = this.m_useAirMode[activeLayout] ^ true;
                            }
                        }

                        this.m_level.AreaDamage(0, this.GetMidX(), this.GetMidY(), data.GetDamageRadius(this.m_upgLevel), data.GetDamage(this.m_upgLevel),
                                                data.GetPreferredTarget(),
                                                data.GetPreferredTargetDamageMod(), data.GetDamageEffect(), 1, null, defaultMode ? 1 : 0, 0, 100, true, false, 100, 0, this, 100,
                                                0);
                    }

                    this.m_hitTime   = 0;
                    this.m_hitCount += 1;

                    if (this.m_hitCount >= data.GetHitCount() && this.m_numSpawns == 0)
                    {
                        this.m_fadeTime       = 1;
                        this.m_hitTime        = -1;
                        this.m_disarmed       = true;
                        this.m_numSpawns      = data.GetNumSpawns(this.m_upgLevel);
                        this.m_spawnInitDelay = data.GetSpawnInitialDelayMS() / 64;
                    }
                }
            }
        }