2012-09-13 11:02:26 +00:00
|
|
|
|
|
|
|
#include "actioneat.hpp"
|
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
|
|
|
#include <components/esm/loadskil.hpp>
|
|
|
|
|
|
|
|
#include "../mwbase/environment.hpp"
|
|
|
|
#include "../mwbase/world.hpp"
|
|
|
|
|
|
|
|
#include "../mwmechanics/creaturestats.hpp"
|
|
|
|
#include "../mwmechanics/npcstats.hpp"
|
|
|
|
|
2013-08-12 23:19:33 +00:00
|
|
|
#include "../mwworld/containerstore.hpp"
|
|
|
|
|
2012-10-01 15:17:04 +00:00
|
|
|
#include "esmstore.hpp"
|
2012-09-13 11:02:26 +00:00
|
|
|
#include "class.hpp"
|
|
|
|
|
|
|
|
namespace MWWorld
|
|
|
|
{
|
|
|
|
void ActionEat::executeImp (const Ptr& actor)
|
|
|
|
{
|
2013-08-12 23:19:33 +00:00
|
|
|
// remove used item (assume the item is present in inventory)
|
|
|
|
getTarget().getContainerStore()->remove(getTarget(), 1, actor);
|
2012-09-13 11:02:26 +00:00
|
|
|
|
|
|
|
// 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) {}
|
|
|
|
}
|