Ejemplo n.º 1
0
        } // GetNextFreeHateListIndex()

        /// <summary>
        /// Sort hate list
        /// </summary>
        private void SortHateList()
        {
            // Bubblesort the hatelist
            int i, j;

            for (i = 9; i >= 0; i--)
            {
                bool bChanged = false;

                for (j = 0; j < i; j++)
                {
                    HateListEntry hle  = entries[j];
                    HateListEntry hle2 = entries[j + 1];

                    if (hle.Target == null)
                    {
                        break;
                    }

                    if (hle.Value < hle2.Value)
                    {
                        HateListEntry tmp = hle;
                        hle  = hle2;
                        hle2 = tmp;

                        bChanged = true;
                    }
                } // for

                if (!bChanged)
                {
                    return;
                }
            } // for
        }     // SortHateList()
Ejemplo n.º 2
0
        internal override void Update(GameTime gameTime)
        {
            moveTimer -= gameTime.ElapsedGameTime.TotalSeconds;
            if (moveTimer > 0)
            {
                return;
            }

            moveTimer = 1.0f;

            this.Owner.UpdateHateList();

            HateListEntry entry = this.Owner.HateList.GetHighestHateListEntry();

            if (entry.Target == null)
            {
                Log.AI(this.Owner?.ToString(), "No enemy ... moving!");

                if (bUpdatePath)
                {
                    Path = Owner.CurrentMap.CalcPath(Owner.TileX, Owner.TileY, destX, destY);
                    if (Path != null)
                    {
                        curNodeIdx  = 0;
                        bUpdatePath = false;
                    }
                }

                if (curNodeIdx == -1 || Path == null)
                {
                    return;
                }

                if (curNodeIdx >= Path.Count)
                {
                    this.Owner.Idle();
                    return;
                }

                IMapPathNode node = Path[curNodeIdx++];
                // TODO!!! Move, not Set
                Owner.SetPosition(node.X, node.Y);
                return;
            }

            this.Owner.CurrentTarget = entry.Target;

            Log.AI(this.Owner?.ToString(), "Enemy spotted! Attacking " + entry.Target.Name + entry.Target.UniqueID);

            bUpdatePath = true;
            Path        = null;

            MoveOrAttack(entry.Target);
        }
Ejemplo n.º 3
0
        internal override void Update(GameTime gameTime)
        {
            attackTimer -= gameTime.ElapsedGameTime.TotalSeconds;
            if (attackTimer > 0)
            {
                return;
            }

            attackTimer = Owner.AttackSpeed;

            this.Owner.UpdateHateList();

            HateListEntry entry = this.Owner.HateList.GetHighestHateListEntry();

            if (entry.Target == null)
            {
                this.Owner.Idle();
                return;
            }

            MoveOrAttack(entry.Target);
        }