Beispiel #1
0
        public void Update(GUnit[] units)
        {
            int dt = -updateTimer.TicksLeft;

            foreach (GUnit u in units)
            {
                if (u.Reaction == GReaction.Hostile)
                {
                    if (!u.IsDead && !PPather.IsStupidItem(u))
                    {
                        UnitData ud;
                        if (dic.TryGetValue(u.GUID, out ud))
                        {
                            ud.Update(dt);
                        }
                        else
                        {
                            // new one
                            ud = new UnitData(u);
                            dic.Add(u.GUID, ud);
                        }
                    }
                }
            }

            List <long> rem = new List <long>();

            foreach (UnitData ud in dic.Values)
            {
                if (!ud.unit.IsValid && ud.lastSeen.IsReady)
                {
                    rem.Add(ud.guid);
                }
                else if (ud.unit.IsDead)
                {
                    rem.Add(ud.guid);
                }
            }
            foreach (long guid in rem)
            {
                dic.Remove(guid);
            }
            updateTimer.Reset();
        }
Beispiel #2
0
        public void Update(BoogieBot.Common.Object[] units)
        {
            int dt = (int)-updateTimer.TicksLeft;

            foreach (BoogieBot.Common.Object u in units)
            {
                if (!u.IsDead && !PPather.IsStupidItem(u))
                {
                    UnitData ud;
                    if (dic.TryGetValue((long)u.GUID.GetOldGuid(), out ud))
                    {
                        ud.Update((int)dt);
                    }
                    else
                    {
                        // new one
                        ud = new UnitData(u);
                        dic.Add((long)u.GUID.GetOldGuid(), ud);
                    }
                }
            }

            List <long> rem = new List <long>();

            foreach (UnitData ud in dic.Values)
            {
                if (!ud.unit.IsValid)
                {
                    rem.Add(ud.guid);
                }
            }
            foreach (long guid in rem)
            {
                dic.Remove(guid);
            }
            updateTimer.Reset();
        }
Beispiel #3
0
        // called when we have died, return when we are alive again
        private void GhostRun()
        {
            BoogieCore.Log(LogType.System, "I died. Let's resurrect");
            Coordinate CorpseLocation = null;



            Coordinate gloc = new Coordinate(0, 0, 0);

            if (CorpseLocation != null)
            {
                gloc = CorpseLocation;
            }

            Location   target = null;
            Coordinate gtarget;

            BoogieCore.Log(LogType.System, "Corpse is at " + gloc);

            if (gloc.Z == 0)
            {
                BoogieCore.Log(LogType.System, "hmm, corpse Z == 0");
                target = new Location(gloc);
                for (int q = 0; q < 50; q += 5)
                {
                    float stand_z = 0;
                    int   flags   = 0;
                    float x       = gloc.X + random.Next(20) - 10;
                    float y       = gloc.Y + random.Next(20) - 10;
                    bool  ok      = world.triangleWorld.FindStandableAt(x, y,
                                                                        -5000,
                                                                        5000,
                                                                        out stand_z, out flags, 0, 0);
                    if (ok)
                    {
                        target = new Location(x, y, stand_z);
                        break;
                    }
                }
            }
            else
            {
                target = new Location(gloc);
            }
            gtarget = new Coordinate(target.X, target.Y, target.Z);

            BoogieCore.Log(LogType.System, "Corpse is at " + target);
            EasyMover em = new EasyMover(this, target, false, false);

            // 2. Run to corpse
            while (Me.IsDead && Me.DistanceTo(gloc) > 20)     // fixme
            {
                EasyMover.MoveResult mr = em.move();
                if (mr != EasyMover.MoveResult.Moving)
                {
                    return;                                        // buhu
                }
                UpdateMyPos();
                Thread.Sleep(50);
            }
            mover.Stop();

            // 3. Find a safe place to res
            // is within 20 yds of corpse now, dialog must be up
            float SafeDistance = 25.0f;

            while (true)
            {
                // some brute force :p
                BoogieBot.Common.Object[] monsters = BoogieCore.world.getObjectListArray();
                float    best_score    = 1E30f;
                float    best_distance = 1E30f;
                Location best_loc      = null;
                for (float x = -35; x <= 35; x += 5)
                {
                    for (float y = -35; y <= 35; y += 5)
                    {
                        float      rx  = target.X + x;
                        float      ry  = target.Y + y;
                        Coordinate xxx = new Coordinate(rx, ry, 0);
                        if (xxx.DistanceTo(gtarget) < 35)
                        {
                            float stand_z = 0;
                            int   flags   = 0;
                            bool  ok      = world.triangleWorld.FindStandableAt(rx, ry,
                                                                                target.Z - 20,
                                                                                target.Z + 20,
                                                                                out stand_z, out flags, 0, 0);
                            if (ok)
                            {
                                float      score = 0.0f;
                                Coordinate l     = new Coordinate(rx, ry, stand_z);
                                foreach (BoogieBot.Common.Object monster in monsters)
                                {
                                    if (monster != null && !monster.IsDead)
                                    {
                                        float d = l.DistanceTo(monster.GetCoordinates());
                                        if (d < 35)
                                        {
                                            // one point per yard
                                            score += 35 - d;
                                        }
                                    }
                                }
                                float this_d = Me.DistanceTo(l);
                                if (score <= best_score && this_d < best_distance)
                                {
                                    best_score    = score;
                                    best_distance = this_d;
                                    best_loc      = new Location(l);
                                }
                            }
                        }
                    }
                }
                if (best_loc != null)
                {
                    Coordinate best_gloc = new Coordinate(best_loc.X, best_loc.Y, best_loc.Z);
                    // walk over there
                    WalkTo(best_gloc, false, 10000, true);

                    // Check if I am safe
                    bool safe = true;
                    BoogieBot.Common.Object unsafe_monster = null;
                    foreach (BoogieBot.Common.Object monster in monsters)
                    {
                        if (!monster.IsDead && !PPather.IsStupidItem(monster))
                        {
                            float d = Me.DistanceTo(monster.GetCoordinates());
                            if (d < SafeDistance)
                            {
                                if (Math.Abs(monster.GetPositionZ() - Me.Location.Z) < 15)
                                {
                                    safe           = false;
                                    unsafe_monster = monster;
                                }
                            }
                        }
                    }
                    if (safe)
                    {
                        break;     // yeah
                    }
                }

                // hmm, look again
                Thread.Sleep(2000);
                SafeDistance -= 0.5f;
            }
        }