/// <summary> /// Use magic. /// </summary> /// <param name="user">The magic user.</param> /// <param name="magic">Magic to use.</param> /// <param name="origin">Magic initial pixel postion in world.</param> /// <param name="destination">Magic destination pixel postiont in world.</param> /// <param name="target">Magic target</param> /// <param name="recursiveCounter"></param> public static void UseMagic(Character user, Magic magic, Vector2 origin, Vector2 destination, Character target = null, int recursiveCounter = 0) { if (user == null || magic == null) { return; } if (magic.SecondMagicFile != null) { AddUseMagicItem(new UseMagicInfoItem(magic.SecondMagicDelay, user, magic.SecondMagicFile, origin, destination, target)); } if (magic.BodyRadius > 0 && target != null && recursiveCounter == 0) { foreach (var body in ObjManager.GetBodyInRaidus(target.TilePosition, magic.BodyRadius, true)) { UseMagic(user, magic, body.PositionInWorld, destination, target, recursiveCounter + 1); } return; } _maigicSpriteIndex = 0; if (magic.FlyingSound != null) { magic.FlyingSound.Play(); } if (magic.BeginAtMouse > 0) { var dir = origin - destination; if (dir != Vector2.Zero) { dir.Normalize(); } origin = destination + dir; } else if (magic.BeginAtUser > 0) { destination = origin; } else if (magic.BeginAtUserAddDirectionOffset > 0) { var dir = destination - origin; if (dir != Vector2.Zero) { dir.Normalize(); } destination = origin + dir; } else if (magic.BeginAtUserAddUserDirectionOffset > 0) { var dir = Utils.GetDirection8(user.CurrentDirection); destination = origin + dir; } if (magic.MeteorMove > 0) { origin = destination; } switch (magic.MoveKind) { case 1: AddFixedPositionMagicSprite(user, magic, destination, true); break; case 2: AddMagicSprite(GetMoveMagicSprite(user, magic, origin, destination, false, GetSpeedRatio(destination - origin))); break; case 3: AddLineMoveMagicSprite(user, magic, origin, destination, false); break; case 4: AddCircleMoveMagicSprite(user, magic, origin, false); break; case 5: AddHeartMoveMagicSprite(user, magic, origin, false); break; case 6: AddSpiralMoveMagicSprite(user, magic, origin, destination, false); break; case 7: AddSectorMoveMagicSprite(user, magic, origin, destination, false); break; case 8: AddRandomSectorMoveMagicSprite(user, magic, origin, destination, false); break; case 9: AddFixedWallMagicSprite(user, magic, origin, destination, true); break; case 10: AddWallMoveMagicSprite(user, magic, origin, destination, false); break; case 11: { switch (magic.Region) { case 1: AddSquareFixedPositionMagicSprite(user, magic, destination, true); break; case 2: AddCrossFixedPositionMagicSprite(user, magic, origin, true); break; case 3: AddRegtangleFixedPositionMagicSprite(user, magic, origin, destination, true); break; case 4: AddIsoscelesTriangleMagicSprite(user, magic, origin, destination, true); break; case 5: AddVTypeFixedPOsitionMagicSprite(user, magic, origin, destination, true); break; case 6: AddRegionFileMagicSprite(user, magic, origin, destination, true); break; } break; } case 13: case 23: AddFollowCharacterMagicSprite(user, magic, origin, true, target); break; case 15: AddSuperModeMagic(user, magic, origin, true); break; case 16: AddFollowEnemyMagicSprite(user, magic, origin, destination, false); break; case 17: AddThrowMagicSprite(user, magic, origin, destination, true); break; case 18: //Empty break; case 19: { var info = new Kind19MagicInfo(magic.KeepMilliseconds, magic, user); _kind19Magics.AddLast(info); } break; case 20: { //Can't use transport magic when in transport if (!user.IsInTransport) { user.IsInTransport = true; AddFixedPositionMagicSprite(user, magic, destination, true); } } break; case 21: { var player = user as Player; if (player != null && target != null && !target.IsDeathInvoked && // Can't control dead people target.Level <= magic.MaxLevel ) { player.ControledCharacter = target; AddFixedPositionMagicSprite(user, magic, user.PositionInWorld, true); } } break; case 22: { AddFixedPositionMagicSprite(user, magic, destination, true); } break; } //Magic side effect if (magic.SideEffectProbability > 0 && Globals.TheRandom.Next(0, 100) < magic.SideEffectProbability) { var amount = ((GetEffectAmount(magic, user) + GetEffectAmount2(magic, user)) * magic.SideEffectPercent) / 100; switch ((Magic.SideEffectDamageType)magic.SideEffectType) { case Magic.SideEffectDamageType.Life: user.DecreaseLifeAddHurt(amount); break; case Magic.SideEffectDamageType.Mana: user.AddMana(-amount); break; case Magic.SideEffectDamageType.Thew: user.AddThew(-amount); break; default: throw new ArgumentOutOfRangeException(); } } if (magic.DieAfterUse > 0) { user.Death(); } }
private static void AddFollowEnemyMagicSprite(Character user, Magic magic, Vector2 origin, Vector2 destination, bool destroyOnEnd) { AddMagicSprite(GetMoveMagicSprite(user, magic, origin, destination, destroyOnEnd)); }
private static void AddSuperModeMagic(Character user, Magic magic, Vector2 origin, bool destroyOnEnd) { Globals.IsInSuperMagicMode = true; Globals.SuperModeMagicSprite = GetFixedPositionMagicSprite(user, magic, origin, destroyOnEnd); }
private static void AddRegtangleFixedPositionMagicSprite(Character user, Magic magic, Vector2 origin, Vector2 destination, bool destroyOnEnd) { var direction = destination - origin; var directionIndex = Utils.GetDirectionIndex(direction, 8); const int columnCount = 5; var count = 3; if (magic.EffectLevel > 3) { count += ((magic.EffectLevel - 1) / 3) * 2; } const float magicDelayMilliseconds = 60f; switch (directionIndex) { case 1: case 3: case 5: case 7: { Vector2 beginPosition = origin, offsetColumn = new Vector2(), offsetRow = new Vector2(); switch (directionIndex) { case 1: offsetColumn = new Vector2(32, 16); offsetRow = new Vector2(-32, 16); break; case 3: offsetColumn = new Vector2(32, -16); offsetRow = new Vector2(-32, -16); break; case 5: offsetColumn = new Vector2(32, 16); offsetRow = new Vector2(32, -16); break; case 7: offsetColumn = new Vector2(32, -16); offsetRow = new Vector2(32, 16); break; } for (var i = 0; i < count; i++) { beginPosition += offsetRow; AddFixedWallMagicSprite(user, magic, beginPosition, offsetColumn, columnCount, destroyOnEnd, i * magicDelayMilliseconds); } } break; case 0: case 4: { var offsetRow = new Vector2(0, -32); if (directionIndex == 0) { offsetRow = new Vector2(0, 32); } var beginPosition = origin; for (var i = 0; i < count; i++) { beginPosition += offsetRow; AddHorizontalFixedWallMagicSprite(user, magic, beginPosition, columnCount, destroyOnEnd, i * magicDelayMilliseconds); } } break; case 2: { var beginPostion = origin; var offsetColumn = new Vector2(0, 32); for (var i = 0; i < count; i++) { if (i % 2 == 0) { beginPostion += new Vector2(-32, -16); } else { beginPostion += new Vector2(-32, 16); } AddFixedWallMagicSprite(user, magic, beginPostion, offsetColumn, columnCount, destroyOnEnd, i * magicDelayMilliseconds); } } break; case 6: { var beginPostion = origin; var offsetColumn = new Vector2(0, 32); for (var i = 0; i < count; i++) { if (i % 2 == 0) { beginPostion += new Vector2(32, 16); } else { beginPostion += new Vector2(32, -16); } AddFixedWallMagicSprite(user, magic, beginPostion, offsetColumn, columnCount, destroyOnEnd, i * magicDelayMilliseconds); } } break; } }
/// <summary> /// /// </summary> /// <param name="equip"></param> /// <param name="currentEquip"></param> /// <param name="justEffectType">Don't applay Attack, Defend,Evade,LifeMax,ThewMax,ManaMax, just equip effect</param> public void Equiping(Good equip, Good currentEquip, bool justEffectType = false) { //Save for restore var life = Life; var thew = Thew; var mana = Mana; UnEquiping(currentEquip, justEffectType); if (equip != null) { if (!justEffectType) { Attack += equip.Attack; Defend += equip.Defend; Evade += equip.Evade; LifeMax += equip.LifeMax; ThewMax += equip.ThewMax; ManaMax += equip.ManaMax; } switch (equip.TheEffectType) { case Good.GoodEffectType.ThewNotLoseWhenRun: IsNotUseThewWhenRun = true; break; case Good.GoodEffectType.ManaRestore: IsManaRestore = true; break; case Good.GoodEffectType.EnemyFrozen: SetFlyIniAdditionalEffect(Magic.AddonEffect.Frozen); break; case Good.GoodEffectType.EnemyPoisoned: SetFlyIniAdditionalEffect(Magic.AddonEffect.Poision); break; case Good.GoodEffectType.EnemyPetrified: SetFlyIniAdditionalEffect(Magic.AddonEffect.Petrified); break; } switch (equip.SpecialEffect) { case 1: //不断恢复生命 _extraLifeRestorePercent = equip.SpecialEffectValue / 100.0f; break; } if (!string.IsNullOrEmpty(equip.FlyIni)) { _flyIniReplace = Utils.GetMagic(equip.FlyIni, MagicFromCache); } if (!string.IsNullOrEmpty(equip.FlyIni2)) { _flyIni2Replace = Utils.GetMagic(equip.FlyIni2, MagicFromCache); } } //Restore Life = life; Thew = thew; Mana = mana; }
public void CopyInfo(Magic magic) { AdditionalEffect = magic.AdditionalEffect; ItemInfo = magic.ItemInfo; }