1 | /* |
---|
2 | * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> |
---|
3 | * |
---|
4 | * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> |
---|
5 | * |
---|
6 | * This program is free software; you can redistribute it and/or modify |
---|
7 | * it under the terms of the GNU General Public License as published by |
---|
8 | * the Free Software Foundation; either version 2 of the License, or |
---|
9 | * (at your option) any later version. |
---|
10 | * |
---|
11 | * This program is distributed in the hope that it will be useful, |
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | * GNU General Public License for more details. |
---|
15 | * |
---|
16 | * You should have received a copy of the GNU General Public License |
---|
17 | * along with this program; if not, write to the Free Software |
---|
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
19 | */ |
---|
20 | |
---|
21 | #include "HomeMovementGenerator.h" |
---|
22 | #include "Creature.h" |
---|
23 | #include "Traveller.h" |
---|
24 | #include "MapManager.h" |
---|
25 | #include "ObjectAccessor.h" |
---|
26 | #include "DestinationHolderImp.h" |
---|
27 | #include "ObjectMgr.h" |
---|
28 | #include "WorldPacket.h" |
---|
29 | |
---|
30 | void |
---|
31 | HomeMovementGenerator<Creature>::Initialize(Creature & owner) |
---|
32 | { |
---|
33 | owner.RemoveUnitMovementFlag(MOVEMENTFLAG_WALK_MODE); |
---|
34 | _setTargetLocation(owner); |
---|
35 | } |
---|
36 | |
---|
37 | void |
---|
38 | HomeMovementGenerator<Creature>::Reset(Creature &) |
---|
39 | { |
---|
40 | } |
---|
41 | |
---|
42 | void |
---|
43 | HomeMovementGenerator<Creature>::_setTargetLocation(Creature & owner) |
---|
44 | { |
---|
45 | if( !&owner ) |
---|
46 | return; |
---|
47 | |
---|
48 | if( owner.hasUnitState(UNIT_STAT_ROOT | UNIT_STAT_STUNNED | UNIT_STAT_DISTRACTED) ) |
---|
49 | return; |
---|
50 | |
---|
51 | float x, y, z; |
---|
52 | owner.GetRespawnCoord(x, y, z); |
---|
53 | |
---|
54 | CreatureTraveller traveller(owner); |
---|
55 | |
---|
56 | uint32 travel_time = i_destinationHolder.SetDestination(traveller, x, y, z); |
---|
57 | modifyTravelTime(travel_time); |
---|
58 | owner.clearUnitState(UNIT_STAT_ALL_STATE); |
---|
59 | } |
---|
60 | |
---|
61 | bool |
---|
62 | HomeMovementGenerator<Creature>::Update(Creature &owner, const uint32& time_diff) |
---|
63 | { |
---|
64 | CreatureTraveller traveller( owner); |
---|
65 | i_destinationHolder.UpdateTraveller(traveller, time_diff, false); |
---|
66 | |
---|
67 | if (time_diff > i_travel_timer) |
---|
68 | { |
---|
69 | owner.AddUnitMovementFlag(MOVEMENTFLAG_WALK_MODE); |
---|
70 | |
---|
71 | // restore orientation of not moving creature at returning to home |
---|
72 | if(owner.GetDefaultMovementType()==IDLE_MOTION_TYPE) |
---|
73 | { |
---|
74 | if(CreatureData const* data = objmgr.GetCreatureData(owner.GetDBTableGUIDLow())) |
---|
75 | { |
---|
76 | owner.SetOrientation(data->orientation); |
---|
77 | WorldPacket packet; |
---|
78 | owner.BuildHeartBeatMsg(&packet); |
---|
79 | owner.SendMessageToSet(&packet, false); |
---|
80 | } |
---|
81 | } |
---|
82 | return false; |
---|
83 | } |
---|
84 | |
---|
85 | i_travel_timer -= time_diff; |
---|
86 | |
---|
87 | return true; |
---|
88 | } |
---|