コード例 #1
0
        static bool OnLearnSpell(LoginClient client, string input)
        {
            string[] split = input.Split(' ');
            if (split.Length < 2)
            {
                return(false);
            }
            uint    targetSpellId = (uint)uint.Parse(split[1]);
            DBSpell targetSpell   = (DBSpell)DataServer.Database.FindObjectByKey(typeof(DBSpell), targetSpellId);

            if (targetSpell == null)
            {
                Chat.System(client, "Spell " + targetSpellId + " not found"); return(true);
            }
            DBKnownSpell newSpell = new DBKnownSpell();

            newSpell.Spell_Id = targetSpellId;
            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
            {
                if (split.Length > 2)
                {
                    newSpell.SpellLevel = uint.Parse(split[2]);
                }
            }
            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) {}
            return(true);
        }
コード例 #2
0
        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);
        }