<commit_before>/*
 * ArcScripts for ArcEmu MMORPG Server
 * Copyright (C) 2008-2012 ArcEmu Team <http://www.ArcEmu.org/>
 * Copyright (C) 2007 Moon++ <http://www.moonplusplus.info/>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

 //////////////////////////////////////////////////////////////////////////////////////////
 ///\brief This script will add support for an SQL table called gameobject_teleports.
 /// This table can be used to teleport players when they use a game object such
 /// as a door or portal. Any object used in this table should exist in the
 /// gameobject_names table, and be of type 10. Custom portal can use the generic
 /// display id of 6831. Portals also have the Sound2 field set to '1'.
//////////////////////////////////////////////////////////////////////////////////////////

#include "Setup.h"

struct GameobjectTeleport
{
    uint32 mapid;
    float x, y, z, o;
    uint32 req_level;
    uint8 req_class;
    uint32 req_achievement;
};

std::map<uint32, GameobjectTeleport*> m_teleStorage;

class CustomTeleport : public GameObjectAIScript // Custom Portals
{
    public:

        CustomTeleport(GameObject* goinstance) : GameObjectAIScript(goinstance)
        { }

        ~CustomTeleport()
        { }

        void OnActivate(Player* pPlayer)
        {
            float x, y, z, orientation;
            uint32 mapid;
            
            std::map<uint32, GameobjectTeleport*>::iterator itr = m_teleStorage.find(this->_gameobject->GetEntry());
            if (itr != m_teleStorage.end())
            {
                GameobjectTeleport* gt = itr->second;
                uint32 required_level = gt->req_level;
                uint8 req_class = gt->req_class;
                uint32 req_achievement = gt->req_achievement;

                if (required_level > pPlayer->getLevel())
                {
                    pPlayer->BroadcastMessage("You must be at least level %ld to use this portal", required_level);
                    return;
                }

                else if (req_class != 0 || req_class != pPlayer->getClass())
                {
                    pPlayer->BroadcastMessage("You do not have the required class to use this Portal", req_class, pPlayer->getClass());
                    return;
                }
                else if (req_achievement != 0 && pPlayer->GetAchievementMgr().HasCompleted(req_achievement))
                {
                    pPlayer->BroadcastMessage("You do not have the required achievement to use this Portal");
                    return;
                }
                else
                {
                    mapid = gt->mapid;
                    x = gt->x;
                    y = gt->y;
                    z = gt->z;
                    orientation = gt->o;

                    pPlayer->SafeTeleport(mapid, 0, x, y, z, orientation);
                }
            }
        }
        static GameObjectAIScript* Create(GameObject* GO) { return new CustomTeleport(GO); }
};


void InitializeGameObjectTeleportTable(ScriptMgr* mgr)
{
    QueryResult* result = NULL;
    result = WorldDatabase.Query("SELECT * FROM gameobject_teleports");
    if (result != NULL)
    {
        // Check if the SQL table is setup correctly
        if (result->GetFieldCount() < 9)
        {
            sLog.outError("Error: Custom portals disabled, invalid 'gameobject_teleports' table.");
            delete result;<commit_msg>Added us to (c) header. Resolved logic in class controle statement. Use named query instead of "*".<commit_after>/*
 * AscEmu Framework based on ArcEmu MMORPG Server
 * Copyright (C) 2014-2015 AscEmu Team <http://www.ascemu.org/>
 * Copyright (C) 2008-2012 ArcEmu Team <http://www.ArcEmu.org/>
 * Copyright (C) 2007 Moon++ <http://www.moonplusplus.info/>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

 //////////////////////////////////////////////////////////////////////////////////////////
 ///\brief This script will add support for an SQL table called gameobject_teleports.
 /// This table can be used to teleport players when they use a game object such
 /// as a door or portal. Any object used in this table should exist in the
 /// gameobject_names table, and be of type 10. Custom portal can use the generic
 /// display id of 6831. Portals also have the Sound2 field set to '1'.
//////////////////////////////////////////////////////////////////////////////////////////

#include "Setup.h"

struct GameobjectTeleport
{
    uint32 mapid;
    float x, y, z, o;
    uint32 req_level;
    uint8 req_class;
    uint32 req_achievement;
};

std::map<uint32, GameobjectTeleport*> m_teleStorage;

class CustomTeleport : public GameObjectAIScript // Custom Portals
{
    public:

        CustomTeleport(GameObject* goinstance) : GameObjectAIScript(goinstance)
        { }

        ~CustomTeleport()
        { }

        void OnActivate(Player* pPlayer)
        {
            float x, y, z, orientation;
            uint32 mapid;
            
            std::map<uint32, GameobjectTeleport*>::iterator itr = m_teleStorage.find(this->_gameobject->GetEntry());
            if (itr != m_teleStorage.end())
            {
                GameobjectTeleport* gt = itr->second;
                uint32 required_level = gt->req_level;
                uint8 req_class = gt->req_class;
                uint32 req_achievement = gt->req_achievement;

                if (required_level > pPlayer->getLevel())
                {
                    pPlayer->BroadcastMessage("You must be at least level %ld to use this portal", required_level);
                    return;
                }
                else if (req_class != 0 && req_class != pPlayer->getClass())
                {
                    pPlayer->BroadcastMessage("You do not have the required class to use this Portal");
                    return;
                }
                else if (req_achievement != 0 && pPlayer->GetAchievementMgr().HasCompleted(req_achievement))
                {
                    pPlayer->BroadcastMessage("You do not have the required achievement to use this Portal");
                    return;
                }
                else
                {
                    mapid = gt->mapid;
                    x = gt->x;
                    y = gt->y;
                    z = gt->z;
                    orientation = gt->o;

                    pPlayer->SafeTeleport(mapid, 0, x, y, z, orientation);
                }
            }
        }
        static GameObjectAIScript* Create(GameObject* GO) { return new CustomTeleport(GO); }
};


void InitializeGameObjectTeleportTable(ScriptMgr* mgr)
{
    QueryResult* result = WorldDatabase.Query("SELECT entry, mapid, x_pos, y_pos, z_pos, orientation, required_level, required_class, required_achievement FROM gameobject_teleports");
    if (result != NULL)
    {
        // Check if the SQL table is setup correctly
        if (result->GetFieldCount() < 9)
        {
            sLog.outError("Error: Custom portals disabled, invalid 'gameobject_teleports' table.");
            delete result;
{'fraction_non_alphanumeric': 0.12879339645545035, 'fraction_numerical': 0.011410536537994658, 'mean_word_length': 1.8090692124105012, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 7, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5825887', 'n_tokens_mistral': 2213, 'n_tokens_neox': 2079, 'n_words': 730}