Advertisement
Vlue

Steal Ability

Apr 11th, 2014
1,596
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.97 KB | None | 0 0
  1. #--# Steal Ability v 1.1
  2. #
  3. # Allows to create abilities that steal items or gold from enemies.
  4. #  Or abilities! Which last until the end of the battle.
  5. #
  6. # Usage: Plug and play, customize and set up note tags as needed.
  7. #
  8. #   Enemy Notetags:
  9. #    Id is the id of the item and chance is the percentage of success
  10. #     <STEAL ITEM id chance>
  11. #     <STEAL WEAPON id chance>
  12. #     <STEAL ARMOR id chance>
  13. #     <STEAL ABILITY id>
  14. #     <STEAL GOLD amount>
  15. #
  16. #   Skill/Class/Actor/Equips notetags:
  17. #     <STEAL>      - Skill only, allows skill to steal items
  18. #     <PICKPOCKET> - Skill only, allows skill to steal gold
  19. #     <STEAL_ABILITY> - Skill only, allows skill to steal ability
  20. #     <STEAL CHANCE bonus> - provides a percentage bonus to steal chance
  21. #
  22. #------#
  23. #-- Script by: V.M of D.T
  24. #
  25. #- Questions or comments can be:
  26. #    given by email: sumptuaryspade@live.ca
  27. #    provided on facebook: http://www.facebook.com/DaimoniousTailsGames
  28. #   All my other scripts and projects can be found here: http://daimonioustails.weebly.com/
  29. #
  30. #--- Free to use in any project, commercial or non-commercial, with credit given
  31. #--Though a donation's always a nice way to say thank you~ (I also accept actual thank you's)
  32.  
  33. ABILITY_STEAL_CHANCE = 100
  34. PICKPOCKET_STEAL_CHANCE = 60
  35.  
  36. class RPG::Enemy
  37.   def steal_array
  38.     steal = {}
  39.     notes = self.note.clone
  40.     while notes =~ /<STEAL ITEM (\d+) (\d+)>/
  41.       steal[[0,$1.to_i]] = $2.to_i
  42.       notes[notes.index("<STEAL")] = "N"
  43.     end
  44.     while notes =~ /<STEAL WEAPON (\d+) (\d+)>/
  45.       steal[[1,$1.to_i]] = $2.to_i
  46.       notes[notes.index("<STEAL")] = "N"
  47.     end
  48.     while notes =~ /<STEAL ARMOR (\d+) (\d+)>/
  49.       steal[[2,$1.to_i]] = $2.to_i
  50.       notes[notes.index("<STEAL")] = "N"
  51.     end
  52.     steal
  53.   end
  54.   def gold_amount
  55.     self.note =~ /<STEAL GOLD (\d+)>/ ? $1 : 0
  56.   end
  57.   def ability_steal
  58.     self.note =~ /<STEAL ABILITY (\d+)>/ ? $1 : 0
  59.   end
  60. end
  61.  
  62. class RPG::UsableItem
  63.   def steal?
  64.     self.note.include?("<STEAL>")
  65.   end
  66.   def pickpocket?
  67.     self.note.include?("<PICKPOCKET>")
  68.   end
  69.   def steal_ability?
  70.     self.note.include?("<STEAL_ABILITY>")
  71.   end
  72. end
  73.  
  74. class RPG::BaseItem
  75.   def steal_chance
  76.     self.note =~ /<STEAL CHANCE (\d+)>/ ? $1.to_i : 0
  77.   end
  78. end
  79.  
  80. class Game_Enemy
  81.   alias steal_init initialize
  82.   def initialize(*args)
  83.     steal_init(*args)
  84.     @steal = enemy.steal_array.clone
  85.     @gold = enemy.gold_amount.to_i
  86.     @ability = enemy.ability_steal.to_i
  87.   end
  88.   def steal_array
  89.     @steal
  90.   end
  91.   def steal(user,skill)
  92.     steal_array.each do |id,chance|
  93.       if rand(100) < chance + user.steal_bonus(skill)
  94.         if Module.const_defined?(:AFFIXES)
  95.           item = $game_party.add_item(id[1],1) if id[0] == 0
  96.           item = $game_party.add_weapon(id[1],1) if id[0] == 1
  97.           item = $game_party.add_armor(id[1],1) if id[0] == 2
  98.         else
  99.           item = $data_items[id[1]] if id[0] == 0
  100.           item = $data_weapons[id[1]] if id[0] == 1
  101.           item = $data_armors[id[1]] if id[0] == 2
  102.           $game_party.gain_item(item,1)
  103.         end
  104.         @steal[id] = -1000
  105.         return item
  106.       end
  107.     end
  108.     return nil
  109.   end
  110.   def pickpocket(user,skill)
  111.     return nil if @gold == 0
  112.     if rand(100) < PICKPOCKET_STEAL_CHANCE + user.steal_bonus(skill)
  113.       amount = rand(enemy.gold_amount.to_i) / 5 * (user.steal_bonus(skill) / 100.to_f + 1)
  114.       if amount > @gold
  115.         amount = @gold
  116.       end
  117.       @gold -= amount
  118.       $game_party.gain_gold(amount.to_i)
  119.       return amount.to_i
  120.     end
  121.     return nil
  122.   end
  123.   def steal_ability(user,skill)
  124.     return nil if @ability == 0
  125.     if rand(100) < ABILITY_STEAL_CHANCE + user.steal_bonus(skill)
  126.       user.add_stolen_ability(@ability)
  127.       return @ability
  128.     end
  129.     return nil
  130.   end
  131. end
  132.  
  133. class Game_Actor
  134.   def steal_bonus(item)
  135.     bonus = item.steal_chance
  136.     bonus += self.actor.steal_chance
  137.     bonus += self.class.steal_chance
  138.     @equips.each do |item|
  139.       next if item.is_nil?
  140.       bonus += item.object.steal_chance
  141.     end
  142.     bonus
  143.   end
  144.   def add_stolen_ability(skill_id)
  145.     @stolen_ability = [] if @stolen_ability.nil?
  146.     @stolen_ability.push(skill_id)
  147.     learn_skill(skill_id)
  148.   end
  149.   def clear_stolen_ability
  150.     return unless @stolen_ability
  151.     @stolen_ability.each do |skill_id|
  152.       forget_skill(skill_id)
  153.     end
  154.     @stolen_ability = []
  155.   end
  156.   def on_battle_end
  157.     super
  158.     clear_stolen_ability
  159.   end
  160. end
  161.  
  162. class Scene_Battle
  163.   def apply_item_effects(target, item)
  164.     target.item_apply(@subject, item)
  165.     refresh_status
  166.     if item.steal?
  167.       stolen_item = target.steal(@subject,item)
  168.       target.result.success = true
  169.     end
  170.     if item.pickpocket?
  171.       stolen_gold = target.pickpocket(@subject,item)
  172.       target.result.success = true
  173.     end
  174.     if item.steal_ability?
  175.       stolen_ability = target.steal_ability(@subject,item)
  176.       target.result.success = true
  177.     end
  178.     @log_window.display_action_results(target, item)
  179.     if item.steal? || item.pickpocket? || item.steal_ability?
  180.       if stolen_item
  181.         @log_window.display_theft(@subject,stolen_item)
  182.       end
  183.       if stolen_gold
  184.         @log_window.display_pickpocket(@subject,stolen_gold)
  185.       end
  186.       if stolen_ability
  187.         @log_window.display_ability_steal(@subject,target,stolen_ability)
  188.       end
  189.       @log_window.display_theft_fail(@subject) if !stolen_item && !stolen_gold && !stolen_ability
  190.     end
  191.   end
  192. end
  193.  
  194. class Window_BattleLog
  195.   def display_theft(user,item)
  196.     add_text(user.name + " stole a " + item.name)
  197.     wait
  198.   end
  199.   def display_theft_fail(user)
  200.     add_text(user.name + " failed to steal anything")
  201.     wait
  202.   end
  203.   def display_pickpocket(user,gold)
  204.     add_text(user.name + " pickpocketed " + gold.to_s + " " + Vocab::currency_unit)
  205.     wait
  206.   end
  207.   def display_ability_steal(user,target,ability)
  208.     add_text(user.name + " stole " + target.name + "'s " + $data_skills[ability].name + " ability!")
  209.     wait
  210.   end
  211. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement