Make unequip event occur on equipped item drop

This commit is contained in:
2022-05-25 23:20:14 +01:00
parent 34612822ae
commit 58427da0c4
+6
View File
@@ -56,10 +56,16 @@ rmInvItem cid invid w = case w ^? creatures . ix cid . crInv . ix invid . itCons
& creatures . ix cid . crInvSel %~ g
& creatures . ix cid . crLeftInvSel %~ g'
& removeAnySlotEquipment
& dounequipfunction
& creatures . ix cid . crInvEquipped %~ IM.delete invid
& creatures . ix cid . crInvEquipped %~ IM.mapKeys g
-- TODO check whether this can be mapKeysMonotonic
where
cr = _creatures w IM.! cid
itm = _crInv cr IM.! invid
dounequipfunction = fromMaybe id $ do
rmf <- itm ^? itUse . eqOnRemove
return $ rmf itm cr
removeAnySlotEquipment = case w ^? creatures . ix cid . crInvEquipped . ix invid of
Just epos -> creatures . ix cid . crEquipment . at epos .~ Nothing
Nothing -> id