Crystal icon indicating copy to clipboard operation
Crystal copied to clipboard

Fix Code “FullmoonAttack”

Open angelk727 opened this issue 2 years ago • 0 comments

Old Code:

protected virtual void FullmoonAttack(int damage, int delay = 500, DefenceType defenceType = DefenceType.ACAgility, int pushDistance = -1, int distance = 1) { MirDirection dir = Direction;

        bool pushed = false;

        for (int j = 1; j <= distance; j++)
        {
            for (int i = 0; i < 8; i++)
            {
                dir = Functions.NextDir(dir);
                Point point = Functions.PointMove(CurrentLocation, dir, j);

                if (!CurrentMap.ValidPoint(point)) continue;

                Cell cell = CurrentMap.GetCell(point);

                if (cell.Objects == null) continue;

                for (int o = 0; o < cell.Objects.Count; o++)
                {
                    MapObject ob = cell.Objects[o];
                    if (ob.Race != ObjectType.Player && ob.Race != ObjectType.Monster && ob.Race != ObjectType.Hero) continue;
                    if (!ob.IsAttackTarget(this)) continue;

                    if (pushDistance > 0 && !pushed)
                    {
                        ob.Pushed(this, Direction, pushDistance);
                        pushed = true;
                    }

                    DelayedAction action = new DelayedAction(DelayedType.Damage, Envir.Time + delay, ob, damage, defenceType);
                    ActionList.Add(action);
                    break;
                }
            }
        }     
    }

Code after repair:Increase judgment on direction

    protected virtual void FullmoonAttack(int damage, int delay = 500, DefenceType defenceType = DefenceType.ACAgility, int pushDistance = -1, int distance = 1) //修改推动的方向问题
    {
        MirDirection dir = Direction;
        List<MapObject> targets = new List<MapObject>();

        for (int j = 1; j <= distance; j++)
        {
            for (int i = 0; i < 8; i++)
            {
                dir = Functions.NextDir(dir);
                Point point = Functions.PointMove(CurrentLocation, dir, j);

                if (!CurrentMap.ValidPoint(point)) continue;

                Cell cell = CurrentMap.GetCell(point);

                if (cell.Objects == null) continue;

                foreach (MapObject ob in cell.Objects)
                {
                    if (ob.Race != ObjectType.Player && ob.Race != ObjectType.Monster && ob.Race != ObjectType.Hero) continue;
                    if (!ob.IsAttackTarget(this)) continue;
                    targets.Add(ob);
                }
            }
        }

        foreach (MapObject ob in targets)
        {
            MirDirection pushDir;

            if (distance == 1)
            {
                pushDir = Functions.ReverseDirection(dir);
            }
            else
            {
                pushDir = Functions.DirectionFromPoint(CurrentLocation, ob.CurrentLocation);
            }

            if (pushDistance > 0 && !ob.InSafeZone)
            {
                ob.Pushed(this, pushDir, pushDistance);
            }

            ActionList.Add(new DelayedAction(DelayedType.Damage, Envir.Time + delay, ob, damage, defenceType));
        }
    }

angelk727 avatar May 26 '23 15:05 angelk727