public override void Run(Sprite caster, Scene scene, MagicArgs args) { double angle = Global.GetAngle(Global.GetRadian(Scene.GetWindowCoordinate(caster.Coordinate), args.Target)) + 180; double singleAngle = 360 / args.Number; for (int i = 0; i < args.Number; i++) { Animation magic = new Animation() { Code = args.Code, Coordinate = args.Coordinate, Z = args.Z }; EventHandler handler = null; magic.Disposed += handler = delegate { magic.Disposed -= handler; magic.Dispose(); scene.RemoveAnimation(magic); }; scene.AddAnimation(magic); magic.RenderTransform = new RotateTransform() { CenterX = magic.Center.X, CenterY = magic.Center.Y, Angle = angle + singleAngle * i }; } //捕获十字(圆)范围内将要伤害的精灵表 for (int i = 0; i < scene.sprites.Count; i++) { if (scene.sprites[i].IsVisible && caster.IsHostileTo(scene.sprites[i].Camp)) { if (scene.sprites[i].InCircle(Scene.GetGameCoordinate(args.Coordinate), args.Radius)) { Targets.Add(scene.sprites[i]); } } } //对精灵表中所有精灵进行魔法/技能伤害 foreach (Sprite sprite in Targets) { caster.CastingToHurt(sprite, args); } Targets.Clear(); }
/// <summary> /// 创建子魔法元素 /// </summary> void createSubMagic(RoleBase caster, Space space, MagicArgs args, double angle, double width) { double radian = GlobalMethod.GetRadian(angle); double x = width * Math.Cos(radian) + args.Position.X; double y = width * Math.Sin(radian) + args.Position.Y; Point position = new Point(x, y); Point p = space.Terrain.GetCoordinateFromPosition(position); //障碍物的位置不能放魔法 if (space.Terrain.InEffectiveRange(p)) { if ((args.SpaceLayer == SpaceLayers.Ground && space.Terrain.Matrix[(int)p.X, (int)p.Y] != 0) || args.SpaceLayer == SpaceLayers.Sky) { AnimationBase magic = new AnimationBase() { Code = args.ResCode, SpaceLayer = args.SpaceLayer, Position = position, Z = (int)y }; EventHandler handler = null; magic.Disposed += handler = delegate { magic.Disposed -= handler; space.RemoveAnimation(magic); }; space.AddAnimation(magic); //捕获圆范围内将要伤害的精灵表 for (int i = space.AllRoles().Count - 1; i >= 0; i--) { RoleBase target = space.AllRoles()[i]; if (caster.IsHostileTo(target) && target.InCircle(position, args.Radius * args.Scale)) { caster.CastingToEffect(target, args); } } } } }
void CreateSubMagic(RoleBase caster, Space space, MagicArgs args, int index) { AnimationBase animation = new AnimationBase() { Code = args.ResCode, Z = targets[index].Z + 1, Effect = shiftHue }; double offsetStartY = (caster.State == States.Riding ? (caster.Profession == Professions.Taoist ? 130 : 110) : 60) * caster.Scale; double offsetEndY = (targets[index].State == States.Riding ? 100 : 50) * caster.Scale; Point from = index == 0 ? new Point(args.Position.X, args.Position.Y - offsetStartY) : temp; Point to = new Point(targets[index].Position.X, targets[index].Position.Y - offsetEndY); temp = to; RotateTransform rotateTransform = new RotateTransform() { CenterX = animation.Center.X, CenterY = animation.Center.Y, Angle = GlobalMethod.GetAngle(to.Y - from.Y, to.X - from.X) }; ScaleTransform scaleTransform = new ScaleTransform() { CenterX = animation.Center.X, CenterY = animation.Center.Y, ScaleX = (GlobalMethod.GetDistance(index == 0 ? args.Position : targets[index - 1].Position, targets[index].Position) / 440), //440为其实体宽度,这里用了硬编码 ScaleY = caster.Scale }; TransformGroup transformGroup = new TransformGroup(); transformGroup.Children.Add(scaleTransform); transformGroup.Children.Add(rotateTransform); animation.RenderTransform = transformGroup; animation.Position = from; space.AddUIElement(animation); EventHandler handler = null; animation.End += handler = delegate { animation.End -= handler; space.RemoveAnimation(animation); if (index == targets.Count) { targets.Clear(); } }; animation.HeartStart(); }
public override void Run(RoleBase caster, Space space, MagicArgs args) { args.Position = args.MagicPosition == MagicPositions.Position ? args.Position : args.Destination; double angle = GlobalMethod.GetAngle(GlobalMethod.GetRadian(args.Position, args.Destination)) + 180; int count = 0; int number = 4; double width = 110 * args.Scale; EventHandler handler = null; DispatcherTimer timer = new DispatcherTimer() { Interval = TimeSpan.FromMilliseconds(100) }; timer.Tick += handler = delegate { if (count == args.Number) { timer.Tick -= handler; timer.Stop(); } else { createSubMagic(space, args, number, angle, width); count++; number += 2; width += 110 * args.Scale; } }; timer.Start(); //捕获圆范围内将要伤害的精灵表 for (int i = space.AllRoles().Count - 1; i >= 0; i--) { RoleBase target = space.AllRoles()[i]; if (caster.IsHostileTo(target) && target.InCircle(args.Position, args.Radius * args.Scale)) { caster.CastingToEffect(target, args); } } }
public override void Run(RoleBase caster, Space space, MagicArgs args) { targets.Add(args.Target); for (int i = space.AllRoles().Count - 1; i >= 0; i--) { if (targets.Count == args.Number) { break; } RoleBase target = space.AllRoles()[i]; if (caster.IsHostileTo(target) && target.InCircle(args.Destination, args.Radius * args.Scale)) { if (target != args.Target) { targets.Add(target); } } } int index = 0; CreateSubMagic(caster, space, args, index); DispatcherTimer timer = new DispatcherTimer() { Interval = TimeSpan.FromMilliseconds(200) }; EventHandler handler = null; timer.Tick += handler = delegate { if (caster.IsHostileTo(targets[index])) { caster.CastingToEffect(targets[index], args); } index++; if (index == targets.Count) { timer.Stop(); timer.Tick -= handler; } else { int newInterval = timer.Interval.Milliseconds - 30; if (newInterval <= 20) { newInterval = 20; } timer.Interval = TimeSpan.FromMilliseconds(newInterval); CreateSubMagic(caster, space, args, index); } }; timer.Start(); }
void CreateSubMagic(RoleBase caster,RoleBase startTarget, RoleBase endTarget, Space space, MagicArgs args) { AnimationBase animation = new AnimationBase() { Code = args.ResCode, Z = startTarget.Z + 1 }; double offsetStartY = (startTarget.State == States.Riding ? (startTarget.Profession == Professions.Taoist ? 130 : 110) : 60) * args.Scale; double offsetEndY = (endTarget.State == States.Riding ? 100 : 50) * args.Scale; Point from = new Point(startTarget.Position.X, startTarget.Position.Y - offsetStartY); Point to = new Point(endTarget.Position.X, endTarget.Position.Y - offsetEndY); RotateTransform rotateTransform = new RotateTransform() { CenterX = animation.Center.X, CenterY = animation.Center.Y, Angle = GlobalMethod.GetAngle(to.Y - from.Y, to.X - from.X) }; ScaleTransform scaleTransform = new ScaleTransform() { CenterX = animation.Center.X, CenterY = animation.Center.Y, ScaleX = (GlobalMethod.GetDistance(startTarget.Position, endTarget.Position) / Convert.ToInt32(args.Tag)), ScaleY = args.Scale }; TransformGroup transformGroup = new TransformGroup(); transformGroup.Children.Add(scaleTransform); transformGroup.Children.Add(rotateTransform); animation.RenderTransform = transformGroup; animation.Position = from; space.AddUIElement(animation); EventHandler handler = null; animation.End += handler = delegate { animation.End -= handler; space.RemoveAnimation(animation); }; animation.HeartStart(); }
void createMagic(Sprite caster, Scene scene, MagicArgs args, int count, double angle, double width) { Animation magic = new Animation() { Code = args.Code, Coordinate = args.Coordinate, Z = args.Z }; EventHandler handler = null; magic.Disposed += handler = delegate { magic.Disposed -= handler; scene.RemoveAnimation(magic); }; scene.AddAnimation(magic); double radian = Global.GetRadian(angle); double x = width * Math.Cos(radian) + magic.Coordinate.X; double y = width * Math.Sin(radian) + magic.Coordinate.Y; magic.Coordinate = new Point(x, y); //捕获圆范围内将要伤害的精灵表 for (int i = 0; i < scene.sprites.Count; i++) { if (scene.sprites[i].IsVisible && caster.IsHostileTo(scene.sprites[i].Camp)) { if (scene.sprites[i].InCircle(Scene.GetGameCoordinate(magic.Coordinate), args.Radius)) { Targets.Add(scene.sprites[i]); } } } //对精灵表中所有精灵进行魔法/技能伤害 foreach (Sprite sprite in Targets) { caster.CastingToHurt(sprite, args); } Targets.Clear(); }
public override void Run(RoleBase caster, Space space, MagicArgs args) { targets.Add(args.Target); for (int i = space.AllRoles().Count - 1; i >= 0; i--) { RoleBase target = space.AllRoles()[i]; if (caster.IsHostileTo(target) && target.InCircle(args.Destination, args.Radius * args.Scale)) { if (target != args.Target) { targets.Add(target); } if (targets.Count == args.Number) { break; } } } CreateSubMagic(caster, space, args); }
public override void Run(RoleBase caster, Space space, MagicArgs args) { int positionX = (int)args.Position.X, positionY = (int)args.Position.Y; int destinationX = (int)args.Destination.X, destinationY = (int)args.Destination.Y; int radius = (int)(100 * caster.Scale); for (int i = 0; i < args.Number; i++) { CircleMagic magic = new CircleMagic(); args.Position = new Point(ObjectBase.RandomSeed.Next(positionX - radius, positionX + radius), ObjectBase.RandomSeed.Next(positionY - radius, positionY + radius)); args.Destination = new Point(ObjectBase.RandomSeed.Next(destinationX - radius, destinationX + radius), ObjectBase.RandomSeed.Next(destinationY - radius, destinationY + radius)); magic.Run(caster, space, args); } }
public override void Run(Sprite caster, Scene scene, MagicArgs args) { double angle = Global.GetAngle(Global.GetRadian(Scene.GetWindowCoordinate(caster.Coordinate), args.Target)) + 180; Point p0 = new Point(args.Coordinate.X, args.Coordinate.Y - 20); Point p1 = new Point(args.Coordinate.X + args.Radius * Math.Cos(Global.GetRadian(angle)), args.Coordinate.Y + args.Radius * Math.Sin(Global.GetRadian(angle))); int count = 0; int number = args.Number; EventHandler handler = null; DispatcherTimer timer = new DispatcherTimer() { Interval = TimeSpan.FromMilliseconds(80) }; timer.Tick += handler = delegate { if (count == args.Number - 1) { timer.Tick -= handler; timer.Stop(); } else { count++; Animation magic = new Animation() { Code = args.Code, Coordinate = args.Coordinate, Z = args.Z }; EventHandler otherHandler = null; magic.Disposed += otherHandler = delegate { magic.Disposed -= otherHandler; scene.RemoveAnimation(magic); }; scene.AddAnimation(magic); magic.RenderTransform = new RotateTransform() { CenterX = magic.Center.X, CenterY = magic.Center.Y, Angle = angle }; EventHandler moveHandler = null; magic.MoveCompleted += moveHandler = delegate { magic.MoveCompleted -= moveHandler; magic.Dispose(); }; magic.Move(p0, p1, 1, MoveModes.Normal); } }; timer.Start(); //捕获多边形范围内将要伤害的精灵表 for (int i = 0; i < scene.sprites.Count; i++) { if (scene.sprites[i].IsVisible && caster.IsHostileTo(scene.sprites[i].Camp)) { if (scene.sprites[i].InPolygon(Global.GetRectRange(angle, p0, p1, args.Radius / 10))) { Targets.Add(scene.sprites[i]); } } } //对精灵表中所有精灵进行魔法/技能伤害 foreach (Sprite sprite in Targets) { caster.CastingToHurt(sprite, args); } Targets.Clear(); }
public override void Run(RoleBase caster, Space space, MagicArgs args) { EventHandler handler = null; AnimationBase animation = new AnimationBase() { Code = (int)args.ResCode, Position = args.Target.Center, Z = -1, }; animation.Disposed += handler = delegate { animation.Disposed -= handler; args.Target.RemoveEffect(EffectTypes.Cure); }; args.Target.AddEffect(animation, EffectTypes.Cure); caster.CastingToEffect(args.Target, args); }
public override void Run(RoleBase caster, Space space, MagicArgs args) { double distance = GlobalMethod.GetDistance(args.Position, args.Destination); double speed = 2; caster.LinearShuttle(args.Destination, distance * speed); int count = 0; EventHandler timerHandler = null; DispatcherTimer timer = new DispatcherTimer() { Interval = TimeSpan.FromMilliseconds(100) }; timer.Tick += timerHandler = delegate { caster.Target = null; if (count == args.Number || caster.Action != Actions.Attack) { timer.Tick -= timerHandler; timer.Stop(); } else { WriteableBitmap writeableBitmap = new WriteableBitmap((int)caster.OverallSize.X, (int)caster.OverallSize.Y); writeableBitmap.Render(caster.EquipEntity(EquipTypes.Overall), null); writeableBitmap.Invalidate(); EntityObject chasingShadow = new EntityObject() { RenderTransform = caster.RenderTransform, ImageSource = writeableBitmap, Center = caster.Center, Position = caster.Position, Z = caster.Z - 20 }; space.Children.Add(chasingShadow); Storyboard storyboard = new Storyboard(); storyboard.Children.Add(GlobalMethod.CreateDoubleAnimation(chasingShadow,"Opacity",0.9,0,TimeSpan.FromMilliseconds(caster.HeartInterval * 3),null)); EventHandler handler = null; storyboard.Completed += handler = delegate { storyboard.Completed -= handler; storyboard.Stop(); space.Children.Remove(chasingShadow); }; storyboard.Begin(); //每200毫秒伤害一次 if (count % 2 == 0) { for (int i = space.AllRoles().Count - 1; i >= 0; i--) { RoleBase target = space.AllRoles()[i]; if (caster.IsHostileTo(target) && target.InCircle(caster.Position, args.Radius * args.Scale)) { caster.CastingToEffect(target, args); } } } count++; } }; timer.Start(); }
public override void Run(RoleBase caster, Space space, MagicArgs args) { int count = 0; caster.AttackToHurt(args.Target); for (int i = space.AllRoles().Count - 1; i >= 0; i--) { RoleBase target = space.AllRoles()[i]; if (caster.IsHostileTo(target) && target.InCircle(args.Target.Position, args.Radius * args.Scale)) { if (target != args.Target) { CreateSubMagic(caster, args.Target, target, space, args); caster.CastingToEffect(target, args); count++; if (count == args.Number) { break; } } } } }
public override void Run(Sprite caster, Scene scene, MagicArgs args) { Animation magic = new Animation() { Code = args.Code, Coordinate = args.Coordinate, Z = args.Z }; EventHandler handler = null; magic.Disposed += handler = delegate { magic.Disposed -= handler; scene.RemoveAnimation(magic); }; scene.AddAnimation(magic); Animation animation = new Animation() { Code = 11, Coordinate = args.Coordinate }; EventHandler animationHandler = null; animation.Disposed += animationHandler = delegate { animation.Disposed -= animationHandler; scene.RemoveAnimation(animation); }; scene.AddAnimation(animation); //捕获圆范围内将要伤害的精灵表 for (int i = 0; i < scene.sprites.Count; i++) { if (scene.sprites[i].IsVisible && caster.IsHostileTo(scene.sprites[i].Camp)) { if (scene.sprites[i].InCircle(Scene.GetGameCoordinate(args.Coordinate), args.Radius)) { Targets.Add(scene.sprites[i]); } } } int count = 0; int number = args.Number; EventHandler timerHandler = null; DispatcherTimer timer = new DispatcherTimer() { Interval = TimeSpan.FromMilliseconds(350) }; timer.Tick += timerHandler = delegate { if (count == args.Number) { timer.Tick -= timerHandler; timer.Stop(); Targets.Clear(); } else { count++; if (count > 1) { args.SpecialEffect = SpecialEffects.None; scene.Shake(15, 10); } //对精灵表中所有精灵进行魔法/技能伤害 foreach (Sprite sprite in Targets) { caster.CastingToHurt(sprite, args); } } }; timer.Start(); }
public override void Run(RoleBase caster, Space space, MagicArgs args) { args.Position = args.MagicPosition == MagicPositions.Position ? args.Position : args.Destination; AnimationBase magic = new AnimationBase() { Code = args.ResCode, SpaceLayer = args.SpaceLayer, Position = args.Position, Z = args.MagicLayer == MagicLayers.Ground ? -1 : (int)args.Position.Y }; EventHandler handler = null; magic.Disposed += handler = delegate { magic.Disposed -= handler; space.RemoveAnimation(magic); }; space.AddAnimation(magic); for (int i = space.AllRoles().Count - 1; i >= 0; i--) { RoleBase target = space.AllRoles()[i]; if (target.InCircle(args.Position, args.Radius * args.Scale)) { caster.CastingToEffect(target, args); } } }
public override void Run(Sprite caster, Scene scene, MagicArgs args) { double angle = Global.GetAngle(Global.GetRadian(Scene.GetWindowCoordinate(caster.Coordinate), args.Target)) + 180; double singleAngle = 18; double startAngle = angle - ((args.Number - 1) / 2 * singleAngle); double endAngle = angle + ((args.Number - 1) / 2 * singleAngle); for (int i = 0; i < args.Number; i++) { double otherAngle = startAngle + singleAngle * i; Animation magic = new Animation() { Code = args.Code, Coordinate = args.Coordinate, Z = args.Z }; EventHandler magicHandler = null; magic.Disposed += magicHandler = delegate { magic.Disposed -= magicHandler; scene.RemoveAnimation(magic); }; scene.AddAnimation(magic); Point p = new Point(args.Coordinate.X + args.Radius * Math.Cos(Global.GetRadian(otherAngle)), args.Coordinate.Y + args.Radius * Math.Sin(Global.GetRadian(otherAngle))); EventHandler moveHandler = null; magic.MoveCompleted += moveHandler = delegate { magic.MoveCompleted -= moveHandler; magic.Dispose(); }; magic.Move(magic.Coordinate, p, 1.3, MoveModes.Normal); } double s0 = 0, s1 = 1, e0 = 0, e1 = 0; if (startAngle < 180 && endAngle > 180) { s0 = startAngle; e0 = 180; s1 = -180; e1 = endAngle - 360; } else if (startAngle >= 180) { s0 = startAngle - 360; e0 = endAngle - 360; } else { s0 = startAngle; e0 = endAngle; } for (int i = 0; i < scene.sprites.Count; i++) { if (scene.sprites[i].IsVisible && caster.IsHostileTo(scene.sprites[i].Camp)) { double spriteAngle = Global.GetAngle(Global.GetRadian(Scene.GetWindowCoordinate(scene.sprites[i].Coordinate), args.Coordinate)); if ((spriteAngle >= s0 && spriteAngle <= e0) || (spriteAngle >= s1 && spriteAngle <= e1)) { Targets.Add(scene.sprites[i]); } } } //对精灵表中所有精灵进行魔法/技能伤害 foreach (Sprite sprite in Targets) { caster.CastingToHurt(sprite, args); } Targets.Clear(); }
public override void Run(Sprite caster, Scene scene, MagicArgs args) { double angle = Global.GetAngle(Global.GetRadian(Scene.GetWindowCoordinate(caster.Coordinate), args.Target)) + 180; double width = 80; int count = 0; EventHandler handler = null; DispatcherTimer timer = new DispatcherTimer() { Interval = TimeSpan.FromMilliseconds(80) }; timer.Tick += handler = delegate { if (count == args.Number) { timer.Tick -= handler; timer.Stop(); } else { createMagic(caster, scene, args, count, angle, width); count++; width += 80; } }; timer.Start(); }
public override void Run(RoleBase caster, Space space, MagicArgs args) { double angle = GlobalMethod.GetAngle(GlobalMethod.GetRadian(args.Position, args.Destination)) + 180; double singleAngle = 10; double startAngle = angle - ((args.Number - 1) / 2 * singleAngle); double endAngle = angle + ((args.Number - 1) / 2 * singleAngle); for (int i = 0; i < args.Number; i++) { double otherAngle = startAngle + singleAngle * i; Bullet bullet = new Bullet(new BulletDatas() { Code = args.ResCode, Type = BulletTypes.Common }) { SpaceLayer = caster.SpaceLayer, Z = (int)args.Destination.Y, }; double offsetX = bullet.Source.PixelWidth * bullet.Scale; double offsetStartY = (caster.State == States.Riding ? (caster.Profession == Professions.Taoist ? 130 : 110) : 60) * bullet.Scale; double offsetEndY = 80 * bullet.Scale; EventHandler handler = null; bullet.MoveCompleted += handler = delegate { bullet.MoveCompleted -= handler; space.RemoveUIElement(bullet); }; space.AddUIElement(bullet); Point p = new Point(args.Destination.X + args.Radius * Math.Cos(GlobalMethod.GetRadian(otherAngle)), args.Destination.Y + args.Radius * Math.Sin(GlobalMethod.GetRadian(otherAngle))); bullet.Move(new Point(args.Position.X - offsetX, args.Position.Y - offsetStartY), new Point(p.X - offsetX, p.Y - offsetEndY), 0.6 / bullet.Scale, MoveModes.Normal); } double s0 = 0, s1 = 1, e0 = 0, e1 = 0; if (startAngle < 180 && endAngle > 180) { s0 = startAngle; e0 = 180; s1 = -180; e1 = endAngle - 360; } else if (startAngle >= 180) { s0 = startAngle - 360; e0 = endAngle - 360; } else { s0 = startAngle; e0 = endAngle; } for (int i = space.AllRoles().Count - 1; i >= 0; i--) { RoleBase target = space.AllRoles()[i]; if (caster.IsHostileTo(target)) { double tempAngle = GlobalMethod.GetAngle(GlobalMethod.GetRadian(target.Position, args.Position)); if ((tempAngle >= s0 && tempAngle <= e0) || (tempAngle >= s1 && tempAngle <= e1) || target.InCircle(args.Position, 50)) { caster.CastingToEffect(target, args); } } } }
public override void Run(RoleBase caster, Space space, MagicArgs args) { args.Position = args.MagicPosition == MagicPositions.Position ? args.Position : args.Destination; Point p = space.Terrain.GetCoordinateFromPosition(args.Position); if (space.Terrain.InEffectiveRange(p)) { if ((args.SpaceLayer == SpaceLayers.Ground && space.Terrain.Matrix[(int)p.X, (int)p.Y] != 0) || args.SpaceLayer == SpaceLayers.Sky) { AnimationBase magic = new AnimationBase() { Code = args.ResCode, SpaceLayer = args.SpaceLayer, Position = args.Position, Z = args.MagicLayer == MagicLayers.Ground ? -1 : (int)args.Position.Y, Loop = true }; //magic.RenderTransform = new RotateTransform() { // CenterX = magic.Center.X, // CenterY = magic.Center.Y, // Angle = GlobalMethod.GetAngle(args.Position.Y - caster.Position.Y, args.Position.X - caster.Position.X) //}; EventHandler handler = null; magic.Disposed += handler = delegate { magic.Disposed -= handler; space.RemoveAnimation(magic); }; space.AddAnimation(magic); int count = 0; DispatcherTimer timer = new DispatcherTimer() { Interval = TimeSpan.FromMilliseconds(Convert.ToInt32(args.Tag)) }; EventHandler timerHandler = null; timer.Tick += timerHandler = delegate { if (count == args.Number) { timer.Stop(); timer.Tick -= timerHandler; magic.Dispose(magic, null); } else { for (int i = space.AllRoles().Count - 1; i >= 0; i--) { RoleBase target = space.AllRoles()[i]; if (caster.IsHostileTo(target) && target.InCircle(args.Position, args.Radius * args.Scale)) { //Targets.Add(target); caster.CastingToEffect(target, args); } } } count++; }; timer.Start(); } } }
public override void Run(RoleBase caster, Space space, MagicArgs args) { args.Position = args.MagicPosition == MagicPositions.Position ? args.Position : args.Destination; double angle = GlobalMethod.GetAngle(GlobalMethod.GetRadian(args.Position, args.Destination)) + 180; double width = args.Radius * args.Scale; int count = 0; EventHandler handler = null; DispatcherTimer timer = new DispatcherTimer() { Interval = TimeSpan.FromMilliseconds(Convert.ToInt32(args.Tag)) }; timer.Tick += handler = delegate { if (count == args.Number) { timer.Tick -= handler; timer.Stop(); } else { createSubMagic(caster, space, args, angle, width); timer.Interval = TimeSpan.FromMilliseconds(timer.Interval.Milliseconds-10); count++; width += args.Radius * args.Scale; } }; timer.Start(); }
public override void Run(RoleBase caster, Space space, MagicArgs args) { int count = 0; int positionX = (int)args.Position.X, positionY = (int)args.Position.Y; int destinationX = (int)args.Destination.X, destinationY = (int)args.Destination.Y; int radius = (int)(130 * caster.Scale); EventHandler handler = null; DispatcherTimer timer = new DispatcherTimer() { Interval = TimeSpan.FromMilliseconds(150) }; timer.Tick += handler = delegate { if (count == args.Number) { timer.Tick -= handler; timer.Stop(); } else { CircleMagic magic = new CircleMagic(); args.Position = new Point(ObjectBase.RandomSeed.Next(positionX - radius, positionX + radius), ObjectBase.RandomSeed.Next(positionY - radius, positionY + radius)); args.Destination = new Point(ObjectBase.RandomSeed.Next(destinationX - radius, destinationX + radius), ObjectBase.RandomSeed.Next(destinationY - radius, destinationY + radius)); magic.Run(caster, space, args); if (args.SpecialEffect == SpecialEffects.Shake) { space.Shake(Convert.ToInt32(args.Tag)); } count++; } }; timer.Start(); }
/// <summary> /// 创建子魔法元素 /// </summary> void createSubMagic(Space space, MagicArgs args, double number, double angle, double width) { for (int i = 0; i < number; i++) { double tempAngle = angle + i * (360 / number); double tempRadian = GlobalMethod.GetRadian(tempAngle); double x = width * Math.Cos(tempRadian) + args.Position.X; double y = width * Math.Sin(tempRadian) + args.Position.Y; Point position = new Point(x, y); Point p = space.Terrain.GetCoordinateFromPosition(position); //障碍物的位置不能放魔法 if (space.Terrain.InEffectiveRange(p)) { if ((args.SpaceLayer == SpaceLayers.Ground && space.Terrain.Matrix[(int)p.X, (int)p.Y] != 0) || args.SpaceLayer == SpaceLayers.Sky) { AnimationBase magic = new AnimationBase() { Code = args.ResCode, SpaceLayer = args.SpaceLayer, Position = position, Z = (int)y }; EventHandler handler = null; magic.Disposed += handler = delegate { magic.Disposed -= handler; space.RemoveAnimation(magic); }; space.AddAnimation(magic); } } } }
public override void Run(Sprite caster, Scene scene, MagicArgs args) { Animation magic = new Animation() { Code = args.Code, Coordinate = args.Coordinate, Z = args.Z }; EventHandler handler = null; magic.Disposed += handler = delegate { magic.Disposed -= handler; scene.RemoveAnimation(magic); }; scene.AddAnimation(magic); scene.Wave(args.Coordinate); for (int i = 0; i < scene.sprites.Count; i++) { if (scene.sprites[i].IsVisible && caster.IsHostileTo(scene.sprites[i].Camp)) { if (scene.sprites[i].InCircle(Scene.GetGameCoordinate(args.Coordinate), args.Radius)) { Targets.Add(scene.sprites[i]); } } } //对精灵表中所有精灵进行魔法/技能伤害 foreach (Sprite sprite in Targets) { caster.CastingToHurt(sprite, args); } Targets.Clear(); }
void CreateSubMagic(RoleBase caster, Space space, MagicArgs args) { Bullet bullet = new Bullet(new BulletDatas() { Code = args.ResCode, Type = BulletTypes.Animation,Loop = true }) { SpaceLayer = caster.SpaceLayer, Z = (int)args.Destination.Y, }; double offsetX = bullet.Offset.X * bullet.Scale; double offsetStartY = (caster.State == States.Riding ? (caster.Profession == Professions.Taoist ? 130 : 110) : 60) * bullet.Scale; double offsetEndY = (targets[index].State == States.Riding ? 100 : 70) * bullet.Scale; EventHandler handler = null; bullet.MoveCompleted += handler = delegate { bullet.MoveCompleted -= handler; space.RemoveUIElement(bullet); if (caster.IsHostileTo(targets[index])) { caster.CastingToEffect(targets[index], args); } index++; if (index == targets.Count) { targets.Clear(); } else { CreateSubMagic(caster, space, args); } }; space.AddUIElement(bullet); bullet.Move(new Point((index == 0 ? args.Position.X : targets[index - 1].Position.X) - offsetX, (index == 0 ? args.Position.Y : targets[index - 1].Position.Y) - offsetStartY), new Point(targets[index].Position.X - offsetX, targets[index].Position.Y - offsetEndY), 0.9 / bullet.Scale, MoveModes.Normal); }
/// <summary> /// 重写释放方法 /// </summary> public override void Dispose() { Target = null; magicArgs = null; auxiliary.Stop(); auxiliary.Tick -= auxiliaryTick; UnloadStoryboardEvent(storyboard); base.Dispose(); }
/// <summary> /// 魔法/技能攻击产生伤害 /// </summary> public void CastingToHurt(Sprite obj,MagicArgs args) { //各种伤害情况判断(实际不这么写,需要真实的数值公式计算) int damage = Global.random.Next(this.MAG + args.DamageMin, this.MAG + args.DamageMax); obj.ChangeLife(-damage, ValueEffects.Decrease); //伤害后如果对象生命为0 if (obj.Life == 0) { obj.ChangeLife(0, ValueEffects.Death); obj.IsAlive = false; if (State == States.Attack) { this.Stand(); } this.Target = null; } else { //显示魔法装饰特效 if (args.SpecialEffect != SpecialEffects.None) { Animation animation = new Animation() { Code = (int)args.SpecialEffect, Coordinate = obj.Center }; EventHandler handler = null; animation.Disposed += handler = delegate { animation.Disposed -= handler; obj.RemoveTemporaryEffect(); }; obj.AddTemporaryEffect(animation); } //魔法附加效果 switch (args.AdditionalEffect) { case AdditionalEffects.Injure: obj.Injure(); break; case AdditionalEffects.Bounce: obj.BeBounce(Scene.GetGameCoordinate(args.Coordinate), 100, 500); break; case AdditionalEffects.BeKnock: obj.BeKnock(40); break; } } }
/// <summary> /// 魔法/技能攻击 /// </summary> /// <param name="magicArgs">魔法/技能参数</param> public void Casting(MagicArgs magicArgs) { if (isActionLocked) { return; } this.magicArgs = magicArgs; if (State != States.Casting) { if (storyboard != null) { storyboard.Pause(); } frame.Current = 0; State = States.Casting; frame.Total = frames.CastingTotal; HeartInterval = frames.CastingInterval; } }
/// <summary> /// 魔法/技能攻击产生效果(伤害/治疗) /// </summary> public void CastingToEffect(RoleBase target, MagicArgs args) { //依据魔法实效类型处理 switch (args.MagicEffectType) { case MagicEffectTypes.Gain: target.ChangeLife(Convert.ToInt32(args.Tag), ValueEffects.Increase); break; case MagicEffectTypes.Reduction: //模拟伤害计算 int damage = RandomSeed.Next(this.MAG + args.EffectMin, this.MAG + args.EffectMax); if (RandomSeed.Next(100) > 90) { target.ChangeLife(0, ValueEffects.Failure); return; } else if (RandomSeed.Next(100) > 85) { //暴击 target.ChangeLife(-damage * 2, ValueEffects.DoubleDecrease); } else { target.ChangeLife(-damage, ValueEffects.Decrease); } //伤害后如果对象生命为0 if (target.Life == 0) { target.ChangeLife(0, ValueEffects.Death); if (Action == Actions.Attack && !isSpecialMove) { this.Stop(); } this.Target = null; return; } break; } //显示魔法附加效果 if (args.AdditionalEffect != AdditionalEffects.None) { EventHandler handler = null; AnimationBase animation = new AnimationBase() { Code = (int)args.AdditionalEffect, Position = target.Center, Z = 1000, }; animation.Disposed += handler = (s0, e0) => { animation.Disposed -= handler; target.RemoveEffect(EffectTypes.Temporary); }; target.AddEffect(animation, EffectTypes.Temporary); } //魔法特殊效果 switch (args.SpecialEffect) { case SpecialEffects.Injure: target.Injure(); break; case SpecialEffects.Bounce: target.BeBounce(args.Position, Convert.ToDouble(args.Tag), 500); break; case SpecialEffects.Knock: //target.BeKnock(40); break; case SpecialEffects.Freeze: //测试,50%几率命中 if (RandomSeed.Next(100) > 50) { target.BeFreeze(Convert.ToDouble(args.Tag)); } break; case SpecialEffects.Petrifaction: //测试,50%几率命中 if (RandomSeed.Next(100) > 50) { target.BePetrifaction(Convert.ToDouble(args.Tag)); } break; case SpecialEffects.Poison: target.BePoison(RandomSeed.Next(200, 500), Convert.ToDouble(args.Tag)); break; case SpecialEffects.Quiver: target.Quiver(6); break; } }
/// <summary> /// 魔法/技能攻击 /// </summary> /// <param name="magicArgs">魔法/技能参数</param> public void Casting(MagicArgs magicArgs) { if (isActionLock || isFreeze || isPetrifaction || isSpecialMove) { return; } if (State == States.Sitting) { State = States.Walking; } if (Action != Actions.Casting) { this.magicArgs = magicArgs; UnloadMoveEvent(); Action = Actions.Casting; //动作与攻击的一致 frame.Current = 0; frame.Max = frames.AttackMax; HeartInterval = frames.AttackInterval * 2 / 3; //速度稍微快些 } }
public override void Run(RoleBase caster, Space space, MagicArgs args) { caster.ClearAttacher(); for (int i = 0; i < args.Number; i++) { Point p = new Point(caster.Coordinate.X + RandomSeed.Next(-5, 5), caster.Coordinate.Y + RandomSeed.Next(-5, 5)); if (!space.Terrain.InEffectiveRange(p) || (args.SpaceLayer == SpaceLayers.Ground && space.Terrain.Matrix[(int)p.X, (int)p.Y] == 0)) { p = caster.Coordinate; } AnimationBase magic = new AnimationBase() { Code = args.ResCode, SpaceLayer = args.SpaceLayer, Position = space.Terrain.GetPositionFromCoordinate(p), Z = args.MagicLayer == MagicLayers.Ground ? -1 : (int)args.Position.Y }; EventHandler handler = null; magic.Disposed += handler = delegate { magic.Disposed -= handler; space.RemoveAnimation(magic); }; space.AddAnimation(magic); //解析配置 XElement xMonster = Infos["Monster"].DescendantsAndSelf("Monsters").Elements().Single(X => X.Attribute("ID").Value == args.AdditionalEffect.ToString()); Monster monster = new Monster(space.Terrain) { ID = (int)xMonster.Attribute("ID") + countID, AttachID = caster.AttachID, Code = (int)xMonster.Attribute("Code"), ArmorCode = (int)xMonster.Attribute("ArmorCode"), AttackRange = (int)xMonster.Attribute("AttackRange"), FullName = string.Format("{0}的召唤兽", caster.FullName), Profession = Professions.Monster, Direction = caster.Direction, State = States.Walking, Camp = caster.Camp, LifeMax = Convert.ToDouble(args.Tag), Life = Convert.ToDouble(args.Tag), SpaceLayer = caster.SpaceLayer, Coordinate = p, TacticAI = TacticAIs.GuardMaster, ActionAI = ActionAIs.Simple, FullNameColor = Colors.Orange, ATK = ObjectBase.RandomSeed.Next(1300, 1600), DEF = ObjectBase.RandomSeed.Next(600, 900), MAG = ObjectBase.RandomSeed.Next(400, 500), DEX = ObjectBase.RandomSeed.Next(0, 30), }; if (xMonster.Attribute("LearnedMagic").Value != string.Empty) { string[] str = xMonster.Attribute("LearnedMagic").Value.Split(','); for (int j = 0; j < str.Count(); j++) { string[] value = str[j].Split('_'); monster.LearnedMagic.Add(Convert.ToInt32(value[0]), Convert.ToInt32(value[1])); } } space.AddRole(monster, new RoleAddedEventArgs() { RegisterDisposedEvent = (bool)xMonster.Attribute("RegisterDisposedEvent"), RegisterIntervalTriggerEvent = (bool)xMonster.Attribute("RegisterIntervalTriggerEvent"), RegisterActionTriggerEvent = (bool)xMonster.Attribute("RegisterActionTriggerEvent"), RegisterDoAttackEvent = (bool)xMonster.Attribute("RegisterDoAttackEvent"), RegisterDoCastingEvent = (bool)xMonster.Attribute("RegisterDoCastingEvent"), RegisterPositionChangedEvent = (bool)xMonster.Attribute("RegisterPositionChangedEvent"), RegisterLifeChangedEvent = (bool)xMonster.Attribute("RegisterLifeChangedEvent"), }); monster.Master = caster; caster.AttachRoles.Add(monster); countID++; if (countID == 10000) { countID = 0; } } }