public void Teleport(ushort MapID, ushort X, ushort Y) { if (MapID != Original.Map.MapID) { Maps.Map map; if (!Core.Kernel.Maps.TrySelect(MapID, out map)) { return; } Original.Map = map; if (Original.Map != null) { Original.LastMapID = Original.Map.MapID; } if (!Original.Map.EnterMap(Original)) { return; } } Maps.MapPoint location = new Maps.MapPoint(MapID, X, Y); Original.X = location.X; Original.Y = location.Y; Original.LastMapX = location.X; Original.LastMapY = location.Y; Original.LastX = location.X; Original.LastY = location.Y; }
/// <summary> /// Creates a new npc and spawns it. /// </summary> /// <param name="id">The id of the npc.</param> /// <param name="name">The name of the npc.</param> /// <param name="location">The location of the npc.</param> /// <param name="mesh">The mesh of the npc.</param> /// <param name="avatar">The avatar of the npc.</param> /// <param name="npctype">The type of the npc.</param> /// <param name="flag">The flat of the npc.</param> public static void CreateNPC(uint id, string name, Maps.MapPoint location, ushort mesh, byte avatar, Enums.NPCType npctype = Enums.NPCType.Normal, ushort flag = 2) { Entities.NPC npc = new ProjectX_V3_Game.Entities.NPC(); npc.EntityUID = id; npc.Mesh = (ushort)(mesh * 10); npc.Flag = flag; npc.Name = name; npc.X = location.X; npc.Y = location.Y; npc.NPCType = npctype; npc.Avatar = avatar; if (!location.Map.EnterMap(npc)) { return; } if (Core.Kernel.NPCs.TryAdd(npc.EntityUID, npc)) { IniFile npcini = new IniFile(ServerDatabase.DatabaseLocation + "\\NPCInfo\\" + id + ".ini", "Info"); npcini.WriteString("Name", name); npcini.WriteString("Type", npctype.ToString()); npcini.Write <ushort>("MapID", location.MapID); npcini.Write <ushort>("X", location.X); npcini.Write <ushort>("Y", location.Y); npcini.Write <ushort>("Flag", flag); npcini.Write <ushort>("Mesh", mesh); npcini.Write <byte>("Avatar", avatar); npc.Screen.UpdateScreen(null); } }
public void InteractWith(Character character, NpcActionTypeEnum actionType) { if (character.Busy) { return; } if (actionType == NpcActionTypeEnum.Talk && CinematicProvider.Instance.IsNpcHandled(character, SpawnRecord.Id)) { var npcPoint = new Maps.MapPoint((short)this.CellId); character.SetDirection(character.Point.OrientationTo(npcPoint, true)); character.RandomTalkEmote(); CinematicProvider.Instance.TalkToNpc(character, SpawnRecord.Id); return; } NpcActionRecord action = GetAction(actionType); if (action != null) { NpcActionProvider.Handle(character, this, action); } else if (character.Client.Account.Role > ServerRoleEnum.Player) { character.Reply("No (" + actionType + ") action linked to this npc...(" + SpawnRecord.Id + ")"); } }
public LastManStanding() : base("LastManStanding", 00, 4, 16) { Players = new ConcurrentDictionary<uint, ProjectX_V3_Game.Entities.GameClient>(); MapLocation = new ProjectX_V3_Game.Maps.MapPoint(50001, 46, 45); BattleClass = new LastManStanding.LastManStandingBattleClass(); BattleClass.LastManStanding = this; new ProjectX_V3_Lib.Threading.BaseThread(CHECK_PLAYERS_THREAD, 5000, "LastManStandingThread").Start(); }
public LastManStanding() : base("LastManStanding", 00, 4, 16) { Players = new ConcurrentDictionary <uint, ProjectX_V3_Game.Entities.GameClient>(); MapLocation = new ProjectX_V3_Game.Maps.MapPoint(50001, 46, 45); BattleClass = new LastManStanding.LastManStandingBattleClass(); BattleClass.LastManStanding = this; new ProjectX_V3_Lib.Threading.BaseThread(CHECK_PLAYERS_THREAD, 5000, "LastManStandingThread").Start(); }
/// <summary> /// Handling the Drop action from the ItemPacket. /// </summary> /// <param name="client">The client.</param> /// <param name="item">The item packet.</param> public static void Handle(Entities.GameClient client, ItemPacket packet) { if (client.Booth != null) { return; } if (!client.Alive) { return; } if (client.Map.MapType == Enums.MapType.Shared) { return; } if (client.Inventory.ContainsByUID(packet.UID)) { Maps.MapPoint Location = client.Map.CreateAvailableLocation <Data.GroundItem>(client.X, client.Y, 3); if (Location != null) { Data.ItemInfo dropitem = client.Inventory.GetItemByUID(packet.UID); if (dropitem != null) { if (!dropitem.IsValidOffItem()) { using (var fmsg = Message.MessageCore.CreateSystem(client.Name, Core.MessageConst.NO_PERMISSION_ITEM)) { client.Send(fmsg); } return; } client.Inventory.RemoveItemByUID(packet.UID); Data.GroundItem ground = new Data.GroundItem(dropitem); ground.PlayerDrop = true; ground.DropType = Enums.DropItemType.Item; ground.X = Location.X; ground.Y = Location.Y; Location.Map.EnterMap(ground); ground.TaskID = ProjectX_V3_Lib.Threading.DelayedTask.StartDelayedTask( () => { Location.Map.LeaveMap(ground); ground.Screen.ClearScreen(); }, Core.TimeIntervals.DroppedItemRemove); ground.Screen.UpdateScreen(null); } } } }
public static void AddNewMonsterSpawn(ushort mapid, ushort x, ushort y, int monsterid, int count, int drop, int range, bool guard) { using (var sql = new SqlHandler(Program.Config.ReadString("GameConnectionString"))) { using (var cmd = new SqlCommandBuilder(sql, SqlCommandType.INSERT, false)) { cmd.AddInsertValue("MonsterID", monsterid); cmd.AddInsertValue("CenterX", x); cmd.AddInsertValue("CenterY", y); cmd.AddInsertValue("Drop", drop); cmd.AddInsertValue("Count", count); if (guard) { cmd.AddInsertValue("Range", (int)1); } else { cmd.AddInsertValue("Range", range); } cmd.Finish("DB_MobSpawns"); } sql.Execute(); } for (int i = 0; i < count; i++) { Entities.Monster spawnmob = Core.Kernel.Monsters[monsterid].Copy(); spawnmob.Direction = (byte)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next(0, 8); if (Core.Kernel.Maps[mapid].EnterMap(spawnmob)) { Maps.MapPoint Location = spawnmob.Map.CreateAvailableLocation <Entities.Monster>(x, y, range); if (Location != null) { spawnmob.X = Location.X; spawnmob.Y = Location.Y; spawnmob.OriginalRange = range; spawnmob.OriginalX = x; spawnmob.OriginalY = y; //if (drop > 0) //{ // spawnmob.DropData = Core.Kernel.DropData[drop].Copy(); //} Threads.MonsterThread.AddToMonsterThread(spawnmob, !(((byte)spawnmob.Behaviour) < 3 || spawnmob.Behaviour == Enums.MonsterBehaviour.PhysicalGuard)); spawnmob.Screen.UpdateScreen(null); } } } }
public void Jump() { if (Core.Screen.GetDistance(Original.X, Original.Y, DestinationX, DestinationY) <= 5) { Threads.ActionThread.Actions.TryRemove(CurrentJumpAction.ActionID, out CurrentJumpAction); CurrentJumpAction = null; return; } Enums.ConquerAngle angle = Core.Screen.GetFacing(Core.Screen.GetAngle(Original.X, Original.Y, DestinationX, DestinationY)); Maps.MapPoint point = Packets.MovementPacket.CreateDirectionPoint(Original.X, Original.Y, (byte)angle); if (!Original.Map.ValidCoord(point.X, point.Y)) { return; } const ushort size = 14; for (ushort i = size; i > 0; i--) { Maps.MapPoint npoint = Packets.MovementPacket.CreateDirectionPoint(point.X, point.Y, (byte)angle); npoint = new ProjectX_V3_Game.Maps.MapPoint(0, npoint.X, npoint.Y); if (Original.Map.ValidCoord(npoint.X, npoint.Y)) { point = npoint; } else { break; } } ushort x = point.X; ushort y = point.Y; Packets.GeneralDataPacket general = new ProjectX_V3_Game.Packets.GeneralDataPacket(Enums.DataAction.Jump); general.Id = Original.EntityUID; general.Data1Low = x; general.Data1High = y; general.Data5 = uint.MaxValue; general.Data3Low = Original.X; general.Data3High = Original.Y; general.Data4 = (uint)Original.Map.MapID; general.Timestamp = ProjectX_V3_Lib.Native.Winmm.timeGetTime(); Original.SendToScreen(general, false, false); Original.X = x; Original.Y = y; }
public void Drop(Maps.Map map, ushort MidLocationX, ushort MidLocationY) { Maps.MapPoint Location = map.CreateAvailableLocation <Data.GroundItem>(MidLocationX, MidLocationY, 10); if (Location != null) { Data.GroundItem ground = new Data.GroundItem(this); ground.DropType = Enums.DropItemType.Item; ground.X = Location.X; ground.Y = Location.Y; Location.Map.EnterMap(ground); ground.TaskID = ProjectX_V3_Lib.Threading.DelayedTask.StartDelayedTask( () => { Location.Map.LeaveMap(ground); ground.Screen.ClearScreen(); }, Core.TimeIntervals.DroppedItemRemove); ground.Screen.UpdateScreen(null); } }
public void Jump(ushort size, Enums.ConquerAngle angle) { Maps.MapPoint point = Packets.MovementPacket.CreateDirectionPoint(Original.X, Original.Y, (byte)angle); if (!Original.Map.ValidCoord(point.X, point.Y)) { return; } for (ushort i = size; i > 0; i--) { Maps.MapPoint npoint = Packets.MovementPacket.CreateDirectionPoint(point.X, point.Y, (byte)angle); npoint = new ProjectX_V3_Game.Maps.MapPoint(0, npoint.X, npoint.Y); if (Original.Map.ValidCoord(npoint.X, npoint.Y)) { point = npoint; } else { break; } } Jump(point.X, point.Y); }
public void Revive() { StatusFlag1 = 0; if (Behaviour == Enums.MonsterBehaviour.PhysicalGuard || Behaviour == Enums.MonsterBehaviour.MagicGuard || Behaviour == Enums.MonsterBehaviour.DeathGuard || Behaviour == Enums.MonsterBehaviour.ReviverGuard1 || Behaviour == Enums.MonsterBehaviour.ReviverGuard2) { X = OriginalX; Y = OriginalY; } else { Maps.MapPoint point = Map.CreateAvailableLocation <Monster>(OriginalX, OriginalY, OriginalRange); X = point.X; Y = point.Y; } HP = MaxHP; MP = MaxMP; Alive = true; Direction = (byte)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next(0, 8); Screen.UpdateScreen(null); }
public static bool LoadMonsterSpawns() { Console.ForegroundColor = ConsoleColor.Yellow; string wrt = "\tLoading Monster Spawns..."; Console.WriteLine(wrt); int SpawnCount = 0; int GuardSpawnCount = 0; using (var spawn = new SqlHandler(Program.Config.ReadString("GameConnectionString"))) { using (var cmd = new SqlCommandBuilder(spawn, SqlCommandType.SELECT, false)) { cmd.Finish("DB_MobSpawns"); } while (spawn.Read()) { ushort mapid = spawn.ReadUInt16("MapID"); Maps.Map map; if (!Core.Kernel.Maps.TrySelect(mapid, out map)) { return(false); } ushort CenterX = spawn.ReadUInt16("CenterX"); ushort CenterY = spawn.ReadUInt16("CenterY"); int Range = spawn.ReadUInt16("Range"); // int DropData = spawn.ReadInt32("DropID"); int Monster = spawn.ReadInt32("MonsterID"); int MobCount = spawn.ReadInt32("Count"); if (CenterX > 0 && CenterY > 0 && Range > 0 && Monster > 0 && MobCount > 0) { for (int j = 0; j < MobCount; j++) { Entities.Monster spawnmob = Core.Kernel.Monsters[Monster].Copy(); spawnmob.MobID = Monster; spawnmob.Direction = (byte)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next(0, 8); if (!map.EnterMap(spawnmob)) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("[MAP] Failed to load spawns. Failed at Map: {0} and MobID: {1}", mapid, Monster); Console.ResetColor(); return(false); } Maps.MapPoint Location = spawnmob.Map.CreateAvailableLocation <Entities.Monster>(CenterX, CenterY, Range); if (Location != null) { spawnmob.X = Location.X; spawnmob.Y = Location.Y; spawnmob.OriginalRange = Range; spawnmob.OriginalX = CenterX; spawnmob.OriginalY = CenterY; spawnmob.DropData = Core.Kernel.DropData[map.MapID].Copy(); if (((byte)spawnmob.Behaviour) < 3 || spawnmob.Behaviour == Enums.MonsterBehaviour.PhysicalGuard) // physical guards should walk around { #if SPAWN_MOBS Threads.MonsterThread.AddToMonsterThread(spawnmob, false); SpawnCount++; #endif } else { Threads.MonsterThread.AddToMonsterThread(spawnmob, true); GuardSpawnCount++; } } else { spawnmob.Map.LeaveMap(spawnmob); // there was no location available } Console.Clear(); Console.WriteLine(wrt); Console.WriteLine("\tLoaded {0} Monster Spawns and {1} Guard Spawns...", SpawnCount, GuardSpawnCount); } } } } return(true); }
public bool Teleport(Maps.MapPoint point) { return(Teleport(point.MapID, point.X, point.Y)); }
private void Creature_Move_Thread() { if (!Alive) { return; } try { if (Target != null) { if (DateTime.Now >= this.MoveTime) { if (Core.Screen.GetDistance(this.X, this.Y, this.Target.X, this.Target.Y) >= this.ViewRange) { byte dir = (byte)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next(0, 8); Maps.MapPoint movepoint = Packets.MovementPacket.CreateDirectionPoint(this.X, this.Y, dir); if (this.Map.ValidMoveCoord <Entities.Monster>(movepoint.X, movepoint.Y)) { this.X = movepoint.X; this.Y = movepoint.Y; this.Direction = dir; using (var movepacket = new Packets.MovementPacket()) { movepacket.EntityUID = this.EntityUID; movepacket.TimeStamp = ProjectX_V3_Lib.Native.Winmm.timeGetTime(); movepacket.Direction = (uint)dir; movepacket.WalkMode = Enums.WalkMode.Run; this.Screen.UpdateScreen(movepacket); } this.MoveTime = DateTime.Now.AddMilliseconds(this.MoveSpeed * 5); } } else { byte dir = (byte)Core.Screen.GetFacing(Core.Screen.GetAngle(this.X, this.Y, this.Target.X, this.Target.Y)); Maps.MapPoint movepoint = Packets.MovementPacket.CreateDirectionPoint(this.X, this.Y, dir); if (this.Map.ValidMoveCoord <Entities.Monster>(movepoint.X, movepoint.Y)) { this.X = movepoint.X; this.Y = movepoint.Y; this.Direction = dir; using (var movepacket = new Packets.MovementPacket()) { movepacket.EntityUID = this.EntityUID; movepacket.TimeStamp = ProjectX_V3_Lib.Native.Winmm.timeGetTime(); movepacket.Direction = (uint)dir; movepacket.WalkMode = Enums.WalkMode.Run; this.Screen.UpdateScreen(movepacket); } } int nextmove = ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next(this.MoveSpeed, this.MoveSpeed * 2); this.MoveTime = DateTime.Now.AddMilliseconds(nextmove); } } } } catch { } }
/// <summary> /// Drops the items and gold associated with the drop data. /// </summary> /// <param name="client">The client to receive cps if any. Put null if not a client drop.</param> /// <param name="MidLocation">The location to star the drop from.</param> public void Drop(Entities.GameClient client, Maps.MapPoint MidLocation) { if (Calculations.BasicCalculations.ChanceSuccess(CPsDropChance)) { // for cps bags just add them to the items // or copy the item drops already existing above and below if (client != null) { client.CPs += (uint)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next((int)MinCPsDrop, (int)MaxCPsDrop); } } else { Maps.MapPoint Location = MidLocation.Map.CreateAvailableLocation <Data.GroundItem>(MidLocation.X, MidLocation.Y, 5); if (Location != null) { // perhaps some vip thing to loot gold in bag, rather than ground ?? uint DropMoney = (uint)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next((int)MinGoldDrop, (int)MaxGoldDrop); if (DropMoney > 0) { uint ItemID = 1090000; if (DropMoney > 10000) { ItemID = 1091020; } else if (DropMoney > 5000) { ItemID = 1091010; } else if (DropMoney > 1000) { ItemID = 1091000; } else if (DropMoney > 100) { ItemID = 1090020; } else if (DropMoney > 50) { ItemID = 1090010; } Data.ItemInfo item; if (Core.Kernel.ItemInfos.TrySelect(ItemID, out item)) { item = item.Copy(); // necessary to not edit original data Data.GroundItem ground = new Data.GroundItem(item); if (client != null) { ground.PlayerDrop = false; ground.OwnerUID = client.EntityUID; ground.DropTime = DateTime.Now; } ground.DropType = Enums.DropItemType.Gold; ground.Money = DropMoney; ground.X = Location.X; ground.Y = Location.Y; Location.Map.EnterMap(ground); ground.TaskID = ProjectX_V3_Lib.Threading.DelayedTask.StartDelayedTask( () => { Location.Map.LeaveMap(ground); ground.Screen.ClearScreen(); }, Core.TimeIntervals.DroppedItemRemove); ground.Screen.UpdateScreen(null); } } } } // could use else if, however we do want to drop gold/cps and items at the same time if (Calculations.BasicCalculations.ChanceSuccess(33)) { if (ItemDrops.Count > 0) { uint[] itemids = ItemDrops.ToArray(); uint ItemID = itemids[ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next(0, itemids.Length - 1)]; Data.ItemInfo item; // check for chances between the different types of items ex. armor, bow etc. item.IsArmor() etc. if (Core.Kernel.ItemInfos.TrySelect(ItemID, out item)) { Maps.MapPoint Location = MidLocation.Map.CreateAvailableLocation <Data.GroundItem>(MidLocation.X, MidLocation.Y, 5); if (Location != null) { item = item.Copy(); // necessary if (item.IsArmor() || item.IsBow() || item.IsRing() || item.IsOneHand() || item.IsTwoHand() || item.IsBoots() || item.IsHeadgear() || item.IsShield() || item.IsNecklace()) { if (Calculations.BasicCalculations.ChanceSuccess(PlusChance)) { byte chance = (byte)(MaxPlus * (MaxPlus + 1)); byte offchance = (byte)(chance / MaxPlus); item.Plus = MinPlus; while (Calculations.BasicCalculations.ChanceSuccess(chance)) { item.Plus += 1; chance -= offchance; } } if (Calculations.BasicCalculations.ChanceSuccess(QualityChance)) { item = Core.Kernel.ItemInfos[item.ItemID + 3].Copy(); if (Calculations.BasicCalculations.ChanceSuccess(20)) { item = Core.Kernel.ItemInfos[item.ItemID + 1].Copy(); if (Calculations.BasicCalculations.ChanceSuccess(15)) { item = Core.Kernel.ItemInfos[item.ItemID + 1].Copy(); if (Calculations.BasicCalculations.ChanceSuccess(10)) { item = Core.Kernel.ItemInfos[item.ItemID + 1].Copy(); } } } } if (Calculations.BasicCalculations.ChanceSuccess(FirstSocketChance) || item.IsOneHand() && Calculations.BasicCalculations.ChanceSuccess(FirstSocketChance * 2) || item.IsTwoHand() && Calculations.BasicCalculations.ChanceSuccess(FirstSocketChance * 2)) { item.Gem1 = Enums.SocketGem.EmptySocket; if (Calculations.BasicCalculations.ChanceSuccess(SecondSocketChance)) { item.Gem2 = Enums.SocketGem.EmptySocket; } } if (Calculations.BasicCalculations.ChanceSuccess(BlessChance)) { item.Bless = 1; } } Data.GroundItem ground = new Data.GroundItem(item); if (client != null) { ground.PlayerDrop = false; ground.OwnerUID = client.EntityUID; ground.DropTime = DateTime.Now; } ground.DropType = Enums.DropItemType.Item; ground.X = Location.X; ground.Y = Location.Y; Location.Map.EnterMap(ground); ground.TaskID = ProjectX_V3_Lib.Threading.DelayedTask.StartDelayedTask( () => { Location.Map.LeaveMap(ground); ground.Screen.ClearScreen(); }, Core.TimeIntervals.DroppedItemRemove); ground.Screen.UpdateScreen(null); } } } } else if (Calculations.BasicCalculations.ChanceSuccess(MeteorChance)) { Data.ItemInfo item; if (Core.Kernel.ItemInfos.TrySelect(1088001, out item)) { Maps.MapPoint Location = MidLocation.Map.CreateAvailableLocation <Data.GroundItem>(MidLocation.X, MidLocation.Y, 5); if (Location != null) { item = item.Copy(); // necessary Data.GroundItem ground = new Data.GroundItem(item); if (client != null) { ground.PlayerDrop = false; ground.OwnerUID = client.EntityUID; ground.DropTime = DateTime.Now; } ground.DropType = Enums.DropItemType.Item; ground.X = Location.X; ground.Y = Location.Y; Location.Map.EnterMap(ground); ground.TaskID = ProjectX_V3_Lib.Threading.DelayedTask.StartDelayedTask( () => { Location.Map.LeaveMap(ground); ground.Screen.ClearScreen(); }, Core.TimeIntervals.DroppedItemRemove); ground.Screen.UpdateScreen(null); } } } else if (Calculations.BasicCalculations.ChanceBigSuccess(10, DragonballChance)) { Data.ItemInfo item; if (Core.Kernel.ItemInfos.TrySelect(1088000, out item)) { Maps.MapPoint Location = MidLocation.Map.CreateAvailableLocation <Data.GroundItem>(MidLocation.X, MidLocation.Y, 5); if (Location != null) { item = item.Copy(); // necessary Data.GroundItem ground = new Data.GroundItem(item); if (client != null) { ground.PlayerDrop = false; ground.OwnerUID = client.EntityUID; ground.DropTime = DateTime.Now; } ground.DropType = Enums.DropItemType.Item; ground.X = Location.X; ground.Y = Location.Y; Location.Map.EnterMap(ground); ground.TaskID = ProjectX_V3_Lib.Threading.DelayedTask.StartDelayedTask( () => { Location.Map.LeaveMap(ground); ground.Screen.ClearScreen(); }, Core.TimeIntervals.DroppedItemRemove); ground.Screen.UpdateScreen(null); } } } else if (Calculations.BasicCalculations.ChanceSuccess(NormalGemChance)) { Data.ItemInfo item; Enums.SocketGem gem = (Enums.SocketGem)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.NextEnum(typeof(Enums.SocketGem)); switch (gem) { case Enums.SocketGem.NormalPhoenixGem: case Enums.SocketGem.RefinedPhoenixGem: case Enums.SocketGem.SuperPhoenixGem: gem = Enums.SocketGem.NormalPhoenixGem; break; case Enums.SocketGem.NormalDragonGem: case Enums.SocketGem.RefinedDragonGem: case Enums.SocketGem.SuperDragonGem: gem = Enums.SocketGem.NormalDragonGem; break; case Enums.SocketGem.NormalRainbowGem: case Enums.SocketGem.RefinedRainbowGem: case Enums.SocketGem.SuperRainbowGem: gem = Enums.SocketGem.NormalRainbowGem; break; case Enums.SocketGem.NormalVioletGem: case Enums.SocketGem.RefinedVioletGem: case Enums.SocketGem.SuperVioletGem: gem = Enums.SocketGem.NormalVioletGem; break; case Enums.SocketGem.NormalFuryGem: case Enums.SocketGem.RefinedFuryGem: case Enums.SocketGem.SuperFuryGem: gem = Enums.SocketGem.NormalFuryGem; break; case Enums.SocketGem.NormalKylinGem: case Enums.SocketGem.RefinedKylinGem: case Enums.SocketGem.SuperKylinGem: gem = Enums.SocketGem.NormalKylinGem; break; case Enums.SocketGem.NormalMoonGem: case Enums.SocketGem.RefinedMoonGem: case Enums.SocketGem.SuperMoonGem: gem = Enums.SocketGem.NormalMoonGem; break; default: return; } uint gemid = (uint)(((uint)gem) + 700000); if (Calculations.BasicCalculations.ChanceSuccess(RefinedGemChance)) { gemid += 1; if (Calculations.BasicCalculations.ChanceSuccess(SuperGemChance)) { gemid += 1; } } if (Core.Kernel.ItemInfos.TrySelect(gemid, out item)) { Maps.MapPoint Location = MidLocation.Map.CreateAvailableLocation <Data.GroundItem>(MidLocation.X, MidLocation.Y, 5); if (Location != null) { item = item.Copy(); // necessary Data.GroundItem ground = new Data.GroundItem(item); if (client != null) { ground.PlayerDrop = false; ground.OwnerUID = client.EntityUID; ground.DropTime = DateTime.Now; } ground.DropType = Enums.DropItemType.Item; ground.X = Location.X; ground.Y = Location.Y; Location.Map.EnterMap(ground); ground.TaskID = ProjectX_V3_Lib.Threading.DelayedTask.StartDelayedTask( () => { Location.Map.LeaveMap(ground); ground.Screen.ClearScreen(); }, Core.TimeIntervals.DroppedItemRemove); ground.Screen.UpdateScreen(null); } } } }
public void Use(Entities.BossMonster boss, Entities.GameClient[] Targets) { if (Targets.Length == 0 && !SpreadSkill || MaxTargets == 0 && !SpreadSkill) { return; } if (DateTime.Now < CoolDownTime) { return; } CoolDownTime = DateTime.Now.AddSeconds(CoolDown); if (MapSkill != null) { MapSkill.ExecuteStart(boss.X, boss.Y); } AreaSkill area = new AreaSkill(); area.boss = boss; area.skill = this; #region Shake, Dark, Zoom if (Shake || Dark || Zoom) { using (var effect = new Packets.MapEffectPacket()) { effect.Shake = Shake; effect.Darkness = Dark; effect.Zoom = Zoom; effect.AppendFlags(); foreach (Entities.GameClient target in Targets) { effect.X = target.X; effect.Y = target.Y; target.Send(effect); } } } #endregion if (MaxTargets == 1) { Array.Resize(ref Targets, 1); } else if (MaxTargets > 0 && Targets.Length > MaxTargets) { Array.Resize(ref Targets, MaxTargets); } #region Explode // TODO: Explosion effect .. if (Explode) { if (PlayerExplode) { using (var str = new Packets.StringPacket(new Packets.StringPacker(MapEffect))) { str.Action = Enums.StringAction.MapEffect; foreach (Entities.GameClient target in Targets) { str.PositionX = target.X; str.PositionY = target.Y; target.SendToScreen(str, true, false); } } } else if (BossExplode) { using (var str = new Packets.StringPacket(new Packets.StringPacker(MapEffect))) { str.Action = Enums.StringAction.MapEffect; str.PositionX = boss.X; str.PositionY = boss.Y; foreach (Entities.GameClient target in Targets) { target.Send(str); } } } else { using (var str = new Packets.StringPacket(new Packets.StringPacker(MapEffect))) { str.Action = Enums.StringAction.MapEffect; str.PositionX = ExplodePos[0]; str.PositionY = ExplodePos[1]; foreach (Entities.GameClient target in Targets) { target.Send(str); } } } } #endregion #region Creatures if (SummonCreatures) { int SpawnSize = (FixCreatureSize ? Targets.Length : (Targets.Length * 2)); if (MaxCreatures != -1) { if (SpawnSize > MaxCreatures) { SpawnSize = MaxCreatures; } } int count = 0; for (int i = 0; i < SpawnSize; i++) { Entities.BossCreature creature = (Entities.BossCreature)Creature.Copy(); if (!FixTargets) { Maps.MapPoint Location = boss.Map.CreateAvailableLocation <Entities.BossCreature>(boss.X, boss.Y, 9); creature.SetData(boss, null); creature.Teleport(Location); } else { try { Entities.GameClient Target = Targets[count]; if (!Target.Alive) { continue; } creature.SetData(boss, Target); Maps.MapPoint Location = boss.Map.CreateAvailableLocation <Entities.BossCreature>(Target.X, Target.Y, 9); creature.Teleport(Location); Entities.BossCreature creature2 = (Entities.BossCreature)Creature.Copy(); creature2.SetData(boss, Target); Location = boss.Map.CreateAvailableLocation <Entities.BossCreature>(Target.X, Target.Y, 9); creature2.Teleport(Location); i++; count++; } catch { } } } } #endregion #region MapEffect if (!string.IsNullOrWhiteSpace(MapEffect)) { using (var str = new Packets.StringPacket(new Packets.StringPacker(MapEffect))) { str.Action = Enums.StringAction.MapEffect; str.PositionX = boss.X; str.PositionY = boss.Y; foreach (Entities.GameClient target in Targets) { if (ShowEffectAtPlayers) { str.PositionX = target.X; str.PositionY = target.Y; } target.SendToScreen(str, true, false); } } } #endregion if (!SpreadSkill) { #region SkillAnimation + Power if (RealSkill != -1) { var usespell = new Packets.UseSpellPacket(); usespell.EntityUID = boss.EntityUID; usespell.SpellID = (ushort)RealSkill; usespell.SpellX = boss.X; usespell.SpellY = boss.Y; usespell.SpellLevel = RealSkilllevel; foreach (Entities.GameClient target in Targets) { if (!target.Alive) { continue; } if (PercentTageEffect != -1) { int damage = ((target.HP / 100) * PercentTageEffect); if (damage <= 0) { damage = 1; } usespell.AddTarget(target.EntityUID, (uint)damage); target.HP -= damage; if (target.HP <= 0) { Packets.Interaction.Battle.Combat.Kill(boss, target, (uint)damage); } } else if (DamageEffect > 0) { int damage = ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next(DamageEffect / 2, DamageEffect); usespell.AddTarget(target.EntityUID, (uint)damage); target.HP -= damage; if (target.HP <= 0) { Packets.Interaction.Battle.Combat.Kill(boss, target, (uint)damage); } } else { usespell.AddTarget(target.EntityUID, 0); } } boss.Screen.UpdateScreen(usespell); } else { foreach (Entities.GameClient target in Targets) { if (!target.Alive) { continue; } using (var interact = new Packets.InteractionPacket()) { interact.Action = Enums.InteractAction.Attack; interact.EntityUID = boss.EntityUID; interact.TargetUID = target.EntityUID; interact.UnPacked = true; interact.X = target.X; interact.Y = target.Y; if (PercentTageEffect != -1) { int damage = (target.HP / PercentTageEffect); interact.Data = (uint)damage; target.HP -= damage; if (target.HP <= 0) { Packets.Interaction.Battle.Combat.Kill(boss, target, (uint)damage); } } else if (DamageEffect > 0) { int damage = ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next(DamageEffect / 2, DamageEffect); interact.Data = (uint)damage; target.HP -= damage; if (target.HP <= 0) { Packets.Interaction.Battle.Combat.Kill(boss, target, (uint)damage); } } else { interact.Data = 0; } boss.Screen.UpdateScreen(interact); } } } #endregion #region Freeze if (Freeze) { foreach (Entities.GameClient target in Targets) { if (!target.Alive) { continue; } target.AddStatusEffect1(Enums.Effect1.IceBlock, FreezeTime); } } #endregion #region Paralyze if (Paralyzed) { foreach (Entities.GameClient target in Targets) { if (!target.Alive) { continue; } target.ParalyzeClient(ParalyzeTime); } } #endregion } #region SpreadEffect if (!string.IsNullOrWhiteSpace(SpreadEffect)) { for (int i = 0; i < EffectPos.Length; i++) { using (var str = new Packets.StringPacket(new Packets.StringPacker(SpreadEffect))) { str.Action = Enums.StringAction.MapEffect; str.PositionX = EffectPos[i][0]; str.PositionY = EffectPos[i][1]; foreach (Entities.GameClient target in Targets) { target.Send(str); } } } } #endregion #region SpreadSkill if (SpreadSkill) { for (int i = 0; i < SkillPos.Length; i++) { Core.PortalPoint p = new Core.PortalPoint(boss.Map.MapID, SkillPos[i][0], SkillPos[i][1]); AreaSkills.TryAdd(p, area); uint TaskID = 0; TaskID = ProjectX_V3_Lib.Threading.DelayedTask.StartDelayedTask(() => { Core.PortalPoint p2 = new Core.PortalPoint(boss.Map.MapID, SkillPos[i][0], SkillPos[i][1]); AreaSkill rArea; AreaSkills.TryRemove(p2, out rArea); }, SkillShowTime, 0); } } #endregion }
void Movement(Entities.Monster mob) { if (!mob.Alive) { return; } try { if (mob.Target != null) { if (DateTime.Now >= mob.MoveTime) { try { if (Core.Screen.GetDistance(mob.X, mob.Y, mob.Target.X, mob.Target.Y) >= mob.ViewRange) { byte dir = (byte)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next(0, 8); Maps.MapPoint movepoint = Packets.MovementPacket.CreateDirectionPoint(mob.X, mob.Y, dir); if (mob.Map.ValidMoveCoord <Entities.Monster>(movepoint.X, movepoint.Y)) { mob.X = movepoint.X; mob.Y = movepoint.Y; mob.Direction = dir; using (var movepacket = new Packets.MovementPacket()) { movepacket.EntityUID = mob.EntityUID; movepacket.TimeStamp = ProjectX_V3_Lib.Native.Winmm.timeGetTime(); movepacket.Direction = (uint)dir; movepacket.WalkMode = Enums.WalkMode.Run; mob.Screen.UpdateScreen(movepacket); } mob.MoveTime = DateTime.Now.AddMilliseconds(mob.MoveSpeed * 5); } return; } else { byte dir = (byte)Core.Screen.GetFacing(Core.Screen.GetAngle(mob.X, mob.Y, mob.Target.X, mob.Target.Y)); Maps.MapPoint movepoint = Packets.MovementPacket.CreateDirectionPoint(mob.X, mob.Y, dir); if (mob.Map.ValidMoveCoord <Entities.Monster>(movepoint.X, movepoint.Y)) { mob.X = movepoint.X; mob.Y = movepoint.Y; mob.Direction = dir; using (var movepacket = new Packets.MovementPacket()) { movepacket.EntityUID = mob.EntityUID; movepacket.TimeStamp = ProjectX_V3_Lib.Native.Winmm.timeGetTime(); movepacket.Direction = (uint)dir; movepacket.WalkMode = Enums.WalkMode.Run; mob.Screen.UpdateScreen(movepacket); } } int nextmove = ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next(mob.MoveSpeed, mob.MoveSpeed * 2); mob.MoveTime = DateTime.Now.AddMilliseconds(nextmove); } } catch { } // target was removed again / out of range :s there is a concurrency problem, just cba to look for it as it's nothing major } } } catch (Exception e) { Console.WriteLine(e.ToString()); } }
public void LoadBot(Enums.BotType BotType, int botid, Maps.MapPoint location, Entities.GameClient Opponent) { switch (BotType) { #region afk bot case Enums.BotType.AFKBot: { using (var sql = new SqlHandler(Program.Config.ReadString("GameConnectionString"))) { using (var cmd = new SqlCommandBuilder(sql, SqlCommandType.SELECT, true)) { cmd.AddWhereValue("BotID", botid); cmd.Finish("DB_Bots"); } if (!sql.Read()) { return; } Original.Name = Core.NameGenerator.GetName(); if (string.IsNullOrEmpty(Original.Name) || string.IsNullOrWhiteSpace(Original.Name)) { return; } Original.Avatar = sql.ReadUInt16("BotAvatar"); Original.Model = sql.ReadUInt16("BotModel"); Original.HairStyle = sql.ReadUInt16("BotHairStyle"); Original.Transformation = sql.ReadUInt16("BotTransformation"); Original.Strength = sql.ReadUInt16("BotStrength"); Original.Agility = sql.ReadUInt16("BotAgility"); Original.Vitality = sql.ReadUInt16("BotVitality"); Original.Spirit = sql.ReadUInt16("BotSpirit"); Original.PKPoints = sql.ReadInt16("BotPKPoints"); Original.Level = sql.ReadByte("BotLevel"); Original.Class = (Enums.Class)Enum.Parse(typeof(Enums.Class), sql.ReadString("BotClass")); Original.PlayerTitle = (Enums.PlayerTitle)Enum.Parse(typeof(Enums.PlayerTitle), sql.ReadString("BotTitle")); Original.Reborns = sql.ReadByte("BotReborns"); Maps.Map map = location.Map; Original.Map = map; Original.LastMapID = Original.Map.MapID; Original.X = location.X; Original.Y = location.Y; Original.LastMapX = location.X; Original.LastMapY = location.Y; Original.LastX = location.X; Original.LastY = location.Y; Original.Action = Enums.ActionType.Sit; Original.Direction = (byte)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next(8); uint entityuid = (uint)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next(700000000, 999999999); Original.EntityUID = entityuid; if (!Original.Map.EnterMap(Original)) { return; } uint WeaponR = sql.ReadUInt32("BotWeaponR"); if (WeaponR > 0) { Data.ItemInfo item = Core.Kernel.ItemInfos[WeaponR].Copy(); Original.Equipments.Equip(item, Enums.ItemLocation.WeaponR, false, false); } uint WeaponL = sql.ReadUInt32("BotWeaponL"); if (WeaponL > 0) { Data.ItemInfo item = Core.Kernel.ItemInfos[WeaponL].Copy(); Original.Equipments.Equip(item, Enums.ItemLocation.WeaponL, false, false); } uint Armor = sql.ReadUInt32("BotArmor"); if (Armor > 0) { Data.ItemInfo item = Core.Kernel.ItemInfos[Armor].Copy(); Original.Equipments.Equip(item, Enums.ItemLocation.Armor, false, false); } uint Head = sql.ReadUInt32("BotHead"); if (Head > 0) { Data.ItemInfo item = Core.Kernel.ItemInfos[Head].Copy(); Original.Equipments.Equip(item, Enums.ItemLocation.Head, false, false); } bool UseSteed = sql.ReadBoolean("BotSteed"); if (UseSteed) { uint Steed = sql.ReadUInt32("BotSteedColor"); Data.ItemInfo item = Core.Kernel.ItemInfos[300000].Copy(); item.SocketAndRGB = Steed; Original.Equipments.Equip(item, Enums.ItemLocation.Steed, false, false); uint MountArmor = sql.ReadUInt32("BotMountArmor"); if (MountArmor > 0) { Data.ItemInfo item2 = Core.Kernel.ItemInfos[MountArmor].Copy(); Original.Equipments.Equip(item2, Enums.ItemLocation.SteedArmor, false, false); } Original.Action = Enums.ActionType.None; Original.AddStatusEffect1(Enums.Effect1.Riding); } uint Garment = sql.ReadUInt32("BotGarment"); if (Garment > 0) { Data.ItemInfo item = Core.Kernel.ItemInfos[Garment].Copy(); Original.Equipments.Equip(item, Enums.ItemLocation.Garment, false, false); } Original.LoggedIn = true; } break; } #endregion * #region duel bot case Enums.BotType.DuelBot: { if (Opponent == null) { return; } Original.Name = Core.NameGenerator.GetName(); if (string.IsNullOrEmpty(Original.Name) || string.IsNullOrWhiteSpace(Original.Name)) { return; } Original.Avatar = Opponent.Avatar; Original.Model = Opponent.Model; Original.HairStyle = Opponent.HairStyle; Original.Transformation = 0; Original.Strength = Opponent.Strength; Original.Agility = Opponent.Agility; Original.Vitality = Opponent.Vitality; Original.Spirit = Opponent.Spirit; Original.PKPoints = Opponent.PKPoints; Original.Level = Opponent.Level; Original.Class = Opponent.Class; Original.PlayerTitle = Opponent.PlayerTitle; Original.Reborns = Opponent.Reborns; Maps.Map map = Opponent.Map; Original.Map = map; Original.LastMapID = Original.Map.MapID; Original.X = Opponent.X; Original.Y = Opponent.Y; Original.LastMapX = Opponent.X; Original.LastMapY = Opponent.Y; Original.LastX = Opponent.X; Original.LastY = Opponent.Y; Original.Action = Enums.ActionType.None; Original.Direction = (byte)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next(8); uint entityuid = (uint)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next(700000000, 999999999); Original.EntityUID = entityuid; if (!Original.Map.EnterMap(Original)) { return; } Original.Equipments.ForceEquipments(Opponent.Equipments); Original.BaseEntity.CalculateBaseStats(); Original.HP = Original.MaxHP; Original.MP = Original.MaxMP; /* * uint WeaponR = sql.ReadUInt32("BotWeaponR"); * if (WeaponR > 0) * { * Data.ItemInfo item = Core.Kernel.ItemInfos[WeaponR].Copy(); * Original.Equipments.Equip(item, Enums.ItemLocation.WeaponR, false, false); * } * uint WeaponL = sql.ReadUInt32("BotWeaponL"); * if (WeaponL > 0) * { * Data.ItemInfo item = Core.Kernel.ItemInfos[WeaponL].Copy(); * Original.Equipments.Equip(item, Enums.ItemLocation.WeaponL, false, false); * } * uint Armor = sql.ReadUInt32("BotArmor"); * if (Armor > 0) * { * Data.ItemInfo item = Core.Kernel.ItemInfos[Armor].Copy(); * Original.Equipments.Equip(item, Enums.ItemLocation.Armor, false, false); * } * uint Head = sql.ReadUInt32("BotHead"); * if (Head > 0) * { * Data.ItemInfo item = Core.Kernel.ItemInfos[Head].Copy(); * Original.Equipments.Equip(item, Enums.ItemLocation.Head, false, false); * } * bool UseSteed = sql.ReadBoolean("BotSteed"); * if (UseSteed) * { * uint Steed = sql.ReadUInt32("BotSteedColor"); * Data.ItemInfo item = Core.Kernel.ItemInfos[300000].Copy(); * item.SocketAndRGB = Steed; * Original.Equipments.Equip(item, Enums.ItemLocation.Steed, false, false); * * uint MountArmor = sql.ReadUInt32("BotMountArmor"); * if (MountArmor > 0) * { * Data.ItemInfo item2 = Core.Kernel.ItemInfos[MountArmor].Copy(); * Original.Equipments.Equip(item2, Enums.ItemLocation.SteedArmor, false, false); * } * * Original.Action = Enums.ActionType.None; * Original.AddStatusEffect1(Enums.Effect1.Riding); * } * uint Garment = sql.ReadUInt32("BotGarment"); * if (Garment > 0) * { * Data.ItemInfo item = Core.Kernel.ItemInfos[Garment].Copy(); * Original.Equipments.Equip(item, Enums.ItemLocation.Garment, false, false); * }*/ Original.LoggedIn = true; break; } #endregion * } }