Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #===================================================
- # Alternate MP X System :: By Zetu (RMVXAce)
- # v1.01
- ##==================================================
- # You may need slight scripting knowledge of working with arrays (but not a whole lot!).
- #-------------------------------------------------------------------------------------------
- # * * Anything in "< >" means replace with the described contents. * *
- # REQUIRED PARAMETERS (Any resource without it will cause an error)
- # :name, <name of resource>
- # :abbv, <1 or 2 character abbv. of resource>
- # :color, <color 1>, <color 2>
- # * These color attributes are indexes of the window skin
- # OPTIONAL PARAMETERS
- # Resource Regen for each turn:
- # :regen, <type>, <base>
- # type can be :mmp, :atk, :def, :spi, :agi, :set
- # base is number multiplied by type (:set is considered 1)
- # Resource Regen on Damage
- # :regenondamage, <type>, <base>
- # type can be :damage, :mmp, :set, :percentdmg
- # base in number multipled by type (:set is considered 1)
- # (:percentdmg is ratio of mmp and damage)
- # :regenelemental, <element_id>, <type>, <base>
- # same as :regenondamage, except on elemental damage (of element_ids)
- # (may place more than 1 id)
- # Resource Change Out of Battle:
- # :depleteoob (Set to 0)
- # :regenoob (Set to Max)
- # Max Value
- # :max, <value>
- # Resource Inversion
- # :invert
- # this allows the resource to Add instead of Subtract for its cost and disallows
- # skill use if cost will exceed the max resource
- #==========================================================================#
- module Z02
- RESOURCES = [
- :regen, :mmp, 0.05,
- :name, "Mana",
- :abbv, "M",
- :color, 23, 22
- ],[
- :depleteoob,
- :regenondamage, :percent, 12,
- :max, 100,
- :name, "Rage",
- :abbv, "R",
- :color, 10, 2
- ],[
- :regenoob,
- :regen, :set, 20,
- :max, 100,
- :name, "Energy",
- :abbv, "E",
- :color, 6, 14
- ],[
- :regenoob,
- :regen, :set, 30,
- :regenondamage, :percent, -15,
- :max, 100,
- :name, "Focus",
- :abbv, "F",
- :color, 3, 11
- ],[
- :invert,
- :depleteoob,
- :regenelemental, 9, :percent, 2,
- :regenelemental, 10, 12, :percent, -1,
- :regen, :set, -30,
- :max, 150,
- :name, "Heat",
- :abbv, "H",
- :color, 2, 10
- ]
- # If set to false, use RESBYCLASS's indexes as Actor IDs instead of Class IDs
- BIND_TO_CLASS = true
- # Place in Class/Actor note to specify what resource(s) they use.
- # (May use more than one.)
- REGEXP_RESOURCES = /<ampx[: ]+(.*)>/i
- # Place in Skill note to specify mana cost. First regexp will default
- # in value in database (MP Cost)
- REGEXP_NOVALUE = /<ampx[: ]+(.+)>/i
- REGEXP_WVALUE = /<ampx[: ]+(.+) +(\d+)>/i
- # Default value if not in RESBYCLASS hash.
- DEF_RES = "Mana"
- end
- class Window_Base < Window
- def draw_actor_ampx(resource, x, y, width)
- draw_gauge(x, y, width, resource.rate, text_color(resource.color1), text_color(resource.color2))
- change_color(text_color(resource.color2))
- draw_text(x, y, 30, line_height, resource.abbv)
- draw_current_and_max_values(x, y, width, resource.value, resource.max,#~
- mp_color(resource.actor), normal_color)
- end
- def draw_actor_mp(actor, x, y, width=124)
- if actor.resources.nil?
- actor.setup(actor.id)
- end
- width /= actor.resources.size
- offset = width
- if actor.resources.size != 1
- offset += 2
- width -= 1
- end
- for i in 0...actor.resources.size
- draw_actor_ampx(actor.resources[i], x+offset*i, y, width)
- end
- end
- end
- class Game_Resources
- attr_reader :name, :abbv, :color1, :color2, :value, :regenelemental,
- :regentype, :regenbase, :regenodtype, :regenodbase, :tags, :regenouttype,
- :regenoutbase, :actor, :index
- attr_accessor :max
- def initialize(type, actor)
- @actor = actor
- @index = get_resource_index(type)
- scan_object_variables(@index)
- end
- def scan_object_variables(index)
- i = 0
- array=Z02::RESOURCES[index]
- @tags = []
- @max = @actor.mmp
- @value = @max
- @maxdefault = true
- @regenelemental = {}
- while (i < array.size)
- case array[i]
- when :name; @name = array[i+1]; i+=1
- when :abbv; @abbv = array[i+1]; i+=1
- when :color; @color1 = array[i+1]; @color2 = array[i+2]; i+=2
- when :regen; @regentype = array[i+1]; @regenbase = array[i+2]; i+=2
- when :regenonoutdmg
- @regenouttype = array[i+1]
- @regenoutbase = array[i+2]
- i+=2
- when :regenondamage
- @regenodtype = array[i+1]
- @regenodbase = array[i+2]
- i+=2
- when :regenelemental
- i+=1
- id = []
- while (array[i].is_a?(Integer))
- id.push(array[i])
- i+=1
- end
- for n in id
- @regenelemental[n]= array[i], array[i+1]
- end
- i+=1
- when :max
- @max = array[i+1]
- i+=1
- @value = [@max, @value].min
- @maxdefault = false
- when :depleteoob; @tags.push(:depleteoob); @value = 0
- when :regenoob; @tags.push(:regenoob)
- when :invert; @tags.push(:invert)
- end
- i+=1
- end
- end
- def get_resource_index(name)
- for i in 0...Z02::RESOURCES.size
- index = Z02::RESOURCES[i].index(:name)+1
- if Z02::RESOURCES[i][index].upcase==name.upcase
- return i
- end
- end
- end
- def reinitialize
- if @tags.include?(:depleteoob)
- self.value=0
- elsif @tags.include?(:regenoob)
- self.value=self.max
- end
- end
- def value=(new_value)
- @value = [[new_value, 0].max, @max].min
- end
- def rate
- max > 0 ? value.to_f / max : 0
- end
- def regen
- return if @actor.dead?
- return if @regentype.nil?
- tvalue = @regenbase
- case @regentype
- when :mmp; tvalue *= max
- when :atk; tvalue *= @actor.atk
- when :def; tvalue *= @actor.def
- when :spi; tvalue *= @actor.spi
- when :agi; tvalue *= @actor.agi
- end
- self.value += tvalue.to_i
- end
- def regendmg(value)
- return if regenodtype.nil?
- tvalue = regenodbase
- case regenodtype
- when :damage
- value *= tvalue
- when :maxmp
- tvalue *= max
- when :percentdmg
- tvalue *= value.to_f/max
- end
- self.value += tvalue.to_i
- end
- def regenoffdmg(value)
- return if regenouttype.nil?
- tvalue = regenoutbase
- case regenouttype
- when :damage
- value *= tvalue
- when :maxmp
- tvalue *= max
- when :percentdmg
- tvalue *= value.to_f/max
- end
- self.value += tvalue.to_i
- end
- def pay?(amount)
- if @tags.include?(:invert)
- return (self.value+amount)<=self.max
- else
- return (self.value)>=amount
- end
- end
- def pay(amount)
- if @tags.include?(:invert)
- self.value += amount
- else
- self.value -= amount
- end
- end
- end
- class Game_Battler < Game_BattlerBase
- attr_reader :resources
- def create_resources
- print "Creating Resources for #{self.name}!\n"
- @resources = []
- create_actor_spec_resources
- @resources.push(Game_Resources.new(Z02::DEF_RES, self)) if @resources.size==0
- end
- def create_actor_spec_resources
- end
- alias z02ote on_turn_end unless $@
- def on_turn_end
- z02ote
- for resource in self.resources
- resource.regen
- end
- end
- alias z02od on_damage
- def on_damage(value)
- z02od(value)
- for resource in self.resources
- resource.regendmg(value)
- end
- end
- def resourcebyid(id)
- for resource in resources
- return resource if resource.index==id
- end
- return nil
- end
- def skill_ampx_costs(skill)
- values = []
- skill.note.scan(Z02::REGEXP_NOVALUE){
- next if (index=self.resources[0].get_resource_index($1)).nil?
- values[index] = skill.mp_cost}
- skill.note.scan(Z02::REGEXP_WVALUE){
- next if (index=self.resources[0].get_resource_index($1)).nil?
- values[index] = $2.to_i}
- if values.size==0
- index = self.resources[0].index
- values[index]=skill.mp_cost
- end
- return values
- end
- def skill_cost_payable?(skill)
- values = skill_ampx_costs(skill)
- for i in 0...values.size
- next if values[i].nil?
- return false if (resource = resourcebyid(i)).nil?
- return false unless resource.pay?(values[i])
- end
- return true
- end
- alias z02psc pay_skill_cost unless $@
- def pay_skill_cost(skill)
- z02psc(skill)
- values = skill_ampx_costs(skill)
- for i in 0...values.size
- next if values[i].nil?
- return false if (resource = resourcebyid(i)).nil?
- resource.pay(values[i])
- end
- end
- end
- class Game_Enemy < Game_Battler
- alias z02init initialize unless $@
- def initialize(index, enemy_id)
- z02init(index, enemy_id)
- create_resources
- end
- end
- class Game_Actor < Game_Battler
- alias z02setup setup unless $@
- def setup(actor_id)
- z02setup(actor_id)
- create_resources
- end
- def create_actor_spec_resources
- (Z02::BIND_TO_CLASS ? self.class : self).note.scan(Z02::REGEXP_RESOURCES){
- @resources.push(Game_Resources.new($1, self))}
- end
- end
- module SceneManager
- class <<self; alias_method :z02call, :call; end
- def self.call(scene_class)
- self.z02call(scene_class)
- for actor in $game_party.members
- next if actor.resources.nil?
- for resource in actor.resources
- resource.reinitialize
- end
- end
- end
- end
- class Window_SkillList < Window_Selectable
- alias z02dsc draw_skill_cost unless $@
- def draw_skill_cost(rect, skill)
- if @actor.skill_tp_cost(skill) > 0
- z02dsc(rect, skill)
- elsif @actor.skill_mp_cost(skill) > 0
- values = @actor.skill_ampx_costs(skill)
- values.size.downto(0) { |i|
- next if values[i].nil?
- next if (resource = @actor.resourcebyid(i)).nil?
- change_color(text_color(resource.color1), @actor.skill_cost_payable?(skill))
- draw_text(rect, values[i], 2)
- rect.width -= 32
- }
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement