1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-10-15 18:46:33 +00:00

Change Class::onHit to take a weapon id

This commit is contained in:
Evil Eye 2025-08-24 09:45:20 +02:00
parent 592b648c3e
commit 52adca2291
9 changed files with 30 additions and 35 deletions

View file

@ -82,7 +82,7 @@ message(STATUS "Configuring OpenMW...")
set(OPENMW_VERSION_MAJOR 0)
set(OPENMW_VERSION_MINOR 50)
set(OPENMW_VERSION_RELEASE 0)
set(OPENMW_LUA_API_REVISION 93)
set(OPENMW_LUA_API_REVISION 94)
set(OPENMW_POSTPROCESSING_API_REVISION 3)
set(OPENMW_VERSION_COMMITHASH "")

View file

@ -349,9 +349,8 @@ namespace MWClass
damage, healthdmg, hitPosition, true, MWMechanics::DamageSourceType::Melee);
}
void Creature::onHit(const MWWorld::Ptr& ptr, const std::map<std::string, float>& damages,
const MWWorld::Ptr& object, const MWWorld::Ptr& attacker, bool successful,
const MWMechanics::DamageSourceType sourceType) const
void Creature::onHit(const MWWorld::Ptr& ptr, const std::map<std::string, float>& damages, ESM::RefId object,
const MWWorld::Ptr& attacker, bool successful, const MWMechanics::DamageSourceType sourceType) const
{
MWMechanics::CreatureStats& stats = getCreatureStats(ptr);
@ -386,8 +385,8 @@ namespace MWClass
statsAttacker.setHitAttemptActorId(stats.getActorId());
}
if (!object.isEmpty())
stats.setLastHitAttemptObject(object.getCellRef().getRefId());
if (!object.empty())
stats.setLastHitAttemptObject(object);
if (setOnPcHitMe && !attacker.isEmpty() && attacker == MWMechanics::getPlayer())
{
@ -403,8 +402,8 @@ namespace MWClass
return;
}
if (!object.isEmpty())
stats.setLastHitObject(object.getCellRef().getRefId());
if (!object.empty())
stats.setLastHitObject(object);
bool hasDamage = false;
bool hasHealthDamage = false;

View file

@ -66,7 +66,7 @@ namespace MWClass
void hit(const MWWorld::Ptr& ptr, float attackStrength, int type, const MWWorld::Ptr& victim,
const osg::Vec3f& hitPosition, bool success) const override;
void onHit(const MWWorld::Ptr& ptr, const std::map<std::string, float>& damages, const MWWorld::Ptr& object,
void onHit(const MWWorld::Ptr& ptr, const std::map<std::string, float>& damages, ESM::RefId object,
const MWWorld::Ptr& attacker, bool successful,
const MWMechanics::DamageSourceType sourceType) const override;

View file

@ -700,7 +700,7 @@ namespace MWClass
damage, healthdmg, hitPosition, true, MWMechanics::DamageSourceType::Melee);
}
void Npc::onHit(const MWWorld::Ptr& ptr, const std::map<std::string, float>& damages, const MWWorld::Ptr& object,
void Npc::onHit(const MWWorld::Ptr& ptr, const std::map<std::string, float>& damages, ESM::RefId object,
const MWWorld::Ptr& attacker, bool successful, const MWMechanics::DamageSourceType sourceType) const
{
MWMechanics::CreatureStats& stats = getCreatureStats(ptr);
@ -735,8 +735,8 @@ namespace MWClass
statsAttacker.setHitAttemptActorId(stats.getActorId());
}
if (!object.isEmpty())
stats.setLastHitAttemptObject(object.getCellRef().getRefId());
if (!object.empty())
stats.setLastHitAttemptObject(object);
if (setOnPcHitMe && !attacker.isEmpty() && attacker == MWMechanics::getPlayer())
{
@ -752,8 +752,8 @@ namespace MWClass
return;
}
if (!object.isEmpty())
stats.setLastHitObject(object.getCellRef().getRefId());
if (!object.empty())
stats.setLastHitObject(object);
if (ptr == MWMechanics::getPlayer() && MWBase::Environment::get().getWorld()->getGodModeState())
return;

View file

@ -81,7 +81,7 @@ namespace MWClass
void hit(const MWWorld::Ptr& ptr, float attackStrength, int type, const MWWorld::Ptr& victim,
const osg::Vec3f& hitPosition, bool success) const override;
void onHit(const MWWorld::Ptr& ptr, const std::map<std::string, float>& damages, const MWWorld::Ptr& object,
void onHit(const MWWorld::Ptr& ptr, const std::map<std::string, float>& damages, ESM::RefId object,
const MWWorld::Ptr& attacker, bool successful,
const MWMechanics::DamageSourceType sourceType) const override;

View file

@ -439,30 +439,27 @@ namespace MWLua
sourceType = MWMechanics::DamageSourceType::Ranged;
else if (sourceTypeStr == "magic")
sourceType = MWMechanics::DamageSourceType::Magical;
sol::optional<Object> weapon = options.get<sol::optional<Object>>("weapon");
std::string_view ammoId = options.get_or<std::string_view>("ammo", {});
ESM::RefId ammo = ESM::RefId::deserializeText(ammoId);
ESM::RefId weaponId = ESM::RefId::deserializeText(ammoId);
if (weaponId.empty())
{
if (sol::optional<Object> weapon = options.get<sol::optional<Object>>("weapon"))
{
MWWorld::Ptr weaponPtr = weapon->ptrOrEmpty();
if (!weaponPtr.isEmpty())
weaponId = weaponPtr.getCellRef().getRefId();
}
}
context.mLuaManager->addAction(
[self = Object(self), damages = std::move(damageCpp),
attacker = options.get<sol::optional<Object>>("attacker"), weapon, ammo,
attacker = options.get<sol::optional<Object>>("attacker"), weaponId,
successful = options.get<bool>("successful"), sourceType = sourceType] {
MWWorld::Ptr attackerPtr;
MWWorld::Ptr weaponPtr;
if (attacker)
attackerPtr = attacker->ptr();
if (weapon)
weaponPtr = weapon->ptrOrEmpty();
if (!ammo.empty())
{
MWWorld::ManualRef projectileRef(*MWBase::Environment::get().getESMStore(), ammo);
weaponPtr = projectileRef.getPtr();
self.ptr().getClass().onHit(
self.ptr(), damages, weaponPtr, attackerPtr, successful, sourceType);
}
else
self.ptr().getClass().onHit(
self.ptr(), damages, weaponPtr, attackerPtr, successful, sourceType);
self.ptr().getClass().onHit(self.ptr(), damages, weaponId, attackerPtr, successful, sourceType);
},
"HitAction");
};

View file

@ -359,7 +359,7 @@ namespace
// Notify the target actor they've been hit
bool isHarmful = magicEffect->mData.mFlags & ESM::MagicEffect::Harmful;
if (target.getClass().isActor() && target != caster && !caster.isEmpty() && isHarmful)
target.getClass().onHit(target, {}, MWWorld::Ptr(), caster, true, MWMechanics::DamageSourceType::Magical);
target.getClass().onHit(target, {}, {}, caster, true, MWMechanics::DamageSourceType::Magical);
// Apply resistances
if (!(effect.mFlags & ESM::ActiveEffect::Flag_Ignore_Resistances))
{

View file

@ -119,7 +119,7 @@ namespace MWWorld
throw std::runtime_error("class cannot hit");
}
void Class::onHit(const Ptr& ptr, const std::map<std::string, float>& damages, const Ptr& object,
void Class::onHit(const Ptr& ptr, const std::map<std::string, float>& damages, ESM::RefId object,
const Ptr& attacker, bool successful, const MWMechanics::DamageSourceType sourceType) const
{
throw std::runtime_error("class cannot be hit");

View file

@ -147,9 +147,8 @@ namespace MWWorld
/// enums. ignored for creature attacks.
/// (default implementation: throw an exception)
virtual void onHit(const MWWorld::Ptr& ptr, const std::map<std::string, float>& damages,
const MWWorld::Ptr& object, const MWWorld::Ptr& attacker, bool successful,
const MWMechanics::DamageSourceType sourceType) const;
virtual void onHit(const MWWorld::Ptr& ptr, const std::map<std::string, float>& damages, ESM::RefId object,
const MWWorld::Ptr& attacker, bool successful, const MWMechanics::DamageSourceType sourceType) const;
///< Alerts \a ptr that it's being hit for \a damages by \a object (sword, arrow, etc). \a attacker specifies
///< the
/// actor responsible for the attack. \a successful specifies if the hit is