public LogicGameObject EvaluateTargets(LogicMovementComponent component)
        {
            if (component != null && !component.IsFlying() && this.m_targetListSize > 1)
            {
                bool fullChar = true;

                int count = 0;

                int minCost = 0x7FFFFFFF;
                int maxCost = 0;

                LogicGameObject minCostTarget = null;

                for (int i = 0; i < this.m_targetListSize; i++)
                {
                    LogicGameObject target = this.m_targets[i];

                    if (target != null)
                    {
                        LogicCombatComponent combatComponent = component.GetParent().GetCombatComponent();

                        if (combatComponent != null && combatComponent.IsInRange(target))
                        {
                            return(target);
                        }

                        int targetCost = component.EvaluateTargetCost(target);

                        if (target.GetMovementComponent() == null)
                        {
                            fullChar = false;
                        }

                        if (targetCost > maxCost)
                        {
                            maxCost = targetCost;
                        }

                        if (targetCost < minCost)
                        {
                            minCost       = targetCost;
                            minCostTarget = target;
                        }

                        ++count;
                    }
                }

                if (count >= 2 && fullChar && minCost != 0x7FFFFFFF && maxCost - minCost < this.m_charVersusCharRandomDistance)
                {
                    return(this.m_targets[component.GetParent().GetGlobalID() % count]);
                }

                return(minCostTarget);
            }

            return(this.m_targets[0]);
        }
Esempio n. 2
0
        public override void SubTick()
        {
            base.SubTick();

            this.m_areaShieldSpeed = 0;

            bool isInAreaShield   = false;
            int  damagePercentage = 100;

            if (this.m_myTeam == 1)
            {
                LogicVector2 areaShield = new LogicVector2();

                if (this.m_level.GetAreaShield(this.GetMidX(), this.GetMidY(), areaShield))
                {
                    this.m_areaShieldSpeed = areaShield.m_x;

                    isInAreaShield   = true;
                    damagePercentage = 0;
                }
            }

            if (this.m_targetReached)
            {
                if (this.m_damageTime > 0)
                {
                    this.UpdateDamage(damagePercentage);
                }
            }
            else
            {
                if (this.m_targetGroups)
                {
                    if (this.m_target != null && this.m_groups != null)
                    {
                        LogicCombatComponent combatComponent = this.m_groups.GetCombatComponent();

                        if (combatComponent != null && !combatComponent.IsInRange(this.m_target))
                        {
                            this.m_target = null;
                        }
                    }
                }

                if (isInAreaShield)
                {
                    this.m_areaShieldDelay = LogicMath.Min(this.m_areaShieldDelay + 16, 200);
                }
                else if (this.m_areaShieldDelay > 0)
                {
                    this.m_areaShieldDelay = LogicMath.Max(this.m_areaShieldDelay - 4, 0);
                }

                if (this.m_areaShieldDelay == 0)
                {
                    if (this.m_target != null && this.m_target.GetMovementComponent() != null)
                    {
                        this.m_targetPosition.Set(this.m_target.GetMidX() * 8, this.m_target.GetMidY() * 8);
                        this.m_targetPosition.Add(this.m_unk168);
                    }
                }
                else if (this.m_target != null && this.m_target.GetMovementComponent() != null)
                {
                    int x = this.m_unk168.m_x + this.m_target.GetMidX() * 8;
                    int y = this.m_unk168.m_y + this.m_target.GetMidY() * 8;

                    LogicVector2 tmp1 = new LogicVector2(x - this.m_unk276.m_x, y - this.m_unk276.m_y);
                    LogicVector2 tmp2 = new LogicVector2(this.m_unk152.m_x, this.m_unk152.m_y);

                    int length1 = tmp1.Normalize(512);
                    int length2 = tmp2.Normalize(512);

                    int angle1 = tmp1.GetAngle();
                    int angle2 = tmp2.GetAngle();

                    if (LogicMath.Abs(LogicMath.NormalizeAngle180(angle1 - angle2)) <= 30)
                    {
                        this.m_targetPosition.m_x += LogicMath.Clamp(x - this.m_targetPosition.m_x, length1 / -500, length1 / 500);
                        this.m_targetPosition.m_y += LogicMath.Clamp(y - this.m_targetPosition.m_y, length1 / -500, length1 / 500);
                    }
                    else
                    {
                        this.m_target = null;
                    }
                }

                this.m_unk144.m_x = this.m_targetPosition.m_x - this.m_unk276.m_x;
                this.m_unk144.m_y = this.m_targetPosition.m_y - this.m_unk276.m_y;

                int distance = (200 - this.m_areaShieldDelay) * (8 * this.GetSpeed() - 8 * this.m_areaShieldSpeed) / 200 + 8 * this.m_areaShieldSpeed;

                if (distance * distance >= this.m_unk144.GetDistanceSquaredTo(0, 0))
                {
                    this.TargetReached(damagePercentage);
                }
                else
                {
                    this.m_unk152.m_x = this.m_unk144.m_x;
                    this.m_unk152.m_y = this.m_unk144.m_y;

                    this.m_unk144.Normalize(distance);

                    this.m_unk276.m_x += this.m_unk144.m_x;
                    this.m_unk276.m_y += this.m_unk144.m_y;

                    this.SetPositionXY(this.m_unk276.m_x >> 3, this.m_unk276.m_y >> 3);

                    this.m_unk160.m_x = this.m_unk144.m_x >> 3;
                    this.m_unk160.m_y = this.m_unk144.m_y >> 3;
                }

                if (this.m_shockwavePushStrength > 0)
                {
                    this.UpdateShockwavePush(this.m_myTeam, this.m_flyingTarget ? 0 : 1);
                }

                if (this.m_penetrating)
                {
                    this.UpdatePenetrating(damagePercentage);
                }

                this.m_travelTime += 16;
            }
        }