TrinityCore
Loading...
Searching...
No Matches
zone_elwynn_forest.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "ScriptMgr.h"
19#include "Containers.h"
20#include "MotionMaster.h"
21#include "ObjectAccessor.h"
22#include "GameEventMgr.h"
23#include "GameTime.h"
24#include "CreatureGroups.h"
25#include "ScriptedCreature.h"
26#include "CreatureAIImpl.h"
27
29{
32 WOODS_PATH = 644016,
33 HOUSE_PATH = 644024,
34 LISA_PATH = 645600
35};
36
45
55
57{
58 NPC_DANA = 804,
60 NPC_JOHN = 806,
61 NPC_LISA = 807,
62 NPC_AARON = 810,
63 NPC_JOSE = 811
64};
65
75
80
81struct npc_cameron : public ScriptedAI
82{
83 npc_cameron(Creature* creature) : ScriptedAI(creature)
84 {
85 _started = false;
86 }
87
99
101 {
102 std::vector<Position> MovePosPositions =
103 {
104 { -9373.521f, -67.71767f, 69.201965f, 1.117011f },
105 { -9374.94f, -62.51654f, 69.201965f, 5.201081f },
106 { -9371.013f, -71.20811f, 69.201965f, 1.937315f },
107 { -9368.419f, -66.47543f, 69.201965f, 3.141593f },
108 { -9372.376f, -65.49946f, 69.201965f, 4.206244f },
109 { -9377.477f, -67.8297f, 69.201965f, 0.296706f }
110 };
111
112 Trinity::Containers::RandomShuffle(MovePosPositions);
113
114 // first we break formation because children will need to move on their own now
115 for (auto guid : _childrenGUIDs)
116 if (Creature* child = ObjectAccessor::GetCreature(*me, guid))
117 if (CreatureGroup* creatureGroup = child->GetFormation())
118 sFormationMgr->RemoveCreatureFromGroup(creatureGroup, child);
119
120 // Move each child to an random position
121 for (uint32 i = 0; i < _childrenGUIDs.size(); ++i)
122 {
124 {
125 children->SetWalk(true);
126 children->GetMotionMaster()->MovePoint(0, MovePosPositions[i], true, MovePosPositions[i].GetOrientation());
127 }
128 }
129 me->SetWalk(true);
130 me->GetMotionMaster()->MovePoint(0, MovePosPositions.back(), true, MovePosPositions.back().GetOrientation());
131 }
132
133 void WaypointReached(uint32 waypointId, uint32 pathId) override
134 {
135 switch (pathId)
136 {
137 case STORMWIND_PATH:
138 {
139 if (waypointId == STORMWIND_WAYPOINT)
140 {
141 me->GetMotionMaster()->MoveRandom(10.f);
143 }
144
145 break;
146 }
147 case GOLDSHIRE_PATH:
148 {
149 if (waypointId == GOLDSHIRE_WAYPOINT)
150 {
151 me->GetMotionMaster()->MoveRandom(10.f);
153 }
154 break;
155 }
156 case WOODS_PATH:
157 {
158 if (waypointId == WOODS_WAYPOINT)
159 {
160 me->GetMotionMaster()->MoveRandom(10.f);
163 }
164
165 break;
166 }
167 case HOUSE_PATH:
168 {
169 if (waypointId == HOUSE_WAYPOINT)
170 {
171 // Move childeren at last point
173
174 // After 30 seconds a random sound should play
176 }
177 break;
178 }
179 }
180 }
181
182 void OnGameEvent(bool start, uint16 eventId) override
183 {
184 if (start && eventId == GAME_EVENT_CHILDREN_OF_GOLDSHIRE)
185 {
186 // Start event at 7 am
187 // Begin pathing
189 _started = true;
190 }
191 else if (!start && eventId == GAME_EVENT_CHILDREN_OF_GOLDSHIRE)
192 {
193 // Reset event at 8 am
194 _started = false;
195 _events.Reset();
196 }
197 }
198
199 void UpdateAI(uint32 diff) override
200 {
201 if (!_started)
202 return;
203
204 _events.Update(diff);
205
206 while (uint32 eventId = _events.ExecuteEvent())
207 {
208 switch (eventId)
209 {
212 break;
215 break;
218 break;
220 for (uint32 i = 0; i < _childrenGUIDs.size(); ++i)
221 {
223 {
224 if (lisa->GetEntry() == NPC_LISA)
225 {
226 lisa->GetMotionMaster()->MovePath(LISA_PATH, false);
227 break;
228 }
229 }
230 }
231 break;
234 break;
236 {
237 _childrenGUIDs.clear();
238
239 // Get all childeren's guid's.
240 if (Creature* dana = me->FindNearestCreature(NPC_DANA, 25.0f))
241 _childrenGUIDs.push_back(dana->GetGUID());
242
243 if (Creature* john = me->FindNearestCreature(NPC_JOHN, 25.0f))
244 _childrenGUIDs.push_back(john->GetGUID());
245
246 if (Creature* lisa = me->FindNearestCreature(NPC_LISA, 25.0f))
247 _childrenGUIDs.push_back(lisa->GetGUID());
248
249 if (Creature* aaron = me->FindNearestCreature(NPC_AARON, 25.0f))
250 _childrenGUIDs.push_back(aaron->GetGUID());
251
252 if (Creature* jose = me->FindNearestCreature(NPC_JOSE, 25.0f))
253 _childrenGUIDs.push_back(jose->GetGUID());
254
255 // If Formation was disbanded, remake.
256 if (!me->GetFormation()->IsFormed())
257 for (auto guid : _childrenGUIDs)
258 if (Creature* child = ObjectAccessor::GetCreature(*me, guid))
259 child->SearchFormation();
260
261 // Start movement
263
264 break;
265 }
266 default:
267 break;
268 }
269 }
270 }
271
272private:
276};
277
First const & RAND(First const &first, Second const &second, Rest const &... rest)
#define sFormationMgr
uint16_t uint16
Definition Define.h:134
uint32_t uint32
Definition Define.h:133
std::vector< ObjectGuid > GuidVector
Definition ObjectGuid.h:262
#define RegisterCreatureAI(ai_name)
Definition ScriptMgr.h:1139
Creature *const me
Definition CreatureAI.h:82
bool IsFormed() const
CreatureGroup * GetFormation()
Definition Creature.h:313
void Update(uint32 time)
Definition EventMap.h:67
EventId ExecuteEvent()
Definition EventMap.cpp:73
void ScheduleEvent(EventId eventId, Milliseconds time, GroupIndex group=0u, PhaseIndex phase=0u)
Definition EventMap.cpp:36
void Reset()
Definition EventMap.cpp:21
void MovePoint(uint32 id, Position const &pos, bool generatePath=true, Optional< float > finalOrient={})
void MovePath(uint32 pathId, bool repeatable)
void MoveRandom(float wanderDistance=0.0f)
MotionMaster * GetMotionMaster()
Definition Unit.h:1667
bool SetWalk(bool enable)
Definition Unit.cpp:13268
Creature * FindNearestCreature(uint32 entry, float range, bool alive=true) const
Definition Object.cpp:2099
void PlayDistanceSound(uint32 soundId, Player *target=nullptr)
Definition Object.cpp:3425
TC_GAME_API Creature * GetCreature(WorldObject const &u, ObjectGuid const &guid)
void RandomShuffle(C &container)
Reorder the elements of the container randomly.
Definition Containers.h:166
static uint32 SoundPicker()
void UpdateAI(uint32 diff) override
void WaypointReached(uint32 waypointId, uint32 pathId) override
npc_cameron(Creature *creature)
void OnGameEvent(bool start, uint16 eventId) override
GuidVector _childrenGUIDs
@ STORMWIND_PATH
@ GOLDSHIRE_PATH
@ HUMAN_FEMALE_EMOTE_CRY
@ CTHUN_DEATH_IS_CLOSE
@ BANSHEE_DEATH
@ CTHUN_YOU_WILL_DIE
@ BANSHEEPREAGGRO
@ NPC_CAMERON
@ STORMWIND_WAYPOINT
@ LISA_WAYPOINT
@ HOUSE_WAYPOINT
@ WOODS_WAYPOINT
@ GOLDSHIRE_WAYPOINT
@ GAME_EVENT_CHILDREN_OF_GOLDSHIRE
@ EVENT_WP_START_WOODS
@ EVENT_WP_START_GOLDSHIRE
@ EVENT_BEGIN_EVENT
@ EVENT_PLAY_SOUNDS
@ EVENT_WP_START_LISA
@ EVENT_WP_START_HOUSE
void AddSC_elwynn_forest()