|
|
@ -54,7 +54,7 @@ namespace
|
|
|
|
if (it != self->mStatsCache.end())
|
|
|
|
if (it != self->mStatsCache.end())
|
|
|
|
return it->second;
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sol::make_object(context.mLua->sol(), getter(obj.ptr()));
|
|
|
|
return sol::make_object(context.mLua->unsafeState(), getter(obj.ptr()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -531,11 +531,12 @@ namespace MWLua
|
|
|
|
{
|
|
|
|
{
|
|
|
|
void addActorStatsBindings(sol::table& actor, const Context& context)
|
|
|
|
void addActorStatsBindings(sol::table& actor, const Context& context)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
sol::table stats(context.mLua->sol(), sol::create);
|
|
|
|
sol::state_view lua = context.sol();
|
|
|
|
|
|
|
|
sol::table stats(lua, sol::create);
|
|
|
|
actor["stats"] = LuaUtil::makeReadOnly(stats);
|
|
|
|
actor["stats"] = LuaUtil::makeReadOnly(stats);
|
|
|
|
|
|
|
|
|
|
|
|
auto skillIncreasesForAttributeStatsT
|
|
|
|
auto skillIncreasesForAttributeStatsT
|
|
|
|
= context.mLua->sol().new_usertype<SkillIncreasesForAttributeStats>("SkillIncreasesForAttributeStats");
|
|
|
|
= lua.new_usertype<SkillIncreasesForAttributeStats>("SkillIncreasesForAttributeStats");
|
|
|
|
for (const auto& attribute : MWBase::Environment::get().getESMStore()->get<ESM::Attribute>())
|
|
|
|
for (const auto& attribute : MWBase::Environment::get().getESMStore()->get<ESM::Attribute>())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
skillIncreasesForAttributeStatsT[ESM::RefId(attribute.mId).serializeText()] = sol::property(
|
|
|
|
skillIncreasesForAttributeStatsT[ESM::RefId(attribute.mId).serializeText()] = sol::property(
|
|
|
@ -546,8 +547,7 @@ namespace MWLua
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// ESM::Class::specializationIndexToLuaId.at(rec.mData.mSpecialization)
|
|
|
|
// ESM::Class::specializationIndexToLuaId.at(rec.mData.mSpecialization)
|
|
|
|
auto skillIncreasesForSpecializationStatsT
|
|
|
|
auto skillIncreasesForSpecializationStatsT
|
|
|
|
= context.mLua->sol().new_usertype<SkillIncreasesForSpecializationStats>(
|
|
|
|
= lua.new_usertype<SkillIncreasesForSpecializationStats>("skillIncreasesForSpecializationStats");
|
|
|
|
"skillIncreasesForSpecializationStats");
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::string_view index = ESM::Class::specializationIndexToLuaId.at(i);
|
|
|
|
std::string_view index = ESM::Class::specializationIndexToLuaId.at(i);
|
|
|
@ -558,7 +558,7 @@ namespace MWLua
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
auto levelStatT = context.mLua->sol().new_usertype<LevelStat>("LevelStat");
|
|
|
|
auto levelStatT = lua.new_usertype<LevelStat>("LevelStat");
|
|
|
|
levelStatT["current"] = sol::property([context](const LevelStat& stat) { return stat.getCurrent(context); },
|
|
|
|
levelStatT["current"] = sol::property([context](const LevelStat& stat) { return stat.getCurrent(context); },
|
|
|
|
[context](const LevelStat& stat, const sol::object& value) { stat.setCurrent(context, value); });
|
|
|
|
[context](const LevelStat& stat, const sol::object& value) { stat.setCurrent(context, value); });
|
|
|
|
levelStatT["progress"] = sol::property([context](const LevelStat& stat) { return stat.getProgress(context); },
|
|
|
|
levelStatT["progress"] = sol::property([context](const LevelStat& stat) { return stat.getProgress(context); },
|
|
|
@ -569,32 +569,32 @@ namespace MWLua
|
|
|
|
[](const LevelStat& stat) { return stat.getSkillIncreasesForSpecializationStats(); });
|
|
|
|
[](const LevelStat& stat) { return stat.getSkillIncreasesForSpecializationStats(); });
|
|
|
|
stats["level"] = addIndexedAccessor<LevelStat>(0);
|
|
|
|
stats["level"] = addIndexedAccessor<LevelStat>(0);
|
|
|
|
|
|
|
|
|
|
|
|
auto dynamicStatT = context.mLua->sol().new_usertype<DynamicStat>("DynamicStat");
|
|
|
|
auto dynamicStatT = lua.new_usertype<DynamicStat>("DynamicStat");
|
|
|
|
addProp(context, dynamicStatT, "base", &MWMechanics::DynamicStat<float>::getBase);
|
|
|
|
addProp(context, dynamicStatT, "base", &MWMechanics::DynamicStat<float>::getBase);
|
|
|
|
addProp(context, dynamicStatT, "current", &MWMechanics::DynamicStat<float>::getCurrent);
|
|
|
|
addProp(context, dynamicStatT, "current", &MWMechanics::DynamicStat<float>::getCurrent);
|
|
|
|
addProp(context, dynamicStatT, "modifier", &MWMechanics::DynamicStat<float>::getModifier);
|
|
|
|
addProp(context, dynamicStatT, "modifier", &MWMechanics::DynamicStat<float>::getModifier);
|
|
|
|
sol::table dynamic(context.mLua->sol(), sol::create);
|
|
|
|
sol::table dynamic(lua, sol::create);
|
|
|
|
stats["dynamic"] = LuaUtil::makeReadOnly(dynamic);
|
|
|
|
stats["dynamic"] = LuaUtil::makeReadOnly(dynamic);
|
|
|
|
dynamic["health"] = addIndexedAccessor<DynamicStat>(0);
|
|
|
|
dynamic["health"] = addIndexedAccessor<DynamicStat>(0);
|
|
|
|
dynamic["magicka"] = addIndexedAccessor<DynamicStat>(1);
|
|
|
|
dynamic["magicka"] = addIndexedAccessor<DynamicStat>(1);
|
|
|
|
dynamic["fatigue"] = addIndexedAccessor<DynamicStat>(2);
|
|
|
|
dynamic["fatigue"] = addIndexedAccessor<DynamicStat>(2);
|
|
|
|
|
|
|
|
|
|
|
|
auto attributeStatT = context.mLua->sol().new_usertype<AttributeStat>("AttributeStat");
|
|
|
|
auto attributeStatT = lua.new_usertype<AttributeStat>("AttributeStat");
|
|
|
|
addProp(context, attributeStatT, "base", &MWMechanics::AttributeValue::getBase);
|
|
|
|
addProp(context, attributeStatT, "base", &MWMechanics::AttributeValue::getBase);
|
|
|
|
addProp(context, attributeStatT, "damage", &MWMechanics::AttributeValue::getDamage);
|
|
|
|
addProp(context, attributeStatT, "damage", &MWMechanics::AttributeValue::getDamage);
|
|
|
|
attributeStatT["modified"]
|
|
|
|
attributeStatT["modified"]
|
|
|
|
= sol::readonly_property([=](const AttributeStat& stat) { return stat.getModified(context); });
|
|
|
|
= sol::readonly_property([=](const AttributeStat& stat) { return stat.getModified(context); });
|
|
|
|
addProp(context, attributeStatT, "modifier", &MWMechanics::AttributeValue::getModifier);
|
|
|
|
addProp(context, attributeStatT, "modifier", &MWMechanics::AttributeValue::getModifier);
|
|
|
|
sol::table attributes(context.mLua->sol(), sol::create);
|
|
|
|
sol::table attributes(lua, sol::create);
|
|
|
|
stats["attributes"] = LuaUtil::makeReadOnly(attributes);
|
|
|
|
stats["attributes"] = LuaUtil::makeReadOnly(attributes);
|
|
|
|
for (const ESM::Attribute& attribute : MWBase::Environment::get().getESMStore()->get<ESM::Attribute>())
|
|
|
|
for (const ESM::Attribute& attribute : MWBase::Environment::get().getESMStore()->get<ESM::Attribute>())
|
|
|
|
attributes[ESM::RefId(attribute.mId).serializeText()] = addIndexedAccessor<AttributeStat>(attribute.mId);
|
|
|
|
attributes[ESM::RefId(attribute.mId).serializeText()] = addIndexedAccessor<AttributeStat>(attribute.mId);
|
|
|
|
|
|
|
|
|
|
|
|
auto aiStatT = context.mLua->sol().new_usertype<AIStat>("AIStat");
|
|
|
|
auto aiStatT = lua.new_usertype<AIStat>("AIStat");
|
|
|
|
addProp(context, aiStatT, "base", &MWMechanics::Stat<int>::getBase);
|
|
|
|
addProp(context, aiStatT, "base", &MWMechanics::Stat<int>::getBase);
|
|
|
|
addProp(context, aiStatT, "modifier", &MWMechanics::Stat<int>::getModifier);
|
|
|
|
addProp(context, aiStatT, "modifier", &MWMechanics::Stat<int>::getModifier);
|
|
|
|
aiStatT["modified"] = sol::readonly_property([=](const AIStat& stat) { return stat.getModified(context); });
|
|
|
|
aiStatT["modified"] = sol::readonly_property([=](const AIStat& stat) { return stat.getModified(context); });
|
|
|
|
sol::table ai(context.mLua->sol(), sol::create);
|
|
|
|
sol::table ai(lua, sol::create);
|
|
|
|
stats["ai"] = LuaUtil::makeReadOnly(ai);
|
|
|
|
stats["ai"] = LuaUtil::makeReadOnly(ai);
|
|
|
|
ai["alarm"] = addIndexedAccessor<AIStat>(MWMechanics::AiSetting::Alarm);
|
|
|
|
ai["alarm"] = addIndexedAccessor<AIStat>(MWMechanics::AiSetting::Alarm);
|
|
|
|
ai["fight"] = addIndexedAccessor<AIStat>(MWMechanics::AiSetting::Fight);
|
|
|
|
ai["fight"] = addIndexedAccessor<AIStat>(MWMechanics::AiSetting::Fight);
|
|
|
@ -604,13 +604,14 @@ namespace MWLua
|
|
|
|
|
|
|
|
|
|
|
|
void addNpcStatsBindings(sol::table& npc, const Context& context)
|
|
|
|
void addNpcStatsBindings(sol::table& npc, const Context& context)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
sol::table npcStats(context.mLua->sol(), sol::create);
|
|
|
|
sol::state_view lua = context.sol();
|
|
|
|
sol::table baseMeta(context.mLua->sol(), sol::create);
|
|
|
|
sol::table npcStats(lua, sol::create);
|
|
|
|
|
|
|
|
sol::table baseMeta(lua, sol::create);
|
|
|
|
baseMeta[sol::meta_function::index] = LuaUtil::getMutableFromReadOnly(npc["baseType"]["stats"]);
|
|
|
|
baseMeta[sol::meta_function::index] = LuaUtil::getMutableFromReadOnly(npc["baseType"]["stats"]);
|
|
|
|
npcStats[sol::metatable_key] = baseMeta;
|
|
|
|
npcStats[sol::metatable_key] = baseMeta;
|
|
|
|
npc["stats"] = LuaUtil::makeReadOnly(npcStats);
|
|
|
|
npc["stats"] = LuaUtil::makeReadOnly(npcStats);
|
|
|
|
|
|
|
|
|
|
|
|
auto skillStatT = context.mLua->sol().new_usertype<SkillStat>("SkillStat");
|
|
|
|
auto skillStatT = lua.new_usertype<SkillStat>("SkillStat");
|
|
|
|
addProp(context, skillStatT, "base", &MWMechanics::SkillValue::getBase);
|
|
|
|
addProp(context, skillStatT, "base", &MWMechanics::SkillValue::getBase);
|
|
|
|
addProp(context, skillStatT, "damage", &MWMechanics::SkillValue::getDamage);
|
|
|
|
addProp(context, skillStatT, "damage", &MWMechanics::SkillValue::getDamage);
|
|
|
|
skillStatT["modified"]
|
|
|
|
skillStatT["modified"]
|
|
|
@ -618,7 +619,7 @@ namespace MWLua
|
|
|
|
addProp(context, skillStatT, "modifier", &MWMechanics::SkillValue::getModifier);
|
|
|
|
addProp(context, skillStatT, "modifier", &MWMechanics::SkillValue::getModifier);
|
|
|
|
skillStatT["progress"] = sol::property([context](const SkillStat& stat) { return stat.getProgress(context); },
|
|
|
|
skillStatT["progress"] = sol::property([context](const SkillStat& stat) { return stat.getProgress(context); },
|
|
|
|
[context](const SkillStat& stat, const sol::object& value) { stat.cache(context, "progress", value); });
|
|
|
|
[context](const SkillStat& stat, const sol::object& value) { stat.cache(context, "progress", value); });
|
|
|
|
sol::table skills(context.mLua->sol(), sol::create);
|
|
|
|
sol::table skills(lua, sol::create);
|
|
|
|
npcStats["skills"] = LuaUtil::makeReadOnly(skills);
|
|
|
|
npcStats["skills"] = LuaUtil::makeReadOnly(skills);
|
|
|
|
for (const ESM::Skill& skill : MWBase::Environment::get().getESMStore()->get<ESM::Skill>())
|
|
|
|
for (const ESM::Skill& skill : MWBase::Environment::get().getESMStore()->get<ESM::Skill>())
|
|
|
|
skills[ESM::RefId(skill.mId).serializeText()] = addIndexedAccessor<SkillStat>(skill.mId);
|
|
|
|
skills[ESM::RefId(skill.mId).serializeText()] = addIndexedAccessor<SkillStat>(skill.mId);
|
|
|
@ -626,7 +627,7 @@ namespace MWLua
|
|
|
|
|
|
|
|
|
|
|
|
sol::table initCoreStatsBindings(const Context& context)
|
|
|
|
sol::table initCoreStatsBindings(const Context& context)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
sol::state_view& lua = context.mLua->sol();
|
|
|
|
sol::state_view lua = context.sol();
|
|
|
|
sol::table statsApi(lua, sol::create);
|
|
|
|
sol::table statsApi(lua, sol::create);
|
|
|
|
auto* vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
|
|
|
|
auto* vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
|
|
|
|
|
|
|
|
|
|
|
@ -635,7 +636,7 @@ namespace MWLua
|
|
|
|
statsApi["Attribute"] = LuaUtil::makeReadOnly(attributes);
|
|
|
|
statsApi["Attribute"] = LuaUtil::makeReadOnly(attributes);
|
|
|
|
statsApi["Attribute"][sol::metatable_key][sol::meta_function::to_string] = ESM::Attribute::getRecordType;
|
|
|
|
statsApi["Attribute"][sol::metatable_key][sol::meta_function::to_string] = ESM::Attribute::getRecordType;
|
|
|
|
|
|
|
|
|
|
|
|
auto attributeT = context.mLua->sol().new_usertype<ESM::Attribute>("Attribute");
|
|
|
|
auto attributeT = lua.new_usertype<ESM::Attribute>("Attribute");
|
|
|
|
attributeT[sol::meta_function::to_string]
|
|
|
|
attributeT[sol::meta_function::to_string]
|
|
|
|
= [](const ESM::Attribute& rec) { return "ESM3_Attribute[" + rec.mId.toDebugString() + "]"; };
|
|
|
|
= [](const ESM::Attribute& rec) { return "ESM3_Attribute[" + rec.mId.toDebugString() + "]"; };
|
|
|
|
attributeT["id"] = sol::readonly_property(
|
|
|
|
attributeT["id"] = sol::readonly_property(
|
|
|
@ -653,7 +654,7 @@ namespace MWLua
|
|
|
|
statsApi["Skill"] = LuaUtil::makeReadOnly(skills);
|
|
|
|
statsApi["Skill"] = LuaUtil::makeReadOnly(skills);
|
|
|
|
statsApi["Skill"][sol::metatable_key][sol::meta_function::to_string] = ESM::Skill::getRecordType;
|
|
|
|
statsApi["Skill"][sol::metatable_key][sol::meta_function::to_string] = ESM::Skill::getRecordType;
|
|
|
|
|
|
|
|
|
|
|
|
auto skillT = context.mLua->sol().new_usertype<ESM::Skill>("Skill");
|
|
|
|
auto skillT = lua.new_usertype<ESM::Skill>("Skill");
|
|
|
|
skillT[sol::meta_function::to_string]
|
|
|
|
skillT[sol::meta_function::to_string]
|
|
|
|
= [](const ESM::Skill& rec) { return "ESM3_Skill[" + rec.mId.toDebugString() + "]"; };
|
|
|
|
= [](const ESM::Skill& rec) { return "ESM3_Skill[" + rec.mId.toDebugString() + "]"; };
|
|
|
|
skillT["id"] = sol::readonly_property(
|
|
|
|
skillT["id"] = sol::readonly_property(
|
|
|
@ -683,7 +684,7 @@ namespace MWLua
|
|
|
|
return res;
|
|
|
|
return res;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
auto schoolT = context.mLua->sol().new_usertype<ESM::MagicSchool>("MagicSchool");
|
|
|
|
auto schoolT = lua.new_usertype<ESM::MagicSchool>("MagicSchool");
|
|
|
|
schoolT[sol::meta_function::to_string]
|
|
|
|
schoolT[sol::meta_function::to_string]
|
|
|
|
= [](const ESM::MagicSchool& rec) { return "ESM3_MagicSchool[" + rec.mName + "]"; };
|
|
|
|
= [](const ESM::MagicSchool& rec) { return "ESM3_MagicSchool[" + rec.mName + "]"; };
|
|
|
|
schoolT["name"]
|
|
|
|
schoolT["name"]
|
|
|
|