This commit is contained in:
2026-01-28 02:29:43 +08:00
parent d71f5d67e3
commit 6949e20a1f
13 changed files with 285 additions and 100 deletions
+2 -1
View File
@@ -307,7 +307,8 @@ func _try_move() -> bool:
Vector2(actor.current_position),
Vector2(final_target),
0,
false
false,
false # Disable visualization
)
var next_step = Vector2i(-1, -1)
@@ -0,0 +1,25 @@
class_name ScarcityController
extends RefCounted
# ScarcityController - Logic for tile generation based on ScarcityModel
static func get_random_tile_id() -> int:
var rng = RandomNumberGenerator.new()
rng.randomize()
var weights = ScarcityModel.get_tile_weights()
var total_weight = 0
# Calculate total weight
for tile in weights:
total_weight += weights[tile]
var roll = rng.randi_range(0, total_weight - 1)
var current = 0
for tile in weights:
current += weights[tile]
if roll < current:
return tile
return ScarcityModel.TILE_HEART # Fallback
@@ -0,0 +1 @@
uid://4ocyvmq6fbmx
@@ -0,0 +1 @@
uid://cray2jslf200d
+26
View File
@@ -34,6 +34,10 @@ var randomize_spawn: bool = true # Default enabled
var enable_cycle_timer: bool = false # Default disabled
signal enable_cycle_timer_changed(enabled: bool)
# Scarcity setting
var scarcity_mode: String = "Normal" # Normal, Aggressive, Chaos
signal scarcity_mode_changed(mode: String)
# Character and area selection
var available_characters: Array[String] = ["Bob", "Gatot", "Masbro", "Oldpop"]
var available_areas: Array[String] = ["Desert", "Forest", "City", "Factory"]
@@ -203,6 +207,26 @@ func sync_enable_cycle_timer(enabled: bool) -> void:
func get_enable_cycle_timer() -> bool:
return enable_cycle_timer
# =============================================================================
# Scarcity Mode
# =============================================================================
func set_scarcity_mode(mode: String) -> void:
"""Host sets scarcity mode. Syncs to clients."""
scarcity_mode = mode
if is_host:
rpc("sync_scarcity_mode", mode)
@rpc("authority", "call_local", "reliable")
func sync_scarcity_mode(mode: String) -> void:
scarcity_mode = mode
# Update ScarcityModel immediately
ScarcityModel.set_mode(mode)
emit_signal("scarcity_mode_changed", mode)
func get_scarcity_mode() -> String:
return scarcity_mode
# =============================================================================
# Character Selection
# =============================================================================
@@ -297,6 +321,8 @@ func start_game() -> void:
rpc("sync_match_duration", match_duration)
# Sync timer setting
rpc("sync_enable_cycle_timer", enable_cycle_timer)
# Sync scarcity mode
rpc("sync_scarcity_mode", scarcity_mode)
# Notify all clients to start
rpc("_on_game_starting")
+8 -12
View File
@@ -170,22 +170,18 @@ func _check_and_refill_grid_if_needed(server_gridmap: Node):
var has_items = false
var item_list = server_gridmap.mesh_library.get_item_list() if server_gridmap.mesh_library else []
# We can't efficiently iterate all cells, but we can check usage via get_used_cells_by_item is too specific
# Iterating columns/rows is safe for this map size (10x10 usually)
for x in range(server_gridmap.columns):
for z in range(server_gridmap.rows):
var item = server_gridmap.get_cell_item(Vector3i(x, 1, z))
if item != -1:
has_items = true
break
if has_items:
# Iterate used cells to check for ANY item on floor 1
var used_cells = server_gridmap.get_used_cells()
for cell in used_cells:
if cell.y == 1: # Floor 1
has_items = true
break
if not has_items:
print("[PlayerboardManager] Floor 1 empty! Respawning tiles with Scarcity...")
# Call randomize_floor on floor 1
# Since Main owns gridmap, we can sync this or just do it server side (which we are)
server_gridmap.randomize_floor(1)
# Call randomize_floor on floor 1 using ScarcityController
# ScarcityController is a global class, so we can pass its static function as a Callable
server_gridmap.randomize_floor(1, ScarcityController.get_random_tile_id)
# We need to sync the ENTIRE floor to clients.
# EnhancedGridMap doesn't have a "Sync Floor" RPC built-in to Main, only single cells or array update.
-51
View File
@@ -1,51 +0,0 @@
extends Node
class_name ScarcityManager
# ScarcityManager - Handles weighted random, tile generation for gameplay balance
const TILES = [7, 8, 9, 10]
const SPECIAL_TILES = [11, 12, 13, 14]
# Weights (higher = more common)
# Standard tiles: Heart, Diamond, Star, Coin
const TILE_WEIGHTS = {
7: 100, # Heart
8: 100, # Diamond
9: 100, # Star
10: 100 # Coin
}
# Special tiles: Burn, Spawn, Freeze, Block, Invisible
const SPECIAL_WEIGHTS = {
11: 5,
12: 5,
13: 5,
14: 5
}
static func get_random_tile_id() -> int:
var rng = RandomNumberGenerator.new()
rng.randomize()
var total_weight = 0
var pool = {}
# Add standard tiles
for id in TILE_WEIGHTS:
pool[id] = TILE_WEIGHTS[id]
total_weight += TILE_WEIGHTS[id]
# Add special tiles
for id in SPECIAL_WEIGHTS:
pool[id] = SPECIAL_WEIGHTS[id]
total_weight += SPECIAL_WEIGHTS[id]
var roll = rng.randi_range(0, total_weight - 1)
var current = 0
for id in pool:
current += pool[id]
if roll < current:
return id
return 7 # Fallback to Heart
+56
View File
@@ -0,0 +1,56 @@
class_name ScarcityModel
extends RefCounted
# ScarcityModel - Data definitions for tile scarcity
# Standard tiles
const TILE_HEART = 7
const TILE_DIAMOND = 8
const TILE_STAR = 9
const TILE_COIN = 10
# Special tiles (Holo)
const TILE_BURN = 11
const TILE_SPAWN = 12
const TILE_FREEZE = 13
const TILE_BLOCK = 14
const STANDARD_TILES = [
TILE_HEART, TILE_DIAMOND, TILE_STAR, TILE_COIN
]
const SPECIAL_TILES = [
TILE_BURN, TILE_SPAWN, TILE_FREEZE, TILE_BLOCK
]
# Weights (higher = more common)
const STANDARD_WEIGHT = 100
const SPECIAL_WEIGHT = 5
# Configuration
static var current_mode: String = "Normal"
# Mode Weights (Special Tile Weight)
const WEIGHTS = {
"Normal": 5, # 5% chance relative to 100
"Aggressive": 25, # 25% chance
"Chaos": 50 # 50% chance
}
static func set_mode(mode: String):
if mode in WEIGHTS:
current_mode = mode
static func get_tile_weights() -> Dictionary:
var weights = {}
var special_weight = WEIGHTS.get(current_mode, 5)
# Standard tiles
for tile in STANDARD_TILES:
weights[tile] = STANDARD_WEIGHT
# Special tiles
for tile in SPECIAL_TILES:
weights[tile] = special_weight
return weights
+1
View File
@@ -0,0 +1 @@
uid://dh2t1v7y0e61q