=begin
#===============================================================================
Title: ITEM MP COST
Author: Hime and Harosata
Created: 2/26/17
Note: As this was made with Hime's script as a base,
terms of this Script will follow hers.
--------------------------------------------------------------------------------
This script is was made from Himework's Custom Use Conditions. Based on a request
to subtract MP when using an item, I figured that I could take the concept
of formula: a.mp >= x and make it subtract MP from an item.
I figured that I could take the concept of formula: a.mp >= x
and make it subtract MP from an item. This is the notetag:
<item_mp: cost >
Place the notetag in your item and the cost of your MP.
If your character does not have the MP for that item, it will be unusable.
For the request, using an item from the Item Menu will not consume MP.
Also, this script can work separately from Himework's Custom Use Conditions,
though if you use her script, you should place hers above mine due to edited
Window_BattleItem stuff. The MP cost can also be affected by MCR,
found in the MP Cost Down state!
#===============================================================================
=end
$imported = {} if $imported.nil?
$imported["TH_CustomItemCost"] = true
#===============================================================================
# ** Configuration
#===============================================================================
module TH
module Custom_itemcost
Regex = /<item_mp:\s*(\d+)\s>/i
end
end
#===============================================================================
# ** Rest of Script
#===============================================================================
module RPG
class UsableItem < BaseItem
def itemcost
load_notetag_itemcost unless @itemcost
return @itemcost
end
def load_notetag_itemcost
res = self.note.match(TH::Custom_itemcost::Regex)
@itemcost = res ? res[1].to_i : 0
end
end
end
class Game_BattlerBase
def custom_itemcost_met?(item)
true
end
end
class Game_Battler < Game_BattlerBase
alias :th_itemcost_use_item :use_item
def use_item(item)
pay_item_cost(item) if item.is_a?(RPG::Item)
th_itemcost_use_item(item)
end
def pay_item_cost(item)
self.mp -= item_mp_cost(item)
end
def item_mp_cost(item)
SceneManager.scene_is?(Scene_Battle) ? (item.itemcost * mcr).to_i : 0
end
end
class Game_Actor < Game_Battler
alias :th_itemcost_usable? :usable?
def usable?(item)
bool = th_itemcost_usable?(item)
return false unless bool
unless @check_itemcost
@check_itemcost = true
bool = custom_itemcost_met?(item)
@check_itemcost = false
end
return bool
end
#-----------------------------------------------------------------------------
#
#-----------------------------------------------------------------------------
alias :th_itemcost_custom_itemcost_met? :custom_itemcost_met?
def custom_itemcost_met?(item)
return false unless th_itemcost_custom_itemcost_met?(item)
return true if self.mp >= item_mp_cost(item)
return false
end
end
class Window_BattleItem < Window_ItemList
def enable?(item)
BattleManager.actor.usable?(item) #and BattleManager.actor.mp >= BattleManager.actor.item_mp_cost(item) #$game_party.usable?(item)
end
def include?(item)
return ($game_party.item_number(item) > 0 and item.battle_ok?) if item.is_a?(RPG::Item) && !item.key_item?
return $game_party.usable?(item)
end
def draw_item(index)
item = @data[index]
if item
rect = item_rect(index)
rect.width -= 4
draw_item_name(item, rect.x, rect.y, enable?(item))
draw_item_cost(rect, item)
draw_item_number(rect, item)
end
end
def draw_item_cost(rect, item)
return false if item == nil
if BattleManager.actor.item_mp_cost(item) > 0
cx = text_size(BattleManager.actor.item_mp_cost(item)).width
change_color(mp_cost_color, enable?(item))
draw_text(rect.x + rect.width - cx - 32, rect.y, rect.width, rect.height, BattleManager.actor.item_mp_cost(item))
change_color(normal_color, enable?(item))
end
end
end