mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-15 23:42:20 +00:00
skill gain from books
This commit is contained in:
parent
234f8fa5d5
commit
f5237ff1a6
@ -145,40 +145,54 @@ void MWMechanics::NpcStats::useSkill (int skillIndex, const ESM::Class& class_,
|
|||||||
if (static_cast<int> (base)!=level)
|
if (static_cast<int> (base)!=level)
|
||||||
{
|
{
|
||||||
// skill leveled up
|
// skill leveled up
|
||||||
|
increaseSkill(skillIndex, class_, false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
getSkill (skillIndex).setBase (base);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MWMechanics::NpcStats::increaseSkill(int skillIndex, const ESM::Class &class_, bool preserveProgress)
|
||||||
|
{
|
||||||
|
float base = getSkill (skillIndex).getBase();
|
||||||
|
|
||||||
|
int level = static_cast<int> (base);
|
||||||
|
|
||||||
|
if (preserveProgress)
|
||||||
|
base += 1;
|
||||||
|
else
|
||||||
base = level+1;
|
base = level+1;
|
||||||
|
|
||||||
// if this is a major or minor skill of the class, increase level progress
|
// if this is a major or minor skill of the class, increase level progress
|
||||||
bool levelProgress = false;
|
bool levelProgress = false;
|
||||||
for (int i=0; i<2; ++i)
|
for (int i=0; i<2; ++i)
|
||||||
for (int j=0; j<5; ++j)
|
for (int j=0; j<5; ++j)
|
||||||
{
|
|
||||||
int skill = class_.data.skills[j][i];
|
|
||||||
if (skill == skillIndex)
|
|
||||||
levelProgress = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
mLevelProgress += levelProgress;
|
|
||||||
|
|
||||||
// check the attribute this skill belongs to
|
|
||||||
const ESM::Skill* skill = MWBase::Environment::get().getWorld ()->getStore ().skills.find(skillIndex);
|
|
||||||
++mSkillIncreases[skill->data.attribute];
|
|
||||||
|
|
||||||
// Play sound & skill progress notification
|
|
||||||
/// \todo check if character is the player, if levelling is ever implemented for NPCs
|
|
||||||
MWBase::Environment::get().getSoundManager ()->playSound ("skillraise", 1, 1);
|
|
||||||
|
|
||||||
std::stringstream message;
|
|
||||||
message << boost::format(MWBase::Environment::get().getWindowManager ()->getGameSettingString ("sNotifyMessage39", ""))
|
|
||||||
% std::string("#{" + ESM::Skill::sSkillNameIds[skillIndex] + "}")
|
|
||||||
% base;
|
|
||||||
MWBase::Environment::get().getWindowManager ()->messageBox(message.str(), std::vector<std::string>());
|
|
||||||
|
|
||||||
if (mLevelProgress >= 10)
|
|
||||||
{
|
{
|
||||||
// levelup is possible now
|
int skill = class_.data.skills[j][i];
|
||||||
MWBase::Environment::get().getWindowManager ()->messageBox ("#{sLevelUpMsg}", std::vector<std::string>());
|
if (skill == skillIndex)
|
||||||
|
levelProgress = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
mLevelProgress += levelProgress;
|
||||||
|
|
||||||
|
// check the attribute this skill belongs to
|
||||||
|
const ESM::Skill* skill = MWBase::Environment::get().getWorld ()->getStore ().skills.find(skillIndex);
|
||||||
|
++mSkillIncreases[skill->data.attribute];
|
||||||
|
|
||||||
|
// Play sound & skill progress notification
|
||||||
|
/// \todo check if character is the player, if levelling is ever implemented for NPCs
|
||||||
|
MWBase::Environment::get().getSoundManager ()->playSound ("skillraise", 1, 1);
|
||||||
|
|
||||||
|
std::stringstream message;
|
||||||
|
message << boost::format(MWBase::Environment::get().getWindowManager ()->getGameSettingString ("sNotifyMessage39", ""))
|
||||||
|
% std::string("#{" + ESM::Skill::sSkillNameIds[skillIndex] + "}")
|
||||||
|
% base;
|
||||||
|
MWBase::Environment::get().getWindowManager ()->messageBox(message.str(), std::vector<std::string>());
|
||||||
|
|
||||||
|
if (mLevelProgress >= 10)
|
||||||
|
{
|
||||||
|
// levelup is possible now
|
||||||
|
MWBase::Environment::get().getWindowManager ()->messageBox ("#{sLevelUpMsg}", std::vector<std::string>());
|
||||||
|
}
|
||||||
|
|
||||||
getSkill (skillIndex).setBase (base);
|
getSkill (skillIndex).setBase (base);
|
||||||
}
|
}
|
||||||
|
@ -79,6 +79,8 @@ namespace MWMechanics
|
|||||||
void useSkill (int skillIndex, const ESM::Class& class_, int usageType = -1);
|
void useSkill (int skillIndex, const ESM::Class& class_, int usageType = -1);
|
||||||
///< Increase skill by usage.
|
///< Increase skill by usage.
|
||||||
|
|
||||||
|
void increaseSkill (int skillIndex, const ESM::Class& class_, bool preserveProgress);
|
||||||
|
|
||||||
int getLevelProgress() const;
|
int getLevelProgress() const;
|
||||||
|
|
||||||
int getLevelupAttributeMultiplier(int attribute) const;
|
int getLevelupAttributeMultiplier(int attribute) const;
|
||||||
|
@ -2,10 +2,18 @@
|
|||||||
|
|
||||||
#include "../mwbase/environment.hpp"
|
#include "../mwbase/environment.hpp"
|
||||||
#include "../mwbase/windowmanager.hpp"
|
#include "../mwbase/windowmanager.hpp"
|
||||||
|
#include "../mwbase/world.hpp"
|
||||||
|
|
||||||
|
#include "../mwworld/player.hpp"
|
||||||
|
#include "../mwworld/class.hpp"
|
||||||
|
|
||||||
|
#include "../mwmechanics/npcstats.hpp"
|
||||||
|
|
||||||
#include "../mwgui/bookwindow.hpp"
|
#include "../mwgui/bookwindow.hpp"
|
||||||
#include "../mwgui/scrollwindow.hpp"
|
#include "../mwgui/scrollwindow.hpp"
|
||||||
|
|
||||||
|
#include <components/esm_store/store.hpp>
|
||||||
|
|
||||||
namespace MWWorld
|
namespace MWWorld
|
||||||
{
|
{
|
||||||
ActionRead::ActionRead (const MWWorld::Ptr& object) : Action (false, object)
|
ActionRead::ActionRead (const MWWorld::Ptr& object) : Action (false, object)
|
||||||
@ -26,5 +34,21 @@ namespace MWWorld
|
|||||||
MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_Book);
|
MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_Book);
|
||||||
MWBase::Environment::get().getWindowManager()->getBookWindow()->open(getTarget());
|
MWBase::Environment::get().getWindowManager()->getBookWindow()->open(getTarget());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ref->base->data.skillID >= 0 && ref->base->data.skillID < ESM::Skill::Length)
|
||||||
|
{
|
||||||
|
MWWorld::Ptr player = MWBase::Environment::get().getWorld ()->getPlayer().getPlayer();
|
||||||
|
MWMechanics::NpcStats& npcStats = MWWorld::Class::get(player).getNpcStats (player);
|
||||||
|
MWWorld::LiveCellRef<ESM::NPC> *playerRef = player.get<ESM::NPC>();
|
||||||
|
const ESM::Class *class_ = MWBase::Environment::get().getWorld()->getStore().classes.find (
|
||||||
|
playerRef->base->cls);
|
||||||
|
|
||||||
|
npcStats.increaseSkill (ref->base->data.skillID, *class_, true);
|
||||||
|
|
||||||
|
// Remove skill from the book
|
||||||
|
/// \todo This will have to be changed later
|
||||||
|
const_cast<ESM::Book*>(ref->base)->data.skillID = -1;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user