Advertisement
Zetu

Z05 v1.03

Jan 6th, 2012
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.                             #======================#
  2.                             #  Z-Systems by: Zetu  #
  3. #===========================#======================#===========================#
  4. #                  *  *  *  Z05 Steal Command  v1.03  *  *  *                  #
  5. #=#==========================================================================#=#
  6.   #  Add regular expression STEAL_SKILL to any skill to allow the player to  #
  7.   #  steal from the target(s) of the skill.  To add stealable items to an    #
  8.   #  enemy, add as many regular expressions STEAL_OBJ to the enemy.          #
  9.   #--------------------------------------------------------------------------#
  10.   #  Requires CORE script.
  11.   #==========================================================================#
  12. module Z05
  13.  
  14.   STEAL_SKILL = /<steal>/i
  15.   STEAL_OBJ   = /<steal[:]*\s*(WEAPON|ITEM|ARMOR|GOLD)\s*(\d+)>/i
  16.  
  17.   NO_STEALS     = "%s has nothing to steal."
  18.   STEAL_GOLD    = "Stole %s gold from %s."
  19.   STEAL_ITEM    = "Stole %s from %s."
  20.   STEAL_FAIL    = "Couldn't steal anything!"
  21.  
  22.   def self.get_steal_ratio(user, target)
  23.     base = 0.85 # Chance to steal if user.agi == target.agi
  24.     # Do NOT set base to 1.0 or 0.0.
  25.     return user.agi/(user.agi+(1/base -1)*target.agi)
  26.   end
  27. #========#======================#====#================================#========#
  28. #--------#                      #----# DO NOT EDIT PAST THIS POINT!!! #--------#
  29. #--------# End of Customization #----# Editing will cause death by    #--------#
  30. #--------#                      #----# brain asplosions.              #--------#
  31. #========#======================#====#================================#========#
  32. end
  33. ($imported||={})[:z05]=true
  34.  
  35. class RPG::UsableItem < RPG::BaseItem
  36.   #--------------------------------------------------------------------------
  37.   # * New method: steal?
  38.   #--------------------------------------------------------------------------
  39.   def steal?
  40.     self.note.scan(Z05::STEAL_SKILL){return true}
  41.       return false
  42.   end
  43. end
  44.  
  45. class Game_Enemy < Game_Battler
  46.     attr_reader :last_stolen_item, :steal_data
  47.   #--------------------------------------------------------------------------
  48.   # * Alias method: initialize
  49.   #--------------------------------------------------------------------------
  50.   alias :z05_initialize :initialize
  51.   def initialize(index, enemy_id)
  52.     z05_initialize(index, enemy_id)
  53.     create_steal_list
  54.   end
  55.   #--------------------------------------------------------------------------
  56.   # * New method: create_steal_list
  57.   #--------------------------------------------------------------------------
  58.   def create_steal_list
  59.     @steal_data = []
  60.     self.enemy.note.scan(Z05::STEAL_OBJ){|type, id|
  61.       case type
  62.       when /item/i
  63.         @steal_data.push($data_items[id.to_i])
  64.       when /weapon/i
  65.         @steal_data.push($data_weapons[id.to_i])
  66.       when /armor/i
  67.         @steal_data.push($data_armors[id.to_i])
  68.       when /gold/i
  69.         @steal_data.push(id.to_i)
  70.       end}
  71.   end
  72.   #--------------------------------------------------------------------------
  73.   # * Super method: item_apply
  74.   #--------------------------------------------------------------------------
  75.   def item_apply(user, item)
  76.     super(user, item)
  77.     @result.steal = nil
  78.     steal_apply(user, item) if item.steal?
  79.   end
  80.  
  81.   def steal_apply(user, item)
  82.     ratio = Z05::get_steal_ratio(user, self)
  83.     if @result.missed||@result.evaded
  84.       @result.steal = :miss
  85.     elsif rand < ratio
  86.       @result.steal = add_item_steal_effect ? :success : :nosteal
  87.     else
  88.       @result.steal = :fail
  89.     end
  90.   end
  91.   #--------------------------------------------------------------------------
  92.   # * New method: add_item_steal_effect
  93.   #--------------------------------------------------------------------------
  94.   def add_item_steal_effect
  95.     return false if @steal_data.size==0
  96.     @stolenitem = @last_stolen_item = @steal_data.random!
  97.       return false if @stolenitem.nil?
  98.       if @stolenitem.is_a?(Integer)
  99.         $game_party.gain_gold(@stolenitem)
  100.       else
  101.         $game_party.gain_item(@stolenitem, 1)
  102.       end
  103.     return true
  104.   end
  105.   #--------------------------------------------------------------------------
  106.   # * New method: reset_steal_item
  107.   #--------------------------------------------------------------------------
  108.   def reset_steal_item
  109.     @last_stolen_item=nil
  110.     @result.steal = nil
  111.   end
  112.  
  113. end
  114.  
  115. class Game_ActionResult
  116.   attr_accessor :steal
  117. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement