仙剑之十里坡

标题: [6r教程整理]通用魔法商店 [打印本页]

作者: 最爱南宫煌    时间: 2010-7-2 22:33
标题: [6r教程整理]通用魔法商店
  1. #==============================================================================
  2. # ■ 本脚本源自www.66rpg.com,转载与使用请保留此信息
  3. #==============================================================================

  4. #——以下是一些自定义的内容

  5. $mShop_use_1 = "灵魄"    #——这项是购买魔法特技的货币的名称,如“灵魄”、“金钱”

  6. $mShop_use_2 = "特斯拉"  #——这项是购买魔法特技的货币单位,如“点”、“¥”

  7. $mShop_use_variable = 1  #——这项是购买魔法特技时消耗的变量编号,如果=0 则是消耗金钱

  8. $mShop_Window_Opacity = 200  #——这项是窗口透明度

  9. #==============================================================================
  10. # ■ Window_MGold
  11. #------------------------------------------------------------------------------
  12. #  显示金钱的窗口。
  13. #==============================================================================
  14. class Window_MGold < Window_Base
  15.   #--------------------------------------------------------------------------
  16.   # ● 初始化窗口
  17.   #--------------------------------------------------------------------------
  18.   def initialize
  19.     super(0, 0, 272, 64)
  20.     self.contents = Bitmap.new(width - 32, height - 32)
  21.     refresh
  22.   end
  23.   #--------------------------------------------------------------------------
  24.   # ● 刷新
  25.   #--------------------------------------------------------------------------
  26.   def refresh
  27.     self.contents.clear
  28.     self.contents.font.color = system_color
  29.     self.contents.draw_text(0, 0 , 240,32 ,$mShop_use_1)
  30.     self.contents.font.color = normal_color
  31.     self.contents.draw_text(0, 0, 240-contents.text_size($mShop_use_2).width-6, 32, $mShop_gold.to_s, 2)
  32.     self.contents.font.color = system_color
  33.     self.contents.draw_text(0, 0, 240, 32, $mShop_use_2, 2)
  34.   end
  35. end
  36. #==============================================================================
  37. # ■ Scene_MShop
  38. #------------------------------------------------------------------------------
  39. #  处理特技商店画面的类。
  40. #==============================================================================
  41. class Scene_MShop
  42.   #--------------------------------------------------------------------------
  43.   # ● 初始化
  44.   #--------------------------------------------------------------------------
  45.   def initialize(id)
  46.     @id = id
  47.   end   
  48.   #--------------------------------------------------------------------------
  49.   # ● 主处理
  50.   #--------------------------------------------------------------------------
  51.   def main
  52.     screen = Spriteset_Map.new
  53.     if $mShop_use_variable == 0
  54.       $mShop_gold = $game_party.gold
  55.     else
  56.       $mShop_gold = $game_variables[$mShop_use_variable]
  57.     end
  58.     # 生成帮助窗口
  59.     @help_window = Window_Help.new
  60.     @help_window.opacity = $mShop_Window_Opacity
  61.     # 生成金钱窗口
  62.     @gold_window = Window_MGold.new
  63.     @gold_window.x = 368
  64.     @gold_window.y = 416
  65.     @gold_window.opacity = $mShop_Window_Opacity
  66.     # 生成购买窗口
  67.     @buy_window = Window_MShopBuy.new(@id)
  68.     @buy_window.active = true
  69.     @buy_window.visible = true
  70.     @buy_window.help_window = @help_window
  71. @buy_window.opacity = $mShop_Window_Opacity
  72.     # 生成状态窗口
  73.     @status_window = Window_MShopStatus.new
  74.     @status_window.visible = true
  75.     @status_window.active = false
  76.     @status_window.opacity = $mShop_Window_Opacity
  77.     # 执行过渡
  78.     Graphics.transition
  79.     # 主循环
  80.     loop do
  81.       # 刷新游戏画面
  82.       Graphics.update
  83.       # 刷新输入信息
  84.       Input.update
  85.       # 刷新画面
  86.       update
  87.       # 如果画面切换的话就中断循环
  88.       if $scene != self
  89.         break
  90.       end
  91.     end
  92.     # 准备过渡
  93.     Graphics.freeze
  94.     # 释放窗口
  95.     @help_window.dispose
  96.     #@mhelp_window.dispose
  97.     @gold_window.dispose
  98.     @buy_window.dispose
  99.     @status_window.dispose
  100.     screen.dispose
  101.   end
  102.   #--------------------------------------------------------------------------
  103.   # ● 刷新画面
  104.   #--------------------------------------------------------------------------
  105.   def update
  106.     # 刷新窗口
  107.     @help_window.update
  108.     #@mhelp_window.update
  109.     @gold_window.update
  110.     @buy_window.update
  111.     @status_window.update
  112.     # 购买窗口激活的情况下: 调用 update_buy
  113.     if @buy_window.active
  114.       update_buy
  115.       return
  116.     end
  117.     if @status_window.active
  118.       update_status
  119.       return
  120.     end
  121.   end
  122.   #--------------------------------------------------------------------------
  123.   # ● 刷新画面 (购买窗口激活的情况下)
  124.   #--------------------------------------------------------------------------
  125.   def update_buy
  126.     @status_window.skill = @buy_window.skill
  127.     if Input.trigger?(Input::B)
  128.       $game_system.se_play($data_system.cancel_se)
  129.       $scene = Scene_Map.new
  130.       return
  131.     end
  132.     if Input.trigger?(Input::C)
  133.       @skill = @buy_window.skill
  134.       if @skill == nil or @skill.price > $mShop_gold
  135.         $game_system.se_play($data_system.buzzer_se)
  136.         return
  137.       end
  138.       $game_system.se_play($data_system.decision_se)
  139.       @buy_window.active = false
  140.       @status_window.index = 0
  141.       @status_window.active = true
  142.     end
  143.   end
  144.   #--------------------------------------------------------------------------
  145.   # ● 刷新画面 (状态窗口激活的情况下)
  146.   #--------------------------------------------------------------------------
  147.   def update_status
  148.     if Input.trigger?(Input::B)
  149.       $game_system.se_play($data_system.cancel_se)
  150.       @status_window.active = false
  151.       @status_window.index = -1
  152.       @buy_window.active = true
  153.     end
  154.     if Input.trigger?(Input::C)
  155.       if $game_party.actors[@status_window.index].skill_learn?(@skill.id)
  156.         $game_system.se_play($data_system.cancel_se)
复制代码

作者: 最爱南宫煌    时间: 2010-7-2 22:34
  1.         return
  2.       else
  3.         $game_system.se_play($data_system.decision_se)
  4.         if $mShop_use_variable == 0
  5.           $game_party.gain_gold(-@skill.price)
  6.           $mShop_gold -= @skill.price
  7.         else
  8.           $game_variables[$mShop_use_variable] -= @skill.price
  9.           $mShop_gold -= @skill.price
  10.         end
  11.         $game_party.actors[@status_window.index].learn_skill(@skill.id)
  12.         @gold_window.refresh
  13.         @buy_window.refresh
  14.        @status_window.refresh
  15.         @status_window.active = false
  16.         @status_window.index = -1
  17.         @buy_window.active = true
  18.       end      
  19.     end     
  20.   end
  21. end
  22. #==============================================================================
  23. # ■ Window_MShopStatus
  24. #------------------------------------------------------------------------------
  25. #  特技商店画面、显示物品所持数与角色装备的窗口。
  26. #==============================================================================
  27. class Window_MShopStatus < Window_Selectable
  28.   #--------------------------------------------------------------------------
  29.   # ● 初始化对像
  30.   #--------------------------------------------------------------------------
  31.   def initialize
  32.     super(368, 64, 272, 352)
  33.     self.contents = Bitmap.new(width - 32, height - 32)
  34.     self.contents.font.size = 18
  35.     @skill = nil
  36.     refresh
  37.   end
  38.   #--------------------------------------------------------------------------
  39.   # ● 刷新
  40.   #--------------------------------------------------------------------------
  41.   def refresh
  42.     self.contents.clear
  43.     for i in 0...$game_party.actors.size
  44.       actor = $game_party.actors[i]
  45.       draw_actor_graphic(actor,12,80*i+64)
  46.       self.contents.font.color = system_color
  47.       self.contents.draw_text(44, 80*i, 240, 32, actor.name)
  48.       self.contents.draw_text(0, 80*i , 240-20,32,"等级",2)
  49.       self.contents.font.color = normal_color
  50.       self.contents.draw_text(0, 80*i, 240, 32, actor.level.to_s , 2)
  51.       self.contents.font.color = system_color
  52.       self.contents.draw_text(44, 80*i+22, 45, 32, $data_system.words.hp)
  53.       self.contents.font.color = normal_color
  54.       self.contents.draw_text(44, 80*i+22, 90, 32, actor.maxhp.to_s,2)
  55.       self.contents.font.color = system_color
  56.       self.contents.draw_text(150, 80*i+22, 45, 32, $data_system.words.sp)
  57.       self.contents.font.color = normal_color
  58.       self.contents.draw_text(150, 80*i+22, 90, 32, actor.maxsp.to_s,2)      
  59.       if actor.skill_learn?(@skill.id)
  60.         self.contents.font.color = Color.new(255,255,255,128)
  61.         self.contents.draw_text(44, 80*i+44, 196, 32, "⊙此项特技已经学习⊙",2)         
  62.       else
  63.         self.contents.font.color = Color.new(255,255,0,255)
  64.         self.contents.draw_text(44, 80*i+44, 240, 32, "★此项特技尚未学习★")
  65.       end
  66.     end
  67.     @item_max = $game_party.actors.size
  68.   end
  69.   #--------------------------------------------------------------------------
  70.   # ● 设置物品
  71.   #     item : 新的物品
  72.   #--------------------------------------------------------------------------
  73.   def skill=(skill)
  74.     if @skill != skill
  75.       @skill = skill
  76.       refresh
  77.     end
  78.   end
  79.   #--------------------------------------------------------------------------
  80.   # ● 刷新光标矩形
  81.   #--------------------------------------------------------------------------
  82.   def update_cursor_rect
  83.     if @index < 0
  84.       self.cursor_rect.empty
  85.     else
  86.       self.cursor_rect.set(0, @index * 80, self.width - 32, 80)
  87.     end
  88.   end
  89. end
  90. #==============================================================================
  91. # ■ Window_MShopBuy
  92. #------------------------------------------------------------------------------
  93. #  特技商店画面、浏览显示可以购买的商品的窗口。
  94. #==============================================================================
  95. class Window_MShopBuy < Window_Selectable
  96.   #--------------------------------------------------------------------------
  97.   # ● 初始化对像
  98.   #     shop_goods : 商品
  99.   #--------------------------------------------------------------------------
  100.   def initialize(id)
  101.     super(0, 64, 368, 416)
  102.     @id = id
  103.     refresh
  104.     self.index = 0
  105.   end
  106.   #--------------------------------------------------------------------------
  107.   # ● 获取物品
  108.   #--------------------------------------------------------------------------
  109.   def skill
  110.     return @data[self.index]
  111.   end
  112.   #--------------------------------------------------------------------------
  113.   # ● 刷新
  114.   #--------------------------------------------------------------------------
  115.   def refresh
  116.     if self.contents != nil
  117.       self.contents.dispose
  118.       self.contents = nil
  119.     end
  120.     @data = []
  121.     for skill_id in @id
  122.       skill = $data_skills[skill_id]
  123.       if skill != nil
  124.         @data.push(skill)
  125.       end
  126.     end
  127.     @item_max = @data.size
  128.     if @item_max > 0
  129.       self.contents = Bitmap.new(width - 32, row_max * 32)
  130.       for i in 0...@item_max
  131.         draw_item(i)
  132.       end
  133.     end
  134.   end
  135.   #--------------------------------------------------------------------------
  136.   # ● 描绘羡慕
  137.   #     index : 项目编号
  138.   #--------------------------------------------------------------------------
  139.   def draw_item(index)
  140.     skill = @data[index]
  141.     # 除此之外的情况设置为无效文字色
  142.     if skill.price <= $mShop_gold
  143.       self.contents.font.color = normal_color
  144.     else
  145.       self.contents.font.color = disabled_color
  146.     end
  147.     x = 4
  148.     y = index * 32
  149.     rect = Rect.new(x, y, self.width - 32, 32)
  150.     self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  151.     bitmap = RPG::Cache.icon(skill.icon_name)
  152.     opacity = self.contents.font.color == normal_color ? 255 : 128
  153.     self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
  154.     self.contents.draw_text(x + 28, y, 212, 32, skill.name, 0)
  155.     self.contents.draw_text(x + 240, y, 88, 32, skill.price.to_s, 2)
  156.   end
  157.   #--------------------------------------------------------------------------
  158.   # ● 刷新帮助文本
  159.   #--------------------------------------------------------------------------
  160.   def update_help
  161.     @help_window.set_text(self.skill == nil ? "" : self.skill.description)
  162.   end
  163. end
  164. #==============================================================================
  165. # ■ RPG原装定义
  166. #==============================================================================
  167. module RPG
  168.   class Skill
  169.     def description
  170.       description = @description.split(/@/)[0]
  171.       return description != nil ? description : ''
  172.     end
  173.     def price
  174.       price = @description.split(/@/)[1]
  175.       return price != nil ? price.to_i : 0
  176.     end
  177.   end
  178. end
复制代码

作者: 最爱南宫煌    时间: 2010-7-2 22:34
这个就是买魔法(特技)的商店脚本。
作者: BlackFeather    时间: 2010-7-3 05:38
这个你不传范例没人用得了
作者: 最爱南宫煌    时间: 2010-7-3 11:35
啊?为什么?
作者: BlackFeather    时间: 2010-7-3 12:52
你自己进去看看吧……




欢迎光临 仙剑之十里坡 (http://palslp.com/BBS/) Powered by Discuz! X2.5