mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-31 21:45:35 +00:00
Replace remaining skill indices in NpcStats
This commit is contained in:
parent
1e0ed42294
commit
72f8f9d1ad
11 changed files with 28 additions and 49 deletions
|
@ -654,7 +654,7 @@ namespace MWClass
|
|||
int weapskill = ESM::Skill::HandToHand;
|
||||
if (!weapon.isEmpty())
|
||||
weapskill = weapon.getClass().getEquipmentSkill(weapon);
|
||||
skillUsageSucceeded(ptr, weapskill, 0);
|
||||
skillUsageSucceeded(ptr, ESM::Skill::indexToRefId(weapskill), 0);
|
||||
|
||||
const MWMechanics::AiSequence& seq = victim.getClass().getCreatureStats(victim).getAiSequence();
|
||||
|
||||
|
@ -843,7 +843,8 @@ namespace MWClass
|
|||
}
|
||||
|
||||
if (ptr == MWMechanics::getPlayer())
|
||||
skillUsageSucceeded(ptr, armor.getClass().getEquipmentSkill(armor), 0);
|
||||
skillUsageSucceeded(
|
||||
ptr, ESM::Skill::indexToRefId(armor.getClass().getEquipmentSkill(armor)), 0);
|
||||
|
||||
switch (armor.getClass().getEquipmentSkill(armor))
|
||||
{
|
||||
|
@ -859,7 +860,7 @@ namespace MWClass
|
|||
}
|
||||
}
|
||||
else if (ptr == MWMechanics::getPlayer())
|
||||
skillUsageSucceeded(ptr, ESM::Skill::Unarmored, 0);
|
||||
Class::skillUsageSucceeded(ptr, ESM::Skill::Unarmored, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1154,7 +1155,7 @@ namespace MWClass
|
|||
return cast.cast(recordId);
|
||||
}
|
||||
|
||||
void Npc::skillUsageSucceeded(const MWWorld::Ptr& ptr, int skill, int usageType, float extraFactor) const
|
||||
void Npc::skillUsageSucceeded(const MWWorld::Ptr& ptr, ESM::RefId skill, int usageType, float extraFactor) const
|
||||
{
|
||||
MWMechanics::NpcStats& stats = getNpcStats(ptr);
|
||||
|
||||
|
|
|
@ -120,7 +120,7 @@ namespace MWClass
|
|||
/// @param rendering Indicates if the scale to adjust is for the rendering mesh, or for the collision mesh
|
||||
|
||||
void skillUsageSucceeded(
|
||||
const MWWorld::Ptr& ptr, int skill, int usageType, float extraFactor = 1.f) const override;
|
||||
const MWWorld::Ptr& ptr, ESM::RefId skill, int usageType, float extraFactor = 1.f) const override;
|
||||
///< Inform actor \a ptr that a skill use has succeeded.
|
||||
|
||||
bool isEssential(const MWWorld::ConstPtr& ptr) const override;
|
||||
|
|
|
@ -160,7 +160,7 @@ namespace MWGui
|
|||
MWWorld::LiveCellRef<ESM::NPC>* playerRef = player.get<ESM::NPC>();
|
||||
|
||||
const ESM::Class* class_ = store.get<ESM::Class>().find(playerRef->mBase->mClass);
|
||||
pcStats.increaseSkill(skill->mIndex, *class_, true);
|
||||
pcStats.increaseSkill(skill->mId, *class_, true);
|
||||
|
||||
// remove gold
|
||||
player.getClass().getContainerStore(player).remove(MWWorld::ContainerStore::sGoldId, price);
|
||||
|
|
|
@ -259,7 +259,7 @@ namespace MWMechanics
|
|||
applyWerewolfDamageMult(victim, projectile, damage);
|
||||
|
||||
if (attacker == getPlayer())
|
||||
attacker.getClass().skillUsageSucceeded(attacker, weaponSkill, 0);
|
||||
attacker.getClass().skillUsageSucceeded(attacker, ESM::Skill::indexToRefId(weaponSkill), 0);
|
||||
|
||||
const MWMechanics::AiSequence& sequence = victim.getClass().getCreatureStats(victim).getAiSequence();
|
||||
bool unaware = attacker == getPlayer() && !sequence.isInCombat()
|
||||
|
|
|
@ -198,9 +198,9 @@ float MWMechanics::NpcStats::getSkillProgressRequirement(ESM::RefId id, const ES
|
|||
return progressRequirement;
|
||||
}
|
||||
|
||||
void MWMechanics::NpcStats::useSkill(int skillIndex, const ESM::Class& class_, int usageType, float extraFactor)
|
||||
void MWMechanics::NpcStats::useSkill(ESM::RefId id, const ESM::Class& class_, int usageType, float extraFactor)
|
||||
{
|
||||
const ESM::Skill* skill = MWBase::Environment::get().getESMStore()->get<ESM::Skill>().find(skillIndex);
|
||||
const ESM::Skill* skill = MWBase::Environment::get().getESMStore()->get<ESM::Skill>().find(id);
|
||||
float skillGain = 1;
|
||||
if (usageType >= 4)
|
||||
throw std::runtime_error("skill usage type out of range");
|
||||
|
@ -219,14 +219,13 @@ void MWMechanics::NpcStats::useSkill(int skillIndex, const ESM::Class& class_, i
|
|||
if (int(value.getProgress()) >= int(getSkillProgressRequirement(skill->mId, class_)))
|
||||
{
|
||||
// skill levelled up
|
||||
increaseSkill(skillIndex, class_, false);
|
||||
increaseSkill(skill->mId, class_, false);
|
||||
}
|
||||
}
|
||||
|
||||
void MWMechanics::NpcStats::increaseSkill(
|
||||
int skillIndex, const ESM::Class& class_, bool preserveProgress, bool readBook)
|
||||
void MWMechanics::NpcStats::increaseSkill(ESM::RefId id, const ESM::Class& class_, bool preserveProgress, bool readBook)
|
||||
{
|
||||
const ESM::Skill* skill = MWBase::Environment::get().getESMStore()->get<ESM::Skill>().find(skillIndex);
|
||||
const ESM::Skill* skill = MWBase::Environment::get().getESMStore()->get<ESM::Skill>().find(id);
|
||||
float base = getSkill(skill->mId).getBase();
|
||||
|
||||
if (base >= 100.f)
|
||||
|
@ -240,13 +239,13 @@ void MWMechanics::NpcStats::increaseSkill(
|
|||
int increase = gmst.find("iLevelupMiscMultAttriubte")->mValue.getInteger(); // Note: GMST has a typo
|
||||
for (const auto& skills : class_.mData.mSkills)
|
||||
{
|
||||
if (skills[0] == skillIndex)
|
||||
if (skills[0] == skill->mIndex)
|
||||
{
|
||||
mLevelProgress += gmst.find("iLevelUpMinorMult")->mValue.getInteger();
|
||||
increase = gmst.find("iLevelUpMinorMultAttribute")->mValue.getInteger();
|
||||
break;
|
||||
}
|
||||
else if (skills[1] == skillIndex)
|
||||
else if (skills[1] == skill->mIndex)
|
||||
{
|
||||
mLevelProgress += gmst.find("iLevelUpMajorMult")->mValue.getInteger();
|
||||
increase = gmst.find("iLevelUpMajorMultAttribute")->mValue.getInteger();
|
||||
|
|
|
@ -86,10 +86,10 @@ namespace MWMechanics
|
|||
|
||||
float getSkillProgressRequirement(ESM::RefId id, const ESM::Class& class_) const;
|
||||
|
||||
void useSkill(int skillIndex, const ESM::Class& class_, int usageType = -1, float extraFactor = 1.f);
|
||||
void useSkill(ESM::RefId id, const ESM::Class& class_, int usageType = -1, float extraFactor = 1.f);
|
||||
///< Increase skill by usage.
|
||||
|
||||
void increaseSkill(int skillIndex, const ESM::Class& class_, bool preserveProgress, bool readBook = false);
|
||||
void increaseSkill(ESM::RefId id, const ESM::Class& class_, bool preserveProgress, bool readBook = false);
|
||||
|
||||
int getLevelProgress() const;
|
||||
|
||||
|
|
|
@ -16,19 +16,4 @@ namespace MWWorld
|
|||
{
|
||||
actor.getClass().consume(getTarget(), actor);
|
||||
}
|
||||
|
||||
ActionApplyWithSkill::ActionApplyWithSkill(const Ptr& object, const ESM::RefId& id, int skillIndex, int usageType)
|
||||
: Action(false, object)
|
||||
, mId(id)
|
||||
, mSkillIndex(skillIndex)
|
||||
, mUsageType(usageType)
|
||||
{
|
||||
}
|
||||
|
||||
void ActionApplyWithSkill::executeImp(const Ptr& actor)
|
||||
{
|
||||
bool consumed = actor.getClass().consume(getTarget(), actor);
|
||||
if (consumed && mUsageType != -1 && actor == MWMechanics::getPlayer())
|
||||
actor.getClass().skillUsageSucceeded(actor, mSkillIndex, mUsageType);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,18 +16,6 @@ namespace MWWorld
|
|||
public:
|
||||
ActionApply(const Ptr& object, const ESM::RefId& id);
|
||||
};
|
||||
|
||||
class ActionApplyWithSkill : public Action
|
||||
{
|
||||
ESM::RefId mId;
|
||||
int mSkillIndex;
|
||||
int mUsageType;
|
||||
|
||||
void executeImp(const Ptr& actor) override;
|
||||
|
||||
public:
|
||||
ActionApplyWithSkill(const Ptr& object, const ESM::RefId& id, int skillIndex, int usageType);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <components/esm3/loadbook.hpp>
|
||||
#include <components/esm3/loadclas.hpp>
|
||||
#include <components/esm3/loadskil.hpp>
|
||||
|
||||
#include "../mwbase/environment.hpp"
|
||||
#include "../mwbase/windowmanager.hpp"
|
||||
|
@ -46,15 +47,15 @@ namespace MWWorld
|
|||
MWMechanics::NpcStats& npcStats = actor.getClass().getNpcStats(actor);
|
||||
|
||||
// Skill gain from books
|
||||
if (ref->mBase->mData.mSkillId >= 0 && ref->mBase->mData.mSkillId < ESM::Skill::Length
|
||||
&& !npcStats.hasBeenUsed(ref->mBase->mId))
|
||||
ESM::RefId skill = ESM::Skill::indexToRefId(ref->mBase->mData.mSkillId);
|
||||
if (!skill.empty() && !npcStats.hasBeenUsed(ref->mBase->mId))
|
||||
{
|
||||
MWWorld::LiveCellRef<ESM::NPC>* playerRef = actor.get<ESM::NPC>();
|
||||
|
||||
const ESM::Class* class_
|
||||
= MWBase::Environment::get().getESMStore()->get<ESM::Class>().find(playerRef->mBase->mClass);
|
||||
|
||||
npcStats.increaseSkill(ref->mBase->mData.mSkillId, *class_, true, true);
|
||||
npcStats.increaseSkill(skill, *class_, true, true);
|
||||
|
||||
npcStats.flagAsUsed(ref->mBase->mId);
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ namespace MWWorld
|
|||
return false;
|
||||
}
|
||||
|
||||
void Class::skillUsageSucceeded(const MWWorld::Ptr& ptr, int skill, int usageType, float extraFactor) const
|
||||
void Class::skillUsageSucceeded(const MWWorld::Ptr& ptr, ESM::RefId skill, int usageType, float extraFactor) const
|
||||
{
|
||||
throw std::runtime_error("class does not represent an actor");
|
||||
}
|
||||
|
|
|
@ -235,10 +235,15 @@ namespace MWWorld
|
|||
///< Consume an item, e. g. a potion.
|
||||
|
||||
virtual void skillUsageSucceeded(
|
||||
const MWWorld::Ptr& ptr, int skill, int usageType, float extraFactor = 1.f) const;
|
||||
const MWWorld::Ptr& ptr, ESM::RefId skill, int usageType, float extraFactor = 1.f) const;
|
||||
///< Inform actor \a ptr that a skill use has succeeded.
|
||||
///
|
||||
/// (default implementations: throws an exception)
|
||||
void skillUsageSucceeded(
|
||||
const MWWorld::Ptr& ptr, ESM::Skill::SkillEnum index, int usageType, float extraFactor = 1.f) const
|
||||
{
|
||||
return skillUsageSucceeded(ptr, ESM::Skill::indexToRefId(index), usageType, extraFactor);
|
||||
};
|
||||
|
||||
virtual bool isEssential(const MWWorld::ConstPtr& ptr) const;
|
||||
///< Is \a ptr essential? (i.e. may losing \a ptr make the game unwinnable)
|
||||
|
|
Loading…
Reference in a new issue