TrinityCore
GenericMovementGenerator.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
19#include "Creature.h"
20#include "CreatureAI.h"
21#include "MoveSpline.h"
22#include "MovementDefines.h"
23#include "ObjectAccessor.h"
24#include "Unit.h"
25
28 : _splineInit(std::move(initializer)), _type(type), _pointId(id), _durationTracksSpline(true), _arrivalSpellId(0)
29{
34 if (args.ArrivalSpellId)
35 _arrivalSpellId = *args.ArrivalSpellId;
36 if (args.ArrivalSpellTarget)
37 _arrivalSpellTargetGuid = *args.ArrivalSpellTarget;
38 if (args.Duration)
39 {
40 _duration.emplace(*args.Duration);
42 }
43}
44
46{
48 {
51 return;
52 }
53
56
57 Movement::MoveSplineInit init(owner);
58 _splineInit(init);
59 int32 duration = init.Launch();
61 _duration.emplace(duration);
62}
63
65{
66 Initialize(owner);
67}
68
70{
72 return false;
73
74 // Cyclic splines never expire, so update the duration only if it's not cyclic
75 if (_duration)
76 _duration->Update(diff);
77
78 if ((_duration && _duration->Passed()) || owner->movespline->Finalized())
79 {
81 return false;
82 }
83 return true;
84}
85
87{
89}
90
91void GenericMovementGenerator::Finalize(Unit* owner, bool/* active*/, bool movementInform)
92{
94
96 MovementInform(owner);
97}
98
100{
101 if (_arrivalSpellId)
103
104 if (Creature* creature = owner->ToCreature())
105 {
106 if (creature->AI())
107 creature->AI()->MovementInform(_type, _pointId);
108 }
109}
int32_t int32
Definition: Define.h:138
uint32_t uint32
Definition: Define.h:142
@ MOTION_MODE_DEFAULT
@ MOTION_PRIORITY_NORMAL
MovementGeneratorType
@ MOVEMENTGENERATOR_FLAG_INITIALIZATION_PENDING
@ MOVEMENTGENERATOR_FLAG_DEACTIVATED
@ MOVEMENTGENERATOR_FLAG_FINALIZED
@ MOVEMENTGENERATOR_FLAG_INFORM_ENABLED
@ MOVEMENTGENERATOR_FLAG_INITIALIZED
@ UNIT_STATE_ROAMING
Definition: Unit.h:259
void Finalize(Unit *, bool, bool) override
bool Update(Unit *, uint32) override
GenericMovementGenerator(std::function< void(Movement::MoveSplineInit &init)> &&initializer, MovementGeneratorType type, uint32 id, GenericMovementGeneratorArgs &&args={})
Optional< TimeTracker > _duration
std::function< void(Movement::MoveSplineInit &init)> _splineInit
void AddFlag(uint16 const flag)
bool HasFlag(uint16 const flag) const
void RemoveFlag(uint16 const flag)
static Creature * ToCreature(Object *o)
Definition: Object.h:219
Definition: Unit.h:627
std::unique_ptr< Movement::MoveSpline > movespline
Definition: Unit.h:1766
SpellCastResult CastSpell(CastSpellTargetArg const &targets, uint32 spellId, CastSpellExtraArgs const &args={ })
Definition: Object.cpp:2896
TC_GAME_API Unit * GetUnit(WorldObject const &, ObjectGuid const &guid)
STL namespace.