赞 | 1 |
VIP | 0 |
好人卡 | 0 |
积分 | 14 |
经验 | 0 |
最后登录 | 2025-7-16 |
在线时间 | 26 小时 |
Lv3.寻梦者
- 梦石
- 1
- 星屑
- 370
- 在线时间
- 26 小时
- 注册时间
- 2023-9-8
- 帖子
- 10
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
#==============================================================================
# ** 味觉系统
#------------------------------------------------------------------------------
# 根据角色对物品味道的偏好调整回复效果
# 在物品备注栏中使用以下标签:
# <味道: 甜> - 定义物品的味道属性
# <讨厌: 甜> - 角色讨厌的味道
# <喜欢: 甜> - 角色喜欢的味道
#==============================================================================
module TasteSystem
# 味道属性列表
TASTE_TAGS = ['甜', '酸', '苦', '辣', '咸', '鲜', '涩', '清淡', '油腻']
# 默认回复量调整系数
DISLIKE_MULTIPLIER = 0.5 # 讨厌的味道回复量减半
LIKE_MULTIPLIER = 2.0 # 喜欢的味道回复量翻倍
end
class RPG::BaseItem
# 获取物品的味道属性
def taste
return @taste unless @taste.nil?
@taste = []
self.note.split(/[\r\n]+/).each do |line|
if line =~ /<味道:\s*(.+?)>/i
$1.split(/[,,、\s]+/).each do |t|
@taste << t.strip if TasteSystem::TASTE_TAGS.include?(t.strip)
end
end
end
@taste
end
end
class RPG::Actor < RPG::BaseItem
# 获取角色讨厌的味道
def disliked_tastes
return @disliked_tastes unless @disliked_tastes.nil?
@disliked_tastes = []
self.note.split(/[\r\n]+/).each do |line|
if line =~ /<讨厌:\s*(.+?)>/i
$1.split(/[,,、\s]+/).each do |t|
@disliked_tastes << t.strip if TasteSystem::TASTE_TAGS.include?(t.strip)
end
end
end
@disliked_tastes
end
# 获取角色喜欢的味道
def liked_tastes
return @liked_tastes unless @liked_tastes.nil?
@liked_tastes = []
self.note.split(/[\r\n]+/).each do |line|
if line =~ /<喜欢:\s*(.+?)>/i
$1.split(/[,,、\s]+/).each do |t|
@liked_tastes << t.strip if TasteSystem::TASTE_TAGS.include?(t.strip)
end
end
end
@liked_tastes
end
end
class Game_Battler < Game_BattlerBase
# 应用物品效果(重写以加入味觉系统)
alias taste_item_apply item_apply
def item_apply(user, item)
# 如果是回复品且使用者是角色之一
if item.is_a?(RPG::Item) && user.is_a?(Game_Actor) && item_has_any_positive_effect?(item)
multiplier = taste_multiplier(user, item)
if multiplier != 1.0
# 临时修改效果值
modified_effects = []
item.effects.each do |effect|
new_effect = effect.dup
if effect.code == 11 # HP恢复
new_effect.value1 = (effect.value1 * multiplier).to_i
new_effect.value2 = (effect.value2 * multiplier).to_i
elsif effect.code == 12 # MP恢复
new_effect.value1 = (effect.value1 * multiplier).to_i
new_effect.value2 = (effect.value2 * multiplier).to_i
end
modified_effects << new_effect
end
# 应用修改后的效果
original_effects = item.effects
item.effects = modified_effects
taste_item_apply(user, item)
item.effects = original_effects
return
end
end
# 无味觉影响或不是回复品时正常应用
taste_item_apply(user, item)
end
# 检查物品是否有任何正面效果
def item_has_any_positive_effect?(item)
item.effects.any? do |effect|
(effect.code == 11 && (effect.value1 > 0 || effect.value2 > 0)) || # HP恢复
(effect.code == 12 && (effect.value1 > 0 || effect.value2 > 0)) || # MP恢复
(effect.code == 21 && effect.value1 > 0) # 参数提升
end
end
# 计算味觉调整系数
def taste_multiplier(user, item)
actor = $data_actors[user.id]
item_tastes = item.taste
return 1.0 if item_tastes.empty?
# 检查是否有讨厌的味道
actor.disliked_tastes.each do |taste|
return TasteSystem::DISLIKE_MULTIPLIER if item_tastes.include?(taste)
end
# 检查是否有喜欢的味道
actor.liked_tastes.each do |taste|
return TasteSystem::LIKE_MULTIPLIER if item_tastes.include?(taste)
end
# 无特别偏好
1.0
end
end
|
#==============================================================================
# ** 香料系统(口味脚本附属包)
#------------------------------------------------------------------------------
# 修复了方法未定义的错误,并优化了香料选择逻辑
# 如果背包里有香料,角色使用物品时会自动撒上去,在物品备注写上<禁用香料>,角色使用此物品将不使用香料
#==============================================================================
module SpiceSystem
SPICE_ICON = 123
MIXED_TASTE_MULTIPLIER = 1.25
end
class RPG::Item < RPG::UsableItem
def spice?
return @is_spice unless @is_spice.nil?
@is_spice = note.include?("<香料:")
end
def no_spice?
return @no_spice unless @no_spice.nil?
@no_spice = note.include?("<禁用香料>")
end
def spice_taste
return @spice_taste unless @spice_taste.nil?
@spice_taste = []
if spice?
note.split(/[\r\n]+/).each do |line|
if line =~ /<香料:\s*(.+?)>/i
$1.split(/[,,、\s]+/).each do |t|
t = t.strip
@spice_taste << t if TasteSystem::TASTE_TAGS.include?(t)
end
end
end
end
@spice_taste
end
end
class Game_Party < Game_Unit
def spices
items.select { |item| item.is_a?(RPG::Item) && item.spice? }
end
def spices_with_taste(taste)
spices.select { |item| item.spice_taste.include?(taste) }
end
end
class Game_Battler < Game_BattlerBase
# 新增方法:为使用者寻找最佳香料
def find_best_spice_for_user(user, item)
return nil unless user.is_a?(Game_Actor)
actor = $data_actors[user.id]
available_spices = $game_party.spices
# 排除角色讨厌的香料
available_spices.reject! do |spice|
spice.spice_taste.any? { |taste| actor.disliked_tastes.include?(taste) }
end
return nil if available_spices.empty?
# 优先选择角色喜欢的香料
liked_spice = available_spices.find do |spice|
spice.spice_taste.any? { |taste| actor.liked_tastes.include?(taste) }
end
liked_spice || available_spices.first
end
# 新增方法:计算混合味道系数
def calculate_mixed_taste_multiplier(user, original_tastes, spice_tastes)
actor = $data_actors[user.id]
# 如果香料的味道和物品的味道完全一致
if (original_tastes & spice_tastes).any?
# 创建一个临时物品来计算原味觉系数
temp_item = RPG::Item.new
temp_item.effects = []
temp_item.note = original_tastes.map { |t| "<味道: #{t}>" }.join("\n")
return taste_multiplier(user, temp_item)
end
SpiceSystem::MIXED_TASTE_MULTIPLIER
end
# 重写物品应用方法
alias spice_item_apply item_apply
def item_apply(user, item)
if item.is_a?(RPG::Item) && user.is_a?(Game_Actor) &&
item_has_any_positive_effect?(item) && !item.no_spice?
best_spice = find_best_spice_for_user(user, item)
if best_spice
original_taste = item.taste
spice_taste = best_spice.spice_taste
multiplier = calculate_mixed_taste_multiplier(user, original_taste, spice_taste)
if multiplier != 1.0
modified_effects = item.effects.map do |effect|
new_effect = effect.dup
if [11, 12].include?(effect.code) # HP/MP恢复
new_effect.value1 = (effect.value1 * multiplier).to_i
new_effect.value2 = (effect.value2 * multiplier).to_i
end
new_effect
end
original_effects = item.effects
item.effects = modified_effects
spice_item_apply(user, item)
item.effects = original_effects
$game_party.lose_item(best_spice, 1)
$game_message.add("#{user.name}使用了#{best_spice.name}调味!")
return
end
end
end
spice_item_apply(user, item)
end
end
|
|
 组图打开中,请稍候......
|