/** * Replaces an item in all inventories. * @param oldItemIO the old item being replaced * @param newItemIO the new item * @ if an error occurs */ public void ReplaceInAllInventories(BaseInteractiveObject oldItemIO, BaseInteractiveObject newItemIO) { if (oldItemIO != null && !oldItemIO.HasIOFlag(IoGlobals.IO_15_MOVABLE) && newItemIO != null && !newItemIO.HasIOFlag(IoGlobals.IO_15_MOVABLE)) { int oldIORefId = Interactive.Instance.GetInterNum(oldItemIO); int newIORefId = Interactive.Instance.GetInterNum(newItemIO); int i = Interactive.Instance.GetMaxIORefId(); for (; i >= 0; i--) { if (i == oldIORefId || i == newIORefId || !Interactive.Instance.HasIO(i)) { continue; } BaseInteractiveObject invOwner = (BaseInteractiveObject)Interactive.Instance.GetIO(i); if (invOwner.Inventory != null) { InventoryData inv = invOwner.Inventory; for (int j = inv.Slots.Length - 1; j >= 0; j--) { if (inv.Slots[j].Io.Equals(oldItemIO)) { inv.Slots[j].Io = newItemIO; } } } } } }
/** * UNTESTED DO NOT USE Replaces an item in an BaseInteractiveObject's inventory. * @param itemIO the item being added * @param old the item being replaced * @ if an error occurs */ public void CheckForInventoryReplaceMe(BaseInteractiveObject itemIO, BaseInteractiveObject old) { if (itemIO != null && old != null) { bool handled = false; if (Io.HasIOFlag(IoGlobals.IO_01_PC)) { if (IsInPlayerInventory(old)) { if (CanBePutInInventory(itemIO)) { handled = true; } else { PutInFrontOfPlayer(itemIO, true); handled = true; } } } if (!handled) { int i = Interactive.Instance.GetMaxIORefId(); for (; i >= 0; i--) { BaseInteractiveObject io = (BaseInteractiveObject)Interactive.Instance.GetIO(i); if (io != null && io.Inventory != null) { InventoryData id = io.Inventory; if (id.IsInPlayerInventory(old)) { if (CanBePutInInventory(itemIO)) { handled = true; break; } else { this.PutInFrontOfPlayer(itemIO, true); handled = true; break; } } id = null; } } } } }