Advertisement
Demintika

DMTK - Weapon Mastery

Jan 11th, 2015
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 22.71 KB | None | 0 0
  1. module DMTK
  2.   module EQUIPMENTS
  3.    
  4.     WEAPONS =  []
  5.     #--------------------------------------------------------------------------
  6.     # *
  7.     #--------------------------------------------------------------------------
  8.     WEAPONS[1] = {#Dagger
  9.     :icon => 150,
  10.     :param6 => [nil,  2,3,4,5,6,7,8,9],
  11.     :learn =>  [nil,nil,3,4,5,6,7,8],
  12.     }
  13.     WEAPONS[2] = {#Sword
  14.     :icon => 147
  15.     }
  16.     WEAPONS[3] = {#Bow
  17.     :icon => 149
  18.     }
  19.     WEAPONS[4] = {#Staff
  20.     :icon => 152
  21.     }
  22.     WEAPONS[5] = {#Claw
  23.     :icon => 145
  24.     }
  25.     WEAPONS[6] = {#Spear
  26.     :icon => 146
  27.     }
  28.     WEAPONS[7] = {#Gun
  29.     :icon => 153
  30.     }
  31.     WEAPONS[8] = {#Book
  32.     :icon => 226
  33.     }
  34.     WEAPONS[9] = {#Scythe
  35.     :icon => 155
  36.     }
  37.     WEAPONS[10]= {#Axe
  38.     :icon => 144
  39.     }
  40.     WEAPONS[11]= {#Throw
  41.     :icon => 154
  42.     }
  43.     WEAPONS[12]= {#Mace
  44.     :icon => 151
  45.     }
  46.     #--------------------------------------------------------------------------
  47.     # *
  48.     #--------------------------------------------------------------------------
  49.     W_LEVEL_MAX = 8
  50.               # 0   1   2   3   4   5   6    7     8
  51.     W_LEVEL = ['F','E','D','C','B','A','S','SS','SSS']
  52.     WL_COLOR= [  8,  7, 30, 13, 9,  11, 17,  12,   18]
  53.   end
  54. end
  55.  
  56. #==============================================================================
  57. # * Game_Actor
  58. #==============================================================================
  59. class Game_Actor < Game_Battler
  60.  
  61.   #--------------------------------------------------------------------------
  62.   # *
  63.   #--------------------------------------------------------------------------
  64.   alias dmtk_mastery_initialize initialize
  65.   def initialize(*arg)
  66.     dmtk_mastery_initialize(*arg)
  67.     dmtk_mastery_init
  68.   end
  69.  
  70.   #--------------------------------------------------------------------------
  71.   # *
  72.   #--------------------------------------------------------------------------
  73.   def dmtk_mastery_init
  74.     @w_mastery = [0] * mastery_size
  75.     @mastery_rank = [0] * mastery_size
  76.   end
  77.  
  78.   #--------------------------------------------------------------------------
  79.   # *
  80.   #--------------------------------------------------------------------------
  81.   def mastery_size
  82.     [DMTK::EQUIPMENTS::WEAPONS.size,$data_system.weapon_types.size].min
  83.   end
  84.  
  85.   #--------------------------------------------------------------------------
  86.   # *
  87.   #--------------------------------------------------------------------------
  88.   def gain_mastery_exp(id, amount)
  89.     return if @mastery_rank[id] == mastery_rank_max
  90.     @w_mastery[id] += amount
  91.     while @w_mastery[id] >= mastery_exp_next(id) && @mastery_rank[id] < mastery_rank_max
  92.       mastery_rank_lvlup(id)
  93.       if @mastery_rank[id] == mastery_rank_max
  94.         @w_mastery[id] = mastery_exp_next(id)
  95.       end
  96.     end
  97.   end
  98.  
  99.   #--------------------------------------------------------------------------
  100.   # *
  101.   #--------------------------------------------------------------------------
  102.   def mastery_rank_lvlup(id)
  103.     @mastery_rank[id] += 1
  104.     arr = DMTK::EQUIPMENTS::WEAPONS[id][:learn]
  105.     return if arr.nil?
  106.     return if arr[@mastery_rank[id]].nil?
  107.     learn_skill(arr[@mastery_rank[id]])
  108.   end
  109.  
  110.   #--------------------------------------------------------------------------
  111.   # *
  112.   #--------------------------------------------------------------------------
  113.   def mastery_exp_for_rank(rank)
  114.     (2 ** rank) * 10
  115.   end
  116.   def mastery_exp_next(w_id)
  117.     mastery_exp_for_rank(@mastery_rank[w_id])
  118.   end
  119.   def mastery_exp_need(w_id)
  120.     mastery_exp_next(w_id) - mastery_exp(w_id)
  121.   end
  122.   def mastery_exp_current(w_id)
  123.     mastery_exp(w_id) - mastery_exp_for_rank(mastery_rank(w_id) - 1)
  124.   end
  125.   def mastery_exp_rate(w_id)
  126.     mastery_exp_current(w_id).to_f / mastery_exp_next(w_id).to_f
  127.   end
  128.   #--------------------------------------------------------------------------
  129.   # *
  130.   #--------------------------------------------------------------------------
  131.   def mastery_exp(w_id)
  132.     @w_mastery[w_id]
  133.   end
  134.   def mastery_rank(w_id)
  135.     @mastery_rank[w_id]
  136.   end
  137.   def mastery_rank_txt(w_id)
  138.     DMTK::EQUIPMENTS::W_LEVEL[mastery_rank(w_id)]
  139.   end
  140.   def mastery_rank_max
  141.     DMTK::EQUIPMENTS::W_LEVEL_MAX
  142.   end
  143.   #--------------------------------------------------------------------------
  144.   # *
  145.   #--------------------------------------------------------------------------
  146.   def wtypes_equipped
  147.     (1..mastery_size).to_a.select {|i| wtype_equipped?(i)}
  148.   end
  149.  
  150.   #--------------------------------------------------------------------------
  151.   # *
  152.   #--------------------------------------------------------------------------
  153.   alias dmtk_mastery_param_plus param_plus
  154.   def param_plus(param_id)
  155.     dmtk_mastery_param_plus(param_id) + mastery_param(param_id)
  156.   end
  157.  
  158.   #--------------------------------------------------------------------------
  159.   # *
  160.   #--------------------------------------------------------------------------
  161.   def mastery_param(param_id)
  162.     sym = ("param" + param_id.to_s).to_sym
  163.     wtypes_equipped.inject(0) {|r,wtype|
  164.       arr = DMTK::EQUIPMENTS::WEAPONS[wtype][sym]
  165.       if arr
  166.         r += arr[mastery_rank(wtype)]
  167.       else
  168.         r
  169.       end
  170.     }
  171.   end
  172.  
  173.   #--------------------------------------------------------------------------
  174.   # *
  175.   #--------------------------------------------------------------------------
  176.   alias dmtk_mastery_added_skills added_skills
  177.   def added_skills
  178.     dmtk_mastery_added_skills | mastery_added_skills
  179.   end
  180.  
  181.   #--------------------------------------------------------------------------
  182.   # *
  183.   #--------------------------------------------------------------------------
  184.   def mastery_added_skills
  185.     wtypes_equipped.inject([]) {|r,wtype|
  186.     arr = DMTK::EQUIPMENTS::WEAPONS[wtype][:added_skills]
  187.     if arr && arr[mastery_rank(wtype)]
  188.       r |= arr[0..mastery_rank(wtype)].compact
  189.     else
  190.       r
  191.     end
  192.     }
  193.   end
  194.  
  195. end
  196.  
  197. #==============================================================================
  198. # * Window_EquipSlot
  199. #==============================================================================
  200. class Window_EquipSlot < Window_Selectable
  201.   #--------------------------------------------------------------------------
  202.   # * Public Instance Variables
  203.   #--------------------------------------------------------------------------
  204.  
  205.   #--------------------------------------------------------------------------
  206.   # * Object Initialization
  207.   #--------------------------------------------------------------------------
  208.   def initialize(x, y, width, height)
  209.     super(x, y, width, height)
  210.     @actor = nil
  211.     refresh
  212.     @last_index = 0
  213.   end
  214.  
  215.   #--------------------------------------------------------------------------
  216.   # * Deselect Item
  217.   #--------------------------------------------------------------------------
  218.   def unselect
  219.     @last_index = index
  220.     super
  221.   end
  222.  
  223.   #--------------------------------------------------------------------------
  224.   # * Select Last
  225.   #--------------------------------------------------------------------------
  226.   def select_last
  227.     select(@last_index) unless @last_index < 0
  228.     @last_index = -1
  229.   end
  230.  
  231.   #--------------------------------------------------------------------------
  232.   # *
  233.   #--------------------------------------------------------------------------
  234.   def activate
  235.     select_last
  236.     super
  237.   end
  238.  
  239.   #--------------------------------------------------------------------------
  240.   # * Set Status Window
  241.   #--------------------------------------------------------------------------
  242.   def status_window=(status_window)
  243.     @status_window = status_window
  244.     call_update_help
  245.   end
  246.   #--------------------------------------------------------------------------
  247.   # * Set Item Window
  248.   #--------------------------------------------------------------------------
  249.   def item_window=(item_window)
  250.     @item_window = item_window
  251.     update
  252.   end
  253.   #--------------------------------------------------------------------------
  254.   # * Update Help Text
  255.   #--------------------------------------------------------------------------
  256.   def update_help
  257.     super
  258.   end
  259.  
  260.   #--------------------------------------------------------------------------
  261.   # *
  262.   #--------------------------------------------------------------------------
  263.   def process_handling
  264.     super
  265.     return unless open? && active
  266.     call_handler(:shift) if Input.repeat?(:SHIFT)
  267.   end
  268.  
  269. end
  270. #==============================================================================
  271. # * Window_EquipItem
  272. #==============================================================================
  273. class Window_EquipItem < Window_ItemList
  274.   #--------------------------------------------------------------------------
  275.   # * Public Instance Variables
  276.   #--------------------------------------------------------------------------
  277.   attr_writer :status_window
  278.   #--------------------------------------------------------------------------
  279.   # *
  280.   #--------------------------------------------------------------------------
  281.   def temp_actor
  282.     @status_window.temp_actor
  283.   end
  284.  
  285.   #--------------------------------------------------------------------------
  286.   # *
  287.   #--------------------------------------------------------------------------
  288.   def call_update_help
  289.     update_help if active && @status_window
  290.   end
  291.  
  292.   #--------------------------------------------------------------------------
  293.   # * Update Help Text
  294.   #--------------------------------------------------------------------------
  295.   def update_help
  296.     super
  297.     if @actor && @status_window
  298.       temp_actor.force_change_equip(@slot_id, item)
  299.       call_handler(:refresh_all)
  300.       @active = true
  301.     end
  302.   end
  303. end
  304.  
  305. #==============================================================================
  306. # * Window_ActorMastery
  307. #==============================================================================
  308. class Window_ActorMastery < Window_Selectable
  309.  
  310.   #--------------------------------------------------------------------------
  311.   # *
  312.   #--------------------------------------------------------------------------
  313.   def initialize(actor)
  314.     super(0,0,160,Graphics.height)
  315.     @actor = actor
  316.     refresh
  317.     activate
  318.   end
  319.    
  320.   #--------------------------------------------------------------------------
  321.   # *
  322.   #--------------------------------------------------------------------------
  323.   def actor=(actor)
  324.     @actor = actor
  325.     refresh
  326.   end
  327.   def help_window=(help_window)
  328.     @help_window = help_window
  329.     @help_window.select(index)
  330.   end
  331.  
  332.   #--------------------------------------------------------------------------
  333.   # *
  334.   #--------------------------------------------------------------------------
  335.   def update
  336.     last_index = index
  337.     super
  338.     if last_index != index && @help_window
  339.       @help_window.select(index)
  340.     end
  341.   end
  342.  
  343.   #--------------------------------------------------------------------------
  344.   # *
  345.   #--------------------------------------------------------------------------
  346.   def refresh
  347.     contents.clear
  348.     draw_weapons if @actor
  349.   end
  350.    
  351.   #--------------------------------------------------------------------------
  352.   # *
  353.   #--------------------------------------------------------------------------
  354.   def size
  355.     DMTK::EQUIPMENTS::WEAPONS.size - (include_barehand? ? 0 : 1)
  356.   end
  357.   #--------------------------------------------------------------------------
  358.   # *
  359.   #--------------------------------------------------------------------------
  360.   alias item_max size
  361.   #--------------------------------------------------------------------------
  362.   # *
  363.   #--------------------------------------------------------------------------
  364.   def col_max
  365.     1
  366.   end
  367.   #--------------------------------------------------------------------------
  368.   # *
  369.   #--------------------------------------------------------------------------
  370.   def include_barehand?
  371.     !DMTK::EQUIPMENTS::WEAPONS[0].nil?
  372.   end
  373.   #--------------------------------------------------------------------------
  374.   # *
  375.   #--------------------------------------------------------------------------
  376.   def draw_weapons
  377.     DMTK::EQUIPMENTS::WEAPONS.size.times {|idx|
  378.       if include_barehand?
  379.         i = idx
  380.       else
  381.         next if idx == 0
  382.         i = idx - 1
  383.       end
  384.       contents.fill_rect(icon_x(i), icon_y(i), table_width - 4, table_height - 4, fill_color)
  385.       draw_level(i,idx)
  386.       draw_icon(w_icon(idx), icon_x(i), icon_y(i))
  387.       change_color(system_color)
  388.       draw_text(icon_x(i) + 26, icon_y(i), table_width-24, line_height, w_text(idx))
  389.     }
  390.   end
  391.  
  392.   #--------------------------------------------------------------------------
  393.   # *
  394.   #--------------------------------------------------------------------------
  395.   def draw_level(i,idx)
  396.     lvl = @actor.mastery_rank(idx)
  397.     change_color(text_color(DMTK::EQUIPMENTS::WL_COLOR[lvl]))
  398.     txt = @actor.mastery_rank_txt(idx)
  399.     draw_text(icon_x(i)+2, icon_y(i), table_width-4, line_height, txt, 2)
  400.     draw_gauge(icon_x(i)+2, gauge_y(i), table_width-8, exprate(idx), text_color(0), text_color(1))
  401.   end
  402.  
  403.   #--------------------------------------------------------------------------
  404.   # *
  405.   #--------------------------------------------------------------------------
  406.   def exprate(idx)
  407.     @actor.mastery_exp_rate(idx)
  408.   end
  409.   #--------------------------------------------------------------------------
  410.   # * Get Color of Vertical Line
  411.   #--------------------------------------------------------------------------
  412.   def fill_color
  413.     color = text_color(0)
  414.     color.alpha = 48
  415.     color
  416.   end
  417.  
  418.   #--------------------------------------------------------------------------
  419.   # *
  420.   #--------------------------------------------------------------------------
  421.   def w_icon(i)
  422.     return DMTK::EQUIPMENTS::WEAPONS[i][:icon]
  423.   end
  424.  
  425.   #--------------------------------------------------------------------------
  426.   # *
  427.   #--------------------------------------------------------------------------
  428.   def w_text(i)
  429.     return $data_system.weapon_types[i]
  430.   end
  431.  
  432.   #--------------------------------------------------------------------------
  433.   # *
  434.   #--------------------------------------------------------------------------
  435.   def icon_x(i)
  436.     2
  437.   end
  438.   def icon_y(i)
  439.     2 + line_height * 2 * i
  440.   end
  441.   def gauge_y(i)
  442.     16 + line_height * 2 * i
  443.   end
  444.   def table_width
  445.     contents_width
  446.   end
  447.   def table_height
  448.     line_height*2
  449.   end
  450.   def contents_height
  451.     table_height * size
  452.   end
  453.   alias item_width table_width
  454.   alias item_height table_height
  455.   #--------------------------------------------------------------------------
  456.   # *
  457.   #--------------------------------------------------------------------------
  458.   def select(idx)
  459.     super(idx)
  460.     @weaponmastery_window.set_w_id(idx) if @weaponmastery_window
  461.   end
  462.  
  463.   #--------------------------------------------------------------------------
  464.   # *
  465.   #--------------------------------------------------------------------------
  466.   def weaponmastery_window=(w)
  467.     @weaponmastery_window = w
  468.   end
  469.  
  470.   #--------------------------------------------------------------------------
  471.   # * Actor Settings
  472.   #--------------------------------------------------------------------------
  473.   def actor=(actor)
  474.     return if @actor == actor
  475.     @actor = actor
  476.     refresh
  477.   end
  478. end
  479. #==============================================================================
  480. # * Window_WeaponMastery
  481. #==============================================================================
  482. class Window_WeaponMastery < Window_Selectable
  483.  
  484.   def initialize(x,y)
  485.     @lines = 1
  486.     super(x, y, Graphics.width - x, Graphics.height - y)
  487.     clear_texts
  488.   end
  489.  
  490.   #--------------------------------------------------------------------------
  491.   # *
  492.   #--------------------------------------------------------------------------
  493.   def contents_height
  494.     line_height * @lines
  495.   end
  496.  
  497.   #--------------------------------------------------------------------------
  498.   # *
  499.   #--------------------------------------------------------------------------
  500.   def clear_texts
  501.     @lines = level_max
  502.     @texts = Array.new(level_max, '')
  503.   end
  504.  
  505.   #--------------------------------------------------------------------------
  506.   # *
  507.   #--------------------------------------------------------------------------
  508.   def level_max
  509.     DMTK::EQUIPMENTS::W_LEVEL_MAX + 1
  510.   end
  511.  
  512.   #--------------------------------------------------------------------------
  513.   # *
  514.   #--------------------------------------------------------------------------
  515.   def set_w_id(id)
  516.     @w_id = id
  517.     refresh
  518.   end
  519.  
  520.   #--------------------------------------------------------------------------
  521.   # *
  522.   #--------------------------------------------------------------------------
  523.   def w_id
  524.     if include_barehand?
  525.       @w_id
  526.     else
  527.       @w_id + 1
  528.     end
  529.   end
  530.  
  531.   #--------------------------------------------------------------------------
  532.   # *
  533.   #--------------------------------------------------------------------------
  534.   def include_barehand?
  535.     !DMTK::EQUIPMENTS::WEAPONS[0].nil?
  536.   end
  537.  
  538.   #--------------------------------------------------------------------------
  539.   # *
  540.   #--------------------------------------------------------------------------
  541.   def refresh
  542.     contents.clear
  543.     draw_informations if @index
  544.   end
  545.  
  546.   #--------------------------------------------------------------------------
  547.   # *
  548.   #--------------------------------------------------------------------------
  549.   def draw_informations
  550.     create_texts
  551.     create_contents
  552.     draw_text_ex(0,0,texts)
  553.   end
  554.  
  555.   #--------------------------------------------------------------------------
  556.   # *
  557.   #--------------------------------------------------------------------------
  558.   def create_texts
  559.     clear_texts
  560.     arr = DMTK::EQUIPMENTS::WEAPONS[w_id]
  561.   #--------------------------------------------------------------------------
  562.     learn = arr[:learn]
  563.     if learn
  564.       level_max.times {|i|
  565.         next unless learn[i]
  566.         skill = $data_skills[learn[i]]
  567.         @texts[i] += sprintf("  Learn Skill: \eI[%d]%s\n",skill.icon_index,skill.name)
  568.         @lines += 1
  569.       }
  570.     end
  571.   #--------------------------------------------------------------------------
  572.     added_skills = arr[:added_skills]
  573.     if added_skills
  574.       level_max.times {|i|
  575.         next unless added_skills[i]
  576.         skill = $data_skills[added_skills[i]]
  577.         @texts[i] += sprintf("  Enable to use Skill: \eI[%d]%s\n",skill.icon_index,skill.name)
  578.         @lines += 1
  579.       }
  580.     end
  581.   #--------------------------------------------------------------------------
  582.     8.times {|param_id|
  583.       sym = ("param" + param_id.to_s).to_sym
  584.       param_plus = arr[sym]
  585.       next unless param_plus
  586.       level_max.times {|i|
  587.         if param_plus[i]
  588. @texts[i] += sprintf("  %s + %d when equip %s\n",Vocab::param(param_id),param_plus[i],w_text)
  589.           @lines += 1
  590.         end
  591.       }
  592.     }
  593.   #--------------------------------------------------------------------------
  594.   end
  595.  
  596.   #--------------------------------------------------------------------------
  597.   # *
  598.   #--------------------------------------------------------------------------
  599.   def texts
  600.     i = -1
  601.     @texts.inject("") {|r,t|
  602.       i += 1
  603.       r += sprintf("At Rank %s:\n%s",rank_text(i),t)
  604.     }
  605.   end
  606.  
  607.   #--------------------------------------------------------------------------
  608.   # *
  609.   #--------------------------------------------------------------------------
  610.   def rank_text(rank)
  611.     sprintf("\eC[%d]%s\eC[0]", rank_color(rank), DMTK::EQUIPMENTS::W_LEVEL[rank])
  612.   end
  613.   def rank_color(rank)
  614.     DMTK::EQUIPMENTS::WL_COLOR[rank]
  615.   end
  616.   def w_text
  617.     $data_system.weapon_types[w_id]
  618.   end
  619.  
  620.   #--------------------------------------------------------------------------
  621.   # *
  622.   #--------------------------------------------------------------------------
  623.   def item_max
  624.     @lines
  625.   end
  626.  
  627. end
  628.  
  629. #==============================================================================
  630. # * Scene_Mastery
  631. #==============================================================================
  632. class Scene_Mastery < Scene_MenuBase
  633.   #--------------------------------------------------------------------------
  634.   # *
  635.   #--------------------------------------------------------------------------
  636.   def start
  637.     super
  638.     create_actormastery_window
  639.     create_status_window
  640.     create_weaponmastery_window
  641.   end
  642.  
  643.   #--------------------------------------------------------------------------
  644.   # *
  645.   #--------------------------------------------------------------------------
  646.   def create_actormastery_window
  647.     @actormastery_window = Window_ActorMastery.new(@actor)
  648.     @actormastery_window.set_handler(:ok,       method(:on_weapon_ok))
  649.     @actormastery_window.set_handler(:cancel,   method(:return_scene))
  650.     @actormastery_window.set_handler(:pagedown, method(:next_actor))
  651.     @actormastery_window.set_handler(:pageup,   method(:prev_actor))
  652.     @actormastery_window.viewport = @viewport
  653.   end
  654.  
  655.   #--------------------------------------------------------------------------
  656.   # * Create Status Window
  657.   #--------------------------------------------------------------------------
  658.   def create_status_window
  659.     @status_window = Window_SkillStatus.new(160, 0)
  660.     @status_window.viewport = @viewport
  661.     @status_window.actor = @actor
  662.   end
  663.  
  664.   #--------------------------------------------------------------------------
  665.   # *
  666.   #--------------------------------------------------------------------------
  667.   def create_weaponmastery_window
  668.     x = @actormastery_window.width
  669.     y = @status_window.height
  670.     @weaponmastery_window = Window_WeaponMastery.new(x,y)
  671.     @weaponmastery_window.viewport = @viewport
  672.     @weaponmastery_window.set_handler(:cancel,   method(:on_weapon_cancel))
  673.     @actormastery_window.weaponmastery_window = @weaponmastery_window
  674.     @actormastery_window.select(0)
  675.   end
  676.  
  677.   #--------------------------------------------------------------------------
  678.   # *
  679.   #--------------------------------------------------------------------------
  680.   def on_weapon_ok
  681.     @weaponmastery_window.activate
  682.     @weaponmastery_window.select(0)
  683.   end
  684.  
  685.   #--------------------------------------------------------------------------
  686.   # *
  687.   #--------------------------------------------------------------------------
  688.   def on_weapon_cancel
  689.     @actormastery_window.activate
  690.     @weaponmastery_window.unselect
  691.   end
  692.  
  693.   #--------------------------------------------------------------------------
  694.   # * Change Actors
  695.   #--------------------------------------------------------------------------
  696.   def on_actor_change
  697.     @actormastery_window.actor = @actor
  698.     @status_window.actor = @actor
  699.   end
  700. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement