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,503 @@
#==============================================================================
# LonaCraft - 45_Nodes.rb
# What it does (spec: docs/SPEC_NODES_AXE.md):
# * Boulders: Rough Stone nodes on wilderness maps.
# - At database load an EventLib event "LonaCraftBoulder" is cloned from
# the game's StaticSaltpeter (Map001 EV807): same init (overlap guard,
# @nap_initialize=3), HP 9, an upright opaque rock graphic, and its
# action runs HCGframes/Mining_Boulder.rb (lonacraft_mine_boulder).
# Graphic: Graphics/Characters/LonaCraft_Boulder.png of this mod if the
# file exists (one PNG = one cell, @manual_cw = @manual_ch = 1 as in
# 90_Furniture.rb), else the game's "$_boulder" sheet.
# - Spawned on every fresh visit of a region map (the game re-rolls its
# own nodes the same way): Game_Interpreter#enter_static_region_map
# (34_Functions_ChangeMap.rb:104, called once by every r-map BIOS while
# $story_stats["ReRollHalfEvents"] is still 1) is overridden; boulders
# are summoned first, then the game's method runs (it resets the flag).
# BOULDER_MAPS: family number of the map name "r<N>_..." => max count,
# in-map region id, tile rule. Count: 1 always, boulder k (k >= 2) if
# 1 + WIS + 2*SUR >= rand(25*(k-1)) (the game's phosphorus roll, r7 BIOS).
# - Mining: a pickaxe (ItemMhPickAxe) held in the MAIN HAND is REQUIRED
# (TOOLS_IN_HAND; carried in the bag is not enough since 2026-10-07);
# without one the swing only shows a line. STA per swing as the game's
# ore nodes (Mining_Saltpeter.rb:11-12): 1 equipped, 2 carried (only
# reachable with TOOLS_IN_HAND = false); with RolePlayS its
# calc_harvest_sta_cost(1, <the pickaxe in hand>) (same numbers plus
# attribute exp). Every 3rd hit 1 Rough Stone (+1 on the last),
# 15% Iron Ore per yield; the boulder is deleted when spent (game rule,
# Mining_Saltpeter.rb:17). Rough Stone and Iron Ore are not in
# 40_Mining.rb MINING_ORES, so no by-product roll on top.
# * Loose stones: on the same fresh visit, 1-3 small stones are scattered on
# the boulder families' maps and on the plains roads (r11), LOOSE_MAPS.
# A loose stone is a static node like the boulder (not a ground drop,
# which the game clears after a while): "LonaCraftLooseStone" is cloned
# from the same StaticSaltpeter library event, with a stone picture (the
# game's ItemRock drop cell, item_icon01 index 5 / dir 2 / pattern 1,
# Map001 EV93, or the mod's Graphics/Characters/LonaCraft_LooseStone.png,
# one cell, when it exists). Its action runs HCGframes/Mining_LooseStone.rb
# (lonacraft_pick_loose_stone): the game's pickup (common_pickup_item:
# pick-up pose, sound, "+1" popup) gives 1 Rough Stone at once, no tool,
# no stamina, no hit count; then the stone is deleted. It stays while the
# map is loaded (@nap_initialize=3, as the ore nodes).
# Same tile filter as the boulders (:open), but allowed up to 3 tiles
# from the start point.
# * Axe for wood: CommonTree.rb and CommonTreeNoble.rb are redirected
# through $mod_load_script (102_ScriptImport.rb:63) to HCGframes/<same
# name> of this mod, exactly as 100_Homes.rb's sellers: the wrapper calls
# lonacraft_tree_chop, which needs an axe (AXES: the mod's Hatchet, a
# main-hand weapon since 2026-10-07, or RolePlayS's axes) held in the MAIN
# HAND (TOOLS_IN_HAND), and then runs the script that was in place
# before LonaCraft (RolePlayS redirects both to its own copies,
# RolePlayS 0_CORE.rb:1707-1717; that copy is kept and run unchanged). Fruit trees are not touched.
# Nothing here is saved: boulders and loose stones live and die with the map visit.
#==============================================================================
module LonaCraft
module Nodes
BOULDERS_ENABLED = true
PICKAXE_REQUIRED = true
AXE_REQUIRED = true
# true (owner 2026-10-07): boulders need the pickaxe and trees the axe
# held in the main hand; false: carried in the bag is enough (the
# rule before 2026-10-07). A quality-tier copy (50_Tiers.rb) of a
# listed tool counts as that tool.
TOOLS_IN_HAND = true
BOULDER_EVENT = "LonaCraftBoulder"
BOULDER_TEMPLATE = "StaticSaltpeter"
BOULDER_SCRIPT = "HCGframes/Mining_Boulder.rb"
BOULDER_HP = 9 # hits per boulder
HITS_PER_YIELD = 3
STONE_ITEM = "ItemLonaCraftRoughStone"
LAST_YIELD_BONUS = 1 # extra Rough Stone on the last yield (4 per boulder)
IRON_ITEM = "ItemLonaCraftIronOre"
IRON_PCT = 15 # per yield
PLACEHOLDER_SPRITE = "$_boulder" # game Graphics/Characters, 3x4 cells of 32x32
CUSTOM_SPRITE = "LonaCraft_Boulder" # <mod>/Graphics/Characters/<name>.png, one cell
START_CLEAR = 6 # no boulder within this many tiles of -point-StartPoint
# Loose stones (static one-pick nodes, no tool)
LOOSE_ENABLED = true
LOOSE_EVENT = "LonaCraftLooseStone"
LOOSE_SCRIPT = "HCGframes/Mining_LooseStone.rb"
LOOSE_SHEET = "item_icon01" # the game's ItemRock drop picture (Map001 EV93)
LOOSE_INDEX = 5
LOOSE_DIR = 2
LOOSE_PATTERN = 1
LOOSE_CUSTOM = "LonaCraft_LooseStone" # <mod>/Graphics/Characters/<name>.png, one 32 x 32 cell
LOOSE_MIN = 1
LOOSE_MAX = 3
LOOSE_START_CLEAR = 3 # not within 2 tiles of -point-StartPoint
# family number => in-map region id (tile rule :open, as the boulders)
LOOSE_MAPS = {
1 => 11, # r1 PlainField
3 => 9, # r3 BadlandMountain
5 => 9, # r5 PineFroest
6 => 9, # r6 BadlandForest
7 => 4, # r7 PineFroestMountain: the walkable path (boulders sit on the rock faces, region 39)
11 => 11, # r11 RoadPlain (+ RolePlayS r11_RoadPlain4)
14 => 9, # r14 AbomDesert
16 => 9, # r16 PlainBadland
19 => 9, # r19 OrkDesert
28 => 9 # r28 OrkBadland
}
# family number (map name "r<N>_...") => [max boulders, in-map region id, rule]
# :open - the tile and its 4 neighbours passable, nothing within 1 tile
# :face - an impassable rock face with a passable 4-neighbour (r7, where
# the game puts its phosphorus, region 39)
BOULDER_MAPS = {
1 => [2, 11, :open], # r1 PlainField (+ RolePlayS r1_PlainField4)
3 => [4, 9, :open], # r3 BadlandMountain
5 => [2, 9, :open], # r5 PineFroest
6 => [3, 9, :open], # r6 BadlandForest
7 => [4, 39, :face], # r7 PineFroestMountain
14 => [2, 9, :open], # r14 AbomDesert
16 => [3, 9, :open], # r16 PlainBadland
19 => [2, 9, :open], # r19 OrkDesert
28 => [3, 9, :open] # r28 OrkBadland
}
PICKAXES = ["ItemMhPickAxe"] # the game's weapon id 11 (RolePlayS updates the same item)
AXES = ["ItemLonaCraftHatchet", "ItemMhLumbAx", "ItemMhPoleaxe"] # missing ones are skipped
TREE_SCRIPTS = [
"Data/HCGframes/event/CommonTree.rb",
"Data/HCGframes/event/CommonTreeNoble.rb"
]
TEXT = "LonaCraft:Nodes:"
@previous = {}
def self.text_key(id)
"#{TEXT}#{id}"
end
#----------------------------------------------------------------------
# Tools
#----------------------------------------------------------------------
def self.tool_items(names)
names.map{|name| $data_ItemName[name] }.compact
end
# carried or equipped
def self.has_any?(names)
return false if $game_party.nil?
tool_items(names).any?{|item| $game_party.has_item?(item, true) }
end
def self.main_hand?(names)
!held_tool(names).nil?
end
# The main-hand item if it is one of +names+ or a quality-tier copy
# of one ("<name>_LC<tier>", 50_Tiers.rb), else nil
def self.held_tool(names)
return nil if $game_player.nil? || $game_player.actor.nil?
eq = $game_player.actor.equips[0]
return nil if eq.nil?
return eq if tool_items(names).any?{|item| item.class == eq.class && item.id == eq.id }
return nil unless eq.is_a?(RPG::Weapon) && defined?(LonaCraft::Tiers)
name = eq.item_name.to_s
return nil unless LonaCraft::Tiers.variant?(name)
names.include?(LonaCraft::Tiers.base_of(name)) ? eq : nil
end
def self.tool_ok?(names)
TOOLS_IN_HAND ? main_hand?(names) : has_any?(names)
end
def self.pickaxe_ok?
!PICKAXE_REQUIRED || tool_ok?(PICKAXES)
end
def self.axe_ok?
!AXE_REQUIRED || tool_ok?(AXES)
end
#----------------------------------------------------------------------
# Boulder event (database load)
#----------------------------------------------------------------------
def self.load_database
register_boulder_event
register_loose_event
rescue => e
p "LonaCraft Nodes load error #{e.class} #{e.message}"
end
def self.custom_sprite?(name)
File.exist?(LonaCraft.resource("Graphics/Characters/#{name}.png"))
end
def self.register_boulder_event
clone_node(BOULDER_EVENT, BOULDER_SCRIPT, PLACEHOLDER_SPRITE, 0, 2, 0, CUSTOM_SPRITE, BOULDER_HP)
end
def self.register_loose_event
clone_node(LOOSE_EVENT, LOOSE_SCRIPT, LOOSE_SHEET, LOOSE_INDEX, LOOSE_DIR, LOOSE_PATTERN, LOOSE_CUSTOM, 1, true)
end
# A node event cloned from the game's StaticSaltpeter: same init
# (overlap guard, @nap_initialize=3), opaque upright picture, its
# action runs +script+ (path relative to the mod).
# through: walk over it (the loose stone, so it never blocks a narrow path);
# the action key still starts it when Lona faces it (priority stays
# "same as characters").
def self.clone_node(name, script, sheet, index, dir, pattern, custom_name, hp, through = false)
src = $data_EventLib[BOULDER_TEMPLATE]
if src.nil?
p "LonaCraft Nodes: EventLib #{BOULDER_TEMPLATE} not found, no #{name}"
return
end
ev = Marshal.load(Marshal.dump(src[1]))
ev.name = name
page = ev.pages[0]
custom = custom_sprite?(custom_name)
page.graphic.tile_id = 0
if custom
page.graphic.character_name = "../../#{LonaCraft.path}/Graphics/Characters/#{custom_name}"
page.graphic.character_index = 0
page.graphic.direction = 2
page.graphic.pattern = 0
else
page.graphic.character_name = sheet
page.graphic.character_index = index
page.graphic.direction = dir
page.graphic.pattern = pattern
end
page.walk_anime = false
page.step_anime = false
page.direction_fix = true
page.through = true if through
path = LonaCraft.resource(script)
found_script = false
page.list.each{|cmd|
next unless cmd.code == 355 || cmd.code == 655
prm = cmd.parameters[0]
next unless prm.is_a?(String)
if prm.include?("load_script(")
cmd.parameters[0] = "load_script(#{path.inspect})"
found_script = true
next
end
prm = prm.gsub(/:HP\s*=>\s*\d+/, ":HP => #{hp}")
prm = prm.gsub(/@forced_z\s*=\s*-?\d+/, "@forced_z = 0") # the ore decal sits below characters
prm = prm.gsub(/@opacity\s*=\s*[^\n]+/, "@opacity = 255")
prm = prm.gsub(/@blend_type\s*=\s*\d+/, "@blend_type = 0") # the ore glitters (additive)
prm = prm.gsub(/@pattern\s*=\s*rand\(\d+\)/, "@pattern = #{page.graphic.pattern}")
cmd.parameters[0] = prm
}
unless found_script
p "LonaCraft Nodes: #{BOULDER_TEMPLATE} has no load_script line, no #{name}"
return
end
if custom
last = page.list.index{|cmd| cmd.code == 118 && cmd.parameters[0] == "end_common" }
if last
page.list.insert(last, EvLib.NewEventCMD("@manual_ch = 1"))
page.list.insert(last, EvLib.NewEventCMD("@manual_cw = 1"))
end
end
$data_EventLib[name] = [src[0], ev]
p "LonaCraft Nodes: #{name} uses #{page.graphic.character_name}"
end
#----------------------------------------------------------------------
# Boulder and loose stone placement (fresh region map visit)
#----------------------------------------------------------------------
def self.family(map)
return nil unless map.name.to_s =~ /\Ar(\d+)_/
$1.to_i
end
def self.boulder_row(map)
fam = family(map)
fam ? BOULDER_MAPS[fam] : nil
end
def self.start_point(map)
pt = map.get_storypoint("StartPoint")
[pt[0], pt[1]]
rescue
nil
end
def self.open_tile?(map, x, y)
return false unless map.valid?(x, y)
return false if map.respond_to?(:water_floor?) && map.water_floor?(x, y)
[2, 4, 6, 8].all?{|d| map.passable?(x, y, d) }
end
def self.closed_tile?(map, x, y)
map.valid?(x, y) && [2, 4, 6, 8].none?{|d| map.passable?(x, y, d) }
end
NEIGHBOURS4 = [[1, 0], [-1, 0], [0, 1], [0, -1]]
# tiles taken by an event, a pending summon or an earlier boulder
def self.taken_tiles(map)
taken = {}
map.events.values.each{|e|
next if e.nil? || (e.respond_to?(:deleted?) && e.deleted?)
taken[[e.x, e.y]] = true
}
pending = map.instance_variable_get(:@summoned_evs)
if pending.is_a?(Array)
pending.each{|row| taken[[row[1], row[2]]] = true if row.is_a?(Array) && !row[1].nil? }
end
taken
end
def self.near_taken?(taken, x, y)
(-1..1).any?{|dx| (-1..1).any?{|dy| taken[[x + dx, y + dy]] } }
end
def self.candidate?(map, rule, taken, start, x, y, clear = START_CLEAR)
return false if near_taken?(taken, x, y)
if start && (x - start[0]).abs < clear && (y - start[1]).abs < clear
return false
end
case rule
when :face
closed_tile?(map, x, y) && NEIGHBOURS4.any?{|dx, dy| open_tile?(map, x + dx, y + dy) }
else
open_tile?(map, x, y) && NEIGHBOURS4.all?{|dx, dy| open_tile?(map, x + dx, y + dy) }
end
end
def self.boulder_count(max)
actor = $game_actors[1]
asd = 1 + actor.wisdom + 2 * actor.survival
count = 1
(2..max).each{|k| count += 1 if asd >= rand(25 * (k - 1)) }
count
end
def self.spawn_boulders(map)
return unless BOULDERS_ENABLED
return unless $data_EventLib[BOULDER_EVENT]
row = boulder_row(map)
return if row.nil?
max, region, rule = row
tiles = map.region_map && map.region_map[region]
return if tiles.nil? || tiles.empty?
start = start_point(map)
taken = taken_tiles(map)
want = boulder_count(max)
placed = 0
tiles.shuffle.each{|x, y|
break if placed >= want
next unless candidate?(map, rule, taken, start, x, y)
EvLib.sum(BOULDER_EVENT, x, y)
taken[[x, y]] = true
placed += 1
}
p "LonaCraft Nodes: #{placed}/#{want} boulders on #{map.name}"
end
# After the boulders: their pending summons count as taken tiles.
def self.spawn_loose_stones(map)
return unless LOOSE_ENABLED
return unless $data_EventLib[LOOSE_EVENT]
fam = family(map)
region = fam ? LOOSE_MAPS[fam] : nil
return if region.nil?
tiles = map.region_map && map.region_map[region]
return if tiles.nil? || tiles.empty?
start = start_point(map)
taken = taken_tiles(map)
want = LOOSE_MIN + rand(LOOSE_MAX - LOOSE_MIN + 1)
placed = 0
tiles.shuffle.each{|x, y|
break if placed >= want
next unless candidate?(map, :open, taken, start, x, y, LOOSE_START_CLEAR)
EvLib.sum(LOOSE_EVENT, x, y)
taken[[x, y]] = true
placed += 1
}
p "LonaCraft Nodes: #{placed}/#{want} loose stones on #{map.name}"
end
#----------------------------------------------------------------------
# Tree redirects (as 100_Homes.rb Homes.redirect)
#----------------------------------------------------------------------
def self.wrapper_script(game_script)
LonaCraft.resource("HCGframes/#{File.basename(game_script.to_s)}")
end
def self.previous_script(game_script)
@previous[game_script.to_s] || game_script.to_s
end
def self.redirect(game_script)
mine = wrapper_script(game_script)
unless File.exist?(mine)
p "LonaCraft Nodes: missing #{mine}, #{game_script} left alone"
return
end
current = $mod_load_script.fetch(game_script, game_script)
@previous[game_script] = current unless current == mine
$mod_load_script[game_script] = mine
end
def self.install_redirects
return if $mod_load_script.nil?
TREE_SCRIPTS.each{|script| redirect(script) }
rescue => e
p "LonaCraft Nodes redirect error #{e.class} #{e.message}"
end
end
end
LonaCraft::Nodes.install_redirects
module DataManager
unless respond_to?(:load_mod_database_lonacraft_nodes)
self.singleton_class.send(:alias_method, :load_mod_database_lonacraft_nodes, :load_mod_database)
def self.load_mod_database
load_mod_database_lonacraft_nodes
LonaCraft::Nodes.load_database
end
end
end
class Game_Interpreter
# GIM_ADDON#enter_static_region_map (34_Functions_ChangeMap.rb:104)
def enter_static_region_map(*args)
begin
if $story_stats["ReRollHalfEvents"] == 1
LonaCraft::Nodes.spawn_boulders($game_map)
LonaCraft::Nodes.spawn_loose_stones($game_map)
end
rescue => e
p "LonaCraft Nodes boulder spawn error #{e.class} #{e.message}"
end
super
end
# Run by HCGframes/Mining_Boulder.rb (the boulder's action)
def lonacraft_mine_boulder
nodes = LonaCraft::Nodes
ev = get_character(0)
return if ev.nil?
actor = $game_player.actor
if actor.sta <= 0
SndLib.sys_ChangeMapFailed(80, 80)
$game_map.popup(0, "QuickMsg:Lona/sta_too_low#{rand(2)}", 0, 0)
return
end
unless nodes.pickaxe_ok?
SndLib.sys_buzzer
$game_map.popup(0, nodes.text_key("Boulder/need_pickaxe"), 0, 0)
return
end
$game_player.animation = $game_player.animation_atk_mh
held = nodes.held_tool(nodes::PICKAXES)
if respond_to?(:calc_harvest_sta_cost) # RolePlayS: 1 equipped / 2 otherwise, plus attribute exp
calc_harvest_sta_cost(1, held ? held.item_name : nodes::PICKAXES[0])
else
actor.sta -= held ? 1 : 2 # always 1 with TOOLS_IN_HAND
end
data = ev.summon_data
if !data.is_a?(Hash)
ev.instance_variable_set(:@summon_data, {:HP => nodes::BOULDER_HP})
data = ev.summon_data
end
data[:HP] = (data[:HP] || nodes::BOULDER_HP) - 1
SndLib.sound_combat_sword_hit_sword
return unless data[:HP] % nodes::HITS_PER_YIELD == 0
x = $game_player.x
y = $game_player.y
count = 1
count += nodes::LAST_YIELD_BONUS if data[:HP] <= 0
count.times{ EvLib.sum(nodes::STONE_ITEM, x, y) } if $data_EventLib[nodes::STONE_ITEM]
EvLib.sum(nodes::IRON_ITEM, x, y) if $data_EventLib[nodes::IRON_ITEM] && rand(100) < nodes::IRON_PCT
ev.delete if data[:HP] <= 0
end
# Run by HCGframes/Mining_LooseStone.rb (a loose stone's action): one
# pick, the game's ground pickup feedback, then the stone is gone.
def lonacraft_pick_loose_stone
ev = get_character(0)
return if ev.nil?
common_pickup_item(LonaCraft::Nodes::STONE_ITEM, true) # pose, sound, "+1" popup (29_Functions_417_Interpreter.rb:861-867, 410-418)
ev.delete
end
# Run by HCGframes/CommonTree.rb and CommonTreeNoble.rb (the redirect)
def lonacraft_tree_chop(game_script)
nodes = LonaCraft::Nodes
unless nodes.axe_ok?
SndLib.sys_buzzer
$game_map.popup(0, nodes.text_key("Tree/need_axe"), 0, 0)
return
end
# the script that ran before LonaCraft (RolePlayS copy or the game's);
# the redirect is lifted for the call so it does not loop back here
mine = $mod_load_script[game_script]
$mod_load_script.delete(game_script) if mine == nodes.wrapper_script(game_script)
begin
load_script(nodes.previous_script(game_script))
ensure
$mod_load_script[game_script] = mine if mine
end
end
end