[Server] Document script functions, part 4

Additionally, clean up some variable names.
This commit is contained in:
David Cernat 2018-04-18 11:02:18 +03:00
parent 76e7392a84
commit 311f770de7
7 changed files with 946 additions and 99 deletions

View file

@ -148,12 +148,12 @@ void GUIFunctions::SendQuickKeyChanges(unsigned short pid) noexcept
mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_QUICKKEYS)->Send(false);
}
void GUIFunctions::SetMapVisibility(unsigned short targetPID, unsigned short affectedPID, unsigned short state) noexcept
void GUIFunctions::SetMapVisibility(unsigned short targetPid, unsigned short affectedPid, unsigned short state) noexcept
{
LOG_MESSAGE(Log::LOG_WARN, "stub");
}
void GUIFunctions::SetMapVisibilityAll(unsigned short targetPID, unsigned short state) noexcept
void GUIFunctions::SetMapVisibilityAll(unsigned short targetPid, unsigned short state) noexcept
{
LOG_MESSAGE(Log::LOG_WARN, "stub");
}

View file

@ -30,13 +30,68 @@
class GUIFunctions
{
public:
/* Do not rename into MessageBox to not conflict with WINAPI's MessageBox */
/**
* \brief Display a simple messagebox at the bottom of the screen that vanishes
* after a few seconds.
*
* Note for C++ programmers: do not rename into MessageBox so as to not conflict
* with WINAPI's MessageBox.
*
* \param pid The player ID for whom the messagebox should appear.
* \param id The numerical ID of the messagebox.
* \param label The text in the messagebox.
* \return void
*/
static void _MessageBox(unsigned short pid, int id, const char *label) noexcept;
/**
* \brief Display an interactive messagebox at the center of the screen that
* vanishes only when one of its buttons is clicked.
*
* \param pid The player ID for whom the messagebox should appear.
* \param id The numerical ID of the messagebox.
* \param label The text in the messagebox.
* \parm buttons The captions of the buttons, separated by semicolons (e.g. "Yes;No;Maybe").
* \return void
*/
static void CustomMessageBox(unsigned short pid, int id, const char *label, const char *buttons) noexcept;
/**
* \brief Display an input dialog at the center of the screen.
*
* \param pid The player ID for whom the input dialog should appear.
* \param id The numerical ID of the input dialog.
* \param label The text at the top of the input dialog.
* \return void
*/
static void InputDialog(unsigned short pid, int id, const char *label) noexcept;
/**
* \brief Display a password dialog at the center of the screen.
*
* Although similar to an input dialog, the password dialog replaces all
* input characters with asterisks.
*
* \param pid The player ID for whom the password dialog should appear.
* \param id The numerical ID of the password dialog.
* \param label The text at the top of the password dialog.
* \parm note The text at the bottom of the password dialog.
* \return void
*/
static void PasswordDialog(unsigned short pid, int id, const char *label, const char *note) noexcept;
/**
* \brief Display a listbox at the center of the screen where each item takes up
* a row and is selectable, with the listbox only vanishing once the Ok button
* is pressed.
*
* \param pid The player ID for whom the listbox should appear.
* \param id The numerical ID of the listbox.
* \param label The text at the top of the listbox.
* \parm buttons The items in the listbox, separated by newlines (e.g. "Item 1\nItem 2").
* \return void
*/
static void ListBox(unsigned short pid, int id, const char *label, const char *items);
/**
@ -104,8 +159,29 @@ public:
static void SendQuickKeyChanges(unsigned short pid) noexcept;
//state 0 - disallow, 1 - allow
static void SetMapVisibility(unsigned short targetPID, unsigned short affectedPID, unsigned short state) noexcept;
static void SetMapVisibilityAll(unsigned short targetPID, unsigned short state) noexcept;
/**
* \brief Determine whether a player can see the map marker of another player.
*
* Note: This currently has no effect, and is just an unimplemented stub.
*
* \param targetPid The player ID whose map marker should be hidden or revealed.
* \param affectedPid The player ID for whom the map marker will be hidden or revealed.
* \param state The state of the map marker (false to hide, true to reveal).
* \return void
*/
static void SetMapVisibility(unsigned short targetPid, unsigned short affectedPid, unsigned short state) noexcept;
/**
* \brief Determine whether a player's map marker can be seen by all other players.
*
* Note: This currently has no effect, and is just an unimplemented stub.
*
* \param targetPid The player ID whose map marker should be hidden or revealed.
* \param state The state of the map marker (false to hide, true to reveal).
* \return void
*/
static void SetMapVisibilityAll(unsigned short targetPid, unsigned short state) noexcept;
};
#endif //OPENMW_GUIAPI_HPP

View file

@ -36,30 +36,185 @@ class ItemFunctions
{
public:
/**
* \brief Clear the last recorded inventory changes for a player.
*
* This is used to initialize the sending of new PlayerInventory packets.
*
* \param pid The player ID whose inventory changes should be used.
* \return void
*/
static void InitializeInventoryChanges(unsigned short pid) noexcept;
/**
* \brief Get the number of slots used for equipment.
*
* The number is 19 before any dehardcoding is done in OpenMW.
*
* \return The number of slots.
*/
static int GetEquipmentSize() noexcept;
/**
* \brief Get the number of indexes in a player's latest inventory changes.
*
* \param pid The player ID whose inventory changes should be used.
* \return The number of indexes.
*/
static unsigned int GetInventoryChangesSize(unsigned short pid) noexcept;
/**
* \brief Equip an item in a certain slot of the equipment of a player.
*
* \param pid The player ID.
* \param slot The equipment slot.
* \param refId The refId of the item.
* \param count The count of the item.
* \param charge The charge of the item.
* \param enchantmentCharge The enchantment charge of the item.
* \return void
*/
static void EquipItem(unsigned short pid, unsigned short slot, const char* refId, unsigned int count, int charge, double enchantmentCharge = -1) noexcept;
/**
* \brief Unequip the item in a certain slot of the equipment of a player.
*
* \param pid The player ID.
* \param slot The equipment slot.
* \return void
*/
static void UnequipItem(unsigned short pid, unsigned short slot) noexcept;
/**
* \brief Add an item to a player's inventory.
*
* Note: This will set the ADD action for all of the player's current inventory changes.
*
* \param pid The player ID.
* \param refId The refId of the item.
* \param count The count of the item.
* \param charge The charge of the item.
* \param enchantmentCharge The enchantment charge of the item.
* \return void
*/
static void AddItem(unsigned short pid, const char* refId, unsigned int count, int charge, double enchantmentCharge = -1) noexcept;
/**
* \brief Remove an item from a player's inventory.
*
* Note: This will set the REMOVE action for all of the player's current inventory changes.
*
* \param pid The player ID.
* \param refId The refId of the item.
* \param count The count of the item.
* \return void
*/
static void RemoveItem(unsigned short pid, const char* refId, unsigned short count) noexcept;
/**
* \brief Check whether a player has equipped an item with a certain refId in any slot.
*
* \param pid The player ID.
* \param refId The refId of the item.
* \return Whether the player has the item equipped.
*/
static bool HasItemEquipped(unsigned short pid, const char* refId);
/**
* \brief Get the refId of the item in a certain slot of the equipment of a player.
*
* \param pid The player ID.
* \param slot The slot of the equipment item.
* \return The refId.
*/
static const char *GetEquipmentItemRefId(unsigned short pid, unsigned short slot) noexcept;
/**
* \brief Get the count of the item in a certain slot of the equipment of a player.
*
* \param pid The player ID.
* \param slot The slot of the equipment item.
* \return The item count.
*/
static int GetEquipmentItemCount(unsigned short pid, unsigned short slot) noexcept;
/**
* \brief Get the charge of the item in a certain slot of the equipment of a player.
*
* \param pid The player ID.
* \param slot The slot of the equipment item.
* \return The charge.
*/
static int GetEquipmentItemCharge(unsigned short pid, unsigned short slot) noexcept;
/**
* \brief Get the enchantment charge of the item in a certain slot of the equipment of
* a player.
*
* \param pid The player ID.
* \param slot The slot of the equipment item.
* \return The enchantment charge.
*/
static double GetEquipmentItemEnchantmentCharge(unsigned short pid, unsigned short slot) noexcept;
/**
* \brief Get the refId of the item at a certain index in a player's latest inventory
* changes.
*
* \param pid The player ID whose inventory changes should be used.
* \param i The index of the inventory item.
* \return The refId.
*/
static const char *GetInventoryItemRefId(unsigned short pid, unsigned int i) noexcept;
/**
* \brief Get the count of the item at a certain index in a player's latest inventory
* changes.
*
* \param pid The player ID whose inventory changes should be used.
* \param i The index of the inventory item.
* \return The item count.
*/
static int GetInventoryItemCount(unsigned short pid, unsigned int i) noexcept;
/**
* \brief Get the charge of the item at a certain index in a player's latest inventory
* changes.
*
* \param pid The player ID whose inventory changes should be used.
* \param i The index of the inventory item.
* \return The charge.
*/
static int GetInventoryItemCharge(unsigned short pid, unsigned int i) noexcept;
/**
* \brief Get the enchantment charge of the item at a certain index in a player's
* latest inventory changes.
*
* \param pid The player ID whose inventory changes should be used.
* \param i The index of the inventory item.
* \return The enchantment charge.
*/
static double GetInventoryItemEnchantmentCharge(unsigned short pid, unsigned int i) noexcept;
/**
* \brief Send a PlayerEquipment packet with a player's equipment.
*
* It is always sent to all players.
*
* \param pid The player ID whose equipment should be sent.
* \return void
*/
static void SendEquipment(unsigned short pid) noexcept;
/**
* \brief Send a PlayerInventory packet with a player's recorded inventory changes.
*
* \param pid The player ID whose inventory changes should be used.
* \param toOthers Whether this packet should be sent only to other players or
* only to the player it is about.
* \return void
*/
static void SendInventoryChanges(unsigned short pid, bool toOthers = false) noexcept;
private:

View file

@ -53,20 +53,20 @@ int StatsFunctions::GetSkillId(const char *name) noexcept
return -1;
}
const char *StatsFunctions::GetAttributeName(unsigned short attribute) noexcept
const char *StatsFunctions::GetAttributeName(unsigned short attributeId) noexcept
{
if (attribute >= Attribute::Length)
if (attributeId >= Attribute::Length)
return "invalid";
return Attribute::sAttributeNames[attribute].c_str();
return Attribute::sAttributeNames[attributeId].c_str();
}
const char *StatsFunctions::GetSkillName(unsigned short skill) noexcept
const char *StatsFunctions::GetSkillName(unsigned short skillId) noexcept
{
if (skill >= Skill::Length)
if (skillId >= Skill::Length)
return "invalid";
return Skill::sSkillNames[skill].c_str();
return Skill::sSkillNames[skillId].c_str();
}
const char *StatsFunctions::GetName(unsigned short pid) noexcept
@ -118,14 +118,6 @@ const char *StatsFunctions::GetBirthsign(unsigned short pid) noexcept
return player->birthsign.c_str();
}
const char *StatsFunctions::GetDeathReason(unsigned short pid) noexcept
{
Player *player;
GET_PLAYER(pid, player, 0);
return player->deathReason.c_str();
}
int StatsFunctions::GetLevel(unsigned short pid) noexcept
{
Player *player;
@ -190,70 +182,70 @@ double StatsFunctions::GetFatigueCurrent(unsigned short pid) noexcept
return player->creatureStats.mDynamic[2].mCurrent;
}
int StatsFunctions::GetAttributeBase(unsigned short pid, unsigned short attribute) noexcept
int StatsFunctions::GetAttributeBase(unsigned short pid, unsigned short attributeId) noexcept
{
Player *player;
GET_PLAYER(pid, player, 0);
if (attribute >= Attribute::Length)
if (attributeId >= Attribute::Length)
return 0;
return player->creatureStats.mAttributes[attribute].mBase;
return player->creatureStats.mAttributes[attributeId].mBase;
}
int StatsFunctions::GetAttributeModifier(unsigned short pid, unsigned short attribute) noexcept
int StatsFunctions::GetAttributeModifier(unsigned short pid, unsigned short attributeId) noexcept
{
Player *player;
GET_PLAYER(pid, player, 0);
if (attribute >= Attribute::Length)
if (attributeId >= Attribute::Length)
return 0;
return player->creatureStats.mAttributes[attribute].mMod;
return player->creatureStats.mAttributes[attributeId].mMod;
}
int StatsFunctions::GetSkillBase(unsigned short pid, unsigned short skill) noexcept
int StatsFunctions::GetSkillBase(unsigned short pid, unsigned short skillId) noexcept
{
Player *player;
GET_PLAYER(pid, player, 0);
if (skill >= Skill::Length)
if (skillId >= Skill::Length)
return 0;
return player->npcStats.mSkills[skill].mBase;
return player->npcStats.mSkills[skillId].mBase;
}
int StatsFunctions::GetSkillModifier(unsigned short pid, unsigned short skill) noexcept
int StatsFunctions::GetSkillModifier(unsigned short pid, unsigned short skillId) noexcept
{
Player *player;
GET_PLAYER(pid, player, 0);
if (skill >= Skill::Length)
if (skillId >= Skill::Length)
return 0;
return player->npcStats.mSkills[skill].mMod;
return player->npcStats.mSkills[skillId].mMod;
}
double StatsFunctions::GetSkillProgress(unsigned short pid, unsigned short skill) noexcept
double StatsFunctions::GetSkillProgress(unsigned short pid, unsigned short skillId) noexcept
{
Player *player;
GET_PLAYER(pid, player, 0.0f);
if (skill >= Skill::Length)
if (skillId >= Skill::Length)
return 0;
return player->npcStats.mSkills[skill].mProgress;
return player->npcStats.mSkills[skillId].mProgress;
}
int StatsFunctions::GetSkillIncrease(unsigned short pid, unsigned int attribute) noexcept
int StatsFunctions::GetSkillIncrease(unsigned short pid, unsigned int attributeId) noexcept
{
Player *player;
GET_PLAYER(pid, player, 0);
if (attribute > Attribute::Length)
if (attributeId > Attribute::Length)
return 0;
return player->npcStats.mSkillIncrease[attribute];
return player->npcStats.mSkillIncrease[attributeId];
}
int StatsFunctions::GetBounty(unsigned short pid) noexcept
@ -264,6 +256,14 @@ int StatsFunctions::GetBounty(unsigned short pid) noexcept
return player->npcStats.mBounty;
}
const char *StatsFunctions::GetDeathReason(unsigned short pid) noexcept
{
Player *player;
GET_PLAYER(pid, player, 0);
return player->deathReason.c_str();
}
void StatsFunctions::SetName(unsigned short pid, const char *name) noexcept
{
Player *player;
@ -300,23 +300,23 @@ void StatsFunctions::SetHead(unsigned short pid, const char *head) noexcept
player->npc.mHead = head;
}
void StatsFunctions::SetHairstyle(unsigned short pid, const char *style) noexcept
void StatsFunctions::SetHairstyle(unsigned short pid, const char *hairstyle) noexcept
{
Player *player;
GET_PLAYER(pid, player,);
if (player->npc.mHair == style)
if (player->npc.mHair == hairstyle)
return;
player->npc.mHair = style;
player->npc.mHair = hairstyle;
}
void StatsFunctions::SetIsMale(unsigned short pid, int value) noexcept
void StatsFunctions::SetIsMale(unsigned short pid, int state) noexcept
{
Player *player;
GET_PLAYER(pid, player,);
player->npc.setIsMale(value == true);
player->npc.setIsMale(state == true);
}
void StatsFunctions::SetBirthsign(unsigned short pid, const char *sign) noexcept
@ -402,70 +402,70 @@ void StatsFunctions::SetFatigueCurrent(unsigned short pid, double value) noexcep
player->creatureStats.mDynamic[2].mCurrent = value;
}
void StatsFunctions::SetAttributeBase(unsigned short pid, unsigned short attribute, int value) noexcept
void StatsFunctions::SetAttributeBase(unsigned short pid, unsigned short attributeId, int value) noexcept
{
Player *player;
GET_PLAYER(pid, player,);
if (attribute >= Attribute::Length)
if (attributeId >= Attribute::Length)
return;
player->creatureStats.mAttributes[attribute].mBase = value;
player->creatureStats.mAttributes[attributeId].mBase = value;
}
void StatsFunctions::ClearAttributeModifier(unsigned short pid, unsigned short attribute) noexcept
void StatsFunctions::ClearAttributeModifier(unsigned short pid, unsigned short attributeId) noexcept
{
Player *player;
GET_PLAYER(pid, player,);
if (attribute >= Attribute::Length)
if (attributeId >= Attribute::Length)
return;
player->creatureStats.mAttributes[attribute].mMod = 0;
player->creatureStats.mAttributes[attributeId].mMod = 0;
}
void StatsFunctions::SetSkillBase(unsigned short pid, unsigned short skill, int value) noexcept
void StatsFunctions::SetSkillBase(unsigned short pid, unsigned short skillId, int value) noexcept
{
Player *player;
GET_PLAYER(pid, player,);
if (skill >= Skill::Length)
if (skillId >= Skill::Length)
return;
player->npcStats.mSkills[skill].mBase = value;
player->npcStats.mSkills[skillId].mBase = value;
}
void StatsFunctions::ClearSkillModifier(unsigned short pid, unsigned short skill) noexcept
void StatsFunctions::ClearSkillModifier(unsigned short pid, unsigned short skillId) noexcept
{
Player *player;
GET_PLAYER(pid, player,);
if (skill >= Skill::Length)
if (skillId >= Skill::Length)
return;
player->npcStats.mSkills[skill].mMod = 0;
player->npcStats.mSkills[skillId].mMod = 0;
}
void StatsFunctions::SetSkillProgress(unsigned short pid, unsigned short skill, double value) noexcept
void StatsFunctions::SetSkillProgress(unsigned short pid, unsigned short skillId, double value) noexcept
{
Player *player;
GET_PLAYER(pid, player, );
if (skill >= Skill::Length)
if (skillId >= Skill::Length)
return;
player->npcStats.mSkills[skill].mProgress = value;
player->npcStats.mSkills[skillId].mProgress = value;
}
void StatsFunctions::SetSkillIncrease(unsigned short pid, unsigned int attribute, int value) noexcept
void StatsFunctions::SetSkillIncrease(unsigned short pid, unsigned int attributeId, int value) noexcept
{
Player *player;
GET_PLAYER(pid, player,);
if (attribute > Attribute::Length)
if (attributeId > Attribute::Length)
return;
player->npcStats.mSkillIncrease[attribute] = value;
player->npcStats.mSkillIncrease[attributeId] = value;
}
void StatsFunctions::SetBounty(unsigned short pid, int value) noexcept
@ -476,12 +476,12 @@ void StatsFunctions::SetBounty(unsigned short pid, int value) noexcept
player->npcStats.mBounty = value;
}
void StatsFunctions::SetCharGenStage(unsigned short pid, int start, int end) noexcept
void StatsFunctions::SetCharGenStage(unsigned short pid, int current, int end) noexcept
{
Player *player;
GET_PLAYER(pid, player,);
player->charGenStage.current = start;
player->charGenStage.current = current;
player->charGenStage.end = end;
mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_CHARGEN)->setPlayer(player);

View file

@ -19,7 +19,6 @@
{"GetHair", StatsFunctions::GetHairstyle},\
{"GetIsMale", StatsFunctions::GetIsMale},\
{"GetBirthsign", StatsFunctions::GetBirthsign},\
{"GetDeathReason", StatsFunctions::GetDeathReason},\
\
{"GetLevel", StatsFunctions::GetLevel},\
{"GetLevelProgress", StatsFunctions::GetLevelProgress},\
@ -43,6 +42,8 @@
\
{"GetBounty", StatsFunctions::GetBounty},\
\
{"GetDeathReason", StatsFunctions::GetDeathReason},\
\
{"SetName", StatsFunctions::SetName},\
{"SetRace", StatsFunctions::SetRace},\
{"SetHead", StatsFunctions::SetHead},\
@ -83,46 +84,304 @@
class StatsFunctions
{
public:
/**
* \brief Get the number of attributes.
*
* The number is 8 before any dehardcoding is done in OpenMW.
*
* \return The number of attributes.
*/
static int GetAttributeCount() noexcept;
/**
* \brief Get the number of skills.
*
* The number is 27 before any dehardcoding is done in OpenMW.
*
* \return The number of skills.
*/
static int GetSkillCount() noexcept;
/**
* \brief Get the numerical ID of an attribute with a certain name.
*
* If an invalid name is used, the ID returned is -1
*
* \param name The name of the attribute.
* \return The ID of the attribute.
*/
static int GetAttributeId(const char *name) noexcept;
/**
* \brief Get the numerical ID of a skill with a certain name.
*
* If an invalid name is used, the ID returned is -1
*
* \param name The name of the skill.
* \return The ID of the skill.
*/
static int GetSkillId(const char *name) noexcept;
static const char *GetAttributeName(unsigned short attribute) noexcept;
static const char *GetSkillName(unsigned short skill) noexcept;
/**
* \brief Get the name of the attribute with a certain numerical ID.
*
* If an invalid ID is used, "invalid" is returned.
*
* \param attributeId The ID of the attribute.
* \return The name of the attribute.
*/
static const char *GetAttributeName(unsigned short attributeId) noexcept;
/**
* \brief Get the name of the skill with a certain numerical ID.
*
* If an invalid ID is used, "invalid" is returned.
*
* \param skillId The ID of the skill.
* \return The name of the skill.
*/
static const char *GetSkillName(unsigned short skillId) noexcept;
/**
* \brief Get the name of a player.
*
* \param pid The player ID.
* \return The name of the player.
*/
static const char *GetName(unsigned short pid) noexcept;
static const char *GetRace(unsigned short pid) noexcept;
static const char *GetHead(unsigned short pid) noexcept;
static const char *GetHairstyle(unsigned short pid) noexcept;
static int GetIsMale(unsigned short pid) noexcept;
static const char *GetBirthsign(unsigned short pid) noexcept;
static const char *GetDeathReason(unsigned short pid) noexcept;
/**
* \brief Get the race of a player.
*
* \param pid The player ID.
* \return The race of the player.
*/
static const char *GetRace(unsigned short pid) noexcept;
/**
* \brief Get the head mesh used by a player.
*
* \param pid The player ID.
* \return The head mesh of the player.
*/
static const char *GetHead(unsigned short pid) noexcept;
/**
* \brief Get the hairstyle mesh used by a player.
*
* \param pid The player ID.
* \return The hairstyle mesh of the player.
*/
static const char *GetHairstyle(unsigned short pid) noexcept;
/**
* \brief Check whether a player is male or not.
*
* \param pid The player ID.
* \return Whether the player is male.
*/
static int GetIsMale(unsigned short pid) noexcept;
/**
* \brief Get the birthsign of a player.
*
* \param pid The player ID.
* \return The birthsign of the player.
*/
static const char *GetBirthsign(unsigned short pid) noexcept;
/**
* \brief Get the character level of a player.
*
* \param pid The player ID.
* \return The level of the player.
*/
static int GetLevel(unsigned short pid) noexcept;
/**
* \brief Get the player's progress to their next character level.
*
* \param pid The player ID.
* \return The level progress.
*/
static int GetLevelProgress(unsigned short pid) noexcept;
/**
* \brief Get the base health of the player.
*
* \param pid The player ID.
* \return The base health.
*/
static double GetHealthBase(unsigned short pid) noexcept;
/**
* \brief Get the current health of the player.
*
* \param pid The player ID.
* \return The current health.
*/
static double GetHealthCurrent(unsigned short pid) noexcept;
/**
* \brief Get the base magicka of the player.
*
* \param pid The player ID.
* \return The base magicka.
*/
static double GetMagickaBase(unsigned short pid) noexcept;
/**
* \brief Get the current magicka of the player.
*
* \param pid The player ID.
* \return The current magicka.
*/
static double GetMagickaCurrent(unsigned short pid) noexcept;
/**
* \brief Get the base fatigue of the player.
*
* \param pid The player ID.
* \return The base fatigue.
*/
static double GetFatigueBase(unsigned short pid) noexcept;
/**
* \brief Get the current fatigue of the player.
*
* \param pid The player ID.
* \return The current fatigue.
*/
static double GetFatigueCurrent(unsigned short pid) noexcept;
static int GetAttributeBase(unsigned short pid, unsigned short attribute) noexcept;
static int GetAttributeModifier(unsigned short pid, unsigned short attribute) noexcept;
/**
* \brief Get the base value of a player's attribute.
*
* \param pid The player ID.
* \param attributeId The attribute ID.
* \return The base value of the attribute.
*/
static int GetAttributeBase(unsigned short pid, unsigned short attributeId) noexcept;
static int GetSkillBase(unsigned short pid, unsigned short skill) noexcept;
static int GetSkillModifier(unsigned short pid, unsigned short skill) noexcept;
static double GetSkillProgress(unsigned short pid, unsigned short skill) noexcept;
static int GetSkillIncrease(unsigned short pid, unsigned int pos) noexcept;
/**
* \brief Get the modifier value of a player's attribute.
*
* \param pid The player ID.
* \param attributeId The attribute ID.
* \return The modifier value of the attribute.
*/
static int GetAttributeModifier(unsigned short pid, unsigned short attributeId) noexcept;
/**
* \brief Get the base value of a player's skill.
*
* \param pid The player ID.
* \param skillId The skill ID.
* \return The base value of the skill.
*/
static int GetSkillBase(unsigned short pid, unsigned short skillId) noexcept;
/**
* \brief Get the modifier value of a player's skill.
*
* \param pid The player ID.
* \param skillId The skill ID.
* \return The modifier value of the skill.
*/
static int GetSkillModifier(unsigned short pid, unsigned short skillId) noexcept;
/**
* \brief Get the progress the player has made towards increasing a certain skill by 1.
*
* \param pid The player ID.
* \param skillId The skill ID.
* \return The skill progress.
*/
static double GetSkillProgress(unsigned short pid, unsigned short skillId) noexcept;
/**
* \brief Get the bonus applied to a certain attribute at the next level up as a result
* of associated skill increases.
*
* Although confusing, the term "skill increase" for this is taken from OpenMW itself.
*
* \param pid The player ID.
* \param skillId The attribute ID.
* \return The increase in the attribute caused by skills.
*/
static int GetSkillIncrease(unsigned short pid, unsigned int attributeId) noexcept;
/**
* \brief Get the bounty of the player.
*
* \param pid The player ID.
* \return The bounty.
*/
static int GetBounty(unsigned short pid) noexcept;
/**
* \brief Get the reason for a player's death.
*
* As of now, the reason is either "suicide" or the name of the killer.
*
* \param pid The player ID.
* \return The reason.
*/
static const char *GetDeathReason(unsigned short pid) noexcept;
/**
* \brief Set the name of a player.
*
* \param pid The player ID.
* \param name The new name of the player.
* \return void
*/
static void SetName(unsigned short pid, const char *name) noexcept;
/**
* \brief Set the race of a player.
*
* \param pid The player ID.
* \param race The new race of the player.
* \return void
*/
static void SetRace(unsigned short pid, const char *race) noexcept;
/**
* \brief Set the head mesh used by a player.
*
* \param pid The player ID.
* \param head The new head mesh of the player.
* \return void
*/
static void SetHead(unsigned short pid, const char *head) noexcept;
static void SetHairstyle(unsigned short pid, const char *style) noexcept;
static void SetIsMale(unsigned short pid, int male) noexcept;
/**
* \brief Set the hairstyle mesh used by a player.
*
* \param pid The player ID.
* \param hairstyle The new hairstyle mesh of the player.
* \return void
*/
static void SetHairstyle(unsigned short pid, const char *hairstyle) noexcept;
/**
* \brief Set whether a player is male or not.
*
* \param pid The player ID.
* \param state Whether the player is male.
* \return void
*/
static void SetIsMale(unsigned short pid, int state) noexcept;
/**
* \brief Set the birthsign of a player.
*
* \param pid The player ID.
* \param name The new birthsign of the player.
* \return void
*/
static void SetBirthsign(unsigned short pid, const char *name) noexcept;
/**
@ -138,33 +397,231 @@ public:
*/
static void SetResetStats(unsigned short pid, bool resetStats) noexcept;
/**
* \brief Set the character level of a player.
*
* \param pid The player ID.
* \param value The new level of the player.
* \return void
*/
static void SetLevel(unsigned short pid, int value) noexcept;
/**
* \brief Set the player's progress to their next character level.
*
* \param pid The player ID.
* \param value The new level progress of the player.
* \return void
*/
static void SetLevelProgress(unsigned short pid, int value) noexcept;
/**
* \brief Set the base health of a player.
*
* \param pid The player ID.
* \param name The new base health of the player.
* \return void
*/
static void SetHealthBase(unsigned short pid, double value) noexcept;
/**
* \brief Set the current health of a player.
*
* \param pid The player ID.
* \param name The new current health of the player.
* \return void
*/
static void SetHealthCurrent(unsigned short pid, double value) noexcept;
/**
* \brief Set the base magicka of a player.
*
* \param pid The player ID.
* \param name The new base magicka of the player.
* \return void
*/
static void SetMagickaBase(unsigned short pid, double value) noexcept;
/**
* \brief Set the current magicka of a player.
*
* \param pid The player ID.
* \param name The new current magicka of the player.
* \return void
*/
static void SetMagickaCurrent(unsigned short pid, double value) noexcept;
/**
* \brief Set the base fatigue of a player.
*
* \param pid The player ID.
* \param name The new base fatigue of the player.
* \return void
*/
static void SetFatigueBase(unsigned short pid, double value) noexcept;
/**
* \brief Set the current fatigue of a player.
*
* \param pid The player ID.
* \param name The new current fatigue of the player.
* \return void
*/
static void SetFatigueCurrent(unsigned short pid, double value) noexcept;
static void SetAttributeBase(unsigned short pid, unsigned short attribute, int value) noexcept;
static void ClearAttributeModifier(unsigned short pid, unsigned short attribute) noexcept;
/**
* \brief Set the base value of a player's attribute.
*
* \param pid The player ID.
* \param attributeId The attribute ID.
* \param value The new base value of the player's attribute.
* \return void
*/
static void SetAttributeBase(unsigned short pid, unsigned short attributeId, int value) noexcept;
static void SetSkillBase(unsigned short pid, unsigned short skill, int value) noexcept;
static void ClearSkillModifier(unsigned short pid, unsigned short skill) noexcept;
static void SetSkillProgress(unsigned short pid, unsigned short skill, double value) noexcept;
static void SetSkillIncrease(unsigned short pid, unsigned int pos, int value) noexcept;
/**
* \brief Clear the modifier value of a player's attribute.
*
* There's no way to set a modifier to a specific value because it can come from
* multiple different sources, but clearing it is a straightforward process that
* dispels associated effects on a client and, if necessary, unequips associated
* items.
*
* \param pid The player ID.
* \param attributeId The attribute ID.
* \return void
*/
static void ClearAttributeModifier(unsigned short pid, unsigned short attributeId) noexcept;
/**
* \brief Set the base value of a player's skill.
*
* \param pid The player ID.
* \param skillId The skill ID.
* \param value The new base value of the player's skill.
* \return void
*/
static void SetSkillBase(unsigned short pid, unsigned short skillId, int value) noexcept;
/**
* \brief Clear the modifier value of a player's skill.
*
* There's no way to set a modifier to a specific value because it can come from
* multiple different sources, but clearing it is a straightforward process that
* dispels associated effects on a client and, if necessary, unequips associated
* items.
*
* \param pid The player ID.
* \param skillId The skill ID.
* \return void
*/
static void ClearSkillModifier(unsigned short pid, unsigned short skillId) noexcept;
/**
* \brief Set the progress the player has made towards increasing a certain skill by 1.
*
* \param pid The player ID.
* \param skillId The skill ID.
* \param value The progress value.
* \return void
*/
static void SetSkillProgress(unsigned short pid, unsigned short skillId, double value) noexcept;
/**
* \brief Set the bonus applied to a certain attribute at the next level up as a result
* of associated skill increases.
*
* Although confusing, the term "skill increase" for this is taken from OpenMW itself.
*
* \param pid The player ID.
* \param skillId The attribute ID.
* \param value The increase in the attribute caused by skills.
* \return void
*/
static void SetSkillIncrease(unsigned short pid, unsigned int attributeId, int value) noexcept;
/**
* \brief Set the bounty of a player.
*
* \param pid The player ID.
* \param value The new bounty.
* \return void
*/
static void SetBounty(unsigned short pid, int value) noexcept;
static void SetCharGenStage(unsigned short pid, int start, int end) noexcept;
/**
* \brief Set the current and ending stages of character generation for a player.
*
* This is used to repeat part of character generation or to only go through part of it.
*
* \param pid The player ID.
* \param current The current stage.
* \param end The ending stage.
* \return void
*/
static void SetCharGenStage(unsigned short pid, int current, int end) noexcept;
/**
* \brief Send a PlayerBaseInfo packet with a player's name, race, head mesh,
* hairstyle mesh, birthsign and stat reset state.
*
* It is always sent to all players.
*
* \param pid The player ID.
* \return void
*/
static void SendBaseInfo(unsigned short pid) noexcept;
/**
* \brief Send a PlayerStatsDynamic packet with a player's dynamic stats (health,
* magicka and fatigue).
*
* It is always sent to all players.
*
* \param pid The player ID.
* \return void
*/
static void SendStatsDynamic(unsigned short pid) noexcept;
/**
* \brief Send a PlayerAttribute packet with a player's attributes.
*
* It is always sent to all players.
*
* \param pid The player ID.
* \return void
*/
static void SendAttributes(unsigned short pid) noexcept;
/**
* \brief Send a PlayerSkill packet with a player's skills, skill increases, and
* progress towards the next level up.
*
* It is always sent to all players.
*
* \param pid The player ID.
* \return void
*/
static void SendSkills(unsigned short pid) noexcept;
/**
* \brief Send a PlayerLevel packet with a player's character level.
*
* It is always sent to all players.
*
* \param pid The player ID.
* \return void
*/
static void SendLevel(unsigned short pid) noexcept;
/**
* \brief Send a PlayerBounty packet with a player's bounty.
*
* It is always sent to all players.
*
* \param pid The player ID.
* \return void
*/
static void SendBounty(unsigned short pid) noexcept;
};

View file

@ -154,9 +154,9 @@ void ScriptFunctions::SetHostname(const char *name) noexcept
mwmp::Networking::getPtr()->getMasterClient()->SetHostname(name);
}
void ScriptFunctions::SetServerPassword(const char *passw) noexcept
void ScriptFunctions::SetServerPassword(const char *password) noexcept
{
mwmp::Networking::getPtr()->setServerPassword(passw);
mwmp::Networking::getPtr()->setServerPassword(password);
}
void ScriptFunctions::SetRuleString(const char *key, const char *value) noexcept

View file

@ -45,43 +45,202 @@ class ScriptFunctions
public:
static void GetArguments(std::vector<boost::any> &params, va_list args, const std::string &def);
static void StopServer(int code) noexcept;
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 Shut down the server.
*
* \param code The shutdown code.
* \return void
*/
static void StopServer(int code) noexcept;
/**
* \brief Send a message to a certain player.
*
* \param pid The player ID.
* \param message The contents of the message.
* \param broadcast Whether the message should also be sent to other players.
* \return void
*/
static void SendMessage(unsigned short pid, const char *message, bool broadcast) noexcept;
/**
* \brief Remove all messages from chat for a certain player.
*
* \param pid The player ID.
* \return void
*/
static void CleanChatByPid(unsigned short pid);
/**
* \brief Remove all messages from chat for everyone on the server.
*
* \return void
*/
static void CleanChat();
/**
* \brief Create timer
* \param callback
* \param msec
* \return return timer id
* \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;
/**
* \brief Kick a certain player from the server.
*
* \param pid The player ID.
* \return void
*/
static void Kick(unsigned short pid) noexcept;
/**
* \brief Ban a certain IP address from the server.
*
* \param ipAddress The IP address.
* \return void
*/
static void BanAddress(const char *ipAddress) noexcept;
/**
* \brief Unban a certain IP address from the server.
*
* \param ipAddress The IP address.
* \return void
*/
static void UnbanAddress(const char *ipAddress) noexcept;
/**
* \brief Get the TES3MP version of the server.
*
* \return The server version.
*/
static const char *GetServerVersion() noexcept;
/**
* \brief Get the protocol version of the server.
*
* \return The protocol version.
*/
static const char *GetProtocolVersion() noexcept;
/**
* \brief Get the average ping of a certain player.
*
* \param pid The player ID.
* \return The average ping.
*/
static int GetAvgPing(unsigned short pid) noexcept;
/**
* \brief Get the IP address of a certain player.
*
* \param pid The player ID.
* \return The IP address.
*/
static const char* GetIP(unsigned short pid) noexcept;
/**
* \brief Set the game mode of the server, as displayed in the server browser.
*
* \param name The new game mode.
* \return void
*/
static void SetModname(const char* name) noexcept;
/**
* \brief Set the name of the server, as displayed in the server browser.
*
* \param name The new name.
* \return void
*/
static void SetHostname(const char* name) noexcept;
/**
* \brief Set the password required to join the server.
*
* \param password The password.
* \return void
*/
static void SetServerPassword(const char *passw) noexcept;
/**
* \brief Set a rule string for the server details displayed in the server browser.
*
* \param key The name of the rule.
* \param value The string value of the rule.
* \return void
*/
static void SetRuleString(const char *key, const char *value) noexcept;
/**
* \brief Set a rule value for the server details displayed in the server browser.
*
* \param key The name of the rule.
* \param value The numerical value of the rule.
* \return void
*/
static void SetRuleValue(const char *key, double value) noexcept;
static constexpr ScriptFunctionData functions[]{