Advertisement
Guest User

Monnaie

a guest
May 2nd, 2015
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 22.07 KB | None | 0 0
  1. module Monnaie
  2.  
  3.   #Nombre de monnaie :
  4.   NBR_MONNAIE = 2
  5.  
  6.   #Mettre un texte pour nom
  7.   NAME = ["Or","Cristal d'âme"]
  8.   #Mettre l'id d'une icone si vous voulez voir l'icone plutot que le nom de la
  9.   #monnaie , mettre nil sinon
  10.   ICON = [190,343]
  11.   #Maximum transportable (mettre nil pour pas de limite)
  12.   MAX_VALUE = [nil,nil]
  13.  
  14.   #Monnaie a afficher dans le menu
  15.   MONNAIE_MENU = [1,2]
  16.  
  17.   #Type de conversion possible entre monnaie
  18.   CONVERSION = [["Or","Âme"],
  19.                 ["Or","Argent"],
  20.                 ["Or","Cuivre"],
  21.                 ["Argent","Or"],
  22.                 ["Argent","Cuivre"],
  23.                 ["Cuivre","Or"],
  24.                 ["Cuivre","Argent"],
  25.                 ["Âme","Or"]
  26.                 ]
  27.   #Taux de conversion des monnaie (a mettre dans le même ordre que le tableau juste au dessus)
  28.   TAUX_CONVERSION = [[100,1], # <= 100 or pour 1 Âme
  29.                      [1,10],  # <= 1 or pour 10 argent
  30.                      [1,100], # <= 1 or pour 100 cuivre
  31.                      [10,1],  # <= 10 argent pour 1 or
  32.                      [1,10],  # <= 1 argent pour 10 cuivre
  33.                      [100,1], # <= 100 cuivre pour 1 or
  34.                      [10,1],  # <= 10 cuivre pour 1 argent
  35.                      [1,100]  # <= 1 Âme pour 100 or
  36.                      ]
  37. =begin
  38.   Nouvelle fonction :
  39.   Dans un text au lieu de mettre \G on peut désormais mettre \G[id] pour
  40.   remplacer par le nom de la id'eme monnaie
  41.  
  42.   En appel de script pour changer recuperer la valeur d'une monnaie :
  43.  
  44.   #Ajout de monnaie
  45.   gain_monnaie(name,value)
  46.   name => sont nom ex "Or"
  47.   value => la valeur du gain
  48.  
  49.   #Perte de monnaie
  50.   perte_monnaie(name,value)
  51.   name => sont nom ex "Or"
  52.   value => la valeur de la perte
  53.  
  54.   #Recuperer la valeur d'une monnaie
  55.   monnaie(name)
  56.   name => sont nom ex "Or"
  57.   OU
  58.   name => tableau de nom ex: ["Or","Argent"]
  59.  
  60.   #Pour lancer un magasin avec une monnaie particulière:
  61.    Faire un appel de script : magasin(name)
  62.    name est le nom de la monnaie utilisable ou un tableau des monnaie utilisable
  63.    Faire ensuite un appel de magasin basique
  64.    ATTENTION : les objet du magasin doivent avoir été définit comme ci-dessous
  65.    Sinon une erreur va ce produire
  66.    ex : magasin("Or")
  67.    ou : magasin(["Or","Argent"])
  68.    
  69.   #Pour définir le prix d'un item :
  70.    Dans la note de l'item mettre :
  71.    <Money = Prix,MON,PRIX,MON,...>
  72.    ex : <Money = 50,Or,20,Argent> pour 50 d'or et 20 d'argent
  73.    
  74.   #Pour définir le gain d'argent sur un monstre
  75.    mettre dans la note du monstre :
  76.    <Money = GAIN,MON,GAIN,MON,...>
  77.    ex : <Money = 10,Or,20,Cuivre> pour 10 d'or et 20 de cuivre
  78.    
  79.   #Pour lancer le menu de conversion de monnaie :
  80.    SceneManager.call(Scene_Conversion)
  81. =end
  82. end
  83. #############################
  84. # Modification BattleManager#
  85. #############################
  86. module BattleManager
  87.   def self.gain_gold
  88.     if $game_troop.gold_total(true) != ""
  89.       $game_message.add('\.' + $game_troop.gold_total)
  90.     end
  91.     wait_for_message
  92.   end
  93. end
  94. ##########################
  95. # Modification Game_Troop#
  96. ##########################
  97. class Game_Troop
  98.   def gold_total(test = false)
  99.     result = {}
  100.     r = 0
  101.     for ene in 0..dead_members.length-1
  102.       r += dead_members[ene].gold * gold_rate
  103.       if $data_enemies[dead_members[ene].enemy_id].note =~ /<Money = (\S+)>/
  104.         array = $1.split(",")
  105.         for i in 0..(array.length-1)/2
  106.           if result.has_key?(array[i*2+1])
  107.             result[array[i*2+1]] += array[i*2].to_i * gold_rate
  108.           else
  109.             result[array[i*2+1]] = array[i*2].to_i * gold_rate
  110.           end
  111.         end
  112.       end
  113.     end
  114.     $game_party.gain_gold(r) if r != 0
  115.     return sprintf(Vocab::ObtainGold, $game_troop.gold_total) if result.empty? && r != 0
  116.     texte = ""
  117.     i = 0
  118.     result.each do |key,value|
  119.       id = Monnaie::NAME.index(key)
  120.       texte += sprintf("%s %s trouvés !",value,key) if i == 0
  121.       texte += sprintf("\n%s %s trouvés !",value,key) if i != 0
  122.       $game_party.gain_gold(value,id) if !test
  123.       i += 1
  124.     end
  125.     return texte
  126.   end
  127. end
  128. #############################
  129. # New class Scene_Conversion#
  130. #############################
  131. class Scene_Conversion < Scene_MenuBase
  132.   def start
  133.     super
  134.     create_help_window
  135.     create_gold_window
  136.     create_list_window
  137.     create_number_window
  138.   end
  139.   def create_gold_window
  140.     @gold_window = Window_Gold.new
  141.     @gold_window.viewport = @viewport
  142.     @gold_window.x = Graphics.width - @gold_window.width
  143.     @gold_window.y = @help_window.height
  144.     array = Monnaie::MONNAIE_MENU
  145.     if array.length > 1
  146.       @gold_window.height = 24+24+@help_window.height
  147.       @gold_window.y = 0
  148.       @help_window.width = Graphics.width-@gold_window.width
  149.       @help_window.create_contents
  150.     end
  151.     @gold_window.value_affichage = array
  152.     @gold_window.create_contents
  153.     @gold_window.refresh
  154.     @help_window.height = @gold_window.height
  155.   end
  156.   def create_list_window
  157.     @list_window = Window_Conversion_List.new(0, @help_window.height, Graphics.width/2,Graphics.height-@help_window.height)
  158.     @list_window.help_window = @help_window
  159.     @list_window.set_handler(:ok,     method(:on_list_ok))
  160.     @list_window.set_handler(:cancel, method(:on_list_cancel))
  161.     @list_window.refresh
  162.     @list_window.select(0)
  163.     @list_window.activate
  164.   end
  165.   def on_list_ok
  166.     return on_number_cancel if !@list_window.enabled?(@list_window.index)
  167.     @number_window.set(@list_window.index)
  168.     @number_window.activate
  169.     @list_window.deactivate
  170.   end
  171.   def on_list_cancel
  172.     return_scene
  173.   end
  174.   def create_number_window
  175.     wy = @list_window.y
  176.     wh = @list_window.height
  177.     @number_window = Window_ConvertNumber.new(Graphics.width/2, wy, Graphics.width/2, wh)
  178.     @number_window.viewport = @viewport
  179.     @number_window.set_handler(:ok,     method(:on_number_ok))
  180.     @number_window.set_handler(:cancel, method(:on_number_cancel))
  181.     @number_window.deactivate
  182.   end
  183.   def on_number_ok
  184.     nbr = @number_window.number
  185.     taux = @number_window.taux
  186.     id = Monnaie::NAME.index(@number_window.from)
  187.     id2 = Monnaie::NAME.index(@number_window.to)
  188.     $game_party.lose_gold(nbr*taux[0],id)
  189.     $game_party.gain_gold(nbr*taux[1],id2)
  190.     @gold_window.refresh
  191.     @list_window.refresh
  192.     on_number_cancel
  193.   end
  194.   def on_number_cancel
  195.     @number_window.deactivate
  196.     @number_window.contents.clear
  197.     @list_window.activate
  198.   end
  199. end
  200. ##############################
  201. # New class Window_ShopNumber#
  202. ##############################
  203. class Window_ConvertNumber < Window_Selectable
  204.   attr_reader   :number                   # quantity entered
  205.   attr_reader   :from
  206.   attr_reader   :to
  207.   attr_reader   :taux
  208.   def initialize(x, y, width, height)
  209.     super(x, y, width, height)
  210.     @max = 1
  211.   end
  212.   def set(index)
  213.     @from = Monnaie::CONVERSION[index][0]
  214.     @to = Monnaie::CONVERSION[index][1]
  215.     id = Monnaie::NAME.index(@from)
  216.     id2 = Monnaie::NAME.index(@to)
  217.     @taux = Monnaie::TAUX_CONVERSION[index]
  218.     @max = ($game_party.gold2[id]/@taux[0])
  219.     if Monnaie::MAX_VALUE[id2] != nil
  220.       @max = [@max,(Monnaie::MAX_VALUE[id2]-$game_party.gold2[id2])/@taux[1]].min
  221.     end
  222.     @number = 1
  223.     refresh
  224.   end
  225.   def refresh
  226.     contents.clear
  227.     draw_name
  228.     draw_number
  229.     draw_total_price
  230.   end
  231.   def draw_name
  232.     draw_text(0, item_y-line_height, contents_width , line_height, @taux[0].to_s+" X "+@from+" => "+@taux[1].to_s+" X "+@to)
  233.     change_color(system_color)
  234.     draw_text(0, item_y, contents_width , line_height, @from)
  235.     change_color(normal_color)
  236.     draw_text(text_size(@from).width, item_y, contents_width , line_height, " => ")
  237.     change_color(system_color)
  238.     draw_text(text_size(@from+" => ").width, item_y, contents_width , line_height, @to)
  239.     change_color(normal_color)
  240.   end
  241.   def draw_number
  242.     change_color(normal_color)
  243.     draw_text(cursor_x - 28, item_y, 22, line_height, "×")
  244.     draw_text(cursor_x, item_y, cursor_width - 4, line_height, @number, 2)
  245.   end
  246.   def draw_total_price
  247.     width = contents_width - 8
  248.     rect = Rect.new(4,price_y,width,line_height)
  249.     id = Monnaie::NAME.index(@from)
  250.     id2 = Monnaie::NAME.index(@to)
  251.     width_tot = 0
  252.     width_tot += text_size(($game_party.gold2[id]-@taux[0]*@number).to_s).width
  253.     if Monnaie::ICON[id] != nil
  254.       width_tot += 24
  255.     else
  256.       width_tot += text_size(" " + @from).width
  257.     end
  258.     width_tot += text_size("   ").width
  259.     width_tot += text_size(($game_party.gold2[id2]+@taux[1]*@number).to_s).width
  260.     if Monnaie::ICON[id2] != nil
  261.       width_tot += 24
  262.     else
  263.       width_tot += text_size(" " + @to).width
  264.     end
  265.     rect.width -= width_tot
  266.     rect.width += text_size(($game_party.gold2[id]-@taux[0]*@number).to_s).width
  267.     draw_text(rect, ($game_party.gold2[id]-@taux[0]*@number).to_s, 2)
  268.     if Monnaie::ICON[id] != nil
  269.       rect.width += 24
  270.       draw_icon(Monnaie::ICON[id], rect.x+rect.width-24, rect.y)
  271.     else
  272.       rect.width += text_size(" " + @from).width
  273.       draw_text(rect, " " + @from, 2)
  274.     end
  275.     rect.width += text_size("   ").width
  276.     draw_text(rect, "   ", 2)
  277.     rect.width += text_size(($game_party.gold2[id2]+@taux[1]*@number).to_s).width
  278.     draw_text(rect, ($game_party.gold2[id2]+@taux[1]*@number).to_s, 2)
  279.     if Monnaie::ICON[id2] != nil
  280.       rect.width += 24
  281.       draw_icon(Monnaie::ICON[id2], rect.x+rect.width-24, rect.y)
  282.     else
  283.       rect.width += text_size(" " + @to).width
  284.       draw_text(rect, " " + @to, 2)
  285.     end
  286.   end
  287.   def item_y
  288.     contents_height / 2 - line_height * 3 / 2
  289.   end
  290.   def price_y
  291.     contents_height / 2 + line_height / 2
  292.   end
  293.   def cursor_width
  294.     figures * 10 + 12
  295.   end
  296.   def cursor_x
  297.     contents_width - cursor_width - 4
  298.   end
  299.   def figures
  300.     return 2
  301.   end
  302.   def update
  303.     super
  304.     if active
  305.       last_number = @number
  306.       update_number
  307.       if @number != last_number
  308.         Sound.play_cursor
  309.         refresh
  310.       end
  311.     end
  312.   end
  313.   def update_number
  314.     change_number(1)   if Input.repeat?(:RIGHT)
  315.     change_number(-1)  if Input.repeat?(:LEFT)
  316.     change_number(10)  if Input.repeat?(:UP)
  317.     change_number(-10) if Input.repeat?(:DOWN)
  318.   end
  319.   def change_number(amount)
  320.     @number = [[@number + amount, @max].min, 1].max
  321.   end
  322.   def update_cursor
  323.     cursor_rect.set(cursor_x, item_y, cursor_width, line_height)
  324.   end
  325. end
  326. ###################################
  327. # New class Window_Conversion_List#
  328. ###################################
  329. class Window_Conversion_List < Window_Selectable
  330.   def initialize(x,y,w,h)
  331.     super(x,y,w,h)
  332.     @data = []
  333.   end
  334.   def col_max
  335.     return 1
  336.   end
  337.   def item_max
  338.     @data ? @data.size : 1
  339.   end
  340.   def item
  341.     @data && index >= 0 ? @data[index] : nil
  342.   end
  343.   def make_item_list
  344.     @data = []
  345.     for i in Monnaie::CONVERSION
  346.       @data.push(i[0]+" => "+i[1])
  347.     end
  348.   end
  349.   def enabled?(index)
  350.     @from = Monnaie::CONVERSION[index][0]
  351.     @to = Monnaie::CONVERSION[index][1]
  352.     id = Monnaie::NAME.index(@from)
  353.     id2 = Monnaie::NAME.index(@to)
  354.     @taux = Monnaie::TAUX_CONVERSION[index]
  355.     @max = ($game_party.gold2[id]/@taux[0])
  356.     if Monnaie::MAX_VALUE[id2] != nil
  357.       @max = [@max,(Monnaie::MAX_VALUE[id2]-$game_party.gold2[id2])/@taux[1]].min
  358.     end
  359.     return false if @max == 0
  360.     return true
  361.   end
  362.   def draw_item(index)
  363.     rect = item_rect(index)
  364.     change_color(normal_color, enabled?(index))
  365.     draw_text(rect.x, rect.y, rect.width,rect.height,@data[index])
  366.   end
  367.   def refresh
  368.     make_item_list
  369.     create_contents
  370.     draw_all_items
  371.   end
  372.   def update_help
  373.     text = "Convertir "
  374.     text += Monnaie::CONVERSION[index][0]
  375.     text += " en "
  376.     text += Monnaie::CONVERSION[index][1]
  377.     @help_window.set_text(text) if @help_window
  378.   end
  379. end
  380. ################################
  381. # Modification de la Scene_Shop#
  382. ################################
  383. class Scene_Shop < Scene_MenuBase
  384.   alias prepare_monnaie prepare
  385.   def prepare(goods, purchase_only,monnaie)
  386.     prepare_monnaie(goods, purchase_only)
  387.     @monnaie = monnaie
  388.     msgbox("Monnaie non définit pour ce shop") if @monnaie == nil
  389.   end
  390.   alias create_gold_window_monnaie create_gold_window
  391.   def create_gold_window
  392.     create_gold_window_monnaie
  393.     array = @monnaie
  394.     array = [@monnaie] if !@monnaie.is_a?(Array)
  395.     if array.length > 1
  396.       @gold_window.height = 24+24+@help_window.height
  397.       @gold_window.y = 0
  398.       @help_window.width = Graphics.width-@gold_window.width
  399.       @help_window.create_contents
  400.     end
  401.     @gold_window.value_affichage = array
  402.     @gold_window.create_contents
  403.     @gold_window.refresh
  404.   end
  405.   def create_buy_window
  406.     wy = @dummy_window.y
  407.     wh = @dummy_window.height
  408.     @buy_window = Window_ShopBuy.new(0, wy, wh, @goods, money)
  409.     @buy_window.viewport = @viewport
  410.     @buy_window.help_window = @help_window
  411.     @buy_window.status_window = @status_window
  412.     @buy_window.hide
  413.     @buy_window.set_handler(:ok,     method(:on_buy_ok))
  414.     @buy_window.set_handler(:cancel, method(:on_buy_cancel))
  415.   end
  416.   alias do_buy_multi_monnaie do_buy
  417.   def do_buy(number)
  418.     if buying_price.is_a?(Integer)
  419.       do_buy_multi_monnaie(number)
  420.     else
  421.       buying_price.each do |key,value|
  422.         id = Monnaie::NAME.index(key)
  423.         $game_party.lose_gold((value*number),id)
  424.       end
  425.       $game_party.gain_item(@item, number)
  426.     end
  427.   end
  428.   alias do_sell_multi_monnaie do_sell
  429.   def do_sell(number)
  430.     if selling_price.is_a?(Integer)
  431.       do_sell_multi_monnaie(number)
  432.     else
  433.       selling_price.each do |key,value|
  434.         id = Monnaie::NAME.index(key)
  435.         $game_party.gain_gold((value*number),id)
  436.       end
  437.       $game_party.lose_item(@item, number)
  438.     end
  439.   end
  440.   alias max_buy_multi_monnaie max_buy
  441.   def max_buy
  442.     max = $game_party.max_item_number(@item) - $game_party.item_number(@item)
  443.     if buying_price.is_a?(Integer)
  444.       return max_buy_multi_monnaie
  445.     else
  446.       ok = [max]
  447.       buying_price.each do |key,value|
  448.         id = Monnaie::NAME.index(key)
  449.         ok.push($game_party.gold2[id] / value)
  450.       end
  451.       return ok.min
  452.     end
  453.   end
  454.   def money
  455.     @gold_window.value_affichage
  456.   end
  457.   def selling_price
  458.     if @item.note =~ /<Money = (\S+)>/
  459.       array = $1.split(",")
  460.       result = {}
  461.       for i in 0..(array.length-1)/2
  462.         result[array[i*2+1]] = array[i*2].to_i
  463.       end
  464.       return result
  465.     else
  466.       return @item.price / 2
  467.     end
  468.   end
  469. end
  470. ######################################
  471. # Modification de la Window ShopSell #
  472. ######################################
  473. class Window_ShopSell < Window_ItemList
  474.   def enable?(item)
  475.     if item.note =~ /<Money = (\S+)>/
  476.       return true
  477.     else
  478.       return item && item.price > 0
  479.     end
  480.   end
  481. end
  482. ########################################
  483. # Modification de la window ShopNumber #
  484. ########################################
  485. class Window_ShopNumber < Window_Selectable
  486.   alias draw_total_price_multi_monnaie draw_total_price
  487.   def draw_total_price ############
  488.     if @price.is_a?(Integer)
  489.       draw_total_price_multi_monnaie
  490.     else
  491.       width = contents_width - 8
  492.       rect = Rect.new(4,price_y,width,line_height)
  493.       width_tot = 0
  494.       @price.each do |key,value|
  495.         width_tot += text_size((value*@number).to_s).width
  496.         if Monnaie::ICON[Monnaie::NAME.index(key)] != nil
  497.           width_tot += 24
  498.         else
  499.           width_tot += text_size(key).width
  500.         end
  501.       end
  502.       rect.width -= width_tot
  503.       @price.each do |key,value|
  504.         id = Monnaie::ICON[Monnaie::NAME.index(key)]
  505.         rect.width += text_size((value*@number).to_s).width
  506.         draw_text(rect, (value*@number).to_s, 2)
  507.         if id != nil
  508.           rect.width += 24
  509.           draw_icon(id, rect.x+rect.width-24, rect.y)
  510.         else
  511.           rect.width += text_size(key).width
  512.           draw_text(rect, key, 2)
  513.         end
  514.       end
  515.     end
  516.   end
  517. end
  518. #####################################
  519. # Modification de la window shopBuy #
  520. #####################################
  521. class Window_ShopBuy < Window_Selectable
  522.   def initialize(x, y, height, shop_goods,money = 0)
  523.     super(x, y, window_width, height)
  524.     @shop_goods = shop_goods
  525.     @money = money
  526.     refresh
  527.     select(0)
  528.   end
  529.   def enable?(item)
  530.     if item && !$game_party.item_max?(item)
  531.       price(item).each do |key,value|
  532.         return false if !@money.include?(Monnaie::NAME.index(key)+1)
  533.         return false if value > $game_party.gold2[Monnaie::NAME.index(key)]
  534.       end
  535.     else
  536.       return false
  537.     end
  538.     return true
  539.   end
  540.   def make_item_list
  541.     @data = []
  542.     @price = {}
  543.     @shop_goods.each do |goods|
  544.       case goods[0]
  545.       when 0;  item = $data_items[goods[1]]
  546.       when 1;  item = $data_weapons[goods[1]]
  547.       when 2;  item = $data_armors[goods[1]]
  548.       end
  549.       if item
  550.         @data.push(item)
  551.         if item.note =~ /<Money = (\S+)>/
  552.           array = $1.split(",")
  553.           result = {}
  554.           for i in 0..(array.length-1)/2
  555.             result[array[i*2+1]] = array[i*2].to_i
  556.           end
  557.           @price[item] = result
  558.         else
  559.           @price[item] = goods[2] == 0 ? item.price : goods[3]
  560.         end
  561.       end
  562.     end
  563.   end
  564.   def draw_item(index)
  565.     item = @data[index]
  566.     rect = item_rect(index)
  567.     draw_item_name(item, rect.x, rect.y, enable?(item))
  568.     rect.width -= 4
  569.     if price(item).is_a?(Integer)
  570.       draw_text(rect, price(item), 2)
  571.     else
  572.       width_tot = 0
  573.       price(item).each do |key,value|
  574.           width_tot += text_size(value.to_s).width
  575.         if Monnaie::ICON[Monnaie::NAME.index(key)] != nil
  576.           width_tot += 24
  577.         else
  578.           width_tot += text_size(key).width
  579.         end
  580.       end
  581.       rect.width -= width_tot
  582.       price(item).each do |key,value|
  583.         id = Monnaie::ICON[Monnaie::NAME.index(key)]
  584.         rect.width += text_size(value.to_s).width
  585.         draw_text(rect, value.to_s, 2)
  586.         if id != nil
  587.           rect.width += 24
  588.           draw_icon(id, rect.x+rect.width-24, rect.y,enable?(item))
  589.         else
  590.           rect.width += text_size(key).width
  591.           draw_text(rect, key, 2)
  592.         end
  593.       end
  594.     end
  595.   end
  596. end
  597. ##################################
  598. # Modification de la window gold #
  599. ##################################
  600. class Scene_Menu
  601.   alias create_gold_window_monnaie create_gold_window
  602.   def create_gold_window
  603.     create_gold_window_monnaie
  604.     @gold_window.value_affichage = Monnaie::MONNAIE_MENU
  605.     @gold_window.height = (Monnaie::MONNAIE_MENU.length+1)*24
  606.     @gold_window.y = Graphics.height - @gold_window.height
  607.     @gold_window.create_contents
  608.     @gold_window.refresh
  609.   end
  610. end
  611. ###################
  612. # Ajout du \G[id] #
  613. ###################
  614. class Window_Base
  615.   alias convert_escape_characters_monnaie convert_escape_characters
  616.   def convert_escape_characters(text)
  617.     result = text.to_s.clone
  618.     result.gsub!(/\\/)            { "\e" }
  619.     result.gsub!(/\eG\[(\d+)\]/i) { Monnaie::NAME[$1.to_i-1] }
  620.     convert_escape_characters_monnaie(result)
  621.   end
  622. end
  623. ##################################
  624. # Modification de la window gold #
  625. ##################################
  626. class Window_Gold < Window_Base
  627.   attr_accessor :value_affichage
  628.   alias initialize_monnaie initialize
  629.   def initialize
  630.     @value_affichage = []
  631.     initialize_monnaie
  632.   end
  633.   def refresh
  634.     contents.clear
  635.     for i in 0..@value_affichage.length-1
  636.       draw_currency_value(value(@value_affichage[i]-1), currency_unit(@value_affichage[i]-1), 4, i*line_height, contents.width - 8)
  637.     end
  638.   end
  639.   def value(id = nil)
  640.     return $game_party.gold if id == nil
  641.     return $game_party.gold2[id]
  642.   end
  643.   def draw_currency_value(value, unit, x, y, width)
  644.     if unit.is_a?(Integer)
  645.       change_color(normal_color)
  646.       draw_text(x, y, width - 24 - 2, line_height, value, 2)
  647.       draw_icon(unit, x+width-24, y)
  648.     else
  649.       cx = text_size(unit).width
  650.       change_color(normal_color)
  651.       draw_text(x, y, width - cx - 2, line_height, value, 2)
  652.       change_color(system_color)
  653.       draw_text(x, y, width, line_height, unit, 2)
  654.     end
  655.   end
  656.   def currency_unit(id = nil)
  657.     return Vocab::currency_unit if id == nil
  658.     return Monnaie::ICON[id] != nil ? Monnaie::ICON[id] : Monnaie::NAME[id]
  659.   end
  660. end
  661. ################################
  662. # Ajout des monnaie a l'équipe #
  663. ################################
  664. class Game_Party
  665.   attr_reader :gold2
  666.   alias initialize_monnaie initialize
  667.   alias gain_gold_monnaie gain_gold
  668.   alias max_gold_monnaie max_gold
  669.  
  670.   def initialize
  671.     initialize_monnaie
  672.     super
  673.     @gold2 = Array.new(Monnaie::NBR_MONNAIE,0)
  674.   end
  675.   def gain_gold(amount,id = nil)
  676.     if id == nil
  677.       gain_gold_monnaie(amount)
  678.     else
  679.       if max_gold(id)
  680.         @gold2[id] = [[@gold2[id]+amount,0].max,max_gold(id)].min
  681.       else
  682.         @gold2[id] = [@gold2[id]+amount,0].max
  683.       end
  684.     end
  685.   end
  686.   def lose_gold(amount,id = nil)
  687.     gain_gold(-amount, id)
  688.   end
  689.   def max_gold(id = nil)
  690.     return max_gold_monnaie if id == nil
  691.     return Monnaie::MAX_VALUE[id]
  692.   end
  693. end
  694. #############################################
  695. # Ajout de commande de modification monnaie #
  696. #############################################
  697. class Game_Interpreter
  698.  
  699.   def command_302
  700.     return if $game_party.in_battle
  701.     goods = [@params]
  702.     while next_event_code == 605
  703.       @index += 1
  704.       goods.push(@list[@index].parameters)
  705.     end
  706.     SceneManager.call(Scene_Shop)
  707.     SceneManager.scene.prepare(goods, @params[4],@magasin_monnaie)
  708.     @magasin_monnaie = nil
  709.     Fiber.yield
  710.   end
  711.  
  712.   def magasin(name)
  713.     if name.is_a?(Array)
  714.       result = []
  715.       for i in name
  716.         result.push(Monnaie::NAME.index(i)+1)
  717.       end
  718.     else
  719.       result = Monnaie::NAME.index(name)+1
  720.     end
  721.     @magasin_monnaie = result
  722.   end
  723.  
  724.   def gain_monnaie(name,value)
  725.     id = Monnaie::NAME.index(name)
  726.     $game_party.gain_gold(value,id)
  727.   end
  728.   def perte_monnaie(name,value)
  729.     id = Monnaie::NAME.index(name)
  730.     $game_party.lose_gold(value,id)
  731.   end
  732.   def monnaie(name)
  733.     id = Monnaie::NAME.index(name)
  734.     return $game_party.gold2[id]
  735.   end
  736. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement