/// <summary> /// Checks whether an item can be put in the specified slot. /// </summary> /// <param name="slot">The slot to check for.</param> /// <param name="item">The item to check for.</param> /// <param name="reason">The translated reason why the item cannot be equiped, if this function returns false. Can be null.</param> /// <returns>True if the item can be inserted into the specified slot.</returns> public bool CanEquip(Slots slot, ItemComponent item, out string reason) { var pass = false; reason = null; if (!ActionBlockerSystem.CanEquip(Owner)) { return(false); } if (item is ClothingComponent clothing) { if (clothing.SlotFlags != SlotFlags.PREVENTEQUIP && (clothing.SlotFlags & SlotMasks[slot]) != 0) { pass = true; } else { reason = Loc.GetString("This doesn't fit."); } } if (Owner.TryGetComponent(out IInventoryController controller)) { pass = controller.CanEquip(slot, item.Owner, pass, out var controllerReason); reason = controllerReason ?? reason; } if (!pass && reason == null) { reason = Loc.GetString("You can't equip this!"); } return(pass && SlotContainers[slot].CanInsert(item.Owner)); }