[Server] Add script functions that get casters of players' active spells

pull/593/head
David Cernat 3 years ago
parent 26033ff7e7
commit bf17bfe1d9

@ -180,10 +180,10 @@ const char* SpellFunctions::GetSpellsActiveDisplayName(unsigned short pid, unsig
bool SpellFunctions::GetSpellsActiveStackingState(unsigned short pid, unsigned int index) noexcept bool SpellFunctions::GetSpellsActiveStackingState(unsigned short pid, unsigned int index) noexcept
{ {
Player* player; Player* player;
GET_PLAYER(pid, player, ""); GET_PLAYER(pid, player, false);
if (index >= player->spellsActiveChanges.activeSpells.size()) if (index >= player->spellsActiveChanges.activeSpells.size())
return "invalid"; return false;
return player->spellsActiveChanges.activeSpells.at(index).isStackingSpell; return player->spellsActiveChanges.activeSpells.at(index).isStackingSpell;
} }
@ -254,6 +254,66 @@ double SpellFunctions::GetSpellsActiveEffectTimeLeft(unsigned short pid, unsigne
return player->spellsActiveChanges.activeSpells.at(spellIndex).params.mEffects.at(effectIndex).mTimeLeft; return player->spellsActiveChanges.activeSpells.at(spellIndex).params.mEffects.at(effectIndex).mTimeLeft;
} }
bool SpellFunctions::DoesSpellsActiveHavePlayerCaster(unsigned short pid, unsigned int index) noexcept
{
Player* player;
GET_PLAYER(pid, player, false);
if (index >= player->spellsActiveChanges.activeSpells.size())
return false;
return player->spellsActiveChanges.activeSpells.at(index).caster.isPlayer;
}
int SpellFunctions::GetSpellsActiveCasterPid(unsigned short pid, unsigned int index) noexcept
{
Player* player;
GET_PLAYER(pid, player, -1);
if (index >= player->spellsActiveChanges.activeSpells.size())
return -1;
Player* caster = Players::getPlayer(player->spellsActiveChanges.activeSpells.at(index).caster.guid);
if (caster != nullptr)
return caster->getId();
return -1;
}
const char* SpellFunctions::GetSpellsActiveCasterRefId(unsigned short pid, unsigned int index) noexcept
{
Player* player;
GET_PLAYER(pid, player, "");
if (index >= player->spellsActiveChanges.activeSpells.size())
return "";
return player->spellsActiveChanges.activeSpells.at(index).caster.refId.c_str();
}
unsigned int SpellFunctions::GetSpellsActiveCasterRefNum(unsigned short pid, unsigned int index) noexcept
{
Player* player;
GET_PLAYER(pid, player, 0);
if (index >= player->spellsActiveChanges.activeSpells.size())
return 0;
return player->spellsActiveChanges.activeSpells.at(index).caster.refNum;
}
unsigned int SpellFunctions::GetSpellsActiveCasterMpNum(unsigned short pid, unsigned int index) noexcept
{
Player* player;
GET_PLAYER(pid, player, 0);
if (index >= player->spellsActiveChanges.activeSpells.size())
return 0;
return player->spellsActiveChanges.activeSpells.at(index).caster.mpNum;
}
const char* SpellFunctions::GetCooldownSpellId(unsigned short pid, unsigned int index) noexcept const char* SpellFunctions::GetCooldownSpellId(unsigned short pid, unsigned int index) noexcept
{ {
Player* player; Player* player;

@ -2,42 +2,48 @@
#define OPENMW_SPELLAPI_HPP #define OPENMW_SPELLAPI_HPP
#define SPELLAPI \ #define SPELLAPI \
{"ClearSpellbookChanges", SpellFunctions::ClearSpellbookChanges},\ {"ClearSpellbookChanges", SpellFunctions::ClearSpellbookChanges},\
{"ClearSpellsActiveChanges", SpellFunctions::ClearSpellsActiveChanges},\ {"ClearSpellsActiveChanges", SpellFunctions::ClearSpellsActiveChanges},\
{"ClearCooldownChanges", SpellFunctions::ClearCooldownChanges},\ {"ClearCooldownChanges", SpellFunctions::ClearCooldownChanges},\
\ \
{"GetSpellbookChangesSize", SpellFunctions::GetSpellbookChangesSize},\ {"GetSpellbookChangesSize", SpellFunctions::GetSpellbookChangesSize},\
{"GetSpellbookChangesAction", SpellFunctions::GetSpellbookChangesAction},\ {"GetSpellbookChangesAction", SpellFunctions::GetSpellbookChangesAction},\
{"GetSpellsActiveChangesSize", SpellFunctions::GetSpellsActiveChangesSize},\ {"GetSpellsActiveChangesSize", SpellFunctions::GetSpellsActiveChangesSize},\
{"GetSpellsActiveChangesAction", SpellFunctions::GetSpellsActiveChangesAction},\ {"GetSpellsActiveChangesAction", SpellFunctions::GetSpellsActiveChangesAction},\
{"GetCooldownChangesSize", SpellFunctions::GetCooldownChangesSize},\ {"GetCooldownChangesSize", SpellFunctions::GetCooldownChangesSize},\
\ \
{"SetSpellbookChangesAction", SpellFunctions::SetSpellbookChangesAction},\ {"SetSpellbookChangesAction", SpellFunctions::SetSpellbookChangesAction},\
{"SetSpellsActiveChangesAction", SpellFunctions::SetSpellsActiveChangesAction},\ {"SetSpellsActiveChangesAction", SpellFunctions::SetSpellsActiveChangesAction},\
\ \
{"AddSpell", SpellFunctions::AddSpell},\ {"AddSpell", SpellFunctions::AddSpell},\
{"AddSpellActive", SpellFunctions::AddSpellActive},\ {"AddSpellActive", SpellFunctions::AddSpellActive},\
{"AddSpellActiveEffect", SpellFunctions::AddSpellActiveEffect},\ {"AddSpellActiveEffect", SpellFunctions::AddSpellActiveEffect},\
{"AddCooldownSpell", SpellFunctions::AddCooldownSpell},\ {"AddCooldownSpell", SpellFunctions::AddCooldownSpell},\
\ \
{"GetSpellId", SpellFunctions::GetSpellId},\ {"GetSpellId", SpellFunctions::GetSpellId},\
{"GetSpellsActiveId", SpellFunctions::GetSpellsActiveId},\ {"GetSpellsActiveId", SpellFunctions::GetSpellsActiveId},\
{"GetSpellsActiveDisplayName", SpellFunctions::GetSpellsActiveDisplayName},\ {"GetSpellsActiveDisplayName", SpellFunctions::GetSpellsActiveDisplayName},\
{"GetSpellsActiveStackingState", SpellFunctions::GetSpellsActiveStackingState},\ {"GetSpellsActiveStackingState", SpellFunctions::GetSpellsActiveStackingState},\
{"GetSpellsActiveEffectCount", SpellFunctions::GetSpellsActiveEffectCount},\ {"GetSpellsActiveEffectCount", SpellFunctions::GetSpellsActiveEffectCount},\
{"GetSpellsActiveEffectId", SpellFunctions::GetSpellsActiveEffectId},\ {"GetSpellsActiveEffectId", SpellFunctions::GetSpellsActiveEffectId},\
{"GetSpellsActiveEffectArg", SpellFunctions::GetSpellsActiveEffectArg},\ {"GetSpellsActiveEffectArg", SpellFunctions::GetSpellsActiveEffectArg},\
{"GetSpellsActiveEffectMagnitude", SpellFunctions::GetSpellsActiveEffectMagnitude},\ {"GetSpellsActiveEffectMagnitude", SpellFunctions::GetSpellsActiveEffectMagnitude},\
{"GetSpellsActiveEffectDuration", SpellFunctions::GetSpellsActiveEffectDuration},\ {"GetSpellsActiveEffectDuration", SpellFunctions::GetSpellsActiveEffectDuration},\
{"GetSpellsActiveEffectTimeLeft", SpellFunctions::GetSpellsActiveEffectTimeLeft},\ {"GetSpellsActiveEffectTimeLeft", SpellFunctions::GetSpellsActiveEffectTimeLeft},\
\ \
{"GetCooldownSpellId", SpellFunctions::GetCooldownSpellId},\ {"DoesSpellsActiveHavePlayerCaster", SpellFunctions::DoesSpellsActiveHavePlayerCaster},\
{"GetCooldownStartDay", SpellFunctions::GetCooldownStartDay},\ {"GetSpellsActiveCasterPid", SpellFunctions::GetSpellsActiveCasterPid},\
{"GetCooldownStartHour", SpellFunctions::GetCooldownStartHour},\ {"GetSpellsActiveCasterRefId", SpellFunctions::GetSpellsActiveCasterRefId},\
{"GetSpellsActiveCasterRefNum", SpellFunctions::GetSpellsActiveCasterRefNum},\
{"GetSpellsActiveCasterMpNum", SpellFunctions::GetSpellsActiveCasterMpNum},\
\ \
{"SendSpellbookChanges", SpellFunctions::SendSpellbookChanges},\ {"GetCooldownSpellId", SpellFunctions::GetCooldownSpellId},\
{"SendSpellsActiveChanges", SpellFunctions::SendSpellsActiveChanges},\ {"GetCooldownStartDay", SpellFunctions::GetCooldownStartDay},\
{"SendCooldownChanges", SpellFunctions::SendCooldownChanges},\ {"GetCooldownStartHour", SpellFunctions::GetCooldownStartHour},\
\
{"SendSpellbookChanges", SpellFunctions::SendSpellbookChanges},\
{"SendSpellsActiveChanges", SpellFunctions::SendSpellsActiveChanges},\
{"SendCooldownChanges", SpellFunctions::SendCooldownChanges},\
\ \
{"InitializeSpellbookChanges", SpellFunctions::InitializeSpellbookChanges} {"InitializeSpellbookChanges", SpellFunctions::InitializeSpellbookChanges}
@ -273,6 +279,52 @@ public:
*/ */
static double GetSpellsActiveEffectTimeLeft(unsigned short pid, unsigned int spellIndex, unsigned int effectIndex) noexcept; static double GetSpellsActiveEffectTimeLeft(unsigned short pid, unsigned int spellIndex, unsigned int effectIndex) noexcept;
/**
* \brief Check whether the spell at a certain index in a player's latest spells active changes has a player
* as its caster.
*
* \param pid The player ID whose spells active changes should be used.
* \param index The index of the spell.
* \return Whether a player is the caster of the spell.
*/
static bool DoesSpellsActiveHavePlayerCaster(unsigned short pid, unsigned int index) noexcept;
/**
* \brief Get the player ID of the caster of the spell at a certain index in a player's latest spells active changes.
*
* \param pid The player ID whose spells active changes should be used.
* \param index The index of the spell.
* \return The player ID of the caster.
*/
static int GetSpellsActiveCasterPid(unsigned short pid, unsigned int index) noexcept;
/**
* \brief Get the refId of the actor caster of the spell at a certain index in a player's latest spells active changes.
*
* \param pid The player ID whose spells active changes should be used.
* \param index The index of the spell.
* \return The refId of the caster.
*/
static const char* GetSpellsActiveCasterRefId(unsigned short pid, unsigned int index) noexcept;
/**
* \brief Get the refNum of the actor caster of the spell at a certain index in a player's latest spells active changes.
*
* \param pid The player ID whose spells active changes should be used.
* \param index The index of the spell.
* \return The refNum of the caster.
*/
static unsigned int GetSpellsActiveCasterRefNum(unsigned short pid, unsigned int index) noexcept;
/**
* \brief Get the mpNum of the actor caster of the spell at a certain index in a player's latest spells active changes.
*
* \param pid The player ID whose spells active changes should be used.
* \param index The index of the spell.
* \return The mpNum of the caster.
*/
static unsigned int GetSpellsActiveCasterMpNum(unsigned short pid, unsigned int index) noexcept;
/** /**
* \brief Get the spell id at a certain index in a player's latest cooldown changes. * \brief Get the spell id at a certain index in a player's latest cooldown changes.
* *

Loading…
Cancel
Save