mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-08-03 15:27:13 -04:00
Merge branch 'lua_pickup_sound' into 'master'
Add getPickUpSound and getDropSound to new aux package, to return the drop and pickup sounds. See merge request OpenMW/openmw!3385
This commit is contained in:
commit
d7135d070d
5
docs/source/reference/lua-scripting/openmw_aux_item.rst
Normal file
5
docs/source/reference/lua-scripting/openmw_aux_item.rst
Normal file
@ -0,0 +1,5 @@
|
||||
Package openmw_aux.item
|
||||
=======================
|
||||
|
||||
.. raw:: html
|
||||
:file: generated_html/openmw_aux_item.html
|
@ -77,6 +77,7 @@ set(BUILTIN_DATA_FILES
|
||||
openmw_aux/time.lua
|
||||
openmw_aux/calendar.lua
|
||||
openmw_aux/calendarconfig.lua
|
||||
openmw_aux/item.lua
|
||||
openmw_aux/ui.lua
|
||||
|
||||
builtin.omwscripts
|
||||
|
123
files/data/openmw_aux/item.lua
Normal file
123
files/data/openmw_aux/item.lua
Normal file
@ -0,0 +1,123 @@
|
||||
local types = require('openmw.types')
|
||||
local core = require('openmw.core')
|
||||
---
|
||||
-- `openmw_aux.item` defines utility functions for objects.
|
||||
-- Implementation can be found in `resources/vfs/openmw_aux/item.lua`.
|
||||
-- @module item
|
||||
-- @usage local aux_item = require('openmw_aux.item')
|
||||
local aux_item = {}
|
||||
|
||||
local SKILL = core.stats.Skill.records
|
||||
|
||||
local armorSkillString = {[SKILL.heavyarmor.id] = "Heavy",[SKILL.mediumarmor.id] = "Medium", [SKILL.lightarmor.id] = "Light"}
|
||||
---
|
||||
-- Checks if the provided armor is Heavy, Medium, or Light. Errors if invaid object supplied.
|
||||
-- @function [parent=#item] getArmorType
|
||||
-- @param openmw.core#GameObject armor Either a gameObject or a armor record.
|
||||
-- @return #string The skill record ID for this armor
|
||||
function aux_item.getArmorType(armor)
|
||||
|
||||
if armor.type ~= types.Armor and not armor.baseArmor then
|
||||
error("Not Armor")
|
||||
end
|
||||
local record = nil
|
||||
if armor.baseArmor then--A record was supplied, not a gameObject
|
||||
record = armor
|
||||
else
|
||||
record = types.Armor.record(armor)
|
||||
end
|
||||
local epsilon = 0.0005;
|
||||
local lightMultiplier = core.getGMST("fLightMaxMod") + epsilon
|
||||
local medMultiplier = core.getGMST("fMedMaxMod") + epsilon
|
||||
local armorGMSTs = {
|
||||
[types.Armor.TYPE.Boots] = "iBootsWeight",
|
||||
[types.Armor.TYPE.Cuirass] = "iCuirassWeight",
|
||||
[types.Armor.TYPE.Greaves] = "iGreavesWeight",
|
||||
[types.Armor.TYPE.Shield] = "iShieldWeight",
|
||||
[types.Armor.TYPE.LBracer] = "iGauntletWeight",
|
||||
[types.Armor.TYPE.RBracer] = "iGauntletWeight",
|
||||
[types.Armor.TYPE.RPauldron] = "iPauldronWeight",
|
||||
[types.Armor.TYPE.LPauldron] = "iPauldronWeight",
|
||||
[types.Armor.TYPE.Helmet] = "iHelmWeight",
|
||||
[types.Armor.TYPE.LGauntlet] = "iGauntletWeight",
|
||||
[types.Armor.TYPE.RGauntlet] = "iGauntletWeight",
|
||||
}
|
||||
local armorType = record.type
|
||||
local weight = record.weight
|
||||
local armorTypeWeight = math.floor(core.getGMST(armorGMSTs[armorType]))
|
||||
|
||||
if weight <= armorTypeWeight * lightMultiplier then
|
||||
return SKILL.lightarmor.id
|
||||
elseif weight <= armorTypeWeight * medMultiplier then
|
||||
return SKILL.mediumarmor.id
|
||||
else
|
||||
return SKILL.heavyarmor.id
|
||||
end
|
||||
end
|
||||
|
||||
local weaponType = types.Weapon.TYPE
|
||||
local weaponSound = {
|
||||
[weaponType.BluntOneHand] = "Weapon Blunt",
|
||||
[weaponType.BluntTwoClose] = "Weapon Blunt",
|
||||
[weaponType.BluntTwoWide] = "Weapon Blunt",
|
||||
[weaponType.MarksmanThrown] = "Weapon Blunt",
|
||||
[weaponType.Arrow] = "Ammo",
|
||||
[weaponType.Bolt] = "Ammo",
|
||||
[weaponType.SpearTwoWide] = "Weapon Spear",
|
||||
[weaponType.MarksmanBow] = "Weapon Bow",
|
||||
[weaponType.MarksmanCrossbow] = "Weapon Crossbow",
|
||||
[weaponType.AxeOneHand] = "Weapon Blunt",
|
||||
[weaponType.AxeTwoHand] = "Weapon Blunt",
|
||||
[weaponType.ShortBladeOneHand] = "Weapon Shortblade",
|
||||
[weaponType.LongBladeOneHand] = "Weapon Longblade",
|
||||
[weaponType.LongBladeTwoHand] = "Weapon Longblade",
|
||||
}
|
||||
local goldIds = { gold_001 = true, gold_005 = true, gold_010 = true, gold_025 = true, gold_100 = true }
|
||||
local function getItemSoundId(object,suffix)
|
||||
local type = object.type
|
||||
if object.type.baseType ~= types.Item or not object then
|
||||
error("Invalid object supplied")
|
||||
end
|
||||
local record = object.type.record(object)
|
||||
local soundId = tostring(type) -- .. " Up"
|
||||
if type == types.Armor then
|
||||
soundId = "Armor " .. armorSkillString[aux_item.getArmorType(object)]
|
||||
elseif type == types.Clothing then
|
||||
soundId = "Clothes"
|
||||
if record.type == types.Clothing.TYPE.Ring then
|
||||
soundId = "Ring"
|
||||
end
|
||||
elseif type == types.Light or type == types.Miscellaneous then
|
||||
if goldIds[object.recordId] then
|
||||
soundId = "Gold"
|
||||
else
|
||||
soundId = "Misc"
|
||||
end
|
||||
elseif type == types.Weapon then
|
||||
soundId = weaponSound[record.type]
|
||||
end
|
||||
return string.format('item %s %s', soundId, suffix)
|
||||
end
|
||||
|
||||
|
||||
---
|
||||
-- Get the sound that should be played when this item is dropped.
|
||||
-- @function [parent=#item] getDropSound
|
||||
-- @param openmw.core#GameObject item
|
||||
-- @return #string
|
||||
function aux_item.getDropSound(item)
|
||||
local itemType = getItemSoundId(item)
|
||||
return getItemSoundId(itemType, "down")
|
||||
end
|
||||
|
||||
---
|
||||
-- Get the sound that should be played when this item is picked up.
|
||||
-- @function [parent=#item] getPickupSound
|
||||
-- @param openmw.core#GameObject item
|
||||
-- @return #string
|
||||
function aux_item.getPickupSound(item)
|
||||
local itemType = getItemSoundId(item)
|
||||
return getItemSoundId(itemType, "up")
|
||||
end
|
||||
|
||||
return aux_item
|
Loading…
x
Reference in New Issue
Block a user