Release 0.0.1.8.8.7

This commit is contained in:
WorldBosse committed 2026-10-29 21:59:06 +04:00
1 parent 3c8a17aa78
commit c7beab414c
16283 files changed
+768761 -2

No files matched your search

@@ -0,0 +1,181 @@
#==============================================================================
# LonaCraft - 60_Skill.rb
# What it does:
# * Crafting level 0..20 with exp. Stored as the plain Hash
# $game_system @lonacraft = {"level"=>n, "exp"=>n}: $game_system is in every
# save (5_DataManager.rb:931/956), so it needs no save hook, and a plain
# Hash still loads if the mod is removed. Saves made before this mod have
# no @lonacraft (Marshal.load skips initialize), so every access goes
# through Game_System#lonacraft_data, which fills it in.
# * Level n -> n+1 needs 20 x (n+1) exp. Level-up shows the popup
# "Crafting skill up" on the map (queued until the map is back if the
# level-up happened in another scene: map popups need its spriteset).
# * Effective skill = level + round(Lona's survival_trait / 2); 0 bonus for
# anyone who is not Lona's own actor (Cocona, NPC portrait channels).
# * Tier roll: rand(100) + 8 x effective - 4 x skill_req;
# >=170 Legendary, >=130 Epic, >=95 Rare, >=60 Uncommon, else Common.
# * With RolePlayS, every craft also gives 0.3 Survival attribute exp
# (RolePlayS\Scripts\05_Attr_Exp.rb:60 add_attribute_exp(attr, amount)).
#==============================================================================
class Game_System
def lonacraft_data
@lonacraft = {} unless @lonacraft.is_a?(Hash)
@lonacraft["level"] ||= 0
@lonacraft["exp"] ||= 0
@lonacraft
end
end
module LonaCraft
module Skill
MAX_LEVEL = 20
EXP_PER_LEVEL = 20 # level n -> n+1 costs EXP_PER_LEVEL * (n+1)
EXP_GEAR_BASE = 5 # gear craft: EXP_GEAR_BASE + skill_req
EXP_PROCESS = 1 # processing recipe (and ammo, 55_Recipes.rb)
ROLL_PER_SKILL = 8
ROLL_PER_REQ = 4
# [tier, minimum roll], best first
THRESHOLDS = [[5, 170], [4, 130], [3, 95], [2, 60]]
RPS_SUR_EXP = 0.3
POPUP_KEY = "LonaCraft:Tiers:Skill/level_up"
def self.data
return {"level" => 0, "exp" => 0} if $game_system.nil? || !$game_system.respond_to?(:lonacraft_data)
$game_system.lonacraft_data
end
def self.level
data["level"].to_i
end
def self.exp
data["exp"]
end
# exp needed to go from level +lv+ to lv+1 (0 at the cap)
def self.exp_to_next(lv = nil)
lv = level if lv.nil?
return 0 if lv >= MAX_LEVEL
EXP_PER_LEVEL * (lv + 1)
end
# Adds exp; returns the number of levels gained.
def self.gain(amount)
d = data
return 0 if amount.nil? || amount.to_f <= 0
return 0 if d["level"].to_i >= MAX_LEVEL
d["exp"] = d["exp"] + amount
ups = 0
# at most MAX_LEVEL level-ups, whatever is in the save
while ups < MAX_LEVEL && d["level"].to_i < MAX_LEVEL && d["exp"] >= exp_to_next(d["level"].to_i)
d["exp"] -= exp_to_next(d["level"].to_i)
d["level"] = d["level"].to_i + 1
ups += 1
end
d["exp"] = 0 if d["level"].to_i >= MAX_LEVEL
notify_level_up if ups > 0
ups
end
# Lona's own actor, or nil (Cocona / NPC channels / no player)
def self.lona
return nil if $game_player.nil?
actor = $game_player.actor
return nil if LonaCraft.vanilla_only_actor?(actor)
actor
rescue => e
nil
end
def self.survival_bonus
actor = lona
return 0 if actor.nil?
(actor.survival_trait.to_f / 2).round
rescue => e
p "LonaCraft Skill survival error #{e.message}"
0
end
def self.effective
level + survival_bonus
end
def self.roll_offset(skill_req)
ROLL_PER_SKILL * effective - ROLL_PER_REQ * skill_req.to_i
end
def self.tier_for_roll(roll)
THRESHOLDS.each{|tier, min| return tier if roll >= min }
1
end
def self.roll_tier(skill_req)
tier_for_roll(rand(100) + roll_offset(skill_req))
end
# [Common, Uncommon, Rare, Epic, Legendary] in whole percent (sum 100),
# exact for the uniform roll rand(100) + offset.
def self.tier_chances(skill_req)
offset = roll_offset(skill_req)
at_least = THRESHOLDS.map{|tier, min|
n = 100 - (min - offset) # rolls r in 0..99 with r + offset >= min
n = 0 if n < 0
n = 100 if n > 100
n
}
g5, g4, g3, g2 = at_least
[100 - g2, g2 - g3, g3 - g4, g4 - g5, g5]
end
# Called by Recipes.craft after a successful craft.
def self.on_craft(recipe)
cheap = recipe.category == :process || recipe.category == :ammo
amount = cheap ? EXP_PROCESS : EXP_GEAR_BASE + recipe.skill_req.to_i
gain(amount)
feed_roleplays
rescue => e
p "LonaCraft Skill on_craft error #{e.message}"
end
def self.feed_roleplays
return unless $imported && $imported[:RolePlayS]
actor = lona
return if actor.nil?
return unless actor.respond_to?(:add_attribute_exp)
actor.add_attribute_exp(:sur, RPS_SUR_EXP)
rescue => e
p "LonaCraft Skill RolePlayS exp error #{e.message}"
end
def self.pending_level_up?
@pending_popup ? true : false
end
def self.notify_level_up
@pending_popup = true
flush_popup
end
# Shows the queued level-up popup if the map scene is up.
def self.flush_popup
return unless @pending_popup
return unless SceneManager.scene_is?(Scene_Map)
return if $game_map.nil?
@pending_popup = false
SndLib.sys_Gain
$game_map.popup(0, POPUP_KEY, 0, 0)
rescue => e
p "LonaCraft Skill popup error #{e.message}"
end
end
end
class Scene_Map
unless method_defined?(:start_lonacraft_skill)
alias_method :start_lonacraft_skill, :start
def start
start_lonacraft_skill
LonaCraft::Skill.flush_popup
end
end
end