CreateDeSpawnPacket() public static method

public static CreateDeSpawnPacket ( uint UniqueId ) : byte[]
UniqueId uint
return byte[]
Example #1
0
        public static void KillMonster(PacketReader reader_, int Index_)
        {
            uint ObjectId = reader_.ReadDword();

            int ObjectIndex = Players.GetObjectIndex(ObjectId);

            ServerSocket.SendPacketIfMonsterIsSpawned(Players.CreateDeSpawnPacket(ObjectId), ObjectIndex);

            for (int i = 0; i <= Monsters.MonsterAmount; i++)
            {
                if (Monsters.General[i].ID == ObjectId)
                {
                    Timers.MonsterAttack[i].Stop();
                    Timers.MonsterMovement[i].Stop();
                    break;
                }
            }
        }
Example #2
0
        public static void OnDeSpawn(int Index_, uint ObjectId)
        {
            if (ObjectId != 0)
            {
                int ObjectIndex = Players.GetObjectIndexAndType(Index_, ObjectId);

                Timers.MonsterAttack[ObjectIndex].Stop();
                Timers.MonsterMovement[ObjectIndex].Stop();

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

                for (int i = 0; i < Player.PlayersOnline; i++)
                {
                    if (Player.General[i].UniqueID != 0 && Player.Objects[i].SpawnedMonsterIndex.Contains(ObjectIndex))
                    {
                        ServerSocket.Send(Players.CreateDeSpawnPacket(ObjectId), i);
                        Player.Objects[i].SpawnedMonsterIndex.Remove(ObjectIndex);
                    }
                }
            }
        }
Example #3
0
        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_);
        }
Example #4
0
        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);
                                }
                            }
                        }
                    }
                }
            }
        }