cinderelmini 发表于 2016-4-7 14:59
采集了背包所有物品数量的一半然后逐个随机减掉一半……
不知道算法是不是对的……有坑再说……
使用方法是 ...
我把你写的这个改了下。结果数量变成了小数点
class Game_Party def lost_half_items list_all = [@items, @weapons, @armors] half_num = 0 list_all.each do |list| list.values.each do |l| half_num += l end end return if half_num == 0 while half_num > 0 list = list_all[rand(3)] next if list.size <= 0 rand_items_id = @items.keys[rand(@items.keys.size)] rand_weapons_id = @weapons.keys[rand(@weapons.keys.size)] rand_armors_id = @armors.keys[rand(@armors.keys.size)] if @items[rand_items_id] > 1 lose_num = @items[rand_items_id] rand_item_number = rand($game_party.item_number(lose_num)) @items[rand_items_id] -= rand_item_number.abs half_num -= 1 else @items.delete(rand_items_id) half_num -= 1 end if @weapons[rand_weapons_id] > 1 lose_num = @weapons[rand_weapons_id] rand_item_number = rand($game_party.item_number(lose_num)) @weapons[rand_weapons_id] -= rand_item_number.abs half_num -= 1 else @items.delete(rand_items_id) half_num -= 1 end if @armors[rand_armors_id] > 1 lose_num = @armors[rand_armors_id] rand_item_number = rand($game_party.item_number(lose_num)) @armors[rand_armors_id] -= rand_item_number.abs half_num -= 1 else @items.delete(rand_items_id) half_num -= 1 end end end end
class Game_Party
def lost_half_items
list_all = [@items, @weapons, @armors]
half_num = 0
list_all.each do |list|
list.values.each do |l|
half_num += l
end
end
return if half_num == 0
while half_num > 0
list = list_all[rand(3)]
next if list.size <= 0
rand_items_id = @items.keys[rand(@items.keys.size)]
rand_weapons_id = @weapons.keys[rand(@weapons.keys.size)]
rand_armors_id = @armors.keys[rand(@armors.keys.size)]
if @items[rand_items_id] > 1
lose_num = @items[rand_items_id]
rand_item_number = rand($game_party.item_number(lose_num))
@items[rand_items_id] -= rand_item_number.abs
half_num -= 1
else
@items.delete(rand_items_id)
half_num -= 1
end
if @weapons[rand_weapons_id] > 1
lose_num = @weapons[rand_weapons_id]
rand_item_number = rand($game_party.item_number(lose_num))
@weapons[rand_weapons_id] -= rand_item_number.abs
half_num -= 1
else
@items.delete(rand_items_id)
half_num -= 1
end
if @armors[rand_armors_id] > 1
lose_num = @armors[rand_armors_id]
rand_item_number = rand($game_party.item_number(lose_num))
@armors[rand_armors_id] -= rand_item_number.abs
half_num -= 1
else
@items.delete(rand_items_id)
half_num -= 1
end
end
end
end
|