You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openmw-tes3mp/apps/openmw-mp/Script/ScriptFunctions.hpp

216 lines
8.8 KiB
C++

#ifndef SCRIPTFUNCTIONS_HPP
#define SCRIPTFUNCTIONS_HPP
#include <Script/Functions/Actors.hpp>
#include <Script/Functions/Books.hpp>
#include <Script/Functions/Cells.hpp>
#include <Script/Functions/CharClass.hpp>
#include <Script/Functions/Chat.hpp>
#include <Script/Functions/Dialogue.hpp>
#include <Script/Functions/Factions.hpp>
#include <Script/Functions/GUI.hpp>
#include <Script/Functions/Items.hpp>
#include <Script/Functions/Mechanics.hpp>
#include <Script/Functions/Miscellaneous.hpp>
#include <Script/Functions/Objects.hpp>
#include <Script/Functions/Positions.hpp>
#include <Script/Functions/Quests.hpp>
[General] Implement RecordDynamic packet, part 1 Spell, potion, enchantment, creature, NPC, armor, book, clothing, miscellaneous and weapon record data can now be sent in a RecordDynamic packet. Additionally, the packets include data related to associated magical effects (for spells, potions and enchantments), data related to default inventory contents (for creatures and NPCs) and data related to body parts affected (for armor and clothing). The server now has associated script functions for setting most of the details of the above, with the main exception being individual creature and NPC stats. Records can either be created entirely from scratch or can use an existing record (set via the baseId variable) as a starting point for their values. In the latter case, only the values that are specifically set override the starting values. Creature and NPC records also have an inventoryBaseId that can be used on top of the baseId to base their inventories on another existing record. The client's RecordHelper class has been heavily expanded to allow for the above mentioned functionality. When players create spells, potions and enchantments as part of regular gameplay, they send RecordDynamic packets that provide the server with the complete details of the records that should be created. When they create enchantments, they also provide the server with armor, book, clothing and weapon records corresponding to the items they've enchanted. This functionality added by this packet was originally supposed to be exclusive to the rewrite, but I've gone ahead and tried to provide it for the pre-rewrite in a way that can mostly be reused for the rewrite.
6 years ago
#include <Script/Functions/RecordsDynamic.hpp>
#include <Script/Functions/Shapeshift.hpp>
#include <Script/Functions/Server.hpp>
#include <Script/Functions/Settings.hpp>
#include <Script/Functions/Spells.hpp>
#include <Script/Functions/Stats.hpp>
#include <Script/Functions/Worldstate.hpp>
#include <RakNetTypes.h>
#include <tuple>
#include <apps/openmw-mp/Player.hpp>
#include "ScriptFunction.hpp"
#include "Types.hpp"
#include <components/openmw-mp/Log.hpp>
#ifndef __PRETTY_FUNCTION__
#define __PRETTY_FUNCTION__ __FUNCTION__
#endif
#define GET_PLAYER(pid, pl, retvalue) \
pl = Players::getPlayer(pid); \
if (player == 0) {\
LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, "%s: Player with pid \'%d\' not found\n", __PRETTY_FUNCTION__, pid);\
/*ScriptFunctions::StopServer(1);*/ \
return retvalue;\
}
class ScriptFunctions
{
public:
static void MakePublic(ScriptFunc _public, const char *name, char ret_type, const char *def) noexcept;
static boost::any CallPublic(const char *name, va_list args) noexcept;
/**
* \brief Create a timer that will run a script function after a certain interval.
*
* \param callback The Lua script function.
* \param msec The interval in miliseconds.
* \return The ID of the timer thus created.
*/
static int CreateTimer(ScriptFunc callback, int msec) noexcept;
/**
* \brief Create a timer that will run a script function after a certain interval and pass
* certain arguments to it.
*
* Example usage:
* - tes3mp.CreateTimerEx("OnTimerTest1", 250, "i", 90)
* - tes3mp.CreateTimerEx("OnTimerTest2", 500, "sif", "Test string", 60, 77.321)
*
* \param callback The Lua script function.
* \param msec The interval in miliseconds.
* \param types The argument types.
* \param args The arguments.
* \return The ID of the timer thus created.
*/
static int CreateTimerEx(ScriptFunc callback, int msec, const char *types, va_list args) noexcept;
/**
* \brief Start the timer with a certain ID.
*
* \param timerId The timer ID.
* \return void
*/
static void StartTimer(int timerId) noexcept;
/**
* \brief Stop the timer with a certain ID.
*
* \param timerId The timer ID.
* \return void
*/
static void StopTimer(int timerId) noexcept;
/**
* \brief Restart the timer with a certain ID for a certain interval.
*
* \param timerId The timer ID.
* \param msec The interval in miliseconds.
* \return void
*/
static void RestartTimer(int timerId, int msec) noexcept;
/**
* \brief Free the timer with a certain ID.
*
* \param timerId The timer ID.
* \return void
*/
static void FreeTimer(int timerId) noexcept;
/**
* \brief Check whether a timer is elapsed.
*
* \param timerId The timer ID.
* \return Whether the timer is elapsed.
*/
static bool IsTimerElapsed(int timerId) noexcept;
static constexpr ScriptFunctionData functions[]{
{"CreateTimer", ScriptFunctions::CreateTimer},
{"CreateTimerEx", ScriptFunctions::CreateTimerEx},
{"MakePublic", ScriptFunctions::MakePublic},
{"CallPublic", ScriptFunctions::CallPublic},
{"StartTimer", ScriptFunctions::StartTimer},
{"StopTimer", ScriptFunctions::StopTimer},
{"RestartTimer", ScriptFunctions::RestartTimer},
{"FreeTimer", ScriptFunctions::FreeTimer},
{"IsTimerElapsed", ScriptFunctions::IsTimerElapsed},
ACTORAPI,
BOOKAPI,
CELLAPI,
CHARCLASSAPI,
CHATAPI,
DIALOGUEAPI,
FACTIONAPI,
GUIAPI,
ITEMAPI,
MECHANICSAPI,
MISCELLANEOUSAPI,
POSITIONAPI,
QUESTAPI,
[General] Implement RecordDynamic packet, part 1 Spell, potion, enchantment, creature, NPC, armor, book, clothing, miscellaneous and weapon record data can now be sent in a RecordDynamic packet. Additionally, the packets include data related to associated magical effects (for spells, potions and enchantments), data related to default inventory contents (for creatures and NPCs) and data related to body parts affected (for armor and clothing). The server now has associated script functions for setting most of the details of the above, with the main exception being individual creature and NPC stats. Records can either be created entirely from scratch or can use an existing record (set via the baseId variable) as a starting point for their values. In the latter case, only the values that are specifically set override the starting values. Creature and NPC records also have an inventoryBaseId that can be used on top of the baseId to base their inventories on another existing record. The client's RecordHelper class has been heavily expanded to allow for the above mentioned functionality. When players create spells, potions and enchantments as part of regular gameplay, they send RecordDynamic packets that provide the server with the complete details of the records that should be created. When they create enchantments, they also provide the server with armor, book, clothing and weapon records corresponding to the items they've enchanted. This functionality added by this packet was originally supposed to be exclusive to the rewrite, but I've gone ahead and tried to provide it for the pre-rewrite in a way that can mostly be reused for the rewrite.
6 years ago
RECORDSDYNAMICAPI,
SHAPESHIFTAPI,
SERVERAPI,
SETTINGSAPI,
SPELLAPI,
STATAPI,
OBJECTAPI,
WORLDSTATEAPI
};
static constexpr ScriptCallbackData callbacks[]{
{"OnServerInit", Callback<>()},
{"OnServerPostInit", Callback<>()},
{"OnServerExit", Callback<bool>()},
{"OnPlayerConnect", Callback<unsigned short>()},
{"OnPlayerDisconnect", Callback<unsigned short>()},
{"OnPlayerDeath", Callback<unsigned short>()},
{"OnPlayerResurrect", Callback<unsigned short>()},
{"OnPlayerCellChange", Callback<unsigned short>()},
{"OnPlayerAttribute", Callback<unsigned short>()},
{"OnPlayerSkill", Callback<unsigned short>()},
{"OnPlayerLevel", Callback<unsigned short>()},
{"OnPlayerBounty", Callback<unsigned short>()},
{"OnPlayerReputation", Callback<unsigned short>()},
{"OnPlayerEquipment", Callback<unsigned short>()},
{"OnPlayerInventory", Callback<unsigned short>()},
{"OnPlayerJournal", Callback<unsigned short>()},
{"OnPlayerFaction", Callback<unsigned short>()},
{"OnPlayerShapeshift", Callback<unsigned short>()},
{"OnPlayerSpellbook", Callback<unsigned short>()},
{"OnPlayerQuickKeys", Callback<unsigned short>()},
{"OnPlayerTopic", Callback<unsigned short>()},
{"OnPlayerDisposition", Callback<unsigned short>()},
{"OnPlayerBook", Callback<unsigned short>()},
{"OnPlayerItemUse", Callback<unsigned short>()},
{"OnPlayerMiscellaneous", Callback<unsigned short>()},
{"OnPlayerInput", Callback<unsigned short>()},
{"OnPlayerRest", Callback<unsigned short>()},
{"OnRecordDynamic", Callback<unsigned short>()},
{"OnCellLoad", Callback<unsigned short, const char*>()},
{"OnCellUnload", Callback<unsigned short, const char*>()},
{"OnCellDeletion", Callback<const char*>()},
{"OnContainer", Callback<unsigned short, const char*>()},
{"OnDoorState", Callback<unsigned short, const char*>()},
{"OnObjectActivate", Callback<unsigned short, const char*>()},
{"OnObjectPlace", Callback<unsigned short, const char*>()},
{"OnObjectState", Callback<unsigned short, const char*>()},
{"OnObjectSpawn", Callback<unsigned short, const char*>()},
{"OnObjectDelete", Callback<unsigned short, const char*>()},
{"OnObjectLock", Callback<unsigned short, const char*>()},
{"OnObjectScale", Callback<unsigned short, const char*>()},
{"OnObjectTrap", Callback<unsigned short, const char*>()},
{"OnVideoPlay", Callback<unsigned short, const char*>()},
{"OnActorList", Callback<unsigned short, const char*>()},
{"OnActorEquipment", Callback<unsigned short, const char*>()},
{"OnActorAI", Callback<unsigned short, const char*>()},
{"OnActorDeath", Callback<unsigned short, const char*>()},
{"OnActorCellChange", Callback<unsigned short, const char*>()},
{"OnActorTest", Callback<unsigned short, const char*>()},
{"OnPlayerSendMessage", Callback<unsigned short, const char*>()},
{"OnPlayerEndCharGen", Callback<unsigned short>()},
{"OnGUIAction", Callback<unsigned short, int, const char*>()},
{"OnWorldKillCount", Callback<unsigned short>()},
{"OnWorldMap", Callback<unsigned short>()},
{"OnWorldWeather", Callback<unsigned short>() },
{"OnMpNumIncrement", Callback<int>()},
{"OnRequestPluginList", Callback<>()}
};
};
#endif //SCRIPTFUNCTIONS_HPP