Advertisement
Holy87

Game Difficulty - ITA

Feb 12th, 2017
405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 19.92 KB | None | 0 0
  1. =begin
  2.  ==============================================================================
  3.   ■ Difficoltà di gioco di Holy87
  4.       versione 1.0
  5.       Difficoltà utente: ★
  6.       Licenza: CC. Chiunque può scaricare, modificare, distribuire e utilizzare
  7.       lo script nei propri progetti, sia amatoriali che commerciali. Vietata
  8.       l'attribuzione impropria.
  9.  ==============================================================================
  10.     Questo script permette di selezionare un livello di difficoltà del gioco.
  11.     Puoi impostare quanti livelli di difficoltà desideri, cambiando probabilità
  12.     di drop, esperienza, oro e parametri dei nemici. La difficoltà è salvata in
  13.     una variabile di gioco, per cui puoi aggiungere condizioni nel gioco a
  14.     seconda del livello di diffoltà scelto tramite semplici condizioni evento
  15.     (ad esempio, puoi far comparire meno scrigni a livello difficile)
  16.  ==============================================================================
  17.   ■ Compatibilità
  18.     Scene_Title -> alias command_new_game
  19.                    alias create_command_window
  20.                    alias start
  21.  ==============================================================================
  22.   ■ Installazione e istruzioni
  23.     Installare questo script sotto Materials e prima del Main.
  24.     Lo script è Plug&Play. Puoi modificare alcuni settaggi in basso, nella
  25.     sezione CONFIGURAZIONE (in particolare, i livelli di difficoltà).
  26.     Puoi specificare un nuovo livello di difficoltà aggiungendo nell'array un
  27.     nuovo hash (gli hash sono valori nelle parentesi {}) con le seguenti
  28.     caratteristiche:
  29.     name: nome difficoltà (ad es. facile, normale, difficile)
  30.     drop_rate: modifica la probabilità di drop (100 è normale, 200 doppio)
  31.     exp_rate: modifica l'esperienza ottenuta in percentuale (come sopra)
  32.     gold_rate: come sopra, ma per l'oro
  33.     enemy_mhp: HP massimi del nemico
  34.     enemy_mmp: MP massimi del nemico
  35.     enemy_atk: attacco dei nemici
  36.     enemy_def: difesa dei nemici
  37.     enemy_mat: attacco magico dei nemici
  38.     enemy_mdf: difesa magica dei nemici
  39.     enemy_agi: agilità dei nemici
  40.     enemy_luk: fortuna dei nemici
  41.  ==============================================================================
  42. =end
  43.  
  44.  
  45. #==============================================================================
  46. # ** CONFIGURAZIONE
  47. #==============================================================================
  48. module Game_Difficulty
  49.   LEVELS = [
  50.     {name: 'Facile', drop_rate: 80,
  51.       enemy_mhp: 75,
  52.       enemy_atk: 75,
  53.       ememy_mat: 75,
  54.       enemy_agi: 75
  55.       },
  56.     {name: 'Normale'}, #nessun'altra configurazione, normale
  57.     {name: 'Difficile',
  58.       drop_rate: 110,
  59.       exp_rate: 110,
  60.       gold_rate: 80,
  61.       enemy_mhp: 125,
  62.       enemy_atk: 125,
  63.       enemy_def: 110,
  64.       enemy_mat: 125,
  65.       enemy_mdf: 110,
  66.       enemy_luk: 125
  67.     }
  68.   ]
  69.   #--------------------------------------------------------------------------
  70.   # * Alcune impostazioni dello script
  71.   #--------------------------------------------------------------------------
  72.   # ID della variabile che memorizzerà la difficoltà scelta
  73.   DIFFICULTY_VARIABLE = 50
  74.   # Vuoi permettere al giocatore di modificare il livello di difficoltà dal
  75.   # menu di gioco?
  76.   SHOW_IN_SETTINGS = true
  77.   # Vuoi mostrare i livelli di difficoltà selezionabili in un popup? (attiva
  78.   # questa opzione se i livelli di difficoltà sono troppi per essere mostrati
  79.   # in una sola riga)
  80.   SHOW_POPUP = false
  81.   # Vuoi mostrare la finestra di selezione livello di difficoltà all'avvio di
  82.   # una nuova partita?
  83.   SHOW_LEVEL_WINDOW = true
  84.   # Livello di difficoltà predefinito
  85.   DEFAULT_DIFFICULTY = 1 # normale
  86.   #--------------------------------------------------------------------------
  87.   # * Vocaboli
  88.   #--------------------------------------------------------------------------
  89.   # Nome del comando nelle opzioni di gioco
  90.   DIFFICULTY_CMD = 'Difficoltà'
  91.   # Testo d'aiuto comando nelle opzioni di gioco
  92.   DIFFICULTY_HELP = 'Seleziona il livello di difficoltà.'
  93.   # Testo d'aiuto nella selezione difficoltà sulla schermata del titolo
  94.   SELECT_HELP = 'Seleziona il livello di difficoltà.'
  95. end
  96.  
  97. #==============================================================================
  98. # ** FINE CONFIGURAZIONE
  99. #------------------------------------------------------------------------------
  100. #                 - ATTENZIONE: NON MODIFICARE OLTRE! -
  101. #==============================================================================
  102.  
  103.  
  104. $imported = {} if $imported == nil
  105. $imported['H87_Difficulty'] = 1.0
  106. #==============================================================================
  107. # ** Game_Difficulty
  108. #------------------------------------------------------------------------------
  109. #
  110. #==============================================================================
  111. module Game_Difficulty
  112.   #--------------------------------------------------------------------------
  113.   # * Returns the difficulties array
  114.   # @return [Array]
  115.   #--------------------------------------------------------------------------
  116.   def self.get_difficulties
  117.     LEVELS.collect {|lev| lev[:name]}
  118.   end
  119.   #--------------------------------------------------------------------------
  120.   # * Option hash
  121.   #--------------------------------------------------------------------------
  122.   hash = {
  123.       :type       => :variable,
  124.       :text       => DIFFICULTY_CMD,
  125.       :help       => DIFFICULTY_HELP,
  126.       :var        => DIFFICULTY_VARIABLE,
  127.       :values     => get_difficulties,
  128.       :open_popup => SHOW_POPUP}
  129.   #--------------------------------------------------------------------------
  130.   # * Adding the setting to Game Options
  131.   #--------------------------------------------------------------------------
  132.   H87Options.push_game_option(hash) if SHOW_IN_SETTINGS && $imported['H87_Options']
  133. end
  134.  
  135. $imported = {} if $imported.nil?
  136. $imported['H87-GameDifficulty'] = 1.0
  137. #==============================================================================
  138. # ** Difficulty_Level
  139. #------------------------------------------------------------------------------
  140. # Contains informations for the difficulty settings
  141. #==============================================================================
  142. class Difficulty_Level
  143.   attr_reader :name             # difficulty name
  144.   attr_reader :exp_rate         # exp rate
  145.   attr_reader :drop_rate        # drop rate
  146.   attr_reader :gold_rate        # gold rate
  147.   attr_reader :enemy_mhp_rate   # enemy max hp rate
  148.   attr_reader :enemy_mmp_rate   # enemy max mp rate
  149.   attr_reader :enemy_atk_rate   # enemy attack rate
  150.   attr_reader :enemy_mat_rate   # enemy magic attack rate
  151.   attr_reader :enemy_mdf_rate   # enemy magic defense rate
  152.   attr_reader :enemy_def_rate   # enemy defense rate
  153.   attr_reader :enemy_agi_rate   # enemy agi rate
  154.   attr_reader :enemy_luk_rate   # enemy luck rate
  155.   #--------------------------------------------------------------------------
  156.   # * Object initialization
  157.   # @param[Hash] hash
  158.   #--------------------------------------------------------------------------
  159.   def initialize(hash)
  160.     @name = hash[:name]
  161.     @exp_rate = hash[:exp_rate] ? hash[:exp_rate] : 100
  162.     @drop_rate = hash[:drop_rate] ? hash[:drop_rate] : 100
  163.     @gold_rate = hash[:gold_rate] ? hash[:gold_rate] : 100
  164.     @enemy_mhp_rate = hash[:enemy_mhp] ? hash[:enemy_mhp] : 100
  165.     @enemy_mmp_rate = hash[:enemy_mmp] ? hash[:enemy_mmp] : 100
  166.     @enemy_atk_rate = hash[:enemy_atk] ? hash[:enemy_atk] : 100
  167.     @enemy_def_rate = hash[:enemy_def] ? hash[:enemy_atk] : 100
  168.     @enemy_mat_rate = hash[:enemy_mat] ? hash[:enemy_mat] : 100
  169.     @enemy_mdf_rate = hash[:enemy_mdf] ? hash[:enemy_mdf] : 100
  170.     @enemy_agi_rate = hash[:enemy_agi] ? hash[:enemy_agi] : 100
  171.     @enemy_luk_rate = hash[:enemy_luk] ? hash[:enemy_luk] : 100
  172.   end
  173. end
  174.  
  175. #==============================================================================
  176. # ** Game_System
  177. #==============================================================================
  178. class Game_System
  179.   #--------------------------------------------------------------------------
  180.   # * Difficulty variable ID
  181.   #--------------------------------------------------------------------------
  182.   def difficulty_id
  183.     $game_variables[Game_Difficulty::DIFFICULTY_VARIABLE]
  184.   end
  185.   #--------------------------------------------------------------------------
  186.   # * Returns the current difficulty level
  187.   # @return [Difficulty_Level]
  188.   #--------------------------------------------------------------------------
  189.   def current_difficulty
  190.     hash = Game_Difficulty::LEVELS[difficulty_id]
  191.     Difficulty_Level.new(hash)
  192.   end
  193. end
  194.  
  195. #==============================================================================
  196. # ** Game_Enemy
  197. #==============================================================================
  198. class Game_Enemy < Game_Battler
  199.   alias h87_gl_pb param_base unless $@
  200.   alias h87_gl_gold gold unless $@
  201.   alias h87_gl_exp exp unless $@
  202.   alias h87_gl_dir drop_item_rate unless $@
  203.   #--------------------------------------------------------------------------
  204.   # * Changes param base adjusting to the difficulty level
  205.   #--------------------------------------------------------------------------
  206.   def param_base(param_id)
  207.     h87_gl_pb(param_id) * adjust_difficulty(param_id) / 100
  208.   end
  209.   #--------------------------------------------------------------------------
  210.   # * Gold
  211.   #--------------------------------------------------------------------------
  212.   def gold
  213.     h87_gl_gold * $game_system.current_difficulty.gold_rate / 100
  214.   end
  215.   #--------------------------------------------------------------------------
  216.   # * Exp
  217.   #--------------------------------------------------------------------------
  218.   def exp
  219.     h87_gl_exp * $game_system.current_difficulty.exp_rate / 100
  220.   end
  221.   #--------------------------------------------------------------------------
  222.   # * Drop item rate
  223.   #--------------------------------------------------------------------------
  224.   def drop_item_rate
  225.     h87_gl_dir * ($game_system.current_difficulty.drop_rate / 100.0 + 1.0)
  226.   end
  227.   #--------------------------------------------------------------------------
  228.   # * Param multiplier
  229.   #--------------------------------------------------------------------------
  230.   def adjust_difficulty(param_id)
  231.     d_lev = $game_system.current_difficulty
  232.     case param_id
  233.       when 0; return d_lev.enemy_mhp_rate # mhp
  234.       when 1; return d_lev.enemy_mmp_rate # mmp
  235.       when 2; return d_lev.enemy_atk_rate # atk
  236.       when 4; return d_lev.enemy_def_rate # def
  237.       when 3; return d_lev.enemy_mat_rate # mat
  238.       when 5; return d_lev.enemy_mdf_rate # mdf
  239.       when 6; return d_lev.enemy_agi_rate # agi
  240.       when 7; return d_lev.enemy_luk_rate # luk
  241.       else;      return 100
  242.     end
  243.   end
  244. end
  245.  
  246. #==============================================================================
  247. # ** Window_DifficultySelect
  248. #------------------------------------------------------------------------------
  249. # Window for difficulty level selection
  250. #==============================================================================
  251. class Window_DifficultySelect < Window_Selectable
  252.   #--------------------------------------------------------------------------
  253.   # * Object initialization
  254.   #--------------------------------------------------------------------------
  255.   def initialize
  256.     make_command_list
  257.     super(0, 0, 160, window_height)
  258.     self.width = window_width
  259.     create_contents
  260.     update_placement
  261.     refresh
  262.     self.openness = 0
  263.   end
  264.   #--------------------------------------------------------------------------
  265.   # * Update Window Position
  266.   #--------------------------------------------------------------------------
  267.   def update_placement
  268.     self.x = (Graphics.width - width) / 2
  269.     self.y = (Graphics.height * 1.6 - height) / 2
  270.   end
  271.   #--------------------------------------------------------------------------
  272.   # * Get Window Width
  273.   #--------------------------------------------------------------------------
  274.   def window_width
  275.     [[max_text + padding * 2 + 4, 160].max, Graphics.width].min
  276.   end
  277.   #--------------------------------------------------------------------------
  278.   # * Get Window Height
  279.   #--------------------------------------------------------------------------
  280.   def window_height
  281.     fitting_height(visible_line_number)
  282.   end
  283.   #--------------------------------------------------------------------------
  284.   # * Get Number of Lines to Show
  285.   #--------------------------------------------------------------------------
  286.   def visible_line_number
  287.     item_max
  288.   end
  289.   #--------------------------------------------------------------------------
  290.   # * Get Number of Items
  291.   #--------------------------------------------------------------------------
  292.   def item_max
  293.     @list.size
  294.   end
  295.   #--------------------------------------------------------------------------
  296.   # * Draw item
  297.   #--------------------------------------------------------------------------
  298.   def draw_item(index)
  299.     draw_text(item_rect(index), item(index).name, alignment)
  300.   end
  301.   #--------------------------------------------------------------------------
  302.   # * Returns the current item (or indexed)
  303.   # @param [Integer] index
  304.   # @return [Difficulty_Level]
  305.   #--------------------------------------------------------------------------
  306.   def item(index = @index)
  307.     @list[index]
  308.   end
  309.   #--------------------------------------------------------------------------
  310.   # * Make command list
  311.   #--------------------------------------------------------------------------
  312.   def make_command_list
  313.     @list = difficulty_levels
  314.   end
  315.   #--------------------------------------------------------------------------
  316.   # * Difficulty levels array
  317.   # @return [Array]
  318.   #--------------------------------------------------------------------------
  319.   def difficulty_levels
  320.     Game_Difficulty::LEVELS.collect{|level| Difficulty_Level.new(level)}
  321.   end
  322.   #--------------------------------------------------------------------------
  323.   # * Max lenght of the commands
  324.   #--------------------------------------------------------------------------
  325.   def max_text
  326.     difficulty_levels.collect{|level| text_size(level.name).width}.max
  327.   end
  328.   #--------------------------------------------------------------------------
  329.   # * Text alignment
  330.   #--------------------------------------------------------------------------
  331.   def alignment; 1; end
  332.   #--------------------------------------------------------------------------
  333.   # * Selects the default difficulty index
  334.   #--------------------------------------------------------------------------
  335.   def default_index; select(Game_Difficulty::DEFAULT_DIFFICULTY); end
  336. end
  337.  
  338. #==============================================================================
  339. # ** Window_LevelHelp
  340. #------------------------------------------------------------------------------
  341. # Help windows for difficulty selection in the title menu
  342. #==============================================================================
  343. class Window_LevelHelp < Window_Base
  344.   #--------------------------------------------------------------------------
  345.   # * Object initialization
  346.   #--------------------------------------------------------------------------
  347.   def initialize(y)
  348.     super(0, y, 160, fitting_height(line_number))
  349.     self.width = window_width
  350.     center_window
  351.     create_contents
  352.     refresh
  353.     self.openness = 0
  354.   end
  355.   #--------------------------------------------------------------------------
  356.   # * Line number
  357.   #--------------------------------------------------------------------------
  358.   def line_number; 1; end
  359.   #--------------------------------------------------------------------------
  360.   # * Get Window Width
  361.   #--------------------------------------------------------------------------
  362.   def window_width
  363.     [[text_size(text).width + padding * 2 + 4, 160].max, Graphics.width].min
  364.   end
  365.   #--------------------------------------------------------------------------
  366.   # * Refresh
  367.   #--------------------------------------------------------------------------
  368.   def refresh
  369.     contents.clear
  370.     draw_text(0, 0, contents_width, line_height, text, 1)
  371.   end
  372.   #--------------------------------------------------------------------------
  373.   # * Text showed
  374.   #--------------------------------------------------------------------------
  375.   def text; Game_Difficulty::SELECT_HELP; end
  376.   #--------------------------------------------------------------------------
  377.   # * Center the window
  378.   #--------------------------------------------------------------------------
  379.   def center_window
  380.     self.x = (Graphics.width - self.width)/2
  381.     self.y = self.y - self.height
  382.   end
  383. end
  384.  
  385. #==============================================================================
  386. # ** Scene_Title
  387. #------------------------------------------------------------------------------
  388. # Adding new window for difficulty selection when a new game occurs
  389. #==============================================================================
  390. class Scene_Title < Scene_Base
  391.   alias h87gl_start start unless $@
  392.   alias h87gl_create_command_window create_command_window unless $@
  393.   alias h87gl_cng command_new_game unless $@
  394.   #--------------------------------------------------------------------------
  395.   # * Start process
  396.   #--------------------------------------------------------------------------
  397.   def start
  398.     h87gl_start
  399.     create_difficulty_window
  400.   end
  401.   #--------------------------------------------------------------------------
  402.   # * Changing method if a level selection is active
  403.   #--------------------------------------------------------------------------
  404.   def create_command_window
  405.     h87gl_create_command_window
  406.     if level_select?
  407.       @command_window.set_handler(:new_game, method(:command_difficulty))
  408.     end
  409.   end
  410.   #--------------------------------------------------------------------------
  411.   # * Difficulty window creation
  412.   #--------------------------------------------------------------------------
  413.   def create_difficulty_window
  414.     @difficulty_window = Window_DifficultySelect.new
  415.     @difficulty_window.set_handler(:ok, method(:command_new_game))
  416.     @difficulty_window.set_handler(:cancel, method(:command_recall_title))
  417.     @difficulty_help = Window_LevelHelp.new(@difficulty_window.y)
  418.   end
  419.   #--------------------------------------------------------------------------
  420.   # * Difficulty selection
  421.   #--------------------------------------------------------------------------
  422.   def command_difficulty
  423.     close_command_window
  424.     @difficulty_window.default_index
  425.     @difficulty_help.open
  426.     @difficulty_window.open
  427.     @difficulty_window.activate
  428.   end
  429.   #--------------------------------------------------------------------------
  430.   # * Reactivates the command title window
  431.   #--------------------------------------------------------------------------
  432.   def command_recall_title
  433.     close_level_window
  434.     @command_window.open
  435.     @command_window.activate
  436.   end
  437.   #--------------------------------------------------------------------------
  438.   # * Close level window
  439.   #--------------------------------------------------------------------------
  440.   def close_level_window
  441.     @difficulty_help.close
  442.     @difficulty_window.close
  443.     update until @difficulty_window.close?
  444.   end
  445.   #--------------------------------------------------------------------------
  446.   # * Command new game
  447.   #--------------------------------------------------------------------------
  448.   def command_new_game
  449.     close_level_window
  450.     h87gl_cng
  451.     var = Game_Difficulty::DIFFICULTY_VARIABLE
  452.     if level_select?
  453.       $game_variables[var] = @difficulty_window.index
  454.     else
  455.       $game_variables[var] = Game_Difficulty::DEFAULT_DIFFICULTY
  456.     end
  457.   end
  458.   #--------------------------------------------------------------------------
  459.   # * Determines if the selection must appear
  460.   #--------------------------------------------------------------------------
  461.   def level_select?
  462.     Game_Difficulty::SHOW_LEVEL_WINDOW
  463.   end
  464. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement