赞 | 11 |
VIP | 0 |
好人卡 | 0 |
积分 | 7 |
经验 | 0 |
最后登录 | 2023-7-13 |
在线时间 | 42 小时 |
Lv2.观梦者
- 梦石
- 0
- 星屑
- 735
- 在线时间
- 42 小时
- 注册时间
- 2019-11-26
- 帖子
- 28
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
比较原始哈,是我做着玩的一个小游戏的脚本。
初来乍到,算是给大家的一点见面礼~
- #-----------------------------------------------------
- #Author: xsrong
- #
- #支持在信息中添加怪物的简介。在数据库敌人标签卡中对应的怪物的备注中以
- #<ENEMY_INFO 简介内容>#标注敌人的简介文字
- #例:<ENEMY_INFO 史莱姆性情温顺,通常不会主动攻击人类。>
- #
- #支持显示自定义属性值。
- #在数据库敌人标签卡中对应的怪物的备注中将需要显示的自定义属性以
- #<属性名 属性值>的形式记录。然后搜索ADD_STATUS,向里面增加需要显示的属性的中
- #文名称。搜索ADD_PARAMS,向里面增加怪物备注中记录的属性名
- #例子可以参考代码中的“测试属性值”
- #
- #本脚本增加了$game_defeate_enemies全局变量
- #$game_defeate_enemies是初始值为0的整数型数组,数组下标为敌人的id,值为击败该敌人的数量
- #如$game_defeate_enemies[1]即为击败id为1的敌人的数量
- #-----------------------------------------------------
- # 向菜单栏中增加【怪物手册】的选项
- class Window_MenuCommand
- ENEMY_MANUAL = "怪物手册"
- alias xsrong_add_original_commands add_original_commands
- def add_original_commands
- xsrong_add_original_commands
- add_command(ENEMY_MANUAL, :enemy_manual)
- end
- end
- # 增加选择【怪物手册】后的动作
- class Scene_Menu
- alias xsrong_create_command_window create_command_window
- def create_command_window
- xsrong_create_command_window
- @command_window.set_handler(:enemy_manual, method(:command_enemy_manual))
- end
-
- #切换到【怪物手册】的场景
- def command_enemy_manual
- SceneManager.call(Scene_Enemy_Manual)
- end
- end
- # 定义【怪物手册】的场景
- class Scene_Enemy_Manual < Scene_MenuBase
- def start
- super
- # 增加怪物清单的选择窗口
- @enemy_manual_list_window = Window_Enemy_Manual_List.new
- @enemy_manual_list_window.set_handler(:enemy_status, method(:on_enemy_status))
- @enemy_manual_list_window.set_handler(:cancel, method(:return_scene))
-
- # 增加显示怪物信息的窗口
- @enemy_manual_status_window = Window_Enemy_Manual_Status.new
-
- # 将增加的两个窗口之间关联起来
- @enemy_manual_list_window.help_window = @enemy_manual_status_window
- @enemy_manual_status_window.main_window = @enemy_manual_list_window
- end
-
- # 怪物图册中按下确定,激活显示怪物信息的窗口
- def on_enemy_status
- @enemy_manual_list_window.deactivate
- @enemy_manual_status_window.activate
- end
- end
- # 定义显示怪物信息的窗口
- class Window_Enemy_Manual_Status < Window_Base
- attr_accessor :main_window
- # 以下两个常量用来表示怪物的自定义属性,使用方法见初始注释
- ADD_STATUS = ["测试属性值:"]
- ADD_PARAMS= ["TEST"]
-
- # 窗口的初始化
- # @offset_y 表示窗口内容的y坐标的修正值,用以实现通过上下方向键滚动窗口内容。
- # @info_arr 保存怪物简介文字的数组,用来实现内容换行
- def initialize
- super(Graphics.width / 3, 0, Graphics.width / 3 * 2, Graphics.height)
- @offset_y = 0
- @info_arr = []
- @status_name = ["体力上限:", "魔力上限:", "物理攻击:", "物理防御:", "魔法攻击:", "魔法防御:", "敏捷值:", "幸运值:"]
- @status_name += ADD_STATUS
- # @status_name = ["击倒次数:"] + @status_name # 取消注释后可在怪物手册中显示击倒该怪物的数量
- deactivate
- end
-
- # 向该窗口中写入查看的怪物的具体信息
- def set_enemy_status(enemy)
- if @enemy != enemy
- @enemy = enemy
- refresh
- end
- end
-
- # 清空窗口中现有的内容
- def clear
- set_enemy_status(nil)
- end
-
- # 向窗口中写入怪物手册的总览内容
- def draw_totle_info
- defeated_enemies = []
- defeated_enemies_count = 0
- $game_defeated_enemies.each do |e|
- defeated_enemies << e if e != 0
- defeated_enemies_count += e
- end
- draw_text_ex(0, line_height * 0, "击倒达成率:" + (defeated_enemies.length.to_f / ($data_enemies.length - 1).to_f * 100).round(2).to_s + "%")
- draw_text_ex(0, line_height * 1, "击倒怪物种类数:" + defeated_enemies.length.to_s + "/" + ($data_enemies.length - 1).to_s)
- draw_text_ex(0, line_height * 2, "击倒怪物数量:" + defeated_enemies_count.to_s)
- end
-
- # 绘制怪物简介的文字
- def draw_enemy_info
- if @enemy
- @info_arr = []
- info = /<ENEMY_INFO\s*(.+)>/ =~ @enemy.note ? $1 : ""
- while info != ""
- @info_arr << info[0..13]
- info[0..13] = ""
- end
- for i in 0..@info_arr.length - 1
- draw_text_ex(0, (i + 3 + @status_name.length) * line_height - @offset_y, @info_arr[i])
- end
- end
- end
-
- # 绘制怪物的名字
- def draw_enemy_name
- draw_text_ex(0, -@offset_y, @enemy.name) if @enemy
- end
-
- # 绘制怪物的各项属性
- def draw_enemy_params
- if @enemy
- add_params = []
- ADD_PARAMS.each do |param|
- param = "<" + param + "\\s*(.+)>"
- p = Regexp.new(param) =~ @enemy.note ? $1 : ""
- add_params << p
- end
- params = @enemy.params
- params += add_params
- params_max_text_length = 0
- @status_name.each do |sn|
- params_max_text_length = sn.length if sn.length > params_max_text_length
- end
- # params = [$game_defeated_enemies[@enemy.id]] + params # 取消注释后可在怪物手册中显示击倒该怪物的数量
- for i in 0..params.length - 1
- draw_text_ex(0, (i + 2) * line_height - @offset_y, @status_name[i])
- draw_text_ex(params_max_text_length * 23, (i + 2) * line_height - @offset_y, params[i])
- end
- end
- end
-
- # 实际绘制窗口的内容
- def draw_enemy_status
- if @enemy
- if $game_defeated_enemies[@enemy.id] != 0 # 曾击败过该敌人则显示敌人的具体信息
- draw_enemy_name
- draw_enemy_params
- draw_enemy_info
- else
- draw_text_ex(0, 0, "??????") # 未曾击败过该敌人则以??????代替敌人的具体信息
- end
- end
- end
-
- # 增加该窗口的按键方法
- def update
- super
- if Input.trigger?(:B)
- @offset_y = 0
- deactivate
- @main_window.activate
- end
-
- if Input.repeat?(:DOWN) && self.active
- scroll_down
- refresh
- end
-
- if Input.repeat?(:UP) && self.active
- scroll_up
- refresh
- end
-
- end
-
- def scroll_down
- @offset_y += line_height if @offset_y < (@info_arr.length + @status_name.length - 13) * line_height
- end
-
- def scroll_up
- @offset_y -= line_height if @offset_y > 0
- end
-
- def refresh
- contents.clear
- draw_enemy_status
- end
- end
- # 定义显示敌人清单的窗口
- class Window_Enemy_Manual_List < Window_Command
- def initialize
- super(0, 0)
- end
-
- def window_width
- return Graphics.width / 3
- end
-
- def window_height
- return Graphics.height
- end
-
- # 增加敌人清单窗口中的各个敌人选项
- def make_command_list
- add_command("手册总览", :all, true)
- $data_enemies.each do |enemy|
- if enemy
- if $game_defeated_enemies[enemy.id] == 0 # 从未击败过该敌人时
- add_command("???", :enemy_status, false) # 敌人的名字以???代替
- else
- add_command(enemy.name, :enemy_status, true) # 如击败过该敌人则显示敌人的真实名字
- end
- end
- end
- end
-
- # 更新显示敌人信息窗口中的内容
- def update_help
- super
- if index > 0
- enemy = $data_enemies[index]
- @help_window.set_enemy_status(enemy)
- else
- @help_window.draw_totle_info
- end
- end
- end
- # 为Gmae_Troop类增加了统计在战斗中打败的怪物的方法,并在战斗胜利后调用该方法
- class Game_Troop
- def defeated_members
- dead_members.inject([]) {|r, enemy| r += [enemy.enemy_id]}
- end
- end
- module BattleManager
- # 修改全局变量$game_defeated_enemies,将战斗中击倒过的怪物对应的数量+1
- def self.gain_defeated_enemies
- $game_troop.defeated_members.each do |enemy_id|
- $game_defeated_enemies[enemy_id] += 1
- end
- end
-
- # 修改战斗胜利后的处理,增加调用gain_defeated_enemies,实现战斗胜利后增加击倒过的怪物数量
- BattleManager.singleton_class.send(:alias_method, :xsrong_process_victory, :process_victory)
- def self.process_victory
- gain_defeated_enemies
- xsrong_process_victory
- end
- end
- module DataManager
- # 开始新游戏时增加$game_defeated_enemies变量
- DataManager.singleton_class.send(:alias_method, :xsrong_create_game_objects, :create_game_objects)
- def self.create_game_objects
- xsrong_create_game_objects
- $game_defeated_enemies = Array.new($data_enemies.length){0}
- end
-
- # 存档时保存$game_defeated_enemies变量
- DataManager.singleton_class.send(:alias_method, :xsrong_make_save_contents, :make_save_contents)
- def self.make_save_contents
- contents = xsrong_make_save_contents
- contents[:defeated_enemies] = $game_defeated_enemies
- contents
- end
-
- # 读档时读取$game_defeated_enemies变量
- DataManager.singleton_class.send(:alias_method, :xsrong_extract_save_contents, :extract_save_contents)
- def self.extract_save_contents(contents)
- xsrong_extract_save_contents(contents)
- $game_defeated_enemies = contents[:defeated_enemies]
- end
- end
复制代码 |
评分
-
查看全部评分
|