internal void MonsterLife() { LifeTaskIsRunning = true; NpcMonster monster = ServerManager.GetNpc(this.MonsterVNum); //Respawn if (!Alive) { double timeDeath = (DateTime.Now - Death).TotalSeconds; if (timeDeath >= monster.RespawnTime / 10) { Alive = true; Target = -1; CurrentHp = monster.MaxHP; CurrentMp = monster.MaxMP; MapX = firstX; MapY = firstY; Map.Broadcast(GenerateIn3()); Map.Broadcast(GenerateEff(7)); } LifeTaskIsRunning = false; return; } else if (Target == -1) { //Normal Move Mode if (monster == null || Alive == false) { LifeTaskIsRunning = false; return; } Random r = new Random((int)DateTime.Now.Ticks & 0x0000FFFF); double time = (DateTime.Now - LastMove).TotalSeconds; int MoveFrequent = 5 - (int)Math.Round((double)(monster.Speed / 5)); if (MoveFrequent < 1) { MoveFrequent = 1; } if (IsMoving) { if (path.Where(s => s != null).ToList().Count > 0)//fix a path problem { if ((DateTime.Now - LastMove).TotalSeconds > 1.0 / monster.Speed) { short MapX = path.ElementAt(0).X; short MapY = path.ElementAt(0).Y; path.RemoveAt(0); LastMove = DateTime.Now; Map.Broadcast($"mv 3 {this.MapMonsterId} {this.MapX} {this.MapY} {monster.Speed}"); Task.Factory.StartNew(async() => { await Task.Delay(500); this.MapX = MapX; this.MapY = MapY; }); LifeTaskIsRunning = false; return; } } else if (time > r.Next(1, MoveFrequent) + 1) { int MoveDistance = (int)Math.Round((double)monster.Speed / 2); byte xpoint = (byte)(r.Next(1, MoveDistance)); byte ypoint = (byte)(r.Next(1, MoveDistance)); short MapX = firstX; short MapY = firstY; if (ServerManager.GetMap(MapId).GetFreePosition(ref MapX, ref MapY, xpoint, ypoint)) { LastMove = DateTime.Now; string movepacket = $"mv 3 {this.MapMonsterId} {MapX} {MapY} {monster.Speed}"; Map.Broadcast(movepacket); Task.Factory.StartNew(async() => { await Task.Delay(500); this.MapX = MapX; this.MapY = MapY; }); } } } if (monster.IsHostile) { Character character = ServerManager.Instance.Sessions.Where(s => s.Character != null && s.Character.Hp > 0).OrderBy(s => Map.GetDistance(new MapCell() { X = MapX, Y = MapY }, new MapCell() { X = s.Character.MapX, Y = s.Character.MapY })).FirstOrDefault(s => s.Character != null && !s.Character.Invisible && s.Character.MapId == MapId)?.Character; if (character != null) { if (Map.GetDistance(new MapCell() { X = character.MapX, Y = character.MapY }, new MapCell() { X = MapX, Y = MapY }) < 7) { Target = character.CharacterId; if (!monster.NoAggresiveIcon) { ServerManager.Instance.Sessions.FirstOrDefault(s => s != null && s.Client != null && s.Character != null && s.Character.CharacterId.Equals(Target)).Client.SendPacket(GenerateEff(5000)); } } } } } else { short?MapX = ServerManager.Instance.GetProperty <short?>(Target, "MapX"); short?MapY = ServerManager.Instance.GetProperty <short?>(Target, "MapY"); int? Hp = ServerManager.Instance.GetProperty <int?>(Target, "Hp"); short?mapId = ServerManager.Instance.GetProperty <short?>(Target, "MapId"); bool? invisible = ServerManager.Instance.GetProperty <bool?>(Target, "Invisible"); if (MapX == null || MapY == null || Hp <= 0 || invisible != null && (bool)invisible) { Target = -1; LifeTaskIsRunning = false; return; } Random r = new Random((int)DateTime.Now.Ticks & 0x0000FFFF); NpcMonsterSkill ski = monster.Skills.Where(s => !s.Used && (DateTime.Now - s.LastUse).TotalMilliseconds >= 100 * ServerManager.GetSkill(s.SkillVNum).Cooldown).OrderBy(rnd => r.Next()).FirstOrDefault(); Skill sk = null; if (ski != null) { sk = ServerManager.GetSkill(ski.SkillVNum); } ClientSession targetSession = Map.Sessions.SingleOrDefault(s => s.Character.CharacterId == Target); int damage = 100; if (targetSession != null && (sk != null && Map.GetDistance(new MapCell() { X = this.MapX, Y = this.MapY }, new MapCell() { X = (short)MapX, Y = (short)MapY }) < sk.Range) || (Map.GetDistance(new MapCell() { X = this.MapX, Y = this.MapY }, new MapCell() { X = (short)MapX, Y = (short)MapY }) <= monster.BasicRange)) { if ((sk != null && ((DateTime.Now - LastEffect).TotalMilliseconds >= sk.Cooldown * 100 + 1000)) || ((DateTime.Now - LastEffect).TotalMilliseconds >= (monster.BasicCooldown < 4 ? 4 : monster.BasicCooldown) * 100 + 100)) { if (ski != null) { ski.Used = true; ski.LastUse = DateTime.Now; Map.Broadcast($"ct 3 {MapMonsterId} 1 {Target} {sk.CastAnimation} -1 {sk.SkillVNum}"); } LastMove = DateTime.Now; // deal 0 damage to GM with GodMode if (targetSession == null) { damage = 0; } else { damage = targetSession.Character.HasGodMode ? 0 : 100; } if (sk != null && sk.CastEffect != 0) { Map.Broadcast(GenerateEff(sk.CastEffect)); Thread.Sleep(sk.CastTime * 100); } path = new List <MapCell>(); targetSession.Character.LastDefence = DateTime.Now; targetSession.Character.GetDamage(damage); Map.Broadcast(null, ServerManager.Instance.GetUserMethod <string>(Target, "GenerateStat"), ReceiverType.OnlySomeone, "", Target); if (sk != null) { Map.Broadcast($"su 3 {MapMonsterId} 1 {Target} {ski.SkillVNum} {sk.Cooldown} {sk.AttackAnimation} {sk.Effect} {this.MapX} {this.MapY} {(targetSession.Character.Hp > 0 ? 1 : 0)} {(int)((double)targetSession.Character.Hp / ServerManager.Instance.GetUserMethod<double>(Target, "HPLoad"))} {damage} 0 0"); } else { Map.Broadcast($"su 3 {MapMonsterId} 1 {Target} 0 {monster.BasicCooldown} 11 {monster.BasicSkill} 0 0 {(targetSession.Character.Hp > 0 ? 1 : 0)} {(int)((double)targetSession.Character.Hp / ServerManager.Instance.GetUserMethod<double>(Target, "HPLoad"))} {damage} 0 0"); } if (ski != null) { ski.Used = false; } LastEffect = DateTime.Now; if (targetSession.Character.Hp <= 0) { Thread.Sleep(1000); ServerManager.Instance.AskRevive(Target); Target = -1; } if ((sk != null && (sk.Range > 0 || sk.TargetRange > 0))) { foreach (Character chara in ServerManager.GetMap(MapId).GetListPeopleInRange(sk.TargetRange == 0 ? this.MapX : (short)MapX, sk.TargetRange == 0 ? this.MapY : (short)MapY, (byte)(sk.TargetRange + sk.Range)).Where(s => s.CharacterId != Target)) { damage = chara.HasGodMode ? 0 : 100; bool AlreadyDead2 = chara.Hp <= 0; chara.GetDamage(damage); chara.LastDefence = DateTime.Now; Map.Broadcast(null, chara.GenerateStat(), ReceiverType.OnlySomeone, "", chara.CharacterId); Map.Broadcast($"su 3 {MapMonsterId} 1 {chara.CharacterId} 0 {monster.BasicCooldown} 11 {monster.BasicSkill} 0 0 {(chara.Hp > 0 ? 1 : 0)} {(int)((double)chara.Hp / chara.HPLoad())} {damage} 0 0"); if (chara.Hp <= 0 && !AlreadyDead2) { Thread.Sleep(1000); ServerManager.Instance.AskRevive(chara.CharacterId); } } } } } else { if (IsMoving == true) { short maxdistance = 22; if (path.Count() == 0) { path = ServerManager.GetMap(MapId).AStar(new MapCell() { X = this.MapX, Y = this.MapY, MapId = this.MapId }, new MapCell() { X = (short)MapX, Y = (short)MapY, MapId = this.MapId }); } if (path.Count > 0 && Map.GetDistance(new MapCell() { X = this.MapX, Y = this.MapY, MapId = this.MapId }, new MapCell() { X = (short)MapX, Y = (short)MapY, MapId = this.MapId }) > 1) { this.MapX = path.ElementAt(0).X; this.MapY = path.ElementAt(0).Y; path.RemoveAt(0); } if (MapId != mapId || (Map.GetDistance(new MapCell() { X = this.MapX, Y = this.MapY }, new MapCell() { X = (short)MapX, Y = (short)MapY }) > maxdistance)) { path = ServerManager.GetMap(MapId).AStar(new MapCell() { X = this.MapX, Y = this.MapY, MapId = this.MapId }, new MapCell() { X = firstX, Y = firstY, MapId = this.MapId }); Target = -1; } else { if ((DateTime.Now - LastMove).TotalSeconds > 1.0 / monster.Speed) { LastMove = DateTime.Now; Map.Broadcast($"mv 3 {this.MapMonsterId} {this.MapX} {this.MapY} {monster.Speed}"); } } } } } LifeTaskIsRunning = false; }
public void ApplyBCards(object session, object sender = null) { //Console.WriteLine($"BCardId: {BCardId} Type: {(BCardType.CardType)Type} SubType: {SubType} CardId: {CardId?.ToString() ?? "null"} ItemVNum: {ItemVNum?.ToString() ?? "null"} SkillVNum: {SkillVNum?.ToString() ?? "null"} SessionType: {session?.GetType().ToString() ?? "null"} SenderType: {sender?.GetType().ToString() ?? "null"}"); switch ((BCardType.CardType)Type) { case BCardType.CardType.Buff: { if (ServerManager.RandomNumber() < FirstData) { Character senderCharacter = sender is ClientSession senderSession ? senderSession.Character : sender as Character; if (session is Character character) { short cardId = (short)SecondData; // If either Berserk Spirit or Strong Berserk Spirit is active // then don't add Weak Berserk Spirit if (cardId == 601 && character.Buff?.Any(s => s?.Card?.CardId == 602 || s?.Card?.CardId == 603) == true) { break; } if (senderCharacter != null) { // TODO: Get anti stats from BCard character.AddBuff(new Buff((short)SecondData, senderCharacter.Level, senderCharacter)); } else { character.AddBuff(new Buff((short)SecondData, character.Level)); } } else if (session is MapMonster mapMonster) { if (senderCharacter != null) { mapMonster.AddBuff(new Buff((short)SecondData, senderCharacter.Level, senderCharacter)); } else { mapMonster.AddBuff(new Buff((short)SecondData, mapMonster.Monster.Level)); } } } } break; case BCardType.CardType.Move: { if (session is Character character) { character.LastSpeedChange = DateTime.Now; character.Session.SendPacket(character.GenerateCond()); } } break; case BCardType.CardType.Summons: { if (session is Character character) { if (character.MapInstance != null) { List <MonsterToSummon> monsterList = new List <MonsterToSummon>(); if (SubType == (byte)AdditionalTypes.Summons.Summons / 10) { int aliveTime = ServerManager.GetNpc((short)SecondData).RespawnTime; for (int i = 0; i < FirstData; i++) { MapCell mapCell = new MapCell { X = (short)(ServerManager.RandomNumber(-1, 2) + character.PositionX), Y = (short)(ServerManager.RandomNumber(-1, 2) + character.PositionY), }; monsterList.Add(new MonsterToSummon((short)SecondData, mapCell, -1, true, false, false, true, false, -1, character, aliveTime, false)); } } if (monsterList.Any()) { EventHelper.Instance.RunEvent(new EventContainer(character.MapInstance, EventActionType.SPAWNMONSTERS, monsterList)); } } } } break; case BCardType.CardType.SpecialAttack: break; case BCardType.CardType.SpecialDefence: break; case BCardType.CardType.AttackPower: break; case BCardType.CardType.Target: break; case BCardType.CardType.Critical: break; case BCardType.CardType.SpecialCritical: break; case BCardType.CardType.Element: break; case BCardType.CardType.IncreaseDamage: break; case BCardType.CardType.Defence: break; case BCardType.CardType.DodgeAndDefencePercent: break; case BCardType.CardType.Block: break; case BCardType.CardType.Absorption: break; case BCardType.CardType.ElementResistance: break; case BCardType.CardType.EnemyElementResistance: break; case BCardType.CardType.Damage: break; case BCardType.CardType.GuarantedDodgeRangedAttack: break; case BCardType.CardType.Morale: break; case BCardType.CardType.Casting: break; case BCardType.CardType.Reflection: break; case BCardType.CardType.DrainAndSteal: break; case BCardType.CardType.HealingBurningAndCasting: { Character senderCharacter = sender is ClientSession senderSession ? senderSession.Character : sender as Character; if (senderCharacter != null) { #region Character if (session is Character character) { void HealingBurningAndCastingAction() { if (!character.IsAlive || character.MapInstance == null || character.Session == null) { return; } int amount = 0; if (SubType == (byte)AdditionalTypes.HealingBurningAndCasting.RestoreHP / 10 || SubType == (byte)AdditionalTypes.HealingBurningAndCasting.DecreaseHP / 10) { if (FirstData > 0) { if (IsLevelScaled) { amount = senderCharacter.Level * FirstData; } else { amount = FirstData; } if (character.Hp + amount > character.HPMax) { amount = character.HPMax - character.Hp; } character.Hp += amount; character.MapInstance.Broadcast(character.GenerateRc(amount)); } else { if (IsLevelScaled) { amount = senderCharacter.Level * (FirstData - 1); } else { amount = FirstData; } amount *= -1; if (character.Hp - amount < 1) { amount = character.Hp - 1; } character.GetDamage(amount); character.MapInstance.Broadcast(character.GenerateDm(amount)); } character.Session.SendPacket(character.GenerateStat()); } else if (SubType == (byte)AdditionalTypes.HealingBurningAndCasting.RestoreMP / 10 || SubType == (byte)AdditionalTypes.HealingBurningAndCasting.DecreaseMP / 10) { if (FirstData > 0) { if (IsLevelScaled) { amount = senderCharacter.Level * FirstData; } else { amount = FirstData; } if (character.Mp + amount > character.MPMax) { amount = character.MPMax - character.Mp; } character.Mp += amount; } else { if (IsLevelScaled) { amount = senderCharacter.Level * (FirstData - 1); } else { amount = FirstData; } amount *= -1; if (character.Mp - amount < 1) { amount = character.Mp - 1; } character.DecreaseMp(amount); } character.Session.SendPacket(character.GenerateStat()); } } HealingBurningAndCastingAction(); if (ThirdData > 0 && CardId != null) { IDisposable disposable = Observable.Interval(TimeSpan.FromSeconds(ThirdData * 2)) .Subscribe(s => HealingBurningAndCastingAction()); character.DisposeBCard(BCardId); character.BCardDisposables[BCardId] = disposable; } } #endregion #region MapMonster else if (session is MapMonster mapMonster) { void HealingBurningAndCastingAction() { if (!mapMonster.IsAlive || mapMonster.MapInstance == null) { return; } int amount = 0; if (SubType == (byte)AdditionalTypes.HealingBurningAndCasting.RestoreHP / 10 || SubType == (byte)AdditionalTypes.HealingBurningAndCasting.DecreaseHP / 10) { if (FirstData > 0) { if (IsLevelScaled) { amount = senderCharacter.Level * FirstData; } else { amount = FirstData; } if (mapMonster.CurrentHp + amount > mapMonster.MaxHp) { amount = mapMonster.MaxHp - mapMonster.CurrentHp; } mapMonster.CurrentHp += amount; mapMonster.MapInstance.Broadcast(mapMonster.GenerateRc(amount)); } else { if (IsLevelScaled) { amount = senderCharacter.Level * (FirstData - 1); } else { amount = FirstData; } amount *= -1; if (mapMonster.CurrentHp - amount < 1) { amount = mapMonster.CurrentHp - 1; } mapMonster.CurrentHp -= amount; mapMonster.MapInstance.Broadcast(mapMonster.GenerateDm(amount)); } } if (SubType == (byte)AdditionalTypes.HealingBurningAndCasting.RestoreMP / 10 || SubType == (byte)AdditionalTypes.HealingBurningAndCasting.DecreaseMP / 10) { if (FirstData > 0) { if (IsLevelScaled) { amount = senderCharacter.Level * FirstData; } else { amount = FirstData; } if (mapMonster.CurrentMp + amount > mapMonster.MaxMp) { amount = mapMonster.MaxMp - mapMonster.CurrentMp; } mapMonster.CurrentMp += amount; } else { if (IsLevelScaled) { amount = senderCharacter.Level * (FirstData - 1); } else { amount = FirstData; } amount *= -1; if (mapMonster.CurrentMp - amount < 1) { amount = mapMonster.CurrentMp - 1; } mapMonster.CurrentMp -= amount; } } } HealingBurningAndCastingAction(); if (ThirdData > 0 && CardId != null) { IDisposable disposable = Observable.Interval(TimeSpan.FromSeconds(ThirdData * 2)) .Subscribe(s => HealingBurningAndCastingAction()); mapMonster.DisposeBCard(BCardId); mapMonster.BCardDisposables[BCardId] = disposable; } } #endregion } } break; case BCardType.CardType.HPMP: { if (SubType == (byte)AdditionalTypes.HPMP.DecreaseRemainingMP / 10) { if (FirstData < 0) { double multiplier = (FirstData * -1) / 100D; if (session is Character character) { character.DecreaseMp((int)(character.Mp * multiplier)); character.Session?.SendPacket(character.GenerateStat()); } else if (session is MapMonster mapMonster) { mapMonster.DecreaseMp((int)(mapMonster.CurrentMp * multiplier)); } } } } break; case BCardType.CardType.SpecializationBuffResistance: { if (SubType == (byte)AdditionalTypes.SpecializationBuffResistance.RemoveGoodEffects / 10) { if (session is Character character) { if (FirstData < 0) { if (ServerManager.RandomNumber() < (FirstData * -1)) { character.Buff?.GetAllItems()?.Where(s => s?.Card?.BuffType == BuffType.Bad && s.Card.Level < SecondData)? .ToList()?.ForEach(s => character.RemoveBuff(s.Card.CardId)); } } else { if (ServerManager.RandomNumber() < FirstData) { character.Buff?.GetAllItems()?.Where(s => s?.Card?.BuffType == BuffType.Good && s.Card.Level < SecondData)? .ToList()?.ForEach(s => character.RemoveBuff(s.Card.CardId)); } } } } } break; case BCardType.CardType.SpecialEffects: { if (SubType == (byte)AdditionalTypes.SpecialEffects.ShadowAppears / 10) { if (session is Character character) { character.NumberOfShadows = FirstData; character.ShadowsDistance = SecondData; character.MapInstance?.Broadcast(character.GenerateSpeed()); } } } break; case BCardType.CardType.Capture: { if (session is MapMonster mapMonster && sender is ClientSession senderSession) { NpcMonster mateNpc = ServerManager.GetNpc(mapMonster.MonsterVNum); if (mateNpc != null) { if (mapMonster.Monster.Catch) { if (mapMonster.IsAlive && mapMonster.CurrentHp <= (int)((double)mapMonster.MaxHp / 2)) { if (mapMonster.Monster.Level < senderSession.Character.Level) { // TODO: Find a new algorithm int[] chance = { 100, 80, 60, 40, 20, 0 }; if (ServerManager.RandomNumber() < chance[ServerManager.RandomNumber(0, 5)]) { Mate mate = new Mate(senderSession.Character, mateNpc, (byte)(mapMonster.Monster.Level - 15 > 0 ? mapMonster.Monster.Level - 15 : 1), MateType.Pet); if (senderSession.Character.CanAddMate(mate)) { senderSession.Character.AddPetWithSkill(mate); senderSession.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("CATCH_SUCCESS"), 0)); senderSession.CurrentMapInstance?.Broadcast(StaticPacketHelper.GenerateEff(UserType.Player, senderSession.Character.CharacterId, 197)); senderSession.CurrentMapInstance?.Broadcast(StaticPacketHelper.SkillUsed(UserType.Player, senderSession.Character.CharacterId, 3, mapMonster.MapMonsterId, -1, 0, 15, -1, -1, -1, true, (int)((float)mapMonster.CurrentHp / (float)mapMonster.MaxHp * 100), 0, -1, 0)); mapMonster.SetDeathStatement(); senderSession.CurrentMapInstance?.Broadcast(StaticPacketHelper.Out(UserType.Monster, mapMonster.MapMonsterId)); } else { senderSession.SendPacket(senderSession.Character.GenerateSay(Language.Instance.GetMessageFromKey("PET_SLOT_FULL"), 10)); senderSession.SendPacket(StaticPacketHelper.Cancel(2, mapMonster.MapMonsterId)); } } else { senderSession.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("CATCH_FAIL"), 0)); senderSession.CurrentMapInstance?.Broadcast(StaticPacketHelper.SkillUsed(UserType.Player, senderSession.Character.CharacterId, 3, mapMonster.MapMonsterId, -1, 0, 15, -1, -1, -1, true, (int)((float)mapMonster.CurrentHp / (float)mapMonster.MaxHp * 100), 0, -1, 0)); } } else { senderSession.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("LEVEL_LOWER_THAN_MONSTER"), 0)); senderSession.SendPacket(StaticPacketHelper.Cancel(2, mapMonster.MapMonsterId)); } } else { senderSession.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("CURRENT_HP_TOO_HIGH"), 0)); senderSession.SendPacket(StaticPacketHelper.Cancel(2, mapMonster.MapMonsterId)); } } else { senderSession.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("MONSTER_CANT_BE_CAPTURED"), 0)); senderSession.SendPacket(StaticPacketHelper.Cancel(2, mapMonster.MapMonsterId)); } } } } break; case BCardType.CardType.SpecialDamageAndExplosions: break; case BCardType.CardType.SpecialEffects2: { if (SubType == (byte)AdditionalTypes.SpecialEffects2.TeleportInRadius / 10) { if (session is Character character) { character.Teleport((short)FirstData); } } } break; case BCardType.CardType.CalculatingLevel: break; case BCardType.CardType.Recovery: break; case BCardType.CardType.MaxHPMP: { if (session is Character character) { if (SubType == (byte)AdditionalTypes.MaxHPMP.IncreasesMaximumHP / 10) { character.HPLoad(); character.Session?.SendPacket(character.GenerateStat()); } else if (SubType == (byte)AdditionalTypes.MaxHPMP.IncreasesMaximumMP / 10) { character.MPLoad(); character.Session?.SendPacket(character.GenerateStat()); } } } break; case BCardType.CardType.MultAttack: break; case BCardType.CardType.MultDefence: break; case BCardType.CardType.TimeCircleSkills: break; case BCardType.CardType.RecoveryAndDamagePercent: break; case BCardType.CardType.Count: break; case BCardType.CardType.NoDefeatAndNoDamage: break; case BCardType.CardType.SpecialActions: { Character senderCharacter = sender is ClientSession senderSession ? senderSession.Character : sender as Character; if (SubType == (byte)AdditionalTypes.SpecialActions.PushBack / 10) { if (senderCharacter != null) { if (session is Character character) { if (character.ResistForcedMovementChance <= 0 || ServerManager.RandomNumber() < character.ResistForcedMovementChance) { character.PushBack((short)FirstData, senderCharacter); } } else if (session is MapMonster mapMonster) { mapMonster.PushBack((short)FirstData, senderCharacter); } } } else if (SubType == (byte)AdditionalTypes.SpecialActions.FocusEnemies / 10) { if (senderCharacter != null) { if (session is Character character) { if (character.ResistForcedMovementChance <= 0 || ServerManager.RandomNumber() < character.ResistForcedMovementChance) { character.Focus((short)FirstData, senderCharacter); } } else if (session is MapMonster mapMonster) { mapMonster.Focus((short)FirstData, senderCharacter); } } } else if (SubType == (byte)AdditionalTypes.SpecialActions.Hide / 10) { if (session is Character character) { character.SetInvisible(true); } } } break; case BCardType.CardType.Transform: break; case BCardType.CardType.Mode: break; case BCardType.CardType.NoCharacteristicValue: break; case BCardType.CardType.LightAndShadow: { if (SubType == (byte)AdditionalTypes.LightAndShadow.RemoveBadEffects / 10) { if (session is Character character) { character.Buff?.GetAllItems()?.Where(s => s?.Card?.BuffType == BuffType.Bad && s.Card.Level < FirstData)? .ToList()?.ForEach(s => character.RemoveBuff(s.Card.CardId)); } } } break; case BCardType.CardType.Item: break; case BCardType.CardType.DebuffResistance: break; case BCardType.CardType.SpecialBehaviour: break; case BCardType.CardType.Quest: break; case BCardType.CardType.SecondSPCard: { if (session is Character character) { if (character.MapInstance != null) { List <MonsterToSummon> monsterList = new List <MonsterToSummon>(); if (SubType == (byte)AdditionalTypes.SecondSPCard.PlantBomb / 10) { MapMonster bomb = character.MapInstance.Monsters.FirstOrDefault(m => m?.Owner?.CharacterId == character.CharacterId && m.MonsterVNum == (short)SecondData); if (bomb == null) { for (int i = 0; i < FirstData; i++) { monsterList.Add(new MonsterToSummon((short)SecondData, new MapCell { X = character.PositionX, Y = character.PositionY }, -1, false, false, false, false, false, -1, character, 0, false)); } } else { bomb.Explode(); break; } } else if (SubType == (byte)AdditionalTypes.SecondSPCard.PlantSelfDestructionBomb / 10) { int aliveTime = ServerManager.GetNpc((short)SecondData).RespawnTime; for (int i = 0; i < FirstData; i++) { MapCell mapCell = new MapCell { X = (short)(ServerManager.RandomNumber(-1, 2) + character.PositionX), Y = (short)(ServerManager.RandomNumber(-1, 2) + character.PositionY), }; monsterList.Add(new MonsterToSummon((short)SecondData, mapCell, -1, true, false, false, true, false, -1, character, aliveTime, true)); } } if (monsterList.Any()) { EventHelper.Instance.RunEvent(new EventContainer(character.MapInstance, EventActionType.SPAWNMONSTERS, monsterList)); } } } } break; case BCardType.CardType.SPCardUpgrade: break; case BCardType.CardType.HugeSnowman: break; case BCardType.CardType.Drain: break; case BCardType.CardType.BossMonstersSkill: break; case BCardType.CardType.LordHatus: break; case BCardType.CardType.LordCalvinas: break; case BCardType.CardType.SESpecialist: { if (SubType == (byte)AdditionalTypes.SESpecialist.LowerHPStrongerEffect / 10) { Character senderCharacter = sender is ClientSession senderSession ? senderSession.Character : sender as Character; if (senderCharacter != null) { if (session is Character character) { double percentage = (character.Hp * 100) / character.HPMax; if (percentage < 35) { character.AddBuff(new Buff(274, senderCharacter.Level, senderCharacter)); } else if (percentage < 67) { character.AddBuff(new Buff(273, senderCharacter.Level, senderCharacter)); } else { character.AddBuff(new Buff(272, senderCharacter.Level, senderCharacter)); } } } } } break; case BCardType.CardType.FourthGlacernonFamilyRaid: break; case BCardType.CardType.SummonedMonsterAttack: break; case BCardType.CardType.BearSpirit: { if (session is Character character) { if (SubType == (byte)AdditionalTypes.BearSpirit.IncreaseMaximumHP / 10) { character.HPLoad(); character.Session?.SendPacket(character.GenerateStat()); } else if (SubType == (byte)AdditionalTypes.BearSpirit.IncreaseMaximumMP / 10) { character.MPLoad(); character.Session?.SendPacket(character.GenerateStat()); } } } break; case BCardType.CardType.SummonSkill: break; case BCardType.CardType.InflictSkill: break; case BCardType.CardType.HideBarrelSkill: break; case BCardType.CardType.FocusEnemyAttentionSkill: break; case BCardType.CardType.TauntSkill: break; case BCardType.CardType.FireCannoneerRangeBuff: break; case BCardType.CardType.VulcanoElementBuff: break; case BCardType.CardType.DamageConvertingSkill: break; case BCardType.CardType.MeditationSkill: { if (session is Character character) { if (SkillVNum.HasValue && SubType.Equals((byte)AdditionalTypes.MeditationSkill.CausingChance / 10) && ServerManager.RandomNumber() < FirstData) { Skill skill = ServerManager.GetSkill(SkillVNum.Value); Skill newSkill = ServerManager.GetSkill((short)SecondData); Observable.Timer(TimeSpan.FromMilliseconds(100)).Subscribe(observer => { foreach (QuicklistEntryDTO quicklistEntry in character.QuicklistEntries.Where(s => s.Pos.Equals(skill.CastId))) { character.Session.SendPacket($"qset {quicklistEntry.Q1} {quicklistEntry.Q2} {quicklistEntry.Type}.{quicklistEntry.Slot}.{newSkill.CastId}.0"); } character.Session.SendPacket($"mslot {newSkill.CastId} -1"); }); character.SkillComboCount++; character.LastSkillComboUse = DateTime.Now; if (skill.CastId > 10) { Observable.Timer(TimeSpan.FromMilliseconds((skill.GetCooldown(character) * 100) + 500)).Subscribe(observer => character.Session.SendPacket(StaticPacketHelper.SkillReset(skill.CastId))); } } switch (SubType) { case 2: character.MeditationDictionary[(short)SecondData] = DateTime.Now.AddSeconds(4); break; case 3: character.MeditationDictionary[(short)SecondData] = DateTime.Now.AddSeconds(8); break; case 4: character.MeditationDictionary[(short)SecondData] = DateTime.Now.AddSeconds(12); break; } } } break; case BCardType.CardType.FalconSkill: break; case BCardType.CardType.AbsorptionAndPowerSkill: break; case BCardType.CardType.LeonaPassiveSkill: break; case BCardType.CardType.FearSkill: break; case BCardType.CardType.SniperAttack: break; case BCardType.CardType.FrozenDebuff: break; case BCardType.CardType.JumpBackPush: break; case BCardType.CardType.FairyXPIncrease: break; case BCardType.CardType.SummonAndRecoverHP: break; case BCardType.CardType.TeamArenaBuff: break; case BCardType.CardType.ArenaCamera: break; case BCardType.CardType.DarkCloneSummon: break; case BCardType.CardType.AbsorbedSpirit: break; case BCardType.CardType.AngerSkill: break; case BCardType.CardType.MeteoriteTeleport: break; case BCardType.CardType.StealBuff: break; case BCardType.CardType.Unknown: break; case BCardType.CardType.EffectSummon: break; default: Logger.Warn($"Card Type {Type} Not Found!"); break; } }
public void ApplyBCards(object session, object sender = null) { Type type = session.GetType(); // int counterBuff = 0; if (type == null) { return; } switch ((BCardType.CardType)Type) { case BCardType.CardType.Buff: { if (type == typeof(Character) && session is Character character) { Buff buff = null; if (sender != null) { Type sType = sender.GetType(); if (sType != null) { if (sType == typeof(Character) && sender is Character sendingCharacter) { buff = new Buff((short)SecondData, sendingCharacter.Level); //Todo: Get anti stats from BCard } } } else { buff = new Buff((short)SecondData, character.Level); } if (ServerManager.RandomNumber() < FirstData) { character.AddBuff(buff); } } else if (type == typeof(MapMonster)) { if (ServerManager.RandomNumber() < FirstData && session is MapMonster mapMonster) { mapMonster.AddBuff(new Buff((short)SecondData, mapMonster.Monster.Level)); } } else if (type == typeof(MapNpc)) { } else if (type == typeof(Mate)) { } break; } case BCardType.CardType.Move: { if (type == typeof(Character) && session is Character character) { character.LastSpeedChange = DateTime.Now; character.Session.SendPacket(character.GenerateCond()); } } break; case BCardType.CardType.Summons: if (type == typeof(Character)) { } else if (type == typeof(MapMonster)) { if (session is MapMonster mapMonster) { List <MonsterToSummon> summonParameters = new List <MonsterToSummon>(); for (int i = 0; i < FirstData; i++) { short x = (short)(ServerManager.RandomNumber(-3, 3) + mapMonster.MapX); short y = (short)(ServerManager.RandomNumber(-3, 3) + mapMonster.MapY); summonParameters.Add(new MonsterToSummon((short)SecondData, new MapCell { X = x, Y = y }, -1, true)); } if (ServerManager.RandomNumber() <= Math.Abs(ThirdData) || ThirdData == 0) { switch (SubType) { case 2: EventHelper.Instance.RunEvent(new EventContainer(mapMonster.MapInstance, EventActionType.SPAWNMONSTERS, summonParameters)); break; default: if (!mapMonster.OnDeathEvents.Any(s => s.EventActionType == EventActionType.SPAWNMONSTERS)) { mapMonster.OnDeathEvents.Add(new EventContainer(mapMonster.MapInstance, EventActionType.SPAWNMONSTERS, summonParameters)); } break; } } } } else if (type == typeof(MapNpc)) { } else if (type == typeof(Mate)) { } break; case BCardType.CardType.SpecialAttack: break; case BCardType.CardType.SpecialDefence: break; case BCardType.CardType.AttackPower: break; case BCardType.CardType.Target: break; case BCardType.CardType.Critical: break; case BCardType.CardType.SpecialCritical: break; case BCardType.CardType.Element: break; case BCardType.CardType.IncreaseDamage: break; case BCardType.CardType.Defence: break; case BCardType.CardType.DodgeAndDefencePercent: break; case BCardType.CardType.Block: break; case BCardType.CardType.Absorption: break; case BCardType.CardType.ElementResistance: break; case BCardType.CardType.EnemyElementResistance: break; case BCardType.CardType.Damage: break; case BCardType.CardType.GuarantedDodgeRangedAttack: break; case BCardType.CardType.Morale: break; case BCardType.CardType.Casting: break; case BCardType.CardType.Reflection: break; case BCardType.CardType.DrainAndSteal: break; case BCardType.CardType.HealingBurningAndCasting: if (type == typeof(Character)) { if (session is Character character && character.Hp > 0) { int bonus = 0; if (SubType == (byte)AdditionalTypes.HealingBurningAndCasting.RestoreHP / 10) { if (IsLevelScaled) { bonus = character.Level * FirstData; } else { bonus = FirstData; } if (character.Hp + bonus <= character.HPLoad()) { character.Hp += bonus; } else { bonus = (int)character.HPLoad() - character.Hp; character.Hp = (int)character.HPLoad(); } character.Session.CurrentMapInstance?.Broadcast(character.Session, character.GenerateRc(bonus)); } if (SubType == (byte)AdditionalTypes.HealingBurningAndCasting.RestoreMP / 10) { if (IsLevelScaled) { bonus = character.Level * FirstData; } else { bonus = FirstData; } if (character.Mp + bonus <= character.MPLoad()) { character.Mp += bonus; } else { bonus = (int)character.MPLoad() - character.Mp; character.Mp = (int)character.MPLoad(); } } character.Session.SendPacket(character.GenerateStat()); } } else if (type == typeof(MapMonster)) { if (ServerManager.RandomNumber() < FirstData && session is MapMonster mapMonster) { mapMonster.AddBuff(new Buff((short)SecondData, mapMonster.Monster.Level)); } } else if (type == typeof(MapNpc)) { } else if (type == typeof(Mate)) { } break; case BCardType.CardType.HPMP: break; case BCardType.CardType.SpecialisationBuffResistance: break; case BCardType.CardType.SpecialEffects: break; case BCardType.CardType.Capture: if (type == typeof(MapMonster)) { if (session is MapMonster mapMonster && sender is ClientSession senderSession) { NpcMonster mateNpc = ServerManager.GetNpc(mapMonster.MonsterVNum); if (mateNpc != null) { if (mapMonster.Monster.Catch) { if (mapMonster.IsAlive && mapMonster.CurrentHp <= (int)((double)mapMonster.MaxHp / 2)) { if (mapMonster.Monster.Level < senderSession.Character.Level) { #warning find a new algorithm int[] chance = { 100, 80, 60, 40, 20, 0 }; if (ServerManager.RandomNumber() < chance[ServerManager.RandomNumber(0, 5)]) { Mate mate = new Mate(senderSession.Character, mateNpc, (byte)(mapMonster.Monster.Level - 15 > 0 ? mapMonster.Monster.Level - 15 : 1), MateType.Pet); if (senderSession.Character.CanAddMate(mate)) { senderSession.Character.AddPetWithSkill(mate); senderSession.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("CATCH_SUCCESS"), 0)); senderSession.CurrentMapInstance?.Broadcast(StaticPacketHelper.GenerateEff(UserType.Player, senderSession.Character.CharacterId, 197)); senderSession.CurrentMapInstance?.Broadcast(StaticPacketHelper.SkillUsed(UserType.Player, senderSession.Character.CharacterId, 3, mapMonster.MapMonsterId, -1, 0, 15, -1, -1, -1, true, (int)((float)mapMonster.CurrentHp / (float)mapMonster.MaxHp * 100), 0, -1, 0)); mapMonster.SetDeathStatement(); senderSession.CurrentMapInstance?.Broadcast(StaticPacketHelper.Out(UserType.Monster, mapMonster.MapMonsterId)); } else { senderSession.SendPacket(senderSession.Character.GenerateSay(Language.Instance.GetMessageFromKey("PET_SLOT_FULL"), 10)); senderSession.SendPacket(StaticPacketHelper.Cancel(2, mapMonster.MapMonsterId)); } } else { senderSession.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("CATCH_FAIL"), 0)); senderSession.CurrentMapInstance?.Broadcast(StaticPacketHelper.SkillUsed(UserType.Player, senderSession.Character.CharacterId, 3, mapMonster.MapMonsterId, -1, 0, 15, -1, -1, -1, true, (int)((float)mapMonster.CurrentHp / (float)mapMonster.MaxHp * 100), 0, -1, 0)); } } else { senderSession.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("LEVEL_LOWER_THAN_MONSTER"), 0)); senderSession.SendPacket(StaticPacketHelper.Cancel(2, mapMonster.MapMonsterId)); } } else { senderSession.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("CURRENT_HP_TOO_HIGH"), 0)); senderSession.SendPacket(StaticPacketHelper.Cancel(2, mapMonster.MapMonsterId)); } } else { senderSession.SendPacket(UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("MONSTER_CANT_BE_CAPTURED"), 0)); senderSession.SendPacket(StaticPacketHelper.Cancel(2, mapMonster.MapMonsterId)); } } } } break; case BCardType.CardType.SpecialDamageAndExplosions: break; case BCardType.CardType.SpecialEffects2: break; case BCardType.CardType.CalculatingLevel: break; case BCardType.CardType.Recovery: break; case BCardType.CardType.MaxHPMP: break; case BCardType.CardType.MultAttack: break; case BCardType.CardType.MultDefence: break; case BCardType.CardType.TimeCircleSkills: break; case BCardType.CardType.RecoveryAndDamagePercent: break; case BCardType.CardType.Count: break; case BCardType.CardType.NoDefeatAndNoDamage: break; case BCardType.CardType.SpecialActions: break; case BCardType.CardType.Mode: break; case BCardType.CardType.NoCharacteristicValue: break; case BCardType.CardType.LightAndShadow: break; case BCardType.CardType.Item: break; case BCardType.CardType.DebuffResistance: break; case BCardType.CardType.SpecialBehaviour: break; case BCardType.CardType.Quest: break; case BCardType.CardType.SecondSPCard: break; case BCardType.CardType.SPCardUpgrade: break; case BCardType.CardType.HugeSnowman: break; case BCardType.CardType.Drain: break; case BCardType.CardType.BossMonstersSkill: break; case BCardType.CardType.LordHatus: break; case BCardType.CardType.LordCalvinas: break; case BCardType.CardType.SESpecialist: break; case BCardType.CardType.FourthGlacernonFamilyRaid: break; case BCardType.CardType.SummonedMonsterAttack: break; case BCardType.CardType.BearSpirit: break; case BCardType.CardType.SummonSkill: break; case BCardType.CardType.InflictSkill: break; case BCardType.CardType.HideBarrelSkill: break; case BCardType.CardType.FocusEnemyAttentionSkill: break; case BCardType.CardType.TauntSkill: break; case BCardType.CardType.FireCannoneerRangeBuff: break; case BCardType.CardType.VulcanoElementBuff: break; case BCardType.CardType.DamageConvertingSkill: break; case BCardType.CardType.MeditationSkill: { if (type == typeof(Character) && session is Character character) { if (SkillVNum.HasValue && SubType.Equals((byte)AdditionalTypes.MeditationSkill.CausingChance / 10) && ServerManager.RandomNumber() < FirstData) { Skill skill = ServerManager.GetSkill(SkillVNum.Value); Skill newSkill = ServerManager.GetSkill((short)SecondData); Observable.Timer(TimeSpan.FromMilliseconds(100)).Subscribe(observer => { foreach (QuicklistEntryDTO quicklistEntry in character.QuicklistEntries.Where(s => s.Pos.Equals(skill.CastId))) { character.Session.SendPacket($"qset {quicklistEntry.Q1} {quicklistEntry.Q2} {quicklistEntry.Type}.{quicklistEntry.Slot}.{newSkill.CastId}.0"); } character.Session.SendPacket($"mslot {newSkill.CastId} -1"); }); character.SkillComboCount++; character.LastSkillComboUse = DateTime.Now; if (skill.CastId > 10) { // HACK this way Observable.Timer(TimeSpan.FromMilliseconds((skill.Cooldown * 100) + 500)).Subscribe(observer => character.Session.SendPacket(StaticPacketHelper.SkillReset(skill.CastId))); } } switch (SubType) { case 2: character.MeditationDictionary[(short)SecondData] = DateTime.Now.AddSeconds(4); break; case 3: character.MeditationDictionary[(short)SecondData] = DateTime.Now.AddSeconds(8); break; case 4: character.MeditationDictionary[(short)SecondData] = DateTime.Now.AddSeconds(12); break; } } } break; case BCardType.CardType.FalconSkill: break; case BCardType.CardType.AbsorptionAndPowerSkill: break; case BCardType.CardType.LeonaPassiveSkill: break; case BCardType.CardType.FearSkill: break; case BCardType.CardType.SniperAttack: break; case BCardType.CardType.FrozenDebuff: break; case BCardType.CardType.JumpBackPush: break; case BCardType.CardType.FairyXPIncrease: break; case BCardType.CardType.SummonAndRecoverHP: break; case BCardType.CardType.TeamArenaBuff: break; case BCardType.CardType.ArenaCamera: break; case BCardType.CardType.DarkCloneSummon: break; case BCardType.CardType.AbsorbedSpirit: break; case BCardType.CardType.AngerSkill: break; case BCardType.CardType.MeteoriteTeleport: break; case BCardType.CardType.StealBuff: break; case BCardType.CardType.Unknown: break; case BCardType.CardType.EffectSummon: break; default: Logger.Warn($"Card Type {Type} not defined!"); break; } }
public void ApplyBCards(object session, object sender = null, short buffLevel = 0) { Type type = session.GetType(); // int counterBuff = 0; switch ((BCardType.CardType)Type) { case BCardType.CardType.Buff: { if (type == typeof(Character) && session is Character character) { Buff buff = null; if (sender != null) { Type sType = sender.GetType(); if (sType == typeof(Character) && sender is Character sendingCharacter) { buff = new Buff((short)((short)SecondData + buffLevel), sendingCharacter.Level); //Todo: Get anti stats from BCard } } else { buff = new Buff((short)((short)SecondData + buffLevel), character.Level); } int anti = 0; if (buff?.Card.BuffType == BuffType.Bad) { anti += character.ShellEffectArmor?.FirstOrDefault(s => s.Effect == (byte)ShellArmorEffectType.ReducedAllNegativeEffect)?.Value ?? 0; switch (SecondData) { case 1: anti += character.ShellEffectArmor?.FirstOrDefault(s => s.Effect == (byte)ShellArmorEffectType .ReducedBleedingAndMinorBleeding) ?.Value ?? 0; anti += character.ShellEffectArmor?.FirstOrDefault(s => s.Effect == (byte)ShellArmorEffectType.ReducedAllBleedingType) ?.Value ?? 0; break; case 7: anti += character.ShellEffectArmor ?.FirstOrDefault(s => s.Effect == (byte)ShellArmorEffectType.ReducedStun)?.Value ?? 0; anti += character.ShellEffectArmor?.FirstOrDefault(s => s.Effect == (byte)ShellArmorEffectType.ReducedAllStun)?.Value ?? 0; break; case 21: anti += character.ShellEffectArmor?.FirstOrDefault(s => s.Effect == (byte)ShellArmorEffectType.ReducedMinorBleeding)?.Value ?? 0; anti += character.ShellEffectArmor?.FirstOrDefault(s => s.Effect == (byte)ShellArmorEffectType .ReducedBleedingAndMinorBleeding) ?.Value ?? 0; anti += character.ShellEffectArmor?.FirstOrDefault(s => s.Effect == (byte)ShellArmorEffectType.ReducedAllBleedingType) ?.Value ?? 0; break; case 27: anti += character.ShellEffectArmor?.FirstOrDefault(s => s.Effect == (byte)ShellArmorEffectType.ReducedFreeze)?.Value ?? 0; break; case 42: anti += character.ShellEffectArmor?.FirstOrDefault(s => s.Effect == (byte)ShellArmorEffectType.ReducedAllBleedingType) ?.Value ?? 0; break; case 66: anti += character.ShellEffectArmor?.FirstOrDefault(s => s.Effect == (byte)ShellArmorEffectType.ReducedAllStun)?.Value ?? 0; break; } } if (ServerManager.RandomNumber() < FirstData / 100D * (100 - anti)) { character.AddBuff(buff); } } else if (type == typeof(MapMonster)) { if (ServerManager.RandomNumber() < FirstData && session is MapMonster mapMonster) { mapMonster.AddBuff(new Buff((short)((short)SecondData + buffLevel), mapMonster.Monster.Level)); } } else if (type == typeof(MapNpc)) { } else if (type == typeof(Mate)) { } } break; case BCardType.CardType.Move: { if (type == typeof(Character) && session is Character character) { character.LastSpeedChange = DateTime.UtcNow; character.Session.SendPacket(character.GenerateCond()); } } break; case BCardType.CardType.Summons: { if (type == typeof(Character)) { // jajamaru spawn if (session is Character character && character.MapInstance != null) { List <MonsterToSummon> summonParameters = new List <MonsterToSummon>(); for (int i = 0; i < FirstData; i++) { short x, y; byte t = 0; do { x = (short)(ServerManager.RandomNumber(-3, 3) + character.PositionX); y = (short)(ServerManager.RandomNumber(-3, 3) + character.PositionY); t++; } while (!character.MapInstance.Map.IsBlockedZone(x, y) && t < byte.MaxValue); summonParameters.Add(new MonsterToSummon((short)SecondData, new MapCell { X = x, Y = y }, -1, true)); } if (ServerManager.RandomNumber() <= Math.Abs(ThirdData) || ThirdData == 0) { switch (SubType) { case 2: EventHelper.Instance.RunEvent(new EventContainer( character.Session.CurrentMapInstance, EventActionType.SpawnMonsters, summonParameters)); break; } } } } else if (type == typeof(MapMonster)) { if (session is MapMonster mapMonster && mapMonster.MapInstance != null) { List <MonsterToSummon> summonParameters = new List <MonsterToSummon>(); for (int i = 0; i < FirstData; i++) { short x, y; byte t = 0; do { x = (short)(ServerManager.RandomNumber(-3, 3) + mapMonster.MapX); y = (short)(ServerManager.RandomNumber(-3, 3) + mapMonster.MapY); t++; } while (!mapMonster.MapInstance.Map.IsBlockedZone(x, y) && t < byte.MaxValue); summonParameters.Add(new MonsterToSummon((short)SecondData, new MapCell { X = x, Y = y }, -1, true)); } if (ServerManager.RandomNumber() <= Math.Abs(ThirdData) || ThirdData == 0) { switch (SubType) { case 2: EventHelper.Instance.RunEvent(new EventContainer(mapMonster.MapInstance, EventActionType.SpawnMonsters, summonParameters)); break; default: if (mapMonster.OnDeathEvents.All(s => s.EventActionType != EventActionType.SpawnMonsters)) { mapMonster.OnDeathEvents.Add(new EventContainer(mapMonster.MapInstance, EventActionType.SpawnMonsters, summonParameters)); } break; } } } } else if (type == typeof(MapNpc)) { } else if (type == typeof(Mate)) { } } break; case BCardType.CardType.SpecialAttack: break; case BCardType.CardType.SpecialDefence: break; case BCardType.CardType.AttackPower: break; case BCardType.CardType.Target: break; case BCardType.CardType.Critical: break; case BCardType.CardType.SpecialCritical: break; case BCardType.CardType.Element: break; case BCardType.CardType.IncreaseDamage: break; case BCardType.CardType.Defence: break; case BCardType.CardType.DodgeAndDefencePercent: break; case BCardType.CardType.Block: break; case BCardType.CardType.Absorption: break; case BCardType.CardType.ElementResistance: break; case BCardType.CardType.EnemyElementResistance: break; case BCardType.CardType.Damage: break; case BCardType.CardType.GuarantedDodgeRangedAttack: break; case BCardType.CardType.Morale: break; case BCardType.CardType.Casting: break; case BCardType.CardType.Reflection: break; case BCardType.CardType.DrainAndSteal: break; case BCardType.CardType.HealingBurningAndCasting: { if (type == typeof(Character)) { if (session is Character character && character.Hp > 0) { int bonus; if (SubType == (byte)AdditionalTypes.HealingBurningAndCasting.RestoreHP / 10) { if (IsLevelScaled) { bonus = character.Level * FirstData; } else { bonus = FirstData; } if (character.Hp + bonus <= character.HPLoad()) { character.Hp += bonus; } else { bonus = (int)character.HPLoad() - character.Hp; character.Hp = (int)character.HPLoad(); } character.Session.CurrentMapInstance?.Broadcast(character.Session, character.GenerateRc(bonus)); } if (SubType == (byte)AdditionalTypes.HealingBurningAndCasting.RestoreMP / 10) { if (IsLevelScaled) { bonus = character.Level * FirstData; } else { bonus = FirstData; } if (character.Mp + bonus <= character.MPLoad()) { character.Mp += bonus; } else { character.Mp = (int)character.MPLoad(); } } character.Session.SendPacket(character.GenerateStat()); } } else if (type == typeof(MapMonster)) { if (ServerManager.RandomNumber() < FirstData && session is MapMonster mapMonster) { mapMonster.AddBuff(new Buff((short)SecondData, mapMonster.Monster.Level)); } } else if (type == typeof(MapNpc)) { } else if (type == typeof(Mate)) { } } break; case BCardType.CardType.Hpmp: if (type == typeof(Character)) { if (session is Character c) { switch (SubType) { case (byte)AdditionalTypes.Hpmp.RestoreDecreasedMP / 10: { int bonus = (int)(FirstData * c.MPLoad() / 100); c.Mp = c.Mp + bonus > 1 ? c.Mp + bonus : c.Mp = 1; } break; } } } break; case BCardType.CardType.SpecialisationBuffResistance: { switch (SubType) { case (byte)AdditionalTypes.SpecialisationBuffResistance.RemoveBadEffects / 10: { if (session is Character c && /*&& sender is ClientSession senderSession*/ ServerManager.RandomNumber() < Math.Abs(FirstData)) { c.DisableBuffs(FirstData > 0 ? BuffType.Good : BuffType.Bad, SecondData); } } break; } } break; case BCardType.CardType.SpecialEffects: break; case BCardType.CardType.Capture: { if (type == typeof(MapMonster) && session is MapMonster mapMonster && sender is ClientSession senderSession) { NpcMonster mateNpc = ServerManager.GetNpcMonster(mapMonster.MonsterVNum); if (mateNpc != null) { if (mapMonster.Monster.Catch) { if (mapMonster.IsAlive && mapMonster.CurrentHp <= (int)((double)mapMonster.MaxHp / 2)) { if (mapMonster.Monster.Level < senderSession.Character.Level) { // TODO: find a new algorithm int[] chance = { 100, 80, 60, 40, 20, 0 }; if (ServerManager.RandomNumber() < chance[ServerManager.RandomNumber(0, 5)]) { Mate mate = new Mate(senderSession.Character, mateNpc, (byte)(mapMonster.Monster.Level - 15 > 0 ? mapMonster.Monster.Level - 15 : 1), MateType.Pet); if (senderSession.Character.CanAddMate(mate)) { senderSession.Character.AddPetWithSkill(mate); senderSession.SendPacket( UserInterfaceHelper.GenerateMsg( Language.Instance.GetMessageFromKey("CATCH_SUCCESS"), 0)); senderSession.CurrentMapInstance?.Broadcast( StaticPacketHelper.GenerateEff(UserType.Player, senderSession.Character.CharacterId, 197)); senderSession.CurrentMapInstance?.Broadcast( StaticPacketHelper.SkillUsed(UserType.Player, senderSession.Character.CharacterId, 3, mapMonster.MapMonsterId, -1, 0, 15, -1, -1, -1, true, (int)(mapMonster.CurrentHp / (float)mapMonster.MaxHp * 100 ), 0, -1, 0)); mapMonster.SetDeathStatement(); senderSession.CurrentMapInstance?.Broadcast( StaticPacketHelper.Out(UserType.Monster, mapMonster.MapMonsterId)); } else { senderSession.SendPacket( senderSession.Character.GenerateSay( Language.Instance.GetMessageFromKey("PET_SLOT_FULL"), 10)); senderSession.SendPacket( StaticPacketHelper.Cancel(2, mapMonster.MapMonsterId)); } } else { senderSession.SendPacket( UserInterfaceHelper.GenerateMsg( Language.Instance.GetMessageFromKey("CATCH_FAIL"), 0)); senderSession.CurrentMapInstance?.Broadcast( StaticPacketHelper.SkillUsed(UserType.Player, senderSession.Character.CharacterId, 3, mapMonster.MapMonsterId, -1, 0, 15, -1, -1, -1, true, (int)(mapMonster.CurrentHp / (float)mapMonster.MaxHp * 100), 0, -1, 0)); } } else { senderSession.SendPacket(UserInterfaceHelper.GenerateMsg( Language.Instance.GetMessageFromKey("LEVEL_LOWER_THAN_MONSTER"), 0)); senderSession.SendPacket( StaticPacketHelper.Cancel(2, mapMonster.MapMonsterId)); } } else { senderSession.SendPacket(UserInterfaceHelper.GenerateMsg( Language.Instance.GetMessageFromKey("CURRENT_HP_TOO_HIGH"), 0)); senderSession.SendPacket(StaticPacketHelper.Cancel(2, mapMonster.MapMonsterId)); } } else { senderSession.SendPacket(UserInterfaceHelper.GenerateMsg( Language.Instance.GetMessageFromKey("MONSTER_CANT_BE_CAPTURED"), 0)); senderSession.SendPacket(StaticPacketHelper.Cancel(2, mapMonster.MapMonsterId)); } } } } break; case BCardType.CardType.SpecialDamageAndExplosions: break; case BCardType.CardType.SpecialEffects2: if (type == typeof(Character)) { if (session is Character c) { short destinationX = c.PositionX; short destinationY = c.PositionY; switch (SubType) { case (byte)AdditionalTypes.SpecialEffects2.TeleportInRadius / 10: { switch (c.Direction) { case 0: // -y destinationY -= (short)FirstData; break; case 1: // +x destinationX += (short)FirstData; break; case 2: // +y destinationY += (short)FirstData; break; case 3: // -x destinationX -= (short)FirstData; break; case 4: // -x -y destinationX -= (short)FirstData; destinationY -= (short)FirstData; break; case 5: // +x +y destinationX += (short)FirstData; destinationY += (short)FirstData; break; case 6: // +x -y destinationX += (short)FirstData; destinationY -= (short)FirstData; break; case 7: // -x +y destinationX -= (short)FirstData; destinationY += (short)FirstData; break; } ServerManager.Instance.TeleportForward(c.Session, c.MapInstanceId, destinationX, destinationY); } break; } } } break; case BCardType.CardType.CalculatingLevel: break; case BCardType.CardType.Recovery: break; case BCardType.CardType.MaxHpmp: break; case BCardType.CardType.MultAttack: break; case BCardType.CardType.MultDefence: break; case BCardType.CardType.TimeCircleSkills: break; case BCardType.CardType.RecoveryAndDamagePercent: break; case BCardType.CardType.Count: break; case BCardType.CardType.NoDefeatAndNoDamage: break; case BCardType.CardType.SpecialActions: { switch (SubType) { case (byte)AdditionalTypes.SpecialActions.RunAway / 10: if (session is MapMonster m) { m.MapInstance.Broadcast(StaticPacketHelper.Say(UserType.Monster, m.MapMonsterId, 0, "!!!")); m.RemoveTarget(); for (int i = 0; i < 10; i++) { Observable.Timer(TimeSpan.FromSeconds(i)).Subscribe(o => { m.MapX++; m.MapY++; m.IgnoreTargetsUntil = DateTime.UtcNow.AddSeconds(10); m.RemoveTarget(); }); } } break; } } break; case BCardType.CardType.Mode: break; case BCardType.CardType.NoCharacteristicValue: break; case BCardType.CardType.LightAndShadow: { switch (SubType) { case (byte)AdditionalTypes.LightAndShadow.RemoveBadEffects / 10: { if (session is Character c /*&& sender is ClientSession senderSession*/) { c.DisableBuffs(BuffType.Bad, FirstData); } } break; } } break; case BCardType.CardType.Item: break; case BCardType.CardType.DebuffResistance: break; case BCardType.CardType.SpecialBehaviour: break; case BCardType.CardType.Quest: break; case BCardType.CardType.SecondSpCard: break; case BCardType.CardType.SpCardUpgrade: break; case BCardType.CardType.HugeSnowman: break; case BCardType.CardType.Drain: break; case BCardType.CardType.BossMonstersSkill: break; case BCardType.CardType.LordHatus: break; case BCardType.CardType.LordCalvinas: break; case BCardType.CardType.SeSpecialist: break; case BCardType.CardType.FourthGlacernonFamilyRaid: break; case BCardType.CardType.SummonedMonsterAttack: break; case BCardType.CardType.BearSpirit: break; case BCardType.CardType.SummonSkill: break; case BCardType.CardType.InflictSkill: break; case BCardType.CardType.HideBarrelSkill: break; case BCardType.CardType.FocusEnemyAttentionSkill: break; case BCardType.CardType.TauntSkill: break; case BCardType.CardType.FireCannoneerRangeBuff: break; case BCardType.CardType.VulcanoElementBuff: break; case BCardType.CardType.DamageConvertingSkill: break; case BCardType.CardType.MeditationSkill: { if (type == typeof(Character) && session is Character character) { if (SkillVNum.HasValue && SubType.Equals((byte)AdditionalTypes.MeditationSkill.CausingChance / 10) && ServerManager.RandomNumber() < FirstData) { Skill skill = ServerManager.GetSkill(SkillVNum.Value); Skill newSkill = ServerManager.GetSkill((short)SecondData); Observable.Timer(TimeSpan.FromMilliseconds(100)).Subscribe(observer => { foreach (QuicklistEntryDTO quicklistEntry in character.QuicklistEntries.Where(s => s.Morph == character.Morph && s.Pos.Equals(skill.CastId))) { character.Session.SendPacket( $"qset {quicklistEntry.Q1} {quicklistEntry.Q2} {quicklistEntry.Type}.{quicklistEntry.Slot}.{newSkill.CastId}.0"); } character.Session.SendPacket($"mslot {newSkill.CastId} -1"); }); character.SkillComboCount++; character.LastSkillComboUse = DateTime.UtcNow; if (skill.CastId > 10) { // HACK this way Observable.Timer(TimeSpan.FromMilliseconds((skill.Cooldown * 100) + 500)) .Subscribe(observer => character.Session.SendPacket(StaticPacketHelper.SkillReset(skill.CastId))); } } switch (SubType) { case 2: character.MeditationDictionary[(short)SecondData] = DateTime.UtcNow.AddSeconds(4); break; case 3: character.MeditationDictionary[(short)SecondData] = DateTime.UtcNow.AddSeconds(8); break; case 4: character.MeditationDictionary[(short)SecondData] = DateTime.UtcNow.AddSeconds(12); break; } } } break; case BCardType.CardType.FalconSkill: { if (session is Character c) { switch (SubType) { case (byte)AdditionalTypes.FalconSkill.Hide: c.Invisible = true; c.Mates.Where(s => s.IsTeamMember).ToList().ForEach(s => c.Session.CurrentMapInstance?.Broadcast(s.GenerateOut())); c.Session.CurrentMapInstance?.Broadcast(c.GenerateInvisible()); c.Session.SendPacket(c.GenerateEq()); break; } } } break; case BCardType.CardType.AbsorptionAndPowerSkill: break; case BCardType.CardType.LeonaPassiveSkill: break; case BCardType.CardType.FearSkill: break; case BCardType.CardType.SniperAttack: break; case BCardType.CardType.FrozenDebuff: break; case BCardType.CardType.JumpBackPush: break; case BCardType.CardType.FairyXPIncrease: break; case BCardType.CardType.SummonAndRecoverHP: break; case BCardType.CardType.TeamArenaBuff: break; case BCardType.CardType.ArenaCamera: break; case BCardType.CardType.DarkCloneSummon: break; case BCardType.CardType.AbsorbedSpirit: break; case BCardType.CardType.AngerSkill: break; case BCardType.CardType.MeteoriteTeleport: if (type == typeof(Character)) { if (session is Character character) { switch (SubType) { case ((byte)AdditionalTypes.MeteoriteTeleport.TeleportYouAndGroupToSavedLocation / 10): if (character.TeleportSet == false) { character.TeleportX = character.PositionX; character.TeleportY = character.PositionY; character.TeleportMap = character.MapId; character.MapInstance.Broadcast(StaticPacketHelper.GenerateEff(UserType.Player, character.CharacterId, 4497)); character.TeleportSet = true; Observable.Timer(TimeSpan.FromSeconds(40)).Subscribe(o => character.TeleportSet = false); } else { if (character.MapInstance.IsPvp) { if (character.MapInstance.MapInstanceType != MapInstanceType.BaseMapInstance) { character.TeleportSet = false; return; } character.MapInstance.Broadcast($"tp 1 {character.CharacterId} {character.TeleportX} {character.TeleportY} 0"); character.PositionX = character.TeleportX; character.PositionY = character.TeleportY; character.TeleportSet = false; } else { if (character.MapId == character.TeleportMap) { if (character.MapInstance.MapInstanceType == MapInstanceType.CaligorInstance) { character.TeleportSet = false; return; } character.MapInstance.Broadcast($"tp 1 {character.CharacterId} {character.TeleportX} {character.TeleportY} 0"); character.PositionX = character.TeleportX; character.PositionY = character.TeleportY; character.TeleportSet = false; } else { character.TeleportSet = false; } } } break; case (byte)AdditionalTypes.MeteoriteTeleport.CauseMeteoriteFall / 10: { int amount = 10 + (character.Level / FirstData); for (int i = 0; i < amount; i++) { Observable.Timer(TimeSpan.FromMilliseconds(i * 500)).Subscribe(o => character.SpawnMeteorite()); } } break; } } } break; case BCardType.CardType.StealBuff: break; case BCardType.CardType.Unknown: break; case BCardType.CardType.EffectSummon: break; default: Logger.Warn($"Card Type {Type} not defined!"); break; } }