TrinityCore
Loading...
Searching...
No Matches
ScriptActions.h
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
18#ifndef TRINITYCORE_SCRIPT_ACTIONS_H
19#define TRINITYCORE_SCRIPT_ACTIONS_H
20
21#include "ScriptActionResult.h"
22#include "Define.h"
23#include "Duration.h"
24
25namespace Scripting::v2
26{
27class ActionBase;
28
29template<typename T>
30class ActionResultSetter;
31
33{
34public:
35 ActionBase();
36 ActionBase(ActionBase const& other);
37 ActionBase(ActionBase&& other) noexcept;
39 ActionBase& operator=(ActionBase&& other) noexcept;
40 virtual ~ActionBase();
41
42 virtual bool IsReady() const noexcept;
43
44protected:
45 friend void MarkActionCompleted(ActionBase& action);
46 void MarkCompleted() noexcept;
47
48private:
49 bool _isReady;
50};
51
52class WaitAction : public ActionBase
53{
54public:
55 explicit WaitAction(TimePoint waitEnd);
56
57 bool IsReady() const noexcept override;
58
59private:
61};
62
63template<typename T>
65{
66public:
67 [[nodiscard]] static ActionResultSetter<T> GetResultSetter(std::shared_ptr<ActionResult> action)
68 {
69 return ActionResultSetter<T>(std::shared_ptr<ActionResultValueHolder<T>>(std::move(action), &action->_result));
70 }
71
72private:
73 ActionResultValueHolder<T> _result = { .Action = *this };
74};
75
76template<>
77class ActionResult<void> : public ActionBase
78{
79public:
80 [[nodiscard]] static ActionResultSetter<void> GetResultSetter(std::shared_ptr<ActionResult> action)
81 {
82 return ActionResultSetter<void>(std::move(action));
83 }
84};
85}
86
87#endif // TRINITYCORE_SCRIPT_ACTIONS_H
#define TC_GAME_API
Definition Define.h:129
std::chrono::steady_clock::time_point TimePoint
time_point shorthand typedefs
Definition Duration.h:40
ActionBase(ActionBase const &other)
ActionBase & operator=(ActionBase const &other)
ActionBase(ActionBase &&other) noexcept
ActionBase & operator=(ActionBase &&other) noexcept
static ActionResultSetter< void > GetResultSetter(std::shared_ptr< ActionResult > action)
static ActionResultSetter< T > GetResultSetter(std::shared_ptr< ActionResult > action)