root/Trunk/src/InstanceScripts/Instance_OldHillsbradFoothills.cpp @ 1134

Revision 1134, 11.9 kB (checked in by jackpoz, 7 months ago)

MODIFIED: Little cleanup.
MODIFIED: Library Headers are automatically located in the Windows build, it's no more needed to manually copy them to VC\include directory.

Line 
1/*
2* ArcScripts for ArcEmu MMORPG Server
3* Copyright (C) 2010 ArcEmu Team <http://www.arcemu.org/>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program.  If not, see <http://www.gnu.org/licenses/>.
17*/
18
19/* Script Comment:
20 * Everything before escort event is made to work as blizzlike as possible!
21 * This is still in development and is tagged[WIP].
22 * It is suggested to apply SQL updates to see this script fully working!
23 * Have fun ~Azolex
24 */
25
26#include "StdAfx.h"
27#include "Setup.h"
28#include "../Common/EasyFunctions.h"
29#include "../Common/Base.h"
30#include "../Common/Instance_Base.h"
31
32static Coords Fires[] =
33{
34        { 2160.68f,     235.382f,   53.8946f,   3.55550f },
35        { 2162.26f,     237.439f,   56.7303f,   5.97846f },
36        { 2192.94f,     258.437f,   54.0479f,   4.17990f },
37        { 2196.59f,     256.212f,   54.5663f,   4.15633f },
38        { 2207.03f,     259.549f,   62.1383f,   5.43653f },
39        { 2225.57f,     248.524f,   62.2857f,   5.66430f },
40        { 2179.05f,     262.558f,   62.2233f,   0.62989f },
41        { 2071.52f,     108.279f,   54.6802f,   3.91757f },
42        { 2160.76f,     246.790f,   62.035f,    0.82231f },
43        { 2195.19f,     257.229f,   58.0637f,   4.13277f },
44        { 2072.30f,     110.435f,   56.8422f,   2.74732f },
45        { 2061.12f,     95.2094f,   62.4747f,   2.04439f },
46        { 2067.92f,     121.267f,   62.7211f,   1.08228f },
47        { 2110.83f,     46.0729f,   62.0335f,   2.71590f },
48        { 2118.41f,     52.8182f,   56.0043f,   2.89655f },
49        { 2120.10f,     51.7093f,   54.6008f,   5.81823f },
50        { 2082.69f,     71.9957f,   55.8388f,   2.77088f },
51        { 2087.61f,     57.1432f,   62.1681f,   2.78659f },
52        { 2083.42f,     70.0828f,   53.7298f,   4.82470f },
53        { 2077.26f,     140.631f,   62.9179f,   1.05479f },
54        { 2070.20f,     75.6493f,   61.9173f,   2.12293f }
55};
56
57static Coords ThrallWP1[] = // pre 2nd boss
58{
59    { 0, 0, 0, 0 },
60    { 2230.29f, 115.049f,       82.2946f,       4.22934f },
61    { 2233.85f, 112.592f,       82.3021f,       5.77657f },
62    { 2231.99f, 108.086f,       82.6628f,       2.69702f },
63    { 2216.39f, 116.700f,       89.4553f,       2.59256f },
64    { 2208.22f, 103.356f,       89.4553f,       2.65854f },
65    { 2198.24f, 109.313f,       89.4553f,       2.60356f },
66    { 2203.42f, 119.908f,       89.4553f,       1.01862f },
67    { 2208.59f, 129.058f,       87.9559f,       2.60984f },
68    { 2195.72f, 136.440f,       88.2164f,       2.62162f },
69    { 2177.87f, 145.974f,       88.2163f,       2.61770f },
70    { 2171.95f, 149.297f,       87.8722f,       4.18456f },
71    { 2164.01f, 137.472f,       84.8832f,       3.90811f },
72    { 2150.95f, 127.355f,       77.7717f,       3.75103f },
73    { 2143.23f, 126.945f,       75.7064f,       2.34045f },
74    { 2139.72f, 135.942f,       72.8990f,       1.76868f },
75    { 2139.86f, 147.191f,       69.7701f,       1.55820f },
76    { 2141.66f, 155.228f,       66.9579f,       1.09010f },
77    { 2146.55f, 164.604f,       64.9990f,       2.45041f },
78    { 2143.41f, 169.553f,       66.2217f,       2.61220f },
79    { 2131.21f, 177.859f,       68.9637f,       2.53759f },
80    { 2118.25f, 186.881f,       68.8476f,       2.53366f },
81    { 2109.50f, 192.808f,       66.2216f,   2.66718f },
82    { 2098.07f, 196.281f,       65.2279f,       2.96406f },
83    { 2088.29f, 206.624f,       64.8821f,       2.43470f },
84    { 2072.24f, 220.331f,       64.8736f,       2.43470f },
85    { 2058.74f, 239.180f,       63.7724f,       2.32396f },
86    { 2054.77f, 243.723f,       63.2682f,       2.39857f }
87};
88
89#define MAX_THRALLWP1 27
90
91enum Data
92{
93    OHF_DATA_NOT_STARTED = 1,
94    OHF_DATA_IN_PROGRESS = 2,
95    OHF_DATA_PERFORMED = 3,
96    OHF_DATA_DONE = 4
97};
98
99enum DataIndex
100{
101    OHF_PHASE_1 = 0, // pre bosss spawn
102    OHF_PHASE_2 = 1, // 1st boss
103    OHF_PHASE_3 = 2, // pre 2nd boss, trall escort part 1
104    OHF_PHASE_4 = 3, // 2nd boss
105    OHF_PHASE_5 = 4, // pre 3rd boss, trall escort part 2
106    OHF_PHASE_6 = 5, // 3rd boss
107    OHF_PHASE_DONE = 6, // Event done
108
109    OHF_END = 7
110};
111
112enum OHF_ENTRIES
113{
114    MAP_OLD_HILSBRAD        = 560,
115
116    GO_LODGE_ABLAZE         = 182589,
117    GO_FIRE                 = 183816,
118
119    CN_EROZION              = 18723,
120    CN_BRAZEN               = 18725,
121    CN_LIEUTENANT_DRAKE     = 17848,
122    CN_THRALL               = 17876,
123
124    WS_OLD_HILLSBRAD        = 2436
125};
126
127class OldHilsbradInstance;
128#define GET_OHF(ptr) static_cast< OldHilsbradInstance* >( ptr->GetMapMgr()->GetScript() )
129
130class OldHilsbradInstance : public MoonInstanceScript
131{
132private:
133    int32 m_numBarrel;
134    uint32 m_phaseData[OHF_END];
135
136public:
137    MOONSCRIPT_INSTANCE_FACTORY_FUNCTION( OldHilsbradInstance, MoonInstanceScript );
138        OldHilsbradInstance( MapMgr* pMapMgr ) : MoonInstanceScript( pMapMgr )
139    {
140        m_numBarrel = 0;
141
142        for( int i = 0; i < OHF_END; ++i )
143            m_phaseData[i] = OHF_DATA_NOT_STARTED; 
144    };
145   
146    void OnLoad()
147    {
148        //AddWorldState( WS_OLD_HILLSBRAD, 0 );
149    }
150
151    void OnPlayerEnter( Player* pPlayer )
152    {
153        //SendWorldStates( pPlayer );
154
155        pPlayer->CastSpell( pPlayer, 35483, true ); // Human illusion
156    };
157
158    void SetData( uint32 pIndex, uint32 pData )
159    {
160        if( pIndex <= OHF_END )
161            return;
162
163        //if( pIndex == OHF_PHASE_2 )
164            //RemoveWorldStates();
165
166        m_phaseData[pIndex] = pData;
167    };
168
169    uint32 GetData( uint32 pIndex )
170        {
171        if( pIndex >= OHF_END )
172            return 0;
173
174        return m_phaseData[pIndex];
175    };
176
177    void OnGameObjectActivate( GameObject* pGameObject, Player* pPlayer )
178    {
179        if( pGameObject->GetEntry() != GO_LODGE_ABLAZE || GetData( OHF_PHASE_1 ) == OHF_DATA_DONE )
180            return;
181
182        pGameObject->Despawn( 1000, 0 );
183        m_numBarrel++;
184        //SetWorldState( WS_OLD_HILLSBRAD, m_numBarrel );
185        if( m_numBarrel != 5 )
186            return;
187
188        SetData( OHF_PHASE_1, OHF_DATA_DONE );
189
190        for( PlayerStorageMap::iterator itr = mInstance->m_PlayerStorage.begin(); itr !=  mInstance->m_PlayerStorage.end(); ++itr )
191            {
192                    pPlayer = itr->second;
193
194                    QuestLogEntry *qle = pPlayer->GetQuestLogForEntry( 10283 );
195                    if( !qle )
196                continue;
197
198                    qle->SetMobCount(0, qle->GetMobCount( 0 ) + 1);
199                    qle->SendUpdateAddKill( 0 );
200                    qle->UpdatePlayerFields();
201            };
202               
203        GameObject* pGO = NULL;
204            for( uint8 i = 0; i < 21; i++ )
205            {
206                    pGO = SpawnGameObject( GO_FIRE, Fires[i].mX, Fires[i].mY, Fires[i].mZ, Fires[i].mO );
207                    sEAS.GameobjectDelete( pGO, 10*60*1000);
208            }
209
210            SpawnCreature( CN_LIEUTENANT_DRAKE, 2118.310303f, 89.565969f, 52.453037f, 2.027089f );
211    }
212};
213
214class ErozionGossip : public GossipScript
215{
216public:
217        void GossipHello(Object* pObject, Player*  Plr, bool AutoSend)
218        {
219                GossipMenu *Menu;
220        OldHilsbradInstance* pInstance = GET_OHF(pObject);
221
222        if( !pInstance )
223            return;
224       
225        objmgr.CreateGossipMenuForPlayer(&Menu, pObject->GetGUID(), 10475, Plr);
226
227        if( pInstance->GetData( OHF_PHASE_1 ) != OHF_DATA_DONE && !Plr->HasItemCount( 25853,1 ) )
228        {
229                    Menu->AddItem( 0, "I need a pack of Incendiary Bombs.", 1 );
230        }
231
232                // It should give another menu if instance is done id: 10474, NYI
233
234                if(AutoSend)
235                        Menu->SendTo(Plr);
236        }
237
238        void GossipSelectOption(Object* pObject, Player*  Plr, uint32 Id, uint32 IntId, const char * Code)
239        {
240                switch (IntId)
241                {
242                        case 1:
243                Item* pBombs = objmgr.CreateItem( 25853, Plr);
244                if( pBombs )
245                                    Plr->GetItemInterface()->AddItemToFreeSlot( pBombs );
246                break;
247                }
248        }
249
250        void Destroy()
251        {
252                delete this;
253        };
254};
255
256class BrazenGossip : public GossipScript
257{
258public:
259        void GossipHello(Object* pObject, Player*  Plr, bool AutoSend)
260        {
261                GossipMenu *Menu;
262
263        objmgr.CreateGossipMenuForPlayer(&Menu, pObject->GetGUID(), 9779, Plr);
264            Menu->AddItem( 0, "I am ready to go to Durnholde Keep.", 1 );
265
266                if(AutoSend)
267                        Menu->SendTo(Plr);
268        }
269
270        void GossipSelectOption(Object* pObject, Player*  Plr, uint32 Id, uint32 IntId, const char * Code)
271        {
272        GossipMenu *Menu;
273                switch (IntId)
274                {
275        case 1:
276            {
277                            if ( !Plr->HasItemCount( 25853,1 ) ) 
278                {
279                    objmgr.CreateGossipMenuForPlayer(&Menu, pObject->GetGUID(), 9780, Plr);
280                    Menu->SendTo(Plr);
281                } 
282                else 
283                {
284                                    Plr->TaxiStart( sTaxiMgr.GetTaxiPath( 534 ), 8317, 0 );
285                    Plr->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_MOUNTED_TAXI);
286                }
287            }break;
288                }
289        }
290
291        void Destroy()
292        {
293                delete this;
294        };
295}; 
296
297class LieutenantDrakeAI : public MoonScriptCreatureAI
298{
299    OldHilsbradInstance* pInstance;
300
301public:
302    MOONSCRIPT_FACTORY_FUNCTION( LieutenantDrakeAI, MoonScriptCreatureAI );
303        LieutenantDrakeAI(Creature* pCreature) : MoonScriptCreatureAI(pCreature)
304        {
305                pInstance = GET_OHF(_unit);
306        };
307
308    void OnCombatStart( Unit* pTarget )
309    {
310        if( pInstance )
311            pInstance->SetData( OHF_PHASE_2, OHF_DATA_IN_PROGRESS );
312
313        ParentClass::OnCombatStart( pTarget );
314    };
315
316    void OnCombatStop( Unit* pTarget )
317    {
318        if( pInstance )
319            pInstance->SetData( OHF_PHASE_2, OHF_DATA_PERFORMED );
320
321        ParentClass::OnCombatStop( pTarget );
322    };
323};
324
325class ThrallAI : public MoonScriptCreatureAI // this will be replaced with escortAI
326{
327    MOONSCRIPT_FACTORY_FUNCTION( ThrallAI, MoonScriptCreatureAI );
328    ThrallAI(Creature* pCreature) : MoonScriptCreatureAI(pCreature)
329    {
330        SetMoveType(Move_DontMoveWP);
331        for( int i = 1; i < MAX_THRALLWP1; ++i )
332            AddWaypoint( CreateWaypoint( i, 0, Flag_Walk, ThrallWP1[i] ) );
333    };
334
335    void StartEscort( Player* pPlayer )
336    {
337        GameObject* pGO = GetNearestGameObject();
338        if( pGO )
339            pGO->SetState( pGO->GetState() == 1 ? 0 : 1 );
340
341        _unit->SetUInt32Value(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_NONE);
342        SetMoveType(Move_ForwardThenStop);
343    };
344
345    void OnCombatStop(Unit* pTarget)
346    {
347        ParentClass::OnCombatStop(pTarget);
348        SetWaypointToMove( m_currentWp );
349    };
350
351    void OnReachWP(uint32 iWaypointId, bool bForwards)
352    {
353        m_currentWp = iWaypointId;
354    };
355
356    uint32 m_currentWp;
357};
358
359class ThrallGossip : public GossipScript
360{
361public:
362        void GossipHello(Object* pObject, Player*  Plr, bool AutoSend)
363        {
364                GossipMenu *Menu;
365        if( !pObject->IsCreature() )
366            return;
367       
368        objmgr.CreateGossipMenuForPlayer(&Menu, pObject->GetGUID(), 9568, Plr);
369            Menu->AddItem( 0, "[PH] Start escort.", 1 );
370
371                if(AutoSend)
372                        Menu->SendTo(Plr);
373        }
374
375        void GossipSelectOption(Object* pObject, Player*  Plr, uint32 Id, uint32 IntId, const char * Code)
376        {
377                switch (IntId)
378                {
379                        case 1:
380                ThrallAI* pThrall = static_cast< ThrallAI* >( TO_CREATURE( pObject )->GetScript() );
381                if( pThrall )
382                    pThrall->StartEscort( Plr );
383                break;
384                }
385        }
386
387        void Destroy()
388        {
389                delete this;
390        };
391};
392
393void SetupOldHillsbradFoothills(ScriptMgr * mgr)
394{
395    mgr->register_instance_script( MAP_OLD_HILSBRAD, &OldHilsbradInstance::Create); 
396    mgr->register_creature_script( CN_LIEUTENANT_DRAKE, &LieutenantDrakeAI::Create );
397    mgr->register_creature_script( CN_THRALL, &ThrallAI::Create );
398
399    GossipScript * eGossip = (GossipScript*) new ErozionGossip;
400    mgr->register_gossip_script( CN_EROZION, eGossip );
401    GossipScript * bGossip = (GossipScript*) new BrazenGossip; 
402    mgr->register_gossip_script( CN_BRAZEN, bGossip );
403    GossipScript * tGossip = (GossipScript*) new ThrallGossip;
404    mgr->register_gossip_script( CN_THRALL, tGossip );
405}
Note: See TracBrowser for help on using the browser.