Advertisement
FlipelyFlip

FFS - Steal Mechanic V2

Sep 7th, 2024
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 8.98 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.       $game_troop.add_stolen_money(money, $game_variables[UserVarId].index)
  118.  
  119.       $game_party.lose_gold(money)
  120.  
  121.       if $game_switches[236] == true
  122.         text = "%s steals %s\eC[1]%s"
  123.       else
  124.         text = "%s klaut %s\eC[1]%s"
  125.       end
  126.  
  127.       text = sprintf(text, $game_variables[UserVarId].name, money, Vocab.currency_unit)
  128.       $game_variables[YEA::MESSAGE::VARIABLE_WIDTH] = width_calc.text_size(text).width - 24
  129.       $game_variables[TextVarId] = text
  130.     end
  131.     #--------------------------------------------------------------------------
  132.     # * Make Item Steal
  133.     #--------------------------------------------------------------------------
  134.     def self.make_item_steal
  135.       width_calc = Window_Base.new(0,0,0,0)
  136.       $game_variables[ItemStealId] = FFS::Stealable.get_item($game_variables[
  137.       ItemStealId])
  138.  
  139.       if $game_switches[236] == true
  140.         text = "%s steals \eC[5]"
  141.       else
  142.         text = "%s klaut \eC[5]"
  143.       end
  144.  
  145.       $game_variables[TextVarId] = sprintf(text, $game_variables[UserVarId].name)      
  146.      
  147.       text += $game_variables[FFS::Stealable::ItemStealId].name
  148.      
  149.       text = sprintf(text, $game_variables[UserVarId].name)
  150.  
  151.       $game_variables[YEA::MESSAGE::VARIABLE_WIDTH] = width_calc.text_size(text).width
  152.  
  153.     end
  154.   end
  155. end
  156.  
  157. class Window_Base < Window
  158.   #--------------------------------------------------------------------------
  159.   # * Destructively Get Control Code
  160.   #--------------------------------------------------------------------------
  161.   def obtain_escape_code(text)
  162.     text.slice!(/^[\?$\.\|\^!><\{\}\\]|^[A-Z]+/i)
  163.   end
  164.   #--------------------------------------------------------------------------
  165.   # * Preconvert Control Characters
  166.   #    As a rule, replace only what will be changed into text strings before
  167.   #    starting actual drawing. The character "\" is replaced with the escape
  168.   #    character (\e).
  169.   #--------------------------------------------------------------------------
  170.   alias :flip_convert_escape_characters_steal_text :convert_escape_characters
  171.   def convert_escape_characters(text)
  172.     result = flip_convert_escape_characters_steal_text(text)
  173.     result.gsub!(/\eresultMoney/i)          { $game_variables[FFS::Stealable::TextVarId].to_s }
  174.     result.gsub!(/\eresultItem/i)           { get_message($game_variables[FFS::Stealable::ItemStealId]).to_s }
  175.     result
  176.   end
  177.  
  178.   def get_message(item)
  179.     text = $game_variables[FFS::Stealable::TextVarId]
  180.     if item.is_a?(RPG::Item)
  181.       text += escape_icon_item(item.id, :item)
  182.     elsif item.is_a?(RPG::Weapon)
  183.       text += escape_icon_item(item.id, :weapon)
  184.     elsif item.is_a?(RPG::Armor)
  185.       text += escape_icon_item(item.id, :armour)
  186.     end                
  187.     return text
  188.   end
  189. end
  190.  
  191. class Window_Message < Window_Base
  192.   #--------------------------------------------------------------------------
  193.   # * Control Character Processing
  194.   #     code : the core of the control character
  195.   #            e.g. "C" in the case of the control character \C[1].
  196.   #     text : character string buffer in drawing processing (destructive)
  197.   #     pos  : draw position {:x, :y, :new_x, :height}
  198.   #--------------------------------------------------------------------------
  199.   alias :flip_process_escape_character_steal_text :process_escape_character
  200.   def process_escape_character(code, text, pos)
  201.     flip_process_escape_character_steal_text(code, text, pos)
  202.     return if code == nil
  203.     case code.upcase
  204.     when '?'
  205.       wait(60)
  206.       @pause_skip = true
  207.     end
  208.   end
  209. end
  210.  
  211. #==============================================================================
  212. # ** BattleManager
  213. #------------------------------------------------------------------------------
  214. #  This module manages battle progress.
  215. #==============================================================================
  216. class << BattleManager
  217.   # ---------------------------------------------------------------------------
  218.   # Overwrite method : process escape
  219.   # ---------------------------------------------------------------------------
  220.   def process_escape
  221.     # Play Begin Escape Voice
  222.     actor_to_speak = DiamondandPlatinum3::BattleVoices::get_battle_actor_id()
  223.     DiamondandPlatinum3::BattleVoices::play_escape_attempt_voice(actor_to_speak)
  224.     $game_variables[YEA::MESSAGE::VARIABLE_WIDTH] = 0
  225.     $game_variables[YEA::MESSAGE::VARIABLE_ROWS] = 0
  226.     $game_message.add(sprintf(Vocab::EscapeStart, $game_party.name))
  227.     success = @preemptive ? true : (rand < @escape_ratio)
  228.     Sound.play_escape
  229.     if success
  230.       process_abort
  231.       $game_party.alive_members.each do |member|
  232.         member.battle_phase = :escape
  233.       end
  234.     else
  235.       @escape_ratio += 0.1
  236.       $game_message.add('\.' + Vocab::EscapeFailure)
  237.       $game_party.clear_actions
  238.     end
  239.     wait_for_message
  240.     # Play Voice for either successful or unsucessful escape
  241.     if success
  242.       DiamondandPlatinum3::BattleVoices::play_escape_successful_voice(actor_to_speak, true)
  243.     else
  244.       DiamondandPlatinum3::BattleVoices::play_escape_failed_voice(actor_to_speak)
  245.     end
  246.      
  247.     # Finish Up
  248.     return success
  249.   end
  250. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement