Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #===============================================================================
- # Cooking Script v1.0 by GubiD 5/16/2011
- #===============================================================================
- module Cooking
- #-----------------------------------------------------------------------------
- # Cooking Time Max - Max time that the cooking bar uses to determine high value
- #-----------------------------------------------------------------------------
- Cooking_Time_Max = 1000
- #-----------------------------------------------------------------------------
- # Cooking Buffer - The time in which prior to and after the 'claim time' that you
- # can still claim your item without having it burnt
- #-----------------------------------------------------------------------------
- Cooking_Buffer = 30
- #-----------------------------------------------------------------------------
- # Result Message - message displayed when you successfully completed a recipe
- #-----------------------------------------------------------------------------
- Result_Msg = "You have cooked a:"
- #-----------------------------------------------------------------------------
- # Failed Message - message displayed when you failure to complete a recipe
- #-----------------------------------------------------------------------------
- Failed_Msg = "You have failed to complete these recipe"
- #-----------------------------------------------------------------------------
- # Level Gained Message - Message to be displayed when you gain a cooking lv
- #-----------------------------------------------------------------------------
- Lv_Gained = "You have gained a cooking lv"
- #-----------------------------------------------------------------------------
- # Recipes
- #-----------------------------------------------------------------------------
- # ID => [ITEM_ID, BURNT_ID, REQ_LV, EXP]
- #-----------------------------------------------------------------------------
- Recipes = {
- 1 => [1,21,1,100],
- 2 => [2,1,2,100]
- }
- #-----------------------------------------------------------------------------
- # Inregredients
- # * Recipe_ID - Must be valid Recipe ID from "Recipes"
- # Returns [ [INGREDIENT_ID(item), Number Req], [INGREDIENT_ID(item2), Number Req] etc]
- #-----------------------------------------------------------------------------
- def self.ingredients(id)
- case id
- when 1
- return [[5,1], [6,1],[7,1],[8,1]]
- when 2
- return [[2,1], [3,1],[5,1],[2,1]]
- end
- end
- #-----------------------------------------------------------------------------
- # Cooking Time - Time Required to cook item, in frames
- #-----------------------------------------------------------------------------
- def self.cooking_time(id)
- case id
- when 1; return 200
- when 2; return 300
- end
- end
- end
- #--------------------------------------------------------------------
- # Game Party - New Methods
- #--------------------------------------------------------------------
- class Game_Party < Game_Unit
- attr_reader :cooking_lv
- attr_reader :learned_recipes
- #--------------------------------------------------------------------
- # Initialize
- #--------------------------------------------------------------------
- alias init_gm_prty_cooking_script initialize unless $@
- def initialize(*args)
- init_gm_prty_cooking_script(*args)
- @cooking_lv = 1
- @cooking_exp = 0
- @cooking_exp_list = [0,500,1000,2000]
- @learned_recipes = []
- end
- #--------------------------------------------------------------------
- # Gain Cooking EXP
- # *EXP Value
- #--------------------------------------------------------------------
- def gain_cooking_exp(value)
- @cooking_exp += value
- @cooking_exp = [@cooking_exp,9999].min
- if @cooking_exp_list[@cooking_lv] < @cooking_exp
- gain_cooking_lv
- end
- end
- #--------------------------------------------------------------------
- # Gain Cooking LV
- #--------------------------------------------------------------------
- def gain_cooking_lv
- @cooking_lv += 1
- end
- #--------------------------------------------------------------------
- # Learn Recipe
- # *RecipeID
- #--------------------------------------------------------------------
- def learn_recipe(number)
- @learned_recipes << number if !@learned_recipes.include?(number)
- @learned_recipes.sort!
- end
- #--------------------------------------------------------------------
- # Forget Recipe
- # *RecipeID
- #--------------------------------------------------------------------
- def forget_recipe(number)
- @learned_recipes.delete(number)
- end
- end
- #--------------------------------------------------------------------
- # Cooking Title - Top window of cooking scene - Displays the Party Cooking Lv
- #--------------------------------------------------------------------
- class Cooking_Title < Window_Base
- def initialize
- super(0,0,544,64)
- refresh
- end
- #-----------------------------------------------------------------------------
- # Refresh - Redraws window contents with current data.
- #-----------------------------------------------------------------------------
- def refresh
- create_contents
- fsize = self.contents.font.size
- self.contents.font.size = 24
- self.contents.draw_text(0,0,544-32,WLH+8, "Cooking")
- self.contents.font.size = fsize
- self.contents.draw_text(0,0,544-32,WLH+8, "Level: #{$game_party.cooking_lv}",2)
- end
- end
- #--------------------------------------------------------------------
- # Cooking Available List
- #--------------------------------------------------------------------
- class Cooking_Availabe_List < Window_Selectable
- def initialize
- super(0,64,544/3, 416-64)
- refresh
- end
- #-----------------------------------------------------------------------------
- # Refresh - Redraws Available List of Recipes with current known and available
- # recipes
- #-----------------------------------------------------------------------------
- def refresh
- recipes = $game_party.learned_recipes
- @item_max = recipes.size
- create_contents
- for i in 0...@item_max
- recipe_data = Cooking::Recipes[recipes[i]]
- cur_lv = $game_party.cooking_lv
- if recipe_data[2] > cur_lv
- draw_recipe_disabled(i)
- else
- draw_recipe_enabled(i)
- end
- end
- end
- #-----------------------------------------------------------------------------
- # Draw Recipe Disabled - Draws index recipe as disabled color
- # *Index of party recipe ID
- #-----------------------------------------------------------------------------
- def draw_recipe_disabled(index)
- fcolor = self.contents.font.color
- self.contents.font.color = Color.new(50,50,50,255)
- rect = item_rect(index)
- r_id = $game_party.learned_recipes[index]
- recipe_data = Cooking::Recipes[r_id]
- item_id = recipe_data[0]
- item = $data_items[item_id]
- self.contents.draw_text(rect, item.name)
- self.contents.font.color = fcolor
- end
- #-----------------------------------------------------------------------------
- # Draw Recipe Enabled - Draws index recipe as enabled color
- # *Index of party recipe ID
- #-----------------------------------------------------------------------------
- def draw_recipe_enabled(index)
- self.contents.font.color = normal_color
- rect = item_rect(index)
- r_id = $game_party.learned_recipes[index]
- recipe_data = Cooking::Recipes[r_id]
- item_id = recipe_data[0]
- item = $data_items[item_id]
- self.contents.draw_text(rect, item.name)
- end
- end
- #-------------------------------------------------------------------------------
- # Cooking Details - Used to display the details of the currently selected recipe
- #-------------------------------------------------------------------------------
- class Cooking_Details < Window_Selectable
- attr_reader :can_cook
- attr_reader :can_claim
- attr_reader :recipe_id
- attr_reader :started
- attr_reader :is_burnt
- def initialize
- super(544/3, 64, 544-544/3, 416-64)
- refresh
- @can_cook = false
- @started = false
- @max = 100
- @elapsed = 0
- @claim_time = 0
- @can_claim = false
- @is_burnt = false
- end
- #-----------------------------------------------------------------------------
- # Refresh - Redraws window contents with the current data
- #-----------------------------------------------------------------------------
- def refresh(recipe_id = nil)
- @recipe_id = recipe_id
- @can_cook = false
- create_contents
- return if recipe_id == nil
- @recipe_data = Cooking::Recipes[@recipe_id]
- @item = $data_items[@recipe_data[0]]
- fsize = self.contents.font.size
- self.contents.font.size = 24
- self.contents.font.bold = true
- self.contents.draw_text(0,0,width-32,WLH+8,@item.name,1)
- self.contents.font.bold = false
- draw_icon(@item.icon_index, ((width-32)/2)-12, 40)
- draw_item_description
- draw_ingredients
- draw_options
- end
- #-----------------------------------------------------------------------------
- # Draw Item(to be earned by recipe) Description
- #-----------------------------------------------------------------------------
- def draw_item_description
- self.contents.draw_text(0,64,width-32,WLH, @item.description,1)
- end
- #-----------------------------------------------------------------------------
- # Draw Ingredients - Method to draw all ingredients required for the current
- # recipe and display how many items you have in your possession as to how
- # many are required for the recipe
- #-----------------------------------------------------------------------------
- def draw_ingredients
- ingredient_list = Cooking.ingredients(@recipe_id)
- self.contents.draw_text(0,136, width-32, WLH, 'Ingredients:', 0)
- required_ingredients = ingredient_list.size
- current_meet = 0
- for i in 0...ingredient_list.size
- y = 160 + WLH*i
- ingredient = ingredient_list[i]
- item = $data_items[ingredient[0]]
- in_possession = $game_party.item_number(item)
- if in_possession < ingredient[1]
- self.contents.font.color = Color.new(50,50,50,255)
- else
- current_meet += 1
- end
- self.contents.draw_text(40,y, width-32-40, WLH, "#{item.name} #{in_possession}/#{ingredient[1]}",0)
- normal_color
- end
- if current_meet == required_ingredients
- @can_cook = true
- end
- end
- #-----------------------------------------------------------------------------
- # Start Cooking - Setup Flags to trigger 'Cooking'
- #-----------------------------------------------------------------------------
- def start_cooking
- @started = true
- @max = Cooking::Cooking_Time_Max
- @elapsed = 0
- @claim_time = Cooking.cooking_time(@recipe_id)
- end
- #-----------------------------------------------------------------------------
- # Update - Added upon to show a progress bar while 'cooking' as well as expose
- # how far done and how well cooked the item is.
- #-----------------------------------------------------------------------------
- def update
- super unless @started
- if @started == true
- w = width-32
- gw = w * @elapsed / @max
- buffer = Cooking::Cooking_Buffer
- if @claim_time + buffer > @elapsed and @elapsed > @claim_time - buffer
- @can_claim = true
- gc1 = Color.new(0,255,50,255)
- gc2 = Color.new(0,255,50,255)
- else
- if @claim_time + buffer < @elapsed
- @is_burnt = true
- end
- @can_claim = false
- gc1 = hp_gauge_color1
- gc2 = hp_gauge_color2
- end
- x = 0
- y = height-32-24-24
- self.contents.fill_rect(x, y + WLH - 8, w, 6, gauge_back_color)
- self.contents.gradient_fill_rect(x, y + WLH - 8, gw, 6, gc1, gc2)
- @elapsed += 1
- end
- end
- #-----------------------------------------------------------------------------
- # Stop Cooking - Clears cooking info
- #-----------------------------------------------------------------------------
- def stop_cooking
- @started = false
- @is_burnt = false
- x = 0
- y = height-32-24-12
- w = width-32
- h = 10
- rect = Rect.new(x,y,w,h)
- self.contents.fill_rect(rect, Color.new(0,0,0,0))
- end
- #-----------------------------------------------------------------------------
- # Draw Options - Draws the Cook and Dont Cook options at the bottom of the window
- #-----------------------------------------------------------------------------
- def draw_options
- w = (width-32)/2
- if @recipe_data[2] > $game_party.cooking_lv
- self.contents.font.color = Color.new(50,50,50,255)
- else
- normal_color
- end
- self.contents.draw_text(0,height-32-WLH, w, WLH, "Cook", 1)
- normal_color
- self.contents.draw_text(w,height-32-WLH, w, WLH, "Don't Cook", 1)
- @item_max = 2
- @column_max = 2
- end
- #-----------------------------------------------------------------------------
- # Item Rect - Updated for displacement of the rect.y position
- #-----------------------------------------------------------------------------
- alias item_rect_cook_detail item_rect unless $@
- def item_rect(index)
- rect = item_rect_cook_detail(index)
- rect.y = height-32-WLH
- return rect
- end
- end
- #-------------------------------------------------------------------------------
- # Cooking Results - Window to display in center of screen until user input.. self disposing
- #-------------------------------------------------------------------------------
- class Cooking_Results < Window_Base
- def initialize(message)
- super(0,416/2-28, 544, 24+32)
- set_message(message)
- end
- #-----------------------------------------------------------------------------
- # Set Message - Draws message then waits for user input before continuing
- #-----------------------------------------------------------------------------
- def set_message(message)
- create_contents
- self.contents.draw_text(0,0,width-32, height-32, message,1)
- loop do
- Graphics.update
- Input.update
- self.update
- break if Input.trigger?(Input::C)
- end
- dispose # dispose self
- end
- end
- #-------------------------------------------------------------------------------
- # Scene Cooking - Scene in which all cooking is performed.
- #-----------------------------------------------------------------------------
- class Scene_Cooking < Scene_Base
- def initialize(force_burn = false)
- @tutorial_burn = force_burn
- end
- def start
- create_windows
- end
- #-----------------------------------------------------------------------------
- # Create Windows
- #-----------------------------------------------------------------------------
- def create_windows
- @title = Cooking_Title.new
- @list = Cooking_Availabe_List.new
- @details = Cooking_Details.new
- @list.active = true
- @list.index = 0
- @last_index = -1
- @details.active = false
- pre_animate_in
- if @tutorial_burn == true
- @list.active = false
- @list.index = 0
- refresh_details
- @details.active = true
- @details.index = 0
- end
- end
- #-----------------------------------------------------------------------------
- # Pre Animate In - Prepares all windows for the animation process
- #-----------------------------------------------------------------------------
- def pre_animate_in
- @title.y -= @title.height
- @list.x -= @list.width
- @details.x += @details.width
- end
- def post_start
- animate_in
- end
- #-----------------------------------------------------------------------------
- # Animate In - Method that brings the windows into the scene
- #-----------------------------------------------------------------------------
- def animate_in
- timer = 10
- while timer > 0
- Graphics.update
- @title.y += @title.height/10
- @list.x += @list.width/10
- @details.x -= @details.width/10
- timer -= 1
- end
- end
- #-----------------------------------------------------------------------------
- # Update method
- #-----------------------------------------------------------------------------
- def update
- update_windows
- if @list.active == true
- update_list
- return
- end
- if @details.active == true
- update_details
- return
- end
- end
- #-----------------------------------------------------------------------------
- # Update Windows - method to update and refresh window contents when required
- #-----------------------------------------------------------------------------
- def update_windows
- if @last_index != @list.index
- @last_index = @list.index
- refresh_details
- end
- @title.update
- @list.update
- @details.update
- end
- #-----------------------------------------------------------------------------
- # Refresh Details - used to refresh the contents of the Details pane
- #-----------------------------------------------------------------------------
- def refresh_details
- recipe_id = $game_party.learned_recipes[@list.index]
- @details.refresh(recipe_id)
- end
- #-----------------------------------------------------------------------------
- # Update Details - method to monitor/manage user input when the detail pane is active
- #-----------------------------------------------------------------------------
- def update_details
- if Input.trigger?(Input::C) or @tutorial_burn
- if @details.index == 0 #When Cook
- if @details.can_cook == false # if cannot book, playe buzzer and return
- Sound.play_buzzer
- return
- end
- #if can.. continue
- Sound.play_decision
- # get ingredient list
- ingredient_list = Cooking.ingredients(@details.recipe_id)
- for i in 0...ingredient_list.size
- ingredient = ingredient_list[i]
- item = $data_items[ingredient[0]]
- number = ingredient[1]
- $game_party.lose_item(item, number) #take items from party
- end
- #set cooking flag
- @details.start_cooking
- # wait for cooking
- wait_for_cooking
- # disable pane, and return control to 'list' window.
- @list.active = true
- @details.active = false
- @details.index = -1
- else # When Dont Cook
- Sound.play_cancel
- @details.active = false
- @list.active = true
- @details.index = -1
- end # /details.index == 0
- #Refresh Window contents
- @title.refresh
- @list.refresh
- @details.refresh(@details.recipe_id)
- if @tutorial_burn == true
- $scene = Scene_Map.new
- end
- end
- #-----------------------------------------------------------------------------
- # If cancel button is selected
- #-----------------------------------------------------------------------------
- if Input.trigger?(Input::B)
- Sound.play_cancel
- @details.active = false
- @details.index = -1
- @list.active = true
- end
- end
- #-----------------------------------------------------------------------------
- # Wait for Cooking - method in which waits for the Detail window while it is
- # cooking and dictates what should happen when a item is successfully or un-
- # successfully cooked within the scene.
- #-----------------------------------------------------------------------------
- def wait_for_cooking
- while @details.started
- Graphics.update
- Input.update
- update_windows
- if ((@tutorial_burn == true and @details.is_burnt == true) or @tutorial_burn == false)
- if Input.trigger?(Input::C)
- # get recipe data
- data = Cooking::Recipes[@details.recipe_id]
- # If recipe is not without 'correct cooking timeframe'
- if @details.can_claim == false
- Sound.play_enemy_damage # Played desired sound effect
- if @details.is_burnt #if item is BURNT but not garbage.. then earn that item.
- item = $data_items[data[1]]
- $game_party.gain_item(item, 1)
- Cooking_Results.new(Cooking::Result_Msg + " #{item.name}") #display message
- else
- Cooking_Results.new(Cooking::Failed_Msg) #if garbage.. display and return
- end
- else #can claim correctly
- Sound.play_recovery #play desired sound
- item = $data_items[data[0]]
- $game_party.gain_item(item, 1) #gain item
- Cooking_Results.new(Cooking::Result_Msg + " #{item.name}") #display success message
- end
- # check current level
- cur_lv = $game_party.cooking_lv
- # gain cooking exp
- $game_party.gain_cooking_exp(data[3])
- # confirm level has not changed.. if it has.. show message
- if cur_lv != $game_party.cooking_lv
- # You could play a sound here as well if you want to.
- Cooking_Results.new(Cooking::Lv_Gained)
- end
- # Stop Cooking
- @details.stop_cooking
- end
- end
- end
- end
- #-----------------------------------------------------------------------------
- # Update List - Method in which to update the LIST window when active.
- #-----------------------------------------------------------------------------
- def update_list
- if Input.trigger?(Input::C)
- recipe_id = $game_party.learned_recipes[@list.index]
- data = Cooking::Recipes[recipe_id]
- #if cooking level required for specified item is too low.. return.
- if data[2] > $game_party.cooking_lv
- Sound.play_buzzer
- return
- end
- Sound.play_decision
- @list.active = false
- @details.active = true
- @details.index = 0
- end
- if Input.trigger?(Input::B)
- Sound.play_cancel
- $scene = Scene_Map.new
- end
- end
- def pre_terminate
- animate_out
- end
- #-----------------------------------------------------------------------------
- # Animate Out - Method to move windows off the scene in prep for disposal
- #-----------------------------------------------------------------------------
- def animate_out
- timer = 10
- while timer > 0
- Graphics.update
- @title.y -= @title.height/10
- @list.x -= @list.width/10
- @details.x += @details.width/10
- timer -= 1
- end
- end
- def terminate
- @title.dispose
- @list.dispose
- @details.dispose
- end
- end
- #-----------------------------------------------------------------------------
- # Game Interpreter - Additional methods in order to make learning/forgetting
- # recipes easier
- #-----------------------------------------------------------------------------
- class Game_Interpreter
- def learn_recipe(number)
- $game_party.learn_recipe(number)
- end
- def forget_recipe(number)
- $game_party.forget_recipe(number)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement