TrinityCore
Loading...
Searching...
No Matches
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 ScriptResult = std::move(args.ScriptResult);
44}
45
64
66{
67 Initialize(owner);
68}
69
71{
73 return false;
74
75 // Cyclic splines never expire, so update the duration only if it's not cyclic
76 if (_duration)
77 _duration->Update(diff);
78
79 if ((_duration && _duration->Passed()) || owner->movespline->Finalized())
80 {
82 return false;
83 }
84 return true;
85}
86
91
92void GenericMovementGenerator::Finalize(Unit* owner, bool/* active*/, bool movementInform)
93{
95
97 MovementInform(owner);
98}
99
101{
102 if (_arrivalSpellId)
104
106
107 if (Creature* creature = owner->ToCreature())
108 {
109 if (creature->AI())
110 creature->AI()->MovementInform(_type, _pointId);
111 }
112}
int32_t int32
Definition Define.h:150
uint32_t uint32
Definition Define.h:154
@ 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:265
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 SetScriptResult(MovementStopReason reason)
void AddFlag(uint16 const flag)
Scripting::v2::ActionResultSetter< MovementStopReason > ScriptResult
bool HasFlag(uint16 const flag) const
void RemoveFlag(uint16 const flag)
Creature * ToCreature()
Definition Object.h:121
Definition Unit.h:635
std::unique_ptr< Movement::MoveSpline > movespline
Definition Unit.h:1838
SpellCastResult CastSpell(CastSpellTargetArg const &targets, uint32 spellId, CastSpellExtraArgs const &args={ })
Definition Object.cpp:2217
TC_GAME_API Unit * GetUnit(WorldObject const &, ObjectGuid const &guid)
STL namespace.