-
Notifications
You must be signed in to change notification settings - Fork 0
/
actions.h
119 lines (95 loc) · 4.26 KB
/
actions.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
////////////////////////////////////////////////////////////////////////
// OpenTibia - an opensource roleplaying game
////////////////////////////////////////////////////////////////////////
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
////////////////////////////////////////////////////////////////////////
#ifndef __ACTIONS__
#define __ACTIONS__
#include "baseevents.h"
#include "luascript.h"
#include "thing.h"
class Action;
class Container;
enum ActionType_t
{
ACTION_ANY,
ACTION_UNIQUEID,
ACTION_ACTIONID,
ACTION_ITEMID,
ACTION_RUNEID,
};
class Actions : public BaseEvents
{
public:
Actions();
virtual ~Actions();
bool useItem(Player* player, const Position& pos, uint8_t index, Item* item);
bool useItemEx(Player* player, const Position& fromPos, const Position& toPos,
uint8_t toStackPos, Item* item, bool isHotkey, uint32_t creatureId = 0);
ReturnValue canUse(const Player* player, const Position& pos);
ReturnValue canUse(const Player* player, const Position& pos, const Item* item);
ReturnValue canUseFar(const Creature* creature, const Position& toPos, bool checkLineOfSight);
bool hasAction(const Item* item) const {return getAction(item);}
protected:
virtual std::string getScriptBaseName() const {return "actions";}
virtual void clear();
virtual Event* getEvent(const std::string& nodeName);
virtual bool registerEvent(Event* event, xmlNodePtr p, bool override);
virtual LuaScriptInterface& getInterface() {return m_interface;}
LuaScriptInterface m_interface;
void registerItemID(int32_t itemId, Event* event);
void registerActionID(int32_t actionId, Event* event);
void registerUniqueID(int32_t uniqueId, Event* event);
typedef std::map<uint16_t, Action*> ActionUseMap;
ActionUseMap useItemMap;
ActionUseMap uniqueItemMap;
ActionUseMap actionItemMap;
bool executeUse(Action* action, Player* player, Item* item, const PositionEx& posEx, uint32_t creatureId);
ReturnValue internalUseItem(Player* player, const Position& pos,
uint8_t index, Item* item, uint32_t creatureId);
bool executeUseEx(Action* action, Player* player, Item* item, const PositionEx& fromPosEx,
const PositionEx& toPosEx, bool isHotkey, uint32_t creatureId);
ReturnValue internalUseItemEx(Player* player, const PositionEx& fromPosEx, const PositionEx& toPosEx,
Item* item, bool isHotkey, uint32_t creatureId);
Action* getAction(const Item* item, ActionType_t type = ACTION_ANY) const;
void clearMap(ActionUseMap& map);
};
typedef bool (ActionFunction)(Player* player, Item* item, const PositionEx& posFrom, const PositionEx& posTo, bool extendedUse, uint32_t creatureId);
class Action : public Event
{
public:
Action(const Action* copy);
Action(LuaScriptInterface* _interface);
virtual ~Action() {}
virtual bool configureEvent(xmlNodePtr p);
virtual bool loadFunction(const std::string& functionName);
//scripting
virtual bool executeUse(Player* player, Item* item, const PositionEx& posFrom,
const PositionEx& posTo, bool extendedUse, uint32_t creatureId);
bool getAllowFarUse() const {return allowFarUse;}
void setAllowFarUse(bool v) {allowFarUse = v;}
bool getCheckLineOfSight() const {return checkLineOfSight;}
void setCheckLineOfSight(bool v) {checkLineOfSight = v;}
virtual ReturnValue canExecuteAction(const Player* player, const Position& toPos);
virtual bool hasOwnErrorHandler() {return false;}
ActionFunction* function;
protected:
virtual std::string getScriptEventName() const {return "onUse";}
virtual std::string getScriptEventParams() const {return "cid, item, fromPosition, itemEx, toPosition";}
static ActionFunction increaseItemId;
static ActionFunction decreaseItemId;
bool allowFarUse;
bool checkLineOfSight;
};
#endif