Issue #356: Implemented ingredient eating
parent
2ccd7a480d
commit
fe68a252d5
@ -0,0 +1,49 @@
|
||||
|
||||
#include "actioneat.hpp"
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
#include <components/esm/loadskil.hpp>
|
||||
|
||||
#include <components/esm_store/store.hpp>
|
||||
|
||||
#include "../mwbase/environment.hpp"
|
||||
#include "../mwbase/world.hpp"
|
||||
|
||||
#include "../mwmechanics/creaturestats.hpp"
|
||||
#include "../mwmechanics/npcstats.hpp"
|
||||
|
||||
#include "class.hpp"
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
void ActionEat::executeImp (const Ptr& actor)
|
||||
{
|
||||
// remove used item
|
||||
getTarget().getRefData().setCount (getTarget().getRefData().getCount()-1);
|
||||
|
||||
// check for success
|
||||
const MWMechanics::CreatureStats& creatureStats = MWWorld::Class::get (actor).getCreatureStats (actor);
|
||||
MWMechanics::NpcStats& npcStats = MWWorld::Class::get (actor).getNpcStats (actor);
|
||||
|
||||
float x =
|
||||
(npcStats.getSkill (ESM::Skill::Alchemy).getModified() +
|
||||
0.2 * creatureStats.getAttribute (1).getModified()
|
||||
+ 0.1 * creatureStats.getAttribute (7).getModified())
|
||||
* creatureStats.getFatigueTerm();
|
||||
|
||||
if (x>=100*static_cast<float> (std::rand()) / RAND_MAX)
|
||||
{
|
||||
// apply to actor
|
||||
std::string id = Class::get (getTarget()).getId (getTarget());
|
||||
|
||||
Class::get (actor).apply (actor, id, actor);
|
||||
// we ignore the result here. Skill increases no matter if the ingredient did something or not.
|
||||
|
||||
// increase skill
|
||||
Class::get (actor).skillUsageSucceeded (actor, ESM::Skill::Alchemy, 1);
|
||||
}
|
||||
}
|
||||
|
||||
ActionEat::ActionEat (const MWWorld::Ptr& object) : Action (false, object) {}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
#ifndef GAME_MWWORLD_ACTIONEAT_H
|
||||
#define GAME_MWWORLD_ACTIONEAT_H
|
||||
|
||||
#include "action.hpp"
|
||||
#include "ptr.hpp"
|
||||
|
||||
namespace MWWorld
|
||||
{
|
||||
class ActionEat : public Action
|
||||
{
|
||||
virtual void executeImp (const Ptr& actor);
|
||||
|
||||
public:
|
||||
|
||||
ActionEat (const MWWorld::Ptr& object);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue