Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class << DataManager
- alias theo_icost_load_db load_database
- def load_database
- theo_icost_load_db
- $data_items.compact.each do |item|
- item.load_item_cost
- end
- end
- end
- class RPG::Item < RPG::UsableItem
- attr_accessor :hp_cost
- attr_accessor :mp_cost
- attr_accessor :tp_cost
- attr_accessor :hp_cost_per
- attr_accessor :mp_cost_per
- attr_accessor :tp_cost_per
- attr_accessor :requirement
- attr_accessor :perform
- def load_item_cost
- @hp_cost = @mp_cost = @tp_cost = @hp_cost_per = @mp_cost_per =
- @tp_cost_per = 0
- @requirement = "true"
- @perform = ""
- req_add = false
- perform_add = false
- note.split(/[\r\n]+/).each do |line|
- case line
- when /<(?:hp cost|hp_cost):[ ]*(\d+)>/i
- @hp_cost = $1.to_i
- when /<(?:hp cost|hp_cost):[ ]*(\d+)\%>/i
- @hp_cost_per = $1.to_i * 0.01
- when /<(?:mp cost|mp_cost):[ ]*(\d+)>/i
- @mp_cost = $1.to_i
- when /<(?:mp cost|mp_cost):[ ]*(\d+)\%>/i
- @mp_cost_per = $1.to_i * 0.01
- when /<(?:tp cost|tp_cost):[ ]*(\d+)>/i
- @tp_cost = $1.to_i
- when /<(?:tp cost|tp_cost):[ ]*(\d+)\%>/i
- @tp_cost_per = $1.to_i * 0.01
- when /<(?:custom requirement|custom_requirement)>/i
- req_add = true
- @requirement = ""
- when /<\/(?:custom requirement|custom_requirement)>/i
- req_add = false
- when /<(?:custom perform|custom_perform)>/i
- perform_add = true
- @perform = ""
- when /<\/(?:custom perform|custom_perform)>/i
- perform_add = false
- else
- if req_add
- @requirement += line
- elsif perform_add
- @perform += line
- end
- end
- end
- end
- def usable?(user)
- eval(requirement)
- end
- end
- class Game_Battler < Game_BattlerBase
- def item_cost_payable?(item)
- item_cost_hp(item) <= hp &&
- item_cost_mp(item) <= mp &&
- item_cost_tp(item) <= tp &&
- item_cost_hpper(item) <= hp_rate &&
- item_cost_mpper(item) <= mp_rate &&
- item_cost_tpper(item) <= tp_rate
- end
- def pay_item_cost(item)
- self.hp -= (mhp * item_cost_hpper(item)).to_i
- self.hp -= item_cost_hp(item)
- self.mp -= (mmp * item_cost_mpper(item)).to_i
- self.mp -= item_cost_mp(item)
- self.tp -= (max_tp * item_cost_tpper(item)).to_i
- self.tp -= item_cost_tp(item)
- begin
- eval(item.perform)
- rescue
- msgbox "there's something wrong with your custom cost perform"
- return
- end
- end
- def item_cost_hp(item)
- item.hp_cost
- end
- def item_cost_mp(item)
- (item.mp_cost * mcr).to_i
- end
- def item_cost_tp(item)
- item.tp_cost
- end
- def item_cost_hpper(item)
- item.hp_cost_per
- end
- def item_cost_mpper(item)
- item.mp_cost_per
- end
- def item_cost_tpper(item)
- item.tp_cost_per
- end
- alias theo_icost_consume_item consume_item
- def consume_item(item)
- theo_icost_consume_item(item)
- pay_item_cost(item)
- end
- end
- class Window_BattleItem < Window_ItemList
- attr_accessor :subject
- alias theo_icost_enable? enable?
- def enable?(item)
- result = true
- if @subject
- result = @subject.item_cost_payable?(item) && item.usable?(@subject)
- end
- result && theo_icost_enable?(item)
- end
- end
- #~ class Window_Help < Window_Base
- #~ alias theo_icost_set_item set_item
- #~ def set_item(item)
- #~ theo_icost_set_item(item)
- #~ return unless SceneManager.scene_is?(Scene_Battle)
- #~ draw_item_cost(item)
- #~ end
- #~
- #~ def draw_item_cost(item)
- #~ hp_color = 20
- #~ mp_color = 23
- #~ tp_color = 29
- #~ text = "\\}"
- #~ text += "\\C[#{hp_color}]"
- #~ text += "#{item.hp_cost} HP" if item.hp_cost > 0
- #~ text += "\\C[#{mp_color}]"
- #~ text += "#{item.mp_cost} MP" if item.mp_cost > 0
- #~ text += "\\C[#{tp_color}]"
- #~ text += "#{item.hp_cost} TP" if item.tp_cost > 0
- #~ text_to_calculate = text.gsub(/(\\C\[\d+\]|\\})/i) {""}
- #~ puts text_to_calculate
- #~ wdth = text_size(text_to_calculate).width
- #~ draw_text_ex(contents.width - wdth/2, line_height + 8, text)
- #~ end
- #~
- #~ end
- class Scene_Battle < Scene_Base
- alias theo_icost_cmd_item command_item
- def command_item
- @item_window.subject = BattleManager.actor
- theo_icost_cmd_item
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment