#=============================================================================== # # Yanfly Engine RD - Battler Stat Morale # Last Date Updated: 2009.06.19 # Level: Normal # # This script generates a new stat for your battlers called Morale. Morale will # affect multiple stats (which you can adjust or even turn off completely) and # can be used in skill requirements. Overall, this is a system for rewarding the # player for doing well and punishing the player for neglecting the team. # # Morale can affect HP, MP, attack power, defensive power, spiritual power, # agility, hit rate, evasion rate, critical rate, and also odds. These can be # enabled and disabled inside the script's module, and you can affect how much # morale certain actions will boost or alter. Some skills can require morale # at certain levels, too. # #=============================================================================== # Updates: # ---------------------------------------------------------------------------- # o 2009.06.19 - Fixed HP/MP dropping bug. # o 2009.05.15 - Started script and finished. #=============================================================================== # Instructions #=============================================================================== # # These go into the skill's notebox # --------------------------------- # # # This causes the skill to require x morale before it can be used. Note that # requiring x morale doesn't mean spending it. A positive requirement will need # for the user's morale to be over x. A negative requirement will need the # user's morale to be under x. If the requirement for morale is zero, the user # will require anything positive. # # # This will cause the skill to change x morale when used. Use "-" and "+" signs # to indicate which direction morale will go. This will affect the battler using # the skill and not the target receiving it. Changing morale can go over and/or # under zero for the skill user. # # # This will cause the skill to boost the target's morale by x when used. Use the # "-" and "+" signs to indicate which direction morale will go. This will affect # the target and not the battler using the skill. Changing morale can go over # and/or under zero for the target. # # These go into the enemy's notebox # --------------------------------- # # # This will change that enemy's maximum morale to x value. Use "+" to indicate # a positive maximum morale and "-" to indicate a negative maximum morale. # # # This will change that enemy's minimum morale to x value. Use "+" to indicate # a positive minimum morale and "-" to indicate a negative minimum morale. # # # This is the morale the enemy gives the party when it's killed. Use "+" to give # the party a positive morale boost or "-" to give the party a negative morale # boost. If the enemy runs away, no morale is affeted. # # These go into a state's notebox # ------------------------------- # # , # This raises max/min morale limit by x value. Use "+" to indicate a positive # increase and "-" to indicate a negative increase. For example, +10 will yield # +10% more max/min morale. This is calculated after level increases. # # , # This raises max/min morale limit by x value. Use "+" to indicate a positive # increase and "-" to indicate a negative increase. For example, +10 will yield # +10 set amount of max/min morale. This is calculated after level increases. # #=============================================================================== # # Compatibility # - Works With: Yanfly's Custom Skill Effects # - Alias: Game_Battler: initialize, stats, slip_damage_effect, skill_can_use? # - Alias: Game_Actor: perform_collapse, HECO stats # - Alias: Game_Enemy: perform_collapse, HECO stats # - Alias: Scene_Battle: battle_end, execute_action_skill # #=============================================================================== $imported = {} if $imported == nil $imported["BattlerStatMorale"] = true module YE module BATTLE module STAT # These numbers govern the default values, minimum values, and maximum # values for your characters' morale. MORALE_DEFAULT = 0 MORALE_BASE_MAXIMUM = 5000 MORALE_BASE_MINIMUM = -5000 # This part determines how much each level affects maximum and minimum # morale capacity. Note that this doesn't apply to enemies. If you wish # to give enemies different maximums and minimums, input tags into their # noteboxes with and to govern that. MORALE_MAX_PER_LEVEL = 100 MORALE_MIN_PER_LEVEL = 50 # This will govern how much of a morale boost battlers will get for # killing enemies, and what penalty battlers get for dying. Also governs # other aspects that may boost or lower morale, too. MORALE_UPON_KILL = 500 # party kills something MORALE_UPON_DEATH = -1500 # battler dies MORALE_UPON_HITTING = 150 # battler hits something MORALE_UPON_ATTACKED = -50 # battler is attacked MORALE_UPON_HEALER = 50 # battler heals someone MORALE_UPON_HEALED = 100 # battler is healed MORALE_UPON_DRAINER = 100 # battler absorbs from target MORALE_UPON_DRAINED = -10 # battler is absorbed from # This part determines the morale increase/decrease per point of damage # or healing as a percentage relative to the battler's MaxHP. MORALE_PER_DAMAGER = 0.100 # attacker boost per point% of damage MORALE_PER_DAMAGED = -0.10 # defender boost per point% of damage MORALE_PER_HEALER = 0.100 # healer boost per point% of damage MORALE_PER_HEALED = 0.200 # healed boost per point% of damage MORALE_PER_DRAINER = 0.200 # attacker boost per point% of drain MORALE_PER_DRAINED = -0.10 # defender boost per point% of drain # This will govern which stats morale will affect. HP/MP and ADSA stats # will be affected by a percentage value. HECO stats will be affected by # a set value. This is done mostly for balancing purposes. If you don't # want morale to affect a particular stat, set that stat value to 0. # Otherwise, this will adjust the value at which each morale point boosts. MORALE_MAXHP = 0.01000 MORALE_MAXMP = 0.01000 MORALE_ATK = 0.01500 MORALE_DEF = 0.02500 MORALE_SPI = 0.01500 MORALE_AGI = 0.02500 MORALE_HIT = 0.00750 MORALE_EVA = 0.00750 MORALE_CRI = 0.01000 MORALE_ODDS = -0.0010 # This will govern morale decay. Morale decay occurs once each turn and # will only happen when morale isn't zero. Upper means if morale is more # than zero. Lower means if morale is lower than zero. Decay will bring # either value closer to zero. MORALE_DECAY_UPPER = 50 MORALE_DECAY_LOWER = -100 # This will govern whether or not morale will be reset each battle for # your actors. This will also govern the morale decay between each battle # if it doesn't reset each battle. If morale is reset, morale reverts to # whatever value you set as the default morale. Decay occurs before adding # victory and escaping values considering that's ideal. MORALE_RESET = false MORALE_AFTER_BATTLE_UPPER = 100 MORALE_AFTER_BATTLE_LOWER = 300 end # STAT end # BATTLE end #YE #=============================================================================== # Editting anything past this point may potentially result in causing computer # damage, incontinence, explosion of user's head, coma, death, and/or halitosis. # Therefore, edit at your own risk. #=============================================================================== module YE module REGEXP module BASEITEM REQUIRE_MORALE = /<(?:REQUIRE_MORALE|require morale)[ ]*([\+\-]\d+)>/i CHANGE_MORALE = /<(?:CHANGE_MORALE|change morale)[ ]*([\+\-]\d+)>/i BOOST_MORALE = /<(?:BOOST_MORALE|boost morale)[ ]*([\+\-]\d+)>/i end module STATE if $imported["LimitBreak"] HECOLIMIT = KGC::LimitBreak::ACTOR_PARAMETER_LIMIT else HECOLIMIT = 999 end MAX_MORALE_PER = /<(?:MAX_MORALE_PER|max morale per)[ ]*([\+\-]\d+)>/i MIN_MORALE_PER = /<(?:MIN_MORALE_PER|min morale per)[ ]*([\+\-]\d+)>/i MAX_MORALE_SET = /<(?:MAX_MORALE_SET|max morale set)[ ]*([\+\-]\d+)>/i MIN_MORALE_SET = /<(?:MIN_MORALE_SET|min morale set)[ ]*([\+\-]\d+)>/i end module ENEMY MAX_MORALE = /<(?:MAX_MORALE|max morale)[ ]*([\+\-]\d+)>/i MIN_MORALE = /<(?:MIN_MORALE|min morale)[ ]*([\+\-]\d+)>/i KILL_MORALE = /<(?:KILL_MORALE|kill morale)[ ]*([\+\-]\d+)>/i end end end #=============================================================================== # RPG::BaseItem #=============================================================================== class RPG::BaseItem #-------------------------------------------------------------------------- # Yanfly_Cache_BSM #-------------------------------------------------------------------------- def yanfly_cache_baseitem_bsm @requires_morale = false; @required_morale = 0 @change_morale = 0; @boost_morale = 0 self.note.split(/[\r\n]+/).each { |line| case line when YE::REGEXP::BASEITEM::REQUIRE_MORALE @requires_morale = true @required_morale = $1.to_i when YE::REGEXP::BASEITEM::CHANGE_MORALE @change_morale = $1.to_i when YE::REGEXP::BASEITEM::BOOST_MORALE @boost_morale = $1.to_i end } end # cache #-------------------------------------------------------------------------- # definitions #-------------------------------------------------------------------------- def requires_morale yanfly_cache_baseitem_bsm if @requires_morale == nil return @requires_morale end def required_morale yanfly_cache_baseitem_bsm if @required_morale == nil return @required_morale end def change_morale yanfly_cache_baseitem_bsm if @change_morale == nil return @change_morale end def boost_morale yanfly_cache_baseitem_bsm if @boost_morale == nil return @boost_morale end end #=============================================================================== # RPG::State #=============================================================================== class RPG::State #-------------------------------------------------------------------------- # Yanfly_Cache_BSM #-------------------------------------------------------------------------- def yanfly_cache_state_bsm @max_morale_per = 100; @min_morale_per = 100 @max_morale_set = 0; @min_morale_set = 0 self.note.split(/[\r\n]+/).each { |line| case line when YE::REGEXP::STATE::MAX_MORALE_PER @max_morale_per += $1.to_i when YE::REGEXP::STATE::MIN_MORALE_PER @min_morale_per += $1.to_i when YE::REGEXP::STATE::MAX_MORALE_SET @max_morale_set += $1.to_i when YE::REGEXP::STATE::MIN_MORALE_SET @min_morale_set += $1.to_i end } end # cache #-------------------------------------------------------------------------- # definitions #-------------------------------------------------------------------------- def max_morale_per yanfly_cache_state_bsm if @max_morale_per == nil return @max_morale_per end def min_morale_per yanfly_cache_state_bsm if @min_morale_per == nil return @min_morale_per end def max_morale_set yanfly_cache_state_bsm if @max_morale_set == nil return @max_morale_set end def min_morale_set yanfly_cache_state_bsm if @min_morale_set == nil return @min_morale_set end end #=============================================================================== # RPG::Enemy #=============================================================================== class RPG::Enemy #-------------------------------------------------------------------------- # Yanfly_Cache_BSM #-------------------------------------------------------------------------- def yanfly_cache_enemy_bsm @max_morale = YE::BATTLE::STAT::MORALE_BASE_MAXIMUM @min_morale = YE::BATTLE::STAT::MORALE_BASE_MINIMUM @kill_morale = YE::BATTLE::STAT::MORALE_UPON_KILL self.note.split(/[\r\n]+/).each { |line| case line when YE::REGEXP::ENEMY::MAX_MORALE @max_morale = $1.to_i when YE::REGEXP::ENEMY::MIN_MORALE @min_morale = $1.to_i when YE::REGEXP::ENEMY::KILL_MORALE @kill_morale = $1.to_i end } end # cache #-------------------------------------------------------------------------- # definitions #-------------------------------------------------------------------------- def max_morale yanfly_cache_enemy_bsm if @max_morale == nil return @max_morale end def min_morale yanfly_cache_enemy_bsm if @min_morale == nil return @min_morale end def kill_morale yanfly_cache_enemy_bsm if @kill_morale == nil return @kill_morale end end #=============================================================================== # Game_Battler #=============================================================================== class Game_Battler #-------------------------------------------------------------------------- # Public Instance Variables #-------------------------------------------------------------------------- attr_accessor :morale #-------------------------------------------------------------------------- # alias initialize #-------------------------------------------------------------------------- alias initialize_bsm initialize unless $@ def initialize initialize_bsm @morale = YE::BATTLE::STAT::MORALE_DEFAULT end #-------------------------------------------------------------------------- # return morale #-------------------------------------------------------------------------- def morale @morale = YE::BATTLE::STAT::MORALE_DEFAULT if @morale == nil @morale = [@morale, self.max_morale].min @morale = [@morale, self.min_morale].max return @morale end #-------------------------------------------------------------------------- # return max morale #-------------------------------------------------------------------------- def max_morale if self.actor? n = YE::BATTLE::STAT::MORALE_BASE_MAXIMUM n += YE::BATTLE::STAT::MORALE_MAX_PER_LEVEL * self.level else n = self.enemy.max_morale end for state in self.states do n *= state.max_morale_per / 100.0 end for state in self.states do n += state.max_morale_set end return Integer(n) end #-------------------------------------------------------------------------- # return min morale #-------------------------------------------------------------------------- def min_morale if self.actor? n = YE::BATTLE::STAT::MORALE_BASE_MINIMUM n += YE::BATTLE::STAT::MORALE_MIN_PER_LEVEL * self.level else n = self.enemy.min_morale end for state in self.states do n *= state.min_morale_per / 100.0 end for state in self.states do n += state.min_morale_set end return Integer(n) end #-------------------------------------------------------------------------- # morale= #-------------------------------------------------------------------------- def morale=(newvalue) hp_per = (self.maxhp == 0) ? 0 : self.hp * 100.0 / self.maxhp mp_per = (self.maxmp == 0) ? 0 : self.mp * 100.0 / self.maxmp @morale = newvalue @morale = [@morale, self.max_morale].min @morale = [@morale, self.min_morale].max self.hp = Integer(hp_per * self.maxhp / 100.0) self.mp = Integer(mp_per * self.maxmp / 100.0) end #-------------------------------------------------------------------------- # boost morale #-------------------------------------------------------------------------- def boost_morale(newvalue) self.morale += newvalue end #-------------------------------------------------------------------------- # perform morale decay #-------------------------------------------------------------------------- def perform_morale_decay if self.morale > 0 self.morale -= YE::BATTLE::STAT::MORALE_DECAY_UPPER self.morale = [self.morale, 0].max elsif self.morale < 0 self.morale -= YE::BATTLE::STAT::MORALE_DECAY_LOWER self.morale = [self.morale, 0].min end end #-------------------------------------------------------------------------- # perform morale decay after battle #-------------------------------------------------------------------------- def perform_morale_decay_after_battle if self.morale > 0 self.morale -= YE::BATTLE::STAT::MORALE_AFTER_BATTLE_UPPER self.morale = [self.morale, 0].max elsif self.morale < 0 self.morale -= YE::BATTLE::STAT::MORALE_AFTER_BATTLE_LOWER self.morale = [self.morale, 0].min end end #-------------------------------------------------------------------------- # morale execute damage #-------------------------------------------------------------------------- def morale_execute_damage(attacker) return unless attacker.is_a?(Game_Battler) #--- if @hp_damage > 0 attacker.boost_morale(YE::BATTLE::STAT::MORALE_UPON_HITTING) self.boost_morale(YE::BATTLE::STAT::MORALE_UPON_ATTACKED) perval0 = @hp_damage * 100.0 / self.maxhp perval1 = Integer(perval0 * YE::BATTLE::STAT::MORALE_PER_DAMAGER) perval2 = Integer(perval0 * YE::BATTLE::STAT::MORALE_PER_DAMAGED) attacker.boost_morale(perval1) self.boost_morale(perval2) elsif @hp_damage < 0 attacker.boost_morale(YE::BATTLE::STAT::MORALE_UPON_HEALER) self.boost_morale(YE::BATTLE::STAT::MORALE_UPON_HEALED) perval0 = @hp_damage * 100.0 / self.maxhp perval1 = Integer(perval0 * YE::BATTLE::STAT::MORALE_PER_HEALER) perval2 = Integer(perval0 * YE::BATTLE::STAT::MORALE_PER_HEALED) attacker.boost_morale(perval1) self.boost_morale(perval2) end #--- if @absorbed attacker.boost_morale(YE::BATTLE::STAT::MORALE_UPON_DRAINER) self.boost_morale(YE::BATTLE::STAT::MORALE_UPON_DRAINED) perval0 = @hp_damage * 100.0 / self.maxhp perval1 = Integer(perval0 * YE::BATTLE::STAT::MORALE_PER_DRAINER) perval2 = Integer(perval0 * YE::BATTLE::STAT::MORALE_PER_DRAINED) attacker.boost_morale(perval1) self.boost_morale(perval2) end #--- end #-------------------------------------------------------------------------- # alias maxhp #-------------------------------------------------------------------------- alias maxhp_bsm maxhp unless $@ def maxhp n = maxhp_bsm boost = YE::BATTLE::STAT::MORALE_MAXHP * self.morale n *= (100.0 + boost) / 100.0 n = [[Integer(n), 1].max, maxhp_limit].min @hp = n if @hp > n return n end #-------------------------------------------------------------------------- # alias maxmp #-------------------------------------------------------------------------- alias maxmp_bsm maxmp unless $@ def maxmp n = maxmp_bsm boost = Integer(YE::BATTLE::STAT::MORALE_MAXMP * self.morale) n *= (100.0 + boost) / 100.0 limit = (defined?(maxmp_limit) ? maxmp_limit : 9999) n = [[Integer(n), 0].max, limit].min @mp = n if @mp > n return n end #-------------------------------------------------------------------------- # alias attack #-------------------------------------------------------------------------- alias atk_bsm atk unless $@ def atk n = atk_bsm boost = Integer(YE::BATTLE::STAT::MORALE_ATK * self.morale) n *= (100.0 + boost) / 100.0 limit = (defined?(parameter_limit) ? parameter_limit : 999) n = [[Integer(n), 1].max, limit].min return n end #-------------------------------------------------------------------------- # alias defense #-------------------------------------------------------------------------- alias def_bsm def unless $@ def def n = def_bsm boost = Integer(YE::BATTLE::STAT::MORALE_DEF * self.morale) n *= (100.0 + boost) / 100.0 limit = (defined?(parameter_limit) ? parameter_limit : 999) n = [[Integer(n), 1].max, limit].min return n end #-------------------------------------------------------------------------- # alias spirit #-------------------------------------------------------------------------- alias spi_bsm spi unless $@ def spi n = spi_bsm boost = Integer(YE::BATTLE::STAT::MORALE_SPI * self.morale) n *= (100.0 + boost) / 100.0 limit = (defined?(parameter_limit) ? parameter_limit : 999) n = [[Integer(n), 1].max, limit].min return n end #-------------------------------------------------------------------------- # alias agility #-------------------------------------------------------------------------- alias agi_bsm agi unless $@ def agi n = agi_bsm boost = Integer(YE::BATTLE::STAT::MORALE_AGI * self.morale) n *= (100.0 + boost) / 100.0 limit = (defined?(parameter_limit) ? parameter_limit : 999) n = [[Integer(n), 1].max, limit].min return n end #-------------------------------------------------------------------------- # alias execute_damage #-------------------------------------------------------------------------- alias execute_damage_bsm execute_damage unless $@ def execute_damage(user) execute_damage_bsm(user) self.morale_execute_damage(user) end unless $imported["CustomSkillEffects"] #-------------------------------------------------------------------------- # alias skill can use? #-------------------------------------------------------------------------- alias skill_can_use_bsm skill_can_use? unless $@ def skill_can_use?(skill) if skill.requires_morale if skill.required_morale >= 0 return false if skill.required_morale > self.morale elsif skill.required_morale < 0 return false if skill.required_morale < self.morale end end return skill_can_use_bsm(skill) end end #-------------------------------------------------------------------------- # alias slip damage effect #-------------------------------------------------------------------------- alias slip_damage_effect_bsm slip_damage_effect unless $@ def slip_damage_effect self.perform_morale_decay slip_damage_effect_bsm end end #=============================================================================== # Game_Actor #=============================================================================== class Game_Actor < Game_Battler #-------------------------------------------------------------------------- # alias perform collapse #-------------------------------------------------------------------------- alias perform_collapse_actor_bsm perform_collapse unless $@ def perform_collapse if $game_temp.in_battle and dead? self.boost_morale(YE::BATTLE::STAT::MORALE_UPON_DEATH) for member in $game_troop.existing_members member.boost_morale(YE::BATTLE::STAT::MORALE_UPON_KILL) end end perform_collapse_actor_bsm end #-------------------------------------------------------------------------- # alias hit #-------------------------------------------------------------------------- alias hit_bsm hit unless $@ def hit n = hit_bsm boost = YE::BATTLE::STAT::MORALE_HIT * self.morale n += boost limit = YE::REGEXP::STATE::HECOLIMIT n = [[Integer(n), 0].max, limit].min return n end #-------------------------------------------------------------------------- # alias eva #-------------------------------------------------------------------------- alias eva_bsm eva unless $@ def eva n = eva_bsm boost = YE::BATTLE::STAT::MORALE_EVA * self.morale n += boost limit = YE::REGEXP::STATE::HECOLIMIT n = [[Integer(n), 0].max, limit].min return n end #-------------------------------------------------------------------------- # alias cri #-------------------------------------------------------------------------- alias cri_bsm cri unless $@ def cri n = cri_bsm boost = YE::BATTLE::STAT::MORALE_CRI * self.morale n += boost limit = YE::REGEXP::STATE::HECOLIMIT n = [[Integer(n), 0].max, limit].min return n end #-------------------------------------------------------------------------- # alias odds #-------------------------------------------------------------------------- alias odds_bsm odds unless $@ def odds n = odds_bsm boost = YE::BATTLE::STAT::MORALE_ODDS * self.morale n += boost limit = YE::REGEXP::STATE::HECOLIMIT n = [[Integer(n), 1].max, limit].min return n end end #=============================================================================== # Game_Enemy #=============================================================================== class Game_Enemy < Game_Battler #-------------------------------------------------------------------------- # alias perform collapse #-------------------------------------------------------------------------- alias perform_collapse_enemy_bsm perform_collapse unless $@ def perform_collapse if $game_temp.in_battle and dead? self.boost_morale(YE::BATTLE::STAT::MORALE_UPON_DEATH) for member in $game_party.existing_members member.boost_morale(self.enemy.kill_morale) end end perform_collapse_enemy_bsm end #-------------------------------------------------------------------------- # alias hit #-------------------------------------------------------------------------- alias hit_bsm hit unless $@ def hit n = hit_bsm boost = YE::BATTLE::STAT::MORALE_HIT * self.morale n += boost limit = YE::REGEXP::STATE::HECOLIMIT n = [[Integer(n), 0].max, limit].min return n end #-------------------------------------------------------------------------- # alias eva #-------------------------------------------------------------------------- alias eva_bsm eva unless $@ def eva n = eva_bsm boost = YE::BATTLE::STAT::MORALE_EVA * self.morale n += boost limit = YE::REGEXP::STATE::HECOLIMIT n = [[Integer(n), 0].max, limit].min return n end #-------------------------------------------------------------------------- # alias cri #-------------------------------------------------------------------------- alias cri_bsm cri unless $@ def cri n = cri_bsm boost = YE::BATTLE::STAT::MORALE_CRI * self.morale n += boost limit = YE::REGEXP::STATE::HECOLIMIT n = [[Integer(n), 0].max, limit].min return n end #-------------------------------------------------------------------------- # alias odds #-------------------------------------------------------------------------- alias odds_bsm odds unless $@ def odds n = odds_bsm boost = YE::BATTLE::STAT::MORALE_ODDS * self.morale n += boost limit = YE::REGEXP::STATE::HECOLIMIT n = [[Integer(n), 1].max, limit].min return n end end #=============================================================================== # Scene Battle #=============================================================================== class Scene_Battle < Scene_Base #-------------------------------------------------------------------------- # alias process_battle_start #-------------------------------------------------------------------------- alias process_battle_start_bsm process_battle_start unless $@ def process_battle_start process_battle_start_bsm for member in $game_troop.members member.morale = YE::BATTLE::STAT::MORALE_DEFAULT end end #-------------------------------------------------------------------------- # alias battle_end #-------------------------------------------------------------------------- alias battle_end_bsm battle_end unless $@ def battle_end(result) for member in $game_party.members if YE::BATTLE::STAT::MORALE_RESET member.morale = YE::BATTLE::STAT::MORALE_DEFAULT else member.perform_morale_decay_after_battle end end battle_end_bsm(result) end #-------------------------------------------------------------------------- # alias execute_action_skill #-------------------------------------------------------------------------- alias execute_action_skill_bsm execute_action_skill unless $@ def execute_action_skill skill = @active_battler.action.skill targets = @active_battler.action.make_targets @active_battler.boost_morale(skill.change_morale) for target in targets target.boost_morale(skill.boost_morale) unless target.dead? end execute_action_skill_bsm end end #=============================================================================== # # END OF FILE # #===============================================================================