Skip to content

Commit 663ae0f

Browse files
committed
Merge branch 'reputation_stat' into 'master'
Reputation stat Closes #123 and #9013 See merge request OpenMW/openmw!5197
2 parents 61a8c6c + b5f9546 commit 663ae0f

File tree

3 files changed

+57
-6
lines changed

3 files changed

+57
-6
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ message(STATUS "Configuring OpenMW...")
8282
set(OPENMW_VERSION_MAJOR 0)
8383
set(OPENMW_VERSION_MINOR 51)
8484
set(OPENMW_VERSION_RELEASE 0)
85-
set(OPENMW_LUA_API_REVISION 117)
85+
set(OPENMW_LUA_API_REVISION 118)
8686
set(OPENMW_POSTPROCESSING_API_REVISION 5)
8787

8888
set(OPENMW_VERSION_COMMITHASH "")

apps/openmw/mwlua/stats.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,45 @@ namespace MWLua
469469
stats.setAiSetting(index, stat);
470470
}
471471
};
472+
473+
class ReputationStat
474+
{
475+
ObjectVariant mObject;
476+
477+
ReputationStat(ObjectVariant object)
478+
: mObject(std::move(object))
479+
{
480+
}
481+
482+
public:
483+
sol::object get(const Context& context, const std::string_view prop) const
484+
{
485+
return getValue(context, mObject, &ReputationStat::setValue, std::monostate{}, prop,
486+
[](const MWWorld::Ptr& ptr) { return ptr.getClass().getNpcStats(ptr).getReputation(); });
487+
}
488+
489+
static std::optional<ReputationStat> create(ObjectVariant object)
490+
{
491+
if (!object.ptr().getClass().isNpc())
492+
return {};
493+
494+
return ReputationStat{ std::move(object) };
495+
}
496+
497+
void cache(const Context& context, const std::string_view prop, const sol::object& value) const
498+
{
499+
SelfObject* obj = mObject.asSelfObject();
500+
obj->cacheStat(*context.mLuaManager,
501+
SelfObject::CachedStat{ &ReputationStat::setValue, std::monostate{}, prop }, value);
502+
}
503+
504+
static void setValue(Index i, std::string_view prop, const MWWorld::Ptr& ptr, const sol::object& value)
505+
{
506+
MWMechanics::NpcStats& stats = ptr.getClass().getNpcStats(ptr);
507+
int intValue = LuaUtil::cast<int>(value);
508+
stats.setReputation(intValue);
509+
}
510+
};
472511
}
473512
}
474513

@@ -612,6 +651,13 @@ namespace MWLua
612651
npcStats["skills"] = LuaUtil::makeReadOnly(skills);
613652
for (const ESM::Skill& skill : MWBase::Environment::get().getESMStore()->get<ESM::Skill>())
614653
skills[ESM::RefId(skill.mId).serializeText()] = addIndexedAccessor<SkillStat>(skill.mId);
654+
655+
auto reputationStatT = lua.new_usertype<ReputationStat>("ReputationStat");
656+
reputationStatT["current"]
657+
= sol::property([=](const ReputationStat& stat) { return stat.get(context, "current"); },
658+
[=](const ReputationStat& stat, const sol::object& value) { stat.cache(context, "current", value); });
659+
660+
npcStats["reputation"] = [](const sol::object& o) { return ReputationStat::create(ObjectVariant(o)); };
615661
}
616662

617663
sol::table initCoreStatsBindings(const Context& context)

files/lua_api/openmw/types.lua

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -439,40 +439,44 @@
439439
-- @field #number magic Number of contributions to magic specialization for the next level up.
440440
-- @field #number stealth Number of contributions to stealth specialization for the next level up.
441441

442-
---
442+
--- Value modification is delayed
443443
-- @type LevelStat
444444
-- @field #number current The actor's current level.
445445
-- @field #number progress The NPC's level progress.
446446
-- @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.
447447
-- @field #SkillIncreasesForSpecializationStats skillIncreasesForSpecialization The NPC's attribute contributions towards the next level up. Values affect the graphic used on the level up screen.
448448

449-
---
449+
--- Value modification is delayed
450450
-- @type DynamicStat
451451
-- @field #number base
452452
-- @field #number current
453453
-- @field #number modifier
454454

455-
---
455+
--- Value modification is delayed
456456
-- @type AttributeStat
457457
-- @field #number base The actor's base attribute value.
458458
-- @field #number damage The amount the attribute has been damaged.
459459
-- @field #number modified The actor's current attribute value (read-only.)
460460
-- @field #number modifier The attribute's modifier.
461461

462-
---
462+
--- Value modification is delayed
463463
-- @type SkillStat
464464
-- @field #number base The NPC's base skill value.
465465
-- @field #number damage The amount the skill has been damaged.
466466
-- @field #number modified The NPC's current skill value (read-only.)
467467
-- @field #number modifier The skill's modifier.
468468
-- @field #number progress [0-1] The NPC's skill progress.
469469

470-
---
470+
--- Value modification is delayed
471471
-- @type AIStat
472472
-- @field #number base The stat's base value.
473473
-- @field #number modifier The stat's modifier.
474474
-- @field #number modified The actor's current ai value (read-only.)
475475

476+
--- Value modification is delayed
477+
-- @type ReputationStat
478+
-- @field #number current Current reputation value.
479+
476480
---
477481
-- @type DynamicStats
478482

@@ -756,6 +760,7 @@
756760
-- @type NpcStats
757761
-- @extends #ActorStats
758762
-- @field #SkillStats skills
763+
-- @field #ReputationStat reputation
759764

760765

761766
--------------------------------------------------------------------------------

0 commit comments

Comments
 (0)