Advertisement
Rutsah

Traits Namer by Kred-Ex

Jun 11th, 2021
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.72 KB | None | 0 0
  1. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
  2. # â–¼ Traits Namer
  3. # Author: Kread-EX
  4. # Version: 1.02
  5. # Release date: 11/03/2012
  6. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
  7.  
  8. #------------------------------------------------------------------------------
  9. # â–¼ UPDATES
  10. #------------------------------------------------------------------------------
  11. # # 03/02/2012. Bug fixes.
  12. # # 24/03/2012. Added methods used by Alchemic Synthesis.
  13. # # 23/03/2012. Version 1.0, now help window generation is included.
  14. #------------------------------------------------------------------------------
  15. # â–¼ TERMS OF USAGE
  16. #------------------------------------------------------------------------------
  17. # # You are free to adapt this work to suit your needs.
  18. # # You can use this work for commercial purposes if you like it.
  19. # # Credit is appreciated.
  20. # #
  21. # # For support:
  22. # # grimoirecastle.wordpress.com
  23. # # rpgmakerweb.com
  24. #------------------------------------------------------------------------------
  25. # â–¼ INTRODUCTION
  26. #------------------------------------------------------------------------------
  27. # # This is a core script. By itself, it doesn't do anything but it used by
  28. # # Runic Enchantment and Alchemic Synthesis. The purpose of this script
  29. # # is to provide an automated way to name traits: the script retrieve the traits
  30. # # data and generates a name based on a customizable template.
  31. #------------------------------------------------------------------------------
  32.  
  33. $imported = {} if $imported.nil?
  34. $imported['KRX-TraitsNamer'] = true
  35.  
  36. puts 'Load: Traits Namer v1.02 by Kread-EX'
  37.  
  38. module KRX
  39. module TraitsNamer
  40. #===========================================================================
  41. # â– CONFIGURATION
  42. #===========================================================================
  43.  
  44. X_PARAMETERS = [
  45.  
  46. 'Accuracy',
  47. 'Evasion',
  48. 'Critical rate',
  49. 'Critical eva. rate',
  50. 'M. Evasion',
  51. 'Magic reflection',
  52. 'Counter rate',
  53. 'HP Regen',
  54. 'MP Regen',
  55. 'TP Regen'
  56.  
  57. ]
  58.  
  59. S_PARAMETERS = [
  60.  
  61. 'Aggro effect',
  62. 'Guard effect',
  63. 'Recovery rate',
  64. 'Pharmacology',
  65. 'MP cost',
  66. 'TP charge rate',
  67. 'Physical damage',
  68. 'Magical damage',
  69. 'Floor damage',
  70. 'EXP rate'
  71.  
  72. ]
  73.  
  74. SPECIAL_FLAGS = [
  75.  
  76. 'Autobattle',
  77. 'Guard',
  78. 'Cover',
  79. 'TP Saver'
  80.  
  81. ]
  82.  
  83. PARTY_ABILITY = [
  84.  
  85. 'Half Encounter',
  86. 'No Encounter',
  87. 'No surprise attacks',
  88. 'No preemptive attacks',
  89. 'Gold x2',
  90. 'Item Drops x2'
  91.  
  92. ]
  93.  
  94. CODENAMES = {
  95.  
  96. 11 => '%s resist: %d%%' , # Element rate
  97. 12 => '%s debuff rate: %d%%' , # Debuff rate
  98. 13 => '%s resist: %d%%' , # State rate
  99. 14 => 'Immunity: %s' , # State immunity
  100. 21 => '%s: %d%%' , # Parameter rate
  101. 22 => '%s: %d%%' , # Additional parameter rate
  102. 23 => '%s: %d%%' , # Special parameter rate
  103. 31 => 'Attack %s' , # Physical attack attribute
  104. 32 => 'Attack %s %d%%' , # Physical attack state
  105. 33 => 'Attack speed %d' , # Attack speed correction
  106. 34 => 'Attack x%d' , # Additional attacks
  107. 41 => 'Command: %s' , # Add skill type
  108. 42 => 'Seal: %s' , # Seal skill type
  109. 43 => 'Skill: %s' , # Add skill
  110. 44 => 'Skill Seal: %s' , # Seal skill
  111. 51 => 'Can equip: %s' , # Add equip type (weapon)
  112. 52 => 'Can equip: %s' , # Add equip type (armor)
  113. 53 => 'Fix equip: %s' , # Fix equip slot
  114. 54 => 'Seal equip: %s' , # Seal equip slot
  115. 55 => 'Dual Wielding' , # Dual Wield
  116. 61 => 'Bonus Actions: +%d%%' , # Bonus actions
  117. 62 => '%s' , # Special flag
  118. 63 => 'Collapse type' , # Collapse type (will never be used, I think)
  119. 64 => '%s' , # Party ability
  120.  
  121. }
  122.  
  123. CODEHELP = {
  124.  
  125. # Element rate
  126. 11 => 'Raises %s resistance by %d%%.',
  127. # Debuff rate
  128. 12 => 'Raises %s resistance by %d%%.',
  129. # State rate
  130. 13 => 'Raises %s resistance by %d%%.',
  131. # State immunity
  132. 14 => 'Grants immunity to %s.',
  133. # Parameter rate
  134. 21 => 'Raises %s by %d%%.',
  135. # Additional parameter rate
  136. 22 => 'Raises %s by %d%%.',
  137. # Special parameter rate
  138. 23 => 'Grants a %d% modifier to %s.',
  139. # Physical attack attribute
  140. 31 => 'Adds %s element to normal attacks.',
  141. # Physical attack state
  142. 32 => 'Adds %s to normal attacks (%d%% accuracy).',
  143. # Attack speed correction (bonus)
  144. 33 => ['Raises attack speed by %d.',
  145. # Attack speed correction (malus)
  146. 'Reduces attack speed by %d.'],
  147. # Additional attacks
  148. 34 => 'Grants %d additional attacks.',
  149. # Add skill type
  150. 41 => 'Enables the %s battle command.',
  151. # Seal skill type
  152. 42 => 'Seals the %s battle command.',
  153. # Add skill
  154. 43 => 'Allows the use of the %s skill',
  155. # Seal skill
  156. 44 => 'Seals the %s skill.',
  157. # Add equip type (weapon)
  158. 51 => 'Allows %s to be equipped.',
  159. # Add equip type (armor)
  160. 52 => 'Allows %s to be equipped.',
  161. # Fix equip slot
  162. 53 => 'Fixes the %s equipment slot.',
  163. # Seal equip slot
  164. 54 => 'Seals the %s equipment slot.',
  165. # Dual Wield
  166. 55 => 'Allows to use two weapons as the same time.',
  167. # Bonus actions
  168. 61 => 'Raises the action rate by %d%%.',
  169. # Autobattle
  170. 62 => ['The character will act on his/her own in battle.',
  171. # Guard
  172. 'The character will permanently defend.',
  173. # Cover
  174. 'The character will take hits for his/her wounded comrades.',
  175. # TP Saver
  176. 'TP are kept after battles.'],
  177. # Collapse type (no need to use it but meh)
  178. 63 => 'Alters the collapse animation.',
  179. # Half encounter
  180. 64 => ['Halves the random encounter rate.',
  181. # No encounter
  182. 'Disables random encounters.',
  183. # No surprise attacks
  184. 'Disables surprise attacks.',
  185. # No preemptive attacks
  186. 'Disables preemptive attacks.',
  187. # Gold x2
  188. 'Doubles the money obtained after a battle.',
  189. # Item Drops x2
  190. 'Doubles the drop rate of items.']
  191.  
  192. }
  193.  
  194. EFFECTS_CODENAMES = {
  195.  
  196. 11 => 'HP Recovery' , # HP Recovery
  197. 12 => 'MP Recovery' , # MP Recovery
  198. 13 => 'TP Recovery' , # TP Gain
  199. 21 => 'Add %s' , # Add State
  200. 22 => 'Cleanse %s' , # Remove State
  201. 31 => '%s+' , # Add buff
  202. 32 => '%s-' , # Add debuff
  203. 33 => 'Dispel %s+' , # Remove buff
  204. 34 => 'Cancel %s-' , # Remove debuff
  205. 41 => 'Escape' , # Escape
  206. 42 => '%s Bonus' , # Permanent stat growth
  207. 43 => 'Learn %s' , # Permanent skill learning
  208. 44 => 'Common Event' , # Common event
  209.  
  210. }
  211.  
  212. EFFECTS_CODEHELP = {
  213.  
  214. # HP Recovery (static)
  215. 11 => ['Restores %d HP.',
  216. # HP Recovery (dynamic)
  217. 'Restores %d%% of maximum HP.'],
  218. # MP Recovery (static)
  219. 12 => ['Restores %d MP.',
  220. # MP Recovery (dynamic)
  221. 'Restores %d%% of maximum MP.'],
  222. # TP Gain
  223. 13 => 'Restores %d%% TP.',
  224. # Add State
  225. 21 => 'Inflicts %s (%d%% chance).',
  226. # Remove State
  227. 22 => 'Cancels %s.',
  228. # Add buff
  229. 31 => 'Increases %s for %d turns.',
  230. # Add debuff
  231. 32 => 'Decreases %s for %d turns.',
  232. # Remove buff
  233. 33 => 'Cancels a previously applied %s buff.',
  234. # Remove debuff
  235. 34 => 'Dispels an active %s debuff.',
  236. # Escape
  237. 41 => 'Automatically escape from battle.',
  238. # Permanent stat growth
  239. 42 => 'Boosts %d by %d permanently.',
  240. # Permanent skill learning
  241. 43 => 'Teaches the %s skill permanently.',
  242. # Common Event
  243. 44 => 'Calls a common event.'
  244.  
  245. }
  246.  
  247. #===========================================================================
  248. # â– CUSTOM TRAITS/EFFECTS CONFIGURATION
  249. #===========================================================================
  250.  
  251. # INSTRUCTIONS
  252. # Here you can define custom traits names and descriptions.
  253. #
  254. # Syntax:
  255. # [type, code, data_id, value 1, value2] => [name, description]
  256. #
  257. # type: 0 (for equipment), 1 (for usables)
  258. #
  259. # code: the code number. Refer to default naming to know what is what.
  260. #
  261. # data_id: the number of the option you've choosen in the trait droplist.
  262. #
  263. # value1: what you typed in the first field where you can write numbers.
  264. # For equipment this is the only one.
  265. #
  266. # value2: usable items only. What you typed in the second field.
  267. #
  268. # description: If you want to also use a custom description. If you only
  269. # want the custom name, set this to nil.
  270.  
  271. CUSTOM_TRAITS = {
  272.  
  273. [0, 32, 2, 50] => ['Poisonous', nil],
  274. [0, 32, 2, 100] => ['Venomous', nil],
  275.  
  276. [1, 11, 0, 0, 10] => ['HP Recovery XS', nil],
  277. [1, 11, 0, 0, 25] => ['HP Recovery S', nil],
  278. [1, 11, 0, 0, 50] => ['HP Recovery M', nil],
  279. [1, 11, 0, 0, 75] => ['HP Recovery L', nil],
  280. [1, 11, 0, 0, 100] => ['HP Recovery XL', 'Restores all HP!'],
  281. [1, 12, 0, 0, 10] => ['MP Recovery XS', nil],
  282. [1, 12, 0, 0, 25] => ['MP Recovery S', nil],
  283. [1, 12, 0, 0, 50] => ['MP Recovery M', nil],
  284. [1, 12, 0, 0, 75] => ['MP Recovery L', nil],
  285. [1, 12, 0, 0, 100] => ['MP Recovery XL', 'Restores all MP!'],
  286. [1, 13, 0, 2, 0] => ['TP Recovery XS', nil],
  287. [1, 13, 0, 5, 0] => ['TP Recovery S', nil],
  288. [1, 13, 0, 10, 0] => ['TP Recovery M', nil],
  289. [1, 13, 0, 16, 0] => ['TP Recovery L', nil],
  290. [1, 13, 0, 20, 0] => ['TP Recovery XL', nil],
  291.  
  292. }
  293.  
  294. #===========================================================================
  295. # â– CONFIGURATION ENDS HERE
  296. #===========================================================================
  297. #--------------------------------------------------------------------------
  298. # â— Generates traits name
  299. #--------------------------------------------------------------------------
  300. def self.feature_name(code, data_id, value)
  301. custom = CUSTOM_TRAITS[[0, code, data_id, self.convert_value(code, value)]]
  302. return custom[0] unless custom.nil? || custom[0].nil?
  303. base_name = CODENAMES[code]
  304. data_name = case code
  305. when 11, 31
  306. $data_system.elements[data_id]
  307. when 12, 21
  308. Vocab.param(data_id)
  309. when 13, 14, 32
  310. $data_states[data_id].name
  311. when 22
  312. X_PARAMETERS[data_id]
  313. when 23
  314. S_PARAMETERS[data_id]
  315. when 41, 42
  316. $data_system.skill_types[data_id]
  317. when 43, 44
  318. $data_skills[data_id].name
  319. when 51
  320. $data_system.weapon_types[data_id]
  321. when 52
  322. $data_system.armor_types[data_id]
  323. when 53, 54
  324. Vocab.etype(data_id)
  325. when 62
  326. SPECIAL_FLAGS[data_id]
  327. when 64
  328. PARTY_ABILITY[data_id]
  329. end
  330. final_value = case code
  331. when 11, 13
  332. 100 - (value * 100)
  333. when 33, 34
  334. value
  335. else
  336. value * 100
  337. end
  338. if data_name.nil?
  339. name = sprintf(base_name, final_value)
  340. else
  341. name = sprintf(base_name, data_name, final_value)
  342. end
  343. name
  344. end
  345. #--------------------------------------------------------------------------
  346. # â— Generates traits description
  347. #--------------------------------------------------------------------------
  348. def self.feature_description(code, data_id, value)
  349. custom = CUSTOM_TRAITS[[0, code, data_id, self.convert_value(code, value)]]
  350. return custom[1] unless custom.nil? || custom[1].nil?
  351. if CODEHELP[code].is_a?(Array)
  352. base_help = CODEHELP[code][data_id]
  353. else
  354. base_help = CODEHELP[code]
  355. end
  356. data_name = case code
  357. when 11, 31
  358. $data_system.elements[data_id]
  359. when 12, 21
  360. Vocab.param(data_id)
  361. when 13, 14, 32
  362. $data_states[data_id].name
  363. when 22
  364. X_PARAMETERS[data_id]
  365. when 23
  366. S_PARAMETERS[data_id]
  367. when 41, 42
  368. $data_system.skill_types[data_id]
  369. when 43, 44
  370. $data_skills[data_id].name
  371. when 51
  372. $data_system.weapon_types[data_id]
  373. when 52
  374. $data_system.armor_types[data_id]
  375. when 53, 54
  376. Vocab.etype(data_id)
  377. when 62
  378. SPECIAL_FLAGS[data_id]
  379. when 64
  380. PARTY_ABILITY[data_id]
  381. end
  382. final_value = case code
  383. when 11, 13
  384. 100 - (value * 100)
  385. when 33, 34
  386. value
  387. else
  388. value * 100
  389. end
  390. if data_name.nil?
  391. name = sprintf(base_help, final_value)
  392. else
  393. name = sprintf(base_help, data_name, final_value)
  394. end
  395. name
  396. end
  397. #--------------------------------------------------------------------------
  398. # â— Generates effects name
  399. #--------------------------------------------------------------------------
  400. def self.effect_name(code, data_id, value1, value2)
  401. custom = CUSTOM_TRAITS[[1, code, data_id,
  402. self.convert_value(code, value1, false),
  403. self.convert_value(code, value2, false)]]
  404. return custom[0] unless custom.nil? || custom[0].nil?
  405. base_name = EFFECTS_CODENAMES[code]
  406. data_name = case code
  407. when 21, 22
  408. $data_states[data_id].name
  409. when 31, 32, 33, 34, 42
  410. Vocab.param(data_id)
  411. when 43
  412. $data_skills[data_id]
  413. end
  414. if data_name.nil?
  415. name = sprintf(base_name, value1, value2)
  416. else
  417. name = sprintf(base_name, data_name, value1, value2)
  418. end
  419. name
  420. end
  421. #--------------------------------------------------------------------------
  422. # â— Generates effects description
  423. #--------------------------------------------------------------------------
  424. def self.effect_description(code, data_id, value1, value2)
  425. custom = CUSTOM_TRAITS[[1, code, data_id,
  426. self.convert_value(code, value1, false),
  427. self.convert_value(code, value2, false)]]
  428. return custom[1] unless custom.nil? || custom[1].nil?
  429. if EFFECTS_CODEHELP[code].is_a?(Array)
  430. base_help = value2 > 0 ? EFFECTS_CODEHELP[code][0] :
  431. EFFECTS_CODEHELP[code][1]
  432. else
  433. base_help = EFFECTS_CODEHELP[code]
  434. end
  435. data_name = case code
  436. when 21, 22
  437. $data_states[data_id].name
  438. when 31, 32, 33, 34, 42
  439. Vocab.param(data_id)
  440. when 43
  441. $data_skills[data_id]
  442. end
  443. value1 = self.convert_value(code, value1, false)
  444. value2 = self.convert_value(code, value2, false)
  445. value1 = value2 if value1 == 0
  446. if data_name.nil?
  447. name = sprintf(base_help, value1, value2)
  448. else
  449. name = sprintf(base_help, data_name, value1, value2)
  450. end
  451. name
  452. end
  453. #--------------------------------------------------------------------------
  454. # â— Converts the real value to the one entered in the editor
  455. #--------------------------------------------------------------------------
  456. def self.convert_value(code, value, feature = true)
  457. if feature && [33, 34].include?(code)
  458. return value.to_i
  459. elsif feature && [21].include?(code)
  460. return (value.to_f / 100)
  461. elsif [11, 12].include?(code) && value <= 1
  462. return (value.to_i * 100).to_i
  463. else
  464. value.to_i
  465. end
  466. end
  467. #--------------------------------------------------------------------------
  468. # â— Points towards either feature name or effect name
  469. #--------------------------------------------------------------------------
  470. def self.trait_name(trait)
  471. if trait.is_a?(RPG::BaseItem::Feature)
  472. return self.feature_name(trait.code, trait.data_id, trait.value)
  473. end
  474. self.effect_name(trait.code, trait.data_id, trait.value1, trait.value2)
  475. end
  476. #--------------------------------------------------------------------------
  477. # â— Points towards either feature description or effect description
  478. #--------------------------------------------------------------------------
  479. def self.trait_description(trait)
  480. if trait.is_a?(RPG::BaseItem::Feature)
  481. return self.feature_description(trait.code, trait.data_id, trait.value)
  482. end
  483. self.effect_description(trait.code, trait.data_id, trait.value1,
  484. trait.value2)
  485. end
  486. end
  487. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement