ld58-collector/audience_manager.gd

94 lines
2.7 KiB
GDScript

class_name AudienceManager extends Node2D
@export var desk: Desk
@export var timer: Timer
@export var game_manager: GameManager
signal ask_accepted
var bark_critical := false
var currently_animated_collector = null
#ideally variable for influencing how much the audience responds to barks
@export var audience_susceptibility := 0.4:
set(value):
audience_susceptibility = clamp(value, 0, 1)
#meant to make the audience more inclined to bid as day progresses
@export var audience_time_pressure := 1.4
@export var min_audience_think_time := 0.5
@export var max_audience_think_time := 2.0
@export var bid_threshold := 3.0
@export var think_chance := 0.5
@export var think_min_time := 1.0
@export var think_max_time := 5.0
var current_ask: int
var latest_bidder: ArtCollector
var acceptable_raise = 0
func _ready() -> void:
desk.numpad.ask_proposed.connect(_handle_ask_proposed)
timer.timeout.connect(_handle_bid_delay_timeout)
desk.bark.bark.connect(_handle_auctioneer_bark)
desk.numpad.reminder_timer.timeout.connect(try_clear_currently_animated_collector)
desk.gavel.gavel_hit.connect(try_clear_currently_animated_collector)
func raise_paddle():
game_manager.state = game_manager.bidding_state.BID
print("Audience accepts the bid at $" + str(current_ask))
game_manager.current_bid = desk.numpad.proposed_ask
var collectors: Array[Node] = get_tree().get_nodes_in_group("ArtCollectors")
collectors.shuffle()
try_clear_currently_animated_collector()
currently_animated_collector = collectors[0]
latest_bidder = collectors[0]
if bark_critical:
latest_bidder.critical_paddle()
print("play crit paddle")
else:
latest_bidder.normal_paddle()
print("play norm paddle")
bark_critical = false
ask_accepted.emit()
func try_clear_currently_animated_collector():
if currently_animated_collector:
currently_animated_collector.idle()
currently_animated_collector = null
func _handle_auctioneer_bark():
if timer.time_left >= think_min_time:
bark_critical = true
timer.stop()
timer.timeout.emit()
else:
acceptable_raise += randi_range(100, 1000)
func _handle_bid_delay_timeout():
if game_manager.state == game_manager.bidding_state.ASKING:
if randf_range(1.2, 5.3) >= bid_threshold:
raise_paddle()
timer.stop()
func _handle_ask_proposed(amount):
current_ask = amount
if acceptable_raise == 0:
acceptable_raise = randf_range(0.1, 0.2) * current_ask
if game_manager.current_bid == 0:
if randf() < think_chance: _start_bid_timer()
elif current_ask - game_manager.current_bid <= acceptable_raise:
_start_bid_timer()
func _start_bid_timer():
timer.stop()
var ask_duration: float = randf_range(min_audience_think_time, max_audience_think_time)
timer.wait_time = ask_duration
timer.start()