-
Notifications
You must be signed in to change notification settings - Fork 206
/
sc_instance.h
135 lines (108 loc) · 6.49 KB
/
sc_instance.h
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
/* Copyright (C) 2006 - 2012 ScriptDev2 <http://www.scriptdev2.com/>
* This program is free software licensed under GPL version 2
* Please see the included DOCS/LICENSE.TXT for more information */
#ifndef SC_INSTANCE_H
#define SC_INSTANCE_H
#include "InstanceData.h"
#include "Map.h"
enum EncounterState
{
NOT_STARTED = 0,
IN_PROGRESS = 1,
FAIL = 2,
DONE = 3,
SPECIAL = 4
};
#define OUT_SAVE_INST_DATA debug_log("SD2: Saving Instance Data for Instance %s (Map %d, Instance Id %d)", instance->GetMapName(), instance->GetId(), instance->GetInstanceId())
#define OUT_SAVE_INST_DATA_COMPLETE debug_log("SD2: Saving Instance Data for Instance %s (Map %d, Instance Id %d) completed.", instance->GetMapName(), instance->GetId(), instance->GetInstanceId())
#define OUT_LOAD_INST_DATA(a) debug_log("SD2: Loading Instance Data for Instance %s (Map %d, Instance Id %d). Input is '%s'", instance->GetMapName(), instance->GetId(), instance->GetInstanceId(), a)
#define OUT_LOAD_INST_DATA_COMPLETE debug_log("SD2: Instance Data Load for Instance %s (Map %d, Instance Id: %d) is complete.", instance->GetMapName(), instance->GetId(), instance->GetInstanceId())
#define OUT_LOAD_INST_DATA_FAIL script_error_log("Unable to load Instance Data for Instance %s (Map %d, Instance Id: %d).", instance->GetMapName(), instance->GetId(), instance->GetInstanceId())
class MANGOS_DLL_DECL ScriptedInstance : public InstanceData
{
public:
ScriptedInstance(Map* pMap) : InstanceData(pMap) {}
~ScriptedInstance() {}
// Default accessor functions
GameObject* GetSingleGameObjectFromStorage(uint32 uiEntry);
Creature* GetSingleCreatureFromStorage(uint32 uiEntry, bool bSkipDebugLog = false);
// Change active state of doors or buttons
void DoUseDoorOrButton(ObjectGuid guid, uint32 uiWithRestoreTime = 0, bool bUseAlternativeState = false);
void DoUseDoorOrButton(uint32 uiEntry, uint32 uiWithRestoreTime = 0, bool bUseAlternativeState = false);
// Respawns a GO having negative spawntimesecs in gameobject-table
void DoRespawnGameObject(ObjectGuid guid, uint32 uiTimeToDespawn = MINUTE);
void DoRespawnGameObject(uint32 uiEntry, uint32 uiTimeToDespawn = MINUTE);
// Toggle the flags of a GO
void DoToggleGameObjectFlags(ObjectGuid guid, uint32 uiGOflags, bool bApply);
void DoToggleGameObjectFlags(uint32 uiEntry, uint32 uiGOflags, bool bApply);
// Sends world state update to all players in instance
void DoUpdateWorldState(uint32 uiStateId, uint32 uiStateData);
// Get a Player from map
Player* GetPlayerInMap(bool bOnlyAlive = false, bool bCanBeGamemaster = true);
/// Wrapper for simulating map-wide text in this instance. It is expected that the Creature is stored in m_mNpcEntryGuidStore if loaded.
void DoOrSimulateScriptTextForThisInstance(int32 iTextEntry, uint32 uiCreatureEntry)
{
// Prevent debug output in GetSingleCreatureFromStorage
DoOrSimulateScriptTextForMap(iTextEntry, uiCreatureEntry, instance, GetSingleCreatureFromStorage(uiCreatureEntry, true));
}
// Starts a timed achievement criteria for all players in instance
void DoStartTimedAchievement(AchievementCriteriaTypes criteriaType, uint32 uiTimedCriteriaMiscId);
protected:
// Storage for GO-Guids and NPC-Guids
typedef std::map<uint32, ObjectGuid> EntryGuidMap;
EntryGuidMap m_mGoEntryGuidStore; ///< Store unique GO-Guids by entry
EntryGuidMap m_mNpcEntryGuidStore; ///< Store unique NPC-Guids by entry
};
// Class for world maps (May need additional zone-wide functions later on)
class MANGOS_DLL_DECL ScriptedMap : public ScriptedInstance
{
public:
ScriptedMap(Map* pMap) : ScriptedInstance(pMap) {}
};
/// A static const array of this structure must be handled to DialogueHelper
struct DialogueEntry
{
int32 iTextEntry; ///< To be said text entry
uint32 uiSayerEntry; ///< Entry of the mob who should say
uint32 uiTimer; ///< Time delay until next text of array is said (0 stops)
};
/// A static const array of this structure must be handled to DialogueHelper
struct DialogueEntryTwoSide
{
int32 iTextEntry; ///< To be said text entry (first side)
uint32 uiSayerEntry; ///< Entry of the mob who should say (first side)
int32 iTextEntryAlt; ///< To be said text entry (second side)
uint32 uiSayerEntryAlt; ///< Entry of the mob who should say (second side)
uint32 uiTimer; ///< Time delay until next text of array is said (0 stops)
};
/// Helper class handling a dialogue given as static const array of DialogueEntry or DialogueEntryTwoSide
class DialogueHelper
{
public:
// The array MUST be terminated by {0,0,0}
DialogueHelper(DialogueEntry const* pDialogueArray);
// The array MUST be terminated by {0,0,0,0,0}
DialogueHelper(DialogueEntryTwoSide const* aDialogueTwoSide);
/// Function to initialize the dialogue helper for instances. If not used with instances, GetSpeakerByEntry MUST be overwritten to obtain the speakers
void InitializeDialogueHelper(ScriptedInstance* pInstance, bool bCanSimulateText = false) { m_pInstance = pInstance; m_bCanSimulate = bCanSimulateText; }
/// Set if take first entries or second entries
void SetDialogueSide(bool bIsFirstSide) { m_bIsFirstSide = bIsFirstSide; }
void StartNextDialogueText(int32 iTextEntry);
void DialogueUpdate(uint32 uiDiff);
protected:
/// Will be called when a dialogue step was done
virtual void JustDidDialogueStep(int32 iEntry) {}
/// Will be called to get a speaker, MUST be implemented if not used in instances
virtual Creature* GetSpeakerByEntry(uint32 uiEntry) { return NULL; }
private:
void DoNextDialogueStep();
ScriptedInstance* m_pInstance;
DialogueEntry const* m_pDialogueArray;
DialogueEntry const* m_pCurrentEntry;
DialogueEntryTwoSide const* m_pDialogueTwoSideArray;
DialogueEntryTwoSide const* m_pCurrentEntryTwoSide;
uint32 m_uiTimer;
bool m_bIsFirstSide;
bool m_bCanSimulate;
};
#endif