Esempio n. 1
0
        public void GoToNearestGraveyard(ref WS_PlayerData.CharacterObject Character, bool Alive, bool Teleport)
        {
            DataTable  GraveQuery = new DataTable();
            bool       foundNear  = false;
            float      distNear   = 0f;
            TGraveyard entryNear  = default;
            TGraveyard entryFar   = default;

            checked
            {
                if (WorldServiceLocator._WS_Maps.Maps[Character.MapID].IsDungeon | WorldServiceLocator._WS_Maps.Maps[Character.MapID].IsBattleGround | WorldServiceLocator._WS_Maps.Maps[Character.MapID].IsRaid)
                {
                    Character.ZoneCheckInstance();
                    int Ghostzone = WorldServiceLocator._WS_Maps.AreaTable[WorldServiceLocator._WS_Maps.GetAreaIDByMapandParent((int)Character.MapID, WorldServiceLocator._WS_Maps.AreaTable[WorldServiceLocator._WS_Maps.GetAreaFlag(Character.resurrectPositionX, Character.resurrectPositionY, (int)Character.MapID)].Zone)].ID;
                    WorldServiceLocator._WorldServer.WorldDatabase.Query($"SELECT id, faction FROM game_graveyard_zone WHERE ghost_zone = {Ghostzone} and (faction = 0 or faction = {Character.Team}) ", ref GraveQuery);
                    if (GraveQuery.Rows.Count == 0)
                    {
                        WorldServiceLocator._WorldServer.Log.WriteLine(LogType.INFORMATION, "GraveYards: No near graveyards for map [{0}], zone [{1}]", Character.MapID, Character.ZoneID);
                        return;
                    }
                    if (WorldServiceLocator._WS_Maps.Maps[Character.MapID].IsDungeon | WorldServiceLocator._WS_Maps.Maps[Character.MapID].IsBattleGround | WorldServiceLocator._WS_Maps.Maps[Character.MapID].IsRaid)
                    {
                        if (Graveyards.ContainsKey(Conversions.ToInteger(GraveQuery.Rows[0]["id"])))
                        {
                            entryFar  = Graveyards[Conversions.ToInteger(GraveQuery.Rows[0]["id"])];
                            entryNear = entryFar;
                        }
                        else
                        {
                            WorldServiceLocator._WorldServer.Log.WriteLine(LogType.INFORMATION, "GraveYard: {0} is missing for map [{1}], zone [{2}]", GraveQuery.Rows[0]["id"], Character.MapID, Character.ZoneID);
                        }
                    }
                    else
                    {
                        IEnumerator enumerator = default;
                        try
                        {
                            enumerator = GraveQuery.Rows.GetEnumerator();
                            while (enumerator.MoveNext())
                            {
                                DataRow row               = (DataRow)enumerator.Current;
                                int     GraveyardID2      = row.As <int>("id");
                                int     GraveyardFaction2 = row.As <int>("faction");
                                if (!Graveyards.ContainsKey(GraveyardID2))
                                {
                                    WorldServiceLocator._WorldServer.Log.WriteLine(LogType.INFORMATION, "GraveYards: Graveyard link invalid [{0}]", GraveyardID2);
                                }
                                else if (Character.MapID != Graveyards[GraveyardID2].Map)
                                {
                                    if (Information.IsNothing(entryFar))
                                    {
                                        entryFar = Graveyards[GraveyardID2];
                                    }
                                }
                                else
                                {
                                    if (GraveyardFaction2 != 0 && GraveyardFaction2 != Character.Team)
                                    {
                                        continue;
                                    }
                                    float dist3 = WorldServiceLocator._WS_Combat.GetDistance(Character.positionX, Graveyards[GraveyardID2].X, Character.positionY, Graveyards[GraveyardID2].Y, Character.positionZ, Graveyards[GraveyardID2].Z);
                                    if (foundNear)
                                    {
                                        if (dist3 < distNear)
                                        {
                                            distNear  = dist3;
                                            entryNear = Graveyards[GraveyardID2];
                                        }
                                    }
                                    else
                                    {
                                        foundNear = true;
                                        distNear  = dist3;
                                        entryNear = Graveyards[GraveyardID2];
                                    }
                                }
                            }
                        }
                        finally
                        {
                            if (enumerator is IDisposable)
                            {
                                (enumerator as IDisposable).Dispose();
                            }
                        }
                    }
                    TGraveyard selectedGraveyard2 = entryNear;
                    if (Information.IsNothing(selectedGraveyard2))
                    {
                        selectedGraveyard2 = entryFar;
                    }
                    WorldServiceLocator._WorldServer.Log.WriteLine(LogType.INFORMATION, "GraveYards: GraveYard.Map[{0}], GraveYard.X[{1}], GraveYard.Y[{2}], GraveYard.Z[{3}]", selectedGraveyard2.Map, selectedGraveyard2.X, selectedGraveyard2.Y, selectedGraveyard2.Z);
                    Character.Teleport(selectedGraveyard2.X, selectedGraveyard2.Y, selectedGraveyard2.Z, 0f, selectedGraveyard2.Map);
                    Character.SendDeathReleaseLoc(selectedGraveyard2.X, selectedGraveyard2.Y, selectedGraveyard2.Z, selectedGraveyard2.Map);
                    return;
                }
                Character.ZoneCheck();
                WorldServiceLocator._WorldServer.WorldDatabase.Query($"SELECT id, faction FROM game_graveyard_zone WHERE ghost_zone = {Character.ZoneID}", ref GraveQuery);
                if (GraveQuery.Rows.Count == 0)
                {
                    WorldServiceLocator._WorldServer.Log.WriteLine(LogType.INFORMATION, "GraveYards: No near graveyards for map [{0}], zone [{1}]", Character.MapID, Character.ZoneID);
                    return;
                }
                IEnumerator enumerator2 = default;
                try
                {
                    enumerator2 = GraveQuery.Rows.GetEnumerator();
                    while (enumerator2.MoveNext())
                    {
                        DataRow row              = (DataRow)enumerator2.Current;
                        int     GraveyardID      = row.As <int>("id");
                        int     GraveyardFaction = row.As <int>("faction");
                        if (!Graveyards.ContainsKey(GraveyardID))
                        {
                            WorldServiceLocator._WorldServer.Log.WriteLine(LogType.INFORMATION, "GraveYards: Graveyard link invalid [{0}]", GraveyardID);
                        }
                        else if (Character.MapID != Graveyards[GraveyardID].Map)
                        {
                            if (Information.IsNothing(entryFar))
                            {
                                entryFar = Graveyards[GraveyardID];
                            }
                        }
                        else
                        {
                            if (GraveyardFaction != 0 && GraveyardFaction != Character.Team)
                            {
                                continue;
                            }
                            float dist2 = WorldServiceLocator._WS_Combat.GetDistance(Character.positionX, Graveyards[GraveyardID].X, Character.positionY, Graveyards[GraveyardID].Y, Character.positionZ, Graveyards[GraveyardID].Z);
                            if (foundNear)
                            {
                                if (dist2 < distNear)
                                {
                                    distNear  = dist2;
                                    entryNear = Graveyards[GraveyardID];
                                }
                            }
                            else
                            {
                                foundNear = true;
                                distNear  = dist2;
                                entryNear = Graveyards[GraveyardID];
                            }
                        }
                    }
                }
                finally
                {
                    if (enumerator2 is IDisposable)
                    {
                        (enumerator2 as IDisposable).Dispose();
                    }
                }
                TGraveyard selectedGraveyard = entryNear;
                if (Information.IsNothing(selectedGraveyard))
                {
                    selectedGraveyard = entryFar;
                }
                if (Teleport)
                {
                    if (Alive & Character.DEAD)
                    {
                        WorldServiceLocator._WS_Handlers_Misc.CharacterResurrect(ref Character);
                        Character.Life.Current = Character.Life.Maximum;
                        if (Character.ManaType == ManaTypes.TYPE_MANA)
                        {
                            Character.Mana.Current = Character.Mana.Maximum;
                        }
                        if (selectedGraveyard.Map == Character.MapID)
                        {
                            Character.SetUpdateFlag(22, Character.Life.Current);
                            if (Character.ManaType == ManaTypes.TYPE_MANA)
                            {
                                Character.SetUpdateFlag(23, Character.Mana.Current);
                            }
                            Character.SendCharacterUpdate();
                        }
                    }
                    WorldServiceLocator._WorldServer.Log.WriteLine(LogType.INFORMATION, "GraveYards: GraveYard.Map[{0}], GraveYard.X[{1}], GraveYard.Y[{2}], GraveYard.Z[{3}]", selectedGraveyard.Map, selectedGraveyard.X, selectedGraveyard.Y, selectedGraveyard.Z);
                    Character.Teleport(selectedGraveyard.X, selectedGraveyard.Y, selectedGraveyard.Z, 0f, selectedGraveyard.Map);
                    Character.SendDeathReleaseLoc(selectedGraveyard.X, selectedGraveyard.Y, selectedGraveyard.Z, selectedGraveyard.Map);
                }
                else
                {
                    Character.positionX = selectedGraveyard.X;
                    Character.positionY = selectedGraveyard.Y;
                    Character.positionZ = selectedGraveyard.Z;
                    Character.MapID     = (uint)selectedGraveyard.Map;
                }
            }
        }