mirror of
https://github.com/OpenMW/openmw.git
synced 2025-10-21 17:26:35 +00:00
Pass ammo to Hit handler by record id
This commit is contained in:
parent
2b7f775ffe
commit
592b648c3e
3 changed files with 19 additions and 8 deletions
|
@ -515,7 +515,7 @@ namespace MWLua
|
||||||
if (!weapon.isEmpty())
|
if (!weapon.isEmpty())
|
||||||
data["weapon"] = LObject(weapon);
|
data["weapon"] = LObject(weapon);
|
||||||
if (!ammo.isEmpty())
|
if (!ammo.isEmpty())
|
||||||
data["ammo"] = LObject(weapon);
|
data["ammo"] = ammo.getCellRef().getRefId().serializeText();
|
||||||
data["type"] = attackType;
|
data["type"] = attackType;
|
||||||
data["strength"] = attackStrength;
|
data["strength"] = attackStrength;
|
||||||
data["damage"] = damageTable;
|
data["damage"] = damageTable;
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include "apps/openmw/mwmechanics/drawstate.hpp"
|
#include "apps/openmw/mwmechanics/drawstate.hpp"
|
||||||
#include "apps/openmw/mwworld/class.hpp"
|
#include "apps/openmw/mwworld/class.hpp"
|
||||||
#include "apps/openmw/mwworld/inventorystore.hpp"
|
#include "apps/openmw/mwworld/inventorystore.hpp"
|
||||||
|
#include "apps/openmw/mwworld/manualref.hpp"
|
||||||
#include "apps/openmw/mwworld/worldmodel.hpp"
|
#include "apps/openmw/mwworld/worldmodel.hpp"
|
||||||
|
|
||||||
#include "../localscripts.hpp"
|
#include "../localscripts.hpp"
|
||||||
|
@ -439,19 +440,29 @@ namespace MWLua
|
||||||
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");
|
sol::optional<Object> weapon = options.get<sol::optional<Object>>("weapon");
|
||||||
sol::optional<Object> ammo = options.get<sol::optional<Object>>("ammo");
|
std::string_view ammoId = options.get_or<std::string_view>("ammo", {});
|
||||||
|
ESM::RefId ammo = ESM::RefId::deserializeText(ammoId);
|
||||||
|
|
||||||
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 ? ammo : weapon,
|
attacker = options.get<sol::optional<Object>>("attacker"), weapon, ammo,
|
||||||
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)
|
if (weapon)
|
||||||
weaponPtr = weapon->ptr();
|
weaponPtr = weapon->ptrOrEmpty();
|
||||||
self.ptr().getClass().onHit(self.ptr(), damages, weaponPtr, attackerPtr, successful, sourceType);
|
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");
|
||||||
};
|
};
|
||||||
|
|
|
@ -192,7 +192,7 @@ local function applyArmor(attack)
|
||||||
I.SkillProgression.skillUsed(skillid, {useType = I.SkillProgression.SKILL_USE_TYPES.Armor_HitByOpponent})
|
I.SkillProgression.skillUsed(skillid, {useType = I.SkillProgression.SKILL_USE_TYPES.Armor_HitByOpponent})
|
||||||
end
|
end
|
||||||
if item and Armor.objectIsInstance(item) then
|
if item and Armor.objectIsInstance(item) then
|
||||||
local attackerIsUnarmedCreature = attack.attacker and not attack.weapon and Creature.objectIsInstance(attack.attacker)
|
local attackerIsUnarmedCreature = attack.attacker and not attack.weapon and not attack.ammo and Creature.objectIsInstance(attack.attacker)
|
||||||
if settings:get('unarmedCreatureAttacksDamageArmor') or not attackerIsUnarmedCreature then
|
if settings:get('unarmedCreatureAttacksDamageArmor') or not attackerIsUnarmedCreature then
|
||||||
core.sendGlobalEvent('ModifyItemCondition', { actor = self, item = item, amount = diff })
|
core.sendGlobalEvent('ModifyItemCondition', { actor = self, item = item, amount = diff })
|
||||||
end
|
end
|
||||||
|
@ -307,7 +307,7 @@ end
|
||||||
-- @field [parent=#AttackInfo] openmw.self#ATTACK_TYPE type (Optional) Attack variant if applicable. For melee attacks this represents chop vs thrust vs slash. For unarmed creatures this implies which of its 3 possible attacks were used. For other attacks this field can be ignored.
|
-- @field [parent=#AttackInfo] openmw.self#ATTACK_TYPE type (Optional) Attack variant if applicable. For melee attacks this represents chop vs thrust vs slash. For unarmed creatures this implies which of its 3 possible attacks were used. For other attacks this field can be ignored.
|
||||||
-- @field [parent=#AttackInfo] openmw.types#Actor attacker (Optional) Attacking actor
|
-- @field [parent=#AttackInfo] openmw.types#Actor attacker (Optional) Attacking actor
|
||||||
-- @field [parent=#AttackInfo] openmw.types#Weapon weapon (Optional) Attacking weapon
|
-- @field [parent=#AttackInfo] openmw.types#Weapon weapon (Optional) Attacking weapon
|
||||||
-- @field [parent=#AttackInfo] openmw.types#Weapon ammo (Optional) Ammo
|
-- @field [parent=#AttackInfo] #string ammo (Optional) Ammo record ID
|
||||||
-- @field [parent=#AttackInfo] openmw.util#Vector3 hitPos (Optional) Where on the victim the attack is landing. Used to spawn blood effects. Blood effects are skipped if nil.
|
-- @field [parent=#AttackInfo] openmw.util#Vector3 hitPos (Optional) Where on the victim the attack is landing. Used to spawn blood effects. Blood effects are skipped if nil.
|
||||||
return {
|
return {
|
||||||
--- Basic combat interface
|
--- Basic combat interface
|
||||||
|
@ -330,7 +330,7 @@ return {
|
||||||
interface = {
|
interface = {
|
||||||
--- Interface version
|
--- Interface version
|
||||||
-- @field [parent=#Combat] #number version
|
-- @field [parent=#Combat] #number version
|
||||||
version = 0,
|
version = 1,
|
||||||
|
|
||||||
--- Add new onHit handler for this actor
|
--- Add new onHit handler for this actor
|
||||||
-- If `handler(attack)` returns false, other handlers for
|
-- If `handler(attack)` returns false, other handlers for
|
||||||
|
|
Loading…
Reference in a new issue