All pastes #757753 Raw Edit

Unbenannt

public cpp v1 · immutable
·published 2007-11-01 16:05 UTC
rendered paste body
/* Copyright (C) 2006,2007 ScriptDev2 <https://scriptdev2.svn.sourceforge.net/>* 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 2 of the License, or* (at your option) 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, write to the Free Software* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA*/#include "../sc_defines.h"#include "../../../../game/Player.h"#include "../../../../game/GossipDef.h"#include "../../../../game/GameEvent.h"#define HALLOWEEN_EVENTID       12#define SPELL_TRICK_OR_TREATED  24755#define SPELL_TREAT             24715struct MANGOS_DLL_DECL npc_innkeeperAI : public ScriptedAI{    npc_innkeeperAI(Creature *c) : ScriptedAI(c) {LoadLocales();EnterEvadeMode();}            bool InCombat;    char **locales;    void LoadLocales()    {        locales=(char **)calloc(256,sizeof(char*));    // allocate and initialize        // If you want to add a new locale just add a line in the format below.        locales[0]="Trick or Treat!";        locales[2]="Des bonbons ou des blagues!";        locales[3]="Süßes oder Saures!";        locales[6]="¡Truco o trato!";    }    void EnterEvadeMode()    {        InCombat = false;        m_creature->RemoveAllAuras();        m_creature->DeleteThreatList();        m_creature->CombatStop();        DoGoHome();    }};CreatureAI* GetAI_npc_innkeeper(Creature *_Creature){    return new npc_innkeeperAI (_Creature);}bool isEventActive(){     const GameEvent::ActiveEvents *ActiveEventsList = gameeventmgr.GetActiveEventList();/*     GameEvent::ActiveEvents::const_iterator itr;     for (itr = ActiveEventsList->begin(); itr != ActiveEventsList->end(); ++itr)     {         if (*itr==HALLOWEEN_EVENTID)         {             return true;         }     }*/     return false;}bool GossipHello_npc_innkeeper(Player *player, Creature *_Creature){    player->TalkedToCreature(_Creature->GetEntry(),_Creature->GetGUID());    _Creature->prepareGossipMenu(player,0);    if (isEventActive()&& !player->GetAura(SPELL_TRICK_OR_TREATED,0))    {        char* fittingLocale = ((npc_innkeeperAI*)_Creature->AI())->locales[player->GetSession()->GetSessionLocaleIndex()]?            ((npc_innkeeperAI*)_Creature->AI())->locales[player->GetSession()->GetSessionLocaleIndex()]:            ((npc_innkeeperAI*)_Creature->AI())->locales[0];        player->PlayerTalkClass->GetGossipMenu()->AddMenuItem(0, fittingLocale, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+HALLOWEEN_EVENTID, false);    }    _Creature->sendPreparedGossip( player );    return true;}bool GossipSelect_npc_innkeeper(Player *player, Creature *_Creature, uint32 sender, uint32 action ){    if (action == GOSSIP_ACTION_INFO_DEF+HALLOWEEN_EVENTID && isEventActive() && !player->GetAura(SPELL_TRICK_OR_TREATED,0))    {        player->CLOSE_GOSSIP_MENU();        player->CastSpell(player, SPELL_TRICK_OR_TREATED, true);        // either trick or treat, 50% chance        if(rand()%2)        {            player->CastSpell(player, SPELL_TREAT, true);        }        else        {            int32 trickspell=0;            switch (rand()%9)   // note that female characters can get male costumes and vice versa            {                case 0:                    trickspell=24753; // cannot cast, random 30sec                    break;                case 1:                    trickspell=24713; // lepper gnome costume                    break;                case 2:                    trickspell=24735; // male ghost costume                    break;                case 3:                    trickspell=24736; // female ghostcostume                    break;                case 4:                    trickspell=24710; // male ninja costume                    break;                case 5:                    trickspell=24711; // female ninja costume                    break;                case 6:                    trickspell=24708; // male pirate costume                    break;                case 7:                    trickspell=24709; // female pirate costume                    break;                case 8:                    trickspell=24723; // skeleton costume                    break;            }            player->CastSpell(player, trickspell, true);        }        return true;    // prevent mangos core handling    }    return false;       // the player didn't select "trick or treat" or cheated, normal core handling}void AddSC_npc_innkeeper(){    Script *newscript;    newscript = new Script;    newscript->Name="innkeeper";    newscript->pGossipHello          = &GossipHello_npc_innkeeper;    newscript->pGossipSelect         = &GossipSelect_npc_innkeeper;    newscript->GetAI = GetAI_npc_innkeeper;    m_scripts[nrscripts++] = newscript;}