aboutsummaryrefslogtreecommitdiff
path: root/src/server/scripts/Custom/test.cpp
blob: aa9e68790759776ce7811c536a342b499dbea466 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/* Copyright (C) 2006 - 2008 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
 */

/* ScriptData
SDName: Test
SD%Complete: 100
SDComment: Script used for testing escortAI
SDCategory: Script Examples
EndScriptData */

#include "precompiled.h"
#include "escort_ai.h"

#define SAY_WALK        "Hmm a nice day for a walk alright"
#define SAY_ATTACK      "Wild Felboar attack!"
#define SAY_TIME_TO_GO  "Time for me to go! See ya around $N!"
#define SAY_BYE         "Bye Bye!"
#define SAY_AGGRO1      "Help $N! I'm under attack!"
#define SAY_AGGRO2      "Die scum!"
#define WHISPER_TOO_FAR "How dare you leave me like that! I hate you! =*("
#define SAY_DIE1        "...no...how could you let me die $N"
#define SAY_DIE2        "ugh..."
#define SAY_DEATHCOIL   "Taste death!"
#define SAY_FIREWORKS   "Fireworks!"
#define SAY_BUFF        "Hmm, I think I could use a buff"

#define GOSSIP_TEXT1    "Click to Test Escort(Attack, Defend, Run)"
#define GOSSIP_TEXT2    "Click to Test Escort(NoAttack, NoDefend, Walk)"
#define GOSSIP_TEXT3    "Click to Test Escort(NoAttack, Defend, Walk)"

struct TRINITY_DLL_DECL npc_testAI : public npc_escortAI
{
    public:

        // CreatureAI functions
        npc_testAI(Creature *c) : npc_escortAI(c) {}

        uint32 DeathCoilTimer;
        uint32 ChatTimer;

        // Pure Virtual Functions
        void WaypointReached(uint32 i)
        {
            switch (i)
            {
                case 1:
                    me->Say(SAY_WALK, LANG_UNIVERSAL, 0);
                    break;

                case 3:
                {
                    me->Say(SAY_ATTACK, LANG_UNIVERSAL, 0);
                    Creature* temp = me->SummonCreature(21878, me->GetPositionX()+5, me->GetPositionY()+7, me->GetPositionZ(), 0, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 3000);
                    if (temp)
                        temp->AI()->AttackStart(me);
                }
                break;

                case 4:
                {
                    me->Say(SAY_TIME_TO_GO, LANG_UNIVERSAL, PlayerGUID);
                    me->HandleEmoteCommand(EMOTE_ONESHOT_WAVE);

                    Unit* temp = Unit::GetUnit(*me, PlayerGUID);
                    if (temp)
                    {
                        temp->MonsterSay(SAY_BYE, LANG_UNIVERSAL, 0);
                        temp->HandleEmoteCommand(EMOTE_ONESHOT_WAVE);
                    }
                }
                break;
            }
        }

        void Aggro(Unit*)
        {
            if (HasEscortState(STATE_ESCORT_ESCORTING))
                me->Say(SAY_AGGRO1, LANG_UNIVERSAL, PlayerGUID);
            else me->Say(SAY_AGGRO2, LANG_UNIVERSAL, 0);
        }

        void Reset()
        {
            DeathCoilTimer = 4000;
            ChatTimer = 4000;
        }

        void JustDied(Unit* killer)
        {
            if (HasEscortState(STATE_ESCORT_ESCORTING))
            {
                //killer = me when player got to far from creature
                if (killer == me)
                {
                    Unit *pTemp = Unit::GetUnit(*me,PlayerGUID);
                    if (pTemp)
                        DoWhisper(WHISPER_TOO_FAR, pTemp);
                }
                else me->Say(SAY_DIE1, LANG_UNIVERSAL, PlayerGUID);
            }
            else me->Say(SAY_DIE2, LANG_UNIVERSAL, 0);
        }

        void UpdateAI(const uint32 diff)
        {
            //Must update npc_escortAI
            npc_escortAI::UpdateAI(diff);

            //Combat check
            if (me->isInCombat() && me->getVictim())
            {
                if (DeathCoilTimer < diff)
                {
                    me->Say(SAY_DEATHCOIL, LANG_UNIVERSAL, 0);
                    me->CastSpell(me->getVictim(), 33130, false);

                    DeathCoilTimer = 4000;
                }else DeathCoilTimer -= diff;
            }else
            {
                //Out of combat but being escorted
                if (HasEscortState(STATE_ESCORT_ESCORTING))
                    if (ChatTimer < diff)
                {
                    if (me->HasAura(3593, 0))
                    {
                        me->Say(SAY_FIREWORKS, LANG_UNIVERSAL, 0);
                        me->CastSpell(me, 11540, false);
                    }else
                    {
                        me->Say(SAY_BUFF, LANG_UNIVERSAL, 0);
                        me->CastSpell(me, 3593, false);
                    }

                    ChatTimer = 12000;
                }else ChatTimer -= diff;
            }
        }
};

CreatureAI* GetAI_test(Creature* pCreature)
{
    npc_testAI* testAI = new npc_testAI(pCreature);

    testAI->AddWaypoint(0, 1231, -4419, 23);
    testAI->AddWaypoint(1, 1198, -4440, 23, 0);
    testAI->AddWaypoint(2, 1208, -4392, 23);
    testAI->AddWaypoint(3, 1231, -4419, 23, 5000);
    testAI->AddWaypoint(4, 1208, -4392, 23, 5000);

    return (CreatureAI*)testAI;
}

bool GossipHello_npc_test(Player* pPlayer, Creature* pCreature)
{
    pPlayer->TalkedToCreature(pCreature->GetEntry(), pCreature->GetGUID());
    pCreature->prepareGossipMenu(pPlayer,0);

    pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, GOSSIP_TEXT1, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+1);
    pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, GOSSIP_TEXT2, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+2);
    pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, GOSSIP_TEXT3, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+3);

    pCreature->sendPreparedGossip(pPlayer);
    return true;
}

bool GossipSelect_npc_test(Player* pPlayer, Creature* pCreature, uint32 uiSender, uint32 uiAction)
{
    if (uiAction == GOSSIP_ACTION_INFO_DEF+1)
    {
        pPlayer->CLOSE_GOSSIP_MENU();
        ((npc_escortAI*)(pCreature->AI()))->Start(true, true, pPlayer->GetGUID());

        return true;                                        // prevent Trinity core handling
    }

    if (uiAction == GOSSIP_ACTION_INFO_DEF+2)
    {
        pPlayer->CLOSE_GOSSIP_MENU();
        ((npc_escortAI*)(pCreature->AI()))->Start(false, false, pPlayer->GetGUID());

        return true;                                        // prevent Trinity core handling
    }

    if (uiAction == GOSSIP_ACTION_INFO_DEF+3)
    {
        pPlayer->CLOSE_GOSSIP_MENU();
        ((npc_escortAI*)(pCreature->AI()))->Start(false, false, pPlayer->GetGUID());

        return true;                                        // prevent Trinity core handling
    }
    return false;
}

void AddSC_test()
{
    Script *newscript;
    newscript = new Script;
    newscript->Name="test";
    newscript->GetAI = &GetAI_test;
    newscript->pGossipHello          = &GossipHello_npc_test;
    newscript->pGossipSelect         = &GossipSelect_npc_test;
    newscript->RegisterSelf();
}