mirror of
https://github.com/OpenMW/openmw.git
synced 2025-10-15 08:56:35 +00:00
Change Class::onHit to take a weapon id
This commit is contained in:
parent
592b648c3e
commit
52adca2291
9 changed files with 30 additions and 35 deletions
|
@ -82,7 +82,7 @@ message(STATUS "Configuring OpenMW...")
|
||||||
set(OPENMW_VERSION_MAJOR 0)
|
set(OPENMW_VERSION_MAJOR 0)
|
||||||
set(OPENMW_VERSION_MINOR 50)
|
set(OPENMW_VERSION_MINOR 50)
|
||||||
set(OPENMW_VERSION_RELEASE 0)
|
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_POSTPROCESSING_API_REVISION 3)
|
||||||
|
|
||||||
set(OPENMW_VERSION_COMMITHASH "")
|
set(OPENMW_VERSION_COMMITHASH "")
|
||||||
|
|
|
@ -349,9 +349,8 @@ namespace MWClass
|
||||||
damage, healthdmg, hitPosition, true, MWMechanics::DamageSourceType::Melee);
|
damage, healthdmg, hitPosition, true, MWMechanics::DamageSourceType::Melee);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Creature::onHit(const MWWorld::Ptr& ptr, const std::map<std::string, float>& damages,
|
void Creature::onHit(const MWWorld::Ptr& ptr, const std::map<std::string, float>& damages, ESM::RefId object,
|
||||||
const MWWorld::Ptr& object, const MWWorld::Ptr& attacker, bool successful,
|
const MWWorld::Ptr& attacker, bool successful, const MWMechanics::DamageSourceType sourceType) const
|
||||||
const MWMechanics::DamageSourceType sourceType) const
|
|
||||||
{
|
{
|
||||||
MWMechanics::CreatureStats& stats = getCreatureStats(ptr);
|
MWMechanics::CreatureStats& stats = getCreatureStats(ptr);
|
||||||
|
|
||||||
|
@ -386,8 +385,8 @@ namespace MWClass
|
||||||
statsAttacker.setHitAttemptActorId(stats.getActorId());
|
statsAttacker.setHitAttemptActorId(stats.getActorId());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!object.isEmpty())
|
if (!object.empty())
|
||||||
stats.setLastHitAttemptObject(object.getCellRef().getRefId());
|
stats.setLastHitAttemptObject(object);
|
||||||
|
|
||||||
if (setOnPcHitMe && !attacker.isEmpty() && attacker == MWMechanics::getPlayer())
|
if (setOnPcHitMe && !attacker.isEmpty() && attacker == MWMechanics::getPlayer())
|
||||||
{
|
{
|
||||||
|
@ -403,8 +402,8 @@ namespace MWClass
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!object.isEmpty())
|
if (!object.empty())
|
||||||
stats.setLastHitObject(object.getCellRef().getRefId());
|
stats.setLastHitObject(object);
|
||||||
|
|
||||||
bool hasDamage = false;
|
bool hasDamage = false;
|
||||||
bool hasHealthDamage = false;
|
bool hasHealthDamage = false;
|
||||||
|
|
|
@ -66,7 +66,7 @@ namespace MWClass
|
||||||
void hit(const MWWorld::Ptr& ptr, float attackStrength, int type, const MWWorld::Ptr& victim,
|
void hit(const MWWorld::Ptr& ptr, float attackStrength, int type, const MWWorld::Ptr& victim,
|
||||||
const osg::Vec3f& hitPosition, bool success) const override;
|
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 MWWorld::Ptr& attacker, bool successful,
|
||||||
const MWMechanics::DamageSourceType sourceType) const override;
|
const MWMechanics::DamageSourceType sourceType) const override;
|
||||||
|
|
||||||
|
|
|
@ -700,7 +700,7 @@ namespace MWClass
|
||||||
damage, healthdmg, hitPosition, true, MWMechanics::DamageSourceType::Melee);
|
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
|
const MWWorld::Ptr& attacker, bool successful, const MWMechanics::DamageSourceType sourceType) const
|
||||||
{
|
{
|
||||||
MWMechanics::CreatureStats& stats = getCreatureStats(ptr);
|
MWMechanics::CreatureStats& stats = getCreatureStats(ptr);
|
||||||
|
@ -735,8 +735,8 @@ namespace MWClass
|
||||||
statsAttacker.setHitAttemptActorId(stats.getActorId());
|
statsAttacker.setHitAttemptActorId(stats.getActorId());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!object.isEmpty())
|
if (!object.empty())
|
||||||
stats.setLastHitAttemptObject(object.getCellRef().getRefId());
|
stats.setLastHitAttemptObject(object);
|
||||||
|
|
||||||
if (setOnPcHitMe && !attacker.isEmpty() && attacker == MWMechanics::getPlayer())
|
if (setOnPcHitMe && !attacker.isEmpty() && attacker == MWMechanics::getPlayer())
|
||||||
{
|
{
|
||||||
|
@ -752,8 +752,8 @@ namespace MWClass
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!object.isEmpty())
|
if (!object.empty())
|
||||||
stats.setLastHitObject(object.getCellRef().getRefId());
|
stats.setLastHitObject(object);
|
||||||
|
|
||||||
if (ptr == MWMechanics::getPlayer() && MWBase::Environment::get().getWorld()->getGodModeState())
|
if (ptr == MWMechanics::getPlayer() && MWBase::Environment::get().getWorld()->getGodModeState())
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -81,7 +81,7 @@ namespace MWClass
|
||||||
void hit(const MWWorld::Ptr& ptr, float attackStrength, int type, const MWWorld::Ptr& victim,
|
void hit(const MWWorld::Ptr& ptr, float attackStrength, int type, const MWWorld::Ptr& victim,
|
||||||
const osg::Vec3f& hitPosition, bool success) const override;
|
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 MWWorld::Ptr& attacker, bool successful,
|
||||||
const MWMechanics::DamageSourceType sourceType) const override;
|
const MWMechanics::DamageSourceType sourceType) const override;
|
||||||
|
|
||||||
|
|
|
@ -439,30 +439,27 @@ namespace MWLua
|
||||||
sourceType = MWMechanics::DamageSourceType::Ranged;
|
sourceType = MWMechanics::DamageSourceType::Ranged;
|
||||||
else if (sourceTypeStr == "magic")
|
else if (sourceTypeStr == "magic")
|
||||||
sourceType = MWMechanics::DamageSourceType::Magical;
|
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", {});
|
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(
|
context.mLuaManager->addAction(
|
||||||
[self = Object(self), damages = std::move(damageCpp),
|
[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] {
|
successful = options.get<bool>("successful"), sourceType = sourceType] {
|
||||||
MWWorld::Ptr attackerPtr;
|
MWWorld::Ptr attackerPtr;
|
||||||
MWWorld::Ptr weaponPtr;
|
MWWorld::Ptr weaponPtr;
|
||||||
if (attacker)
|
if (attacker)
|
||||||
attackerPtr = attacker->ptr();
|
attackerPtr = attacker->ptr();
|
||||||
if (weapon)
|
self.ptr().getClass().onHit(self.ptr(), damages, weaponId, attackerPtr, successful, sourceType);
|
||||||
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);
|
|
||||||
},
|
},
|
||||||
"HitAction");
|
"HitAction");
|
||||||
};
|
};
|
||||||
|
|
|
@ -359,7 +359,7 @@ namespace
|
||||||
// Notify the target actor they've been hit
|
// Notify the target actor they've been hit
|
||||||
bool isHarmful = magicEffect->mData.mFlags & ESM::MagicEffect::Harmful;
|
bool isHarmful = magicEffect->mData.mFlags & ESM::MagicEffect::Harmful;
|
||||||
if (target.getClass().isActor() && target != caster && !caster.isEmpty() && isHarmful)
|
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
|
// Apply resistances
|
||||||
if (!(effect.mFlags & ESM::ActiveEffect::Flag_Ignore_Resistances))
|
if (!(effect.mFlags & ESM::ActiveEffect::Flag_Ignore_Resistances))
|
||||||
{
|
{
|
||||||
|
|
|
@ -119,7 +119,7 @@ namespace MWWorld
|
||||||
throw std::runtime_error("class cannot hit");
|
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
|
const Ptr& attacker, bool successful, const MWMechanics::DamageSourceType sourceType) const
|
||||||
{
|
{
|
||||||
throw std::runtime_error("class cannot be hit");
|
throw std::runtime_error("class cannot be hit");
|
||||||
|
|
|
@ -147,9 +147,8 @@ namespace MWWorld
|
||||||
/// enums. ignored for creature attacks.
|
/// enums. ignored for creature attacks.
|
||||||
/// (default implementation: throw an exception)
|
/// (default implementation: throw an exception)
|
||||||
|
|
||||||
virtual void onHit(const MWWorld::Ptr& ptr, const std::map<std::string, float>& damages,
|
virtual void onHit(const MWWorld::Ptr& ptr, const std::map<std::string, float>& damages, ESM::RefId object,
|
||||||
const MWWorld::Ptr& object, const MWWorld::Ptr& attacker, bool successful,
|
const MWWorld::Ptr& attacker, bool successful, const MWMechanics::DamageSourceType sourceType) const;
|
||||||
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
|
///< Alerts \a ptr that it's being hit for \a damages by \a object (sword, arrow, etc). \a attacker specifies
|
||||||
///< the
|
///< the
|
||||||
/// actor responsible for the attack. \a successful specifies if the hit is
|
/// actor responsible for the attack. \a successful specifies if the hit is
|
||||||
|
|
Loading…
Reference in a new issue