bgillisp

Battle Control Script

May 24th, 2015
89
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Battle Control Script, Version 0.3
  2. # Released 8/4/2015
  3. # Author: bgillisp
  4.  
  5. # Description:
  6.  
  7. # The first of my planned battle system scripts, this script gives the designer
  8. # better control over how many of the little things are calculated inside the
  9. # engine
  10. #
  11. # Current Features:
  12. #
  13. # -Can add a state that makes the target always do the minimum possible
  14. # damage (like the curse spell in some games).
  15. # -Can add a state that makes the target always do the maximum possible
  16. # damage (like the bless spell in some games).
  17. # -Can add a notetag to a skill or item which increases or decreases the
  18. # to hit chance of a physical or magical attack by x%.
  19. # -Can add a notetag to a skill or item which makes the skill or item
  20. # always do at least x damage, or at most x damage
  21. # -Can set a global max or min in the editible region, which can be
  22. # overridden on a skill by skill basis.
  23.  
  24. # -Can change the global value for critical damage
  25. # -Can set states which increase or decrease critical damage done
  26. # -Can set equipment which increase or decrease critical damage done
  27. # -Can make enemies do increased or decreased critical damage
  28. # -Can set up complex formulas which increase your critical hit damage
  29. # by a stat, current HP, MP, TP, or a combination of the four!
  30.  
  31. # Planned features:
  32. # -Ability to add states which dampen or stretch the variance.
  33. # -Ability to make a skill use a normal distribution curve for computing
  34. # damage. This will allow you to still have the possibility of a high
  35. # power hit, but it would be rarer than it is now.
  36.  
  37. # Overwtitten Methods:
  38. # make_damage_value, from class Game_Battler.
  39. # item_hit, from class Game_Battler.
  40. # Aliased Methods: None
  41.  
  42. # To use: Place the script in your materials section, but above main.
  43. # ***Important*** This script must go *above* any script that aliases
  44. # the make_damage_value function and the item)hit function. It is highly
  45. # advised for that reason that you put this script *first* in your script
  46. # list. If that is not possible, put this script above your battle system
  47. # scripts.
  48.  
  49. # Compatibility issues: Must go above any battle system scripts, or the
  50. # battle system will fail to work. Must go above my HP Barrier script,
  51. # else the HP Barrier script will not work.
  52.  
  53. # Requires some editing to work with Yanfly's Battle Engine. Patch will be
  54. # posted for that engine once finished (no ETA at the moment). I cannot
  55. # provide support for other battle engines though as I don't have them set
  56. # up on my system. However, you do have my permission to find someone else
  57. # to edit this script so it works with the other battle systems.
  58.  
  59. # Terms of use: Free for use for commercial and non-commercial games, with
  60. # credit given.
  61.  
  62. #-------------------------------------------------------------------------
  63. # Editable Region
  64.  
  65.  
  66. module BG_Battle_Control_Script
  67. #Set the state which, if applied, the attacker always does minimum damage
  68. BG_Variance_Min = 26
  69.  
  70. #Set the state which, if applied, the attacker always does max damage
  71. BG_Variance_Max = 27
  72.  
  73. #Set here the states which will change the variance. Seperate each state
  74. #by a comma
  75. BG_Variance_Change = [ #Opening [, do not delete
  76. [28, 0.5], #State 28 will reduce the variance by 50%, or cut it in half.
  77. [29, 2.0], #State 29 will double the variance.
  78. #Insert your states here, or replace the ones above
  79. ] #Do not delete this!
  80.  
  81. #Set here the highest the variance is to ever be.
  82. #Waring: Values more than 1.00 can resulit in an attack doing negative damage!
  83. BG_Variance_Max = 1.00
  84.  
  85.  
  86.  
  87. #Set to the lowest damage you want any skill to be able to do, without a
  88. #notetag, before resistances are calculated
  89. BG_Minimum_Damage = 1
  90.  
  91. #Set to the highest damage you want any skill to be able to do, without a
  92. #notetag, before resistances are calculated
  93. BG_Maximum_Damage = 9999
  94.  
  95.  
  96.  
  97. #Set the states that can raise or lower critical hit damage done by the
  98. #one inflicted with the state
  99. #Format: Everything is entered in an array, inside of an array. To add a state,
  100. #the format is [x, y], where x is the id of the state, and y is the percent
  101. #the state increases (or decreases) your critical damage by.
  102.  
  103. BG_Critical_Damage_Given_States = [ #Opening [, do not delete
  104. [30, 0.25 ], #State 30 adds 25% to critical damage done
  105. [31, -0.25], #State 31 removes 25% to critical damage done.
  106. #Insert your states here, or replace the ones above.
  107. ] #Do not delete this!
  108.  
  109. BG_Critical_Damage_Received_States = [ #opening [, do not remove
  110. [32, 0.25], #State 32 increases critical damage taken by 25%.
  111. [33, -0.25], #State 33 reduces critical damage taken by 25%.
  112. #insert your states here, or replace the ones above.
  113. ] #Do not delete this!
  114.  
  115.  
  116. #Set to the default critical hit percent you wish the game to use.
  117. #The script uses 2.0 by default, though the default engine uses 3.0
  118. BG_Default_Critical_Value = 2.0
  119.  
  120. #Set to true to turn on the advanced critical hit damage features below
  121. BG_Critial_Features_On = false
  122.  
  123.  
  124.  
  125. ###### Advanced Features for Critical Hit. Use with caution!!!! ####
  126. # ***Disabled by default*** #
  127. ########################################################################
  128.  
  129. #Set here the amount critical damage is to increase, based on a stat
  130. #Set to 0.00 to disable
  131. BG_Critical_Boost_Value = 0.00
  132.  
  133. #Amount current HP boosts your critical damage by. Using this would mean that
  134. #wounded monsters do less damage on a critical hit. Set to 0.00 to disable
  135. BG_Critical_HP_Boost = 0.00
  136.  
  137. #Amount current MP boosts your crtiical damage by. Set to 0.00 to disable
  138. BG_Critical_MP_Boost = 0.00
  139.  
  140. #Amount current TP boosts your critical damage by. Set to 0.00 to disable
  141. BG_Critial_TP_Boost = 0.00
  142.  
  143. #Set here the max of the critical boost, from stats, HP, MP and TP
  144. #Default is 1.0, for 100% boost.
  145. BG_Critical_Boost_Max = 1.0
  146.  
  147. #Set here the number corresponding to the param that you wish to boose
  148. #the critical damage. Currently, it is set to param 7, which is LUK.
  149. #Key:
  150. # 0 = MHP
  151. # 1 = MMP
  152. # 2 = ATK
  153. # 3 = DEF
  154. # 4 = MAT
  155. # 5 = MDF
  156. # 6 = AGL
  157. # 7 = LUK
  158. # 8 onward will crash the game, as those params do not exist without a custom
  159. # script to add them.
  160. BG_Critical_Boost_Stat = 7
  161.  
  162. end
  163.  
  164. #End of Editable Region
  165. #---------------------------------------------------------------------------
  166.  
  167. #Do not edit anything below here unless you know what you are doing. Failure to
  168. #follow these directions may result in your game crashing or doing unpredictable
  169. #things. I am not responsible for any damage which results if you decide to edit
  170. #things below this line
  171. #------------------------------------------------------------------------------
  172.  
  173. module DataManager
  174.  
  175. #--------------------------------------------------------------------------
  176. # alias method: load_database
  177. #--------------------------------------------------------------------------
  178. class <<self; alias load_database_bg_variancecontrol_load_database load_database; end
  179. def self.load_database
  180. load_database_bg_variancecontrol_load_database
  181. load_notetags_bg_variancecontrol
  182. end
  183.  
  184. #--------------------------------------------------------------------------
  185. # new method: load_notetags_bg_bpbarrier
  186. #--------------------------------------------------------------------------
  187. def self. load_notetags_bg_variancecontrol
  188. groups = [$data_actors, $data_classes, $data_weapons, $data_armors,
  189. $data_enemies, $data_states, $data_skills, $data_items]
  190. for group in groups
  191. for obj in group
  192. next if obj.nil?
  193. obj.load_notetags_bg_variancecontrol
  194. end
  195. end
  196. end
  197.  
  198. end # End moudle DataManager
  199.  
  200. #Code to load the notetags and store it in a state
  201. class RPG::BaseItem
  202.  
  203. #Define all variables needed for notetag loading here
  204. attr_accessor :to_hit_modify
  205. attr_accessor :skill_max
  206. attr_accessor :skill_min
  207. attr_accessor :critical_value
  208.  
  209. #Used in equips and enemies only, this is the amount to add or subtract
  210. #to the critical damage done.
  211. attr_accessor :critical_modify
  212.  
  213. #Used for actors and enemies only, this overrides the default value to multiply
  214. #the damage by when a critical hit occurs.
  215. attr_accessor :hhhhh
  216.  
  217. def load_notetags_bg_variancecontrol
  218.  
  219. #Initialize all variables. This should avoid any of them being nil
  220. @to_hit_modify = 0.0
  221. @critical_value = 0.0
  222. @critical_modify = 0.0
  223. @skill_max = BG_Battle_Control_Script::BG_Maximum_Damage
  224. @skill_min = BG_Battle_Control_Script::BG_Minimum_Damage
  225.  
  226. @store = self.note[/(?<=<To_Hit_Modify: ).*?(?=[>])/].to_f
  227. if(@store != nil && @store != 0)
  228. @to_hit_modify = @store
  229. end
  230.  
  231. @store = self.note[/(?<=<Critical_Value: ).*?(?=[>])/].to_f
  232. if(@store != nil && @store > 1)
  233. @critical_value = @store
  234. end
  235.  
  236. @store = self.note[/(?<=<Critical_Modify: ).*?(?=[>])/].to_f
  237. if(@store != nil && @store != 0)
  238. @critical_modify = @store
  239. end
  240.  
  241. @store = self.note[/(?<=<Skill_Max: ).*?(?=[>])/].to_f
  242. if(@store != nil && @store > 0)
  243. @skill_max = @store.to_i
  244. end
  245.  
  246. @store = self.note[/(?<=<Skill_Min: ).*?(?=[>])/].to_f
  247. if(@store != nil && @store > 0)
  248. @skill_min = @store.to_i
  249. end
  250.  
  251. #Error catch. If you ever set the min > max, it will set them equal to each
  252. #other
  253. if(@skill_min > @skill_max)
  254. @skill_min = @skill_max
  255. end
  256.  
  257. end #End load_notetags
  258.  
  259.  
  260. end #End class RPG::BaseItem
  261.  
  262.  
  263. class Game_Battler < Game_BattlerBase
  264.  
  265.  
  266. #Overwrite method, make_damage_value
  267. def make_damage_value(user, item)
  268. value = item.damage.eval(user, self, $game_variables)
  269.  
  270. #Set the damage to the minimum allowed by the skill now, if it is not healing
  271. if(value < item.skill_min && !item.damage.recover?)
  272. value = item.skill_min
  273. end
  274.  
  275. #Set the minimum for healing skills now
  276. if(value > -item.skill_min && item.damage.recover?)
  277. value = -item.skill_min
  278. end
  279.  
  280. #Set the damage to the maximum allowed by the skill now.
  281. if(value > item.skill_max && item.skill_max > 0 && !item.damage.recover?)
  282. value = item.skill_max
  283. end
  284.  
  285. #Set the maximum for healing skills now
  286. if(value < -item.skill_max && item.skill_max > 0 && item.damage.recover?)
  287. value = -item.skill_max
  288. end
  289.  
  290. value *= item_element_rate(user, item)
  291. value *= pdr if item.physical?
  292. value *= mdr if item.magical?
  293. value *= rec if item.damage.recover?
  294.  
  295. #Changes to the critical hit system are here. Copy/paste the appropriate
  296. #code as needed.
  297.  
  298. ########### Begin changes to the critical hit system
  299.  
  300. #Save the old value, before first calculation is done.
  301. oldvalue = value
  302.  
  303. #Check for critical hit
  304. if(@result.critical)
  305.  
  306. msgbox_p(user.actor.class_id)
  307.  
  308. #Check if the skill or item has a special critical value. If so, use it.
  309. #If not, call the default.
  310. if(item.critical_value > 1)
  311. value *= item.critical_value
  312. else
  313. value = apply_critical(value)
  314. end #End code for calculating the critical hit value.
  315.  
  316. #Check to see if we need to add to the boost (or take away from it), based
  317. #on user equips
  318.  
  319. #Check if an actor is the user
  320. if(user.actor?)
  321. for equip in user.equips
  322. next if equip.nil?
  323. value += oldvalue * equip.critical_modify
  324. end #End for loop
  325. end
  326.  
  327. #Check if the enemy has a modification to their critical damage
  328. if(user.enemy?)
  329. value += oldvalue * user.enemy.critical_modify
  330. end
  331.  
  332. #Check now to see if the user has a state which raises or lowers the
  333. #amount of critical damage they do
  334. for states in BG_Battle_Control_Script::BG_Critical_Damage_Given_States
  335. if(user.state?(states[0]))
  336. value += oldvalue * states[1]
  337. end
  338. end
  339.  
  340. #Finally, check to see if the target has a state which reduces critical
  341. #damage taken.
  342. for states in BG_Battle_Control_Script::BG_Critical_Damage_Received_States
  343. if(self.state?(states[0]))
  344. value += oldvalue * states[1]
  345. end
  346. end
  347.  
  348. #Check to see if the boost took us below normal damage. If so, reset
  349. #the damage to the lowest allowed critical hit value, which is 1 more
  350. #than standard damage.
  351. if(value < oldvalue)
  352. value = oldvalue + 1
  353. end
  354.  
  355. #If optional features to boost critical damage based on stats is turned on,
  356. #apply the boost here
  357. if(BG_Battle_Control_Script::BG_Critial_Features_On == true)
  358.  
  359. #Initial boost calculation, based on the boost stat
  360. boostvalue = oldvalue * BG_Battle_Control_Script::BG_Critical_Boost_Value * user.param(BG_Battle_Control_Script::BG_Critical_Boost_Stat)
  361.  
  362. #Next, calculate the boost, based on current HP
  363. boostvalue += oldvalue * BG_Battle_Control_Script::BG_Critical_HP_Boost * user.hp
  364.  
  365. #Next, calculate the boost, based on current MP
  366. boostvalue += oldvalue * BG_Battle_Control_Script::BG_Critical_MP_Boost * user.mp
  367.  
  368. #Finally, calculate the boost, based on user's current TP.
  369. boostvalue += oldvalue * BG_Battle_Control_Script::BG_Critial_TP_Boost * user.tp
  370.  
  371. #Check to see if it is too high, based on the max
  372. if(boostvalue >= BG_Battle_Control_Script::BG_Critical_Boost_Max * oldvalue)
  373. boostvalue = BG_Battle_Control_Script::BG_Critical_Boost_Max * oldvalue
  374. end #End check to see if boost is too large
  375.  
  376. #Check to see if the boost is worse than doing no critical hit at all
  377. if( (value + boostvalue) < (value - oldvalue) )
  378.  
  379. #If we are here, the boost was worse than standard damage. Reset the
  380. #damage back to the old value, and set the boost to 0.
  381. value = oldvalue + 1
  382. boostvalue = 0
  383.  
  384. end #End check
  385.  
  386. #Add in the amount of the boost now
  387. value += boostvalue
  388.  
  389. end #End if statement for optional boost features
  390.  
  391. end #End check for critical hit.
  392.  
  393.  
  394. ########### End changes to the critical hit system################
  395.  
  396. #Changes to the variance calculation are here. If you wish to apply these
  397. #to a different battle system comment out the line apply_variance, then
  398. #copy and paste these lines in its place.
  399.  
  400.  
  401. ########### Begin changes to the variance system here ############
  402.  
  403. #Compute the HP value of the variance
  404. amp = [value.abs * item.damage.variance / 100, 0].max.to_i
  405.  
  406. #Debug line, uncommment if you wish to see the HP value of the variance
  407. #msgbox_p(amp)
  408.  
  409. #If we are to do the minimum damage, apply the variance now.
  410. if user.state?(BG_Battle_Control_Script::BG_Variance_Min)
  411. var = -amp
  412. elsif user.state?(BG_Battle_Control_Script::BG_Variance_Max)
  413. var = amp
  414. else
  415. #Calculate the value of the variance normally
  416. var = rand(amp + 1) + rand(amp + 1) - amp
  417. end
  418.  
  419. #Apply the variance
  420. if(value >=0)
  421. value += var
  422. else
  423. value -= var
  424. end
  425.  
  426. #End modified code. The rest of this is the same as the default battle
  427. #Engine
  428.  
  429. value = apply_guard(value)
  430. @result.make_damage(value.to_i, item)
  431. end
  432.  
  433. #Changes to how to_hit is calculated. Now, it checks to see if there is a
  434. #notetag on an item to add a boost (or penalty) to the to hit for a physical
  435. #attack.
  436. def item_hit(user, item)
  437. rate = (item.success_rate * 0.01) # Get success rate
  438.  
  439. #To add this to another battle system, replace the check if item_physical
  440. #with this code, up to the *** part below
  441. if item.physical?
  442. rate *= user.hit # Physical attack: Multiply hit rate
  443.  
  444. #If bonus or penalty to hit is defined, add it into the rate.
  445. if(item.to_hit_modify != nil)
  446. rate += item.to_hit_modify
  447. end
  448. end #End if item.physical?
  449.  
  450. if item.magical?
  451.  
  452. #If bonus or penalty to hit is defined, add it onto the rate, which is
  453. #1.0, or 100%, by default.
  454. if(item.to_hit_modify != nil)
  455. rate += item.to_hit_modify
  456. end
  457.  
  458. end #End if item.magical?
  459.  
  460. #******End of edits to item_hit, rest is the default code###
  461.  
  462. return rate # Return calculated hit rate
  463. end
  464.  
  465. #Does a random damage between the min and max. Best used directly in the
  466. #damage formula
  467. def uniform_damage(min, max)
  468.  
  469. #Compute the range of the numbers
  470. roll = (max - min).to_i
  471.  
  472. #Safety check, make sure the number is at least 1
  473. if(roll < 0)
  474. roll = 1
  475. end
  476.  
  477. #Compute the random number
  478. udvalue = rand(roll) + 1 + min
  479.  
  480. return udvalue
  481.  
  482. end
  483.  
  484. #Overwritten method, apply_critical
  485. def apply_critical(damage)
  486. damage * BG_Battle_Control_Script::BG_Default_Critical_Value
  487. end #End apply_critical
  488.  
  489.  
  490. end #End Game_Battler
RAW Paste Data