cooldoode325

Skill_Weapon_Levels

Feb 24th, 2014
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.33 KB | None | 0 0
  1. #Equipment and Skill Levels v1.0
  2. #----------#
  3. #Features: Allows individual equipment and skills gain exp and levels, thus
  4. # becoming stronger!
  5. #
  6. #Usage: Plug and play, customize as needed
  7. # Notetags, use these to override defaults:
  8. # <MLVL #> - sets the max level for the object
  9. # <PARAM #> - sets the parameter increase for the object
  10. # <XPRATE #> - sets the xp rate for the object
  11. # <XPRATIO #> - sets the ratio of xp gained
  12. # <MPCOST #> - sets the mp cost increase for skills
  13. #
  14. #----------#
  15. #-- Script by: V.M of D.T
  16. #
  17. #- Questions or comments can be:
  18. # posted on the thread for the script
  19. # given by email: [email protected]
  20. # provided on facebook: http://www.facebook.com/DaimoniousTailsGames
  21. #
  22. #- Free to use in any project with credit given, donations always welcome!
  23.  
  24. module LVLUP
  25. #Default change to parameters per level in percentage
  26. PARAMETER_INCREASE = 0.25
  27. #Default exp needed to level. It's current_level * EXP_RATE
  28. EXP_RATE = 100
  29. #Default ratio of exp gained for equipped items in percentage
  30. #E.g 0.5 means items gain 50 exp for every 100 gained by the actor
  31. EXP_MULTIPLIER = 0.5
  32. #Display of the item's name, as a String
  33. ITEM_NAME = "'Lvl ' + item.get_level.to_s + ' ' + item.name"
  34. #Display of the skill's name, as a String
  35. SKILL_NAME = "'Lvl ' + @actor.get_skill_level(item.id).to_s + ' ' + item.name"
  36. #Whether to draw the exp bar over the icon or not
  37. DRAW_EXP_BAR = true
  38. #Default max level for objects
  39. MAX_LEVEL = 99
  40. #Whether to level up skills or not
  41. LEVEL_UP_SKILLS = true
  42. #Whether to level up equipment or not
  43. LEVEL_UP_ITEMS = true
  44. #Default increase to skill costs per level
  45. MP_COST = 0.1
  46. def self.mlvl(note)
  47. note =~ /<MLVL (\d+)>/
  48. $~ ? $~[1].to_i : MAX_LEVEL
  49. end
  50. def self.param(note)
  51. note =~ /<PARAM (\d+)>/
  52. $~ ? $~[1].to_i : PARAMETER_INCREASE
  53. end
  54. def self.xprate(note)
  55. note =~ /<XPRATE (\d+)>/
  56. $~ ? $~[1].to_i : EXP_RATE
  57. end
  58. def self.xpratio(note)
  59. note =~ /<XPRATIO (\d+)>/
  60. $~ ? $~[1].to_i : EXP_MULTIPLIER
  61. end
  62. def self.mpcost(note)
  63. note =~ /<MPCOST (\d+)>/
  64. $~ ? $~[1].to_i : MP_COST
  65. end
  66. end
  67.  
  68. class RPG::EquipItem < RPG::BaseItem
  69. def params
  70. return @params if !LVLUP::LEVEL_UP_ITEMS
  71. stats = [0] * 8
  72. stats.each_index do |i|
  73. stats[i] = @params[i] * (1 + get_level * LVLUP.param(@note))
  74. end
  75. stats
  76. end
  77. def change_exp(value)
  78. get_exp
  79. @current_exp += value * LVLUP.xpratio(@note)
  80. check_level
  81. end
  82. def check_level
  83. while get_exp > get_level * LVLUP.xprate(@note)
  84. @level += 1
  85. @current_exp -= get_level * LVLUP.xprate(@note)
  86. @level = LVLUP.mlvl(@note) if @level > LVLUP.mlvl(@note)
  87. end
  88. end
  89. def get_level
  90. @level = 1 if @level.nil?
  91. @level
  92. end
  93. def get_exp
  94. @current_exp = 0 if @current_exp.nil?
  95. @current_exp
  96. end
  97. def exp_rate
  98. return 1 if get_level == LVLUP.mlvl(@note)
  99. get_exp.to_f / (get_level * LVLUP.xprate(@note))
  100. end
  101. end
  102.  
  103. class Game_Actor
  104. alias level_up_change change_exp
  105. alias level_up_init initialize
  106. alias level_up_mdv make_damage_value
  107. alias level_up_mp_cost skill_mp_cost
  108. alias level_up_tp_cost skill_tp_cost
  109. def initialize(*args)
  110. level_up_init(*args)
  111. @skill_exp = {}
  112. @skill_level = {}
  113. increase_skill_exp(1)
  114. refresh
  115. end
  116. def change_exp(exp,show)
  117. level_up_change(exp,show)
  118. increase_item_exp(exp) if LVLUP::LEVEL_UP_ITEMS
  119. increase_skill_exp(exp) if LVLUP::LEVEL_UP_SKILLS
  120. end
  121. def increase_item_exp(exp)
  122. items = equips
  123. items.each do |item|
  124. next if item.nil?
  125. item.change_exp(exp)
  126. end
  127. end
  128. def increase_skill_exp(exp)
  129. skills.each do |skill|
  130. next if skill.nil?
  131. @skill_exp[skill.id] = 0 if @skill_exp[skill.id].nil?
  132. @skill_exp[skill.id] += exp * LVLUP.xpratio(@note)
  133. while @skill_exp[skill.id] > get_skill_level(skill.id) * 100
  134. @skill_level[skill.id] += 1
  135. @skill_exp[skill.id] -= @skill_level[skill.id] * 100
  136. @skill_level[skill.id] = LVLUP.mlvl(@note) if @skill_level[skill.id] > LVLUP.mlvl(@note)
  137. end
  138. end
  139. end
  140. def get_skill_level(id)
  141. @skill_level[id] = 1 if @skill_level[id].nil?
  142. @skill_level[id]
  143. end
  144. def get_skill_exp_rate(id)
  145. @skill_exp[id] / (@skill_level[id] * 100)
  146. end
  147. def skill_mp_cost(skill)
  148. return level_up_mp_cost(skill) if !LVLUP::LEVEL_UP_SKILLS
  149. (skill.mp_cost * mcr * (1 + get_skill_level(skill.id) * LVLUP.mpcost(@note))).to_i
  150. end
  151. def skill_tp_cost(skill)
  152. return level_up_tp_cost(skill) if !LVLUP::LEVEL_UP_SKILLS
  153. (skill.tp_cost * (1 + get_skill_level(skill.id) * LVLUP.mpcost(@note))).to_i
  154. end
  155. def slvl(id)
  156. get_skill_level(id)
  157. end
  158. def make_damage_value(user,item)
  159. $last_actor_skill = item.id
  160. level_up_mdv(user,item)
  161. end
  162. end
  163.  
  164. class Game_Party
  165. alias lvl_initialize initialize
  166. def initialize
  167. lvl_initialize
  168. @saved_weapons = $data_weapons
  169. @saved_armors = $data_armors
  170. end
  171. attr_accessor :saved_weapons
  172. attr_accessor :saved_armors
  173. def gain_item(item, amount, include_equip = false)
  174. container = item_container(item.class)
  175. return unless container
  176. last_number = item_number(item)
  177. if item.is_a?(RPG::EquipItem) && last_number != 0
  178. data = $data_weapons if item.is_a?(RPG::Weapon)
  179. data = $data_armors if item.is_a?(RPG::Armor)
  180. item = Marshal.load(Marshal.dump(data[item.id]))
  181. data.push(item)
  182. item.id = data.size
  183. end
  184. last_number = item_number(item)
  185. new_number = last_number + amount
  186. container[item.id] = [[new_number, 0].max, max_item_number(item)].min
  187. container.delete(item.id) if container[item.id] == 0
  188. if include_equip && new_number < 0
  189. discard_members_equip(item, -new_number)
  190. end
  191. $game_map.need_refresh = true
  192. end
  193. end
  194.  
  195. class Scene_Load
  196. alias lvl_on_load_success on_load_success
  197. def on_load_success
  198. lvl_on_load_success
  199. $data_weapons = $game_party.saved_weapons
  200. $data_armors = $game_party.saved_armors
  201. end
  202. end
  203.  
  204. class RPG::UsableItem::Damage
  205. alias level_up_eval eval
  206. def eval(a, b, v)
  207. return level_up_eval(a,b,v) if !LVLUP::LEVEL_UP_SKILLS
  208. val = [Kernel.eval(@formula), 0].max * sign rescue 0
  209. val *= (1 + a.slvl($last_actor_skill) * LVLUP.param(@note)) if a.is_a?(Game_Actor)
  210. val
  211. end
  212. end
  213.  
  214. class Window_Base
  215. alias level_up_din draw_item_name
  216. def draw_item_name(item, x, y, enabled = true, width = 172)
  217. return unless item
  218. if !LVLUP::LEVEL_UP_SKILLS && item.is_a?(RPG::Skill)
  219. return level_up_din(item,x,y,enabled,width)
  220. elsif !LVLUP::LEVEL_UP_ITEMS && (item.is_a?(RPG::Weapon) || item.is_a?(RPG::Armor))
  221. return level_up_din(item,x,y,enabled,width)
  222. end
  223. draw_icon(item.icon_index, x, y, enabled)
  224. change_color(normal_color, enabled)
  225. if item.is_a?(RPG::EquipItem) && LVLUP::DRAW_EXP_BAR
  226. draw_item_gauge(item,x,y)
  227. elsif item.is_a?(RPG::Skill) && LVLUP::DRAW_EXP_BAR && @actor
  228. draw_skill_gauge(item,x,y)
  229. end
  230. change_color(item.color, enabled) if Module.const_defined?(:AFFIXES)
  231. text = item.name
  232. text = eval(LVLUP::ITEM_NAME) if !item.is_a?(RPG::Skill) && !item.is_a?(RPG::Item)
  233. text = eval(LVLUP::SKILL_NAME) if item.is_a?(RPG::Skill) && @actor
  234. draw_text(x + 24, y, width, line_height, text)
  235. change_color(normal_color, enabled)
  236. end
  237. def draw_item_gauge(item,x,y)
  238. fill_w = (24 * item.exp_rate).to_i
  239. gauge_y = y + line_height - 8
  240. contents.fill_rect(x, gauge_y, 24, 6, gauge_back_color)
  241. contents.gradient_fill_rect(x, gauge_y, fill_w, 6, Color.new(0,255,0), Color.new(75,200,75))
  242. contents.font.size = 14
  243. draw_text(x+6,y+line_height-12,36,14,(item.exp_rate * 100).to_i.to_s + "%")
  244. contents.font.size = Font.default_size
  245. end
  246. def draw_skill_gauge(item,x,y)
  247. exp_rate = @actor.get_skill_exp_rate(item.id)
  248. fill_w = (24 * exp_rate).to_i
  249. gauge_y = y + line_height - 8
  250. contents.fill_rect(x, gauge_y, 24, 6, gauge_back_color)
  251. contents.gradient_fill_rect(x, gauge_y, fill_w, 6, Color.new(0,255,0), Color.new(75,200,75))
  252. contents.font.size = 14
  253. draw_text(x+6,y+line_height-12,36,14,(exp_rate * 100).to_i.to_s + "%")
  254. contents.font.size = Font.default_size
  255. end
  256. end
Advertisement
Add Comment
Please, Sign In to add comment