public void SetTeam(int team)
        {
            this.m_team = team;

            if (team != 0)
            {
                if (this.m_parent.GetGameObjectType() == LogicGameObjectType.CHARACTER)
                {
                    LogicCharacter       character       = (LogicCharacter)this.m_parent;
                    LogicCombatComponent combatComponent = character.GetCombatComponent();

                    if (combatComponent != null)
                    {
                        if (character.GetCharacterData().IsUnderground())
                        {
                            combatComponent.SetUndergroundTime(0);
                        }

                        LogicMovementComponent movementComponent = character.GetMovementComponent();

                        if (movementComponent != null)
                        {
                            movementComponent.SetUnderground(false);
                        }
                    }
                }
            }
        }
        public void UpdateHeroHealthToAvatar(int hitpoint)
        {
            LogicAvatar   avatar = this.m_team == 1 ? this.m_parent.GetLevel().GetHomeOwnerAvatar() : this.m_parent.GetLevel().GetVisitorAvatar();
            LogicHeroData data   = null;

            int upgLevel = 0;

            if (this.m_parent.IsHero())
            {
                LogicCharacter character = (LogicCharacter)this.m_parent;

                data     = (LogicHeroData)character.GetCharacterData();
                upgLevel = character.GetUpgradeLevel();
            }
            else if (this.m_parent.GetGameObjectType() == LogicGameObjectType.BUILDING)
            {
                LogicBuilding          building          = (LogicBuilding)this.m_parent;
                LogicHeroBaseComponent heroBaseComponent = building.GetHeroBaseComponent();

                if (heroBaseComponent == null)
                {
                    return;
                }

                LogicBuildingData buildingData = building.GetBuildingData();

                if (!buildingData.GetShareHeroCombatData())
                {
                    return;
                }

                LogicCombatComponent combatComponent = building.GetCombatComponent();

                if (combatComponent == null || !combatComponent.IsEnabled())
                {
                    return;
                }

                data     = buildingData.GetHeroData();
                upgLevel = avatar.GetUnitUpgradeLevel(data);
            }

            if (data != null)
            {
                int secs = LogicMath.Min(data.GetSecondsToFullHealth(hitpoint, upgLevel), data.GetFullRegenerationTimeSec(upgLevel));

                if (avatar != null)
                {
                    avatar.GetChangeListener().CommodityCountChanged(0, data, secs);
                    avatar.SetHeroHealth(data, secs);
                }
            }
        }
Exemple #3
0
        public void UpdatePushBack()
        {
            int startSpeed = this.m_pushTime * this.m_pushTime / this.m_pushInitTime;
            int endSpeed   = this.m_pushInitTime - startSpeed;
            int pushBackX  = (startSpeed * this.m_pushBackStartPosition.m_x + endSpeed * this.m_pushBackEndPosition.m_x) / this.m_pushInitTime;
            int pushBackY  = (startSpeed * this.m_pushBackStartPosition.m_y + endSpeed * this.m_pushBackEndPosition.m_y) / this.m_pushInitTime;

            if (this.m_parent == null || this.m_parent.IsFlying() || this.m_parent.GetParent().GetLevel().GetTileMap().IsPassablePathFinder(pushBackX >> 8, pushBackY >> 8) ||
                this.m_ignorePush)
            {
                this.SetPosition(pushBackX, pushBackY);
            }
            else
            {
                this.m_pushBackStartPosition.m_x = this.m_position.m_x;
                this.m_pushBackStartPosition.m_y = this.m_position.m_y;
                this.m_pushBackEndPosition.m_x   = this.m_position.m_x;
                this.m_pushBackEndPosition.m_y   = this.m_position.m_y;
            }

            this.m_pushTime = LogicMath.Max(this.m_pushTime - 16, 0);

            if (this.m_pushTime == 0)
            {
                LogicGameObject      parent          = this.m_parent.GetParent();
                LogicCombatComponent combatComponent = parent.GetCombatComponent();

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

                    if (character.GetCharacterData().GetPickNewTargetAfterPushback() || this.m_ignorePush)
                    {
                        if (combatComponent != null)
                        {
                            combatComponent.ForceNewTarget();
                        }
                    }
                }

                this.m_parent.NewTargetFound();

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

                this.m_ignorePush = false;
            }
        }
Exemple #4
0
        public override void Tick()
        {
            if (this.m_triggeredByRadius)
            {
                LogicLevel level = this.m_parent.GetLevel();

                if (level.IsInCombatState())
                {
                    if (!this.m_triggered)
                    {
                        if (((level.GetLogicTime().GetTick() / 4) & 7) == 0)
                        {
                            LogicArrayList <LogicComponent> components = this.m_parent.GetComponentManager().GetComponents(LogicComponentType.MOVEMENT);

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

                                if (gameObject.GetGameObjectType() == LogicGameObjectType.CHARACTER)
                                {
                                    LogicCharacter         character         = (LogicCharacter)gameObject;
                                    LogicMovementComponent movementComponent = character.GetMovementComponent();

                                    bool triggerDisabled = false;

                                    if (movementComponent != null)
                                    {
                                        LogicMovementSystem movementSystem = movementComponent.GetMovementSystem();

                                        if (movementSystem != null && movementSystem.IsPushed())
                                        {
                                            triggerDisabled = movementSystem.IgnorePush();
                                        }
                                    }

                                    if (!triggerDisabled && character.GetCharacterData().GetTriggersTraps())
                                    {
                                        this.ObjectClose(character);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #5
0
        public void ObjectClose(LogicGameObject gameObject)
        {
            LogicHitpointComponent hitpointComponent = gameObject.GetHitpointComponent();

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

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

                LogicCombatComponent combatComponent = gameObject.GetCombatComponent();

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

                            if (LogicMath.Abs(distanceX) <= this.m_triggerRadius &&
                                LogicMath.Abs(distanceY) <= this.m_triggerRadius &&
                                distanceX * distanceX + distanceY * distanceY < (uint)(this.m_triggerRadius * this.m_triggerRadius))
                            {
                                this.Trigger();
                            }
                        }
                    }
                }
            }
        }
Exemple #6
0
        public override void Tick()
        {
            LogicAvatar homeOwnerAvatar = this.m_parent.GetLevel().GetHomeOwnerAvatar();

            if (homeOwnerAvatar != null)
            {
                this.m_updateAvatarCooldown += 64;

                if (this.m_updateAvatarCooldown > 1000)
                {
                    homeOwnerAvatar.UpdateStarBonusLimitCooldown();
                    homeOwnerAvatar.UpdateLootLimitCooldown();

                    this.m_updateAvatarCooldown -= 1000;
                }
            }

            if (this.m_parent.IsAlive())
            {
                if (!this.IsEmpty())
                {
                    if (this.m_bunkerSearchTime > 0)
                    {
                        this.m_bunkerSearchTime -= 64;
                    }
                    else
                    {
                        bool airTriggered = false;
                        bool groundLocked = false;

                        if (this.m_team == 1)
                        {
                            bool inAirDistance    = false;
                            bool inGroundDistance = false;

                            int clanCastleRadius = LogicDataTables.GetGlobals().GetClanCastleRadius();

                            if (LogicDataTables.GetGlobals().CastleTroopTargetFilter())
                            {
                                LogicCharacter closestGroundAttacker = this.ClosestAttacker(false);
                                LogicCharacter closestAirAttacker    = this.ClosestAttacker(true);

                                if (closestAirAttacker != null)
                                {
                                    inAirDistance = closestAirAttacker.GetPosition().GetDistanceSquaredTo(this.m_parent.GetX(), this.m_parent.GetY()) <
                                                    clanCastleRadius * clanCastleRadius;
                                }

                                if (closestGroundAttacker != null)
                                {
                                    inGroundDistance = closestGroundAttacker.GetPosition().GetDistanceSquaredTo(this.m_parent.GetX(), this.m_parent.GetY()) <
                                                       clanCastleRadius * clanCastleRadius;
                                }
                            }
                            else
                            {
                                LogicCharacter closestAttacker =
                                    (LogicCharacter)this.m_parent.GetLevel().GetGameObjectManager()
                                    .GetClosestGameObject(this.m_parent.GetX(), this.m_parent.GetY(), this.m_filter);

                                if (closestAttacker != null)
                                {
                                    inAirDistance = inGroundDistance = closestAttacker.GetPosition().GetDistanceSquaredTo(this.m_parent.GetX(), this.m_parent.GetY()) <
                                                                       clanCastleRadius * clanCastleRadius;
                                }
                            }

                            groundLocked = !inGroundDistance;
                            airTriggered = inAirDistance;

                            if (!airTriggered && groundLocked)
                            {
                                this.m_bunkerSearchTime = LogicDataTables.GetGlobals().GetBunkerSearchTime();
                                return;
                            }
                        }
                        else
                        {
                            airTriggered = true;
                        }

                        LogicCharacterData spawnData = null;
                        int spawnLevel = -1;

                        for (int i = 0; i < this.GetUnitTypeCount(); i++)
                        {
                            LogicCombatItemData data = this.GetUnitType(i);

                            if (data != null)
                            {
                                int count = this.GetUnitCount(i);

                                if (count > 0)
                                {
                                    int upgLevel = this.GetUnitLevel(i);

                                    if (data.GetCombatItemType() == LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER)
                                    {
                                        LogicCharacterData    characterData    = (LogicCharacterData)data;
                                        LogicAttackerItemData attackerItemData = characterData.GetAttackerItemData(upgLevel);

                                        if (!(airTriggered & groundLocked) || attackerItemData.GetTrackAirTargets(false))
                                        {
                                            if (airTriggered | groundLocked || attackerItemData.GetTrackGroundTargets(false))
                                            {
                                                this.RemoveUnits(data, upgLevel, 1);

                                                spawnData  = characterData;
                                                spawnLevel = upgLevel;
                                            }
                                        }
                                    }
                                }
                            }

                            if (spawnData != null)
                            {
                                break;
                            }
                        }

                        if (spawnData != null)
                        {
                            LogicCharacter character =
                                (LogicCharacter)LogicGameObjectFactory.CreateGameObject(spawnData, this.m_parent.GetLevel(), this.m_parent.GetVillageType());

                            character.GetHitpointComponent().SetTeam(this.m_team);

                            if (character.GetChildTroops() != null)
                            {
                                LogicArrayList <LogicCharacter> childrens = character.GetChildTroops();

                                for (int i = 0; i < childrens.Size(); i++)
                                {
                                    childrens[i].GetHitpointComponent().SetTeam(this.m_team);
                                }
                            }

                            character.SetUpgradeLevel(spawnLevel == -1 ? 0 : spawnLevel);
                            character.SetAllianceUnit();

                            if (character.GetCharacterData().IsJumper())
                            {
                                character.GetMovementComponent().EnableJump(3600000);
                            }

                            if (this.m_team == 1)
                            {
                                if (LogicDataTables.GetGlobals().EnableDefendingAllianceTroopJump())
                                {
                                    character.GetMovementComponent().EnableJump(3600000);
                                }

                                if (LogicDataTables.GetGlobals().AllianceTroopsPatrol())
                                {
                                    character.GetCombatComponent().SetSearchRadius(LogicDataTables.GetGlobals().GetClanCastleRadius() >> 9);

                                    if (this.m_parent.GetGameObjectType() == LogicGameObjectType.BUILDING)
                                    {
                                        character.GetMovementComponent().SetBaseBuilding((LogicBuilding)this.m_parent);
                                    }
                                }
                            }
                            else
                            {
                                LogicAvatar visitorAvatar = this.m_parent.GetLevel().GetVisitorAvatar();

                                visitorAvatar.RemoveAllianceUnit(spawnData, spawnLevel);
                                visitorAvatar.GetChangeListener().AllianceUnitRemoved(spawnData, spawnLevel);

                                LogicBattleLog battleLog = this.m_parent.GetLevel().GetBattleLog();

                                battleLog.IncrementDeployedAllianceUnits(spawnData, 1, spawnLevel);
                                battleLog.SetAllianceUsed(true);
                            }

                            if (this.m_team == 1)
                            {
                                int spawnOffsetX = 0;
                                int spawnOffsetY = 0;

                                switch (this.m_troopSpawnOffset)
                                {
                                case 0:
                                    spawnOffsetX = 1;
                                    spawnOffsetY = 0;
                                    break;

                                case 1:
                                    spawnOffsetX = -1;
                                    spawnOffsetY = 0;
                                    break;

                                case 2:
                                    spawnOffsetX = 0;
                                    spawnOffsetY = 1;
                                    break;

                                case 3:
                                    spawnOffsetX = 0;
                                    spawnOffsetY = -1;
                                    break;
                                }

                                character.SetInitialPosition(this.m_parent.GetMidX() + ((this.m_parent.GetWidthInTiles() << 8) - 128) * spawnOffsetX,
                                                             this.m_parent.GetMidY() + ((this.m_parent.GetHeightInTiles() << 8) - 128) * spawnOffsetY);

                                if (++this.m_troopSpawnOffset > 3)
                                {
                                    this.m_troopSpawnOffset = 0;
                                }
                            }
                            else if (LogicDataTables.GetGlobals().AllowClanCastleDeployOnObstacles())
                            {
                                int posX = this.m_parent.GetX() + (this.m_parent.GetWidthInTiles() << 9) - 128;
                                int posY = this.m_parent.GetY() + (this.m_parent.GetHeightInTiles() << 8);

                                if (LogicGamePlayUtil.GetNearestValidAttackPos(this.m_parent.GetLevel(), posX, posY, out int outputX, out int outputY))
                                {
                                    character.SetInitialPosition(outputX, outputY);
                                }
                                else
                                {
                                    character.SetInitialPosition(posX, posY);
                                }
                            }
                            else
                            {
                                character.SetInitialPosition(this.m_parent.GetX() + (this.m_parent.GetWidthInTiles() << 9) - 128,
                                                             this.m_parent.GetY() + (this.m_parent.GetHeightInTiles() << 8));
                            }

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

                        this.m_bunkerSearchTime = LogicDataTables.GetGlobals().GetBunkerSearchTime();
                    }
                }
            }
Exemple #7
0
        public LogicCharacter ClosestAttacker(bool flyingTroop)
        {
            LogicGameObjectManager           gameObjectManager = this.m_parent.GetLevel().GetGameObjectManagerAt(0);
            LogicArrayList <LogicGameObject> gameObjects       = gameObjectManager.GetGameObjects(LogicGameObjectType.CHARACTER);

            int            closestDistance  = 0x7fffffff;
            LogicCharacter closestCharacter = null;

            for (int i = 0; i < gameObjects.Size(); i++)
            {
                LogicCharacter         character         = (LogicCharacter)gameObjects[i];
                LogicHitpointComponent hitpointComponent = character.GetHitpointComponent();
                LogicCombatComponent   combatComponent   = character.GetCombatComponent();

                bool deployTime = combatComponent != null && combatComponent.GetUndergroundTime() > 0;

                if (!deployTime && (LogicDataTables.GetGlobals().SkeletonOpenClanCastle() || !LogicDataTables.IsSkeleton(character.GetCharacterData())))
                {
                    if (hitpointComponent != null)
                    {
                        if (character.IsAlive() && character.IsFlying() == flyingTroop && hitpointComponent.GetTeam() == 0)
                        {
                            int distance = character.GetPosition().GetDistanceSquaredTo(this.m_parent.GetMidX(), this.m_parent.GetMidY());

                            if (distance < closestDistance)
                            {
                                closestDistance  = distance;
                                closestCharacter = character;
                            }
                        }
                    }
                }
            }

            return(closestCharacter);
        }