设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 3194|回复: 13
打印 上一主题 下一主题

[已经解决] 请教一个关于变量储存的问题

[复制链接]

Lv3.寻梦者

梦石
0
星屑
2421
在线时间
162 小时
注册时间
2020-8-9
帖子
106
跳转到指定楼层
1
发表于 2021-8-10 19:10:13 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
50星屑
由于做了一个强化池,每个精灵都有自己的上限,这样的话,因为精灵有6项基本属性,每个精灵就要占用6个变量,很耗变量,有没有什么办法让这些数据以txt的形式储存到外部而不占用内部的变量呢?

即建立一个TXT,把精灵强化后的积累量放到这个txt里,并且拥有编号,就好像  :
                                                                                                                  “1号项目
                                                                                                                   20
                                                                                                                   2号项目
                                                                                                                   30”
这样子,有点类似“物品合成简易优化版”的那个脚本,但是它不仅要能读取,还要能写入,并且能给写入的数据分组。(我的说法可能不太清晰,请大佬们见谅,我会尽量讲清楚我的问题的)

最佳答案

查看完整内容

我再写详细一点: 1. 独立开关用做独立变量, 将Game_SelfSwitches的第20行 由 return @data[key] == true ? true : false[/pre] 改成 return @data[key] || false[/pre] 2. 精灵数据的存储 首先,建立一个空地图,这个地图不需要任何图块,只用来存储数据及占位用,假设这个地图的编号为200。 然后,在地图上粘贴空事件,每个空事件对应一个精灵(因为独立开关需要依附地图事件而存在)——此步可选,取决于精灵是不是需要 ...

Lv5.捕梦者 (版主)

遠航の猫咪

梦石
3
星屑
22432
在线时间
2335 小时
注册时间
2005-10-15
帖子
1160

开拓者

2
发表于 2021-8-10 19:10:14 | 只看该作者
本帖最后由 SailCat 于 2021-8-13 11:00 编辑

我再写详细一点:
1. 独立开关用做独立变量,
将Game_SelfSwitches的第20行
RUBY 代码复制
  1. return @data[key] == true ? true : false

改成
RUBY 代码复制
  1. return @data[key] || false


2. 精灵数据的存储
首先,建立一个空地图,这个地图不需要任何图块,只用来存储数据及占位用,假设这个地图的编号为200。
然后,在地图上粘贴空事件,每个空事件对应一个精灵(因为独立开关需要依附地图事件而存在)——此步可选,取决于精灵是不是需要行走图等,如果需要行走图,就这样做,如果精灵只是一堆数据,并没有图像,可以跳过这一步。
再次,插入一个插件脚本,内容如下:
RUBY 代码复制
  1. class Interpreter
  2.   def plugin_buff_pixie(id, key, value = nil)
  3.     $game_self_switches[[200, id, key]] ||= 0
  4.     $game_self_switches[[200, id, key]] += (value || 0)
  5.   end
  6. end


3. 每当需要强化精灵时,用事件脚本调用:
plugin_buff_pixie(精灵的ID,强化的类型,强化值),如 plugin_buff_pixie(1, :str, 7) 即为将1号精灵的str值增加7
需要获取精灵的强化能力,则调用plugin_buff_pixie(精灵的ID,强化的类型),如plugin_buff_pixie(1, :str) 即为获取1号精灵的str值,未经设置过的值都是0。

2和3两步其实不是必须的,只是实现一个事件脚本中的插件命令,目的是为了简化操作,方便书写,你也可以每次都用$game_self_switches开头的生代码,但那样会很烦。

这个做法和硬改Game_System的好处相比就是:由于套了独立开关的默认壳子,旧存档100%兼容(这一个好处就足够了)

评分

参与人数 2星屑 +50 +1 收起 理由
RyanBern + 50 认可答案
939034448 + 1 谢谢大佬

查看全部评分

SailCat (小猫子·要开心一点) 共上站 24 次,发表过 11 篇文章 上 次 在: [2006年01月28日11:41:18 星期六] 从 [162.105.120.91] 到本站一游。
回复

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
7921
在线时间
1049 小时
注册时间
2012-4-3
帖子
1271

开拓者

3
发表于 2021-8-10 20:04:18 手机端发表。 | 只看该作者
提供一个思路,比如建一个temp数组变量,然后,a代表精灵属性ID关系,b代表精灵ID关系,写法a = temp[精灵ID]、b = temp[属性ID],也可以有temp[属性ID][精灵ID]的简化方式。
只是前提是,需要自建一个temp变量。这个让楼下来写吧。(手机码字见谅。

评分

参与人数 1+1 收起 理由
939034448 + 1 我试试,谢谢大佬

查看全部评分

回复

使用道具 举报

Lv5.捕梦者 (版主)

梦石
1
星屑
23963
在线时间
3338 小时
注册时间
2011-7-8
帖子
3925

开拓者

4
发表于 2021-8-12 13:35:28 | 只看该作者
所以你可能是想要一个自定义的数据结构,并且保存在存档里?这样可以吗:
  1. class MyData
  2.   attr_accessor :prop1
  3.   attr_accessor :prop2
  4.   attr_accessor :prop3

  5.   # 各属性的初始值
  6.   def initialize
  7.     @prop1 = 0
  8.     @prop2 = 0
  9.     @prop3 = 0
  10.   end
  11. end
复制代码

脚本里调用:
  1. # 存储到变量1里
  2. $game_variables[1] = MyData.new
  3. # 获取属性1
  4. $game_variables[1].prop1
  5. # 修改属性1
  6. $game_variables[1].prop1 = 10
  7. $game_variables[1].prop1 += 10
复制代码

评分

参与人数 1+1 收起 理由
939034448 + 1 是因为做强化池每个精灵都要占用6个变量,.

查看全部评分

熟悉rgss和ruby,xp区版主~
正在填坑:《膜拜组传奇》讲述膜拜组和学霸们的故事。
已上steam:与TXBD合作的Reformers《变革者》
* 战斗调用公共事件 *
* RGSOS 网络脚本 *
回复

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
2421
在线时间
162 小时
注册时间
2020-8-9
帖子
106
5
 楼主| 发表于 2021-8-12 14:16:17 | 只看该作者
guoxiaomi 发表于 2021-8-12 13:35
所以你可能是想要一个自定义的数据结构,并且保存在存档里?这样可以吗:

脚本里调用:

噗,评分里居然显示不完全,我再发一下吧,我是嫌每个精灵占用6个变量位太多了,想把数据储存到外部,就不用占用数据库里的变量位了,毕竟有效变量只有5000,效果的话应该和RyanBern大佬的物品合成简易优化版脚本差不多,但是多了一个写入的功能,物品合成的话只能在外部修改

点评

4 除非你的TXT是存在服务器里去读取内容..否则等於任人修改TXT...  发表于 2021-8-12 19:55
你有以下解决方法..1:不用GAME变量用自定义变量 2:GAME变量可以存数值或哈希..一个变量塞N个数据 3:其实GAME变量可以不只5000  发表于 2021-8-12 19:54
回复

使用道具 举报

Lv5.捕梦者 (版主)

梦石
1
星屑
23963
在线时间
3338 小时
注册时间
2011-7-8
帖子
3925

开拓者

6
发表于 2021-8-12 19:29:23 | 只看该作者
939034448 发表于 2021-8-12 14:16
噗,评分里居然显示不完全,我再发一下吧,我是嫌每个精灵占用6个变量位太多了,想把数据储存到外部,就 ...

嫌变量位太多不一定要把变量的数据储存在外部,RB的脚本你发一下,我看看
熟悉rgss和ruby,xp区版主~
正在填坑:《膜拜组传奇》讲述膜拜组和学霸们的故事。
已上steam:与TXBD合作的Reformers《变革者》
* 战斗调用公共事件 *
* RGSOS 网络脚本 *
回复

使用道具 举报

Lv5.捕梦者

梦石
10
星屑
39440
在线时间
1914 小时
注册时间
2010-11-14
帖子
3315

R考场第七期纪念奖

7
发表于 2021-8-12 22:02:52 | 只看该作者
实际上你可以给Game_System加东西,很多脚本都是这么做的。

举个例子
RUBY 代码复制
  1. class Game_System
  2.   attr_accessor :fairies # 精灵
  3.   alias initialize_for_init_fairies initialize
  4.   def initialize
  5.     initialize_for_init_fairies
  6.     self.fairies = []
  7.   end
  8. end


这样以后,就可以在任何能敲脚本的地方用$game_system.fairies[n]来读写这个数组的第n号元素
由于是在Game_System里,你不用修改存读档的代码。

由于引入了脚本,需要你懂一点基本语法才能驾驭,不过这个学习是值得的。

评分

参与人数 1+1 收起 理由
939034448 + 1 感谢大佬指导!

查看全部评分

用头画头像,用脚写脚本
回复

使用道具 举报

Lv5.捕梦者 (版主)

遠航の猫咪

梦石
3
星屑
22432
在线时间
2335 小时
注册时间
2005-10-15
帖子
1160

开拓者

8
发表于 2021-8-12 23:07:09 | 只看该作者
独立开关当独立变量了解一下?改一行脚本就可以

点评

独立变量的个数没有上限,只和事件数量有关。你可以开一个地图,用1-999号事件存储1-999号精灵的数据。每个精灵使用E-I的六个独立开关号即可。  发表于 2021-8-13 10:42

评分

参与人数 1+1 收起 理由
939034448 + 1 还有这事儿!不过我需要几千个位置也可以吗.

查看全部评分

SailCat (小猫子·要开心一点) 共上站 24 次,发表过 11 篇文章 上 次 在: [2006年01月28日11:41:18 星期六] 从 [162.105.120.91] 到本站一游。
回复

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
2421
在线时间
162 小时
注册时间
2020-8-9
帖子
106
9
 楼主| 发表于 2021-8-13 01:31:40 | 只看该作者
本帖最后由 939034448 于 2021-8-13 01:36 编辑
guoxiaomi 发表于 2021-8-12 19:29
嫌变量位太多不一定要把变量的数据储存在外部,RB的脚本你发一下,我看看 ...

这个脚本只有打开脚本编辑器界面一次才会生效TXT的变动,不过考虑到要做写入的话好像确实是任人修改了......话说有没有给变量破限的,不过听说破限了也是无效变量....
  1. #=============================================================================
  2. # 物品合成简易优化版 Ver 1.0
  3. #-----------------------------------------------------------------------------
  4. # By : RyanBern
  5. #-----------------------------------------------------------------------------
  6. # 功能介绍:
  7. #     这是一个简单的物品合成系统,和论坛上原有的有所不同。在这个系统里面你可以
  8. #     通过学习配方来获取某种道具的合成方法,也可以直接合成。有关数据存储我已经
  9. #     改成了外部文件的形式,下面就说明一下如何使用。
  10. #-----------------------------------------------------------------------------
  11. # 使用方法:
  12. #     1.有关数据编辑,在游戏根目录里面建立一个名为 Recipes.txt 的记事本,然后
  13. #       再里面写下所有配方的内容,下面是一个例子表明如何书写一组完整的数据。
  14. #       <recipe=1>
  15. #         <product>kind=0,id=3</product>
  16. #         <ingredients>
  17. #           kind=0,id=1,number=2
  18. #           kind=0,id=2,number=2
  19. #         </ingredients>
  20. #       </recipe>
  21. #       其中,第一行recipe=1表示这是ID为1的配方的数据,这里ID是从1开始的。
  22. #       第二行是表示最终合成的物品,kind表示分类,道具为0,武器为1,防具为2;id
  23. #       就是对应的ID
  24. #       第三行是原料的设定,所有的材料都必须在<ingredients></ingredients>之间
  25. #       每一行代表一种原料的分类,id,和数量,注意不要写重复了。
  26. #       如果想再增加一条配方,则令起一行开一个<recipe>结点即可。
  27. #     2.有关学习配方:
  28. #       $game_party.recipe_learn?(配方ID) 用于判断是否习得某一配方
  29. #       $game_party.learn_recipe(配方ID) 学习该ID的配方
  30. #       $game_party.forget_recipe(配方ID) 失去该ID的配方
  31. #     3.有关场景调用:
  32. #       $scene = Scene_Craft.new 直接打开合成场景,配方为主角已有的配方
  33. #       $scene = Scene_Craft.new(0/1/2) 打开合成场景,配方为产品分类为i的配方(无论主角是否习得)
  34. #       $scene = Scene_Craft.new(3) 打开合成场景,配方为所有的配方
  35. #-----------------------------------------------------------------------------
  36. # 注意事项:
  37. #     1.Recipes.txt里面的缩进不是必须的。
  38. #     2.游戏发布时,可以删去Recipes.txt,不过建议在你的制作工程中保留一个副本
  39. #       以便日后做出更改。
  40. #-----------------------------------------------------------------------------
  41. # 更新记录:
  42. #=============================================================================
  43. module RB
  44.   Regex_Recipe = /<recipe\s*=\s*(\d+)>(.*?)<\/recipe>/m
  45.   Regex_Product = /<product>\s*kind\s*=\s*(\d)\s*,\s*id\s*=\s*(\d+)\s*<\/product>/m
  46.   Regex_Ingredient = /<ingredients>(.*?)<\/ingredients>/m
  47.   Regex_Ingredient_Info = /kind\s*=\s*(\d)\s*,\s*id\s*=\s*(\d+)\s*,\s*number\s*=\s*(\d+)/
  48. end
  49. module RPG
  50.   class Recipe
  51.     attr_accessor :id
  52.     attr_accessor :product
  53.     attr_accessor :ingredients
  54.     def initialize
  55.       @id = 0
  56.       @product = Ingredient.new
  57.       @ingredients = []
  58.     end
  59.     class Ingredient
  60.       attr_accessor :kind
  61.       attr_accessor :id
  62.       attr_accessor :number
  63.       def initialize(kind = 0, id = 0, number = 0)
  64.         @kind = kind
  65.         @id = id
  66.         @number = number
  67.       end
  68.     end
  69.   end
  70.   def self.extract_recipe
  71.     filename = "Recipes.txt"
  72.     outfile_name = "Data/Recipes.rxdata"
  73.     data = []
  74.     begin
  75.       file = File.open(filename, "r")
  76.       str = file.read
  77.       file.close
  78.       while str.slice!(RB::Regex_Recipe)
  79.         id = $1.to_i
  80.         contents = $2
  81.         recipe = Recipe.new
  82.         recipe.id = id
  83.         if RB::Regex_Product =~ contents
  84.           recipe.product.kind = $1.to_i
  85.           recipe.product.id = $2.to_i
  86.         end
  87.         if RB::Regex_Ingredient =~ contents
  88.           ingredient_contents = $1
  89.           ingredient_contents.scan(RB::Regex_Ingredient_Info) do |a|
  90.             recipe.ingredients << Recipe::Ingredient.new(a[0].to_i, a[1].to_i, a[2].to_i)
  91.           end
  92.         end
  93.         data[id] = recipe
  94.       end
  95.       outfile = File.open(outfile_name, "wb")
  96.       Marshal.dump(data, outfile)
  97.       outfile.close
  98.     rescue
  99.       p 1
  100.     end
  101.   end
  102. end

  103. class Game_Party
  104.   alias rb_initialize_20141226 initialize
  105.   def initialize
  106.     rb_initialize_20141226
  107.     @recipes = {}
  108.   end
  109.   def recipe_learn?(recipe_id)
  110.     @recipes ||= {}
  111.     return @recipes[recipe_id]
  112.   end
  113.   def learn_recipe(recipe_id)
  114.     @recipes ||= {}
  115.     @recipes[recipe_id] = true
  116.   end
  117.   def forget_recipe(recipe_id)
  118.     @recipes ||= {}
  119.     @recipes[recipe_id] = nil
  120.   end
  121.   def product_max_num(recipe_id)
  122.     max = -1
  123.     recipe = $data_recipes[recipe_id]
  124.     return 0 if recipe.nil?
  125.     recipe.ingredients.each do |ingredient|
  126.       num_need = ingredient.number
  127.       case ingredient.kind
  128.       when 0
  129.         num_current = item_number(ingredient.id)
  130.       when 1
  131.         num_current = weapon_number(ingredient.id)
  132.       when 2
  133.         num_current = armor_number(ingredient.id)
  134.       else
  135.         num_current = 0
  136.       end
  137.       max = num_current / num_need if max == -1 || num_current / num_need < max
  138.     end
  139.     return max == -1 ? 0 : max
  140.   end
  141. end

  142. class Window_Product < Window_Selectable
  143.   def initialize(mode = -1)
  144.     super(0, 64, 240, 480 - 64)
  145.     self.index = 0
  146.     @mode = mode
  147.     refresh
  148.   end
  149.   def recipe
  150.     return @data[self.index]
  151.   end
  152.   def item
  153.     recipe = self.recipe
  154.     return nil if recipe.nil?
  155.     product = recipe.product
  156.     case product.kind
  157.     when 0
  158.       item = $data_items[product.id]
  159.     when 1
  160.       item = $data_weapons[product.id]
  161.     when 2
  162.       item = $data_armors[product.id]
  163.     else
  164.       item = nil
  165.     end
  166.     return item
  167.   end
  168.   def refresh
  169.     if self.contents != nil
  170.       self.contents.dispose
  171.       self.contents = nil
  172.     end
  173.     @data = []
  174.     (1...$data_recipes.size).each do |i|
  175.       if @mode == -1 && $game_party.recipe_learn?(i) || $data_recipes[i].product.kind == @mode || @mode == 3
  176.         @data << $data_recipes[i] if $data_recipes[i] != nil
  177.       end
  178.     end
  179.     @item_max = @data.size
  180.     if @item_max > 0
  181.       self.contents = Bitmap.new(width - 32, @item_max * 32)
  182.       @data.each_index{|i| draw_item(i)}
  183.     else
  184.       self.contents = Bitmap.new(width - 32, 32)
  185.       self.contents.draw_text(4, 0, 192, 32, "没有可用配方")
  186.     end
  187.   end
  188.   def draw_item(index)
  189.     x = 4
  190.     y = 32 * index
  191.     product = @data[index].product
  192.     case product.kind
  193.     when 0
  194.       item = $data_items[product.id]
  195.     when 1
  196.       item = $data_weapons[product.id]
  197.     when 2
  198.       item = $data_armors[product.id]
  199.     else
  200.       item = nil
  201.     end
  202.     if item == nil
  203.       return
  204.     end
  205.     disabled = $game_party.product_max_num(@data[index].id) == 0
  206.     bitmap = RPG::Cache.icon(item.icon_name)
  207.     opacity = disabled ? 128 : 255
  208.     self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
  209.     self.contents.font.color = disabled ? disabled_color : normal_color
  210.     self.contents.draw_text(x + 28, y, 176, 32, item.name)
  211.   end
  212.   def update_help
  213.     @help_window.set_text(self.item == nil ? "" : self.item.description)
  214.   end
  215. end

  216. class Window_Ingredients < Window_Base
  217.   def initialize
  218.     super(240, 288, 400, 192)
  219.     @waiting = 0
  220.     @dy = 1
  221.     @recipe = nil
  222.     refresh
  223.   end
  224.   def recipe=(recipe)
  225.     if @recipe != recipe
  226.       @recipe = recipe
  227.       @waiting = 40
  228.       @dy = 1
  229.       self.oy = 0
  230.       refresh
  231.     end
  232.   end
  233.   def refresh
  234.     if self.contents != nil
  235.       self.contents.dispose
  236.       self.contents = nil
  237.     end
  238.     if @recipe == nil
  239.       return
  240.     end
  241.     h = 32 * @recipe.ingredients.size
  242.     if h > 0
  243.       self.contents = Bitmap.new(width - 32, h)
  244.       @recipe.ingredients.each_with_index do |ingredient, index|
  245.         draw_item(ingredient, index)
  246.       end
  247.     end
  248.   end
  249.   def draw_item(ingredient, index)
  250.     x = 4
  251.     y = index * 32
  252.     case ingredient.kind
  253.     when 0
  254.       item = $data_items[ingredient.id]
  255.       num = $game_party.item_number(ingredient.id)
  256.     when 1
  257.       item = $data_weapons[ingredient.id]
  258.       num = $game_party.weapon_number(ingredient.id)
  259.     when 2
  260.       item = $data_armors[ingredient.id]
  261.       num = $game_party.armor_number(ingredient.id)
  262.     else
  263.       item = nil
  264.     end
  265.     if item == nil
  266.       return
  267.     end
  268.     bitmap = RPG::Cache.icon(item.icon_name)
  269.     disabled = num < ingredient.number
  270.     opacity = disabled ? 128 : 255
  271.     self.contents.blt(x, y+4, bitmap, Rect.new(0, 0, 24, 24), opacity)
  272.     self.contents.font.color = disabled ? disabled_color : normal_color
  273.     self.contents.draw_text(x + 28, y, 192, 32, item.name)
  274.     self.contents.draw_text(x + 220, y, 64, 32, num.to_s, 2)
  275.     self.contents.font.color = normal_color
  276.     self.contents.draw_text(x + 264, y, 64, 32, ingredient.number.to_s, 2)
  277.   end
  278.   def update
  279.     super
  280.     if self.contents != nil && self.contents.height > self.height - 32
  281.       if @waiting > 0
  282.         @waiting -= 1
  283.         return
  284.       end
  285.       self.oy += @dy
  286.       if self.oy + self.height - 32 >= self.contents.height
  287.         @dy = -1
  288.         @waiting = 60
  289.       end
  290.       if self.oy <= 0
  291.         @dy = 1
  292.         @waiting = 60
  293.       end
  294.     end
  295.   end
  296. end

  297. class Window_Craft_Number < Window_Base
  298.   def initialize
  299.     super(240, 64, 400, 160)
  300.     self.contents = Bitmap.new(width - 32, height - 32)
  301.     @recipe = nil
  302.     @max = 1
  303.     @number = 1
  304.     @number_current = 0
  305.   end
  306.   def recipe=(recipe)
  307.     if @recipe != recipe
  308.       @recipe = recipe
  309.       reset
  310.       refresh
  311.     end
  312.   end
  313.   def reset
  314.     if @recipe == nil
  315.       @number = 0
  316.       @number_current = 0
  317.       return
  318.     end
  319.     product = @recipe.product
  320.     case product.kind
  321.     when 0
  322.       @number_current = $game_party.item_number(product.id)
  323.     when 1
  324.       @number_current = $game_party.weapon_number(product.id)
  325.     when 2
  326.       @number_current = $game_party.armor_number(product.id)
  327.     else
  328.       @number_current = 0
  329.     end
  330.     @max = $game_party.product_max_num(@recipe.id)
  331.     @max = [@max, 99 - @number_current].min
  332.     @number = @max == 0 ? 0 : 1
  333.   end
  334.   def number
  335.     return @number
  336.   end
  337.   #--------------------------------------------------------------------------
  338.   # ● 刷新
  339.   #--------------------------------------------------------------------------
  340.   def refresh
  341.     self.contents.clear
  342.     self.contents.font.color = system_color
  343.     self.contents.draw_text(4, 0, 364, 32, "所持数")
  344.     self.contents.draw_text(4, 32, 364, 32, "最大可合成数")
  345.     self.contents.draw_text(4, 64, 364, 32, "当前合成数量")
  346.     self.contents.font.color = normal_color
  347.     self.contents.draw_text(4, 0, 364, 32, @number_current.to_s, 2)
  348.     self.contents.draw_text(4, 32, 364, 32, @max.to_s, 2)
  349.     self.contents.draw_text(252, 96, 32, 32, "×")
  350.     self.contents.draw_text(308, 96, 24, 32, @number.to_s, 2)
  351.   end
  352.   def update
  353.     super
  354.     if self.active
  355.       # 光标右 (+1)
  356.       if Input.repeat?(Input::RIGHT) and @number < @max
  357.         $game_system.se_play($data_system.cursor_se)
  358.         @number += 1
  359.         refresh
  360.       end
  361.       # 光标左 (-1)
  362.       if Input.repeat?(Input::LEFT) and @number > 1
  363.         $game_system.se_play($data_system.cursor_se)
  364.         @number -= 1
  365.         refresh
  366.       end
  367.       # 光标上 (+10)
  368.       if Input.repeat?(Input::UP) and @number < @max
  369.         $game_system.se_play($data_system.cursor_se)
  370.         @number = [@number + 10, @max].min
  371.         refresh
  372.       end
  373.       # 光标下 (-10)
  374.       if Input.repeat?(Input::DOWN) and @number > 1
  375.         $game_system.se_play($data_system.cursor_se)
  376.         @number = [@number - 10, 1].max
  377.         refresh
  378.       end
  379.     end
  380.   end
  381. end
  382. class Window_Craft_Label < Window_Base
  383.   def initialize
  384.     super(240, 224, 400, 64)
  385.     self.contents = Bitmap.new(width - 32, height - 32)
  386.     refresh
  387.   end
  388.   def refresh
  389.     self.contents.clear
  390.     self.contents.font.color = system_color
  391.     self.contents.draw_text(0, 0, width - 32, 32, "材料名称                                     现有   需要")
  392.   end
  393. end

  394. class Scene_Title
  395.   alias rb_main_20141226 main
  396.   def main
  397.     if $DEBUG
  398.       RPG.extract_recipe
  399.     end
  400.     $data_recipes = load_data("Data/Recipes.rxdata")
  401.     rb_main_20141226
  402.   end
  403. end

  404. class Scene_Craft
  405.   def initialize(mode = -1)
  406.     @mode = mode
  407.   end
  408.   def main
  409.     @product_window = Window_Product.new(@mode)
  410.     @help_window = Window_Help.new
  411.     @product_window.help_window = @help_window
  412.     @ingredient_window = Window_Ingredients.new
  413.     @number_window = Window_Craft_Number.new
  414.     @label_window = Window_Craft_Label.new
  415.     Graphics.transition
  416.     loop do
  417.       Graphics.update
  418.       Input.update
  419.       update
  420.       if $scene != self
  421.         break
  422.       end
  423.     end
  424.     Graphics.freeze
  425.     @product_window.dispose
  426.     @help_window.dispose
  427.     @ingredient_window.dispose
  428.     @number_window.dispose
  429.     @label_window.dispose
  430.   end
  431.   def update
  432.     @product_window.update
  433.     @ingredient_window.update
  434.     @ingredient_window.recipe = @product_window.recipe
  435.     @number_window.recipe = @product_window.recipe
  436.     if @product_window.active
  437.       update_product
  438.       return
  439.     end
  440.     if @number_window.active
  441.       update_number
  442.     end
  443.   end
  444.   def update_product
  445.     if Input.trigger?(Input::B)
  446.       $game_system.se_play($data_system.cancel_se)
  447.       $scene = Scene_Map.new
  448.       return
  449.     end
  450.     if Input.trigger?(Input::C)
  451.       recipe = @product_window.recipe
  452.       if recipe == nil || $game_party.product_max_num(recipe.id) == 0
  453.         $game_system.se_play($data_system.buzzer_se)
  454.         return
  455.       end
  456.       $game_system.se_play($data_system.decision_se)
  457.       @number_window.cursor_rect.set(304, 96, 32, 32)
  458.       @product_window.active = false
  459.       @number_window.active = true
  460.       return
  461.     end
  462.   end
  463.   def update_number
  464.     @number_window.update
  465.     if Input.trigger?(Input::B)
  466.       $game_system.se_play($data_system.cancel_se)
  467.       @number_window.active = false
  468.       @product_window.active = true
  469.       @number_window.cursor_rect.empty
  470.       return
  471.     end
  472.     if Input.trigger?(Input::C)
  473.       $game_system.se_play($data_system.shop_se)
  474.       recipe = @product_window.recipe
  475.       case recipe.product.kind
  476.       when 0
  477.         $game_party.gain_item(recipe.product.id, @number_window.number)
  478.       when 1
  479.         $game_party.gain_weapon(recipe.product.id, @number_window.number)
  480.       when 2
  481.         $game_party.gain_armor(recipe.product.id, @number_window.number)
  482.       end
  483.       recipe.ingredients.each do |ingredient|
  484.         case ingredient.kind
  485.         when 0
  486.           $game_party.lose_item(ingredient.id, ingredient.number * @number_window.number)
  487.         when 1
  488.           $game_party.lose_weapon(ingredient.id, ingredient.number * @number_window.number)
  489.         when 2
  490.           $game_party.lose_armor(ingredient.id, ingredient.number * @number_window.number)
  491.         end
  492.       end
  493.       @product_window.refresh
  494.       @ingredient_window.refresh
  495.       @number_window.reset
  496.       @number_window.refresh
  497.       @product_window.active = true
  498.       @number_window.active = false
  499.       @number_window.cursor_rect.empty
  500.       return
  501.     end
  502.   end
  503. end
复制代码
回复

使用道具 举报

Lv5.捕梦者

梦石
0
星屑
33163
在线时间
10488 小时
注册时间
2009-3-15
帖子
4756
10
发表于 2021-8-14 09:25:29 | 只看该作者
实际上你可以给Game_System加东西,很多脚本都是这么做的。

RUBY 代码复制
  1. class Game_System
  2.   attr_accessor :精灵
  3. def 精灵;return @精灵||=[];end
  4. end


只要不进行初始化就可以兼容旧存档...

评分

参与人数 1+1 收起 理由
939034448 + 1 谢谢大佬提供指导

查看全部评分

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-4-23 17:25

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表