查看: 3375|回复: 4

[原创发布] 【同样轮子联欢】脚本-根据状态改变脸图

[复制链接]
梦石
2
星屑
6767
在线时间
501 小时
注册时间
2018-3-23
回帖
487

R考场第七期银奖

发表于 2020-5-25 21:45:40 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
本帖最后由 MCCF 于 2020-6-4 22:06 编辑

这个脚本的功能?字面意思(狗头
此脚本使用无需署名(但是最好还是署名啦……
[fold=脚本][pre lang="ruby"]#==============================================================================
# 根据状态更改脸图 V2.0
#  By MCCF
#==============================================================================
#  - [简要概述]本脚本允许根据状态改变角色的脸图。脸图的优先级取决于状态的优先级。
#------------------------------------------------------------------------------
#  - [使用规约]可在当地法律允许范围内自由使用。但是希望您能署名MCCF。
#==============================================================================
#  - [使用说明]
#------------------------------------------------------------------------------
#  - 在状态-备注中写入<state_face = id>则该状态附着后会修改角色的脸图为ID号。
#  - 不同角色的第ID号脸图有所不同。这需要在配置模块中设置。ID为0则恢复正常脸图。
#------------------------------------------------------------------------------
#  - 2.0版本可以设置多种脸图叠加时,替换成新的第三种脸图等。
#  - 注意多种脸图的优先级高于单个脸图的优先级。可以把单个脸图伪装成多种脸图来解决。
#==============================================================================
#  - [兼容性]
#------------------------------------------------------------------------------
#  - 本脚本可以兼容大部分修改状态方面的脚本,但改动过大的脚本可能不会兼容。
#==============================================================================
#  通用配置模块  
#==============================================================================
module StateFace_Config
  
  # 指定不同角色的所有脸图
  ACTOR_FACES = {
    # 数据库中1号角色
    1 => {
      # 1号脸图为"Actor4"的第一行第一个
      1 => ["Actor4",0],
      # 2号脸图为"Evil"的第二行第三个
      2 => ["Evil",6],
      # 1, 2号脸图相结合时,脸图为"Evil"的第二行第四个
      [1, 2] => ["Evil",7]
    },
    # 数据库中2号角色
    2 => {
      # 2号脸图为"Evil"的第一行第四个
      2 => ["Evil",3],
    },
  } # 可在本行之前按照格式继续添加
  
end
#==============================================================================
#  配置模块结束  
#==============================================================================

#==============================================================================
# ■ RPG::State
#------------------------------------------------------------------------------
#   状态的数据类。
#==============================================================================
class RPG::State < RPG::BaseItem
  #--------------------------------------------------------------------------
  # ● 获取脸图ID
  #--------------------------------------------------------------------------
  def face_id
    return /<state_face\s*=\s*(\d+)>/i =~ @note ? $1.to_i : nil
  end
end

#==============================================================================
# ■ Game_Actor
#------------------------------------------------------------------------------
#  管理角色的类。
#==============================================================================
class Game_Actor < Game_Battler
  #--------------------------------------------------------------------------
  # ● 设置
  #--------------------------------------------------------------------------
  alias state_face_setup setup
  def setup(actor_id)
    @actor_id = actor_id
    @normal_face_name = actor.face_name
    @normal_face_index = actor.face_index
    state_face_setup(actor_id)
    update_face_states
  end
  #--------------------------------------------------------------------------
  # ● 附加状态
  #--------------------------------------------------------------------------
  alias state_face_add_new_state add_new_state
  def add_new_state(state_id)
    state_face_add_new_state(state_id)
    update_face_states
  end
  #--------------------------------------------------------------------------
  # ● 消除状态
  #--------------------------------------------------------------------------
  alias state_face_erase_state erase_state
  def erase_state(state_id)
    state_face_erase_state(state_id)
    if sort_face_states.empty?
      @face_name = @normal_face_name
      @face_index = @normal_face_index
    else
      update_face_states
    end
  end
  #--------------------------------------------------------------------------
  # ● 清除状态信息
  #--------------------------------------------------------------------------
  alias state_face_clear_states clear_states
  def clear_states
    state_face_clear_states
    @face_name = @normal_face_name
    @face_index = @normal_face_index
  end
  #--------------------------------------------------------------------------
  # ● 更改图像
  #--------------------------------------------------------------------------
  alias state_face_set_graphic set_graphic
  def set_graphic(character_name, character_index, face_name, face_index)
    @normal_face_name = face_name
    @normal_face_index = face_index
    fname = sort_face_states.empty? ? face_name : @face_name
    findex = sort_face_states.empty? ? face_index : @face_index
    state_face_set_graphic(character_name, character_index, fname, findex)
  end
  #--------------------------------------------------------------------------
  # ● 排序当前脸图状态
  #--------------------------------------------------------------------------
  def sort_face_states
    face_states = self.states.select { |state| state.face_id }
    face_states = face_states.sort_by { |state| [0 - state.priority, id] }
    face_states.collect {|state| state.id }
  end
  #--------------------------------------------------------------------------
  # ● 更新状态脸图
  #--------------------------------------------------------------------------
  def update_face_states
    unless sort_face_states.empty?
      face_states = sort_face_states
      if setting = StateFace_Config::ACTOR_FACES[@actor_id]
        if $data_states[face_states[0]].face_id == 0
          @face_name = @normal_face_name
          @face_index = @normal_face_index
          return
        end
        face_ids = []
        face_states.each do |id|
          unless face_ids.include?($data_states[id].face_id)
            face_ids.push($data_states[id].face_id)
          end
        end
        result = setting.select do |key|
          key.is_a?(Array) && key.all? {|id| face_ids.include?(id) }
        end
        result = result.max_by do |key, value|
          key.collect {|id| face_ids.index(id) || -1 }
        end
        if result
          result = result[1]
        else
          result = setting[$data_states[face_states[0]].face_id]
          return unless result
        end
        @face_name = result[0]
        @face_index = result[1]
      end
    end
  end
end[/pre][/fold][fold=范例工程] 根据状态改变脸图.zip (1.43 MB, 下载次数: 79, 售价: 1 星屑) [/fold]
祝好。
梦石
2
星屑
6767
在线时间
501 小时
注册时间
2018-3-23
回帖
487

R考场第七期银奖

 楼主| 发表于 2020-6-4 22:06:08 | 显示全部楼层
果然不更新就不会有人来看233333
更新到了V2.0版本。
增加了多个状态结合产生新的脸图的效果。例如重伤状态+悲伤状态=重伤+悲伤的新脸图,且这个新脸图与单独重伤和单独悲伤的脸图可以不同。
修改了一堆BUG。增强了兼容性和码风优雅性。
祝好。
回复

使用道具 举报

梦石
0
星屑
317
在线时间
64 小时
注册时间
2022-5-6
回帖
9
发表于 2023-5-18 20:31:24 | 显示全部楼层
厉害????!
回复

使用道具 举报

梦石
0
星屑
95
在线时间
94 小时
注册时间
2021-4-23
回帖
37
发表于 2023-8-3 07:29:20 | 显示全部楼层
代码制度责任,( _ _)ノ|民主文明和谐,自由平等公正法友善制,爱国经验和晨曦
回复

使用道具 举报

梦石
0
星屑
3319
在线时间
191 小时
注册时间
2023-7-1
回帖
11
发表于 2023-8-7 19:29:42 | 显示全部楼层
附件没法下载,应该没有关系吧
回复

使用道具 举报

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

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部