[Small Release] Fix Move()

09/18/2008 15:32 Rechocto#1
I'm sure a lot of you have noticed, but on most servers where the mobs actually do move, you can stand directly south (thats.. down.. for you slow people) of the monster, they stop. here is how to fix:

go to your Move() function, and find byte ToDir = (blah blah blah) and replace it with a much more correct calculation:
Code:
                    byte ToDir = (byte)((7 - MyMath.PointDirecton(PosX, PosY, Target.LocX, Target.LocY) / 45 % 8));
next change:
Code:
                    if (!Other.PlaceFree(PosX, PosY, ToDir))
                        return;
to
Code:
                    if (!Other.PlaceFree(PosX, PosY, ToDir, (uint)Map))
                        return;
rightclick on PlaceFree and click "Go To Definition"

and replace the code for PlaceFree with:

Code:
        public static bool PlaceFree(short X, short Y, byte MoveDir, uint map)
        {
            bool Ret = true;

            switch (MoveDir)
            {
                case 0: Y += 1; break;
                case 1: X -= 1; Y += 1; break;
                case 2: X -= 1; break;
                case 3: X -= 1;Y -= 1; break;
                case 4: Y -= 1; break;
                case 5: X += 1; Y -= 1; break;
                case 6: X += 1; break;
                case 7: Y += 1; X += 1;break;
            }

            foreach (DictionaryEntry DE in Mobs.AllMobs)
            {
                SingleMob Mob = (SingleMob)DE.Value;
                if(Mob.Map == map)
                    if (Mob.Alive)
                        if (Mob.PosX == X)
                            if (Mob.PosY == Y)
                                Ret = false;
            }
            return Ret;
        }
    }
Finally, back in Entities.cs, under what you just changed you have:
Code:
                    short AddX = 0;
                    short AddY = 0;
change it to:

Code:
                    short AddX = 0;
                    short AddY = 1;
and now mobs wont just STOP, they will go a bit southwest (thats down and left) then continue chasing you.
09/18/2008 17:08 taguro#2
thanks for the post, keep up the good work.
09/18/2008 18:28 glupkotrup#3
Nice...
09/18/2008 18:34 YukiXian#4
For what is thix an Fix? , I don't really understand it...
09/18/2008 18:52 Rechocto#5
the first 2 lines of the first post, yukixian
09/18/2008 19:08 YukiXian#6
Quote:
Originally Posted by Rechocto View Post
the first 2 lines of the first post, yukixian
And I don't understand the first two lines,....
09/18/2008 19:37 THE BAT#7
Thanks alot of the fix

but i have only a comment for the overload of PlaceFree Function
Code:
if (!Other.PlaceFree(PosX, PosY, ToDir, (uint)Map))
                        return;
i think that its not required to include the map in the PlaceFree Function, because actually the mob will get the target from the their current map.
09/18/2008 21:19 Rechocto#8
place free checks if X and Y are filled by another mob, mobs sometimes stop randomly because another map has a mob in that place (happens rarely, I have noticed it.. but it actually baffles me why it doesn't happen more often without Map in the vars..)
09/18/2008 21:31 konkizta#9
Thanks :handsdown:
09/18/2008 21:51 THE BAT#10
Quote:
Originally Posted by Rechocto View Post
place free checks if X and Y are filled by another mob, mobs sometimes stop randomly because another map has a mob in that place (happens rarely, I have noticed it.. but it actually baffles me why it doesn't happen more often without Map in the vars..)
Nice, Thanks :)
09/19/2008 08:25 ~Yuki~#11
Thx its helpful^^