[9581] Fixed apply damage reduction to melee/ranged damage.
[getmangos.git] / src / game / PointMovementGenerator.cpp
blobc6c861fed855975dca6fb20c503b43d358071ae6
1 /*
2 * Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
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.
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.
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
19 #include "PointMovementGenerator.h"
20 #include "Errors.h"
21 #include "Creature.h"
22 #include "CreatureAI.h"
23 #include "TemporarySummon.h"
24 #include "DestinationHolderImp.h"
25 #include "World.h"
27 //----- Point Movement Generator
28 template<class T>
29 void PointMovementGenerator<T>::Initialize(T &unit)
31 unit.StopMoving();
32 unit.addUnitState(UNIT_STAT_ROAMING|UNIT_STAT_ROAMING_MOVE);
33 Traveller<T> traveller(unit);
34 i_destinationHolder.SetDestination(traveller, i_x, i_y, i_z);
36 if (unit.GetTypeId() == TYPEID_UNIT && ((Creature*)&unit)->canFly())
37 ((Creature&)unit).AddSplineFlag(SPLINEFLAG_UNKNOWN7);
40 template<class T>
41 void PointMovementGenerator<T>::Finalize(T &unit)
43 unit.clearUnitState(UNIT_STAT_ROAMING|UNIT_STAT_ROAMING_MOVE);
46 template<class T>
47 void PointMovementGenerator<T>::Interrupt(T &unit)
49 unit.clearUnitState(UNIT_STAT_ROAMING|UNIT_STAT_ROAMING_MOVE);
52 template<class T>
53 void PointMovementGenerator<T>::Reset(T &unit)
55 unit.StopMoving();
56 unit.addUnitState(UNIT_STAT_ROAMING|UNIT_STAT_ROAMING_MOVE);
60 template<class T>
61 bool PointMovementGenerator<T>::Update(T &unit, const uint32 &diff)
63 if(!&unit)
64 return false;
66 if(unit.hasUnitState(UNIT_STAT_CAN_NOT_MOVE))
68 unit.clearUnitState(UNIT_STAT_ROAMING_MOVE);
69 return true;
72 unit.addUnitState(UNIT_STAT_ROAMING_MOVE);
73 Traveller<T> traveller(unit);
74 if (i_destinationHolder.UpdateTraveller(traveller, diff, false))
76 if (!IsActive(unit)) // force stop processing (movement can move out active zone with cleanup movegens list)
77 return true; // not expire now, but already lost
80 if(i_destinationHolder.HasArrived())
82 unit.StopMoving();
83 MovementInform(unit);
84 return false;
87 return true;
90 template<>
91 void PointMovementGenerator<Player>::MovementInform(Player&)
95 template <>
96 void PointMovementGenerator<Creature>::MovementInform(Creature &unit)
98 if (unit.AI())
99 unit.AI()->MovementInform(POINT_MOTION_TYPE, id);
101 if (unit.isTemporarySummon())
103 TemporarySummon* pSummon = (TemporarySummon*)(&unit);
104 if (IS_CREATURE_GUID(pSummon->GetSummonerGUID()))
105 if(Creature* pSummoner = unit.GetMap()->GetCreature(pSummon->GetSummonerGUID()))
106 if (pSummoner->AI())
107 pSummoner->AI()->SummonedMovementInform(&unit, POINT_MOTION_TYPE, id);
111 template void PointMovementGenerator<Player>::Initialize(Player&);
112 template void PointMovementGenerator<Creature>::Initialize(Creature&);
113 template void PointMovementGenerator<Player>::Finalize(Player&);
114 template void PointMovementGenerator<Creature>::Finalize(Creature&);
115 template void PointMovementGenerator<Player>::Interrupt(Player&);
116 template void PointMovementGenerator<Creature>::Interrupt(Creature&);
117 template void PointMovementGenerator<Player>::Reset(Player&);
118 template void PointMovementGenerator<Creature>::Reset(Creature&);
119 template bool PointMovementGenerator<Player>::Update(Player &, const uint32 &diff);
120 template bool PointMovementGenerator<Creature>::Update(Creature&, const uint32 &diff);
122 void AssistanceMovementGenerator::Finalize(Unit &unit)
124 unit.clearUnitState(UNIT_STAT_ROAMING|UNIT_STAT_ROAMING_MOVE);
126 ((Creature*)&unit)->SetNoCallAssistance(false);
127 ((Creature*)&unit)->CallAssistance();
128 if (unit.isAlive())
129 unit.GetMotionMaster()->MoveSeekAssistanceDistract(sWorld.getConfig(CONFIG_UINT32_CREATURE_FAMILY_ASSISTANCE_DELAY));