Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # Smithing System v1.0.0
- #------------------------------------------------------------------------------
- # This module defines list of craftable weapons
- #==============================================================================
- # Terms of Use:
- #------------------------------------------------------------------------------
- # Can be used in free games with credit, for a commercial license message
- # XenonCreations and you can negotiate on a price.
- #==============================================================================
- # Credits:
- #------------------------------------------------------------------------------
- # Zarby - For Scripting
- # XenonCreations - Ideas and Demo
- #==============================================================================
- # How to Use:
- #------------------------------------------------------------------------------
- # Call script in event... "SceneManager.goto(Scene_Blacksmith)"
- #==============================================================================
- # ** Craft
- #------------------------------------------------------------------------------
- module Craft
- #Bar start at 130 if difficulty is 1 bar reduce by 12 everytime, if 10 by 30 everytime
- #up to 5 time then after 4 time it remain 10 pixel of greenbar
- #Difficulty 1-10, bar reduce (Difficulty * 2) + 10
- #[Weapon, [[Material,Quantity], Difficulty]
- Weapons_Recipes = [
- [1,[[20,3],[21,3],[1,3],[2,3],[3,3]],2],
- [13,[[20,4],[21,2]],2],
- [19,[[20,2],[21,4]],1],
- [20,[[20,2],[21,4]],10],
- [21,[[20,2],[21,4]],5]
- #Add more weapon here
- ]
- def self.Weapon_Recipes
- return Weapons_Recipes
- end
- end
- #==============================================================================
- # ** Window_BlacksmithList
- #------------------------------------------------------------------------------
- # This window displays all craftable weapons
- #==============================================================================
- class Window_BlacksmithList < Window_Command
- #--------------------------------------------------------------------------
- # * Set Window Width
- #--------------------------------------------------------------------------
- def window_width
- return 160
- end
- #--------------------------------------------------------------------------
- # * Set Window Height
- #--------------------------------------------------------------------------
- def window_height
- return 292
- end
- #--------------------------------------------------------------------------
- # * Set Number of items visible
- #--------------------------------------------------------------------------
- def visible_line_number
- item_max
- end
- #--------------------------------------------------------------------------
- # * Set the choices of window to the list of weapons
- #--------------------------------------------------------------------------
- def make_command_list
- for ind in 0..Craft.Weapon_Recipes.size-1
- mats = false
- for i in 0..(Craft.Weapon_Recipes[ind][1].size)-1
- nbr = $game_party.item_number($data_items[Craft.Weapon_Recipes[ind][1][i][0]])
- nbrr = Craft.Weapon_Recipes[ind][1][i][1]
- if (nbr >= nbrr)
- mats = true
- else
- mats = false
- break
- end
- end
- add_command($data_weapons[Craft.Weapon_Recipes[ind][0]].name, :weapon,mats)
- end
- end
- end
- #==============================================================================
- # ** Scene_Blacksmith
- #------------------------------------------------------------------------------
- # This class performs the craft of weapons
- #==============================================================================
- class Scene_Blacksmith < Scene_MenuBase
- #--------------------------------------------------------------------------
- # * Start Processing
- #--------------------------------------------------------------------------
- def start
- super
- create_background
- create_windows
- @minigame = false
- @minigame_open = false
- @succes = 0
- @greenbar = 130
- @minigame_started = false
- @minigame_timer = 0
- @minigame_freeze = false
- @minigame_cursor_direction = false
- @speed = 4
- @done = false
- @last_index = -1
- end
- #--------------------------------------------------------------------------
- # * Update Processing
- #--------------------------------------------------------------------------
- def update
- super
- ind = @selectable_window.index
- for i in 0..(Craft.Weapon_Recipes[ind][1].size)-1
- nbr = $game_party.item_number($data_items[Craft.Weapon_Recipes[ind][1][i][0]])
- nbrr = Craft.Weapon_Recipes[ind][1][i][1]
- end
- if (@minigame == true)
- forge_minigame
- if (@minigame_open == false)
- draw_minigame
- @minigame_open = true
- end
- end
- if (Input.trigger?(:B))
- if (@minigame == false)
- if @selectable_window.active == false
- cancel_selected_weapon
- else
- SceneManager.goto(Scene_Map)
- end
- elsif (@minigame_started == false)
- @minigame = false
- @minigame_open = false
- @minigame_sprite.visible = false
- @minigame_cursor_sprite.visible = false
- @description_window.visible = true
- end
- end
- if (@last_index != @selectable_window.index)
- draw_description
- @last_index = @selectable_window.index
- end
- if (@done == true)
- if (@minigame_timer >= 10)
- terminate
- SceneManager.goto(Scene_Map)
- end
- end
- end
- #--------------------------------------------------------------------------
- # * Weapon Command : When we select a weapons
- #--------------------------------------------------------------------------
- def command_weapon
- @selectable_window.active = false
- @minigame = true
- @help_window.set_text("Choose a weapon to craft \n Are you sure ?")
- end
- #--------------------------------------------------------------------------
- # * Weapon Cancel Command : When we cancel selection of weapon
- #--------------------------------------------------------------------------
- def cancel_selected_weapon
- @selectable_window.active = true
- @description_window.visible = true
- @help_window.set_text("Choose a weapon to craft")
- @selectable_window.active = true
- draw_description
- end
- #--------------------------------------------------------------------------
- # * Draw Description of the weapon selected
- #--------------------------------------------------------------------------
- def draw_description
- @description_window.contents.clear
- ind = @selectable_window.index
- @description_window.visible = true
- w = $data_weapons[Craft.Weapon_Recipes[ind][0]]
- @description_window.draw_icon(w.icon_index, 0, 0)
- @description_window.contents.font.color = Color.new(100,160,50)
- @description_window.draw_text(32,0,320,24,w.name,0)
- desc = w.description.split("\n")
- @description_window.contents.font.size = 16
- @description_window.contents.font.color = Color.new(200,230,180)
- @description_window.draw_text(0,24,420,24,desc[0],0)
- @description_window.draw_text(0,38,420,24,desc[1],0)
- @description_window.contents.font.size = 20
- @description_window.contents.font.color = Color.new(255,255,255)
- @description_window.draw_text(0,70,320,24,"Weapon Type : "+$data_system.weapon_types[w.wtype_id],0)
- @description_window.contents.fill_rect(0,60,320,4,Color.new(0,0,0))
- @description_window.contents.fill_rect(1,61,294,2,Color.new(255,255,255))
- statsy = 90
- for i in 0..3
- @description_window.draw_text(0,statsy + (20 * i),320,24,Vocab.param(i)+" : "+w.params[i].to_s,0)
- @description_window.draw_text(160,statsy + (20 * i),320,24,Vocab.param(i+3)+" : "+w.params[i].to_s,0)
- end
- @description_window.contents.fill_rect(0,180,320,4,Color.new(0,0,0))
- @description_window.contents.fill_rect(1,181,294,2,Color.new(255,255,255))
- @description_window.contents.font.size = 24
- @description_window.contents.font.color = Color.new(200,230,180)
- @description_window.draw_text(0,190,320,24,"Materials Owned/Required",0)
- @description_window.contents.font.color = Color.new(255,255,255)
- @description_window.contents.font.size = 20
- ind = @selectable_window.index
- for i in 0..(Craft.Weapon_Recipes[ind][1].size)-1
- nbr = $game_party.item_number($data_items[Craft.Weapon_Recipes[ind][1][i][0]])
- nbrr = Craft.Weapon_Recipes[ind][1][i][1]
- if (nbr >= nbrr)
- @description_window.contents.font.color = Color.new(160,230,30)
- else
- @description_window.contents.font.color = Color.new(150,10,10)
- end
- @description_window.draw_text(0,216 + (i * 20),320,24,$data_items[Craft.Weapon_Recipes[ind][1][i][0]].name,0)
- @description_window.draw_text(240,216 + (i * 20),70,24,nbr.to_s + "/" + nbrr.to_s ,1)
- end
- end
- #--------------------------------------------------------------------------
- # * Forge Minigame processing everything about minigame is here
- #--------------------------------------------------------------------------
- def forge_minigame
- if (@minigame_started == false)
- if (Input.trigger?(:C))
- @minigame_started = true
- @minigame_timer = 0
- end
- end
- if (@minigame_started == true)
- @minigame_timer += 1
- #If we can repress :
- if (@minigame_timer >= 15)
- @minigame_timer = 15
- if (@minigame_freeze == false)
- if (Input.trigger?(:C))
- if (centerbar == true)
- @succes +=20
- @minigame_timer = 0
- Sound.play_ok
- @greenbar -= (Craft.Weapon_Recipes[@selectable_window.index][2]*2)+10
- @speed +=1
- draw_minigame
- if (@succes >= 100)
- w = $data_weapons[Craft.Weapon_Recipes[@selectable_window.index][0]]
- $game_party.gain_item(w, 1)
- $game_message.add("Congrats you created a " +(w.name)+" !")
- for i in 0..(Craft.Weapon_Recipes[ @selectable_window.index][1].size)-1
- it = $data_items[Craft.Weapon_Recipes[@selectable_window.index][1][i][0]]
- q = Craft.Weapon_Recipes[@selectable_window.index][1][i][1]
- $game_party.gain_item(it, -q)
- end
- @done = true
- end
- r = rand(10)
- if (r >= 6)
- @minigame_cursor_direction = true
- else
- @minigame_cursor_direction = false
- end
- @minigame_freeze = true
- else
- Sound.play_buzzer
- @minigame_freeze = true
- @minigame_timer = 0
- w = $data_weapons[Craft.Weapon_Recipes[@selectable_window.index][0]]
- $game_message.add("You failed creation of " +(w.name)+" !\nYou lose your materials")
- for i in 0..(Craft.Weapon_Recipes[ @selectable_window.index][1].size)-1
- it = $data_items[Craft.Weapon_Recipes[@selectable_window.index][1][i][0]]
- q = Craft.Weapon_Recipes[@selectable_window.index][1][i][1]
- $game_party.gain_item(it, -q)
- end
- @done = true
- draw_minigame
- end
- end
- end
- end
- if (@minigame_freeze == false)
- if (@minigame_cursor_direction == false)
- @minigame_cursor_sprite.x +=@speed
- if (@minigame_cursor_sprite.x >= 498)
- @minigame_cursor_direction = true
- end
- else
- @minigame_cursor_sprite.x -=@speed
- if (@minigame_cursor_sprite.x <= 202)
- @minigame_cursor_direction = false
- end
- end
- else
- if (@minigame_timer >= 15)
- @minigame_freeze = false
- @minigame_timer = 0
- end
- end
- end
- end
- #--------------------------------------------------------------------------
- # * Center bar : check if the bar is in the green
- #--------------------------------------------------------------------------
- def centerbar
- if (@minigame_cursor_sprite.x >= 202 + (150 - @greenbar/2))
- if (@minigame_cursor_sprite.x <= 498 - (150 - @greenbar/2))
- return true
- end
- end
- return false
- end
- #--------------------------------------------------------------------------
- # * Draw Icon, allow to draw icon
- #--------------------------------------------------------------------------
- def draw_icon(icon_index, x, y, contents)
- bitmap = Cache.system("Iconset")
- rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
- contents.blt(x, y, bitmap, rect, 255)
- end
- #--------------------------------------------------------------------------
- # * Draw Minigame, draw everything used for the minigame
- #--------------------------------------------------------------------------
- def draw_minigame
- @help_window.set_text("Get Ready \nTry to stop the bar in center green")
- @description_window.visible = false
- @minigame_sprite.visible = true
- @minigame_cursor_sprite.visible = true
- @minigame_sprite.bitmap = Bitmap.new(320,240)
- @minigame_sprite.x = 192
- @minigame_sprite.y = 120
- @minigame_sprite.bitmap.fill_rect(0,0,320,240,Color.new(0,0,0))
- @minigame_sprite.bitmap.fill_rect(1,1,318,238,Color.new(255,255,255))
- @minigame_sprite.bitmap.fill_rect(3,3,314,234,Color.new(0,0,0))
- @minigame_sprite.bitmap.clear_rect(4,4,312,232)
- @minigame_sprite.bitmap.fill_rect(4,4,312,232,Color.new(0,0,0,180))
- @minigame_sprite.bitmap.draw_text(10,180,120,24,"Succes :",0)
- @minigame_sprite.bitmap.draw_text(10,10,200,24,"Difficulty : ",0)
- for i in 1..((Craft.Weapon_Recipes[@selectable_window.index][2]))
- draw_icon(126, 10 + ((i-1)*30), 34, @minigame_sprite.bitmap)
- end
- @minigame_sprite.bitmap.fill_rect(9,202,302,24,Color.new(0,0,0))
- @minigame_sprite.bitmap.fill_rect(10,203,(@succes*3),22,Color.new(0,255,0))
- @minigame_sprite.bitmap.fill_rect(9,109,302,18,Color.new(0,0,0))
- @minigame_sprite.bitmap.fill_rect(10,110,300,16,Color.new(150,10,10))
- @minigame_sprite.bitmap.fill_rect(160 - (@greenbar/2),110,@greenbar,16,Color.new(160,230,30))
- @minigame_cursor_sprite.bitmap = Bitmap.new(4,48)
- @minigame_cursor_sprite.bitmap.fill_rect(0,0,4,18,Color.new(0,0,0))
- @minigame_cursor_sprite.bitmap.fill_rect(1,1,2,16,Color.new(255,255,255))
- @minigame_cursor_sprite.bitmap.fill_rect(0,30,4,18,Color.new(0,0,0))
- @minigame_cursor_sprite.bitmap.fill_rect(1,31,2,16,Color.new(255,255,255))
- end
- #--------------------------------------------------------------------------
- # * Create Windows
- #--------------------------------------------------------------------------
- def create_windows
- @selectable_window = Window_BlacksmithList.new(0,120)
- @craftlist_window = Window_Base.new(0,72,160,48)
- @help_window = Window_Help.new()
- @help_window.set_text("Choose a weapon to craft")
- @craftlist_window.draw_text(0,0,140,24,"Craft List",1)
- @selectable_window.set_handler(:weapon,method(:command_weapon))
- @description_window = Window_Base.new(160,72,320,340)
- @description_window.visible = true
- @minigame_sprite = Sprite.new()
- @minigame_sprite.visible = false
- @minigame_cursor_sprite = Sprite.new()
- @minigame_cursor_sprite.x = (352)
- @minigame_cursor_sprite.y = (240-26)
- @minigame_cursor_sprite.visible = false
- end
- #--------------------------------------------------------------------------
- # * Terminate processing
- #--------------------------------------------------------------------------
- def terminate
- super
- dispose_background
- @selectable_window.dispose
- @craftlist_window.dispose
- @help_window.dispose
- @description_window.dispose
- @minigame_sprite.dispose
- @minigame_cursor_sprite.dispose
- end
- end
RAW Paste Data