CreateSpawnPacket() public static method

public static CreateSpawnPacket ( Item general, _Position pos ) : byte[]
general Item
pos _Position
return byte[]
Exemplo n.º 1
0
 public static void OnRangeSpawn(int 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);
                 }
             }
         }
     }
     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);
                 }
             }
         }
     }
 }
Exemplo n.º 2
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);
                                }
                            }
                        }
                    }
                }
            }
        }