class_name Tutorial extends Control ## Short contextual tips on the first day and night (night 1), one at a time in a box above the ## hotbar. Each shows when it's useful and goes away once it's done: ## Day: move -> gather -> store at the shed -> build (also once half the day has gone) ## Dusk: where and when the thieves come ## Night: fight (once enemies are in), fear (when crowded), recover (when something is ## dropped), patch up (when hurt) ## The most urgent one wins (recover, fear, patch, shoot, dusk, then the day's in order). ## [Backspace / Back] hides them until the game is restarted; Settings turns them off. ## Finished tips stay finished for the session, so a retry or a second vacation doesn't repeat ## them. const TEXT := { "move": "Move with [W A S D] or the left stick. You're the scarecrow: keep the farm safe until the farmers are back.", "gather": "Hold [E / X] at a dead tree, the haystacks, or the scrap heap to gather wood, straw, and scrap.", "store": "Your pouch only holds so much ([I] shows what's in it): walk onto the barn's apron (the Supply Shed) to store what you carry.", "build": "Press [B / d-pad up] to build. Pick a fence [1], place it with left mouse / RT. Aliens have to break through fences.", "dusk": "Dusk: aliens come at nightfall, from every side of the farm.", "shoot": "Aim with the mouse or the right stick and hold left mouse / RT to stab with your pitchfork. The supply shed sells a corn shooter (switch with [Tab / the number keys]); more weapons arrive there over the days, like pumpkin bombs for your off-hand (throw them with [right mouse / LT]).", "fear": "Crowded? [Q / LB] Fear scares off everything nearby, and they drop what they carry.", "recover": "Something was dropped! Walk over it to bring it home. A dropped animal follows you back to the pen.", "patch": "Hurt? Hold [F / Y] to patch up with straw. Health carries over to the next night.", } const PRIORITY: Array[String] = ["recover", "fear", "patch", "shoot", "dusk", "move", "gather", "store", "build"] const DONE_TIME := 0.9 const CROWD_RADIUS := 7.0 var sim: FarmSim ## Off when the player turned tips off in Settings. var enabled := true ## The player hid them (for this session). var dismissed := false var done := {} var current := "" var _box: PanelContainer var _text: Label var _hint: Label var _start := Vector3.ZERO var _shots_at_night: int = 0 var _done_left: float = 0.0 func setup(p_sim: FarmSim) -> void: sim = p_sim sim.campaign.phase_changed.connect(_on_phase) sim.interactions.deposited.connect(func(_moved: Dictionary) -> void: _finish("store")) sim.scarecrow.fear_used.connect(func(_p: Vector3, _n: int) -> void: _finish("fear")) sim.scarecrow.patched.connect(func(_hp: int) -> void: _finish("patch")) sim.loot.loot_event.connect(func(kind: StringName, _id: int, _at: Vector3) -> void: if kind == &"recovered" or kind == &"following": _finish("recover")) sim.campaign.campaign_ended.connect(func(_o: CampaignController.Outcome) -> void: _show("")) _start = sim.player.global_position func _ready() -> void: set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) mouse_filter = Control.MOUSE_FILTER_IGNORE _box = PanelContainer.new() var bg := StyleBoxFlat.new() bg.bg_color = Color(0.08, 0.1, 0.08, 0.86) bg.border_color = Color(0.95, 0.82, 0.45) bg.set_border_width_all(2) bg.set_corner_radius_all(6) bg.content_margin_left = 18.0 bg.content_margin_right = 18.0 bg.content_margin_top = 10.0 bg.content_margin_bottom = 10.0 _box.add_theme_stylebox_override("panel", bg) _box.mouse_filter = Control.MOUSE_FILTER_IGNORE add_child(_box) var col := VBoxContainer.new() _box.add_child(col) _text = Label.new() _text.custom_minimum_size = Vector2(760.0, 0.0) _text.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART _text.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER _text.add_theme_font_size_override("font_size", 24) col.add_child(_text) _hint = Label.new() _hint.text = "Tip ยท [Backspace / Back] hide tips" _hint.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER _hint.add_theme_font_size_override("font_size", 16) _hint.add_theme_color_override("font_color", Color(0.7, 0.72, 0.65)) col.add_child(_hint) _box.visible = false func _process(delta: float) -> void: if sim == null: return var s := sim.campaign.state if not enabled or dismissed or s.night != 1 or sim.campaign.is_over() or sim._menu_open() \ or (sim.dialogue != null and sim.dialogue.is_playing()): _show("") return _check_done() if _done_left > 0.0: _done_left -= delta return var want := "" for id in PRIORITY: if not done.has(id) and _wanted(id): want = id break _show(want) ## Whether the tip is useful right now. func _wanted(id: String) -> bool: var c := sim.campaign var phase := c.state.phase var day := phase == CampaignController.Phase.DAY or phase == CampaignController.Phase.DUSK var night := phase == CampaignController.Phase.NIGHT or phase == CampaignController.Phase.DAWN match id: "move": return phase == CampaignController.Phase.DAY "gather": return day and done.has("move") "store": return day and c.state.resources.pouch_total(sim.local_avatar.slot) > 0 "build": return day and (done.has("store") or c.state.phase_time_left < c.phase_length(CampaignController.Phase.DAY) * 0.5 or phase == CampaignController.Phase.DUSK) "dusk": return phase == CampaignController.Phase.DUSK "shoot": return night and sim.enemies.alive_count() > 0 "fear": return night and sim.scarecrow.fear_left == 0.0 and _enemies_near() >= 2 "recover": return sim.loot.count(LootSystem.Status.DROPPED) > 0 "patch": return night and sim.scarecrow.hp() < sim.scarecrow.max_hp() return false func _check_done() -> void: var s := sim.campaign.state if not done.has("move") and Vector2(sim.player.global_position.x - _start.x, sim.player.global_position.z - _start.z).length() > 4.0: _finish("move") var e := s.night_events if not done.has("gather") and int(e.get("gathered_wood", 0)) + int(e.get("gathered_scrap", 0)) + int(e.get("gathered_straw", 0)) > 0: _finish("gather") if not done.has("build") and int(e.get("structures_built", 0)) > 0: _finish("build") if not done.has("shoot") and sim.combat.attacks() - _shots_at_night >= 4 and s.phase == CampaignController.Phase.NIGHT: _finish("shoot") func _finish(id: String) -> void: if done.has(id): return done[id] = true if id == current and _box.visible: _text.text = "Done! " + _text.text _text.add_theme_color_override("font_color", Color(0.6, 1.0, 0.55)) _done_left = DONE_TIME func _show(id: String) -> void: current = id _box.visible = id != "" if id == "": return _text.text = TEXT[id] _text.remove_theme_color_override("font_color") _box.reset_size() _box.position = Vector2((size.x - _box.size.x) * 0.5, size.y - 250.0 - _box.size.y) func _enemies_near() -> int: var p := Vector2(sim.player.global_position.x, sim.player.global_position.z) var es := sim.enemies var n := 0 for d in es.active_count: if es.alive[d] == 1 and Vector2(es.pos_x[d], es.pos_z[d]).distance_to(p) <= CROWD_RADIUS: n += 1 return n func _on_phase(phase: CampaignController.Phase, _previous: CampaignController.Phase) -> void: match phase: CampaignController.Phase.DAY: _start = sim.player.global_position CampaignController.Phase.NIGHT: _finish("dusk") _shots_at_night = sim.combat.attacks() func _unhandled_input(event: InputEvent) -> void: if _box.visible and event.is_action_pressed("hide_tips"): dismissed = true _show("") get_viewport().set_input_as_handled()