[Release]Fixed SS/FB System

02/01/2010 06:25 Arcо#1
Big credits to saint for showing me the geometry behind this.

First go to MyMath.cs and search for
Code:
public static class MyMath
and over that put this:
Code:
public struct coords
    {
        public int X;
        public int Y;

        public coords(int x, int y)
        {
            this.X = x;
            this.Y = y;
        }
    }

Next go to MyMath.cs and search for
Code:
static Random Rnd = new Random();
Under that insert this:
Code:
public static bool Contains(this coords[] Coords, coords Check)
        {
            foreach (coords Coord in Coords)
                if (Coord.X == Check.X && Check.Y == Coord.Y)
                    return true;
            return false;
        }
        public static List<coords> LineCoords(ushort userx, ushort usery, ushort shotx, ushort shoty, byte length)
        {
            double dir = Math.Atan2(shoty - usery, shotx - userx);
            double f_x = (Math.Cos(dir) * length) + userx;
            double f_y = (Math.Sin(dir) * length) + usery;

            return bresenham(userx, usery, (int)f_x, (int)f_y);
        }
        public static void Add(this List<coords> Coords, int x, int y)
        {
            coords add = new coords((ushort)x, (ushort)y);
            if (!Coords.Contains(add))
                Coords.Add(add);
        }
        public static List<coords> bresenham(int x0, int y0, int x1, int y1)
        {
            List<coords> ThisLine = new List<coords>();

            int dy = y1 - y0;
            int dx = x1 - x0;
            int stepx, stepy;

            if (dy < 0) { dy = -dy; stepy = -1; } else { stepy = 1; }
            if (dx < 0) { dx = -dx; stepx = -1; } else { stepx = 1; }
            dy <<= 1;                                                  
            dx <<= 1;                                                  

            ThisLine.Add(x0, y0);
            if (dx > dy)
            {
                int fraction = dy - (dx >> 1);                         
                while (x0 != x1)
                {
                    if (fraction >= 0)
                    {
                        y0 += stepy;
                        fraction -= dx;                                
                    }
                    x0 += stepx;
                    fraction += dy;                                   
                    ThisLine.Add(x0, y0);
                }
            }
            else
            {
                int fraction = dx - (dy >> 1);
                while (y0 != y1)
                {
                    if (fraction >= 0)
                    {
                        x0 += stepx;
                        fraction -= dy;
                    }
                    y0 += stepy;
                    fraction += dx;
                    ThisLine.Add(x0, y0);
                }
            }
            return ThisLine;
        }
Now open Skills.cs and go to this line:
Code:
if ((!RangeFromChar && MyMath.PointDistance(AimX, AimY, GuildWars.ThePole.Loc.X, GuildWars.ThePole.Loc.Y) <= Info.MaxDist || MyMath.PointDistance(User.Loc.X, User.Loc.Y, GuildWars.ThePole.Loc.X, GuildWars.ThePole.Loc.Y) <= Info.MaxDist) && GuildWars.War && User.MyGuild != GuildWars.LastWinner)
Replace all this:
Code:
                    if ((!RangeFromChar && MyMath.PointDistance(AimX, AimY, GuildWars.ThePole.Loc.X, GuildWars.ThePole.Loc.Y) <= Info.MaxDist || MyMath.PointDistance(User.Loc.X, User.Loc.Y, GuildWars.ThePole.Loc.X, GuildWars.ThePole.Loc.Y) <= Info.MaxDist) && GuildWars.War && User.MyGuild != GuildWars.LastWinner)
                        if (Info.Targetting == TargetType.Sector && InSector(GuildWars.ThePole.Loc.X, GuildWars.ThePole.Loc.Y) || Info.Targetting != TargetType.Sector)
                            if (Info.Targetting == TargetType.Linear && MyMath.PointDirecton(User.Loc.X, User.Loc.Y, AimX, AimY) == MyMath.PointDirecton(User.Loc.X, User.Loc.Y, GuildWars.ThePole.Loc.X, GuildWars.ThePole.Loc.Y) || Info.Targetting != TargetType.Linear)
                                MiscTargets.Add(GuildWars.ThePole.EntityID, GetDamage(GuildWars.ThePole.CurHP));

                    if (GuildWars.War && !GuildWars.TheRightGate.Opened && (!RangeFromChar && MyMath.PointDistance(AimX, AimY, GuildWars.TheRightGate.Loc.X, GuildWars.TheRightGate.Loc.Y) <= Info.MaxDist || MyMath.PointDistance(User.Loc.X, User.Loc.Y, GuildWars.TheRightGate.Loc.X, GuildWars.TheRightGate.Loc.Y) <= Info.MaxDist))
                        if (Info.Targetting == TargetType.Sector && InSector(GuildWars.TheRightGate.Loc.X, GuildWars.TheRightGate.Loc.Y) || Info.Targetting != TargetType.Sector)
                            if (Info.Targetting == TargetType.Linear && MyMath.PointDirecton(User.Loc.X, User.Loc.Y, AimX, AimY) == MyMath.PointDirecton(User.Loc.X, User.Loc.Y, GuildWars.TheRightGate.Loc.X, GuildWars.TheRightGate.Loc.Y) || Info.Targetting != TargetType.Linear)
                                MiscTargets.Add(GuildWars.TheRightGate.EntityID, GetDamage(GuildWars.TheRightGate.CurHP));

                    if (GuildWars.War && !GuildWars.TheLeftGate.Opened && (!RangeFromChar && MyMath.PointDistance(AimX, AimY, GuildWars.TheLeftGate.Loc.X, GuildWars.TheLeftGate.Loc.Y) <= Info.MaxDist || MyMath.PointDistance(User.Loc.X, User.Loc.Y, GuildWars.TheLeftGate.Loc.X, GuildWars.TheLeftGate.Loc.Y) <= Info.MaxDist))
                        if (Info.Targetting == TargetType.Sector && InSector(GuildWars.TheLeftGate.Loc.X, GuildWars.TheLeftGate.Loc.Y) || Info.Targetting != TargetType.Sector)
                            if (Info.Targetting == TargetType.Linear && MyMath.PointDirecton(User.Loc.X, User.Loc.Y, AimX, AimY) == MyMath.PointDirecton(User.Loc.X, User.Loc.Y, GuildWars.TheLeftGate.Loc.X, GuildWars.TheLeftGate.Loc.Y) || Info.Targetting != TargetType.Linear)
                                MiscTargets.Add(GuildWars.TheLeftGate.EntityID, GetDamage(GuildWars.TheLeftGate.CurHP));
With this:
Code:
                    List<coords> Line = new List<coords>(5);
                    if (Info.Targetting == TargetType.Linear)
                        Line = MyMath.LineCoords(User.Loc.X, User.Loc.Y, AimX, AimY, 10);
                    if ((!RangeFromChar && MyMath.PointDistance(AimX, AimY, GuildWars.ThePole.Loc.X, GuildWars.ThePole.Loc.Y) <= Info.MaxDist || MyMath.PointDistance(User.Loc.X, User.Loc.Y, GuildWars.ThePole.Loc.X, GuildWars.ThePole.Loc.Y) <= Info.MaxDist) && GuildWars.War && User.MyGuild != GuildWars.LastWinner)
                        if (Info.Targetting == TargetType.Sector && InSector(GuildWars.ThePole.Loc.X, GuildWars.ThePole.Loc.Y) || Info.Targetting != TargetType.Sector)
                            if (Info.Targetting == TargetType.Linear && Line.Contains(new coords(GuildWars.ThePole.Loc.X, GuildWars.ThePole.Loc.Y)) || Info.Targetting != TargetType.Linear)
                                MiscTargets.Add(GuildWars.ThePole.EntityID, GetDamage(GuildWars.ThePole.CurHP));

                    if (GuildWars.War && !GuildWars.TheRightGate.Opened && (!RangeFromChar && MyMath.PointDistance(AimX, AimY, GuildWars.TheRightGate.Loc.X, GuildWars.TheRightGate.Loc.Y) <= Info.MaxDist || MyMath.PointDistance(User.Loc.X, User.Loc.Y, GuildWars.TheRightGate.Loc.X, GuildWars.TheRightGate.Loc.Y) <= Info.MaxDist))
                        if (Info.Targetting == TargetType.Sector && InSector(GuildWars.TheRightGate.Loc.X, GuildWars.TheRightGate.Loc.Y) || Info.Targetting != TargetType.Sector)
                            if (Info.Targetting == TargetType.Linear && Line.Contains(new coords(GuildWars.TheRightGate.Loc.X, GuildWars.TheRightGate.Loc.Y)) || Info.Targetting != TargetType.Linear)
                                MiscTargets.Add(GuildWars.TheRightGate.EntityID, GetDamage(GuildWars.TheRightGate.CurHP));

                    if (GuildWars.War && !GuildWars.TheLeftGate.Opened && (!RangeFromChar && MyMath.PointDistance(AimX, AimY, GuildWars.TheLeftGate.Loc.X, GuildWars.TheLeftGate.Loc.Y) <= Info.MaxDist || MyMath.PointDistance(User.Loc.X, User.Loc.Y, GuildWars.TheLeftGate.Loc.X, GuildWars.TheLeftGate.Loc.Y) <= Info.MaxDist))
                        if (Info.Targetting == TargetType.Sector && InSector(GuildWars.TheLeftGate.Loc.X, GuildWars.TheLeftGate.Loc.Y) || Info.Targetting != TargetType.Sector)
                            if (Info.Targetting == TargetType.Linear && Line.Contains(new coords(GuildWars.TheLeftGate.Loc.X, GuildWars.TheLeftGate.Loc.Y)) || Info.Targetting != TargetType.Linear)
                                MiscTargets.Add(GuildWars.TheLeftGate.EntityID, GetDamage(GuildWars.TheLeftGate.CurHP));
Now still in Skills.cs, search for:
Code:
Hashtable MapMobs = (Hashtable)World.H_Mobs[User.Loc.Map];
Under that put this
Code:
                    List<coords> Line = new List<coords>(5);
                    if (Info.Targetting == TargetType.Linear)
                        Line = MyMath.LineCoords(User.Loc.X, User.Loc.Y, AimX, AimY, 10);
Now find this:
Code:
                        foreach (Mob M in MapMobs.Values)
                        {
                            if (M.Alive)
                            {
                                if ((!RangeFromChar && MyMath.PointDistance(AimX, AimY, M.Loc.X, M.Loc.Y) <= Info.MaxDist) || MyMath.PointDistance(User.Loc.X, User.Loc.Y, M.Loc.X, M.Loc.Y) <= Info.MaxDist)
                                    if (Info.Targetting == TargetType.Sector && InSector(M.Loc.X, M.Loc.Y) || Info.Targetting != TargetType.Sector)
                                        if (Info.Targetting == TargetType.Linear && MyMath.PointDirecton(User.Loc.X, User.Loc.Y, AimX, AimY) == MyMath.PointDirecton(User.Loc.X, User.Loc.Y, M.Loc.X, M.Loc.Y) || Info.Targetting != TargetType.Linear)
                                            if (User.PKMode == PKMode.PK || !M.NeedsPKMode && !MobTargets.Contains(M))
                                                MobTargets.Add(M, GetDamage(M));
                            }
                        }
And replace it with this:
Code:
                        foreach (Mob M in MapMobs.Values)
                        {
                            if (M.Alive)
                            {
                                if ((!RangeFromChar && MyMath.PointDistance(AimX, AimY, M.Loc.X, M.Loc.Y) <= Info.MaxDist) || MyMath.PointDistance(User.Loc.X, User.Loc.Y, M.Loc.X, M.Loc.Y) <= Info.MaxDist)
                                    if (Info.Targetting == TargetType.Sector && InSector(M.Loc.X, M.Loc.Y) || Info.Targetting != TargetType.Sector)
                                        if (Info.Targetting == TargetType.Linear && Line.Contains(new coords(M.Loc.X, M.Loc.Y)) || Info.Targetting != TargetType.Linear)
                                            if (User.PKMode == PKMode.PK || !M.NeedsPKMode && !MobTargets.Contains(M))
                                                MobTargets.Add(M, GetDamage(M));
                            }
                        }
Next replace this:
Code:
                    foreach (Character C in World.H_Chars.Values)
                    {
                        if (C.Alive && (C != User || Info.Damageing == DamageType.HealHP || Info.Damageing == DamageType.HealMP))
                        {
                            if ((!RangeFromChar && MyMath.PointDistance(AimX, AimY, C.Loc.X, C.Loc.Y) <= Info.MaxDist) || MyMath.PointDistance(User.Loc.X, User.Loc.Y, C.Loc.X, C.Loc.Y) <= Info.MaxDist)
                                if (Info.Targetting == TargetType.Sector && InSector(C.Loc.X, C.Loc.Y) || Info.Targetting != TargetType.Sector)
                                    if (Info.Targetting == TargetType.Linear && MyMath.PointDirecton(User.Loc.X, User.Loc.Y, AimX, AimY) == MyMath.PointDirecton(User.Loc.X, User.Loc.Y, C.Loc.X, C.Loc.Y) || Info.Targetting != TargetType.Linear)
                                        if (C.PKAble(User.PKMode, User) && !PlayerTargets.Contains(C) && !World.NoPKMaps.Contains(User.Loc.Map) || Info.ExtraEff == ExtraEffect.UnMount)
                                            if (Game.World.NoPKMaps.Contains(User.Loc.Map) && GetDamage(C) == 0 || !Game.World.NoPKMaps.Contains(User.Loc.Map) || (Info.ExtraEff == ExtraEffect.UnMount && C.StatEff.Contains(StatusEffectEn.Ride)) && C.Equips.Steed.Plus < User.Equips.Steed.Plus)
                                                if (User.MyClient.GM && C.EntityID == User.EntityID || !User.MyClient.GM)
                                                PlayerTargets.Add(C, GetDamage(C));
                        }
                    }
With:
Code:
                    foreach (Character C in World.H_Chars.Values)
                    {
                        if (C.Alive && (C != User || Info.Damageing == DamageType.HealHP || Info.Damageing == DamageType.HealMP))
                        {
                            if ((!RangeFromChar && MyMath.PointDistance(AimX, AimY, C.Loc.X, C.Loc.Y) <= Info.MaxDist) || MyMath.PointDistance(User.Loc.X, User.Loc.Y, C.Loc.X, C.Loc.Y) <= Info.MaxDist)
                                if (Info.Targetting == TargetType.Sector && InSector(C.Loc.X, C.Loc.Y) || Info.Targetting != TargetType.Sector)
                                    if (Info.Targetting == TargetType.Linear && Line.Contains(new coords(C.Loc.X, C.Loc.Y)) || Info.Targetting != TargetType.Linear)
                                        if (C.PKAble(User.PKMode, User) && !PlayerTargets.Contains(C) && !World.NoPKMaps.Contains(User.Loc.Map) || Info.ExtraEff == ExtraEffect.UnMount)
                                            if (Game.World.NoPKMaps.Contains(User.Loc.Map) && GetDamage(C) == 0 || !Game.World.NoPKMaps.Contains(User.Loc.Map) || (Info.ExtraEff == ExtraEffect.UnMount && C.StatEff.Contains(StatusEffectEn.Ride)) && C.Equips.Steed.Plus < User.Equips.Steed.Plus)
                                                if (true)
                                                    PlayerTargets.Add(C, GetDamage(C));
                        }
                    }
Then replace this:
Code:
                    foreach (NPC C in World.H_NPCs.Values)
                    {
                        if ((C.Flags == 21 || C.Flags == 22) && User.Level >= C.Level)
                        {
                            if ((!RangeFromChar && MyMath.PointDistance(AimX, AimY, C.Loc.X, C.Loc.Y) <= Info.MaxDist) || MyMath.PointDistance(User.Loc.X, User.Loc.Y, C.Loc.X, C.Loc.Y) <= Info.MaxDist)
                                if (Info.Targetting == TargetType.Sector && InSector(C.Loc.X, C.Loc.Y) || Info.Targetting != TargetType.Sector)
                                    if (Info.Targetting == TargetType.Linear && MyMath.PointDirecton(User.Loc.X, User.Loc.Y, AimX, AimY) == MyMath.PointDirecton(User.Loc.X, User.Loc.Y, C.Loc.X, C.Loc.Y) || Info.Targetting != TargetType.Linear)
                                        if (!NPCTargets.Contains(C))
                                            NPCTargets.Add(C, GetDamage(C));
                        }
                    }
With:
Code:
                    List<coords> Line = new List<coords>(5);
                    if (Info.Targetting == TargetType.Linear)
                        Line = MyMath.LineCoords(User.Loc.X, User.Loc.Y, AimX, AimY, 10);
                    foreach (NPC C in World.H_NPCs.Values)
                    {
                        if ((C.Flags == 21 || C.Flags == 22) && User.Level >= C.Level)
                        {
                            if ((!RangeFromChar && MyMath.PointDistance(AimX, AimY, C.Loc.X, C.Loc.Y) <= Info.MaxDist) || MyMath.PointDistance(User.Loc.X, User.Loc.Y, C.Loc.X, C.Loc.Y) <= Info.MaxDist)
                                if (Info.Targetting == TargetType.Sector && InSector(C.Loc.X, C.Loc.Y) || Info.Targetting != TargetType.Sector)
                                    if (Info.Targetting == TargetType.Linear && Line.Contains(new coords(C.Loc.X, C.Loc.Y)) || Info.Targetting != TargetType.Linear)
                                        if (!NPCTargets.Contains(C))
                                            NPCTargets.Add(C, GetDamage(C));
                        }
                    }
And bam that should be it!
If Saint posts on this thread people should thank him as well.
02/01/2010 06:27 walmartboi#2
Great job.

+k

Edit: Got a couple errors when adding this.

FIXED -> Namespace "coords" could not be found. Are you missing an assemble reference?


HELP -> No overload for method 'Add' takes 2 arguments.
02/01/2010 07:04 pro4never#3
Sounds like the ones saying no overload for method 'add' takes 2 arguments are things in the source referring to the old function. Go to where they are and try to correct them (so they match how the new function works) using the fixed skill system as an example.


@ thread, not read through the entire math of that but assuming it works. Nice job.
02/01/2010 07:09 walmartboi#4
It's not other areas in the source, it's in what he posted:

Code:
public static List<coords> bresenham(int x0, int y0, int x1, int y1)
        {
            List<coords> ThisLine = new List<coords>();

            int dy = y1 - y0;
            int dx = x1 - x0;
            int stepx, stepy;

            if (dy < 0) { dy = -dy; stepy = -1; } else { stepy = 1; }
            if (dx < 0) { dx = -dx; stepx = -1; } else { stepx = 1; }
            dy <<= 1;                                                  
            dx <<= 1;                                                  

            [COLOR="Red"]ThisLine.Add(x0, y0);[/COLOR]
            if (dx > dy)
            {
                int fraction = dy - (dx >> 1);                         
                while (x0 != x1)
                {
                    if (fraction >= 0)
                    {
                        y0 += stepy;
                        fraction -= dx;                                
                    }
                    x0 += stepx;
                    fraction += dy;                                   
                    [COLOR="Red"]ThisLine.Add(x0, y0);[/COLOR]
                }
            }
            else
            {
                int fraction = dx - (dy >> 1);
                while (y0 != y1)
                {
                    if (fraction >= 0)
                    {
                        x0 += stepx;
                        fraction -= dy;
                    }
                    y0 += stepy;
                    fraction += dx;
                    [COLOR="Red"]ThisLine.Add(x0, y0);[/COLOR]
                }
            }
            return ThisLine;
        }
Marked the errors in red.
02/01/2010 07:12 dillhack#5
yes i get these too
02/01/2010 07:16 Arcо#6
Thats odd I don't get these at all.
And my code seems to be exactly the same.
02/01/2010 07:22 walmartboi#7
Yeah, it's a very odd error, I can't find a fix for it.
02/01/2010 07:35 pro4never#8
Quote:
Originally Posted by .Arco View Post
Thats odd I don't get these at all.
And my code seems to be exactly the same.
You most likely have a second void that only uses 2 inputs and that's why it works for you.
02/01/2010 07:55 walmartboi#9
Yeah, can you help us out a little bit arco?
02/01/2010 08:01 Arcо#10
Yeah I'm looking right now.
02/01/2010 08:20 walmartboi#11
Alrighty, it might just be that you have an extra definition that we don't have.
02/01/2010 08:50 Arcо#12
public struct coords
{
public int X;
public int Y;

public coords(int x, int y)
{
this.X = x;
this.Y = y;
}
}
was supposed to go OVER MyMath, not under.
02/01/2010 08:52 walmartboi#13
Nope, that still does not work. Add me on msn [Only registered and activated users can see links. Click Here To Register...] so we can figure this out.
02/01/2010 08:53 Arcо#14
Quote:
Originally Posted by walmartboi View Post
Nope, that still does not work. Add me on msn [Only registered and activated users can see links. Click Here To Register...] so we can figure this out.
You moved it from under to over?
02/01/2010 08:55 walmartboi#15
Nevermind, got it working, I'll post the results of how good it is when I build my source.

Edit: Works great while sitting down, but there are a few bugs when you ss/fb a monster while in air. But overall, great work! :P +k