Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- =begin
- ================Frysning Crafting=====================
- A simple crafting class for your game.
- Free for commercial and non commercial use.
- Credits are welcome : D
- ======================================================
- 23-9-2015: Version 1.1
- added: Icons for weapons, armours items
- added: More pages with more info
- added: Unlock systeem
- 22-9-2015: Version 1.0
- first release version
- =====================================================
- Add this to items that you want to craft.
- <mat>
- kind id amount
- kind id amount
- g amount
- </mat>
- kind is the type of item
- g gold you can skip the id part then.
- 1 items
- 2 armour
- 3 weapons
- Example
- <mat>
- 1 1 1
- g 10
- </mat>
- The item will cost 1 potion and 10 currency to craft.
- if you want get more then 1 item for a craft:
- <amount: number> where you can fill in number with the desired int.
- Example
- <amount: 10>
- when crafting this item it will give you 10 of it.
- if an item should not be craftable then don't fill the notetag with
- the requiremnts
- if you want to ignore a complete set of types
- just fill the id's in here then.
- Weapons and Armours get automatic sorted in category.
- items on the other hand... nope.
- So how do we use it?
- in $item_categorie make the categorie's you want to use.
- then set in the items you want to fit in that category
- <ctype: category> only 1 type at the time. caseinsenstive
- Example
- <ctype: potions> wil only show items that are categorized as potions.
- unlock system
- if an item should be unlocked first before crafting it
- <unlock>
- party level
- switch number
- </unlock
- Example
- <unlock>
- party 5
- switch 1
- </unlock>
- The highest party member needs to be level 5 and switch 1 needs to be true.
- ===============TODO=============================================
- ----------
- =============Known issues=======================================
- In the item menu and then the submenu's if we return we go back to the root.
- =end
- $item_categories = ["Potions"]
- $weapon_ignore=[]
- $armor_ignore=[]
- class Scene_Crafting < Scene_MenuBase
- def initialize
- super
- @help_window = Window_Help.new(1)
- @help_window.set_text("Crafting Menu")
- @list_window = Window_CraftingChooices.new
- @list_window.set_handler(:cancel, method(:list_cancel))
- @list_window.set_handler(:ok, method(:list_ok))
- @list_window.refresh
- @list_window.activate
- @list_window.select(0)
- end
- def update
- super
- if @description != nil && @description.visible == true
- if Input.trigger?(:LEFT )
- @description.index = -1
- elsif Input.trigger?(:RIGHT)
- @description.index = 1
- end
- end
- if @item == @list_window.current_item
- return
- end
- if @description != nil && @list_window.item != nil
- @item = @list_window.current_item
- if @item != nil
- if @item[:kind] == 6
- @description.refresh
- @description.hide
- end
- if @item[:kind] == -3 || @item[:kind] == -2 || @item[:kind] == -1
- @description.item= @list_window.item
- @description.refresh
- @description.show
- end
- end
- end
- end
- def choice_cancel
- end
- def list_cancel
- if @list_window.item == nil
- else
- @item = @list_window.item
- end
- if @description != nil
- @description.hide
- end
- if @item[:kind] == 1 || @item[:kind] == 2 || @item[:kind] == 3 then
- SceneManager.return
- elsif @item[:kind] == 6 && @list_window.item == nil
- @list_window.create_list({:kind => 1, :name => "Items"})
- elsif @item[:kind] == 6
- @list_window.create_list(nil)
- elsif @item[:kind] == 5 && @list_window.item == nil
- @list_window.create_list({:kind => 3, :name => "Armour"})
- elsif @item[:kind] == 5
- @list_window.create_list(nil)
- elsif @item[:kind] == 4 && @list_window.item == nil
- @list_window.create_list({:kind => 2, :name => "Weapons"})
- elsif @item[:kind] == 4
- @list_window.create_list(nil)
- elsif @item[:kind] == -1 && @list_window.item == nil
- @list_window.create_list({:kind => 2, :name => "Weapons"})
- elsif @item[:kind] == -1
- @list_window.create_list({:kind => 2, :name => "Weapons"})
- elsif @item[:kind] == -2
- @list_window.create_list({:kind => 3, :name => "Armour"})
- elsif @item[:kind] == -3
- @list_window.create_list(nil)
- end
- @list_window.refresh
- @list_window.select(0)
- @list_window.activate
- end
- def list_ok
- if @list_window.item == nil
- list_cancel
- return
- end
- @item = @list_window.item;
- if @item[:kind] == 1 || @item[:kind] == 4 || @item[:kind] == 5
- if @description == nil
- @description = Window_CraftingDetails.new
- else
- @description.show
- end
- @list_window.create_list(@item);
- @list_window.refresh
- @list_window.select(0)
- @list_window.activate
- @description.item= @list_window.item
- elsif @item[:kind] == -3 || @item[:kind] == -2 || @item[:kind] == -1
- if @command_window == nil
- @command_window = Window_CraftItem.new
- @command_window.x = Graphics.width / 2 - @command_window.width / 2
- @command_window.y = Graphics.height / 2 - @command_window.height / 2
- @command_window.set_handler(:craft, method(:craft_item))
- @command_window.set_handler(:cancel, method(:f_cancel))
- @command_window.width = 300
- else
- @command_window.show
- end
- @command_window.Set(@item)
- @command_window.refresh
- @command_window.select(0)
- @command_window.activate
- @command_window.open
- else
- @list_window.create_list(@item);
- @list_window.refresh
- @list_window.select(0)
- @list_window.activate
- end
- end
- def craft_item
- @command_window.close
- if @item[:kind] == -3
- uItem = $data_items[@item[:term_id]]
- elsif @item[:kind] == -2
- uItem = $data_armors[@item[:term_id]]
- else
- uItem = $data_weapons[@item[:term_id]]
- end
- items = []
- b = true
- if uItem.note =~ /<mat>((.|\s)*)<\/mat>/i
- collection = $1.split("\n")
- collection.each do | val |
- #p val
- if val == "\r"
- next
- end
- itemcollection = val.split(' ')
- #p itemcollection
- if itemcollection[0] == "g"
- if Integer(itemcollection[1]) <= $game_party.gold
- items.push({ :itemKind => 0, :amount =>
- Integer(itemcollection[1])})
- else
- b = false
- end
- else
- itemkind = Integer(itemcollection[0])
- itemId = Integer(itemcollection[1])
- if itemkind == 1 #items
- pItem = $data_items[itemId]
- has = $game_party.item_number($data_items[itemId])
- elsif itemkind == 2 #armours
- pItem = $data_armors[itemId]
- else #weapons
- pItem = $data_weapons[itemId]
- end
- if has >= Integer(itemcollection[2])
- items.push({:itemId => itemId, :itemKind => itemkind, :amount =>
- Integer(itemcollection[2])})
- else
- b = false
- end
- end
- end
- end
- #p b
- if b == true
- items.each do | makjes |
- if makjes[:itemKind] == 0
- $game_party.lose_gold(makjes[:amount])
- elsif makjes[:itemKind] == 1
- $game_party.gain_item($data_items[makjes[:itemId]],-makjes[:amount])
- elsif makjes[:itemKind] == 2
- $game_party.gain_item($data_armors[makjes[:itemId]],-makjes[:amount])
- else
- $game_party.gain_item($data_weapons[makjes[:itemId]],-makjes[:amount])
- end
- end
- amounts = 1
- if uItem.note =~ /<amount: (.*)>/i
- amounts = Integer($1)
- end
- if @item[:kind] == -3
- $game_party.gain_item( $data_items[@item[:term_id]],amounts)
- elsif @item[:kind] == -2
- $game_party.gain_item( $data_armors[@item[:term_id]],amounts)
- else
- $game_party.gain_item( $data_weapons[@item[:term_id]],amounts)
- end
- else
- RPG::SE.new("Buzzer1", 50, 100).play
- end
- @list_window.refresh
- @list_window.activate()
- @description.refresh
- @command_window.hide
- end
- def f_cancel
- @command_window.close
- @list_window.refresh
- @list_window.activate()
- @command_window.hide
- end
- end
- class Window_CraftingDetails < Window_Base
- def item=(item)
- return if @item == item
- @item = item
- refresh
- end
- def index=(i)
- if @index == nil
- @index = 0
- end
- @index += i
- if @index < 0
- @index = 4
- elsif @index > 4
- @index = 0
- end
- refresh
- end
- def initialize
- @bitmap = Cache.system("Iconset")
- @index = 0
- super(Graphics.width-Graphics.width/1.5,48,Graphics.width-Graphics.width/3,Graphics.height-48)
- end
- def refresh
- contents.clear
- return unless @item
- return if @item[:kind] ==6
- contents.font.size = 18
- change_color(system_color)
- if @item[:kind] == -3
- @uItem = $data_items[@item[:term_id]]
- has = $game_party.item_number($data_items[@item[:term_id]])
- elsif @item[:kind] == -2
- @uItem = $data_armors[@item[:term_id]]
- has = $game_party.item_number($data_armors[@item[:term_id]])
- elsif @item[:kind] == -1
- @uItem = $data_weapons[@item[:term_id]]
- has = $game_party.item_number($data_weapons[@item[:term_id]])
- end
- amounts = 1
- if @uItem.note =~ /<amount: (.*)>/i
- amounts = Integer($1)
- end
- change_color(text_color(0))
- draw_text(0,0,contents.width,line_height,@uItem.name)
- case @index
- when 0
- draw_text(0,18,contents.width,line_height,@uItem.description)
- change_color(text_color(14))
- draw_text(0,54,contents.width,line_height,"Cost #{@uItem.price}#{$data_system.currency_unit}")
- change_color(text_color(13))
- draw_text(0, 72, contents.width,line_height,"You got #{has}. You will get #{amounts} for crafting. ")
- y = 90
- draw_ingredients(y)
- when 1
- if@item[:kind] == -2 || @item[:kind] == -1
- draw_item_stats
- y = 170
- end
- when 2
- @loc = 2
- draw_elements
- when 3
- change_color(system_color)
- draw_states(0,36, @uItem.features)
- when 4
- draw_skills
- else
- end
- @names = ["Main", "Stats","Elements", "States", "Features"]
- first = if @index < 1 then 4 else @index-1 end
- second =if @index > 3 then 0 else @index+1 end
- prev_one = @names[first]
- next_one = @names[second]
- change_color(text_color(0))
- draw_text(0,310, contents.width,line_height,
- "<====#{prev_one}===== ====#{next_one}====>")
- @loc=1
- end
- def draw_states(xloc, yloc, features)
- size=136
- change_color(system_color)
- draw_text(0,36, contents.width,line_height,"Can inflict:")
- yloc += line_height
- $data_states.each do | id, waarde |
- isDrawed = false
- change_color(text_color(0))
- features.each do | feature |
- if feature.code == 32
- if $data_states[feature.data_id] == id
- isDrawed = true
- draw_background_box(xloc, yloc,size)
- icon_index = $data_states[feature.data_id].icon_index
- draw_icon(icon_index,xloc,yloc)
- draw_text(xloc +26,yloc, contents.width,line_height,
- "#{$data_states[feature.data_id].name}")
- yloc += line_height if xloc == size + 20
- xloc = xloc >= 0 + size ? 0: 20+ size
- end
- end
- end
- end
- yloc += line_height;
- xloc = 0;
- change_color(system_color)
- draw_text(0,yloc,contents.width,line_height, "Can resist: ")
- yloc += line_height
- $data_states.each do | id, waarde |
- change_color(text_color(0))
- features.each do | feature |
- if feature.code == 14 || feature.code == 13
- if $data_states[feature.data_id] == id
- draw_background_box(xloc, yloc,size)
- icon_index = $data_states[feature.data_id].icon_index
- draw_icon(icon_index,xloc,yloc)
- draw_text(xloc +26,yloc, contents.width,line_height,
- "#{$data_states[feature.data_id].name}")
- yloc += line_height if xloc == size + 20
- xloc = xloc >= 0 + size ? 0: 20+ size
- end
- end
- end
- end
- end
- def draw_elements
- cloc = (18*@loc)
- change_color(system_color)
- draw_text(0,cloc,contents.width,line_height,"Elemental Resistances: ")
- draw_item_elements(0,cloc+18, @uItem.features)
- change_color(system_color)
- draw_text(0,cloc+(18*8),contents.width,line_height, "Base hits with: ")
- change_color(text_color(0))
- draw_attack_element(0,cloc+(18*9), @uItem.features)
- end
- def draw_attack_element(xloc, yloc, features)
- size=136
- $data_system.elements.drop(1).each do | elementalid |
- change_color(text_color(0))
- features.each do | feature |
- if feature.code == 31
- if $data_system.elements[feature.data_id] == elementalid
- draw_background_box(xloc, yloc,size)
- icon_index = ELEMENTME::ELEMENTS[elementalid][:icon]
- draw_icon(icon_index,xloc,yloc)
- draw_text(xloc +26,yloc, contents.width,line_height,
- "#{elementalid}")
- yloc += line_height if xloc == size + 20
- xloc = xloc >= 0 + size ? 0: 20+ size
- end
- end
- end
- end
- end
- def draw_item_elements(xloc,yloc,features)
- size=136
- $data_system.elements.drop(1).each do | elementalid |
- change_color(text_color(0))
- rate = 0
- features.each do | feature |
- if feature.code == 11
- if $data_system.elements[feature.data_id] == elementalid
- rate = (feature.value * 100).round
- end
- end
- end
- draw_background_box(xloc, yloc,size)
- icon_index = ELEMENTME::ELEMENTS[elementalid][:icon]
- draw_icon(icon_index,xloc,yloc)
- draw_text(xloc +26,yloc, contents.width,line_height,
- "#{elementalid}")
- if rate == 100 || rate == 0
- change_color(text_color(0))
- elsif rate < 100
- change_color(text_color(24))
- else
- change_color(text_color(25))
- end
- urate = 100 - rate
- if urate == 100
- urate = "+0"
- elsif urate > 0
- urate = "+#{urate}"
- end
- draw_text(xloc + 90,yloc, contents.width,line_height,
- "#{urate}%" )
- yloc += line_height if xloc == size + 20
- xloc = xloc >= 0 + size ? 0: 20+ size
- end
- end
- def draw_ingredients(y)
- dx = 0
- dy = y
- if @uItem.note =~ /<mat>((.|\s)*)<\/mat>/i# /<(?:mat):[ ](.*)>/i#/<mat>(.|\s)*<\/mat>/m
- collection = $1.split("\n")
- collection.each do | val |
- #p val
- if val == "\r"
- next
- end
- itemcollection = val.split(' ')
- if itemcollection[0] == "g"
- if $game_party.gold >= Integer(itemcollection[1])
- change_color(text_color(11))
- else
- change_color(text_color(10))
- end
- draw_text(0,dy+18, contents.width,line_height,
- "Need #{$data_system.currency_unit}#{itemcollection[1]}, you have #{$game_party.gold}." )
- dy += 18
- else
- itemkind = Integer(itemcollection[0])
- itemId = Integer(itemcollection[1])
- if itemkind == 1 #items
- pItem = $data_items[itemId]
- has = $game_party.item_number($data_items[itemId])
- elsif itemkind == 2 #armours
- pItem = $data_armors[itemId]
- has = $game_party.item_number($data_armors[itemId])
- else #weapons
- pItem = $data_weapons[itemId]
- has = $game_party.item_number($data_weaponss[itemId])
- end
- if has >= Integer(itemcollection[2])
- change_color(text_color(11))
- else
- change_color(text_color(10))
- end
- draw_text(0,dy+18, contents.width,line_height,"#{pItem.name}, need #{itemcollection[2]}, you have #{has}." )
- dy += 18
- end
- end
- end
- end
- def draw_skills
- change_color(system_color)
- draw_text(0,(36), contents.width,line_height,
- "Skills Learn")
- @loc += 2
- @uItem.features.each do | feature |
- if feature.code == 43
- change_color(text_color(14))
- icon_index = $data_skills[feature.data_id].icon_index
- draw_icon(icon_index, 1, (18*@loc))
- draw_text(26,(18*@loc), contents.width,line_height,
- $data_skills[feature.data_id].name)
- @loc +=1
- change_color(text_color(0))
- end
- end
- end
- def draw_item_stats
- dx = 0; dy = 54
- change_color(system_color)
- draw_text(0,36, contents.width,line_height,"Stats")
- dw = (contents.width - 48) / 3
- for i in 0...8
- draw_equip_param(i, dx, dy, dw)
- dx = dx >= 0 + dw ? 0: 0 + dw
- dy += line_height if dx == 0
- end
- end
- def draw_equip_param(param_id, dx, dy, dw)
- draw_background_box(dx, dy, dw)
- change_color(text_color(0))
- draw_text(dx+4, dy, dw-8, line_height, Vocab::param(param_id))
- draw_set_param(param_id, dx, dy, dw)
- end
- def draw_set_param(param_id, dx, dy, dw)
- value = @uItem.params[param_id]
- change_color(param_change_color(value), value != 0)
- text = value#.group
- text = "+" + text.to_s if value > 0
- draw_text(dx+4, dy, dw-8, line_height, text, 2)
- return text
- end
- def draw_background_box(dx, dy, dw)
- colour = Color.new(0, 0, 0, translucent_alpha/2)
- rect = Rect.new(dx+1, dy+1, dw-2, line_height-2)
- contents.fill_rect(rect, colour)
- end
- end
- class Window_CraftingChooices < Window_ItemList
- def initialize()
- super(0,48,Graphics.width-Graphics.width/1.5,Graphics.height-(48))
- end
- @m_type = "";
- def create_list(m_type)
- @m_type = m_type
- end
- def see_unlocks(item)
- show = true;
- if item.note =~ /<unlock>((.|\s)*)<\/unlock>/i
- unlocks = $1.gsub("\r", "").split("\n")
- unlocks.each do | unlock|
- if unlock == "" || unlock == nil
- next
- end
- unlockVals = unlock.split(' ');
- case unlockVals[0]
- when "party"
- if $game_party.highest_level < Integer(unlockVals[1])
- show = false
- end
- when "switch"
- if $game_switches[Integer(unlockVals[1])] == false
- show = false
- end
- end
- end
- end
- return show
- end
- def make_item_list
- @data =[]
- if @m_type == nil
- @data.push({:kind => 1,:name => "Items"})
- @data.push({:kind => 2,:name => "Weapons"})
- @data.push({:kind => 3,:name => "Armour"})
- elsif @m_type[:kind] == 1
- useCategorie = false;
- if $item_categories != nil
- useCategorie = true;
- $item_categories.each do | categor |
- @data.push({:kind => 6, :name => categor})
- end
- end
- $data_items.each do | item |
- if item == nil || item == ""
- next
- end
- if item.note =~ /<mat>(.|\s)*<\/mat>/i
- if see_unlocks(item) == true
- if item.note !~ /<cType: (.*)>/i
- @data.push({:kind => -3, :term_id => item.id,:name => item.name , :icon => item.icon_index})
- end
- end
- end
- end
- elsif @m_type[:kind] == 6
- $data_items.each do | item |
- if item == nil || item == ""
- next
- end
- if item.note =~ /<mat>(.|\s)*<\/mat>/i
- if see_unlocks(item) == true
- if item.note =~ /<cType: (.*)>/i
- if $1.downcase == @m_type[:name].downcase
- @data.push({:kind => -3, :term_id => item.id,:name => item.name , :icon => item.icon_index})
- end
- end
- end
- end
- end
- elsif @m_type[:kind] == 3
- wtype = 1
- $data_system.armor_types .each do |armor|
- if armor == nil || armor == ""
- next
- end
- notuse = false
- $armor_ignore.each do | id |
- if id == wtype
- notuse = true
- end
- end
- if notuse == false
- @data.push({:kind => 5, :term_id => wtype, :name => armor})
- end
- wtype += 1
- end
- elsif @m_type[:kind] == 2
- wtype = 1
- $data_system.weapon_types .each do |weapon|
- notuse = false
- if weapon == nil || weapon == ""
- next
- end
- $weapon_ignore.each do | id |
- if id == wtype
- notuse = true
- end
- end
- if notuse == false
- @data.push({:kind => 4, :term_id => wtype, :name => weapon})
- end
- wtype += 1
- end
- elsif @m_type[:kind] == 4
- $data_weapons.each do | qw |
- if qw == nil
- next
- end
- if qw.wtype_id == @m_type[:term_id]
- if qw.note =~ /<mat>(.|\s)*<\/mat>/i
- if see_unlocks(qw) == true
- @data.push({:kind => -1, :term_id => qw.id, :name => qw.name, :icon => qw.icon_index})
- end
- end
- end
- end
- elsif @m_type[:kind] == 5
- $data_armors.each do | qw |
- if qw == nil
- next
- end
- if qw.atype_id == @m_type[:term_id]
- if qw.note =~ /<mat>(.|\s)*<\/mat>/i
- if see_unlocks(qw) == true
- @data.push({:kind => -2, :term_id => qw.id, :name => qw.name, :icon => qw.icon_index})
- end
- end
- end
- end
- end
- end
- def draw_item(index)
- change_color(text_color(0))
- contents.font.size = 18
- item = @data[index]
- if item
- rect = item_rect(index)
- rect.width -= 4
- if item[:icon] != nil
- draw_icon(item[:icon],0,rect.y)
- rect.x = 26
- draw_text(rect, item[:name])
- else
- draw_text(rect, item[:name])
- end
- end
- end
- def col_max; 1; end
- def current_item
- @data[@index]
- end
- def current_item_enabled?
- true
- end
- end
- class Window_CraftItem < Window_Command
- def initialize
- super(0,0)
- self.openness = 0
- end
- def Set(item)
- @item = item
- end
- def make_command_list
- return unless @item
- if @item[:kind] == -3
- uItem = $data_items[@item[:term_id]]
- elsif @item[:kind] == -2
- uItem = $data_armors[@item[:term_id]]
- else
- uItem = $data_weapons[@item[:term_id]]
- end
- add_command("Craft #{uItem.name}", :craft)
- add_command("Cancel", :cancel)
- end
- def window_height
- fitting_height(2)
- end
- end
- module ELEMENTME
- ELEMENTS = {}
- ELEMENTS["Physical"] = {
- :icon => 116
- }
- ELEMENTS["Absorb"] = {
- :icon => 0
- }
- ELEMENTS["Fire"] = {
- :icon => 96
- }
- ELEMENTS["Ice"] = {
- :icon => 97
- }
- ELEMENTS["Thunder"] = {
- :icon => 98
- }
- ELEMENTS["Water"] = {
- :icon => 99
- }
- ELEMENTS["Earth"] = {
- :icon => 100
- }
- ELEMENTS["Wind"] = {
- :icon => 101
- }
- ELEMENTS["Holy"] = {
- :icon => 102
- }
- ELEMENTS["Dark"] = {
- :icon => 103
- }
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement