Пример #1
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();
                            }
                        }
                    }
                }
            }
        }
Пример #2
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);
        }
        public void CauseDamage(int damage, int gameObjectId, LogicGameObject gameObject)
        {
            if (damage >= 0 || this.m_hp != 0)
            {
                if (this.m_parent == null)
                {
                    if (damage > 0 && this.m_invulnerabilityTime > 0)
                    {
                        return;
                    }
                }
                else
                {
                    LogicCombatComponent combatComponent = this.m_parent.GetCombatComponent();

                    if (combatComponent != null)
                    {
                        if (combatComponent.GetUndergroundTime() > 0 && damage > 0)
                        {
                            damage = 0;
                        }
                    }

                    if (!this.m_parent.GetLevel().GetInvulnerabilityEnabled())
                    {
                        if (damage > 0 && this.m_invulnerabilityTime > 0)
                        {
                            return;
                        }
                    }
                    else
                    {
                        damage = 0;
                    }

                    if (this.m_parent.GetGameObjectType() == LogicGameObjectType.CHARACTER)
                    {
                        LogicCharacter character = (LogicCharacter)this.m_parent;
                        LogicArrayList <LogicCharacter> childTroops = character.GetChildTroops();

                        if (childTroops != null && childTroops.Size() > 0 || character.GetSpawnDelay() > 0)
                        {
                            return;
                        }
                    }
                }

                if (gameObjectId != 0 && damage < 0)
                {
                    int prevHealingIdx = -1;
                    int healingIdx     = -1;

                    for (int i = 0; i < 8; i++)
                    {
                        if (this.m_healingId[i] == gameObjectId)
                        {
                            prevHealingIdx = i;
                        }
                        else if (healingIdx == -1)
                        {
                            healingIdx = i;

                            if (this.m_healingTime[i] > 0)
                            {
                                healingIdx = -1;
                            }
                        }
                    }

                    if (healingIdx < prevHealingIdx && prevHealingIdx != -1 && healingIdx != -1)
                    {
                        this.m_healingId[healingIdx]       = gameObjectId;
                        this.m_healingTime[healingIdx]     = 1000;
                        this.m_healingId[prevHealingIdx]   = 0;
                        this.m_healingTime[prevHealingIdx] = 0;
                    }
                    else if (prevHealingIdx == -1)
                    {
                        if (healingIdx != -1)
                        {
                            this.m_healingId[healingIdx]   = gameObjectId;
                            this.m_healingTime[healingIdx] = 1000;
                        }
                        else
                        {
                            healingIdx = 8;
                        }
                    }
                    else
                    {
                        healingIdx = prevHealingIdx;
                        this.m_healingTime[prevHealingIdx] = 1000;
                    }

                    damage = damage * LogicDataTables.GetGlobals().GetHealStackPercent(healingIdx) / 100;
                }

                int prevHp         = (this.m_hp + 99) / 100;
                int prevAccurateHp = this.m_hp;
                this.m_hp = LogicMath.Clamp(this.m_hp - damage, 0, this.m_maxHp);
                int hp = (this.m_hp + 99) / 100;

                if (prevHp > hp)
                {
                    LogicResourceStorageComponent resourceStorageComponent =
                        (LogicResourceStorageComponent)this.m_parent.GetComponent(LogicComponentType.RESOURCE_STORAGE);
                    LogicResourceProductionComponent resourceProductionComponent =
                        (LogicResourceProductionComponent)this.m_parent.GetComponent(LogicComponentType.RESOURCE_PRODUCTION);
                    LogicWarResourceStorageComponent warResourceStorageComponent =
                        (LogicWarResourceStorageComponent)this.m_parent.GetComponent(LogicComponentType.WAR_RESOURCE_STORAGE);

                    if (this.m_parent.GetGameObjectType() == LogicGameObjectType.BUILDING)
                    {
                        LogicBuilding building = (LogicBuilding)this.m_parent;

                        if (!building.GetBuildingData().IsLootOnDestruction() || prevAccurateHp > 0 && (this.m_hp == 0 || (uint)this.m_hp >= 0xFFFFFF3A))
                        {
                            if (resourceStorageComponent != null)
                            {
                                resourceStorageComponent.ResourcesStolen(prevHp - hp, prevHp);
                            }
                            if (resourceProductionComponent != null)
                            {
                                resourceProductionComponent.ResourcesStolen(prevHp - hp, prevHp);
                            }
                            if (warResourceStorageComponent != null)
                            {
                                warResourceStorageComponent.ResourcesStolen(prevHp - hp, prevHp);
                            }
                        }
                    }

                    if (this.m_parent.IsWall())
                    {
                        this.m_parent.RefreshPassable();
                    }
                    this.m_lastDamageTime = 0;
                }

                this.UpdateHeroHealthToAvatar(hp);

                if (damage <= 0)
                {
                    if (damage < 0)
                    {
                        // Listener
                    }
                }
                else
                {
                    if (this.m_parent.GetMovementComponent() != null)
                    {
                        this.m_parent.GetMovementComponent().SetPatrolFreeze();
                    }
                }

                if (prevAccurateHp > 0 && this.m_hp == 0)
                {
                    this.m_parent.DeathEvent();
                    this.m_parent.GetLevel().UpdateBattleStatus();

                    if (this.m_parent.IsWall())
                    {
                        this.WallRemoved();
                    }
                }
            }
        }