static bool TrainerBuy(LoginClient client, CMSG msgID, BinReader data) { ulong trainerGUID = data.ReadUInt64(); ulong spellId = data.ReadUInt32(); BinWriter trainer = LoginClient.NewPacket(SMSG.TRAINER_BUY_SUCCEEDED); trainer.Write(trainerGUID); trainer.Write(spellId); client.Send(trainer); DataObject[] obj = DataServer.Database.SelectObjects(typeof(DBVendor), "GUID = '" + trainerGUID + "'"); if (obj.Length == 0) { Chat.System(client, "Vendor not found"); return(true); } DBVendor tvendor = (DBVendor)obj[0]; DBTraining tTrain = null; foreach (DBTraining training in tvendor.Trainings) { if (training.SpellID == spellId) { tTrain = training; break; } } if (tTrain == null) { Chat.System("This vendor cannot teach you that spell"); return(true); } // DBSpell targetSpell = (DBSpell)DataServer.Database.FindObjectByKey(typeof(DBSpell), spellId); DBSpell targetSpell = tTrain.Spell; uint teachSpellId = (tTrain.TeachSpellID == 0?0x1ff7:tTrain.TeachSpellID); if (targetSpell == null) { Chat.System(client, "Spell " + spellId + " not found"); return(true); } DBKnownSpell newSpell = new DBKnownSpell(); newSpell.Spell_Id = (uint)spellId; if (client.Character.Spells == null || client.Character.Spells.Length == 0) { newSpell.Slot = 1; } else { newSpell.Slot = (uint)client.Character.Spells.Length + 1; } newSpell.CharacterID = client.Character.ObjectId; try { newSpell.SpellLevel = uint.Parse(targetSpell.Rank); } catch (Exception) {} if (newSpell.SpellLevel == 0) { newSpell.SpellLevel = 1; } DataServer.Database.AddNewObject(newSpell); DataServer.Database.FillObjectRelations(client.Character); DataServer.Database.FillObjectRelations(client.Character.Spells[newSpell.Slot - 1]); try { Chat.System(client, "Spell " + client.Character.Spells[newSpell.Slot - 1].Spell.Name + " added."); } catch (Exception) {} BinWriter trainer2 = LoginClient.NewPacket(SMSG.SPELL_START); trainer2.Write((ulong)trainerGUID); trainer2.Write((ulong)trainerGUID); //trainerGUID); trainer2.Write((uint)teachSpellId); //0x1ff7); // trainer2.Write((UInt16)0); trainer2.Write((ushort)0); trainer2.Write((UInt32)0); trainer2.Write((short)2); trainer2.Write((ulong)client.Character.ObjectId); client.Send(trainer2); BinWriter trainer3 = LoginClient.NewPacket(SMSG.LEARNED_SPELL); trainer3.Write((short)spellId); trainer3.Write((UInt16)0x00); client.Send(trainer3); BinWriter trainer4 = LoginClient.NewPacket(SMSG.SPELL_GO); trainer4.Write((ulong)trainerGUID); trainer4.Write((ulong)client.Character.ObjectId); //trainerGUID); trainer4.Write((uint)teachSpellId); //0x1ff7); //trainer4.Write((UInt32)0); // trainer4.Write((UInt16)0); trainer4.Write((byte)0); trainer4.Write((byte)0x01); trainer4.Write((byte)0x01); trainer4.Write((ulong)client.Character.ObjectId); trainer4.Write((byte)0x00); trainer4.Write((short)2); trainer4.Write((ulong)client.Character.ObjectId); client.Send(trainer4); BinWriter trainer5 = LoginClient.NewPacket(SMSG.SPELLLOGEXECUTE); trainer5.Write((ulong)trainerGUID); trainer5.Write((short)spellId); trainer5.Write((UInt16)0); trainer5.Write((UInt32)0x1); trainer5.Write((UInt32)0x24); trainer5.Write((UInt32)0x1); trainer5.Write((ulong)client.Character.ObjectId); client.Send(trainer5); Chat.System(client, "Debug : successfully bought spell!"); return(true); }
static bool OnvAddTrain(LoginClient client, string input) { if (client.Account.AccessLvl < ACCESSLEVEL.GM) { Chat.System(client, "You do not have access to this command"); return(true); } string[] split = input.Split(' '); if (split.Length < 4) { return(false); } DBTraining item = new DBTraining(); DataObject[] obj = DataServer.Database.SelectObjects(typeof(DBVendor), "GUID='" + client.Character.Selected + "'"); if (obj == null || obj.Length == 0) { Chat.System(client, "Vendor not found"); return(true); } DBVendor vendor = (DBVendor)obj[0]; item.VendorID = vendor.ObjectId; CLASS tmpClass = CLASS.MAGE; try { tmpClass = (CLASS)Enum.Parse(typeof(CLASS), split[1], true); } catch (Exception) { Chat.System(client, "Invalid class"); return(false); } item.Class = (int)tmpClass; item.SpellID = (uint)int.Parse(split[2]); DBSpell spell = (DBSpell)DataServer.Database.FindObjectByKey(typeof(DBSpell), item.SpellID); if (spell == null) { Chat.System(client, "Spell not found for ID " + item.SpellID); item = null; return(false); } item.TeachSpellID = uint.Parse(split[3]); DBSpell trainspell = (DBSpell)DataServer.Database.FindObjectByKey(typeof(DBSpell), item.TeachSpellID); if (trainspell == null) { Chat.System(client, "Spell not found for ID " + item.TeachSpellID); item = null; return(false); } // if (split.Length>3) item.Price = int.Parse(split[4]); // else if (template.BuyPrice>0) // item.Price=template.BuyPrice; // else // item.Price=(int)10; DataServer.Database.AddNewObject(item); DataServer.Database.SaveObject(item); DataServer.Database.FillObjectRelations(vendor); DataServer.Database.FillObjectRelations(item); Chat.System(client, "Added item " + item.Spell.Name + " to vendor " + vendor.Name); return(true); }