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(); }
/// <summary> /// 显示风中粒子 /// </summary> /// <param name="role">所修饰角色</param> /// <param name="equipType">所参照的装备</param> /// <param name="particleType">粒子类型</param> /// <param name="color">颜色</param> /// <param name="amount">量</param> public void ShowWindParticles(RoleBase role, EquipTypes equipType, ParticleTypes particleType, double color, double amount) { ObjectBase equip = role.EquipEntity(equipType); if (!equip.IsVisible) { return; } int distance = 0; double speed = 0; if (role.Action == Actions.Stop) { distance = 40; speed = RandomSeed.Next(2000, 3000) * 0.01; } else { distance = 40; speed = RandomSeed.Next(1000, 1500) * 0.01; } int halfDistance = distance / 2; int obliqueDistance = distance * 2 / 3; Dispatcher.BeginInvoke(delegate { WriteableBitmap writeableBitmap = new WriteableBitmap(equip, null); if (writeableBitmap.Pixels.Count() != 0) { lock (writeableBitmap) { writeableBitmap.Invalidate(); int z = 0; if (equipType == EquipTypes.Weapon) { if (role.State == States.Riding && role.Direction != Directions.South) { z = role.Z + equip.Z + 5; } else { z = role.Z + equip.Z; } } else { z = (role.Direction == Directions.North || role.Direction == Directions.NorthEast || role.Direction == Directions.NorthWest) ? role.Z : role.Z - 20; } z -= role.ZAddition; Point position = equipType == EquipTypes.Overall ? role.Center : equip.Position; Point2D destination = new Point2D(); EffectBase effect = null; if (color == 0) { effect = new MonoChrome() { FilterColor = Colors.White }; } else if (color == 1) { effect = new MonoChrome() { FilterColor = Colors.Black }; } else { effect = new ShiftHue() { HueShift = color }; } switch (role.Direction) { case Directions.North: destination.X = 0; destination.Y = RandomSeed.Next(halfDistance, distance); break; case Directions.NorthEast: destination.X = -RandomSeed.Next(halfDistance, obliqueDistance); destination.Y = RandomSeed.Next(halfDistance, obliqueDistance); break; case Directions.East: destination.X = -RandomSeed.Next(halfDistance, distance); destination.Y = 0; break; case Directions.SouthEast: destination.X = -RandomSeed.Next(halfDistance, obliqueDistance); destination.Y = -RandomSeed.Next(halfDistance, obliqueDistance); break; case Directions.South: destination.X = 0; destination.Y = -RandomSeed.Next(halfDistance, distance); break; case Directions.SouthWest: destination.X = RandomSeed.Next(halfDistance, obliqueDistance); destination.Y = -RandomSeed.Next(halfDistance, obliqueDistance); break; case Directions.West: destination.X = RandomSeed.Next(halfDistance, distance); destination.Y = 0; break; case Directions.NorthWest: destination.X = RandomSeed.Next(halfDistance, obliqueDistance); destination.Y = RandomSeed.Next(halfDistance, obliqueDistance); break; } for (int i = 0; i < amount; i++) { int x = RandomSeed.Next(0, writeableBitmap.PixelWidth); int y = RandomSeed.Next(0, writeableBitmap.PixelHeight); byte[] bytes = BitConverter.GetBytes(writeableBitmap.Pixels[writeableBitmap.PixelWidth * y + x]); if (bytes[3] != 0) { Particle particle = new Particle() { SpaceLayer = role.SpaceLayer, Z = z, Effect = effect, Source = GlobalMethod.GetImage(string.Format("Particle/{0}{1}.png", particleType, RandomSeed.Next(0, 3)), UriType.Project) }; space.Children.Add(particle); EventHandler handler = null; particle.Disposed += handler = (s, e) => { Particle p = s as Particle; p.Disposed -= handler; space.Children.Remove(p); }; double pX = (position.X - x) * particle.Scale; double pY = (position.Y - y) * particle.Scale; particle.Move(new Point(role.Position.X - pX, role.Position.Y - pY), new Point(role.Position.X - pX + destination.X * particle.Scale, role.Position.Y - pY + destination.Y * particle.Scale), speed, MoveModes.Opacity); } } } } }); }
/// <summary> /// 显示追影(停止动作时不显示) /// </summary> /// <param name="role">所修饰角色</param> /// <param name="equipType">所参照的装备</param> /// <param name="color">颜色</param> /// <param name="coefficient">系数</param> public void ShowChasingShadow(RoleBase role, EquipTypes equipType, Color color, double coefficient) { if (role.Action != Actions.Stop) { ObjectBase equip = role.EquipEntity(equipType); if (!equip.IsVisible) { return; } WriteableBitmap writeableBitmap = new WriteableBitmap((int)role.OverallSize.X, (int)role.OverallSize.Y); writeableBitmap.Render(equip, null); writeableBitmap.Invalidate(); Rectangle rectangle = new Rectangle() { Width = role.OverallSize.X, Height = role.OverallSize.Y, Fill = new SolidColorBrush(color) }; rectangle.OpacityMask = new ImageBrush() { ImageSource = writeableBitmap }; writeableBitmap = new WriteableBitmap((int)role.OverallSize.X, (int)role.OverallSize.Y); writeableBitmap.Render(rectangle, null); writeableBitmap.Invalidate(); EntityObject chasingShadow = new EntityObject() { RenderTransform = role.RenderTransform, ImageSource = writeableBitmap, Center = role.Center, Position = role.Position, Z = role.Z - 20 }; space.Children.Add(chasingShadow); Storyboard storyboard = new Storyboard(); storyboard.Children.Add(GlobalMethod.CreateDoubleAnimation(chasingShadow,"Opacity",0.7,0, TimeSpan.FromMilliseconds(role.HeartInterval * coefficient),null)); EventHandler handler = null; storyboard.Completed += handler = delegate { storyboard.Completed -= handler; storyboard.Stop(); space.Children.Remove(chasingShadow); }; storyboard.Begin(); } }
/// <summary> /// 设置影子与角色动作同步变形(真实光影) /// </summary> /// <param name="role">角色</param> public void SetShadowSyncTo(RoleBase role) { if (role.IsVisible && ShadowType == ShadowTypes.Reality) { EntityObject shadow = shadowList.SingleOrDefault(X => X.ID == role.ID); if (shadow != null) { WriteableBitmap writeableBitmap = new WriteableBitmap((int)role.OverallSize.X, (int)role.OverallSize.Y); writeableBitmap.Render(role.EquipEntity(EquipTypes.Overall), null); writeableBitmap.Invalidate(); Rectangle rectangle = new Rectangle() { Width = role.OverallSize.X, Height = role.OverallSize.Y, Fill = new SolidColorBrush(Colors.Black) }; rectangle.OpacityMask = new ImageBrush() { ImageSource = writeableBitmap }; writeableBitmap = new WriteableBitmap((int)role.OverallSize.X, (int)role.OverallSize.Y); writeableBitmap.Render(rectangle, null); writeableBitmap.Invalidate(); shadow.ImageSource = writeableBitmap; if (shadow.Projection == null) { shadow.Projection = new PlaneProjection() { GlobalOffsetX = -role.Center.X + shadow.Center.X, GlobalOffsetY = -role.Center.Y + shadow.Center.Y, LocalOffsetX = -48, LocalOffsetY = 92, RotationX = 86, RotationY = 7.6 }; shadow.Opacity = 0.5; } } } }