=begin
例:敌人备注写
<掉落物 敌群:1>
经验:100
金钱:100
物品:1(2) # 1号物品 1/2概率获得
武器:2(3) # 2号武器 1/3概率获得
防具:3(4) # 3号防具 1/4概率获得
</掉落物>
=end
class RPG::Enemy
DROP_TAG = "(?:掉落物|drop_item)"
TROOP_REG = "[ ]*(?:敌群|troop)[ :=]*"
CUSTOM_DROP_REG = /<#{DROP_TAG}#{TROOP_REG}(\d+)>((?:\s*\S\s*)+)<\/#{DROP_TAG}>/mi
CUSTOM_EXP_REG = /(?:经验|exp)[ :=]*(\d+)/mi
CUSTOM_GOLD_REG = /(?:金钱|gold)[ :=]*(\d+)/mi
CUSTOM_ITEM_REG = /(?:物品|item|武器|weapon|防具|armor)[ :=]*\d+\(\d+\)/mi
def drop_notes
self.note =~ CUSTOM_DROP_REG ? [$1, $2] : nil
end
def drop_condition?
return false unless drop_notes
$game_troop.troop_id == drop_notes[0].to_i
end
alias exp_for_custom exp
def exp
drop_condition? ? custom_exp : exp_for_custom
end
def custom_exp
drop_notes[1] =~ CUSTOM_EXP_REG ? $1.to_i : exp_for_custom
end
alias gold_for_custom gold
def gold
drop_condition? ? custom_gold : gold_for_custom
end
def custom_gold
drop_notes[1] =~ CUSTOM_GOLD_REG ? $1.to_i : gold_for_custom
end
alias drop_items_for_custom drop_items
def drop_items
drop_condition? ? custom_drop_items : drop_items_for_custom
end
def custom_drop_items
droping_items = drop_notes[1].scan(CUSTOM_ITEM_REG)
return drop_items_for_custom if droping_items.empty?
droping_items.inject([]) do |r,s|
item = RPG::Enemy::DropItem.new
if s =~ /物品|item/ then item.kind = 1
elsif s =~ /武器|weapon/ then item.kind = 2
elsif s =~ /防具|armor/ then item.kind = 3
end
item.data_id = $1.to_i if s =~ /(\d+)/
item.denominator = $1.to_i if s =~ /\((\d+)\)/
r << item
end
end
end
class Game_Troop
attr_reader :troop_id
end