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(); }
/// <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); } } } } }
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(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(); } } }
/// <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(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; } } }
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(); }