Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #======================#
- # Z-Systems by: Zetu #
- #===========================#======================#===========================#
- # * * * Z02 AMPX Ace Version v1.03 * * * #
- #=#==========================================================================#=#
- # 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, <type>, <element_id(s)>, <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, :percentdmg, 120,
- :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, :percentdmg, -150,
- :max, 100,
- :name, "Focus",
- :abbv, "F",
- :color, 3, 11
- ],[
- :invert,
- :depleteoob,
- :regenelemental, 3, :percent, 80,
- :regenelemental, 4, 6, :percent, -120,
- :regen, :set, -30,
- :max, 150,
- :name, "Heat",
- :abbv, "H",
- :color, 2, 10
- ]]
- # Place in Class/Actor note to specify what resource(s) they use.
- # (May use more than one.)
- REGEXP_RESOURCES = /<ampx[:]*\s*(.*)>/i
- # Place in Skill note to specify mana cost. First regexp will default
- # in value in database (MP Cost)
- REGEXP_NOVALUE = /<ampxcost[:]*\s*(.+)>/i
- REGEXP_WVALUE = /<ampxcost[:]*\s*(.+) +(\d+)>/i
- # If skill does MP damage/healing, use this to tell what resource.
- REGEXP_AMPX = /<ampxvalue[:]*\s*(.+)>/i
- # Default value if not in RESBYCLASS hash.
- DEF_RES = "Mana"
- #========#======================#====#================================#========#
- #--------# #----# DO NOT EDIT PAST THIS POINT!!! #--------#
- #--------# End of Customization #----# Editing will cause death by #--------#
- #--------# #----# brain asplosions. #--------#
- #========#======================#====#================================#========#
- end
- ($imported||={})[:z02]=true
- class Window_Base < Window
- #--------------------------------------------------------------------------
- # * New method: draw_actor_ampx
- #--------------------------------------------------------------------------
- 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
- #--------------------------------------------------------------------------
- # * Overwrite method: draw_actor_mp
- #--------------------------------------------------------------------------
- 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_writer :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 = []
- @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 max
- @max.nil? ? @actor.mmp : @max
- 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=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 regenoffdmg(amt)
- return if regenouttype.nil?
- return if amt < 1
- tvalue = regenoutbase
- case regenouttype
- when :damage; tvalue *= amt
- when :maxmp; tvalue *= max
- when :percentdmg; tvalue *= amt.to_f/@actor.mhp
- end
- self.value += tvalue.to_i
- end
- def regendmg(amt, element_id=0)
- regendmgreg(amt)
- regendmgele(amt, element_id)
- end
- def regendmgreg(amt)
- return if regenodtype.nil?
- return if amt < 1
- tvalue = regenodbase
- case regenodtype
- when :damage; tvalue *= amt
- when :maxmp; tvalue *= max
- when :percentdmg; tvalue *= amt.to_f/@actor.mhp
- end
- self.value += tvalue.to_i
- end
- def regendmgele(amt, element_id)
- return if regenelemental.nil?
- return if regenelemental[element_id].nil?
- return if amt < 1
- tvalue = regenelemental[element_id][1]
- case regenelemental[element_id][0]
- when :damage; tvalue *= amt
- when :maxmp; tvalue *= max
- when :percentdmg; tvalue *= amt.to_f/@actor.mhp
- end
- self.value += tvalue.to_i
- end
- def pay?(amount)
- if @tags.include?(:invert)
- return (@value+amount)<=@max
- else
- return (@value)>=amount
- end
- end
- def pay(amt)
- if @tags.include?(:invert)
- @value += amt
- else
- @value -= amt
- end
- end
- end
- class Game_Battler < Game_BattlerBase
- attr_reader :resources
- #--------------------------------------------------------------------------
- # * New method: create_resources
- #--------------------------------------------------------------------------
- def create_resources
- @resources = []
- create_actor_spec_resources
- @resources.push(Game_Resources.new(Z02::DEF_RES, self)) if @resources.size==0
- end
- #--------------------------------------------------------------------------
- # * New method: create_actor_spec_resources
- #--------------------------------------------------------------------------
- def create_actor_spec_resources
- end
- #--------------------------------------------------------------------------
- # * Alias method: on_turn_end
- #--------------------------------------------------------------------------
- alias :z02ote :on_turn_end
- def on_turn_end
- z02ote
- for resource in @resources
- resource.regen
- end
- end
- #--------------------------------------------------------------------------
- # * New method: resourcebyid
- #--------------------------------------------------------------------------
- def resourcebyid(id)
- for resource in @resources
- return resource if resource.index==id
- end
- return nil
- end
- #--------------------------------------------------------------------------
- # * New method: skill_ampx_costs
- #--------------------------------------------------------------------------
- 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
- #--------------------------------------------------------------------------
- # * Overwrite method: skill_cost_payable?
- #--------------------------------------------------------------------------
- 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 method: pay_skill_cost
- #--------------------------------------------------------------------------
- alias :z02psc :pay_skill_cost
- 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
- #--------------------------------------------------------------------------
- # * Alias method: item_apply
- #--------------------------------------------------------------------------
- alias :z02ia :item_apply
- def item_apply(user, item)
- z02ia(user, item)
- if @result.hit?
- unless item.damage.none?
- ampx_ondamage(user, item.damage.element_id)
- resource = resource(item)
- unless resource.nil?
- resource.value -= @result.mp_damage
- ####user.mp += @result.mp_drain#### NEED TO ADD DRAIN
- end
- end
- end
- end
- def ampx_ondamage(user, element_id)
- return if @result.hp_damage==0
- for resource in @resources
- resource.regendmg(@result.hp_damage, element_id)
- end
- for resource in user.resources
- resource.regenoffdmg(@result.hp_damage)
- end
- end
- def resource(item)
- name = item.resourcename
- for resource in resources
- return resource if resource.name.upcase==name.upcase
- end
- return nil
- end
- end
- class Game_Enemy < Game_Battler
- #--------------------------------------------------------------------------
- # * Alias method: initialize
- #--------------------------------------------------------------------------
- alias :z02init :initialize
- def initialize(index, enemy_id)
- z02init(index, enemy_id)
- create_resources
- end
- end
- class Game_Actor < Game_Battler
- #--------------------------------------------------------------------------
- # * Alias method: setup
- #--------------------------------------------------------------------------
- alias :z02setup :setup
- def setup(actor_id)
- z02setup(actor_id)
- create_resources
- end
- #--------------------------------------------------------------------------
- # * New method: create_actor_spec_resources
- #--------------------------------------------------------------------------
- def create_actor_spec_resources
- self.class.note.scan(Z02::REGEXP_RESOURCES){
- @resources.push(Game_Resources.new($1, self))}
- end
- end
- module SceneManager
- #--------------------------------------------------------------------------
- # * Alias method: call
- #--------------------------------------------------------------------------
- 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 method: draw_skill_cost
- #--------------------------------------------------------------------------
- alias :z02dsc :draw_skill_cost
- 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
- class RPG::UsableItem < RPG::BaseItem
- def resourcename
- self.note.scan(Z02::REGEXP_AMPX){
- return $1}
- return Z02::DEF_RES
- end
- end
- class Game_ActionResult
- def ampx_damage_text(name)
- if @mp_drain > 0
- fmt = @battler.actor? ? Vocab::ActorDrain : Vocab::EnemyDrain
- sprintf(fmt, @battler.name, name, @mp_drain)
- elsif @mp_damage > 0
- fmt = @battler.actor? ? Vocab::ActorLoss : Vocab::EnemyLoss
- sprintf(fmt, @battler.name, name, @mp_damage)
- elsif @mp_damage < 0
- fmt = @battler.actor? ? Vocab::ActorRecovery : Vocab::EnemyRecovery
- sprintf(fmt, @battler.name, name, -@mp_damage)
- else
- ""
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement