Advertisement
FlipelyFlip

Steal Mechanic

Jun 4th, 2024 (edited)
686
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 8.90 KB | None | 0 0
  1. module FFS
  2.   module Stealable
  3.    
  4.     # UserVarId ist die Variable-ID, welche speichert, welcher Gegner
  5.     # den Skill verwendet hat um so eine eindeutige Zuweisung zu erhalten.
  6.     UserVarId = 321
  7.    
  8.     # ItemStealId ist die Variable-ID, welche speichert, welches Item aus der
  9.     # vordefinierten Tabelle gestohlen wird.
  10.     ItemStealId = 322
  11.    
  12.     # TextVarId ist die Variable-ID, welche verwendet wird um den Text vom
  13.     # Stehlen dynamisch in der Messagebox anzuzeigen.
  14.     TextVarId = 323
  15.    
  16.     # Entspricht einer Prozentzahl, wieviel mindestens
  17.     # bei einem erfolgreichen Diebstahl geklaut wird.
  18.     MinGeldRate = 1.0
  19.    
  20.     # Entspricht einer Prozentzahl, wieviel maximal vom
  21.     # gesamten Geld geklaut werden kann.
  22.     MaxGeldRate = 3.0
  23.                              
  24.     # Definiert die Liste, welche Items geklaut werden können.
  25.     # Die Aufschlüsselung ist wie folgt:
  26.     #
  27.     # [item ID, Typ, Wahrscheinlichkeit]
  28.     #
  29.     # item ID entspricht der ID, welche in der Datenbank das Item festlegt.
  30.     #
  31.     # Typ ist ein Wert, der besagt, was für ein Item es ist.
  32.     # 1 = Item, 2 = Waffe und 3 = Rüstung
  33.     #
  34.     # Wahrscheinlichkeit ist eine Zahl zwischen 1 und 9.
  35.     # 1 besagt, das es eher unwahrscheinlich ist, wobei 9 sehr Wahrscheinlich
  36.     # ist.
  37.     ItemListe = [        
  38.             [  1,1, 1],
  39.             [  2,1, 1],
  40.             [  3,1, 5],
  41.             [  4,1, 2],
  42.             [ 70,2, 9],
  43.             [  6,3, 7],
  44.            
  45.     ] # <-- NICHT LÖSCHEN!!
  46.    
  47.     #--------------------------------------------------------------------------
  48.     # * Get Random Steal
  49.     #--------------------------------------------------------------------------
  50.     def self.get_random_steal
  51.       steal_list = []
  52.       for i in 0...ItemListe.size
  53.         for j in 0...ItemListe[i][2]
  54.           steal_list.push(ItemListe[i])
  55.         end
  56.       end
  57.       steal_list = randomize_list(steal_list)
  58.       lucky_item = rand(steal_list.size)
  59.       return steal_list[lucky_item]
  60.     end
  61.     #--------------------------------------------------------------------------
  62.     # * Randomize List
  63.     #--------------------------------------------------------------------------
  64.     def self.randomize_list(ary)
  65.       nary = Array.new(ary.size)
  66.       pos = 0
  67.       for i in 0...ary.size
  68.         pos = rand(ary.size)
  69.         while (nary[pos] != nil)
  70.           pos = rand(ary.size)
  71.         end
  72.         nary[pos] = ary[i]
  73.       end
  74.       return nary
  75.     end
  76.     #--------------------------------------------------------------------------
  77.     # * Check Steal
  78.     #--------------------------------------------------------------------------
  79.     def self.check_steal(ary, cnt=0)
  80.       cnt += 1
  81.       item = get_item(ary)
  82.       if $game_party.has_item?(item)
  83.         $game_party.lose_item(item, 1)
  84.         return ary
  85.       end
  86.      
  87.       return [] if cnt >= 10
  88.       ary = get_random_steal
  89.       check_steal(ary, cnt)
  90.     end
  91.     #--------------------------------------------------------------------------
  92.     # * Get Item
  93.     #--------------------------------------------------------------------------
  94.     def self.get_item(item)
  95.       case item[1]
  96.       when 1
  97.         item = $data_items[item[0]]
  98.       when 2
  99.         item = $data_weapons[item[0]]
  100.       when 3
  101.         item = $data_armors[item[0]]
  102.       end
  103.       return item
  104.     end
  105.     #--------------------------------------------------------------------------
  106.     # * Make Money Steal
  107.     #--------------------------------------------------------------------------
  108.     def self.make_money_steal
  109.       width_calc = Window_Base.new(0,0,0,0)
  110.       money = 0
  111.  
  112.       money = rand() * (MaxGeldRate - MinGeldRate) + MinGeldRate
  113.  
  114.       money = ($game_party.gold / 100 * money).floor
  115.  
  116.       $game_variables[UserVarId].add_stolen_gold(money, $game_variables[UserVarId].index)
  117.  
  118.       $game_party.lose_gold(money)
  119.  
  120.       if $game_switches[236] == true
  121.         text = "%s steals %s\eC[1]%s"
  122.       else
  123.         text = "%s klaut %s\eC[1]%s"
  124.       end
  125.  
  126.       text = sprintf(text, $game_variables[UserVarId].name, money, Vocab.currency_unit)
  127.       $game_variables[YEA::MESSAGE::VARIABLE_WIDTH] = width_calc.text_size(text).width - 24
  128.       $game_variables[TextVarId] = text
  129.     end
  130.     #--------------------------------------------------------------------------
  131.     # * Make Item Steal
  132.     #--------------------------------------------------------------------------
  133.     def self.make_item_steal
  134.       width_calc = Window_Base.new(0,0,0,0)
  135.       $game_variables[ItemStealId] = FFS::Stealable.get_item($game_variables[
  136.       ItemStealId])
  137.  
  138.       if $game_switches[236] == true
  139.         text = "%s steals \eC[5]"
  140.       else
  141.         text = "%s klaut \eC[5]"
  142.       end
  143.  
  144.       $game_variables[TextVarId] = sprintf(text, $game_variables[UserVarId].name)      
  145.      
  146.       text += $game_variables[FFS::Stealable::ItemStealId].name
  147.      
  148.       text = sprintf(text, $game_variables[UserVarId].name)
  149.  
  150.       $game_variables[YEA::MESSAGE::VARIABLE_WIDTH] = width_calc.text_size(text).width
  151.  
  152.     end
  153.   end
  154. end
  155.  
  156. class Window_Base < Window
  157.   #--------------------------------------------------------------------------
  158.   # * Destructively Get Control Code
  159.   #--------------------------------------------------------------------------
  160.   def obtain_escape_code(text)
  161.     text.slice!(/^[\?$\.\|\^!><\{\}\\]|^[A-Z]+/i)
  162.   end
  163.   #--------------------------------------------------------------------------
  164.   # * Preconvert Control Characters
  165.   #    As a rule, replace only what will be changed into text strings before
  166.   #    starting actual drawing. The character "\" is replaced with the escape
  167.   #    character (\e).
  168.   #--------------------------------------------------------------------------
  169.   alias :flip_convert_escape_characters_steal_text :convert_escape_characters
  170.   def convert_escape_characters(text)
  171.     result = flip_convert_escape_characters_steal_text(text)
  172.     result.gsub!(/\eresultMoney/i)          { $game_variables[FFS::Stealable::TextVarId].to_s }
  173.     result.gsub!(/\eresultItem/i)           { get_message($game_variables[FFS::Stealable::ItemStealId]).to_s }
  174.     result
  175.   end
  176.  
  177.   def get_message(item)
  178.     text = $game_variables[FFS::Stealable::TextVarId]
  179.     if item.is_a?(RPG::Item)
  180.       text += escape_icon_item(item.id, :item)
  181.     elsif item.is_a?(RPG::Weapon)
  182.       text += escape_icon_item(item.id, :weapon)
  183.     elsif item.is_a?(RPG::Armor)
  184.       text += escape_icon_item(item.id, :armour)
  185.     end                
  186.     return text
  187.   end
  188. end
  189.  
  190. class Window_Message < Window_Base
  191.   #--------------------------------------------------------------------------
  192.   # * Control Character Processing
  193.   #     code : the core of the control character
  194.   #            e.g. "C" in the case of the control character \C[1].
  195.   #     text : character string buffer in drawing processing (destructive)
  196.   #     pos  : draw position {:x, :y, :new_x, :height}
  197.   #--------------------------------------------------------------------------
  198.   alias :flip_process_escape_character_steal_text :process_escape_character
  199.   def process_escape_character(code, text, pos)
  200.     flip_process_escape_character_steal_text(code, text, pos)
  201.     return if code == nil
  202.     case code.upcase
  203.     when '?'
  204.       wait(60)
  205.       @pause_skip = true
  206.     end
  207.   end
  208. end
  209.  
  210. #==============================================================================
  211. # ** BattleManager
  212. #------------------------------------------------------------------------------
  213. #  This module manages battle progress.
  214. #==============================================================================
  215. class << BattleManager
  216.   # ---------------------------------------------------------------------------
  217.   # Overwrite method : process escape
  218.   # ---------------------------------------------------------------------------
  219.   def process_escape
  220.     # Play Begin Escape Voice
  221.     actor_to_speak = DiamondandPlatinum3::BattleVoices::get_battle_actor_id()
  222.     DiamondandPlatinum3::BattleVoices::play_escape_attempt_voice(actor_to_speak)
  223.     $game_variables[YEA::MESSAGE::VARIABLE_WIDTH] = 0
  224.     $game_variables[YEA::MESSAGE::VARIABLE_ROWS] = 0
  225.     $game_message.add(sprintf(Vocab::EscapeStart, $game_party.name))
  226.     success = @preemptive ? true : (rand < @escape_ratio)
  227.     Sound.play_escape
  228.     if success
  229.       process_abort
  230.       $game_party.alive_members.each do |member|
  231.         member.battle_phase = :escape
  232.       end
  233.     else
  234.       @escape_ratio += 0.1
  235.       $game_message.add('\.' + Vocab::EscapeFailure)
  236.       $game_party.clear_actions
  237.     end
  238.     wait_for_message
  239.     # Play Voice for either successful or unsucessful escape
  240.     if success
  241.       DiamondandPlatinum3::BattleVoices::play_escape_successful_voice(actor_to_speak, true)
  242.     else
  243.       DiamondandPlatinum3::BattleVoices::play_escape_failed_voice(actor_to_speak)
  244.     end
  245.      
  246.     # Finish Up
  247.     return success
  248.   end
  249. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement