mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-28 21:07:59 +03:00
Merge branch 'player_rep_lua' into 'master'
Some checks failed
Build and test / Ubuntu (push) Has been cancelled
Build and test / MacOS (push) Has been cancelled
Build and test / Read .env file and expose it as output (push) Has been cancelled
Build and test / Windows (2019) (push) Has been cancelled
Build and test / Windows (2022) (push) Has been cancelled
Some checks failed
Build and test / Ubuntu (push) Has been cancelled
Build and test / MacOS (push) Has been cancelled
Build and test / Read .env file and expose it as output (push) Has been cancelled
Build and test / Windows (2019) (push) Has been cancelled
Build and test / Windows (2022) (push) Has been cancelled
Add lua bindings for player reputation See merge request OpenMW/openmw!3943
This commit is contained in:
commit
d39bc75817
2 changed files with 48 additions and 0 deletions
|
@ -164,6 +164,36 @@ namespace MWLua
|
|||
}
|
||||
};
|
||||
|
||||
class ReputationStat
|
||||
{
|
||||
ObjectVariant mObject;
|
||||
|
||||
ReputationStat(ObjectVariant object)
|
||||
: mObject(std::move(object))
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
sol::object getCurrent(const Context& context) const
|
||||
{
|
||||
return getValue(context, mObject, &setNpcValue, std::monostate{}, "current",
|
||||
[](const MWWorld::Ptr& ptr) { return ptr.getClass().getNpcStats(ptr).getReputation(); });
|
||||
}
|
||||
|
||||
void setCurrent(const Context& context, const sol::object& value) const
|
||||
{
|
||||
SelfObject* obj = mObject.asSelfObject();
|
||||
obj->ptr().getClass().getNpcStats(obj->ptr()).setReputation(value.as<int>());
|
||||
}
|
||||
|
||||
static std::optional<ReputationStat> create(ObjectVariant object, Index)
|
||||
{
|
||||
if (!object.ptr().getClass().isNpc())
|
||||
return {};
|
||||
return ReputationStat{ std::move(object) };
|
||||
}
|
||||
};
|
||||
|
||||
class LevelStat
|
||||
{
|
||||
ObjectVariant mObject;
|
||||
|
@ -502,6 +532,10 @@ namespace sol
|
|||
{
|
||||
};
|
||||
template <>
|
||||
struct is_automagical<MWLua::ReputationStat> : std::false_type
|
||||
{
|
||||
};
|
||||
template <>
|
||||
struct is_automagical<MWLua::DynamicStat> : std::false_type
|
||||
{
|
||||
};
|
||||
|
@ -627,6 +661,12 @@ namespace MWLua
|
|||
npcStats["skills"] = LuaUtil::makeReadOnly(skills);
|
||||
for (const ESM::Skill& skill : MWBase::Environment::get().getESMStore()->get<ESM::Skill>())
|
||||
skills[ESM::RefId(skill.mId).serializeText()] = addIndexedAccessor<SkillStat>(skill.mId);
|
||||
|
||||
auto reputationStatT = lua.new_usertype<ReputationStat>("ReputationStat");
|
||||
reputationStatT["current"]
|
||||
= sol::property([context](const ReputationStat& stat) { return stat.getCurrent(context); },
|
||||
[context](const ReputationStat& stat, const sol::object& value) { stat.setCurrent(context, value); });
|
||||
npcStats["reputation"] = addIndexedAccessor<ReputationStat>(0);
|
||||
}
|
||||
|
||||
sol::table initCoreStatsBindings(const Context& context)
|
||||
|
|
|
@ -431,6 +431,10 @@
|
|||
-- @field #SkillIncreasesForAttributeStats skillIncreasesForAttribute The NPC's attribute contributions towards the next level up. Values affect how much each attribute can be increased at level up.
|
||||
-- @field #SkillIncreasesForSpecializationStats skillIncreasesForSpecialization The NPC's attribute contributions towards the next level up. Values affect the graphic used on the level up screen.
|
||||
|
||||
---
|
||||
-- @type ReputationStat
|
||||
-- @field #number current The actor's current Reputation. Must be a number in the range of 0-255.
|
||||
|
||||
---
|
||||
-- @type DynamicStat
|
||||
-- @field #number base
|
||||
|
@ -734,6 +738,7 @@
|
|||
-- @param openmw.core#GameObject actor
|
||||
-- @return #LevelStat
|
||||
|
||||
|
||||
--- The actor's stats.
|
||||
-- @field [parent=#Actor] #ActorStats stats
|
||||
|
||||
|
@ -741,6 +746,9 @@
|
|||
-- @type NpcStats
|
||||
-- @extends ActorStats
|
||||
-- @field #SkillStats skills
|
||||
-- @field #ReputationStat reputation
|
||||
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue