eqemu-server/zone/quest_parser_collection.h
Kinglykrab 856aa51cb8
[Bots] Add support for Bot scripting. (#2515)
* [Bots] Add support for Bot scripting.

# Perl
- Add support for `zone/bot.pl` and `zone/bot_v#.pl`.
- Add support for `global/global_bot.pl`.
- Add `$bot->SignalBot(signal_id)` to Perl.
- Add `$bot->OwnerMessage(message)` to Perl.
- Add `$entity_list->SignalAllBotsByOwnerCharacterID(character_id, signal_id)` to Perl.
- Add `$entity_list->SignalBotByBotID(bot_id, signal_id)` to Perl.
- Add `$entity_list->SignalBotByBotName(bot_name, signal_id)` to Perl.
- Add `EVENT_SPELL_EFFECT_BOT` to Perl.
- Add `EVENT_SPELL_EFFECT_BUFF_TIC_BOT` to Perl.

# Lua
- Add support for `zone/bot.lua` and `zone/bot_v#.lua`.
- Add support for `global/global_bot.lua`.
- Add `bot:SignalBot(signal_id)` to Lua.
- Add `bot:OwnerMessage(message)` to Lua.
- Add `entity_list:SignalAllBotsByOwnerCharacterID(character_id, signal_id)` to Lua.
- Add `entity_list:SignalBotByBotID(bot_id, signal_id)` to Lua.
- Add `entity_list:SignalBotByBotName(bot_name, signal_id)` to Lua.
- Add `EVENT_SPELL_EFFECT_BOT` to Lua.
- Add `EVENT_SPELL_EFFECT_BUFF_TIC_BOT` to Lua.

# Supported Bot Events
1. `EVENT_CAST`
2. `EVENT_CAST_BEGIN`
3. `EVENT_CAST_ON`
4. `EVENT_COMBAT`
5. `EVENT_DEATH`
6. `EVENT_DEATH_COMPLETE`
7. `EVENT_SAY`
8. `EVENT_SIGNAL`
9. `EVENT_SLAY`
10. `EVENT_SLAY_NPC`
11. `EVENT_SPAWN`
12. `EVENT_TARGET_CHANGE`
13. `EVENT_TIMER`
14. `EVENT_USE_SKILL`

# Common
- Convert NPC pointers in common events to Mob pointers so bots are supported.
- Convert signal IDs to `int` where it wasn't already, allowing negative signals to be sent properly.

* Add EVENT_POPUP_RESPONSE.

* Cleanup and fix EVENT_COMBAT/EVENT_SLAY/EVENT_NPC_SLAY.

* Fix DoNPCEmote calls.

* Update attack.cpp

* Update event_codes.h

* Update bot_command.cpp
2022-11-16 21:02:16 -06:00

223 lines
7.3 KiB
C++

/* EQEMu: Everquest Server Emulator
Copyright (C) 2001-2006 EQEMu Development Team (http://eqemulator.net)
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; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY except by those people which sell it, which
are required to give you total support for your newly bought product;
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, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _EQE_QUESTPARSERCOLLECTION_H
#define _EQE_QUESTPARSERCOLLECTION_H
#include "../common/types.h"
#include "encounter.h"
#include "beacon.h"
#include "client.h"
#include "corpse.h"
#include "doors.h"
#include "groups.h"
#include "mob.h"
#include "object.h"
#include "raids.h"
#include "trap.h"
#include "quest_interface.h"
#include "zone_config.h"
#include <list>
#include <map>
#define QuestFailedToLoad 0xFFFFFFFF
#define QuestUnloaded 0x00
extern const ZoneConfig *Config;
class Client;
class Mob;
class NPC;
class QuestInterface;
namespace EQ
{
class Any;
class ItemInstance;
}
class QuestParserCollection {
public:
QuestParserCollection();
~QuestParserCollection();
void RegisterQuestInterface(QuestInterface *qi, std::string ext);
void UnRegisterQuestInterface(QuestInterface *qi, std::string ext);
void ClearInterfaces();
void AddVar(std::string name, std::string val);
void Init();
void ReloadQuests(bool reset_timers = true);
void RemoveEncounter(const std::string name);
bool HasQuestSub(uint32 npcid, QuestEventID evt, bool check_encounters = false);
bool PlayerHasQuestSub(QuestEventID evt, bool check_encounters = false);
bool SpellHasQuestSub(uint32 spell_id, QuestEventID evt, bool check_encounters = false);
bool ItemHasQuestSub(EQ::ItemInstance *itm, QuestEventID evt, bool check_encounters = false);
#ifdef BOTS
bool BotHasQuestSub(QuestEventID evt);
#endif
int EventNPC(QuestEventID evt, NPC* npc, Mob *init, std::string data, uint32 extra_data,
std::vector<std::any> *extra_pointers = nullptr);
int EventPlayer(QuestEventID evt, Client *client, std::string data, uint32 extra_data,
std::vector<std::any> *extra_pointers = nullptr);
int EventItem(QuestEventID evt, Client *client, EQ::ItemInstance *item, Mob *mob, std::string data, uint32 extra_data,
std::vector<std::any> *extra_pointers = nullptr);
int EventSpell(QuestEventID evt, Mob* mob, Client *client, uint32 spell_id, std::string data, uint32 extra_data,
std::vector<std::any> *extra_pointers = nullptr);
int EventEncounter(QuestEventID evt, std::string encounter_name, std::string data, uint32 extra_data,
std::vector<std::any> *extra_pointers = nullptr);
#ifdef BOTS
int EventBot(
QuestEventID evt,
Bot *bot,
Mob *init,
std::string data,
uint32 extra_data,
std::vector<std::any> *extra_pointers = nullptr
);
#endif
void GetErrors(std::list<std::string> &quest_errors);
/*
Internally used memory reference for all Perl Event Export Settings
Some exports are very taxing on CPU given how much an event is called.
These are loaded via DB and have defaults loaded in PerlEventExportSettingsDefaults.
Database loaded via Database::LoadPerlEventExportSettings(log_settings)
*/
struct PerlEventExportSettings {
uint8 qglobals;
uint8 mob;
uint8 zone;
uint8 item;
uint8 event_variables;
};
PerlEventExportSettings perl_event_export_settings[_LargestEventID];
void LoadPerlEventExportSettings(PerlEventExportSettings* perl_event_export_settings);
private:
bool HasQuestSubLocal(uint32 npcid, QuestEventID evt);
bool HasQuestSubGlobal(QuestEventID evt);
bool NPCHasEncounterSub(uint32 npc_id, QuestEventID evt);
bool PlayerHasQuestSubLocal(QuestEventID evt);
bool PlayerHasQuestSubGlobal(QuestEventID evt);
bool PlayerHasEncounterSub(QuestEventID evt);
bool SpellHasEncounterSub(uint32 spell_id, QuestEventID evt);
bool ItemHasEncounterSub(EQ::ItemInstance* item, QuestEventID evt);
bool HasEncounterSub(QuestEventID evt, const std::string& package_name);
#ifdef BOTS
bool BotHasQuestSubLocal(QuestEventID evt);
bool BotHasQuestSubGlobal(QuestEventID evt);
#endif
int EventNPCLocal(QuestEventID evt, NPC* npc, Mob *init, std::string data, uint32 extra_data, std::vector<std::any> *extra_pointers);
int EventNPCGlobal(QuestEventID evt, NPC* npc, Mob *init, std::string data, uint32 extra_data, std::vector<std::any> *extra_pointers);
int EventPlayerLocal(QuestEventID evt, Client *client, std::string data, uint32 extra_data, std::vector<std::any> *extra_pointers);
int EventPlayerGlobal(QuestEventID evt, Client *client, std::string data, uint32 extra_data, std::vector<std::any> *extra_pointers);
#ifdef BOTS
int EventBotLocal(
QuestEventID evt,
Bot *bot,
Mob *init,
std::string data,
uint32 extra_data,
std::vector<std::any> *extra_pointers
);
int EventBotGlobal(
QuestEventID evt,
Bot *bot,
Mob *init,
std::string data,
uint32 extra_data,
std::vector<std::any> *extra_pointers
);
#endif
QuestInterface *GetQIByNPCQuest(uint32 npcid, std::string &filename);
QuestInterface *GetQIByGlobalNPCQuest(std::string &filename);
QuestInterface *GetQIByPlayerQuest(std::string &filename);
QuestInterface *GetQIByGlobalPlayerQuest(std::string &filename);
QuestInterface *GetQIBySpellQuest(uint32 spell_id, std::string &filename);
QuestInterface *GetQIByItemQuest(std::string item_script, std::string &filename);
QuestInterface *GetQIByEncounterQuest(std::string encounter_name, std::string &filename);
#ifdef BOTS
QuestInterface *GetQIByBotQuest(std::string &filename);
QuestInterface *GetQIByGlobalBotQuest(std::string &filename);
#endif
int DispatchEventNPC(QuestEventID evt, NPC* npc, Mob *init, std::string data, uint32 extra_data,
std::vector<std::any> *extra_pointers);
int DispatchEventPlayer(QuestEventID evt, Client *client, std::string data, uint32 extra_data,
std::vector<std::any> *extra_pointers);
int DispatchEventItem(QuestEventID evt, Client *client, EQ::ItemInstance *item, Mob *mob, std::string data, uint32 extra_data,
std::vector<std::any> *extra_pointers);
int DispatchEventSpell(QuestEventID evt, Mob* mob, Client *client, uint32 spell_id, std::string data, uint32 extra_data,
std::vector<std::any> *extra_pointers);
#ifdef BOTS
int DispatchEventBot(
QuestEventID evt,
Bot *bot,
Mob *init,
std::string data,
uint32 extra_data,
std::vector<std::any> *extra_pointers
);
#endif
std::map<uint32, QuestInterface*> _interfaces;
std::map<uint32, std::string> _extensions;
std::list<QuestInterface*> _load_precedence;
//0x00 = Unloaded
//0xFFFFFFFF = Failed to Load
std::map<uint32, uint32> _npc_quest_status;
uint32 _global_npc_quest_status;
uint32 _player_quest_status;
uint32 _global_player_quest_status;
#ifdef BOTS
uint32 _bot_quest_status;
uint32 _global_bot_quest_status;
#endif
std::map<uint32, uint32> _spell_quest_status;
std::map<uint32, uint32> _item_quest_status;
std::map<std::string, uint32> _encounter_quest_status;
};
extern QuestParserCollection *parse;
#endif