Commit b5e41cbe96274ec15d86a2f4f502891ba53d0c26

Authored by DarkGod
2 parents 10cfd29b f75f4b0e

Merge branch 'more_self_referential_inventory' into 'master'

Make objects know what inventory they're in.

Inspired by the mess that is Wintertide's special on hit. As of !693, combat tables and their objects is now a two-way association. This MR aims to make the object-actor association similarly two way. Items should know where they are and who is holding them, which is accomplished by setting `o.in_inven`, which holds `o.in_inven.actor` and `o.in_inven.id`. This prevents requiring obnoxious searches of inventories for an item in question, and prevents potential search collisions (as `define_as` is not a perfect identifier).

**This MR is save safe, although any behavior reliant on this will not apply to objects without changing their position in inventories.**

See merge request !802
... ... @@ -313,6 +313,8 @@ function _M:onAddObject(o, inven_id, item)
313 313 end
314 314 end
315 315 end
  316 +
  317 + o.in_inven = {actor = self, id = inven_id}
316 318 end
317 319
318 320 --- Called upon removing an object
... ... @@ -323,6 +325,7 @@ function _M:onRemoveObject(o, inven_id, item)
323 325 end
324 326 end
325 327 o.carried = nil
  328 + o.in_inven = nil
326 329 end
327 330
328 331 --- Called upon dropping an object
... ...
... ... @@ -68,8 +68,9 @@ It is said the Conclave created this weapon for their warmaster during the dark
68 68 local Map = require "engine.Map"
69 69
70 70 -- special_on_hit doesn't know what item triggered it, so find it
71   - local self, item, inven_id = who:findInAllInventoriesBy("define_as", "LONGSWORD_WINTERTIDE")
72   - if not self or not who:getInven(inven_id).worn then return end
  71 + local self = combat.self
  72 + local inven_id = self and self.in_inven and self.in_inven.id
  73 + if not self or not inven_id or not who:getInven(inven_id).worn then return end
73 74
74 75 if who.turn_procs.wintertide_sword then return end
75 76
... ...