Allow creatures to use potions

macos_ci_fix
Evil Eye 8 months ago
parent 08ff69f199
commit 0814ef5697

@ -74,6 +74,7 @@
Bug #7557: Terrain::ChunkManager::createChunk is called twice for the same position, lod on initial loading
Bug #7573: Drain Fatigue can't bring fatigue below zero by default
Bug #7603: Scripts menu size is not updated properly
Bug #7604: Goblins Grunt becomes idle once injured
Feature #3537: Shader-based water ripples
Feature #5492: Let rain and snow collide with statics
Feature #6149: Dehardcode Lua API_REVISION

@ -3,6 +3,7 @@
#include <components/esm3/loadmgef.hpp>
#include "../mwbase/environment.hpp"
#include "../mwbase/luamanager.hpp"
#include "../mwbase/soundmanager.hpp"
#include "../mwbase/world.hpp"
@ -14,6 +15,7 @@
#include "../mwphysics/physicssystem.hpp"
#include "../mwworld/inventorystore.hpp"
#include "../mwworld/worldmodel.hpp"
namespace MWClass
{
@ -90,4 +92,15 @@ namespace MWClass
moveSpeed *= 0.75f;
return moveSpeed;
}
bool Actor::consume(const MWWorld::Ptr& consumable, const MWWorld::Ptr& actor) const
{
MWBase::Environment::get().getWorld()->breakInvisibility(actor);
MWMechanics::CastSpell cast(actor, actor);
const ESM::RefId& recordId = consumable.getCellRef().getRefId();
MWBase::Environment::get().getWorldModel()->registerPtr(consumable);
MWBase::Environment::get().getLuaManager()->itemConsumed(consumable, actor);
actor.getClass().getContainerStore(actor).remove(consumable, 1);
return cast.cast(recordId);
}
}

@ -62,6 +62,8 @@ namespace MWClass
/// Return current movement speed.
float getCurrentSpeed(const MWWorld::Ptr& ptr) const override;
bool consume(const MWWorld::Ptr& consumable, const MWWorld::Ptr& actor) const override;
// not implemented
Actor(const Actor&) = delete;
Actor& operator=(const Actor&) = delete;

@ -21,7 +21,6 @@
#include "../mwbase/dialoguemanager.hpp"
#include "../mwbase/environment.hpp"
#include "../mwbase/luamanager.hpp"
#include "../mwbase/mechanicsmanager.hpp"
#include "../mwbase/soundmanager.hpp"
#include "../mwbase/windowmanager.hpp"
@ -1123,17 +1122,6 @@ namespace MWClass
return getNpcStats(ptr).isWerewolf() ? 0.0f : Actor::getEncumbrance(ptr);
}
bool Npc::consume(const MWWorld::Ptr& consumable, const MWWorld::Ptr& actor) const
{
MWBase::Environment::get().getWorld()->breakInvisibility(actor);
MWMechanics::CastSpell cast(actor, actor);
const ESM::RefId& recordId = consumable.getCellRef().getRefId();
MWBase::Environment::get().getWorldModel()->registerPtr(consumable);
MWBase::Environment::get().getLuaManager()->itemConsumed(consumable, actor);
actor.getClass().getContainerStore(actor).remove(consumable, 1);
return cast.cast(recordId);
}
void Npc::skillUsageSucceeded(const MWWorld::Ptr& ptr, ESM::RefId skill, int usageType, float extraFactor) const
{
MWMechanics::NpcStats& stats = getNpcStats(ptr);

@ -114,8 +114,6 @@ namespace MWClass
float getArmorRating(const MWWorld::Ptr& ptr) const override;
///< @return combined armor rating of this actor
bool consume(const MWWorld::Ptr& consumable, const MWWorld::Ptr& actor) const override;
void adjustScale(const MWWorld::ConstPtr& ptr, osg::Vec3f& scale, bool rendering) const override;
/// @param rendering Indicates if the scale to adjust is for the rendering mesh, or for the collision mesh

@ -176,34 +176,35 @@ namespace MWMechanics
return bestAction;
}
if (actor.getClass().hasInventoryStore(actor))
const bool hasInventoryStore = actor.getClass().hasInventoryStore(actor);
MWWorld::ContainerStore& store = actor.getClass().getContainerStore(actor);
for (MWWorld::ContainerStoreIterator it = store.begin(); it != store.end(); ++it)
{
MWWorld::InventoryStore& store = actor.getClass().getInventoryStore(actor);
for (MWWorld::ContainerStoreIterator it = store.begin(); it != store.end(); ++it)
if (it->getType() == ESM::Potion::sRecordId)
{
if (it->getType() == ESM::Potion::sRecordId)
float rating = ratePotion(*it, actor);
if (rating > bestActionRating)
{
float rating = ratePotion(*it, actor);
if (rating > bestActionRating)
{
bestActionRating = rating;
bestAction = std::make_unique<ActionPotion>(*it);
antiFleeRating = std::numeric_limits<float>::max();
}
bestActionRating = rating;
bestAction = std::make_unique<ActionPotion>(*it);
antiFleeRating = std::numeric_limits<float>::max();
}
else if (!it->getClass().getEnchantment(*it).empty())
}
// TODO remove inventory store check, creatures should be able to use enchanted items they cannot equip
else if (hasInventoryStore && !it->getClass().getEnchantment(*it).empty())
{
float rating = rateMagicItem(*it, actor, enemy);
if (rating > bestActionRating)
{
float rating = rateMagicItem(*it, actor, enemy);
if (rating > bestActionRating)
{
bestActionRating = rating;
bestAction = std::make_unique<ActionEnchantedItem>(it);
antiFleeRating = std::numeric_limits<float>::max();
}
bestActionRating = rating;
bestAction = std::make_unique<ActionEnchantedItem>(it);
antiFleeRating = std::numeric_limits<float>::max();
}
}
}
if (hasInventoryStore)
{
MWWorld::Ptr bestArrow;
float bestArrowRating = rateAmmo(actor, enemy, bestArrow, ESM::Weapon::Arrow);

Loading…
Cancel
Save