#============================================================================== # LonaCraft - 30_Process.rb # What it does: # * PROCESS_RECIPES: simple recipes that turn inventory items straight into # materials (no storage box), listed in the Processing group of the # crafting screen at their stations (Stations::PROCESS, 55_Recipes.rb; # planks and fibre rope also by hand from the main menu). # * Each use costs 1 STA (PROCESS_STA_COST). # * Inputs are taken from the inventory only (equipped items are not used). # * Plant fibre: the input FIBRE means "any plant". The eligible set is built # at load by scanning $data_items for pot_data tag "Plant" or any tag # starting with "Herb" (so the game's and RolePlayS's plants are both # included). Mixed plants are allowed; the cheapest, then most plentiful, # are used first, and the narration names the plants used. # * PROCESS_RECIPES below is only the data. 55_Recipes.rb turns it into # Recipes entries (category :process, fixed tier 1, id "process:", # changeable in Config/Recipes.json) and owns the affordability check and # the crafting itself. (The dark pot's old Process menu is gone, and with it # the old list helpers affordable_process_recipes and fibre_used_text; the # plants used are tracked in Recipes.last_fibre_used, 55_Recipes.rb.) #============================================================================== module LonaCraft FIBRE = "*plant" # pseudo input name: any eligible plant item # [text key under LonaCraft:Station:Process/, {input => qty}, {output => qty}] PROCESS_RECIPES = [ ["Plank", {"ItemMhWoodenClub" => 1}, {"ItemLonaCraftPlank" => 2}], ["Leather", {"ItemLonaCraftHide" => 2}, {"ItemLonaCraftLeather" => 1}], ["Nails", {"ItemLonaCraftIronIngot" => 1}, {"ItemLonaCraftNails" => 4}], ["RopeCloth", {"ItemLonaCraftClothBolt" => 3}, {"ItemLonaCraftRope" => 1}], ["RopeFibre", {FIBRE => 4}, {"ItemLonaCraftRope" => 1}], ["ClothFibre", {FIBRE => 4}, {"ItemLonaCraftClothBolt" => 1}], ["Glass", {"ItemMineral" => 2, "ItemMhWoodenClub" => 1}, {"ItemLonaCraftGlass" => 1}], ["Smelt", {"ItemLonaCraftIronOre" => 2, "ItemMhWoodenClub" => 1}, {"ItemLonaCraftIronIngot" => 1}], ["CutStone", {"ItemLonaCraftRoughStone" => 2}, {"ItemLonaCraftStoneBlock" => 1}] ] PROCESS_STA_COST = 1 def self.fibre_tag?(tag) tag = tag.to_s tag == "Plant" || tag.start_with?("Herb") end # Called from load_database after the items are registered. def self.build_fibre_items @fibre_items = [] $data_items.each{|item| next if item.nil? || item.item_name.nil? || item.item_name.to_s.empty? next if ITEM_NAMES.include?(item.item_name) next if item.key_item? next unless item.pot_data.is_a?(Hash) next unless item.pot_data.keys.any?{|tag| fibre_tag?(tag) } @fibre_items << item.item_name } p "LonaCraft fibre plants: #{@fibre_items.join(", ")}" @fibre_items end def self.fibre_items @fibre_items || [] end def self.fibre_owned list = [] fibre_items.each{|name| obj = $data_ItemName[name] next if obj.nil? count = $game_party.item_number(obj) list << [obj, count] if count > 0 } list end def self.fibre_total total = 0 fibre_owned.each{|data| total += data[1] } total end # [[item, amount], ...] covering +qty+ plants: cheapest first, then most plentiful. def self.pick_fibre(qty) owned = fibre_owned.sort_by{|data| [data[0].price.to_i, -data[1]] } picked = [] left = qty owned.each{|obj, count| break if left <= 0 take = count < left ? count : left picked << [obj, take] left -= take } left > 0 ? [] : picked end # Kept for callers that still pass a PROCESS_RECIPES row # ([key, {input => qty}, {output => qty}]); a Recipes entry is passed # straight to Recipes.affordable?. def self.process_affordable?(recipe) if recipe.is_a?(Array) return false if recipe[2].keys.any?{|name| $data_ItemName[name].nil? } recipe = Recipes::Recipe.new(nil, recipe[1], 0, 1, :process, 1, recipe[0]) end Recipes.affordable?(recipe) end end