mirror of
https://github.com/badvision/lawless-legends.git
synced 2024-10-03 06:54:42 +00:00
More work on stackables.
This commit is contained in:
parent
dbc94d707c
commit
ddbeebd9b0
@ -2767,12 +2767,23 @@ end
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Add to a list if named obj not already in it; returns TRUE if really added.
|
||||
// Also handles incrementing stackable items.
|
||||
export def addUnique(pList, p_thing)#1
|
||||
if !scanForNamedObj(*pList, p_thing=>s_name)
|
||||
addToList(pList, p_thing)
|
||||
word p_existing
|
||||
|
||||
// If it's stackable and player already has some, just increase the stack
|
||||
p_existing = scanForNamedObj(*pList, p_thing=>s_name)
|
||||
if p_existing
|
||||
if p_existing->t_type == TYPE_FANCY_ITEM and p_existing=>w_count > 0
|
||||
p_existing=>w_count++
|
||||
return TRUE
|
||||
fin
|
||||
return FALSE
|
||||
return FALSE // already have one, and it's not stackable
|
||||
fin
|
||||
|
||||
// Otherwise, add a new item
|
||||
addToList(pList, p_thing)
|
||||
return TRUE
|
||||
end
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -2886,7 +2897,12 @@ export def removeNamed(name, pList)#0
|
||||
word p_thing
|
||||
p_thing = scanForNamedObj(*pList, name)
|
||||
if p_thing
|
||||
// If it's stackable and there's more than one, just reduce the count. Otherwise take it all.
|
||||
if p_thing->t_type == TYPE_FANCY_ITEM and p_thing=>w_count > 1
|
||||
p_thing=>w_count--
|
||||
else
|
||||
removeFromList(pList, p_thing)
|
||||
fin
|
||||
else
|
||||
printf1("Warning: couldn't find '%s' to remove.\n", name)
|
||||
fin
|
||||
|
@ -406,22 +406,33 @@ end
|
||||
|
||||
// Select an item and use it. Returns item if it needs to be processed by outer loop, else NULL
|
||||
def doUse(player, item)#1
|
||||
if item=>p_modifiers
|
||||
if streqi(item=>p_modifiers=>s_name, @S_HEALTH)
|
||||
word pMod, oldVal, newVal
|
||||
if item->t_type == TYPE_FANCY_ITEM and item=>p_modifiers
|
||||
clearMenuRect()
|
||||
clearMainRect()
|
||||
rawDisplayStr("^V000\n^J^J^J")
|
||||
if player=>w_health < player=>w_maxHealth
|
||||
player=>w_health = min(player=>w_health + item=>p_modifiers=>w_modValue, player=>w_maxHealth)
|
||||
removeFromList(@player=>p_items, item)
|
||||
rawDisplayf2("Healed to %d/%d", player=>w_health, player=>w_maxHealth)
|
||||
pMod = item=>p_modifiers
|
||||
while pMod
|
||||
oldVal = getStat(player, pMod=>s_name)
|
||||
setStat(player, pMod=>s_name, oldVal + pMod=>w_modValue)
|
||||
newVal = getStat(player, pMod=>s_name)
|
||||
rawDisplayStr(pMod=>s_name)
|
||||
if newVal <> oldVal
|
||||
takeItemFromPlayer(player, item=>s_name) // also handles reducing count of stackables
|
||||
if newVal > oldVal
|
||||
rawDisplayStr(" increased")
|
||||
else
|
||||
rawDisplayStr("No healing needed.")
|
||||
rawDisplayStr(" decreased")
|
||||
fin
|
||||
rawDisplayf2(" from %d to %d.", oldVal, newVal)
|
||||
else
|
||||
rawDisplayStr(" already at the limit.")
|
||||
fin
|
||||
pause(800)
|
||||
pMod = pMod=>p_nextObj
|
||||
loop
|
||||
return NULL
|
||||
fin
|
||||
fin
|
||||
return item // general 'use' handled by outer engine, because it might involve graphics
|
||||
end
|
||||
|
||||
@ -878,12 +889,10 @@ end
|
||||
// For countable "stuff" (e.g. ammo), display the count and appropriate singular or plural name.
|
||||
def _displayItemName(pItem)#1
|
||||
isPlural = FALSE
|
||||
if pItem->t_type == TYPE_FANCY_ITEM
|
||||
if pItem=>w_count > 0
|
||||
if pItem->t_type == TYPE_FANCY_ITEM and pItem=>w_count > 0
|
||||
isPlural = pItem=>w_count > 1
|
||||
rawDisplayf1("%d ", pItem=>w_count)
|
||||
fin
|
||||
fin
|
||||
buildString(@addToString)
|
||||
printf1("%s", pItem=>s_name) // need proper plural processing
|
||||
rawDisplayStr(finishString(isPlural))
|
||||
|
@ -185,7 +185,7 @@ def browseItem(num)#0
|
||||
matchEquipped(pItem, compSkip) // to set pMatchPlayer
|
||||
pComp = scanForNamedObj(pMatchPlayer=>p_items, pItem=>s_name)
|
||||
if pComp
|
||||
if pItem->t_type == TYPE_FANCY_ITEM
|
||||
if pItem->t_type == TYPE_FANCY_ITEM and pItem=>w_count > 0
|
||||
pComp=>w_count = min(30000, pComp=>w_count + pItem=>w_count)
|
||||
else
|
||||
rawDisplayStr("\nDuplicate item.")
|
||||
|
Loading…
Reference in New Issue
Block a user