Project1

标题: 怎把这天气系统RPGXP加效果功能?下雨时地上会湿 [打印本页]

作者: tzt198724    时间: 昨天 12:24
标题: 怎把这天气系统RPGXP加效果功能?下雨时地上会湿
# 自动天气系统
# 用法: 直接插入脚本编辑器,通过开关控制(默认开关15)
module AutoWeather
  # 配置
  SWITCH_ID = 15       # 控制开关ID
  MIN_DURATION = 300   # 最小持续时间(帧)
  MAX_DURATION = 600   # 最大持续时间(帧)
  WEATHER_CHANCES = [  # 天气概率(总和100)
    50,  # 晴天
    20,  # 雨天
    15,  # 雪天
    15   # 雾天
  ]
  
  # 初始化
  def self.init
    @active = false
    @timer = 0
    @current_weather = 0
    @duration = 0
  end
  
  # 更新天气
  def self.update
    return unless $game_switches[SWITCH_ID]
   
    if @timer <= 0
      set_new_weather
    else
      @timer -= 1
    end
  end
  
  # 设置新天气
  def self.set_new_weather
    # 修正随机持续时间写法,适配RPGXP的Ruby版本
    @duration = MIN_DURATION + rand(MAX_DURATION - MIN_DURATION + 1)
    @timer = @duration
   
    # 随机天气类型
    rand_val = rand(100)
    total = 0
    new_weather = 0
   
    WEATHER_CHANCES.each_with_index do |chance, i|
      total += chance
      if rand_val < total
        new_weather = i
        break
      end
    end
   
    # 应用天气
    if new_weather != @current_weather
      @current_weather = new_weather
      case new_weather
      when 0 then $game_screen.weather(0, 0, 0)  # 晴天
      when 1 then $game_screen.weather(1, 8, 15) # 雨天
      when 2 then $game_screen.weather(2, 8, 15) # 雪天
      when 3 then $game_screen.weather(3, 6, 20) # 雾天
      end
    end
  end
end

# 初始化
AutoWeather.init

# 集成到主循环
class Scene_Map
  alias auto_weather_update update
  def update
    auto_weather_update
    AutoWeather.update
  end
end
怎把这天气系统RPGXP加效果功能?下雨时地上会湿,下雪地上一层雪,不同的天气会有不同环境和地理效果




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1