示例#1
0
        public override void Update(float dt)
        {
            if (currentEnemy == null)
            {
                List <ITargetable> targets = map.GetTargetsInRange(position, info.range);
                for (int x = 0; x < targets.Count; x++)
                {
                    if (targets[x] == this)
                    {
                        continue;
                    }
                    if (targets[x].GetTeam() != GetTeam())
                    {
                        currentEnemy = targets[x];
                    }
                }
            }
            else
            {
                if (CanAttack(currentEnemy))
                {
                    atkCooldown = 1.0f / info.attackSpeed;
                    map.Attacks.Add(new Attack(map, DamageType.Physical, info.attack, info.armorPen, position, this, currentEnemy, 60));
                }
                if (currentEnemy.IsDead() || (currentEnemy.GetPosition() - GetPosition()).LengthSquared() < info.range * info.range)
                {
                    currentEnemy = null;
                }
            }
            atkCooldown -= dt;

            base.Update(dt);
        }
示例#2
0
        public void Update(float dt)
        {
            if (target != null)
            {
                targetPosition = target.GetPosition();
            }
            Vector3 diff   = targetPosition - position;
            float   length = diff.Length();

            diff     /= length;
            position += diff * dt * Speed;

            if (target != null && target.IsDead())
            {
                map.Attacks.Remove(this);
                return;
            }

            if (target != null && length < 1)
            {
                map.Attacks.Remove(this);
                switch (type)
                {
                case DamageType.Physical: target.TakePhysDmg(damage, pen); break;

                case DamageType.Magical: target.TakeMagDmg(damage, pen); break;
                }
                if (target.IsDead())
                {
                    if (attacker != null)
                    {
                        attacker.ReceiveGold(target.GoldValue);
                        attacker.ReceiveXP(target.ExpValue);
                    }
                }
            }
        }
示例#3
0
        public void AttackUpdate(float dt)
        {
            targetPos = currentEnemy.GetPosition();
            Vector3 diff   = currentEnemy.GetPosition() - champion.GetPosition();
            float   length = diff.Length();

            diff /= length;
            if (champion.InRange(currentEnemy))
            {
                champion.Attack(currentEnemy);
                targetPos = champion.GetPosition();
            }
            if (currentEnemy.IsDead())
            {
                currentEnemy = null;
                state        = TestControllerState.Laning;
            }
        }
示例#4
0
文件: Minion.cs 项目: MyEyes/MobaAI
        public override void Update(float dt)
        {
            List <ITargetable> targets = map.GetTargetsInRange(GetPosition(), info.viewRadius);

            for (int x = 0; x < targets.Count; x++)
            {
                if (targets[x] == this)
                {
                    continue;
                }
                if (currentEnemy == null && targets[x].GetTeam() != GetTeam() && targets[x].IsTargetable(GetTeam()))
                {
                    currentEnemy = targets[x];
                }
                Vector3 diff   = targets[x].GetPosition() - GetPosition();
                float   length = diff.Length();
                diff /= length;
                if (length < 10 && length != 0)
                {
                    Move(-diff * dt);
                }
            }

            if (currentEnemy == null)
            {
                targetPos = nextTarget;
                Vector3 diff   = nextTarget - GetPosition();
                float   length = diff.Length();
                diff /= length;
                if (length < 5)
                {
                    targetID++;
                    if (targetID >= lane.Waypoints.Length)
                    {
                        targetID = lane.Waypoints.Length - 1;
                    }
                    nextTarget = lane.Waypoints[targetID];
                }
            }
            else
            {
                targetPos = currentEnemy.GetPosition();
                Vector3 diff   = currentEnemy.GetPosition() - GetPosition();
                float   length = diff.Length();
                diff /= length;
                if (length < info.range)
                {
                    Attack(currentEnemy);
                    targetPos = GetPosition();
                }
                else
                {
                    ITargetable test = GetClosestEnemy();
                    if (test != null)
                    {
                        currentEnemy = test;
                    }
                }
                if (currentEnemy.IsDead() || length > info.viewRadius)
                {
                    currentEnemy = null;
                }
            }

            Vector3 tp;

            if (evade)
            {
                tp = evasionTarget;
            }
            else
            {
                tp = targetPos;
            }

            Vector3 tdiff   = tp - GetPosition();
            float   tlength = tdiff.Length();

            tdiff /= tlength;
            if (tlength > 0)
            {
                Vector3 predictedPosition = GetPosition() + tdiff * info.movespeed * 0.5f;

                if (map.InCollision(predictedPosition))
                {
                    evade = true;
                    ICollidable collider = map.GetCollider(predictedPosition);
                    if (collider != null)
                    {
                        Vector3 vertex = collider.Bounds.GetEdgeToCircumvent(GetPosition(), tp);
                        Vector3 dir    = vertex - collider.Bounds.Center;
                        dir          /= dir.Length();
                        evasionTarget = vertex + dir * Size;
                    }
                }

                Move(tdiff * info.movespeed * dt);
            }

            if (evade && tlength < 1)
            {
                evade = false;
            }

            base.Update(dt);
        }