1/**
2 * The Forgotten Server - a free and open-source MMORPG server emulator
3 * Copyright (C) 2019 Mark Samman <mark.samman@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20#ifndef FS_EVENTS_H_BD444CC0EE167E5777E4C90C766B36DC
21#define FS_EVENTS_H_BD444CC0EE167E5777E4C90C766B36DC
22
23#include "luascript.h"
24#include "const.h"
25
26class Party;
27class ItemType;
28class Tile;
29
30class Events
31{
32 struct EventsInfo {
33 // Creature
34 int32_t creatureOnChangeOutfit = -1;
35 int32_t creatureOnAreaCombat = -1;
36 int32_t creatureOnTargetCombat = -1;
37 int32_t creatureOnHear = -1;
38
39 // Party
40 int32_t partyOnJoin = -1;
41 int32_t partyOnLeave = -1;
42 int32_t partyOnDisband = -1;
43 int32_t partyOnShareExperience = -1;
44
45 // Player
46 int32_t playerOnBrowseField = -1;
47 int32_t playerOnLook = -1;
48 int32_t playerOnLookInBattleList = -1;
49 int32_t playerOnLookInTrade = -1;
50 int32_t playerOnLookInShop = -1;
51 int32_t playerOnMoveItem = -1;
52 int32_t playerOnItemMoved = -1;
53 int32_t playerOnMoveCreature = -1;
54 int32_t playerOnReportRuleViolation = -1;
55 int32_t playerOnReportBug = -1;
56 int32_t playerOnTurn = -1;
57 int32_t playerOnTradeRequest = -1;
58 int32_t playerOnTradeAccept = -1;
59 int32_t playerOnTradeCompleted = -1;
60 int32_t playerOnGainExperience = -1;
61 int32_t playerOnLoseExperience = -1;
62 int32_t playerOnGainSkillTries = -1;
63 int32_t playerOnWrapItem = -1;
64
65 // Monster
66 int32_t monsterOnDropLoot = -1;
67 int32_t monsterOnSpawn = -1;
68 };
69
70 public:
71 Events();
72
73 bool load();
74
75 // Creature
76 bool eventCreatureOnChangeOutfit(Creature* creature, const Outfit_t& outfit);
77 ReturnValue eventCreatureOnAreaCombat(Creature* creature, Tile* tile, bool aggressive);
78 ReturnValue eventCreatureOnTargetCombat(Creature* creature, Creature* target);
79 void eventCreatureOnHear(Creature* creature, Creature* speaker, const std::string& words, SpeakClasses type);
80
81 // Party
82 bool eventPartyOnJoin(Party* party, Player* player);
83 bool eventPartyOnLeave(Party* party, Player* player);
84 bool eventPartyOnDisband(Party* party);
85 void eventPartyOnShareExperience(Party* party, uint64_t& exp);
86
87 // Player
88 bool eventPlayerOnBrowseField(Player* player, const Position& position);
89 void eventPlayerOnLook(Player* player, const Position& position, Thing* thing, uint8_t stackpos, int32_t lookDistance);
90 void eventPlayerOnLookInBattleList(Player* player, Creature* creature, int32_t lookDistance);
91 void eventPlayerOnLookInTrade(Player* player, Player* partner, Item* item, int32_t lookDistance);
92 bool eventPlayerOnLookInShop(Player* player, const ItemType* itemType, uint8_t count);
93 bool eventPlayerOnMoveItem(Player* player, Item* item, uint16_t count, const Position& fromPosition, const Position& toPosition, Cylinder* fromCylinder, Cylinder* toCylinder);
94 void eventPlayerOnItemMoved(Player* player, Item* item, uint16_t count, const Position& fromPosition, const Position& toPosition, Cylinder* fromCylinder, Cylinder* toCylinder);
95 bool eventPlayerOnMoveCreature(Player* player, Creature* creature, const Position& fromPosition, const Position& toPosition);
96 void eventPlayerOnReportRuleViolation(Player* player, const std::string& targetName, uint8_t reportType, uint8_t reportReason, const std::string& comment, const std::string& translation);
97 bool eventPlayerOnReportBug(Player* player, const std::string& message, const Position& position, uint8_t category);
98 bool eventPlayerOnTurn(Player* player, Direction direction);
99 bool eventPlayerOnTradeRequest(Player* player, Player* target, Item* item);
100 bool eventPlayerOnTradeAccept(Player* player, Player* target, Item* item, Item* targetItem);
101 void eventPlayerOnTradeCompleted(Player* player, Player* target, Item* item, Item* targetItem, bool isSuccess);
102 void eventPlayerOnGainExperience(Player* player, Creature* source, uint64_t& exp, uint64_t rawExp);
103 void eventPlayerOnLoseExperience(Player* player, uint64_t& exp);
104 void eventPlayerOnGainSkillTries(Player* player, skills_t skill, uint64_t& tries);
105 void eventPlayerOnWrapItem(Player* player, Item* item);
106
107 // Monster
108 void eventMonsterOnDropLoot(Monster* monster, Container* corpse);
109 bool eventMonsterOnSpawn(Monster* monster, const Position& position, bool startup, bool artificial);
110
111 private:
112 LuaScriptInterface scriptInterface;
113 EventsInfo info;
114};
115
116#endif
117