[General] Allow setting of AI fight & dynamic stats in record packets

Additionally, allow the setting of the Autocalc flag for an NPC record based on an existing record.
pull/471/head
David Cernat 6 years ago
parent d03722b3f4
commit 888e1dfff8

@ -719,6 +719,10 @@ void RecordsDynamicFunctions::SetRecordHealth(int health) noexcept
tempArmor.data.mData.mHealth = health;
else if (writeRecordsType == mwmp::RECORD_TYPE::WEAPON)
tempWeapon.data.mData.mHealth = health;
else if (writeRecordsType == mwmp::RECORD_TYPE::CREATURE)
tempCreature.data.mData.mHealth = health;
else if (writeRecordsType == mwmp::RECORD_TYPE::NPC)
tempNpc.data.mNpdt.mHealth = health;
else
{
LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, "Tried to set health for record type %i which lacks that property", writeRecordsType);
@ -971,6 +975,57 @@ void RecordsDynamicFunctions::SetRecordLevel(int level) noexcept
tempOverrides.hasLevel = true;
}
void RecordsDynamicFunctions::SetRecordMagicka(int magicka) noexcept
{
unsigned short writeRecordsType = WorldstateFunctions::writeWorldstate.recordsType;
if (writeRecordsType == mwmp::RECORD_TYPE::CREATURE)
tempCreature.data.mData.mMana = magicka;
else if (writeRecordsType == mwmp::RECORD_TYPE::NPC)
tempNpc.data.mNpdt.mMana = magicka;
else
{
LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, "Tried to set magicka for record type %i which lacks that property", writeRecordsType);
return;
}
tempOverrides.hasMagicka = true;
}
void RecordsDynamicFunctions::SetRecordFatigue(int fatigue) noexcept
{
unsigned short writeRecordsType = WorldstateFunctions::writeWorldstate.recordsType;
if (writeRecordsType == mwmp::RECORD_TYPE::CREATURE)
tempCreature.data.mData.mFatigue = fatigue;
else if (writeRecordsType == mwmp::RECORD_TYPE::NPC)
tempNpc.data.mNpdt.mFatigue = fatigue;
else
{
LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, "Tried to set fatigue for record type %i which lacks that property", writeRecordsType);
return;
}
tempOverrides.hasFatigue = true;
}
void RecordsDynamicFunctions::SetRecordAiFight(int aiFight) noexcept
{
unsigned short writeRecordsType = WorldstateFunctions::writeWorldstate.recordsType;
if (writeRecordsType == mwmp::RECORD_TYPE::CREATURE)
tempCreature.data.mAiData.mFight = aiFight;
else if (writeRecordsType == mwmp::RECORD_TYPE::NPC)
tempNpc.data.mAiData.mFight = aiFight;
else
{
LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, "Tried to set AI fight for record type %i which lacks that property", writeRecordsType);
return;
}
tempOverrides.hasAiFight = true;
}
void RecordsDynamicFunctions::SetRecordIdByIndex(unsigned int index, const char* id) noexcept
{
unsigned short writeRecordsType = WorldstateFunctions::writeWorldstate.recordsType;

@ -80,6 +80,9 @@
{"SetRecordFaction", RecordsDynamicFunctions::SetRecordFaction},\
\
{"SetRecordLevel", RecordsDynamicFunctions::SetRecordLevel},\
{"SetRecordMagicka", RecordsDynamicFunctions::SetRecordMagicka},\
{"SetRecordFatigue", RecordsDynamicFunctions::SetRecordFatigue},\
{"SetRecordAiFight", RecordsDynamicFunctions::SetRecordAiFight},\
\
{"SetRecordIdByIndex", RecordsDynamicFunctions::SetRecordIdByIndex},\
{"SetRecordEnchantmentIdByIndex", RecordsDynamicFunctions::SetRecordEnchantmentIdByIndex},\
@ -677,11 +680,38 @@ public:
* \brief Set the level of the temporary record stored on the server for the
* currently specified record type.
*
* \param value The level of the record.
* \param level The level of the record.
* \return void
*/
static void SetRecordLevel(int level) noexcept;
/**
* \brief Set the magicka of the temporary record stored on the server for the
* currently specified record type.
*
* \param magicka The magicka of the record.
* \return void
*/
static void SetRecordMagicka(int magicka) noexcept;
/**
* \brief Set the fatigue of the temporary record stored on the server for the
* currently specified record type.
*
* \param fatigue The fatigue of the record.
* \return void
*/
static void SetRecordFatigue(int fatigue) noexcept;
/**
* \brief Set the AI fight value of the temporary record stored on the server for the
* currently specified record type.
*
* \param aiFight The AI fight value of the record.
* \return void
*/
static void SetRecordAiFight(int aiFight) noexcept;
/**
* \brief Set the id of the record at a certain index in the records stored on the server.
*

@ -139,6 +139,18 @@ void RecordHelper::overrideCreatureRecord(const mwmp::CreatureRecord& record)
if (record.baseOverrides.hasLevel)
finalData.mData.mLevel = recordData.mData.mLevel;
if (record.baseOverrides.hasHealth)
finalData.mData.mHealth = recordData.mData.mHealth;
if (record.baseOverrides.hasMagicka)
finalData.mData.mMana = recordData.mData.mMana;
if (record.baseOverrides.hasFatigue)
finalData.mData.mFatigue = recordData.mData.mFatigue;
if (record.baseOverrides.hasAiFight)
finalData.mAiData.mFight = recordData.mAiData.mFight;
if (record.baseOverrides.hasFlags)
finalData.mFlags = recordData.mFlags;
@ -228,9 +240,31 @@ void RecordHelper::overrideNpcRecord(const mwmp::NpcRecord& record)
if (record.baseOverrides.hasLevel)
finalData.mNpdt.mLevel = recordData.mNpdt.mLevel;
if (record.baseOverrides.hasHealth)
finalData.mNpdt.mHealth = recordData.mNpdt.mHealth;
if (record.baseOverrides.hasMagicka)
finalData.mNpdt.mMana = recordData.mNpdt.mMana;
if (record.baseOverrides.hasFatigue)
finalData.mNpdt.mFatigue = recordData.mNpdt.mFatigue;
if (record.baseOverrides.hasAiFight)
finalData.mAiData.mFight = recordData.mAiData.mFight;
if (record.baseOverrides.hasFlags)
finalData.mFlags = recordData.mFlags;
if (record.baseOverrides.hasAutoCalc)
{
finalData.mNpdtType = recordData.mNpdtType;
if ((recordData.mFlags & ESM::NPC::Autocalc) != 0)
finalData.mFlags |= ESM::NPC::Autocalc;
else
finalData.mFlags &= ~ESM::NPC::Autocalc;
}
if (!record.inventoryBaseId.empty() && doesNpcRecordExist(record.inventoryBaseId))
finalData.mInventory.mList = world->getStore().get<ESM::NPC>().search(record.inventoryBaseId)->mInventory.mList;
else if (record.baseOverrides.hasInventory)

@ -88,6 +88,9 @@ namespace mwmp
bool hasFaction = false;
bool hasLevel = false;
bool hasMagicka = false;
bool hasFatigue = false;
bool hasAiFight = false;
};
struct ArmorRecord

@ -176,6 +176,10 @@ void PacketRecordDynamic::Packet(RakNet::BitStream *bs, bool send)
RW(recordData.mModel, send, true);
RW(recordData.mData.mType, send);
RW(recordData.mData.mLevel, send);
RW(recordData.mData.mHealth, send);
RW(recordData.mData.mMana, send);
RW(recordData.mData.mFatigue, send);
RW(recordData.mAiData.mFight, send);
RW(recordData.mFlags, send);
RW(recordData.mScript, send, true);
ProcessInventoryList(record.inventory, recordData.mInventory, send);
@ -187,6 +191,10 @@ void PacketRecordDynamic::Packet(RakNet::BitStream *bs, bool send)
RW(overrides.hasModel, send);
RW(overrides.hasSubtype, send);
RW(overrides.hasLevel, send);
RW(overrides.hasHealth, send);
RW(overrides.hasMagicka, send);
RW(overrides.hasFatigue, send);
RW(overrides.hasAiFight, send);
RW(overrides.hasFlags, send);
RW(overrides.hasScript, send);
RW(overrides.hasInventory, send);
@ -212,6 +220,10 @@ void PacketRecordDynamic::Packet(RakNet::BitStream *bs, bool send)
RW(recordData.mFaction, send, true);
RW(recordData.mScript, send, true);
RW(recordData.mNpdt.mLevel, send);
RW(recordData.mNpdt.mHealth, send);
RW(recordData.mNpdt.mMana, send);
RW(recordData.mNpdt.mFatigue, send);
RW(recordData.mAiData.mFight, send);
RW(recordData.mNpdtType, send);
ProcessInventoryList(record.inventory, recordData.mInventory, send);
@ -227,6 +239,11 @@ void PacketRecordDynamic::Packet(RakNet::BitStream *bs, bool send)
RW(overrides.hasFaction, send);
RW(overrides.hasScript, send);
RW(overrides.hasLevel, send);
RW(overrides.hasHealth, send);
RW(overrides.hasMagicka, send);
RW(overrides.hasFatigue, send);
RW(overrides.hasAiFight, send);
RW(overrides.hasAutoCalc, send);
RW(overrides.hasInventory, send);
}
}

Loading…
Cancel
Save