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