add servicesOffered to npc and creature records

macos_ci_fix
Zackhasacat 1 year ago
parent a1828eec29
commit 9f80d68795

@ -1,6 +1,7 @@
#include "types.hpp"
#include <components/esm3/loadcrea.hpp>
#include <components/esm3/loadnpc.hpp>
#include <components/lua/luastate.hpp>
#include <components/misc/resourcehelpers.hpp>
#include <components/resource/resourcesystem.hpp>
@ -48,5 +49,51 @@ namespace MWLua
record["soulValue"] = sol::readonly_property([](const ESM::Creature& rec) -> int { return rec.mData.mSoul; });
record["type"] = sol::readonly_property([](const ESM::Creature& rec) -> int { return rec.mData.mType; });
record["baseGold"] = sol::readonly_property([](const ESM::Creature& rec) -> int { return rec.mData.mGold; });
record["servicesOffered"] = sol::readonly_property([](const ESM::Creature& rec) {
std::vector<std::string> providedServices;
int mServices = rec.mAiData.mServices;
if (mServices & ESM::NPC::Spells)
providedServices.push_back("Spells");
if (mServices & ESM::NPC::Spellmaking)
providedServices.push_back("Spellmaking");
if (mServices & ESM::NPC::Enchanting)
providedServices.push_back("Enchanting");
if (mServices & ESM::NPC::Repair)
providedServices.push_back("Repair");
if (mServices & ESM::NPC::AllItems)
providedServices.push_back("Barter");
if (mServices & ESM::NPC::Weapon)
providedServices.push_back("Weapon");
if (mServices & ESM::NPC::Armor)
providedServices.push_back("Armor");
if (mServices & ESM::NPC::Clothing)
providedServices.push_back("Clothing");
if (mServices & ESM::NPC::Books)
providedServices.push_back("Books");
if (mServices & ESM::NPC::Ingredients)
providedServices.push_back("Ingredients");
if (mServices & ESM::NPC::Picks)
providedServices.push_back("Picks");
if (mServices & ESM::NPC::Probes)
providedServices.push_back("Probes");
if (mServices & ESM::NPC::Lights)
providedServices.push_back("Lights");
if (mServices & ESM::NPC::Apparatus)
providedServices.push_back("Apparatus");
if (mServices & ESM::NPC::RepairItem)
providedServices.push_back("RepairItem");
if (mServices & ESM::NPC::Misc)
providedServices.push_back("Misc");
if (mServices & ESM::NPC::Potions)
providedServices.push_back("Potions");
if (mServices & ESM::NPC::MagicItems)
providedServices.push_back("MagicItems");
if (rec.getTransport().size() > 0)
providedServices.push_back("Travel");
return providedServices;
});
}
}

@ -3,6 +3,7 @@
#include <components/esm3/loadnpc.hpp>
#include <components/lua/luastate.hpp>
#include "apps/openmw/mwworld/worldmodel.hpp"
#include <apps/openmw/mwbase/environment.hpp>
#include <apps/openmw/mwbase/mechanicsmanager.hpp>
#include <apps/openmw/mwbase/world.hpp>
@ -57,6 +58,54 @@ namespace MWLua
else
throw std::runtime_error("NPC or Player expected");
};
record["servicesOffered"] = sol::readonly_property([](const ESM::NPC& rec) {
std::vector<std::string> providedServices;
int mServices = rec.mAiData.mServices;
if (mServices & ESM::NPC::Spells)
providedServices.push_back("Spells");
if (mServices & ESM::NPC::Spellmaking)
providedServices.push_back("Spellmaking");
if (mServices & ESM::NPC::Enchanting)
providedServices.push_back("Enchanting");
if (mServices & ESM::NPC::Training)
providedServices.push_back("Training");
if (mServices & ESM::NPC::Repair)
providedServices.push_back("Repair");
if (mServices & ESM::NPC::AllItems)
providedServices.push_back("Barter");
if (mServices & ESM::NPC::Weapon)
providedServices.push_back("Weapon");
if (mServices & ESM::NPC::Armor)
providedServices.push_back("Armor");
if (mServices & ESM::NPC::Clothing)
providedServices.push_back("Clothing");
if (mServices & ESM::NPC::Books)
providedServices.push_back("Books");
if (mServices & ESM::NPC::Ingredients)
providedServices.push_back("Ingredients");
if (mServices & ESM::NPC::Picks)
providedServices.push_back("Picks");
if (mServices & ESM::NPC::Probes)
providedServices.push_back("Probes");
if (mServices & ESM::NPC::Lights)
providedServices.push_back("Lights");
if (mServices & ESM::NPC::Apparatus)
providedServices.push_back("Apparatus");
if (mServices & ESM::NPC::RepairItem)
providedServices.push_back("RepairItem");
if (mServices & ESM::NPC::Misc)
providedServices.push_back("Misc");
if (mServices & ESM::NPC::Potions)
providedServices.push_back("Potions");
if (mServices & ESM::NPC::MagicItems)
providedServices.push_back("MagicItems");
if (rec.getTransport().size() > 0)
providedServices.push_back("Travel");
return providedServices;
});
npc["getDisposition"] = [](const Object& o, const Object& player) -> int {
if (player.ptr() != MWBase::Environment::get().getWorld()->getPlayerPtr())

@ -701,6 +701,7 @@
-- @field #number soulValue The soul value of the creature record
-- @field #number type The @{#Creature.TYPE} of the creature
-- @field #number baseGold The base barter gold of the creature
-- @field #list<#string> servicesOffered The services of the creature, in a table. Possible entries are: Spells, Spellmaking, Enchanting, Repair, Barter, Weapon, Armor, Clothing, Books, Ingredients, Picks, Probes, Lights, Apparatus, RepairItems, Misc, Potions, MagicItems, Travel.
--- @{#NPC} functions
@ -750,6 +751,7 @@
-- @field #number baseGold The base barter gold of the NPC
-- @field #number baseDisposition NPC's starting disposition
-- @field #bool isMale The gender setting of the NPC
-- @field #list<#string> servicesOffered The services of the creature, in a table. Possible entries are: Spells, Spellmaking, Enchanting, Training, Repair, Barter, Weapon, Armor, Clothing, Books, Ingredients, Picks, Probes, Lights, Apparatus, RepairItems, Misc, Potions, MagicItems, Travel.
--------------------------------------------------------------------------------

Loading…
Cancel
Save