Advertisement
gerkrt

RPGXP - ENG - Effectivity ratings(weap, skills,etc)

Sep 16th, 2011
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 14.87 KB | None | 0 0
  1. #==============================================================================
  2. # Effectivity ratings for skills, defenses and attacks
  3. # By gerkrt/gerrtunk
  4. # Version: 1.5
  5. # License: GPL, credits
  6. # Date: 09/07/2011
  7. # For the latests updates or bugs fixes of this script check here:
  8. # http://usuarios.multimania.es/kisap/english_list.html
  9. #==============================================================================
  10.  
  11. =begin
  12.  
  13. ---------INTRODUCTION----------
  14.  
  15. This script gives a lost option expanded from 2k3, where you could create
  16. elements for equipment that defined it general effectivity in a scale of rates.
  17.  
  18. Now you can set it for classes also, and for skills too.
  19.  
  20. --------INSTRUCTIONS------------
  21.  
  22. You have to define two things:
  23. -Group armors, skills... by a name.
  24.   Weapons_groups = {
  25.    
  26.     'Great Axe' => [1, 10],
  27.     'Bow' => [[4,5]]
  28.   }
  29.  
  30. 'Group name' => ['weapon_id1, weapon_id2, etc],
  31.  
  32.  
  33. -Make skills, weapons, etc scale ratings.
  34.  
  35.   Weapons_skills_ratings  = {
  36.     'Great Axe' => [0.10, 0.20],
  37.     'Bow' => [0.20, 0.40, 0.60, 0.80]
  38.   }
  39.  
  40. 'Group name' => ['rate for rating1, for 2, etc],
  41.  
  42. See that you need to add a entry for each group defining the scale ratings,
  43. and the group.
  44.  
  45. What more you need? You have to define how effictevily the battler will use
  46. the scale. For example, adding entries of that groups in some classes with
  47. the effecitivety value:
  48.  
  49.   Classes_ratings = {
  50.    1 => {
  51.      'Great Axe' => 1,
  52.      'Bow' => 1
  53.     },
  54.    
  55.    2 => {
  56.      'Mag' => 2
  57.     },
  58.   }
  59.  
  60. Then you have to add to classes ratings or actors ratings the group name with
  61. the rating index value:
  62.  
  63. 'Group name' => rate index,
  64.  
  65. The rate index number extract the values you store in Weapons_skills_ratings, like if
  66. it used the 'A', 'B', etc, but with numbers. This works in the natural order, but
  67. using a -1 index: it starts with index 0, 1, 2, 3, 4, etc. You can customitze each
  68. scale at your will, in power or number of entries.
  69.  
  70. In this case, for example, for class 1:
  71.    1 => {
  72.      'Great Axe' => 1, # 0.20
  73.      'Bow' => 1, # 0.40
  74.     },
  75.  
  76. Then the value in the rating is multiplied with the damage. If there are values
  77. of actor and class, first these two are multiplied, and then with the damage.
  78.  
  79. This means that a 0.10 is a 10% and a 1.4 a 140%
  80.  
  81. Note that if you put a invalid index in classes or actors ratings
  82. it will give you a error.
  83.  
  84. The other things are pretty straightforward from here, they just use the same
  85. methods and vocablury but for others things: skills, defense, actors, etc.
  86.  
  87. ----CONFIGURE THE MODE-------
  88.  
  89. Set the mode used by the script: 'Both' classes and and actors, 'Only classes'
  90. and 'Only actors'. You have to add that 'words' in that variable:
  91.  
  92. Use_class_actors = 'Both'
  93.  
  94. =end
  95.  
  96.  
  97.  
  98.  
  99. module Wep
  100.   # Set the mode used by the script: 'Both' classes and and actors, 'Only classes'
  101.   # and 'Only actors'.
  102.   Use_class_actors = 'Both'
  103.  
  104.  
  105.   Weapons_groups = {
  106.                    
  107.     'Great Axe' => [1, 10],
  108.     'Bow' => [[4,5]]
  109.   }
  110.  
  111.   Weapons_skills_ratings  = {
  112.     'Great Axe' => [0.10, 0.20],
  113.     'Bow' => [0.20, 0.40, 0.60, 0.80, 1.00, 1.20, 1.40]
  114.   }
  115.  
  116.   Skills_groups = {
  117.                    
  118.     'Mag' => [7],
  119.   }
  120.  
  121.   Skills_skills_ratings  = {
  122.     'Mag' => [0.10, 0.20],
  123.   }
  124.  
  125.  
  126.   Armors_groups = {
  127.                    
  128.     'Base' => [13],
  129.     'Test' => [1]
  130.   }
  131.  
  132.   Armors_skills_ratings  = {
  133.     'Base' => [0.10, 0.20, 0.50],
  134.     'Test'=> [0.10, 0.13, 0.50]
  135.    
  136.   }
  137.  
  138.   Classes_ratings = {
  139.    1 => {
  140.      'Great Axe' => 1,
  141.      'Bow' => 1,
  142.      'Base' => 2,
  143.      'Mag' => 1,
  144.      'Test' => 1
  145.     }
  146.  
  147.   }
  148.  
  149.    Actors_ratings = {
  150.    1 => {
  151.      'Great Axe' => 0,
  152.      'Bow' => 1,
  153.     }
  154.  
  155.   }
  156.    
  157. end
  158.  
  159.  
  160. class Game_Actor
  161.  
  162.   #--------------------------------------------------------------------------
  163.   # * Attack Rate
  164.   #--------------------------------------------------------------------------  
  165.   def attack_rate
  166.     # Search mark
  167.     encounter = false
  168.     class_val = 0
  169.     actor_val = 0
  170.     val = 0
  171.    
  172.     # Search if equipped weapons have rate
  173.     for key,  value in Wep::Weapons_groups
  174.       if value.include?(self.weapon_id)
  175.         encounter = true
  176.         # Class rate
  177.         if Wep::Classes_ratings[self.class_id] != nil and Wep::Classes_ratings[@class_id][key] != nil
  178.           rate = Wep::Classes_ratings[self.class_id][key]
  179.           #p 'rate', rate
  180.           class_val = Wep::Weapons_skills_ratings[key][rate]
  181.           #p 'classval', class_val
  182.          
  183.         end
  184.        
  185.         if Wep::Actors_ratings[@actor_id] != nil and Wep::Actors_ratings[@actor_id][key] != nil
  186.           # Actor rate
  187.           rate = Wep::Actors_ratings[@actor_id][key]
  188.           actor_val = Wep::Weapons_skills_ratings[key][rate]
  189.         end
  190.       end
  191.     end
  192.    
  193.  
  194.     # Check mode
  195.     if Wep::Use_class_actors == 'Both'
  196.       if actor_val == 0
  197.         val = class_val
  198.       elsif class_val == 0
  199.         val = actor_val
  200.       else
  201.         val = class_val * actor_val
  202.       end
  203.       #p 'bo', val
  204.     elsif Wep::Use_class_actors == 'Only classes'
  205.       val = class_val
  206.       #p'clas'
  207.     else
  208.       val = actor_val
  209.     end
  210.    
  211.     # Make default if no value used
  212.     val = 1.00 if encounter == false
  213.     #p val, class_val, actor_val
  214.     return val
  215.   end
  216.  
  217.   #--------------------------------------------------------------------------
  218.   # * Skill Rate
  219.   #--------------------------------------------------------------------------
  220.   def skill_rate(skill_id)
  221.     # Search mark
  222.     encounter = false
  223.     class_val = 0
  224.     actor_val = 0
  225.     val = 0
  226.    
  227.     # Search if equipped weapons have rate
  228.     for key,  value in Wep::Skills_groups
  229.       if value.include?(skill_id)
  230.         #p 'encounter', Wep::Classes_ratings[self.class_id], Wep::Classes_ratings[self.class_id][key]
  231.         encounter = true
  232.         # Class rate
  233.         if Wep::Classes_ratings[self.class_id] != nil and Wep::Classes_ratings[@class_id][key] != nil
  234.           rate = Wep::Classes_ratings[self.class_id][key]
  235.           #p 'rate', rate,Wep::Skills_skills_ratings[key], key
  236.           class_val = Wep::Skills_skills_ratings[key][rate]
  237.          
  238.           #p 'classval', class_val
  239.          
  240.         end
  241.        
  242.         if Wep::Actors_ratings[@actor_id] != nil and Wep::Actors_ratings[@actor_id][key] != nil
  243.           # Actor rate
  244.           rate = Wep::Actors_ratings[@actor_id][key]
  245.           actor_val = Wep::Skills_skills_ratings[key][rate]
  246.         end
  247.       end
  248.     end
  249.    
  250.  
  251.     # Check mode
  252.     if Wep::Use_class_actors == 'Both'
  253.       if actor_val == 0
  254.         val = class_val
  255.       elsif class_val == 0
  256.         val = actor_val
  257.       else
  258.         val = class_val * actor_val
  259.       end
  260.       #p 'bo', val
  261.     elsif Wep::Use_class_actors == 'Only classes'
  262.       val = class_val
  263.       #p'clas'
  264.     else
  265.       val = actor_val
  266.     end
  267.    
  268.     # Make default if no value used
  269.     val = 1.00 if encounter == false
  270.     #p val, class_val, actor_val
  271.     return val
  272.   end
  273.    
  274.  
  275.   #--------------------------------------------------------------------------
  276.   # * Defend Rate
  277.   #--------------------------------------------------------------------------
  278.   def defend_rate
  279.     # Search mark
  280.     encounter = false
  281.     class_val = 0
  282.     actor_val = 0
  283.     val = 0
  284.     arm_arr = [@armor1_id,@armor2_id,@armor3_id,@armor4_id ]
  285.    
  286.     for arm_id in arm_arr
  287.       # Search if equipped weapons have rate
  288.       for key,  value in Wep::Armors_groups
  289.         if value.include?(arm_id)        
  290.           encounter = true
  291.           # Class rate
  292.           if Wep::Classes_ratings[self.class_id] != nil and Wep::Classes_ratings[self.class_id][key] != nil
  293.             rate = Wep::Classes_ratings[self.class_id][key] and Wep::Classes_ratings[@class_id][key] != nil
  294.             #p 'rate', rate
  295.             class_val += Wep::Armors_skills_ratings[key][rate]
  296.             #p 'classval', class_val
  297.            
  298.           end
  299.          
  300.           if Wep::Actors_ratings[@actor_id] != nil and Wep::Actors_ratings[@actor_id][key] != nil
  301.             # Actor rate
  302.             rate = Wep::Actors_ratings[@actor_id][key]
  303.             #p rate
  304.             actor_val += Wep::Armors_skills_ratings[key][rate]
  305.           end
  306.         end
  307.       end
  308.      
  309.     end
  310.     # Check mode
  311.     if Wep::Use_class_actors == 'Both'
  312.       if actor_val == 0
  313.         val = class_val
  314.       elsif class_val == 0
  315.         val = actor_val
  316.       else
  317.         val = class_val * actor_val
  318.       end
  319.       #p 'both'
  320.     elsif Wep::Use_class_actors == 'Only classes'
  321.       val = class_val
  322.       #p'clas'
  323.     else
  324.       val = actor_val
  325.     end
  326.    
  327.     # Make default if no value used
  328.     val = 1.00 if encounter == false
  329.     #p val, class_val, actor_val
  330.     return val
  331.   end
  332.  
  333.  
  334.  
  335. end
  336.  
  337.  
  338. class Game_Battler
  339.  
  340.   #--------------------------------------------------------------------------
  341.   # * Apply Skill Effects
  342.   #     user  : the one using skills (battler)
  343.   #     skill : skill
  344.   #--------------------------------------------------------------------------
  345.   def skill_effect(user, skill)
  346.     # Clear critical flag
  347.     self.critical = false
  348.     # If skill scope is for ally with 1 or more HP, and your own HP = 0,
  349.     # or skill scope is for ally with 0, and your own HP = 1 or more
  350.     if ((skill.scope == 3 or skill.scope == 4) and self.hp == 0) or
  351.        ((skill.scope == 5 or skill.scope == 6) and self.hp >= 1)
  352.       # End Method
  353.       return false
  354.     end
  355.     # Clear effective flag
  356.     effective = false
  357.     # Set effective flag if common ID is effective
  358.     effective |= skill.common_event_id > 0
  359.     # First hit detection
  360.     hit = skill.hit
  361.     if skill.atk_f > 0
  362.       hit *= user.hit / 100
  363.     end
  364.     hit_result = (rand(100) < hit)
  365.     # Set effective flag if skill is uncertain
  366.     effective |= hit < 100
  367.     # If hit occurs
  368.     if hit_result == true
  369.       # Calculate power
  370.       power = skill.power + user.atk * skill.atk_f / 100
  371.       if power > 0
  372.         power -= self.pdef * skill.pdef_f / 200
  373.         power -= self.mdef * skill.mdef_f / 200
  374.         power = [power, 0].max
  375.       end
  376.       # Calculate rate
  377.       rate = 20
  378.       rate += (user.str * skill.str_f / 100)
  379.       rate += (user.dex * skill.dex_f / 100)
  380.       rate += (user.agi * skill.agi_f / 100)
  381.       rate += (user.int * skill.int_f / 100)
  382.       # Calculate basic damage
  383.       self.damage = power * rate / 20
  384.      
  385.       # Rating correction only for actors
  386.       if user.is_a? Game_Actor
  387.        self.damage *= user.skill_rate(skill.id)
  388.        self.damage = self.damage.to_i
  389.       end
  390.       # Rating defensive correction only for actors
  391.       if self.is_a? Game_Actor
  392.        self.damage *= self.defend_rate
  393.        self.damage = self.damage.to_i
  394.       end
  395.      
  396.       # Element correction
  397.       self.damage *= elements_correct(skill.element_set)
  398.       self.damage /= 100
  399.      
  400.       # If damage value is strictly positive
  401.       if self.damage > 0
  402.         # Guard correction
  403.         if self.guarding?
  404.           self.damage /= 2
  405.         end
  406.       end
  407.       # Dispersion
  408.       if skill.variance > 0 and self.damage.abs > 0
  409.         amp = [self.damage.abs * skill.variance / 100, 1].max
  410.         self.damage += rand(amp+1) + rand(amp+1) - amp
  411.       end
  412.       # Second hit detection
  413.       eva = 8 * self.agi / user.dex + self.eva
  414.       hit = self.damage < 0 ? 100 : 100 - eva * skill.eva_f / 100
  415.       hit = self.cant_evade? ? 100 : hit
  416.       hit_result = (rand(100) < hit)
  417.       # Set effective flag if skill is uncertain
  418.       effective |= hit < 100
  419.     end
  420.     # If hit occurs
  421.     if hit_result == true
  422.       # If physical attack has power other than 0
  423.       if skill.power != 0 and skill.atk_f > 0
  424.         # State Removed by Shock
  425.         remove_states_shock
  426.         # Set to effective flag
  427.         effective = true
  428.       end
  429.       # Substract damage from HP
  430.       last_hp = self.hp
  431.       self.hp -= self.damage
  432.       effective |= self.hp != last_hp
  433.       # State change
  434.       @state_changed = false
  435.       effective |= states_plus(skill.plus_state_set)
  436.       effective |= states_minus(skill.minus_state_set)
  437.       # If power is 0
  438.       if skill.power == 0
  439.         # Set damage to an empty string
  440.         self.damage = ""
  441.         # If state is unchanged
  442.         unless @state_changed
  443.           # Set damage to "Miss"
  444.           self.damage = "Miss"
  445.         end
  446.       end
  447.     # If miss occurs
  448.     else
  449.       # Set damage to "Miss"
  450.       self.damage = "Miss"
  451.     end
  452.     # If not in battle
  453.     unless $game_temp.in_battle
  454.       # Set damage to nil
  455.       self.damage = nil
  456.     end
  457.     # End Method
  458.     return effective
  459.   end
  460.  
  461.   #--------------------------------------------------------------------------
  462.   # * Applying Normal Attack Effects
  463.   #     attacker : battler
  464.   #--------------------------------------------------------------------------
  465.   def attack_effect(attacker)
  466.     # Clear critical flag
  467.     self.critical = false
  468.     # First hit detection
  469.     hit_result = (rand(100) < attacker.hit)
  470.     # If hit occurs
  471.     if hit_result == true
  472.       # Calculate basic damage
  473.       atk = [attacker.atk - self.pdef / 2, 0].max
  474.       self.damage = atk * (20 + attacker.str) / 20
  475.       # Rating correction only for actors
  476.       if attacker.is_a? Game_Actor
  477.        self.damage *= attacker.attack_rate
  478.        self.damage = self.damage.to_i
  479.       end
  480.       # Rating defensive correction only for actors
  481.       if self.is_a? Game_Actor
  482.        self.damage *= self.defend_rate
  483.        self.damage = self.damage.to_i
  484.       end
  485.       # Element correction
  486.       self.damage *= elements_correct(attacker.element_set)
  487.       self.damage /= 100
  488.       # If damage value is strictly positive
  489.       if self.damage > 0
  490.         # Critical correction
  491.         if rand(100) < 4 * attacker.dex / self.agi
  492.           self.damage *= 2
  493.           self.critical = true
  494.         end
  495.         # Guard correction
  496.         if self.guarding?
  497.           self.damage /= 2
  498.         end
  499.       end
  500.       # Dispersion
  501.       if self.damage.abs > 0
  502.         amp = [self.damage.abs * 15 / 100, 1].max
  503.         self.damage += rand(amp+1) + rand(amp+1) - amp
  504.       end
  505.       # Second hit detection
  506.       eva = 8 * self.agi / attacker.dex + self.eva
  507.       hit = self.damage < 0 ? 100 : 100 - eva
  508.       hit = self.cant_evade? ? 100 : hit
  509.       hit_result = (rand(100) < hit)
  510.     end
  511.     # If hit occurs
  512.     if hit_result == true
  513.       # State Removed by Shock
  514.       remove_states_shock
  515.       # Substract damage from HP
  516.       self.hp -= self.damage
  517.       # State change
  518.       @state_changed = false
  519.       states_plus(attacker.plus_state_set)
  520.       states_minus(attacker.minus_state_set)
  521.     # When missing
  522.     else
  523.       # Set damage to "Miss"
  524.       self.damage = "Miss"
  525.       # Clear critical flag
  526.       self.critical = false
  527.     end
  528.     # End Method
  529.     return true
  530.   end
  531.  
  532.  
  533. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement