Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $imported_trvc_params = true # make this false to disable this script
- if $imported_trvc_params
- # =============================================================================
- # ======== INTRODUCTION =======================================================
- # =============================================================================
- # Name: Stat Manager
- # Author: Trevyn MC (http://trevync.wordpress.com/)
- # Version: 1.2 (5/28/14)
- #
- # Purpose: Allows for the easy creation of custom stats. Features a number of
- # "plugins" that cause custom stats to effect the game in various
- # ways
- #
- # Dependencies: None
- #
- # Terms Of Use:
- # 1 Always give credit
- # 2 Let me know when you release a game (a response to the forum post about
- # this script is enough)
- # 3 Always include the full introduction section with the script
- #
- # Otherwise you are free to use and modify as you see fit for both
- # commercial or non_commercial projects
- #
- # Compatibility:
- # Overwrites: None
- # Alias: 1 Method
- # Data_Manager::load_database
- #
- # Mostly This script just adds new stats. since by itself it doesn't
- # actually do anything with them there should not be any compatibility
- # issues
- #
- # Change_log:
- # 5/28/14: 1.0 Initial Release
- # 5/28/14: 1.1 Bug fix. Changed script calls
- # 5/28/14: 1.2 Conditional and Formula Modifiers
- #
- # =============================================================================
- # ========= INSTRUCTIONS ======================================================
- # =============================================================================
- # Place this script Above Materials and below main
- #
- # To add a new stat to the game simply put the name of the stat in the
- # Add_New_Params_Here array
- #
- # After that the new stat will be added to the game! it is that simple
- #
- # To retrieve the stats value with a simple call
- #
- # $game_actors[id].t_stat(param_name)
- # Returns the combined value of all objects that modify that stat
- # for the specified actor.
- #
- # You can also use these script calls to modify custom paramaters of
- # an actor
- # $game_actors[id].t_stat_rate(rate, param_name)
- # Or
- # $game_actors[id].t_stat_plus(plus, param_name)
- # Or
- # $game_actors[id].t_stat_reset(param_name)
- #
- # Notetags:
- # <stat_name: (+,-,*) value>
- # Put this notetag on Actors, Enemies, States, Classes, Equips, Or Skills
- #
- # example
- # <str: - 6>
- # <cha: + 5>
- # <dex: * 2.5>
- # etc
- #
- # In addition there are two more note_tag types.
- # conditions and formulas. Use these wisely! as making conditions/formulas
- # based on other t_stats will potentially crash the game...
- # Avoid recursive calls!
- #
- # <int: condition>
- # actor? ? true : false
- # </int>
- # <wis: formula>
- # level * 12
- # </wis>
- #
- # multitple conditions or multiple formulas on the same object affecting the
- # same stat will be ignored.
- #
- #
- #
- #
- # One more note is if you put
- # a.t_stat(param_name)
- # or
- # b.t_stat(param_name)
- #
- # in a skill damage formula then you can modify skill damage base on these
- # parameters.
- #
- #
- # =============================================================================
- # ========= CUSTOMIZATION =====================================================
- # =============================================================================
- module Trvc_Params
- Add_New_Params_Here = [
- # [name , formula],
- "str",
- "wis",
- "dex",
- "con",
- "int",
- "cha",
- ] # do not touch
- Params = [# they can also be added here if you understand how this script works
- # [[:catagory_name, Id],["notetag value", Notetag_Id(optional)]]
- # if Notetag_Id is specified then the notetage will be
- # <stat_catagory stat_id: (+,-,*) value> and the calls to access a stat become
- # t_param(name, id)
- ]
- end
- # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- # =============================================================================
- # ========= TECHNICAL STUFF ===================================================
- # =============================================================================
- module Trvc_Params
- # ===========================================================================
- # ======================== Read Notetags on database load ===================
- # ===========================================================================
- def self.init_params
- Add_New_Params_Here.each do |n|
- Params.push([[n.to_sym, 0],[n]])
- end
- for o in $data_skills | $data_classes | $data_enemies | $data_states | $data_actors | $data_weapons | $data_armors
- next if o.nil?
- next unless o.note.match(/<.*>/)# skipps objects that have not notetags
- for p in Params
- next if p.nil?
- read_param_note(o, p)
- end
- end
- end
- # ======================== Read an individual notetag =======================
- def self. read_param_note(o, p)
- return if p.nil?
- key = p[1][0]
- return unless o.note.match(/<(#{key})/)# Skips if key isn't found
- id = p[1][1]
- id = id.to_s if id
- id = "" if id.nil?
- ary = o.note.scan(/<(#{key})[ _\-]?(#{id}):\s*([\+\*\-]?)\s*(\d*\.*\d+)>/)
- return unless ary
- for a in ary
- next if a.nil?
- rate = 1.0
- plus = 0
- case a[2]
- when "*"
- rate = a[3].to_f
- when "-"
- plus = -(a[3].to_f)
- else
- plus = a[3].to_f
- end
- o.add_t_param(p[0][0],p[0][1], Param.new(rate,plus))
- end
- options = o.note.scan(/<#{key}[ _\-]?#{id}:\s*(condition|formula)>(.*)<\/#{key}/m)
- for opt in options
- next if opt.nil?
- case opt[0]
- when "formula"
- formula = opt[1]
- when "condition"
- condition = opt[1]
- end
- par = Param.new
- par.formula = formula if formula
- par.condition = condition if condition
- o.add_t_param(p[0][0],p[0][1], par)
- end
- end
- # ===========================================================================
- # =========================== Param Class Definition ========================
- # ===========================================================================
- class Param
- # ========================= Initialize members ============================
- def initialize(r = 1.0, p = 0)
- @rate = r
- @plus = p
- @formula = "0"
- @condition = "true"
- end
- attr_accessor :condition
- attr_accessor :formula
- attr_accessor :rate
- attr_accessor :plus
- # ========================= Public Method for combining parameter =========
- def combine(p)
- return self unless p.is_a? Param
- @rate *= p.rate
- @plus += p.plus
- @condition = p.condition if @condition == "true"
- @formula = p.formula if @formula == "0"
- return self
- end
- # ========================== Calculates and returns the value =============
- def value
- result = @plus * @rate
- result
- end
- # ========================== Resets the value to default ==================
- def reset
- @rate = 1.0
- @plus = 0
- end
- end
- # ================================= End Class Param =========================
- end
- # =================================== End Module Trvc_Params ==================
- # =============================================================================
- # ======================= Add or retrieve Params from database objects
- # =============================================================================
- class RPG::BaseItem
- # =========================== To retrieve ===================================
- def get_t_param(type, id)
- return nil if @trvc_params.nil?
- return nil if @trvc_params[type].nil?
- return @trvc_params[type][id]
- end
- # =========================== To Add ========================================
- def add_t_param(type, id, p)
- @trvc_params = {} if @trvc_params.nil?
- @trvc_params[type] = [] if @trvc_params[type].nil?
- if @trvc_params[type][id].nil?
- @trvc_params[type][id] = p
- else
- @trvc_params[type][id].combine(p)
- end
- end
- end
- # ====================================== End RPG::Base_Item ===================
- # =============================================================================
- # ===================================== Access Parameters by actor ============
- # =============================================================================
- class Game_Battler < Game_BattlerBase
- def t_stat(type, id = 0)
- t_param(type, id).value
- end
- # ===================================== Retrieve param object ===============
- def t_param(type, id = 0)
- p = Trvc_Params::Param.new
- ary = collect_t_feature_objs.compact.push( self)
- for o in ary
- temp = o.get_t_param(type, id)
- next if temp.nil?
- next unless eval(temp.condition) rescue false
- p.plus += eval(temp.formula) rescue 0
- p.combine(temp)
- end
- p
- end
- # ===================================== Add a bonus value ===================
- def t_stat_plus(value, type, id = 0)
- p = Trvc_Params::Param.new(1.0, value)
- add_t_param(type, id, p)
- end
- # ===================================== Add a rate ==========================
- def t_stat_rate(value, type, id = 0)
- p = Trvc_Params::Param.new(value, 0)
- add_t_param(type, id, p)
- end
- # ===================================== Reset local modifiers ===============
- def t_stat_reset(type, id = 0)
- get_t_param(type, id).reset unless get_t_param(type, id).nil?
- end
- # ===========================================================================
- # ======================= Add or retrieve local Params from battlers
- # ===========================================================================
- # =========================== To retrieve ===================================
- def get_t_param(type, id)
- return nil if @trvc_params.nil?
- return nil if @trvc_params[type].nil?
- return @trvc_params[type][id]
- end
- # =========================== To Add ========================================
- def add_t_param(type, id, p)
- @trvc_params = {} if @trvc_params.nil?
- @trvc_params[type] = [] if @trvc_params[type].nil?
- if @trvc_params[type][id].nil?
- @trvc_params[type][id] = p
- else
- @trvc_params[type][id].combine(p)
- end
- end
- def debug_test
- print t_stat(:cha)
- end
- end
- # ====================================== End Game_Battler ===================
- # ===========================================================================
- # ===================== Get Lists of objects with params ====================
- # ===========================================================================
- class Game_Battler < Game_BattlerBase
- def collect_t_feature_objs
- end
- end
- class Game_Enemy < Game_Battler
- def collect_t_feature_objs
- ary = [enemy] + states
- ary.compact
- end
- end
- class Game_Actor < Game_Battler
- def collect_t_feature_objs
- ary = skills + equips + states + [self.class] + [actor]
- ary.compact
- end
- end
- # ===========================================================================
- # ======================= Set up parameters on application start ============
- # ===========================================================================
- module DataManager
- class << self
- alias trvc_load_database load_database
- alias trvc_create_objects create_game_objects
- end
- def self.load_database
- trvc_load_database
- Trvc_Params::init_params
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement