Advertisement
TheSixth

Custom Parameters by Sixth

Apr 20th, 2016
2,853
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 56.62 KB | None | 0 0
  1. #===============================================================================
  2. # * [ACE] Custom Parameters
  3. #===============================================================================
  4. # * Made by: Sixth (www.rpgmakervxace.net, www.forums.rpgmakerweb.com)
  5. # * Version: 1.5
  6. # * Updated: 22/04/2018
  7. # * Requires: -----------
  8. #-------------------------------------------------------------------------------
  9. # * < Change Log >
  10. #-------------------------------------------------------------------------------
  11. # * Version 1.0 (21/04/2016)
  12. #   - Initial release.
  13. # * Version 1.1 (22/04/2016)
  14. #   - Changed the manually added bonus (with script calls) for multiplier
  15. #     parameters. Instead of them being an additive bonus, they are now
  16. #     multiplier bonuses as well.
  17. #   - Added the ability to get the value of a parameter from a custom method
  18. #     with or without arguments.
  19. # * Version 1.2 (22/04/2016)
  20. #   - Added shortened methods for getting the custom parameter values.
  21. #     For example: actor.vit, enemy.sta, and so on.
  22. #   - Added shortened methods for getting the custom parameter names.
  23. #     For example: Vocab.cdr, Vocab.cdr_a, Vocab.cparam("spi"), and so on.
  24. #   - Changed the name of the default (non-shortened) methods, so make sure
  25. #     to check the description of the script calls again if you use those!
  26. #     Basically, "custom_prm" is changed to "cparam" in all old script calls!
  27. # * Version 1.3 (24/04/2016)
  28. #   - The minimum and maximum values can be manipulated with note-tags and
  29. #     script calls as well from now on, so you can make "Limit Break" equipment,
  30. #     for example, to increase the maximum possible value for a parameter, or
  31. #     make items/events which change the maximum/minimum possible values.
  32. #   - Relocated the place where you need to place your own methods for using the
  33. #     method call note-tags/settings. They are now in the 'CustomParamMethods'
  34. #     module.
  35. #   - Added an optional argument for the 'add_cparam' method. It will let you
  36. #     decide if the value added should be added to the bonus parameter value
  37. #     even if the player reached the minimum/maximum values for that parameter
  38. #     (including actor, equipment, state and class bonuses) or not.
  39. #   - Changed the update settings to be more specific. You can now choose to
  40. #     only update the parameter's actual value, minimum value or maximum value.
  41. #     You can also use new note-tags to specify the update setting for an object
  42. #     specifically, instead of always using a global update setting.
  43. #     Depending on how you use your custom parameters, this might increase
  44. #     performance slightly.
  45. # * Version 1.4 (08/05/2016)
  46. #   - Optimized the update check. Now it reads the note-tag of your database
  47. #     objects only once for that.
  48. # * Version 1.5 (22/04/2018)
  49. #   - Slight optimization.
  50. #-------------------------------------------------------------------------------
  51. # * < Description >
  52. #-------------------------------------------------------------------------------
  53. # * This script will let you make your own custom parameters.
  54. #   These parameters can be whatever you want them to be.
  55. #   You can access the new parameters with the provided script calls.
  56. # * Create simple and static parameters or more complex and dynamic ones!
  57. #   You can use eval formulas and your own custom methods for setting up
  58. #   the values of your new parameters too!
  59. # * Make additive or multiplier parameters!
  60. # * Actors, Classes, Enemies, Equipment and States can all get these custom
  61. #   parameters with simple note-tagging.
  62. # * Increase/decrease your custom parameters with script calls! Permanently!
  63. # * These new parameters won't do anything at all until you make them do
  64. #   something! Use them in your damage formulas, use them in eventing or use
  65. #   them in your own custom scripts!
  66. #-------------------------------------------------------------------------------
  67. # * < Note-Tags >
  68. #-------------------------------------------------------------------------------
  69. # * These note-tags can be used on Actors, Classes, Enemies, Equipment and
  70. #   States! All note-tags are optional!
  71. # * The custom parameter for an Actor or Enemy will start on the default value
  72. #   you have set up in the script's settings. But if you want an actor or enemy
  73. #   to have a different starting value, you can use the provided note-tags to
  74. #   set up a custom starting value for them!
  75. # * If a Class, Equipment or State doesn't have a note-tag for a custom
  76. #   parameter, that parameter will be set to either 0 (in the case of additive
  77. #   parameters) or 1 (in the case of multiplier parameters) for them.
  78. #   If an Actor or Enemy got no note-tag for a custom parameter, that parameter
  79. #   will be set to the default parameter value you have set up in the script.
  80. # * To be very short and simple:
  81. #   - Actor and Enemy note-tags control the starting value of these parameters.
  82. #   - Class, Equipment and State note-tags will be bonuses for these parameters.
  83. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  84. # * To set up a static (non-eval) custom parameter, use this note-tag:
  85. #
  86. #     <cparam: value>
  87. #
  88. #   Hahh! How simple, right? :P
  89. #
  90. #   So, the 'cparam' you see is a key used in the settings of this script. That
  91. #   is the custom parameter's key, and it can be any valid key from the settings
  92. #   of this script.
  93. #
  94. #   The 'value' can be any numeric value including integers and float numbers,
  95. #   and positive or negative values.
  96. #
  97. #   In the case of additive bonuses, these values will be added together for the
  98. #   same custom parameter, and the result will be added to the actor's or
  99. #   enemy's default (starting) parameter value.
  100. #   This is the same behavior like the one that the default parameters
  101. #   (HP, ATK, etc) use.
  102. #
  103. #   In the case of multiplier bonuses, these values will be multiplied with
  104. #   each other for the same custom parameter, and the result will be used to
  105. #   multiply the default (starting) parameter value. In other words, any and all
  106. #   multiplier bonus of the same custom parameter will get multiplied with each
  107. #   other.
  108. #   This is the same behavior like the one that the default s-parameters
  109. #   (GRD, MCR, etc) and the elemental damage rate features use.
  110. #
  111. #   Some examples using the parameters from the sample settings:
  112. #
  113. #     <cdr: 0.25>
  114. #   If this is placed on an Actor or Enemy, this will be the starting value for
  115. #   their CDR (Critical Damage Rate) custom parameter.
  116. #   If this is placed on a Class, Equipment or State, this will be a bonus
  117. #   value, which will be either added to the starting value (in the case of
  118. #   additive parameters) or will multiply the total value of the current custom
  119. #   parameter (in the case of multiplier parameters).
  120. #
  121. #     <cha: -15>
  122. #   Well, same as above, but this will control the CHA (Charisma) custom
  123. #   parameter instead.
  124. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  125. # * To set up a dynamic (eval) custom parameter, use this note-tag:
  126. #  
  127. #     <cparam formula: string>
  128. #
  129. #   This basically works the same way as the static note-tags, but instead of
  130. #   taking a static value, this will evaluate a valid ruby code to determine
  131. #   the real value of the custom parameter.
  132. #
  133. #   The 'string' will be the code which will be evaluated to get the value.
  134. #  
  135. #   NOTE:
  136. #   Unless you set the custom parameter to be updated every time it's value is
  137. #   requested, the formula will be evaluated only once and never again!
  138. #   So, if you want to base a parameter on the value of a variable, for example,
  139. #   you should set up the update feature for that custom parameter in the
  140. #   script's settings or use the update note-tags for your database objects!
  141. #   This is purely for optimization, because most people really don't need
  142. #   formulas for their custom parameters, I guess. It would be a waste of
  143. #   performance to always read the note-tags of all feature objects AND
  144. #   re-evaluate the formula when a custom parameter's value is requested, so
  145. #   I made this extra (and fully optional) setting to avoid the re-readings
  146. #   and re-calculating of note-tag formulas.
  147. #
  148. #   Some examples using the parameters from the sample settings:
  149. #
  150. #     <sta formula: user.agi * 10>
  151. #   This specific note-tag would modify the STA (Stamina) custom parameter.
  152. #   As you can see, it references the user, and that is used to get the owner
  153. #   of the parameter (actor or enemy).
  154. #   So, to get to the point, this will read the owner's current AGI, and would
  155. #   base the owner's STA on that parameter. In short, the owner's base STA would
  156. #   always be 10 times higher than it's AGI, so it would be a dynamic value.
  157. #
  158. #   Like the above example shows, using this function needs at least a minimum
  159. #   amount of coding knowledge in Ruby.
  160. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  161. # * To set up a dynamic or static (based on your custom methods) custom
  162. #   parameter using your own methods, use this note-tag:
  163. #  
  164. #     <cparam method: method_name, arg1, arg2, ...>
  165. #
  166. #   Well, this works similarly as the eval note-tag above, but instead of
  167. #   evaluating a string, this will call the specified method with the specified
  168. #   arguments (if any) you used in the note-tag.
  169. #   This lets you make your own custom methods for your custom parameters as
  170. #   long as you know how to code them in Ruby.
  171. #   NOTE:
  172. #   Mind the spaces used after the commas in the note-tag! They are required!
  173. #  
  174. #   You custom methods must be defined in the 'CustomParamMethods' module!
  175. #   The first argument of any custom method must be the 'user', which will
  176. #   get the actor/enemy the parameter belongs to.
  177. #   The rest of the arguments will be your own arguments if you specify them
  178. #   in your note-tags.
  179. #   If you just use the method name without any arguments in the note-tag, than
  180. #   no additional arguments will be used for the method. In other words, the
  181. #   arguments are optional!
  182. #   Note that all arguments will be passed as strings, so you must convert them
  183. #   to the object type you want to work with inside your own methods!
  184. #
  185. #   Examples using my sample custom methods found in the script:
  186. #
  187. #     <spi method: mp_left, 10, 0.75>
  188. #   This will control the SPI custom parameter.
  189. #   Will call the method named 'mp_left' in the CustomParamMethods module with
  190. #   the mandatory 'user' argument (which gets you the actor/enemy of the
  191. #   parameter), and with the optional arguments specified in the note-tag. The
  192. #   optional arguments are "10" and "0.75".
  193. #   If you check out the sample method named 'mp_left' in the script, you will
  194. #   see that the value returned will be calculated based on the remaining MP
  195. #   of the actor/enemy.
  196. #   The argument "10" will be the minimum value added to the parameter,
  197. #   regardless of the current remaining MP, and the argument "0.75" will be the
  198. #   multiplier used in the MP based calculation, so whatever amount of MP the
  199. #   actor/enemy lost will get multiplied by 0.75, and the result of that plus
  200. #   10 (from the first argument) will be the total parameter value gained.
  201. #   The arguments here let you re-use this note-tag type on many different
  202. #   database items, and it will let you specify different values based on the
  203. #   arguments you use in your note-tags.
  204. #   Conclusion: You can create your own methods AND your own note-tags as well!
  205. #
  206. #     <rge method: hp_left>
  207. #   This modifies the RGE (Rage, fitting name for the stat based on it's value
  208. #   calculation - see below) custom parameter.
  209. #   Similar to the above note-tag, but this one got no optional arguments.
  210. #   If you check out the method named 'hp_left' in the script below, you will
  211. #   see that the parameter value gained will depend on the remaining HP of the
  212. #   actor/enemy. The remaining HP will get multiplied by 2, and that will be the
  213. #   actual value gained. Pretty simple method, yet perfect for this stat, right?
  214. #
  215. #   NOTE:
  216. #   Just like with the formula (eval) note-tags, if you want the parameter to
  217. #   be updated every time it is requested, set up it's update settings!
  218. #   If you don't do it, it will only be calculated once and never more!
  219. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  220. # * To set up custom maximum or minimum value limits or bonuses for your
  221. #   parameters, use these note-tags:
  222. #
  223. #   - Static note-tags:
  224. #
  225. #     <cparam max: value>  # For modifying the maximum parameter values.
  226. #     <cparam min: value>  # For modifying the minimum parameter values.
  227. #
  228. #   - Eval formula note-tags:
  229. #
  230. #     <cparam max formula: string>
  231. #     <cparam min formula: string>
  232. #
  233. #   - Custom method call note-tags:
  234. #
  235. #     <cparam max method: method_name, arg1, arg2, ...>
  236. #     <cparam min method: method_name, arg1, arg2, ...>
  237. #
  238. #   The static note-tags only accept integers or float numbers as values!
  239. #   The formula note-tags will read the entered string, evaluate it as a Ruby
  240. #   code and will use the returned value.
  241. #   The custom method call note-tags will get the method name from the note-tag,
  242. #   run that method (which must be in the 'CustomParamMethods' module!), and
  243. #   will use the returned value.
  244. #  
  245. #   If these note-tags are set on an Actor or Enemy, these will decide the base
  246. #   minimum/maximum values the parameter can get.
  247. #   If these note-tags are on a Class, Equipment or State, the value will be
  248. #   added to the base minimum/maximum values, effectively raising or lowering
  249. #   them. Can be used to make "Limit Break" equipment and such things.
  250. #
  251. #   NOTE:
  252. #   Remember to set up your update settings for the parameters/objects which use
  253. #   a formula or a custom method for their values!
  254. #
  255. #   Examples:
  256. #
  257. #     <cdr max: 0.5>
  258. #   If this is on an Actor or Enemy, it will set the maximum possible value for
  259. #   the CDR parameter to be 0.5 for the actor/enemy.
  260. #   If this is on a Class, Equipment or State, this will be a bonus value which
  261. #   will be added to the base maximum value for the parameter, so, in this case,
  262. #   the maximum possible value for the parameter will be raised by 0.5.
  263. #
  264. #     <mor min: -75>
  265. #   If this is on an Actor or Enemy, it will set the minimum possible value for
  266. #   the MOR parameter to be -75 for the actor/enemy.
  267. #   If this is on a Class, Equipment or State, this will be a bonus value which
  268. #   will be added to the base minimum value for the parameter, so, in this case,
  269. #   the minimum possible value for the parameter will be lowered by 75.
  270. #
  271. #     <vit max formula: user.hp/10 + user.def/2>
  272. #   Changes the maximum possible value for the VIT parameter.
  273. #   Uses an eval formula for getting the value. This formula will set the
  274. #   maximum limit for VIT to be equal with the user's current HP / 10 plus the
  275. #   user's DEF stat.
  276. #
  277. #     <dex min method: lvl_formula, 0.009, 3, 5, 31>
  278. #   This will change the minimum possible value limit for the DEX parameter.
  279. #   The value will be whatever the method named 'lvl_formula' in the
  280. #   'CustomParamMethods' returns. The note-tag passes the arguments "0.009",
  281. #   "3", "5" and "31" to the method. Based on these numbers and on the user's
  282. #   level, the value will be calculated according to the method.
  283. #   Because this uses the user's level in the method, this can only be used on
  284. #   database objects that can only appear on actors (enemies got no levels)!
  285. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  286. # * To set up the update method for an object specifically, use this note-tag:
  287. #
  288. #     <cparam type update>
  289. #
  290. #   The 'cparam', as always, is a valid key from the parameter settings from the
  291. #   script.
  292. #  
  293. #   Depending on the 'type' you use, different values will be updated:
  294. #   value = Updates the parameter's current value on the database object.
  295. #   max = Updates the parameter's maximum limit on the database object.
  296. #   min = Updates the parameter's minimum limit on the database object.
  297. #
  298. #   Kinda hard to explain this feature, but here is what this actually does:
  299. #
  300. #   If the :update setting for a parameter is omitted for a specific type
  301. #   (value, max or min), you can still update these on your database objects
  302. #   separately if needed. This is, of course, only needed if the database object
  303. #   uses a note-tag for a cparam, cparam max or cparam min value with an eval
  304. #   formula or custom method. If the database object uses a simple static
  305. #   note-tag for these, it got no reason for being updated after it's
  306. #   initialization.
  307. #
  308. #   So, here is a full example for an armor with the following note-tags:
  309. #
  310. #     <cha formula: user.level * 5>
  311. #     <dex: 12>
  312. #     <sta max method: hp_left>
  313. #     <cha value update>
  314. #
  315. #   Lets assume that none of the parameters got any :update settings set up
  316. #   for them in the script...
  317. #
  318. #   Okay, so what happens here?
  319. #   This specific armor gives a lot of stats, namely:
  320. #   The CHA parameter will be raised based on the user's level multiplied by 5.
  321. #   If the user is level 1, it would give +5 CHA, if the user is level 2, it
  322. #   would give +10 CHA, and so on.
  323. #   Because the object got the <cha value update> note-tag, the added bonus will
  324. #   be recalculated every time the CHA parameter is requested in any way, so
  325. #   it can update itself with the user's level.
  326. #   If that note-tag would not be used, whatever level the user was when the
  327. #   CHA parameter was first requested on this armor will be used in all of the
  328. #   calculations after. So, if the user was level 1, it will give +5 CHA always,
  329. #   regardless if the player level up or not. If the user was level 4 when the
  330. #   CHA parameter is requested on the armor, it will always give +20 CHA for any
  331. #   actor who equips it, no matter if the other actors got different levels or
  332. #   not.
  333. #   So, if you want a dynamically calculated value which updates itself when
  334. #   needed, you will need to use the update note-tag on the used object with the
  335. #   specific parameter and parameter value type.
  336. #   Lets move on to the next stat bonus on this armor...
  337. #   DEX will be raised by 12. Just like that, a plain old static bonus. This
  338. #   will never need to be updated, because it will always give +12, no matter
  339. #   who equips it and when.
  340. #   Next, the maximum limit for the STA parameter will change depending on the
  341. #   value that the method named 'hp_left' returns. That method will base it's
  342. #   value on the user's remaining HP, so the less HP the user has, the higher
  343. #   their STA parameter can get. Note that it CAN get higher, but unless the
  344. #   user got enough STA, it will NOT automatically add that much STA, it just
  345. #   raises the limit for that parameter. Kinda like the "Limit Break" feature
  346. #   in the FF series, which raised the damage cap to 99999 instead of 9999.
  347. #   Now, because the armor got no <sta max update> note-tag, the calculation
  348. #   for the maximum STA value bonus will only be run once in your entire game!
  349. #   So, depending on when the player equips the armor, and on how much HP the
  350. #   actor get at that time, the bonus will be based on that actor's HP, and
  351. #   will stay on that value forever, no matter if someone else equips it or if
  352. #   the HP of the user changes or not.
  353. #
  354. #   As a last note, the update note-tags on this armor will only update the
  355. #   specified parameter values on this armor!
  356. #
  357. #   I hope this wall of text cleared up what this note-tag does exactly.
  358. #   If not, though luck, because I don't think that I can explain it any better.
  359. #
  360. #   Here are a few more examples:
  361. #
  362. #     <cdr value update>
  363. #     <spi max update>
  364. #     <mor min update>
  365. #-------------------------------------------------------------------------------
  366. # * < Script Calls >
  367. #-------------------------------------------------------------------------------
  368. # * The following script calls can be used anywhere you want, from an evented
  369. #   script call, or from a custom script, doesn't matter!
  370. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  371. # * To get the current value of the actor's or enemy's custom parameter, you
  372. #   can use this script call:
  373. #
  374. #     actor_object.cparam("cparam")  # For actors.
  375. #     enemy_object.cparam("cparam")  # For enemies.
  376. #
  377. #   From v1.2:
  378. #    
  379. #     actor_object.cparam   # For actors.
  380. #     enemy_object.cparam   # For enemies.
  381. #
  382. #   The 'actor_object' can be any method or variable which returns a valid
  383. #   actor object. The most commonly used are:
  384. #     $game_actors[ID] - To get the actor based on it's database ID.
  385. #     $game_party.members[index] - To get the actor based on it's party index.
  386. #
  387. #   The 'enemy_object' can be any method or variable which returns a valid
  388. #   enemy object. There aren't many ways of getting an enemy object, because
  389. #   they only exist in battles by default, but here is the one which is usable
  390. #   in case you need it:
  391. #     $game_troop.members[index] - To get the enemy based on it's troop index.
  392. #
  393. #   The "cparam" can be any valid custom parameter key from the settings of this
  394. #   script. Obviously, this is used to get the value of the selected parameter.
  395. #
  396. #   Examples:
  397. #
  398. #     $game_actors[2].cparam("vit") # Old method, still usable.
  399. #     $game_actors[2].vit           # New method from v1.2.
  400. #   This would return the VIT (Vitality) custom parameter of Actor 2.
  401. #
  402. #     $game_troop.members[1].cparam("cdr")  # Old method, still usable.
  403. #     $game_troop.members[1].cdr            # New method from v1.2.
  404. #   This would return the CDR (Critical Damage Rate) parameter of the 1st enemy
  405. #   from the current opponents in battle.
  406. #   Note that this is only usable in battles and it's not really useful, I just
  407. #   wanted to make an example for an enemy. :P
  408. #
  409. #   - In the damage formula:
  410. #
  411. #     a.cparam("sta") # Old method, still usable.
  412. #     a.sta           # New method from v1.2.
  413. #   Gets the STA (Stamina) parameter of the user of the skill/item.
  414. #
  415. #     b.cparam("mor") # Old method, still usable.
  416. #     b.mor           # New method from v1.2.
  417. #   Gets the MOR (Morality) parameter of the target of the skill/item.
  418. #
  419. #   - In conditional branches:
  420. #
  421. #   Well, basically the same as the regular script calls, but here you can (and
  422. #   should) compare their values with a specific value.
  423. #   Some examples:
  424. #
  425. #     $game_actors[2].cparam("vit") >= 300  # Old method, still usable.
  426. #     $game_actors[2].vit >= 300            # New method from v1.2.
  427. #   This check returns true if the VIT of Actor 2 is higher than 300.
  428. #
  429. #     $game_actors[2].cparam("mor") > $game_actors[3].cparam("mor")
  430. #     $game_actors[2].mor > $game_actors[3].mor
  431. #   This returns true if the MOR of Actor 2 is higher than the MOR of Actor 3.
  432. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  433. # * To increase/decrease a custom parameter, use this script call:
  434. #
  435. #     actor_object.add_cparam("cparam",value,limit) # Old method, still usable.
  436. #     actor_object.add_cparam(value,limit)          # New method from v1.2.
  437. #  
  438. #   The 'actor_object' is the same as above, so refer to the explanation there.
  439. #  
  440. #   The "cparam" can be any valid custom parameter key from the settings of this
  441. #   script. Obviously, this is used to get the value of the selected parameter.
  442. #
  443. #   And the 'value' will be the value added to the selected parameter.
  444. #   It can be positive and negative, and integer or float number as well!
  445. #
  446. #   The 'limit' argument is an optional one. This decides if the script call
  447. #   will add the value to the parameter even if it reached the minimum/maximum
  448. #   limits or not. If this is set to true, it will NOT add anymore parameter
  449. #   value if it has already reached the minimum/maximum values (including all
  450. #   bonuses from class, equipment and state note-tags)! If this is false, it
  451. #   will keep adding the values regardless if the parameter reached it's
  452. #   minimum/maximum value or not.
  453. #   The default value of this argument is false, if you omit it in your script
  454. #   calls, that value will be used!
  455. #   Another hard thing to explain without examples, so here we go!
  456. #   Suppose the actor has 960 total DEX with all the bonuses. Than the actor
  457. #   equips an armor which increases DEX by 100. The max limit for DEX is 999.
  458. #   So, after equipping the armor, the value of DEX would be capped on 999.
  459. #   Now, the player drinks a weird potion which would increase it's DEX by 5
  460. #   permanently. But DEX is already at it's max value, so what will happen now?
  461. #   If this optional argument is set to true, and the player drinks the potion,
  462. #   the stat gain from that potion will not happen, because the actor's DEX
  463. #   is already at it's max value. Now the actor un-equips this armor, and his
  464. #   DEX would drop back to 960. So, no increase can be seen even after taking
  465. #   off the armor!
  466. #   But if the actor drinks another of these potions, now without the armor,
  467. #   the actor's DEX will indeed be increased by 5, because the total value
  468. #   of DEX is not capped without the armor.
  469. #   Lets see what happens when this optional argument is set to false now...
  470. #   Now the actor has 965 DEX without the armor, and again, 999 with it
  471. #   equipped. So, the actor equips the armor again. He drinks another weird
  472. #   potion, which is seemingly the same, but the script call used for this
  473. #   one is using false for this optional argument. After drinking it, the
  474. #   DEX stays the same, 999 with the armor equipped. Ohh, well, what a bummer,
  475. #   right? But when the armor is unequipped, the player can notice that the
  476. #   value of DEX increased from 965 to 970! So, when this arguments is false,
  477. #   it WILL add the bonus from the script call, even if the parameter's value
  478. #   is capped already. This doesn't mean that the parameter will exceed the
  479. #   maximum allowed values! But if the player unequips some stuffs giving
  480. #   bonuses for the parameter, the increase from the script call will be
  481. #   visible.
  482. #   I hope this clears this up... Phew!
  483. #
  484. #   Examples:
  485. #
  486. #     $game_party.members[0].add_cparam("cha",5) # Old method, still usable.
  487. #     $game_party.members[0].add_cha(5)          # New method from v1.2.
  488. #   Increases CHA by 5 for the party leader.
  489. #
  490. #     $game_actors[4].add_cparam("mor",-12) # Old method, still usable.
  491. #     $game_actors[4].add_mor(-12)          # New method from v1.2.
  492. #   Decreases MOR by 12 for Actor 4.
  493. #
  494. #   NOTE:
  495. #   In the case of additive parameters, these extra bonuses will be simply added
  496. #   to the value of the parameters. Permanently!
  497. #   The starting value of these bonuses is always 0!
  498. #
  499. #   In the case of multiplier parameters, the values you add this way will
  500. #   multiply the existing value of the custom parameter. Again, permanently!
  501. #   The starting value of these bonuses is always 1!
  502. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  503. # * To get the total amount of bonus value of a custom parameter (which you add
  504. #   with the above script call), use this script call:
  505. #
  506. #     actor_object.cparam_bonus("cparam") # Old method, still usable.
  507. #     actor_object.cparam_bonus           # New method from v1.2.
  508. #
  509. #   This will return the total value of bonus custom parameter which you added
  510. #   with the above 'add_cparam' script call.
  511. #  
  512. #   It should be clear what the above script call means by now, so I will
  513. #   jump to the examples right away:
  514. #
  515. #     $game_actors[7].cparam_bonus("cdr") # Old method, still usable.
  516. #     $game_actors[7].cdr_bonus           # New method from v1.2.
  517. #   Gets the total value of bonus CDR Actor 7 has.
  518. #
  519. #     $game_party.members[2].cparam_bonus("vit") # Old method, still usable.
  520. #     $game_party.members[2].vit_bonus           # New method from v1.2.
  521. #   Gets the total value of bonus VIT the 2nd actor in the party has.
  522. #
  523. #   In theory, you can add bonus custom parameters for enemies too, but only in
  524. #   the battle, and once the battle is over, these bonuses will be reset.
  525. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  526. # * To get the maximum/minimum value limits for a parameter, use this script
  527. #   call:
  528. #
  529. #   - For actors:
  530. #
  531. #     actor_object.cparam_max("cparam")
  532. #     actor_object.cparam_max
  533. #     actor_object.cparam_min("cparam")
  534. #     actor_object.cparam_min
  535. #
  536. #   - For enemies (although you most probably won't use this on enemies):
  537. #
  538. #     enemy_object.cparam_max("cparam")
  539. #     enemy_object.cparam_max
  540. #     enemy_object.cparam_min("cparam")
  541. #     enemy_object.cparam_min
  542. #
  543. #   From v1.3, you can manipulate these limits with note-tags and script calls
  544. #   as well, so it might be useful to know the limits of your parameters.
  545. #   Well, it is mostly useful for coding purposes, but who knows, someone might
  546. #   just use it for some eventing and what not...
  547. #
  548. #   Anyway, these will return the total amount of maximum/minimum limits of the
  549. #   parameters.
  550. #
  551. #   Examples:
  552. #
  553. #     $game_actors[1].cparam_max("sta")
  554. #     $game_actors[1].sta_max
  555. #   Both of these will return the maximum limit for the STA parameter for
  556. #   actor 1.
  557. #
  558. #     $game_party.members[3].cparam_min("dex")
  559. #     $game_party.members[3].dex_min
  560. #   Both of these will return the minimum limit for the DEX parameter for
  561. #   the 3rd party member.
  562. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  563. # * To raise or lower the maximum/minimum limits of your parameters, you can
  564. #   use these script calls:
  565. #
  566. #     actor_object.add_cparam_max("cparam",value)
  567. #     actor_object.add_cparam_max(value)
  568. #     actor_object.add_cparam_min("cparam",value)
  569. #     actor_object.add_cparam_min(value)
  570. #
  571. #   These script calls will raise or lower the maximum/minimum limits of your
  572. #   parameters permanently.
  573. #  
  574. #   Examples:
  575. #
  576. #     $game_actors[2].add_cparam_max("rge",35)
  577. #     $game_actors[2].add_rge_max(35)
  578. #   Both of these will raise the maximum limit for the RGE parameter by 35 for
  579. #   actor 2.
  580. #
  581. #     $game_actors[5].add_cparam_min("mor",-50)
  582. #     $game_actors[5].add_mor_min(-50)
  583. #   Both of these will lower the minimum limit for the MOR parameter by 50 for
  584. #   actor 5.
  585. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  586. # * To check the values added for your maximum/minimum limits with the above
  587. #   script call for your parameters, use this script call:
  588. #
  589. #     actor_object.cparam_max_bonus("cparam")
  590. #     actor_object.cparam_max_bonus
  591. #     actor_object.cparam_min_bonus("cparam")
  592. #     actor_object.cparam_min_bonus
  593. #
  594. #   These will get the values added with the 'add_cparam_max' and
  595. #   'add_cparam_min' script calls explained above.
  596. #   Might be good in some eventing or in your own scripts.
  597. #
  598. #   Examples:
  599. #
  600. #     $game_actors[2].cparam_max("cdr")
  601. #     $game_actors[2].cdr_max
  602. #   Both of these will return the total added value for the maximum limit of
  603. #   the CDR parameter for actor 2.
  604. #
  605. #     $game_actors[5].cparam_min_bonus("mor")
  606. #     $game_actors[5].mor_min_bonus
  607. #   Both of these will return the total added value for the minimum limit of
  608. #   the MOR parameter for actor 5.
  609. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  610. # * To get the names and short names of your custom parameters, you can use any
  611. #   of the following script calls (if you set these settings up in the script):
  612. #
  613. #   - For the full names:
  614. #
  615. #     Vocab.cparam("cparam")
  616. #     Vocab.cparam
  617. #     CustomParams::Params["cparam"][:name]
  618. #
  619. #   - For the shortened names:
  620. #
  621. #     Vocab.cparam_a("cparam")
  622. #     Vocab.cparam_a
  623. #     CustomParams::Params["cparam"][:short]  
  624. #  
  625. #   Examples using the sample settings:
  626. #
  627. #     Vocab.cparam("spi")
  628. #     Vocab.spi
  629. #     CustomParams::Params["spi"][:name]
  630. #   All of these would return the full name of the custom parameter, and that
  631. #   is "Spirit" in this case.
  632. #
  633. #     Vocab.cparam_a("sta")
  634. #     Vocab.sta_a
  635. #     CustomParams::Params["sta"][:short]
  636. #   All of these would return the shortened name of the custom parameter, and
  637. #   that is "STA" in this case.
  638. #
  639. #   You can use these script calls anywhere you want!
  640. #-------------------------------------------------------------------------------
  641. # * < Installation >
  642. #-------------------------------------------------------------------------------
  643. # * Place this script between Materials and Main!
  644. #-------------------------------------------------------------------------------
  645. # * < Compatibility Info >
  646. #-------------------------------------------------------------------------------
  647. # * No known incompatibilities.
  648. #-------------------------------------------------------------------------------
  649. # * < Known Issues >
  650. #-------------------------------------------------------------------------------
  651. # * No known issues.
  652. #-------------------------------------------------------------------------------
  653. # * < Terms of Use >
  654. #-------------------------------------------------------------------------------
  655. # * Free to use for whatever purposes you want.
  656. # * Credit me (Sixth) in your game, pretty please! :P
  657. # * Posting modified versions of this script is allowed as long as you notice me
  658. #   about it with a link to it!
  659. #===============================================================================
  660. $imported = {} if $imported.nil?
  661. $imported["SixthCustomParams"] = true
  662. #===============================================================================
  663. # Settings:
  664. #===============================================================================
  665. module CustomParams
  666.   #-----------------------------------------------------------------------------
  667.   # Custom Parameter Settings:
  668.   #-----------------------------------------------------------------------------
  669.   # This is where you set up all your custom parameters.
  670.   # You can make as many as you want!
  671.   #
  672.   # Format:
  673.   #
  674.   #   "cparam_key" => {
  675.   #     :name => "Param Name",
  676.   #     :short => "Param Name - Short Version",
  677.   #     :default => value,
  678.   #     :min => min_value,
  679.   #     :max => max_value,
  680.   #     :type => :add/:mul,
  681.   #     :update => [:value,:min,:max],
  682.   #   },
  683.   #
  684.   # Details:
  685.   #
  686.   #   "cparam_key" => {
  687.   # This will be the key of the custom parameter. You can name it however you
  688.   # want, but make sure to use a string for it, and make sure that there are
  689.   # no duplicates!
  690.   # This will be used in your note-tags and script calls, so I advise you to
  691.   # use shorter keys!
  692.   # NOTE:
  693.   # You don't use the quotation marks in your note-tags, but you must use it
  694.   # in any script calls which deal with custom parameters!
  695.   # You can NOT use any key names here which are already defined method names
  696.   # in the Game_Battler class! For example, the default params like ATK, DEF,
  697.   # and such are defined as 'atk' and 'def', so those method names are already
  698.   # taken. If you use a method name which is already taken by the default
  699.   # engine, you will overwrite those methods, and as such, you will most
  700.   # probably brake your game, because those methods are needed for the engine
  701.   # to function correctly!
  702.   # If, by any chance, overwriting these methods is exactly what you are
  703.   # looking for, by all means, you can do it, just make sure to return the
  704.   # correct object/value type in your methods, for example, ATK, DEF, and such
  705.   # basic parameters expect positive integer numbers only, and CRI, EXR, and
  706.   # other x-params/s-params expect a float number!  
  707.   #
  708.   #   :name => "Param Name",
  709.   # This would be the full name of the parameter.
  710.   # It is a setting which can be used to set up a name for your parameters.
  711.   # Not used at all in the script! It is meant to be a helper setting for other
  712.   # scripters, so that they can reference the name of the parameters from this
  713.   # setting area in case they want to display it somewhere.
  714.   # I might make use of this setting myself if someone request a menu edit to
  715.   # show these new parameters somewhere, but until that happens, you don't have
  716.   # to set these up at all, unless you want to use them somewhere in your own
  717.   # codes.
  718.   #
  719.   #   :short => "Param Name - Short Version",
  720.   # Same as above, just a helper setting for other scripters.
  721.   # Feel free to ignore this setting if you want!
  722.   #
  723.   #   :default => value,
  724.   # This will be the default value (starting value) of the parameter.
  725.   # If an Actor or Enemy got no note-tags specifying a custom starting value
  726.   # for a parameter, these values will be loaded.
  727.   # The value can be an integer or float number, and it can be positive or
  728.   # negative as well.
  729.   # Advanced users can set this to be a string, in which case the string will
  730.   # be evaluated as a Ruby code, and the returned value will be the value of
  731.   # the parameter. Needless to say, this requires some Ruby coding knowledge!
  732.   # You have a unique local variable which you can use to determine the owner of
  733.   # the parameter in your formulas, you can reference it with 'user'
  734.   # (without the apostrophes!). This will let you make formulas which can change
  735.   # the value of the custom parameter depending on who is using that specific
  736.   # armor piece or depending on how high the actor's/enemy's DEF is,
  737.   # for example.
  738.   # From v1.1, you can also set the value to a symbol, which will run the method
  739.   # named like the symbol you used, and the result of that method will be the
  740.   # value of the parameter. This method will be run in the 'CustomParamMethods'
  741.   # module, so make sure that you add your own custom methods there! Your
  742.   # methods must contain one argument, and that will be the owner of the
  743.   # parameter! You must add this argument to your methods!
  744.   # And additionally, you can also use an array for the value, where the first
  745.   # element will be the symbol of the method name you want to use, and the
  746.   # second element will be another array containing all the arguments you want
  747.   # to send to that method. The arguments themselves will be evaluated in the
  748.   # settings module, so you can't use any dynamic values or any in-game data
  749.   # for those! Keep this in mind when you add your arguments!
  750.   # Just like in the case of method using note-tags, the first argument will
  751.   # always be the actor/enemy the parameter belongs to, and your own arguments
  752.   # will come after that!
  753.   # NOTE:
  754.   # If you want to use the eval and/or custom method features, make sure to read
  755.   # the setting explanation of the :update setting, and the note-tags made for
  756.   # the parameter updates!
  757.   #
  758.   #   :min => min_value,
  759.   # This is the minimum allowed value for the parameter.
  760.   # The value of the parameter can never go below this!
  761.   # You can set this up the same way like the :default setting explained above.
  762.   # If you want this to be updated whenever the parameter is requested, you
  763.   # must include :min in the :update setting for the parameter!
  764.   #
  765.   #   :max => max_value,
  766.   # This is the maximum allowed value for the parameter.
  767.   # The value of the parameter can never go above this!
  768.   # You can set this up the same way like the :default setting explained above.
  769.   # If you want this to be updated whenever the parameter is requested, you
  770.   # must include :max in the :update setting for the parameter!
  771.   #
  772.   #   :type => :add/:mul,
  773.   # This is the type of the parameter.
  774.   # It can be either additive (:add) or multiplier (:mul).
  775.   # To get what these mean, please refer to the explanation I gave in the
  776.   # "Note-Tags" section (the explanation can be found in the details of the
  777.   # first note-tag)!
  778.   # You can omit this setting, in which case :add will be used by default!
  779.   #
  780.   #   :update => [:value,:min,:max],
  781.   # This will decide if the value, max value, and/or min value for the parameter
  782.   # should always be updated when the parameter is requested, or only once.
  783.   # In the case of static parameters (which are not using any dynamic
  784.   # (eval or method) values) you can omit this setting, and it will only read
  785.   # the values once (when they are initialized). If you are using a dynamic
  786.   # value setting for a parameter (eval or method), you should set this setting
  787.   # up for your parameter, so that the code string/method that you entered could
  788.   # be re-calculated every time the value of the parameter is requested.
  789.   # So, in that case, this must be an array which can contain 3 symbols. These
  790.   # symbols will decide which value should be updated when needed and which
  791.   # shouldn't. The 3 symbols are:
  792.   # :value = For the actual value of the parameter.
  793.   # :max = For the maximum value of the parameter.
  794.   # :min = For the minimum value of the parameter.
  795.   # You can enter all 3 or only one or two of these symbols, it's up to you.
  796.   # Do not update your parameters if you don't need to, that might cause some
  797.   # performance loss depending on how you use your custom parameters!
  798.   # Note that if you set one of these 3 values to be updated here, they will
  799.   # always be updated when the parameter is requested on all database objects
  800.   # used by the actor/enemy!
  801.   # From v1.3, you can use a note-tag on your database objects to specify
  802.   # exactly which param should be updated for that specific object.
  803.   # This note-tag is object based, parameter based, and parameter value type
  804.   # based (value, min value, max value), so you can be very specific as to which
  805.   # parameters will update. This should be more performance friendly in case you
  806.   # use a lot of dynamic parameters, but you don't need to re-calculate the
  807.   # values on all objects or on all values. For example, if your default
  808.   # parameter value uses an eval formula, but all your other objects (equipment,
  809.   # states, classes, etc) use simple numeric values to raise/lower the
  810.   # parameter, you don't really need to update anything but the normal value,
  811.   # and only for the actors and enemies.
  812.   # For more details on this, visit the note-tag section!
  813.   #
  814.   # NOTE:
  815.   # If you are a scripter, you can also add your own settings to the custom
  816.   # parameters as well. Just use a different key for your settings, and you can
  817.   # easily reference them later from anywhere. For example, if you want to add
  818.   # icon settings for a parameter drawing method, you could make a setting
  819.   # named :icon and use that to set the icon index of the parameter.
  820.   # This way you can keep all of your settings for your custom parameters at
  821.   # one place.
  822.   #-----------------------------------------------------------------------------
  823.   Params = {
  824.     'str' => {
  825.       :name => "Strength", :short => "STR",
  826.       :default => 10, :min => 1, :max => 999,
  827.     },
  828.     "dex" => {
  829.       :name => "Dexterity", :short => "DEX",
  830.       :default => 10, :min => 1, :max => 999,
  831.     },
  832.     'res' => {
  833.       :name => "Resistance", :short => "RES",
  834.       :default => 10, :min => 1, :max => 999,
  835.     },
  836.     'blk' => {
  837.       :name => "Block", :short => "BLK",
  838.       :default => 10, :min => 1, :max => 999,
  839.     },
  840.     'skl' => {
  841.       :name => "Skill", :short => "SKL",
  842.       :default => 10, :min => 1, :max => 999,
  843.     },
  844.     'pro' => {
  845.       :name => "Profession", :short => "PRO",
  846.       :default => 10, :min => 1, :max => 999,
  847.     },
  848.     "vit" => {
  849.       :name => "Vitality", :short => "VIT",
  850.       :default => [:lvl_formula, [0.009, 3, 5, 31, "true"]], # Uses the 'lvl_formula' method defined below
  851.       :min => 1, :max => 999,
  852.       #:update => [:value], <-- Will use the <vit value update> note-tag on the actor
  853.     },
  854.     "spi" => {
  855.       :name => "Spirit", :short => "SPI",
  856.       :default => "user.vit / 2", # Will be half of the VIT custom parameter
  857.       :min => 1, :max => 999, :update => [:value],
  858.     },
  859.     "cdr" => {
  860.       :name => "Crit Damage", :short => "CDR",
  861.       :default => 1.0, :min => 0.0, :max => 3.0, :type => :mul,
  862.     },
  863.     "sta" => {
  864.       :name => "Stamina", :short => "STA",
  865.       :default => "user.agi * 10", # Will be equal with the user's AGI x 10
  866.       :min => 10, :max => 2000, :update => [:value],
  867.     },
  868.     "cha" => {
  869.       :name => "Charisma", :short => "CHA",
  870.       :default => "$game_system.playtime / 60", # Will be equal with the minutes played
  871.       :min => 0, :max => 9999, :update => [:value],
  872.     },
  873.     "mor" => {
  874.       :name => "Morality", :short => "MOR",
  875.       :default => 0, :min => -100, :max => 100,
  876.     },
  877.     "rge" => {
  878.       :name => "Rage", :short => "RGE",
  879.       :default => :hp_left, # Will use the method named 'hp_left' for the value calculation
  880.       :min => 0, :max => 9999, :update => [:value],
  881.     },
  882.     # Add more custom parameter settings here!
  883.   }
  884.  
  885. end
  886.  
  887. #-------------------------------------------------------------------------------
  888. # Custom Parameter Methods:
  889. #-------------------------------------------------------------------------------
  890. # This is the place where you will need to set up your own methods you want
  891. # to use for your custom parameters.
  892. # You can make as many as you want!
  893. # Remember that the first argument must be the user/owner of the parameter!
  894. # The rest of the arguments can be freely set, you can add as many as you want,
  895. # and you can do anything you want to do with them in your methods.
  896. #
  897. # NOTE:
  898. # This is an advanced feature for people with coding knowledge!
  899. # Calling these methods should be faster than calling an eval, so if you can,
  900. # use your own methods set up here instead of always using eval formulas!
  901. #-------------------------------------------------------------------------------
  902. module CustomParamMethods # <-- No touchy-touchy!
  903.  
  904.   class << self # <-- No touchy-touchy!
  905.    
  906.     # A level based formula generated with 4 numeric values.
  907.     # This is the same calculation like the built-in XP setting in the
  908.     # database uses (it's called "EXP Curve" on the "Class" tab).
  909.     def lvl_formula(user,base=1,extra=1,acc_a=1,acc_b=1,round_it="true")
  910.       lv = user.level.to_f
  911.       base = base.to_f
  912.       extra = extra.to_f
  913.       acc_a = acc_a.to_f
  914.       acc_b = acc_b.to_f
  915.       v = (base*((lv-1)**(0.9+acc_a/250))*lv*(lv+1)/
  916.         (6+lv**2/50/acc_b)+(lv-1)*extra)
  917.       v = v.round.to_i if round_it == "true"
  918.       return v
  919.     end
  920.    
  921.     # Another level based formula generated with 3 numeric values.
  922.     def lvl_based(user,base="5",mul1="0.5",mul2="0.5",round_it="true")
  923.       val = base.to_f + user.level * (mul1.to_f + (user.level * mul2.to_f))
  924.       val = val.to_i if round_it == "true"
  925.       return val
  926.     end
  927.    
  928.     # The param scales in proportion of the actor's remaining HP
  929.     def hp_left(user)
  930.       return (user.mhp - user.hp) * 2
  931.     end
  932.    
  933.     # The param scales in proportion of the actor's remaining mp
  934.     # A minimum value can be set with arguments as well as the multiplier used
  935.     def mp_left(user,min="10",mul="0.5")
  936.       return min.to_i + ((user.mmp - user.mp) * mul.to_f).to_i
  937.     end
  938.    
  939.   end # <-- No touchy-touchy!
  940.  
  941. end # <-- No touchy-touchy!
  942. #===============================================================================
  943. # End of settings! Editing anything below may lead to... you know it, right? o.o
  944. #===============================================================================
  945.  
  946. module Vocab
  947.  
  948.   class << self
  949.    
  950.     def cparam(prm)
  951.       return CustomParams::Params[prm][:name] || ""
  952.     end
  953.    
  954.     def cparam_a(prm)
  955.       return CustomParams::Params[prm][:short] || ""
  956.     end
  957.    
  958.     CustomParams::Params.keys.each do |prm|
  959.       cprm = %Q(
  960.      
  961.         def #{prm}
  962.           return CustomParams::Params['#{prm}'][:name] || ""
  963.         end
  964.        
  965.         def #{prm}_a
  966.           return CustomParams::Params['#{prm}'][:short] || ""
  967.         end
  968.                
  969.       )
  970.       module_eval(cprm)
  971.     end
  972.    
  973.   end
  974.  
  975. end
  976.  
  977. class RPG::BaseItem
  978.  
  979.   attr_accessor :cparam, :cparam_max, :cparam_min
  980.  
  981.   def update_cparam?(param,type)
  982.     if CustomParams::Params[param][:update] &&
  983.        CustomParams::Params[param][:update].include?(type)
  984.       return true
  985.     elsif self.cparam_update(param,type)
  986.       return true
  987.     end
  988.     return false
  989.   end
  990.  
  991.   def cparam_update(param,type)
  992.     @cparam_update = {} if @cparam_update.nil?
  993.     if @cparam_update[[param,type]].nil?
  994.       if @note =~ /<#{param} #{type} update>/i
  995.         @cparam_update[[param,type]] = true
  996.       else
  997.         @cparam_update[[param,type]] = false
  998.       end
  999.     end
  1000.     return @cparam_update[[param,type]]
  1001.   end
  1002.  
  1003.   def cparam(param,user)
  1004.     @cparam = {} if @cparam.nil?
  1005.     if @cparam[param].nil? || update_cparam?(param,:value)
  1006.       init_cparam(param,user)
  1007.     end
  1008.     return @cparam[param]
  1009.   end
  1010.  
  1011.   def init_cparam(param,user)
  1012.     if @note =~ /<#{param} formula: (.*)>/i
  1013.       @cparam[param] = eval($1)
  1014.     elsif @note =~ /<#{param} method: (.*)>/i
  1015.       args = [user]; mthd = ""
  1016.       $1.split(", ").each_with_index do |data,i|
  1017.         i == 0 ? mthd = data : args << data
  1018.       end
  1019.       if args.size > 1
  1020.         @cparam[param] = CustomParamMethods.send(mthd,*args)
  1021.       else
  1022.         @cparam[param] = CustomParamMethods.send($1,user)
  1023.       end
  1024.     elsif @note =~ /<#{param}: (.*)>/i
  1025.       @cparam[param] = $1.include?(".") ? $1.to_f : $1.to_i
  1026.     else
  1027.       case self
  1028.       when RPG::Actor, RPG::Enemy
  1029.         if CustomParams::Params[param][:default].is_a?(String)
  1030.           @cparam[param] = eval(CustomParams::Params[param][:default])
  1031.         elsif CustomParams::Params[param][:default].is_a?(Symbol)
  1032.           mthd = CustomParams::Params[param][:default]
  1033.           @cparam[param] = CustomParamMethods.send(mthd,user)
  1034.         elsif CustomParams::Params[param][:default].is_a?(Array)
  1035.           mthd = CustomParams::Params[param][:default][0]
  1036.           args = [user] + CustomParams::Params[param][:default][1]
  1037.           @cparam[param] = CustomParamMethods.send(mthd,*args)
  1038.         else
  1039.           @cparam[param] = CustomParams::Params[param][:default]
  1040.         end
  1041.       else
  1042.         if CustomParams::Params[param][:type] == :mul # Multiplier type
  1043.           @cparam[param] = 1
  1044.         else # Additive type
  1045.           @cparam[param] = 0
  1046.         end
  1047.       end
  1048.     end
  1049.   end
  1050.  
  1051.   def cparam_max(param,user)
  1052.     @cparam_max = {} if @cparam_max.nil?
  1053.     if @cparam_max[param].nil? || update_cparam?(param,:max)
  1054.       init_cparam_max(param,user)
  1055.     end
  1056.     return @cparam_max[param]
  1057.   end
  1058.  
  1059.   def init_cparam_max(param,user)
  1060.     if @note =~ /<#{param} max formula: (.*)>/i
  1061.       @cparam_max[param] = eval($1)
  1062.     elsif @note =~ /<#{param} max method: (.*)>/i
  1063.       args = [user]; mthd = ""
  1064.       $1.split(", ").each_with_index do |data,i|
  1065.         i == 0 ? mthd = data : args << data
  1066.       end
  1067.       if args.size > 1
  1068.         @cparam_max[param] = CustomParamMethods.send(mthd,*args)
  1069.       else
  1070.         @cparam_max[param] = CustomParamMethods.send($1,user)
  1071.       end
  1072.     elsif @note =~ /<#{param} max: (.*)>/i
  1073.       @cparam_max[param] = $1.include?(".") ? $1.to_f : $1.to_i
  1074.     else
  1075.       case self
  1076.       when RPG::Actor, RPG::Enemy
  1077.         if CustomParams::Params[param][:max].is_a?(String)
  1078.           @cparam_max[param] = eval(CustomParams::Params[param][:max])
  1079.         elsif CustomParams::Params[param][:max].is_a?(Symbol)
  1080.           mthd = CustomParams::Params[param][:max]
  1081.           @cparam_max[param] = CustomParamMethods.send(mthd,user)
  1082.         elsif CustomParams::Params[param][:max].is_a?(Array)
  1083.           mthd = CustomParams::Params[param][:max][0]
  1084.           args = [user] + CustomParams::Params[param][:max][1]
  1085.           @cparam_max[param] = CustomParamMethods.send(mthd,*args)
  1086.         else
  1087.           @cparam_max[param] = CustomParams::Params[param][:max]
  1088.         end
  1089.       else
  1090.         @cparam_max[param] = 0
  1091.       end
  1092.     end
  1093.   end
  1094.  
  1095.   def cparam_min(param,user)
  1096.     @cparam_min = {} if @cparam_min.nil?
  1097.     if @cparam_min[param].nil? || update_cparam?(param,:min)
  1098.       init_cparam_min(param,user)
  1099.     end
  1100.     return @cparam_min[param]
  1101.   end
  1102.  
  1103.   def init_cparam_min(param,user)
  1104.     if @note =~ /<#{param} min formula: (.*)>/i
  1105.       @cparam_min[param] = eval($1)
  1106.     elsif @note =~ /<#{param} min method: (.*)>/i
  1107.       args = [user]; mthd = ""
  1108.       $1.split(", ").each_with_index do |data,i|
  1109.         i == 0 ? mthd = data : args << data
  1110.       end
  1111.       if args.size > 1
  1112.         @cparam_min[param] = CustomParamMethods.send(mthd,*args)
  1113.       else
  1114.         @cparam_min[param] = CustomParamMethods.send($1,user)
  1115.       end
  1116.     elsif @note =~ /<#{param} min: (.*)>/i
  1117.       @cparam_min[param] = $1.include?(".") ? $1.to_f : $1.to_i
  1118.     else
  1119.       case self
  1120.       when RPG::Actor, RPG::Enemy
  1121.         if CustomParams::Params[param][:min].is_a?(String)
  1122.           @cparam_min[param] = eval(CustomParams::Params[param][:min])
  1123.         elsif CustomParams::Params[param][:min].is_a?(Symbol)
  1124.           mthd = CustomParams::Params[param][:min]
  1125.           @cparam_min[param] = CustomParamMethods.send(mthd,user)
  1126.         elsif CustomParams::Params[param][:min].is_a?(Array)
  1127.           mthd = CustomParams::Params[param][:min][0]
  1128.           args = [user] + CustomParams::Params[param][:min][1]
  1129.           @cparam_min[param] = CustomParamMethods.send(mthd,*args)
  1130.         else
  1131.           @cparam_min[param] = CustomParams::Params[param][:min]
  1132.         end
  1133.       else
  1134.         @cparam_min[param] = 0
  1135.       end
  1136.     end
  1137.   end
  1138.      
  1139. end
  1140.  
  1141. class Game_Battler < Game_BattlerBase
  1142.    
  1143.   def cparam(param)
  1144.     val = CustomParams::Params[param][:type] == :mul ? 1 : 0
  1145.     max = min = 0
  1146.     feature_objects.each do |obj|
  1147.       if CustomParams::Params[param][:type] == :mul
  1148.         val *= obj.cparam(param,self)
  1149.       else
  1150.         val += obj.cparam(param,self)
  1151.       end
  1152.       max += obj.cparam_max(param,self)
  1153.       min += obj.cparam_min(param,self)
  1154.     end
  1155.     max += self.cparam_max_bonus(param)
  1156.     min += self.cparam_min_bonus(param)
  1157.     if CustomParams::Params[param][:type] == :mul
  1158.       val *= self.cparam_bonus(param)
  1159.     else
  1160.       val += self.cparam_bonus(param)
  1161.     end
  1162.     val = max if val > max
  1163.     val = min if val < min
  1164.     return val
  1165.   end
  1166.      
  1167.   def cparam_bonus(param)
  1168.     @cparam_bonus = {} if @cparam_bonus.nil?
  1169.     init_cparam_bonus(param) if @cparam_bonus[param].nil?
  1170.     return @cparam_bonus[param]
  1171.   end
  1172.  
  1173.   def init_cparam_bonus(param)
  1174.     if CustomParams::Params[param][:type] == :mul # Multiplier type
  1175.       @cparam_bonus[param] = 1
  1176.     else # Additive type
  1177.       @cparam_bonus[param] = 0
  1178.     end
  1179.   end
  1180.  
  1181.   def add_cparam(param,val,limit=false)
  1182.     @cparam_bonus = {} if @cparam_bonus.nil?
  1183.     init_cparam_bonus(param) if @cparam_bonus[param].nil?
  1184.     if CustomParams::Params[param][:type] == :mul # Multiplier type
  1185.       @cparam_bonus[param] *= val
  1186.     else
  1187.       @cparam_bonus[param] += val
  1188.     end
  1189.     return unless limit
  1190.     max = cparam_max(param)
  1191.     min = cparam_min(param)
  1192.     @cparam_bonus[param] = max if @cparam_bonus[param] > max
  1193.     @cparam_bonus[param] = min if @cparam_bonus[param] < min
  1194.   end
  1195.  
  1196.   def cparam_max(param)
  1197.     max = 0
  1198.     feature_objects.each do |obj|
  1199.       max += obj.cparam_max(param,self)
  1200.     end
  1201.     max += self.cparam_max_bonus(param)
  1202.     return max
  1203.   end
  1204.  
  1205.   def cparam_max_bonus(param)
  1206.     @cparam_max_bonus = {} if @cparam_max_bonus.nil?
  1207.     @cparam_max_bonus[param] = 0 if @cparam_max_bonus[param].nil?
  1208.     return @cparam_max_bonus[param]
  1209.   end
  1210.  
  1211.   def add_cparam_max(param,val)
  1212.     @cparam_max_bonus = {} if @cparam_max_bonus.nil?
  1213.     @cparam_max_bonus[param] = 0 if @cparam_max_bonus[param].nil?
  1214.     @cparam_max_bonus[param] += val
  1215.   end
  1216.  
  1217.   def cparam_min(param)
  1218.     min = 0
  1219.     feature_objects.each do |obj|
  1220.       min += obj.cparam_min(param,self)
  1221.     end
  1222.     min += self.cparam_min_bonus(param)
  1223.     return min
  1224.   end
  1225.  
  1226.   def cparam_min_bonus(param)
  1227.     @cparam_min_bonus = {} if @cparam_min_bonus.nil?
  1228.     @cparam_min_bonus[param] = 0 if @cparam_min_bonus[param].nil?
  1229.     return @cparam_min_bonus[param]
  1230.   end
  1231.  
  1232.   def add_cparam_min(param,val)
  1233.     @cparam_min_bonus = {} if @cparam_min_bonus.nil?
  1234.     @cparam_min_bonus[param] = 0 if @cparam_min_bonus[param].nil?
  1235.     @cparam_min_bonus[param] += val
  1236.   end
  1237.  
  1238.   CustomParams::Params.keys.each do |prm|
  1239.     cprm = %Q(
  1240.    
  1241.       def #{prm}
  1242.         return self.cparam('#{prm}')
  1243.       end
  1244.      
  1245.       def #{prm}_bonus
  1246.         return self.cparam_bonus('#{prm}')
  1247.       end
  1248.      
  1249.       def add_#{prm}(val,limit=true)
  1250.         return self.add_cparam('#{prm}',val,limit)
  1251.       end
  1252.      
  1253.       def #{prm}_max
  1254.         return self.cparam_max('#{prm}')
  1255.       end
  1256.      
  1257.       def #{prm}_max_bonus
  1258.         return self.cparam_max_bonus('#{prm}')
  1259.       end
  1260.      
  1261.       def add_#{prm}_max(val)
  1262.         return self.add_cparam_max('#{prm}',val)
  1263.       end
  1264.      
  1265.       def #{prm}_min
  1266.         return self.cparam_min('#{prm}')
  1267.       end
  1268.      
  1269.       def #{prm}_min_bonus
  1270.         return self.cparam_min_bonus('#{prm}')
  1271.       end
  1272.      
  1273.       def add_#{prm}_min(val)
  1274.         return self.add_cparam_min('#{prm}',val)
  1275.       end
  1276.      
  1277.     )
  1278.     class_eval(cprm)
  1279.   end
  1280.  
  1281. end
  1282. #==============================================================================
  1283. # !!END OF SCRIPT - OHH, NOES!!
  1284. #==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement