Nice script

Do only this part deal with finding disassembled items in the note?
CODE
class RPG::BaseItem
#--------------------------------------------------------------------------
# disassembled_items
#--------------------------------------------------------------------------
def disassembled_items
return @disassembled_items if @disassembled_items != nil
@disassembled_items = []
disassembled = false
self.note.split(/[\r\n]+/).each { |line|
case line
when /<(?:DISASSEMBLE|disassmbled)>/i
disassembled = true
when /<\/(?:DISASSEMBLE|disassmbled)>/i
disassembled = false
when /(.*)[ ](\d+)/i
next unless disassembled
case $1.upcase
when "WEAPON", "W", "WEP"
@disassembled_items.push($data_weapons[$2.to_i])
when "ARMOR", "ARMOUR", "A", "ARM"
@disassembled_items.push($data_armors[$2.to_i])
when "ITEM", "I"
@disassembled_items.push($data_items[$2.to_i])
end
end
}
return @disassembled_items
end
end
In that case the following edit should hopefully do it: (I haven't tested it)
CODE
class RPG::BaseItem
#--------------------------------------------------------------------------
# disassembled_items
#--------------------------------------------------------------------------
def disassembled_items
return @disassembled_items if @disassembled_items != nil
@disassembled_items = []
disassembled = false
self.note.split(/[\r\n]+/).each { |line|
case line
when /<(?:DISASSEMBLE|disassmbled)>/i
disassembled = true
when /<\/(?:DISASSEMBLE|disassmbled)>/i
disassembled = false
when /([^\s\d]*)\s*\d/
next unless disassembled
case $1.upcase
when "WEAPON", "W", "WEP"
item_ids = line.scan(/\d+/)
items = item_ids.map {|id| $data_weapons[id.to_i]}
@disassembled_items.push(*items)
when "ARMOR", "ARMOUR", "A", "ARM"
item_ids = line.scan(/\d+/)
items = item_ids.map {|id| $data_armors[id.to_i]}
@disassembled_items.push(*items)
when "ITEM", "I"
item_ids = line.scan(/\d+/)
items = item_ids.map {|id| $data_items[id.to_i]}
@disassembled_items.push(*items)
end
end
}
return @disassembled_items
end
end
I changed the
/(.*)[ ](\d+)/i regular expression to
/([^\s\d]*)\s*\d+/. There was no reason to test for case insensitivity so I removed that.
I changed the space requirement to allow for any amount of whitespace before the first digit to reduce potential frustration. I also made it optionally. Discarding whitespace if you are pressured on room in the note is a bonus.
The grouping captures the text until a whitespace character or a digit is met and stores this in $1 which you use to determine type of item. Note that it only checks for the existence of a single digit so the regular expression probably won't check the entire string of a valid match. (Why should it)
In each item type I scan for groups of digits to retrieve an array of numbers. (Remember that they are still strings)
I then map them to their respective objects and use the * operator to expand the array into a list of arguments.
Note that one can add a, say weapon, multiple times. I did not alter this functionality since it may have been intentional. I am just pointing it out in case you hadn't considered it.
*hugs*