コード例 #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("-------------------------------------------------------");
            Console.WriteLine(" <Silkroad Gameserver>  Copyright (C) <2011>  <DarkEmu>");
            Console.WriteLine("-------------------------------------------------------");
            Console.WriteLine("Loading essentiel data and connecting to database.\nThis could take some minutes!");
            Database.Connect(Settings.ReadSettings("Settings.txt"));

            Database.CheckTables(new string[] { "mastery", "user", "characters", "skills", "items" });

            DatabaseCore.SetPulseTime(5000);
            DatabaseCore.SetPulseFlag(false);
            DatabaseCore.SetQueryLocation("tmpQueryGameServer.txt");
            DatabaseCore.Start();

            Console.WriteLine("Data from database loaded, Changes on the database wont effect the server now!");

            Timers.LoadTimers();
            Silkroad.DumpObjects();

            ServerSocket server = new ServerSocket("127.0.0.1", 15780);

            server.Start();

            Console.WriteLine("Use 'help' to get all commands.");
            while (exit == false)
            {
                Commands(Console.ReadLine());
            }
        }
コード例 #2
0
ファイル: Items.cs プロジェクト: Pascal1000/server1
        public static void MoveItemToDatabase(int CharacterItemIndexSource, int CharacterItemIndexDestination, string CharacterName)
        {
            uint tmpItemId     = DatabaseCore.Item.ItemId[CharacterItemIndexSource];
            byte tmpType       = DatabaseCore.Item.Type[CharacterItemIndexSource];
            byte tmpQuantity   = DatabaseCore.Item.Quantity[CharacterItemIndexSource];
            byte tmpDurability = DatabaseCore.Item.Durability[CharacterItemIndexSource];
            byte tmpBlueAmount = DatabaseCore.Item.BlueAmount[CharacterItemIndexSource];

            DatabaseCore.Item_.Blue_ tmpBlue = DatabaseCore.Item.Blue[CharacterItemIndexSource];

            DatabaseCore.Item.ItemId[CharacterItemIndexSource]     = DatabaseCore.Item.ItemId[CharacterItemIndexDestination];
            DatabaseCore.Item.Type[CharacterItemIndexSource]       = DatabaseCore.Item.Type[CharacterItemIndexDestination];
            DatabaseCore.Item.Quantity[CharacterItemIndexSource]   = DatabaseCore.Item.Quantity[CharacterItemIndexDestination];
            DatabaseCore.Item.Durability[CharacterItemIndexSource] = DatabaseCore.Item.Durability[CharacterItemIndexDestination];
            DatabaseCore.Item.BlueAmount[CharacterItemIndexSource] = DatabaseCore.Item.BlueAmount[CharacterItemIndexDestination];
            DatabaseCore.Item.Blue[CharacterItemIndexSource]       = DatabaseCore.Item.Blue[CharacterItemIndexDestination];

            DatabaseCore.Item.ItemId[CharacterItemIndexDestination]     = tmpItemId;
            DatabaseCore.Item.Type[CharacterItemIndexDestination]       = tmpType;
            DatabaseCore.Item.Quantity[CharacterItemIndexDestination]   = tmpQuantity;
            DatabaseCore.Item.Durability[CharacterItemIndexDestination] = tmpDurability;
            DatabaseCore.Item.BlueAmount[CharacterItemIndexDestination] = tmpBlueAmount;
            DatabaseCore.Item.Blue[CharacterItemIndexDestination]       = tmpBlue;

            DatabaseCore.WriteQuery("UPDATE items SET itemid='{0}',type='{1}',quantity='{2}',durability='{3}',BlueAmount='{4}' WHERE slot='{5}' AND owner='{6}'", DatabaseCore.Item.ItemId[CharacterItemIndexDestination], DatabaseCore.Item.Type[CharacterItemIndexDestination], DatabaseCore.Item.Quantity[CharacterItemIndexDestination], DatabaseCore.Item.Durability[CharacterItemIndexDestination], DatabaseCore.Item.BlueAmount[CharacterItemIndexDestination], DatabaseCore.Item.Slot[CharacterItemIndexDestination], CharacterName);
            DatabaseCore.WriteQuery("UPDATE items SET itemid='{0}',type='{1}',quantity='{2}',durability='{3}',BlueAmount='{4}' WHERE slot='{5}' AND owner='{6}'", DatabaseCore.Item.ItemId[CharacterItemIndexSource], DatabaseCore.Item.Type[CharacterItemIndexSource], DatabaseCore.Item.Quantity[CharacterItemIndexSource], DatabaseCore.Item.Durability[CharacterItemIndexSource], DatabaseCore.Item.BlueAmount[CharacterItemIndexSource], DatabaseCore.Item.Slot[CharacterItemIndexSource], CharacterName);

            for (uint j = 1; j < 9; j++)
            {
                DatabaseCore.WriteQuery("UPDATE items SET blue{0}='{1}',blue{0}amount='{2}' WHERE slot='{3}' AND owner='{4}'", j, DatabaseCore.Item.Blue[CharacterItemIndexDestination].BlueAmount[j], DatabaseCore.Item.Blue[CharacterItemIndexDestination].Blue[j], DatabaseCore.Item.Slot[CharacterItemIndexDestination], CharacterName);
                DatabaseCore.WriteQuery("UPDATE items SET blue{0}='{1}',blue{0}amount='{2}' WHERE slot='{3}' AND owner='{4}'", j, DatabaseCore.Item.Blue[CharacterItemIndexSource].BlueAmount[j], DatabaseCore.Item.Blue[CharacterItemIndexSource].Blue[j], DatabaseCore.Item.Slot[CharacterItemIndexSource], CharacterName);
            }
        }
コード例 #3
0
        public static void OnSkillUpdate(PacketReader reader_, int Index_)
        {
            int CharacterSkillIndex = DatabaseCore.Skill.GetIndexByName(Player.General[Index_].CharacterName);

            uint SkillId = reader_.ReadDword();

            Silkroad.Skill_ NewSkill = Silkroad.GetSkillById(SkillId);
            if (Player.Stats[Index_].Skillpoints >= NewSkill.RequiredSp)
            {
                writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_SKILLUPDATE);
                writer.AppendByte(1);
                writer.AppendDword(SkillId);
                ServerSocket.Send(writer.getWorkspace(), Index_);

                DatabaseCore.Skill.SkillAmount[CharacterSkillIndex]++;
                for (int i = 1; i <= DatabaseCore.Skill.SkillAmount[CharacterSkillIndex]; i++)
                {
                    if (DatabaseCore.Skill.Skills[CharacterSkillIndex].SkillId[i] == SkillId - 1)
                    {
                        DatabaseCore.WriteQuery("UPDATE skills SET Skill{0}='{1}' WHERE Skill{0}='{2}' AND owner='{3}'", i, SkillId, DatabaseCore.Skill.Skills[CharacterSkillIndex].SkillId[i], Player.General[Index_].CharacterName);
                        DatabaseCore.Skill.Skills[CharacterSkillIndex].SkillId[i + 1] = SkillId;
                    }
                }
                DatabaseCore.WriteQuery("UPDATE skills SET Skill{0}='{1}' WHERE owner='{2}'", DatabaseCore.Skill.SkillAmount[CharacterSkillIndex], SkillId, Player.General[Index_].CharacterName);
                DatabaseCore.WriteQuery("UPDATE skills SET AmountSkill='{0}' WHERE owner='{1}'", DatabaseCore.Skill.SkillAmount[CharacterSkillIndex], Player.General[Index_].CharacterName);

                DatabaseCore.Skill.Skills[CharacterSkillIndex].SkillId[DatabaseCore.Skill.SkillAmount[CharacterSkillIndex] - 1] = SkillId;

                Player.Stats[Index_].Skillpoints -= (uint)NewSkill.RequiredSp;
                SPUpdate(Index_);
            }
        }
コード例 #4
0
        public static void OnMasteryUpdate(PacketReader reader_, int Index_)
        {
            uint mastery = reader_.ReadDword();

            int[] CharacterMasteryIndex = DatabaseCore.Mastery.GetIndexByName(Player.General[Index_].CharacterName, Player.Stats[Index_].Model >= 14717);

            byte CurrentMasteryIndex = 0;

            for (byte i = 0; i < CharacterMasteryIndex.Length; i++)
            {
                if (DatabaseCore.Mastery.MasteryId[CharacterMasteryIndex[i]] == mastery)
                {
                    CurrentMasteryIndex = i;
                }
            }
            ulong sp_required = Silkroad.GetLevelDataByLevel(DatabaseCore.Mastery.MasteryLevel[CharacterMasteryIndex[CurrentMasteryIndex]]).Skillpoints;

            if (Player.Stats[Index_].Skillpoints >= sp_required)
            {
                DatabaseCore.Mastery.MasteryLevel[CharacterMasteryIndex[CurrentMasteryIndex]]++;
                Player.Stats[Index_].Skillpoints -= (uint)sp_required;
                SPUpdate(Index_);

                writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_MASTERYUPDATE);
                writer.AppendByte(1);
                writer.AppendDword(mastery);
                writer.AppendByte(DatabaseCore.Mastery.MasteryLevel[CharacterMasteryIndex[CurrentMasteryIndex]]);
                ServerSocket.Send(writer.getWorkspace(), Index_);

                DatabaseCore.WriteQuery("UPDATE mastery SET level='{0}' WHERE mastery='{1}' AND owner='{2}'", DatabaseCore.Mastery.MasteryLevel[CharacterMasteryIndex[CurrentMasteryIndex]], mastery, Player.General[Index_].CharacterName);
            }
        }
コード例 #5
0
        public static void SPUpdate(int Index_)
        {
            PacketWriter writer = new PacketWriter();

            writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_SKILLPOINTS);
            writer.AppendByte(2);
            writer.AppendDword(Player.Stats[Index_].Skillpoints);
            writer.AppendByte(0);
            ServerSocket.Send(writer.getWorkspace(), Index_);
            DatabaseCore.WriteQuery("UPDATE characters SET sp='{0}' WHERE name='{1}'", Player.Stats[Index_].Skillpoints, Player.General[Index_].CharacterName);
        }
コード例 #6
0
ファイル: Stats.cs プロジェクト: Pascal1000/server1
        public static void GetBerserk(int Index_, int ObjectIndex)
        {
            if (random.Next(0, 10) > 7 && Player.Stats[Index_].BerserkBar != 5)
            {
                Player.Stats[Index_].BerserkBar++;

                writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_SKILLPOINTS);
                writer.AppendByte(4);
                writer.AppendByte(Player.Flags[Index_].Berserk);
                writer.AppendDword(Monsters.General[ObjectIndex].UniqueID);
                ServerSocket.Send(writer.getWorkspace(), Index_);
                DatabaseCore.WriteQuery("UPDATE characters SET berserkbar='{0}' WHERE name='{1}'", Player.Flags[Index_].Berserk, Player.General[Index_].CharacterName);
            }
        }
コード例 #7
0
ファイル: Movement.cs プロジェクト: Pascal1000/server1
        public static bool MoveToObject(int Index_, ref _Position obj_1, _Position obj_2, uint uniqueid, uint characterid, double weapondistance, byte weapontype, bool Monster)
        {
            double distance_x = obj_1.X - obj_2.X;
            double distance_y = obj_1.Y - obj_2.Y;
            double distance   = Formula.CalculateDistance(distance_x, distance_y);

            if (weapontype == 6 || weapontype == 12)
            {
                weapondistance = 250;
                distance_y    -= 100;
                distance_x    -= 150;
            }

            if (distance > weapondistance)
            {
                distance_x = (distance_x - ((distance_x * 10) / distance));
                distance_y = (distance_y - ((distance_y * 10) / distance));

                obj_1.X -= (float)distance_x;
                obj_1.Y -= (float)distance_y;

                writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_MOVEMENT);
                writer.AppendDword(uniqueid);
                writer.AppendByte(1);
                writer.AppendByte(obj_1.XSector);
                writer.AppendByte(obj_1.YSector);
                writer.AppendWord((ushort)obj_1.X);
                writer.AppendWord((ushort)obj_1.Z);
                writer.AppendWord((ushort)obj_1.Y);
                writer.AppendByte(0);
                if (Monster)
                {
                    ServerSocket.SendPacketIfMonsterIsSpawned(writer.getWorkspace(), Index_);
                }
                else
                {
                    ServerSocket.SendPacketIfPlayerIsSpawned(writer.getWorkspace(), Index_);
                }

                if (characterid != 0)
                {
                    DatabaseCore.WriteQuery("UPDATE characters SET xpos='{0}',ypos='{1}' WHERE id='{2}'", (int)obj_1.X, (int)obj_2.Y, characterid);
                }

                return(false);
            }
            return(true);
        }
コード例 #8
0
ファイル: Items.cs プロジェクト: Pascal1000/server1
        public static void CreateItem(PacketReader reader_, int Index_)
        {
            int[] CharacterItemIndex = DatabaseCore.Item.GetIndexByName(Player.General[Index_].CharacterName);

            byte freeslot = FreeSlot(CharacterItemIndex);

            uint itemid   = reader_.ReadDword();
            byte itemplus = reader_.ReadByte();

            Silkroad.Item_ DestinationItem_ = Silkroad.GetItemById(itemid);

            if (DestinationItem_.ITEM_TYPE_NAME.Contains("ITEM_ETC_GOLD_"))
            {
                freeslot = 254;
            }

            PacketWriter writer = new PacketWriter();

            writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ITEM_MOVEMENT);
            writer.AppendWord(0x601);
            writer.AppendByte(freeslot);
            if (freeslot != 254)
            {
                writer.AppendDword(itemid);
            }
            if (DestinationItem_.ITEM_TYPE_NAME.Contains("CH") || DestinationItem_.ITEM_TYPE_NAME.Contains("EU"))
            {
                writer.AppendByte(itemplus);
                writer.AppendLword(0);
                writer.AppendDword((uint)DestinationItem_.MIN_DURA);
                writer.AppendByte(0);

                DatabaseCore.WriteQuery("UPDATE items SET itemid='{0}',plusvalue='{1}',type='0',durability='{2}' WHERE itemnumber='item{3}' AND owner ='{4}'", itemid, itemplus, DestinationItem_.MIN_DURA, freeslot, Player.General[Index_].CharacterName);
                AddItemToDatabase(CharacterItemIndex[freeslot], itemid, 0, 0, (byte)DestinationItem_.MIN_DURA, itemplus, 0);
            }
            else if (DestinationItem_.ITEM_TYPE_NAME.Contains("ETC"))
            {
                if (freeslot != 254)
                {
                    writer.AppendWord(itemplus);
                    DatabaseCore.WriteQuery("UPDATE items SET itemid='{0}',plusvalue='0',type='1',durability='{1}',quantity='{2}' WHERE itemnumber='item{3}' AND owner ='{4}'", itemid, DestinationItem_.MIN_DURA, itemplus, freeslot, Player.General[Index_].CharacterName);
                    AddItemToDatabase(CharacterItemIndex[freeslot], itemid, 1, itemplus, (byte)DestinationItem_.MIN_DURA, 0, 0);
                }
            }

            ServerSocket.Send(writer.getWorkspace(), Index_);
        }
コード例 #9
0
ファイル: Stats.cs プロジェクト: Pascal1000/server1
        public static void OnStatPacket(int Index_)
        {
            writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_STATS);
            writer.AppendDword(Player.Stats[Index_].MinPhy);
            writer.AppendDword(Player.Stats[Index_].MaxPhy);
            writer.AppendDword(Player.Stats[Index_].MinMag);
            writer.AppendDword(Player.Stats[Index_].MaxMag);
            writer.AppendWord(Player.Stats[Index_].PhyDef);
            writer.AppendWord(Player.Stats[Index_].MagDef);
            writer.AppendWord(Player.Stats[Index_].Hit);
            writer.AppendWord(Player.Stats[Index_].Parry);
            writer.AppendDword(Player.Stats[Index_].HP);
            writer.AppendDword(Player.Stats[Index_].MP);
            writer.AppendWord(Player.Stats[Index_].Strength);
            writer.AppendWord(Player.Stats[Index_].Intelligence);
            ServerSocket.Send(writer.getWorkspace(), Index_);

            DatabaseCore.WriteQuery(
                "UPDATE characters SET min_phyatk='{0}', max_phyatk='{1}', min_magatk='{2}', max_magatk='{3}', phydef='{4}', magdef='{5}', hit='{6}', parry='{7}', hp='{8}', mp='{9}', strength='{10}', intelligence='{11}', attribute='{12}' WHERE id='{13}'", Player.Stats[Index_].MinPhy, Player.Stats[Index_].MaxPhy, Player.Stats[Index_].MinMag, Player.Stats[Index_].MaxMag, Player.Stats[Index_].PhyDef, Player.Stats[Index_].MagDef, Player.Stats[Index_].Hit, Player.Stats[Index_].Parry, Player.Stats[Index_].HP, Player.Stats[Index_].MP, Player.Stats[Index_].Strength, Player.Stats[Index_].Intelligence, Player.Stats[Index_].Attributes, Player.General[Index_].CharacterID);
        }
コード例 #10
0
        private static void BanPlayer(PacketReader reader_, int Index_)
        {
            ushort charlen = reader_.ReadWord();

            string name = reader_.ReadString(false, charlen);

            bool banned = false;

            for (int i = 0; i <= Player.PlayersOnline; i++)
            {
                if (name == Player.General[i].CharacterName && Index_ != i)
                {
                    ServerSocket.DisconnectSocket(i);
                    DatabaseCore.WriteQuery("UPDATE user SET banned='1' WHERE name='{0}'", Player.General[i].User);
                    banned = true;
                }
            }

            if (!banned)
            {
                DatabaseCore.WriteQuery("UPDATE user SET banned='1' WHERE name='{0}'", name);
            }
        }
コード例 #11
0
ファイル: Stats.cs プロジェクト: Pascal1000/server1
        public static void GetXP(int Index_, int ObjectIndex)
        {
            int xprate = 2, sprate = 2, goldrate = 2;

            Silkroad.Gold_ tmpGold = Silkroad.GetGoldDataByLevel(Monsters.General[ObjectIndex].Level);
            ulong          sp      = (ulong)random.Next(tmpGold.Skillpoints, tmpGold.Skillpoints + 25);
            ulong          exp     = Monsters.General[ObjectIndex].Exp;

            if (Player.Stats[Index_].Level < Monsters.General[ObjectIndex].Level)
            {
                exp = ((ulong)(Monsters.General[ObjectIndex].Level - Player.Stats[Index_].Level) * Monsters.General[ObjectIndex].Exp) * (ulong)xprate;
            }
            if (Player.Stats[Index_].Level > Monsters.General[ObjectIndex].Level)
            {
                exp = ((ulong)(Player.Stats[Index_].Level - Monsters.General[ObjectIndex].Level) / Monsters.General[ObjectIndex].Exp) * (ulong)xprate;
                if (exp == 0)
                {
                    exp = 1;
                }
            }
            if (Player.Stats[Index_].Level == Monsters.General[ObjectIndex].Level)
            {
                exp = (Monsters.General[ObjectIndex].Exp * (ulong)xprate);
            }

            sp *= (ulong)sprate;

            writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_EXP);
            writer.AppendDword(Monsters.General[ObjectIndex].UniqueID);
            writer.AppendLword(exp);
            writer.AppendLword(sp);
            writer.AppendByte(0);
            if (CheckIfNewLevel(Index_, exp))
            {
                writer.AppendWord(Player.Stats[Index_].Attributes);
                ServerSocket.Send(writer.getWorkspace(), Index_);

                writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ANIMATION_LEVEL_UP);
                writer.AppendDword(Player.General[Index_].UniqueID);

                ServerSocket.SendPacketIfPlayerIsSpawned(writer.getWorkspace(), Index_);

                Formula.CalculateHP(Index_);
                Formula.CalculateMP(Index_);
                STRUpdate(Index_);
                INTUpdate(Index_);
            }
            else
            {
                ServerSocket.Send(writer.getWorkspace(), Index_);
            }

            CheckIfNewSp(Index_, sp);

            HPUpdate(Index_, false);
            MPUpdate(Index_, false);
            OnStatPacket(Index_);

            DatabaseCore.WriteQuery("UPDATE characters SET experience='{0}',level = '{1}',sp = '{2}',skillpointbar = '{3}' WHERE name='{4}'", Player.Stats[Index_].Experience, Player.Stats[Index_].Level, Player.Stats[Index_].Skillpoints, Player.Stats[Index_].SkillpointBar, Player.General[Index_].CharacterName);
            uint goldamount = (uint)(tmpGold.Gold * goldrate);

            int ItemIndex = Item.ItemAmount;

            if (goldamount < 10000)
            {
                Item.General[ItemIndex].Pk2ID = 1;
            }
            else if (goldamount >= 10000 && goldamount <= 500000)
            {
                Item.General[ItemIndex].Pk2ID = 2;
            }
            else if (goldamount >= 500001)
            {
                Item.General[ItemIndex].Pk2ID = 3;
            }

            Item.General[ItemIndex].UniqueID   = (uint)random.Next(76000000, 79999999);
            Item.General[ItemIndex].Plus       = 0;
            Item.General[ItemIndex].Durability = 0;
            Item.General[ItemIndex].Pickable   = true;
            Item.General[ItemIndex].Quantity   = goldamount;
            Item.Position[ItemIndex].XSector   = Monsters.Position[ObjectIndex].XSector;
            Item.Position[ItemIndex].YSector   = Monsters.Position[ObjectIndex].YSector;
            byte randomplace = (byte)random.Next(1, 7);

            Item.Position[ItemIndex].X = Monsters.Position[ObjectIndex].X + randomplace;
            Item.Position[ItemIndex].Z = Monsters.Position[ObjectIndex].Z;
            Item.Position[ItemIndex].Y = Monsters.Position[ObjectIndex].Y + randomplace;
            Item.General[ItemIndex].DroppedByUniqueId = Monsters.General[ObjectIndex].UniqueID;
            Item.ItemAmount++;

            writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_SPAWN);
            if (goldamount < 10000)
            {
                writer.AppendDword(1);
            }
            else if (goldamount >= 10000 && goldamount <= 500000)
            {
                writer.AppendDword(2);
            }
            else if (goldamount >= 500001)
            {
                writer.AppendDword(3);
            }
            writer.AppendDword(goldamount);
            writer.AppendDword(Item.General[ItemIndex].UniqueID);
            writer.AppendByte(Item.Position[ItemIndex].XSector);
            writer.AppendByte(Item.Position[ItemIndex].YSector);
            writer.AppendFloat(Item.Position[ItemIndex].X);
            writer.AppendFloat(Item.Position[ItemIndex].X);
            writer.AppendFloat(Item.Position[ItemIndex].Y);
            writer.AppendWord(0xDC72);
            writer.AppendByte(0);
            writer.AppendByte(0);
            writer.AppendByte(5);
            writer.AppendDword(0);
            byte[] tmpBuffer = writer.getWorkspace();

            for (int i = 0; i < Player.PlayersOnline; i++)
            {
                if (Player.General[i].CharacterID != 0)
                {
                    if (Formula.CalculateDistance(Item.Position[ItemIndex], Player.Position[i]) <= 800)
                    {
                        ServerSocket.Send(tmpBuffer, i);
                        Player.Objects[i].SpawnedItemsIndex.Add(ItemIndex);
                    }
                }
            }
        }
コード例 #12
0
ファイル: PlayerAction.cs プロジェクト: Pascal1000/server1
        private static void PickUpItem(int Index_, int ObjectIndex)
        {
            int[] CharacterItemIndex = DatabaseCore.Item.GetIndexByName(Player.General[Index_].CharacterName);

            PacketWriter writer = new PacketWriter();

            for (int i = 0; i < Player.PlayersOnline; i++)
            {
                if (Player.General[i].UniqueID != 0)
                {
                    double Distance = Formula.CalculateDistance(Item.Position[ObjectIndex], Player.Position[i]);
                    if (Distance <= 800)
                    {
                        if (Player.Objects[i].SpawnedItemsIndex.Contains(ObjectIndex))
                        {
                            ServerSocket.Send(Players.CreateDeSpawnPacket(Item.General[ObjectIndex].UniqueID), i);
                            Player.Objects[i].SpawnedItemsIndex.Remove(ObjectIndex);
                        }
                    }
                }
            }

            Silkroad.Item_ tmpItem = Silkroad.GetItemById(Item.General[ObjectIndex].Pk2ID);

            byte freeslot = 0;

            if (Item.General[ObjectIndex].Pk2ID == 1 || Item.General[ObjectIndex].Pk2ID == 2 || Item.General[ObjectIndex].Pk2ID == 3)
            {
                freeslot = 254;
            }
            else
            {
                freeslot = Items.FreeSlot(CharacterItemIndex);
            }

            writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ITEM_MOVEMENT);
            writer.AppendWord(0x601);
            writer.AppendByte(freeslot);
            if (freeslot != 254)
            {
                writer.AppendDword(Item.General[ObjectIndex].Pk2ID);
            }
            if (tmpItem.ITEM_TYPE_NAME.Contains("CH") || tmpItem.ITEM_TYPE_NAME.Contains("EU"))
            {
                writer.AppendByte(Item.General[ObjectIndex].Plus);
                writer.AppendLword(0);
                writer.AppendDword((uint)tmpItem.MIN_DURA);
                writer.AppendByte(0);

                DatabaseCore.WriteQuery("UPDATE items SET itemid='{0}',plusvalue='{1}',type='0',durability='{2}' WHERE itemnumber='item{3}' AND owner ='{4}'", Item.General[ObjectIndex].Pk2ID, Item.General[ObjectIndex].Plus, Item.General[ObjectIndex].Durability, freeslot, Player.General[Index_].CharacterName);
                Items.AddItemToDatabase(CharacterItemIndex[freeslot], Item.General[ObjectIndex].Pk2ID, 0, 0, (byte)Item.General[ObjectIndex].Durability, Item.General[ObjectIndex].Plus, 0);
            }
            else if (tmpItem.ITEM_TYPE_NAME.Contains("ETC"))
            {
                if (freeslot == 254)
                {
                    writer.AppendDword(Item.General[ObjectIndex].Quantity);
                    Player.Stats[Index_].Gold += Item.General[ObjectIndex].Quantity;
                    DatabaseCore.WriteQuery("UPDATE characters SET gold='{0}' WHERE name='{1}'", Player.Stats[Index_].Gold, Player.General[Index_].CharacterName);
                }
                else
                {
                    writer.AppendWord((ushort)Item.General[ObjectIndex].Quantity);
                    DatabaseCore.WriteQuery("UPDATE items SET itemid='{0}',plusvalue='0',type='1',durability='{1}',quantity='{2}' WHERE itemnumber='item{3}' AND owner ='{4}'", Item.General[ObjectIndex].Pk2ID, Item.General[ObjectIndex].Durability, Item.General[ObjectIndex].Quantity, freeslot, Player.General[Index_].CharacterName);
                    Items.AddItemToDatabase(CharacterItemIndex[freeslot], Item.General[ObjectIndex].Pk2ID, 1, (byte)Item.General[ObjectIndex].Quantity, (byte)Item.General[ObjectIndex].Durability, 0, 0);
                }
            }

            ServerSocket.Send(writer.getWorkspace(), Index_);

            Item.General[ObjectIndex]  = new Item._General();
            Item.Position[ObjectIndex] = new _Position();

            writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_NEW_GOLD_AMOUNT);
            writer.AppendByte(1);
            writer.AppendLword(Player.Stats[Index_].Gold);
            writer.AppendByte(0);
            ServerSocket.Send(writer.getWorkspace(), Index_);

            writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ANIMATION_ITEM_PICKUP);
            writer.AppendDword(Player.General[Index_].UniqueID);
            writer.AppendByte(141);
            ServerSocket.Send(writer.getWorkspace(), Index_);

            writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_SKILL_ATTACK);
            writer.AppendByte(2);
            writer.AppendByte(0);
            ServerSocket.Send(writer.getWorkspace(), Index_);
        }
コード例 #13
0
ファイル: Movement.cs プロジェクト: Pascal1000/server1
        unsafe public static void OnMovement(byte *ptr, int Index_)
        {
            Silkroad.C_S.MOVEMENT_GROUND *tmpPtr = (Silkroad.C_S.MOVEMENT_GROUND *)ptr;

            if (tmpPtr->Type == 0)
            {
                Silkroad.C_S.MOVEMENT_SKY *MovingSky = (Silkroad.C_S.MOVEMENT_SKY *)ptr;
                writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_MOVEMENT);
                writer.AppendDword(Player.General[Index_].UniqueID);
                writer.AppendByte(MovingSky->Type);
                writer.AppendByte(MovingSky->Flag);
                writer.AppendWord((ushort)((MovingSky->Angle * 360) / 65536));
                writer.AppendByte(1);
                writer.AppendByte(Player.Position[Index_].XSector);
                writer.AppendByte(Player.Position[Index_].YSector);
                writer.AppendWord((ushort)Player.Position[Index_].X);
                writer.AppendFloat(Player.Position[Index_].Z);
                writer.AppendWord((ushort)Player.Position[Index_].Y);
            }
            else if (tmpPtr->Type == 1)
            {
                if (Player.General[Index_].State != 4 || Player.General[Index_].State != 10 || Player.General[Index_].State != 1)
                {
                    Player.Objects[Index_].AttackingSkillID = 0;
                    Player.Objects[Index_].NormalAttack     = false;
                    Player.Objects[Index_].UsingSkill       = false;
                    Player.General[Index_].Busy             = false;
                    Timers.PlayerAttack[Index_].Stop();

                    Player.Position[Index_].XSector = tmpPtr->XSector;
                    Player.Position[Index_].YSector = tmpPtr->YSector;
                    Player.Position[Index_].X       = tmpPtr->X;
                    Player.Position[Index_].Z       = tmpPtr->Z;
                    Player.Position[Index_].Y       = tmpPtr->Y;

                    writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_MOVEMENT);
                    writer.AppendDword(Player.General[Index_].UniqueID);
                    writer.AppendByte(tmpPtr->Type);
                    writer.AppendByte(Player.Position[Index_].XSector);
                    writer.AppendByte(Player.Position[Index_].YSector);
                    writer.AppendWord((ushort)Player.Position[Index_].X);
                    writer.AppendWord((ushort)Player.Position[Index_].Z);
                    writer.AppendWord((ushort)Player.Position[Index_].Y);
                    writer.AppendByte(0);

                    byte[] tmpBuffer = writer.getWorkspace();

                    for (int i = 0; i < Player.PlayersOnline; i++)
                    {
                        if (Player.General[i].CharacterID != 0)
                        {
                            if (i == Index_)
                            {
                                ServerSocket.Send(tmpBuffer, i);
                            }
                            else
                            {
                                if (Formula.CalculateDistance(Player.Position[Index_], Player.Position[i]) <= 800 && Player.Objects[i].SpawnedIndex.Contains(Index_))
                                {
                                    ServerSocket.Send(tmpBuffer, i);
                                }
                            }
                        }
                    }

                    DatabaseCore.WriteQuery("UPDATE characters SET xsect='{0}', ysect='{1}', xpos='{2}', zpos='{3}', ypos='{4}' where id='{5}'", Player.Position[Index_].XSector, Player.Position[Index_].YSector, Player.Position[Index_].X, Player.Position[Index_].Z, Player.Position[Index_].Y, Player.General[Index_].CharacterID);

                    for (int i = 0; i < Player.PlayersOnline; i++)
                    {
                        if (Player.General[i].CharacterID != 0 && Index_ != i)
                        {
                            double Distance = Formula.CalculateDistance(Player.Position[Index_], Player.Position[i]);
                            if (Distance <= 800)
                            {
                                if (!Player.Objects[Index_].SpawnedIndex.Contains(i))
                                {
                                    ServerSocket.Send(Character.CreateSpawnPacket(Player.General[i], Player.Flags[i], Player.Position[i], Player.Stats[i], Player.Speeds[i]), Index_);
                                    Player.Objects[Index_].SpawnedIndex.Add(i);

                                    ServerSocket.Send(Character.CreateSpawnPacket(Player.General[Index_], Player.Flags[Index_], Player.Position[Index_], Player.Stats[Index_], Player.Speeds[Index_]), i);
                                    Player.Objects[i].SpawnedIndex.Add(Index_);
                                }
                            }
                            else if (Distance > 800)
                            {
                                if (Player.Objects[Index_].SpawnedIndex.Contains(i))
                                {
                                    ServerSocket.Send(Players.CreateDeSpawnPacket(Player.General[i].UniqueID), Index_);
                                    Player.Objects[Index_].SpawnedIndex.Remove(i);

                                    ServerSocket.Send(Players.CreateDeSpawnPacket(Player.General[Index_].UniqueID), i);
                                    Player.Objects[i].SpawnedIndex.Remove(Index_);
                                }
                            }
                        }
                    }

                    for (int i = 0; i < Monsters.MonsterAmount; i++)
                    {
                        if (Monsters.General[i].UniqueID != 0 && !Monsters.General[i].Dead)
                        {
                            double Distance = Formula.CalculateDistance(Player.Position[Index_], Monsters.Position[i]);
                            if (Distance <= 800)
                            {
                                if (!Player.Objects[Index_].SpawnedMonsterIndex.Contains(i))
                                {
                                    ServerSocket.Send(MonsterSpawn.CreateSpawnPacket(Monsters.General[i].ID, Monsters.General[i].UniqueID, Monsters.Position[i], Monsters.General[i].Type), Index_);
                                    Player.Objects[Index_].SpawnedMonsterIndex.Add(i);
                                }
                            }
                            else if (Distance > 800)
                            {
                                if (Player.Objects[Index_].SpawnedMonsterIndex.Contains(i))
                                {
                                    ServerSocket.Send(Players.CreateDeSpawnPacket(Monsters.General[i].UniqueID), Index_);
                                    Player.Objects[Index_].SpawnedMonsterIndex.Remove(i);
                                }
                            }
                        }
                    }

                    for (int i = 0; i < Item.ItemAmount; i++)
                    {
                        if (Item.General[i].UniqueID != 0)
                        {
                            double Distance = Formula.CalculateDistance(Player.Position[Index_], Item.Position[i]);
                            if (Distance <= 800)
                            {
                                if (!Player.Objects[Index_].SpawnedItemsIndex.Contains(i))
                                {
                                    ServerSocket.Send(Items.CreateSpawnPacket(Item.General[i], Item.Position[i]), Index_);
                                    Player.Objects[Index_].SpawnedItemsIndex.Add(i);
                                }
                            }
                            else if (Distance > 800)
                            {
                                if (Player.Objects[Index_].SpawnedItemsIndex.Contains(i))
                                {
                                    ServerSocket.Send(Players.CreateDeSpawnPacket(Item.General[i].UniqueID), Index_);
                                    Player.Objects[Index_].SpawnedItemsIndex.Remove(i);
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #14
0
ファイル: Items.cs プロジェクト: Pascal1000/server1
        public static void OnUseItem(PacketReader reader, int Index_)
        {
            int[] CharacterItemIndex = DatabaseCore.Item.GetIndexByName(Player.General[Index_].CharacterName);
            byte  slot = reader.ReadByte();

            Silkroad.Item_ item = Silkroad.GetItemById(DatabaseCore.Item.ItemId[CharacterItemIndex[slot]]);

            if (DatabaseCore.Item.ItemId[CharacterItemIndex[slot]] >= 4 && DatabaseCore.Item.ItemId[CharacterItemIndex[slot]] <= 23)
            {
                if ((DatabaseCore.Item.Quantity[CharacterItemIndex[slot]] - 1) > 0)
                {
                    DatabaseCore.Item.Quantity[CharacterItemIndex[slot]]--;
                }
                else
                {
                    DeleteFromDatabase(CharacterItemIndex[slot]);
                    DatabaseCore.WriteQuery("DELETE FROM items WHERE itemnumber='item{0}' AND owner='{1}'", slot, Player.General[Index_].CharacterName);
                }

                PacketWriter writer = new PacketWriter();
                writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ITEM_USE);
                writer.AppendByte(1);
                writer.AppendByte(slot);
                writer.AppendWord(DatabaseCore.Item.Quantity[CharacterItemIndex[slot]]);
                writer.AppendWord(reader.ReadWord());
                ServerSocket.Send(writer.getWorkspace(), Index_);

                writer = new PacketWriter();
                writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ANIMATION_POTION);
                writer.AppendDword(Player.General[Index_].UniqueID);
                if (item.ITEM_TYPE_NAME.Contains("HP") && !item.ITEM_TYPE_NAME.Contains("SPOTION"))
                {
                    writer.AppendDword(0x04);
                    ServerSocket.SendPacketIfPlayerIsSpawned(writer.getWorkspace(), Index_);

                    Player.Stats[Index_].CHP += item.USE_TIME;
                    Stats.HPUpdate(Index_, false);
                }
                else if (item.ITEM_TYPE_NAME.Contains("HP") && item.ITEM_TYPE_NAME.Contains("SPOTION"))
                {
                    writer.AppendDword(0x04);
                    ServerSocket.SendPacketIfPlayerIsSpawned(writer.getWorkspace(), Index_);

                    Player.Stats[Index_].CHP += ((int)Player.Stats[Index_].HP * item.USE_TIME2 / 100);
                    Stats.HPUpdate(Index_, false);
                }
                else if (item.ITEM_TYPE_NAME.Contains("MP") && !item.ITEM_TYPE_NAME.Contains("SPOTION"))
                {
                    writer.AppendDword(0x0E);
                    ServerSocket.SendPacketIfPlayerIsSpawned(writer.getWorkspace(), Index_);

                    Player.Stats[Index_].CMP += item.USE_TIME3;
                    Stats.MPUpdate(Index_, false);
                }
                else if (item.ITEM_TYPE_NAME.Contains("MP") && item.ITEM_TYPE_NAME.Contains("SPOTION"))
                {
                    writer.AppendDword(0x0E);
                    ServerSocket.SendPacketIfPlayerIsSpawned(writer.getWorkspace(), Index_);

                    Player.Stats[Index_].CMP += ((int)Player.Stats[Index_].MP * item.USE_TIME4 / 100);
                    Stats.MPUpdate(Index_, false);
                }
                else if (item.ITEM_TYPE_NAME.Contains("ALL") && !item.ITEM_TYPE_NAME.Contains("SPOTION"))
                {
                    writer.AppendDword(0x17);
                    ServerSocket.SendPacketIfPlayerIsSpawned(writer.getWorkspace(), Index_);

                    Player.Stats[Index_].CHP += item.USE_TIME;
                    Player.Stats[Index_].CMP += item.USE_TIME3;
                    Stats.HPMPUpdate(Index_);
                }
                else if (item.ITEM_TYPE_NAME.Contains("ALL") && item.ITEM_TYPE_NAME.Contains("SPOTION"))
                {
                    writer.AppendDword(0x17);
                    ServerSocket.SendPacketIfPlayerIsSpawned(writer.getWorkspace(), Index_);

                    Player.Stats[Index_].CHP += ((int)Player.Stats[Index_].HP * item.USE_TIME2 / 100);
                    Player.Stats[Index_].CMP += ((int)Player.Stats[Index_].MP * item.USE_TIME4 / 100);
                    Stats.HPMPUpdate(Index_);
                }
            }
        }
コード例 #15
0
ファイル: Items.cs プロジェクト: Pascal1000/server1
        unsafe public static void MoveItem(byte *ptr, int Index_)
        {
            Silkroad.C_S.MOVE_ITEM *tmpPtr = (Silkroad.C_S.MOVE_ITEM *)ptr;

            PacketWriter writer = new PacketWriter();

            switch (tmpPtr->Type)
            {
            case 0:

                int[]          CharacterItemIndex = DatabaseCore.Item.GetIndexByName(Player.General[Index_].CharacterName);
                Silkroad.Item_ SourceItem_        = Silkroad.GetItemById(DatabaseCore.Item.ItemId[CharacterItemIndex[tmpPtr->Source]]);
                Silkroad.Item_ DestinationItem_   = Silkroad.GetItemById(DatabaseCore.Item.ItemId[CharacterItemIndex[tmpPtr->Destination]]);

                if (SourceItem_.ITEM_TYPE_NAME.Contains("FRPVP_VOUCHER"))
                {
                    if (Player.Stats[Index_].Level >= 10 && CheckItemGender(SourceItem_, Index_))
                    {
                        writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ANIMATION_CAPE);
                        writer.AppendDword(Player.General[Index_].UniqueID);
                        writer.AppendWord(0x102);
                        writer.AppendByte(0xA);

                        ServerSocket.SendPacketIfPlayerIsSpawned(writer.getWorkspace(), Index_);
                        Timers.UsingItemTimer[Index_].Interval      = 10000;
                        Player.Objects[Index_].SourceItemIndex      = CharacterItemIndex[tmpPtr->Source];
                        Player.Objects[Index_].DestinationItemIndex = CharacterItemIndex[tmpPtr->Destination];
                        Timers.UsingItemTimer[Index_].Start();
                    }
                    else
                    {
                        writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ITEM_MOVEMENT);
                        writer.AppendWord(0x1002);
                        ServerSocket.Send(writer.getWorkspace(), Index_);
                    }
                }
                else
                {
                    if (tmpPtr->Destination < 13)
                    {
                        if (!SourceItem_.ITEM_TYPE_NAME.Contains("ETC"))
                        {
                            if (!CheckItemGender(SourceItem_, Index_))
                            {
                                writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ITEM_MOVEMENT);
                                writer.AppendWord(0x1602);
                                ServerSocket.Send(writer.getWorkspace(), Index_);
                                return;
                            }
                            else if (!CheckItemLevel(SourceItem_, Index_))
                            {
                                writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ITEM_MOVEMENT);
                                writer.AppendWord(0x1002);
                                ServerSocket.Send(writer.getWorkspace(), Index_);
                                return;
                            }

                            if (tmpPtr->Destination == 6)
                            {
                                Player.General[Index_].WeaponType = SourceItem_.CLASS_C;
                            }

                            Silkroad.Item_ WeaponItem = Silkroad.GetItemById(DatabaseCore.Item.ItemId[CharacterItemIndex[6]]);

                            Console.WriteLine(WeaponItem.CLASS_C);
                            if (tmpPtr->Destination == 6 && DatabaseCore.Item.ItemId[CharacterItemIndex[7]] != 0 && (Player.General[Index_].WeaponType != 2 && Player.General[Index_].WeaponType != 3 && Player.General[Index_].WeaponType != 7 && Player.General[Index_].WeaponType != 10 && Player.General[Index_].WeaponType != 15))
                            {
                                byte unequipped = UnEnquipShield(Index_, CharacterItemIndex, CharacterItemIndex[7]);
                                if (unequipped != 255)
                                {
                                    MoveItemToDatabase(CharacterItemIndex[7], unequipped, Player.General[Index_].CharacterName);
                                }
                            }

                            if (tmpPtr->Destination == 7 && DatabaseCore.Item.ItemId[CharacterItemIndex[6]] != 0 && (WeaponItem.CLASS_C != 2 && WeaponItem.CLASS_C != 3 && WeaponItem.CLASS_C != 7 && WeaponItem.CLASS_C != 10 && WeaponItem.CLASS_C != 15))
                            {
                                byte unequipped = UnEnquipWeapon(Index_, CharacterItemIndex, CharacterItemIndex[6]);
                                if (unequipped != 255)
                                {
                                    MoveItemToDatabase(CharacterItemIndex[6], unequipped, Player.General[Index_].CharacterName);
                                }
                            }

                            EquipItem(Index_, CharacterItemIndex[tmpPtr->Source], CharacterItemIndex[tmpPtr->Destination]);
                        }
                        else
                        {
                            if (!(tmpPtr->Destination == 7 && (Player.General[Index_].WeaponType == 6 || Player.General[Index_].WeaponType == 12) && DatabaseCore.Item.ItemId[CharacterItemIndex[7]] != 0))
                            {
                                return;
                            }
                        }
                    }
                    if (tmpPtr->Source < 13)
                    {
                        UnEquipItem(Index_, CharacterItemIndex[tmpPtr->Source], CharacterItemIndex[tmpPtr->Destination]);
                    }

                    writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ITEM_MOVEMENT);
                    writer.AppendByte(1);
                    writer.AppendByte(tmpPtr->Type);
                    writer.AppendByte(tmpPtr->Source);
                    writer.AppendByte(tmpPtr->Destination);
                    writer.AppendWord(tmpPtr->Amount);
                    writer.AppendByte(0);
                    ServerSocket.Send(writer.getWorkspace(), Index_);

                    MoveItemToDatabase(CharacterItemIndex[tmpPtr->Source], CharacterItemIndex[tmpPtr->Destination], Player.General[Index_].CharacterName);
                }
                Stats.OnStatPacket(Index_);
                break;

            case 7:
                CharacterItemIndex = DatabaseCore.Item.GetIndexByName(Player.General[Index_].CharacterName);

                int ItemIndex = Item.ItemAmount;
                Item.General[ItemIndex].Pk2ID      = DatabaseCore.Item.ItemId[CharacterItemIndex[tmpPtr->Source]];
                Item.General[ItemIndex].UniqueID   = (uint)random.Next(76000000, 79999999);
                Item.General[ItemIndex].Plus       = DatabaseCore.Item.PlusValue[CharacterItemIndex[tmpPtr->Source]];
                Item.General[ItemIndex].Durability = DatabaseCore.Item.Durability[CharacterItemIndex[tmpPtr->Source]];
                Item.General[ItemIndex].Pickable   = true;
                Item.General[ItemIndex].Quantity   = DatabaseCore.Item.Quantity[CharacterItemIndex[tmpPtr->Source]];
                Item.Position[ItemIndex].XSector   = Player.Position[Index_].XSector;
                Item.Position[ItemIndex].YSector   = Player.Position[Index_].YSector;
                byte randomplace = (byte)random.Next(1, 7);
                Item.Position[ItemIndex].X = Player.Position[Index_].X + randomplace;
                Item.Position[ItemIndex].Z = Player.Position[Index_].Z;
                Item.Position[ItemIndex].Y = Player.Position[Index_].Y + randomplace;
                Item.General[ItemIndex].DroppedByUniqueId = Player.General[Index_].UniqueID;
                Item.ItemAmount++;

                writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ITEM_MOVEMENT);
                writer.AppendByte(1);
                writer.AppendByte(tmpPtr->Type);
                writer.AppendByte(tmpPtr->Source);
                ServerSocket.Send(writer.getWorkspace(), Index_);

                Silkroad.Item_ tmpItem = Silkroad.GetItemById(DatabaseCore.Item.ItemId[CharacterItemIndex[tmpPtr->Source]]);

                byte[] tmpBuffer = new byte[0];
                if (tmpItem.ITEM_TYPE_NAME.Contains("CH") || tmpItem.ITEM_TYPE_NAME.Contains("EU"))
                {
                    writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_SPAWN);
                    writer.AppendDword(DatabaseCore.Item.ItemId[CharacterItemIndex[tmpPtr->Source]]);
                    writer.AppendByte(DatabaseCore.Item.PlusValue[CharacterItemIndex[tmpPtr->Source]]);
                    writer.AppendDword(Item.General[ItemIndex].UniqueID);
                    writer.AppendByte(Item.Position[ItemIndex].XSector);
                    writer.AppendByte(Item.Position[ItemIndex].YSector);
                    writer.AppendFloat(Item.Position[ItemIndex].X);
                    writer.AppendFloat(Item.Position[ItemIndex].X);
                    writer.AppendFloat(Item.Position[ItemIndex].Y);
                    writer.AppendWord(0xAAA6);
                    writer.AppendByte(0);
                    writer.AppendByte(0);
                    writer.AppendByte(6);
                    writer.AppendDword(Item.General[ItemIndex].DroppedByUniqueId);
                    tmpBuffer = writer.getWorkspace();
                }
                else if (tmpItem.ITEM_TYPE_NAME.Contains("ETC"))
                {
                    writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_SPAWN);
                    writer.AppendDword(DatabaseCore.Item.ItemId[CharacterItemIndex[tmpPtr->Source]]);
                    writer.AppendDword(Item.General[ItemIndex].UniqueID);
                    writer.AppendByte(Item.Position[ItemIndex].XSector);
                    writer.AppendByte(Item.Position[ItemIndex].YSector);
                    writer.AppendFloat(Item.Position[ItemIndex].X);
                    writer.AppendFloat(Item.Position[ItemIndex].X);
                    writer.AppendFloat(Item.Position[ItemIndex].Y);
                    writer.AppendWord(0xAAA6);
                    writer.AppendByte(0);
                    writer.AppendByte(0);
                    writer.AppendByte(6);
                    writer.AppendDword(Item.General[ItemIndex].DroppedByUniqueId);
                    tmpBuffer = writer.getWorkspace();
                }

                for (int i = 0; i < Player.PlayersOnline; i++)
                {
                    if (Player.General[i].CharacterID != 0)
                    {
                        if (Formula.CalculateDistance(Item.Position[ItemIndex], Player.Position[i]) <= 800)
                        {
                            ServerSocket.Send(tmpBuffer, i);
                            Player.Objects[i].SpawnedItemsIndex.Add(ItemIndex);
                        }
                    }
                }

                DatabaseCore.WriteQuery("UPDATE items SET itemid='0',plusvalue='0' ,durability='30' WHERE itemnumber='item{0}' AND owner='{1}'", tmpPtr->Source, Player.General[Index_].CharacterName);
                Stats.OnStatPacket(Index_);

                DeleteFromDatabase(CharacterItemIndex[tmpPtr->Source]);

                break;

            case 10:
                if (Player.Stats[Index_].Gold != 0)
                {
                    PacketReader reader = new PacketReader(ptr, 5);
                    reader.ModifyIndex(1);
                    uint goldamount = reader.ReadDword();


                    ItemIndex = Item.ItemAmount;
                    if (goldamount < 10000)
                    {
                        Item.General[ItemIndex].Pk2ID = 1;
                    }
                    else if (goldamount >= 10000 && goldamount <= 500000)
                    {
                        Item.General[ItemIndex].Pk2ID = 2;
                    }
                    else if (goldamount >= 500001)
                    {
                        Item.General[ItemIndex].Pk2ID = 3;
                    }

                    Item.General[ItemIndex].UniqueID   = (uint)random.Next(76000000, 79999999);
                    Item.General[ItemIndex].Plus       = 0;
                    Item.General[ItemIndex].Durability = 0;
                    Item.General[ItemIndex].Pickable   = true;
                    Item.General[ItemIndex].Quantity   = goldamount;
                    Item.Position[ItemIndex].XSector   = Player.Position[Index_].XSector;
                    Item.Position[ItemIndex].YSector   = Player.Position[Index_].YSector;
                    randomplace = (byte)random.Next(1, 7);
                    Item.Position[ItemIndex].X = Player.Position[Index_].X + randomplace;
                    Item.Position[ItemIndex].Z = Player.Position[Index_].Z;
                    Item.Position[ItemIndex].Y = Player.Position[Index_].Y + randomplace;
                    Item.General[ItemIndex].DroppedByUniqueId = Player.General[Index_].UniqueID;
                    Item.ItemAmount++;

                    writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_SPAWN);
                    if (goldamount < 10000)
                    {
                        writer.AppendDword(1);
                    }
                    else if (goldamount >= 10000 && goldamount <= 500000)
                    {
                        writer.AppendDword(2);
                    }
                    else if (goldamount >= 500001)
                    {
                        writer.AppendDword(3);
                    }
                    writer.AppendDword(goldamount);
                    writer.AppendDword(Item.General[ItemIndex].UniqueID);
                    writer.AppendByte(Item.Position[ItemIndex].XSector);
                    writer.AppendByte(Item.Position[ItemIndex].YSector);
                    writer.AppendFloat(Item.Position[ItemIndex].X);
                    writer.AppendFloat(Item.Position[ItemIndex].X);
                    writer.AppendFloat(Item.Position[ItemIndex].Y);
                    writer.AppendWord(0xDC72);
                    writer.AppendByte(0);
                    writer.AppendByte(0);
                    writer.AppendByte(6);
                    writer.AppendDword(0);

                    tmpBuffer = writer.getWorkspace();

                    for (int i = 0; i < Player.PlayersOnline; i++)
                    {
                        if (Player.General[i].CharacterID != 0)
                        {
                            if (Formula.CalculateDistance(Item.Position[ItemIndex], Player.Position[i]) <= 800)
                            {
                                ServerSocket.Send(tmpBuffer, i);
                                Player.Objects[i].SpawnedItemsIndex.Add(ItemIndex);
                            }
                        }
                    }

                    Player.Stats[Index_].Gold -= goldamount;
                    writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_NEW_GOLD_AMOUNT);
                    writer.AppendByte(1);
                    writer.AppendLword(Player.Stats[Index_].Gold);
                    writer.AppendByte(0);
                    ServerSocket.Send(writer.getWorkspace(), Index_);


                    writer.SetOpcode(SERVER_OPCODES.GAME_SERVER_ITEM_MOVEMENT);
                    writer.AppendByte(1);
                    writer.AppendByte(10);
                    writer.AppendDword(goldamount);
                    ServerSocket.Send(writer.getWorkspace(), Index_);

                    DatabaseCore.WriteQuery("UPDATE characters SET gold='{0}' WHERE name='{1}'", Player.Stats[Index_].Gold, Player.General[Index_].CharacterName);
                }
                break;
            }
        }