public bool ReviveMerc() { if (!GameData.HasMerc && Settings.Instance.ResurrectMercenary()) { Logger.Write("Reviving Merc"); MoveTo(5082, 5080); MoveTo(5060, 5076); NpcEntity qual = GetNpc("Qual-Kehk"); if (qual != null && qual != default(NpcEntity)) { TalkToTrader(qual.Id); } else { LeaveGame(); return(false); } byte[] three = { 0x03, 0x00, 0x00, 0x00 }; SendPacket(0x38, three, BitConverter.GetBytes(qual.Id), GenericHandler.Nulls); Thread.Sleep(300); SendPacket(0x62, BitConverter.GetBytes(qual.Id)); Thread.Sleep(300); SendPacket(0x38, three, BitConverter.GetBytes(qual.Id), GenericHandler.Nulls); Thread.Sleep(300); SendPacket(0x30, GenericHandler.One, BitConverter.GetBytes(qual.Id)); Thread.Sleep(300); MoveTo(5060, 5076); MoveTo(5082, 5080); MoveTo(5081, 5076); } return(true); }
public bool ReviveMerc() { if (!BotGameData.HasMerc) { Console.WriteLine("{0}: [D2GS] Reviving Merc", Account); MoveTo(5082, 5080); MoveTo(5060, 5076); NpcEntity qual = GetNpc("Qual-Kehk"); if (qual != null && qual != default(NpcEntity)) { TalkToTrader(qual.Id); } else { LeaveGame(); return(false); } byte[] three = { 0x03, 0x00, 0x00, 0x00 }; SendPacket(0x38, three, BitConverter.GetBytes(qual.Id), GenericServer.nulls); Thread.Sleep(300); SendPacket(0x62, BitConverter.GetBytes(qual.Id)); Thread.Sleep(300); SendPacket(0x38, three, BitConverter.GetBytes(qual.Id), GenericServer.nulls); Thread.Sleep(300); SendPacket(0x30, GenericServer.one, BitConverter.GetBytes(qual.Id)); Thread.Sleep(300); MoveTo(5060, 5076); MoveTo(5082, 5080); MoveTo(5081, 5076); } return(true); }
public NpcEntity GetNpc(String name) { NpcEntity npc = (from n in m_gameData.Npcs where n.Value.Name == name select n).FirstOrDefault().Value; return(npc); }
public void AddNpc(String name, Char symbol) { NpcEntity npc = GetNpc(name); if (npc != null && npc.Initialized && Math.Abs(npc.Location.X - m_x) < 40 && Math.Abs(npc.Location.Y - m_y) < 40) { m_map[40 + npc.Location.X - m_x, 40 + npc.Location.Y - m_y] = new MapPoint(symbol, ConsoleColor.Green); } }
public bool GetAliveNpc(String name, double range, out NpcEntity output) { var n = (from npc in BotGameData.Npcs where npc.Value.Name == name && npc.Value.Life > 0 && (range == 0 || range > Me.Location.Distance(npc.Value.Location)) select npc).FirstOrDefault(); if (n.Value == null) { output = default(NpcEntity); return(false); } output = n.Value; return(true); }
public bool VisitMalah() { NpcEntity malah = GetNpc("Malah"); if (malah != null && malah != default(NpcEntity)) { TalkToTrader(malah.Id); } else { LeaveGame(); return(false); } if (GetSkillLevel(Skills.Type.book_of_townportal) < 10) { Thread.Sleep(300); SendPacket(0x38, GenericHandler.One, BitConverter.GetBytes(malah.Id), GenericHandler.Nulls); Thread.Sleep(2000); Item n = (from item in GameData.Items where item.Value.action == (uint)Item.Action.add_to_shop && item.Value.type == "tsc" select item).FirstOrDefault().Value; Logger.Write("Buying TPs"); byte[] temp = { 0x02, 0x00, 0x00, 0x00 }; for (int i = 0; i < 9; i++) { SendPacket(0x32, BitConverter.GetBytes(malah.Id), BitConverter.GetBytes(n.Id), GenericHandler.Nulls, temp); Thread.Sleep(200); } Thread.Sleep(500); } if (malah != null && malah != default(NpcEntity)) { SendPacket(0x30, GenericHandler.One, BitConverter.GetBytes(malah.Id)); } else { LeaveGame(); return(false); } Thread.Sleep(300); return(true); }
public bool TalkToTrader(UInt32 id) { BotGameData.TalkedToNpc = false; NpcEntity npc = BotGameData.Npcs[id]; double distance = BotGameData.Me.Location.Distance(npc.Location); //if(debugging) Console.WriteLine("{0}: [D2GS] Attempting to talk to NPC", Account); SendPacket(0x59, GenericServer.one, BitConverter.GetBytes(id), BitConverter.GetBytes((UInt16)BotGameData.Me.Location.X), GenericServer.zero, GenericServer.zero, BitConverter.GetBytes((UInt16)BotGameData.Me.Location.Y), GenericServer.zero, GenericServer.zero); int sleepStep = 200; for (int timeDifference = (int)distance * 120; timeDifference > 0; timeDifference -= sleepStep) { SendPacket(0x04, GenericServer.one, BitConverter.GetBytes(id)); Thread.Sleep(Math.Min(sleepStep, timeDifference)); } SendPacket(0x13, GenericServer.one, BitConverter.GetBytes(id)); Thread.Sleep(200); SendPacket(0x2f, GenericServer.one, BitConverter.GetBytes(id)); int timeoutStep = 100; for (long npc_timeout = 4000; npc_timeout > 0 && !BotGameData.TalkedToNpc; npc_timeout -= timeoutStep) { Thread.Sleep(timeoutStep); } if (!BotGameData.TalkedToNpc) { Console.WriteLine("{0}: [D2GS] Failed to talk to NPC", Account); return(false); } return(true); }
public bool TalkToTrader(UInt32 id) { GameData.TalkedToNpc = false; NpcEntity npc = GameData.Npcs[id]; double distance = GameData.Me.Location.Distance(npc.Location); //if(debugging) Logger.Write("Attempting to talk to NPC"); SendPacket(Actions.MakeEntityMove(id, GameData.Me.Location)); int sleepStep = 200; for (int timeDifference = (int)distance * 120; timeDifference > 0; timeDifference -= sleepStep) { SendPacket(0x04, GenericHandler.One, BitConverter.GetBytes(id)); Thread.Sleep(Math.Min(sleepStep, timeDifference)); } SendPacket(0x13, GenericHandler.One, BitConverter.GetBytes(id)); Thread.Sleep(200); SendPacket(0x2f, GenericHandler.One, BitConverter.GetBytes(id)); int timeoutStep = 100; for (long npcTimeout = 4000; npcTimeout > 0 && !GameData.TalkedToNpc; npcTimeout -= timeoutStep) { Thread.Sleep(timeoutStep); } if (!GameData.TalkedToNpc) { Logger.Write("Failed to talk to NPC"); return(false); } return(true); }
protected void NpcAssignment(byte type, List<byte> data) { byte[] packet = data.ToArray(); NpcEntity output; //try //{ BitReader br = new BitReader(data.ToArray()); br.ReadBitsLittleEndian(8); UInt32 id = (uint)br.Read(32); UInt16 npctype = (ushort)br.Read(16); UInt16 x = (ushort)br.Read(16); UInt16 y = (ushort)br.Read(16); byte life = (byte)br.Read(8); byte size = (byte)br.Read(8); output = new NpcEntity(id, npctype, life, x, y); if(ClientlessBot.debugging) Console.WriteLine("NPC id: {3}, Type: {0:X}, Life: {1:X}, Size: {2:X}", npctype, life, data.Count, id); int informationLength = 16; String[] entries; if (!m_owner.m_dm.m_monsterFields.Get(npctype, out entries)) Console.WriteLine("Failed to read monstats data for NPC of type {0}", type); if(entries.Length != informationLength) Console.WriteLine("Invalid monstats entry for NPC of type {0}", type); bool lookupName = false; if (data.Count > 0x10) { br.Read(4); if (br.ReadBit()) { for (int i = 0; i < informationLength; i++) { int temp; int value = Int32.Parse(entries[i]); if (!BitScanReverse(out temp, (uint)value - 1)) temp = 0; if (temp == 31) temp = 0; //Console.WriteLine("BSR: {0} Bitcount: {1}", temp+1, bitCount); int bits = br.Read(temp+1); } } output.SuperUnique = false; output.HasFlags = br.ReadBit(); if (output.HasFlags) { output.Champion = br.ReadBit(); output.Unique = br.ReadBit(); output.SuperUnique = br.ReadBit(); output.IsMinion = br.ReadBit(); output.Ghostly = br.ReadBit(); //Console.WriteLine("{0} {1} {2} {3} {4}", output.Champion, output.Unique, output.SuperUnique, output.IsMinion, output.Ghostly); } if (output.SuperUnique) { output.SuperUniqueId = br.ReadBitsLittleEndian(16); String name; if (!m_owner.m_dm.m_superUniques.Get(output.SuperUniqueId, out name)) { Console.WriteLine("Failed to lookup super unique monster name for {0}", output.SuperUniqueId); output.Name = "invalid"; } else { output.Name = name; //Console.WriteLine("NPC: {0}", name); } } else lookupName = true; if (data.Count > 17 && lookupName != true && output.Name != "invalid") { output.IsLightning = false; while (true) { byte mod = (byte)br.ReadBitsLittleEndian(8); if (mod == 0) break; if (mod == 0x11) output.IsLightning = true; } } } else lookupName = true; if (lookupName) { String name; if (!m_owner.m_dm.m_monsterNames.Get((int)output.Type, out name)) Console.WriteLine("Failed to Look up monster name for {0}", output.Type); else output.Name = name; //Console.WriteLine("NPC: {0}", name); } NpcEntity tempnpc; if (m_owner.BotGameData.Npcs.TryGetValue(id, out tempnpc)) m_owner.BotGameData.Npcs[id] = output; else m_owner.BotGameData.Npcs.Add(id, output); // } // catch // { // } }
public bool GetAliveNpc(String name, double range, out NpcEntity output) { var n = (from npc in BotGameData.Npcs where npc.Value.Name == name && npc.Value.Life > 0 && (range == 0 || range > Me.Location.Distance(npc.Value.Location)) select npc).FirstOrDefault(); if (n.Value == null) { output = default(NpcEntity); return false; } output = n.Value; return true; }
public void DoPindle() { UInt32 curLife = 0; MoveTo(5089, 5019); MoveTo(5090, 5030); MoveTo(5082, 5033); MoveTo(5074, 5033); if (!VisitMalah()) { return; } MoveTo(5073, 5032); MoveTo(5073, 5044); MoveTo(5078, 5055); MoveTo(5081, 5065); MoveTo(5081, 5076); if (!ReviveMerc()) { return; } MoveTo(5082, 5087); MoveTo(5085, 5098); MoveTo(5088, 5110); MoveTo(5093, 5121); MoveTo(5103, 5124); MoveTo(5111, 5121); EnterRedPortal(); //Status = ClientStatus.STATUS_KILLING_PINDLESKIN; Logger.Write("Killing Pindleskin"); //Precast(); //teleport... //SwitchSkill((uint)Skills.Type.teleport); //Thread.Sleep(300); MoveTo(10064, 13268); Thread.Sleep(500); MoveTo(10061, 13260); Thread.Sleep(500); MoveTo(10058, 13236); Thread.Sleep(500); //SendPacket(Actions.CastOnCoord(10064, 13286)); //Thread.Sleep(300); //SendPacket(Actions.CastOnCoord(10061, 13260)); //Thread.Sleep(300); //SendPacket(Actions.CastOnCoord(10058, 13236)); //Thread.Sleep(300); NpcEntity pindle = GetNpc("Pindleskin"); if (pindle == default(NpcEntity)) { Thread.Sleep(500); pindle = GetNpc("Pindleskin"); if (pindle == default(NpcEntity)) { Logger.Write("Unable to find Pindleskin, probably got stuck."); LeaveGame(); return; } } curLife = GameData.Npcs[pindle.Id].Life; if (GameData.Npcs[pindle.Id].IsLightning && GameData.CharacterSkillSetup == GameData.CharacterSkillSetupType.SORCERESS_LIGHTNING) { LeaveGame(); return; } while (GameData.Npcs[pindle.Id].Life > 0 && _d2gsConnection.Socket.Connected) { if (!Attack(pindle.Id)) { LeaveGame(); return; } if (curLife > GameData.Npcs[pindle.Id].Life) { curLife = GameData.Npcs[pindle.Id].Life; //Console.WriteLine("{0}: [D2GS] Pindleskins Life: {1}", Account, curLife); } } Logger.Write("{0} is dead. Killing minions", pindle.Name); NpcEntity monster; while (GetAliveNpc("Defiled Warrior", 20, out monster) && _d2gsConnection.Socket.Connected) { curLife = GameData.Npcs[monster.Id].Life; Logger.Write("Killing Defiled Warrior"); while (GameData.Npcs[monster.Id].Life > 0 && _d2gsConnection.Socket.Connected) { if (!Attack(monster.Id)) { LeaveGame(); return; } if (curLife > GameData.Npcs[monster.Id].Life) { curLife = GameData.Npcs[monster.Id].Life; //Console.WriteLine("{0}: [D2GS] Defiled Warriors Life: {1}", Account, curLife); } } } Logger.Write("Minions are dead, looting..."); PickItems(); //if (!TownPortal()) //{ //LeaveGame(); //return; //} }
public NpcEntity GetNpc(String name) { NpcEntity npc = GameData.Npcs.FirstOrDefault(n => n.Value.Name == name).Value; return(npc); }
public void DoPindle() { UInt32 curLife = 0; if (Pindle) { MoveTo(5089, 5019); MoveTo(5090, 5030); MoveTo(5082, 5033); MoveTo(5074, 5033); if (!VisitMalah()) { return; } MoveTo(5073, 5032); MoveTo(5073, 5044); MoveTo(5078, 5055); MoveTo(5081, 5065); MoveTo(5081, 5076); if (!ReviveMerc()) { return; } MoveTo(5082, 5087); MoveTo(5085, 5098); MoveTo(5088, 5110); MoveTo(5093, 5121); MoveTo(5103, 5124); MoveTo(5111, 5121); EnterRedPortal(); Status = ClientStatus.STATUS_KILLING_PINDLESKIN; Console.WriteLine("{0}: [D2GS] Killing Pindleskin", Account); Precast(); SwitchSkill(0x36); Thread.Sleep(300); CastOnCoord(10064, 13286); Thread.Sleep(300); CastOnCoord(10061, 13260); Thread.Sleep(300); CastOnCoord(10058, 13236); Thread.Sleep(300); if (ClientlessBot.debugging) { Console.WriteLine("Current Position: ({0},{1})", Me.Location.X, Me.Location.Y); } NpcEntity pindle = GetNpc("Pindleskin"); if (pindle == default(NpcEntity)) { Thread.Sleep(500); pindle = GetNpc("Pindleskin"); if (pindle == default(NpcEntity)) { Console.WriteLine("{0}: [D2GS] Unable to find Pindleskin, probably got stuck.", Account); LeaveGame(); return; } } curLife = BotGameData.Npcs[pindle.Id].Life; if (BotGameData.Npcs[pindle.Id].IsLightning && BotGameData.CharacterSkillSetup == GameData.CharacterSkillSetupType.SORCERESS_LIGHTNING && Difficulty == GameDifficulty.HELL) { LeaveGame(); return; } while (BotGameData.Npcs[pindle.Id].Life > 0 && m_gs.m_socket.Connected) { if (!Attack(pindle.Id)) { LeaveGame(); return; } if (curLife > BotGameData.Npcs[pindle.Id].Life) { curLife = BotGameData.Npcs[pindle.Id].Life; //Console.WriteLine("{0}: [D2GS] Pindleskins Life: {1}", Account, curLife); } } Console.WriteLine("{0}: [D2GS] {1} is dead. Killing minions", Account, pindle.Name); NpcEntity monster; while (GetAliveNpc("Defiled Warrior", 20, out monster) && m_gs.m_socket.Connected) { curLife = BotGameData.Npcs[monster.Id].Life; Console.WriteLine("{0}: [D2GS] Killing Defiled Warrior", Account); while (BotGameData.Npcs[monster.Id].Life > 0 && m_gs.m_socket.Connected) { if (!Attack(monster.Id)) { LeaveGame(); return; } if (curLife > BotGameData.Npcs[monster.Id].Life) { curLife = BotGameData.Npcs[monster.Id].Life; //Console.WriteLine("{0}: [D2GS] Defiled Warriors Life: {1}", Account, curLife); } } } Console.WriteLine("{0}: [D2GS] Minions are dead, looting...", Account); PickItems(); //if (!TownPortal()) //{ //LeaveGame(); //return; //} } }
protected void NpcAssignment(byte type, List <byte> data) { byte[] packet = data.ToArray(); NpcEntity output; //try //{ BitReader br = new BitReader(data.ToArray()); br.ReadBitsLittleEndian(8); UInt32 id = (uint)br.Read(32); UInt16 npctype = (ushort)br.Read(16); UInt16 x = (ushort)br.Read(16); UInt16 y = (ushort)br.Read(16); byte life = (byte)br.Read(8); byte size = (byte)br.Read(8); output = new NpcEntity(id, npctype, life, x, y); if (ClientlessBot.debugging) { Console.WriteLine("NPC id: {3}, Type: {0:X}, Life: {1:X}, Size: {2:X}", npctype, life, data.Count, id); } int informationLength = 16; String[] entries; if (!m_owner.m_dm.m_monsterFields.Get(npctype, out entries)) { Console.WriteLine("Failed to read monstats data for NPC of type {0}", type); } if (entries.Length != informationLength) { Console.WriteLine("Invalid monstats entry for NPC of type {0}", type); } bool lookupName = false; if (data.Count > 0x10) { br.Read(4); if (br.ReadBit()) { for (int i = 0; i < informationLength; i++) { int temp; int value = Int32.Parse(entries[i]); if (!BitScanReverse(out temp, (uint)value - 1)) { temp = 0; } if (temp == 31) { temp = 0; } //Console.WriteLine("BSR: {0} Bitcount: {1}", temp+1, bitCount); int bits = br.Read(temp + 1); } } output.SuperUnique = false; output.HasFlags = br.ReadBit(); if (output.HasFlags) { output.Champion = br.ReadBit(); output.Unique = br.ReadBit(); output.SuperUnique = br.ReadBit(); output.IsMinion = br.ReadBit(); output.Ghostly = br.ReadBit(); //Console.WriteLine("{0} {1} {2} {3} {4}", output.Champion, output.Unique, output.SuperUnique, output.IsMinion, output.Ghostly); } if (output.SuperUnique) { output.SuperUniqueId = br.ReadBitsLittleEndian(16); String name; if (!m_owner.m_dm.m_superUniques.Get(output.SuperUniqueId, out name)) { Console.WriteLine("Failed to lookup super unique monster name for {0}", output.SuperUniqueId); output.Name = "invalid"; } else { output.Name = name; //Console.WriteLine("NPC: {0}", name); } } else { lookupName = true; } if (data.Count > 17 && lookupName != true && output.Name != "invalid") { output.IsLightning = false; while (true) { byte mod = (byte)br.ReadBitsLittleEndian(8); if (mod == 0) { break; } if (mod == 0x11) { output.IsLightning = true; } } } } else { lookupName = true; } if (lookupName) { String name; if (!m_owner.m_dm.m_monsterNames.Get((int)output.Type, out name)) { Console.WriteLine("Failed to Look up monster name for {0}", output.Type); } else { output.Name = name; } //Console.WriteLine("NPC: {0}", name); } NpcEntity tempnpc; if (m_owner.BotGameData.Npcs.TryGetValue(id, out tempnpc)) { m_owner.BotGameData.Npcs[id] = output; } else { m_owner.BotGameData.Npcs.Add(id, output); } // } // catch // { // } }