* changements des objectifs, donnent juste des graines, sprite moins gros et objectifs plus nombreux * changement de la probabilité de mutation * refactor du code terrain et planet
174 lines
5.0 KiB
GDScript
174 lines
5.0 KiB
GDScript
extends Control
|
|
class_name Tutorial
|
|
|
|
const INDICATOR_SCENE = preload("res://gui/game/tutorial/in_game_indicator/in_game_indicator.tscn")
|
|
|
|
var indicators : Array[InGameIndicator]
|
|
@export var player : Player
|
|
|
|
@onready var steps : Array[Step] = [
|
|
TakeShovelStep.new(),
|
|
DigLootStep.new(),
|
|
TakeSeedStep.new(),
|
|
PlantSeedStep.new(),
|
|
RechargeStep.new(),
|
|
WaitMaturePlant.new(),
|
|
HarvestMaturePlant.new(),
|
|
]
|
|
var actual_step : Step = null : set = pass_to_step
|
|
|
|
func _process(_d):
|
|
if not GameInfo.game_data.tutorial_done:
|
|
if not actual_step and len(steps):
|
|
destroy_indicators()
|
|
pass_to_step(steps.pop_front())
|
|
|
|
if player and actual_step and actual_step.is_step_over(player):
|
|
destroy_indicators()
|
|
if len(steps):
|
|
pass_to_step(steps.pop_front())
|
|
else :
|
|
GameInfo.game_data.tutorial_done = true
|
|
|
|
func destroy_indicators():
|
|
for i in indicators:
|
|
i.queue_free()
|
|
indicators = []
|
|
|
|
func pass_to_step(new_step : Step):
|
|
actual_step = new_step
|
|
indicators = new_step.generate_indicators(player)
|
|
for i in indicators:
|
|
add_child(i)
|
|
|
|
class Step:
|
|
func generate_indicator(text : String) -> InGameIndicator:
|
|
var new_indicator : InGameIndicator = INDICATOR_SCENE.instantiate()
|
|
new_indicator.setup(
|
|
text
|
|
)
|
|
return new_indicator
|
|
|
|
func generate_indicators(_player : Player) -> Array[InGameIndicator]:
|
|
return []
|
|
|
|
func is_step_over(_p : Player) -> bool:
|
|
return true
|
|
|
|
class TakeShovelStep extends Step:
|
|
func generate_indicators(p: Player) -> Array[InGameIndicator]:
|
|
for entity in p.planet.entity_container.get_children():
|
|
if entity is ItemObject and entity.item is Shovel:
|
|
var indicator = generate_indicator("Take the Shovel")
|
|
indicator.follow_entity(entity)
|
|
return [
|
|
indicator
|
|
]
|
|
printerr("No Shovel found...")
|
|
return []
|
|
|
|
func is_step_over(p : Player) -> bool:
|
|
return p.inventory.length() > 0
|
|
|
|
class DigLootStep extends Step:
|
|
func generate_indicators(p: Player) -> Array[InGameIndicator]:
|
|
var indicators : Array[InGameIndicator] = []
|
|
for entity in p.planet.entity_container.get_children():
|
|
if entity is UndergroundLoot:
|
|
var indicator = generate_indicator("Dig Underground Loot")
|
|
indicator.follow_entity(entity)
|
|
indicators.append(
|
|
indicator
|
|
)
|
|
return indicators
|
|
|
|
func is_step_over(p : Player) -> bool:
|
|
for entity in p.terrain.entity_container.get_children():
|
|
if entity is ItemObject and entity.item is Seed:
|
|
return true
|
|
return false
|
|
|
|
class TakeSeedStep extends Step:
|
|
func generate_indicators(p: Player) -> Array[InGameIndicator]:
|
|
var indicators : Array[InGameIndicator] = []
|
|
for entity in p.terrain.entity_container.get_children():
|
|
if entity is ItemObject and entity.item is Seed:
|
|
var indicator = generate_indicator("Take a seed")
|
|
indicator.follow_entity(entity)
|
|
indicators.append(
|
|
indicator
|
|
)
|
|
return indicators
|
|
|
|
func is_step_over(p : Player) -> bool:
|
|
for item in p.inventory.items:
|
|
if item is Seed:
|
|
return true
|
|
return false
|
|
|
|
class PlantSeedStep extends Step:
|
|
func generate_indicators(p: Player) -> Array[InGameIndicator]:
|
|
var indicator = generate_indicator("Plant the seed in decontamined zone")
|
|
indicator.follow_game_position(Vector2(0,0) + p.planet.entity_container.global_position)
|
|
return [indicator]
|
|
|
|
func is_step_over(p : Player) -> bool:
|
|
for entity in p.terrain.entity_container.get_children():
|
|
if entity is Plant:
|
|
return true
|
|
return false
|
|
|
|
class RechargeStep extends Step:
|
|
func generate_indicators(p: Player) -> Array[InGameIndicator]:
|
|
for entity in p.planet.entity_container.get_children():
|
|
var indicator = generate_indicator("Recharge to pass days")
|
|
indicator.follow_entity(entity)
|
|
if entity is TruckRecharge:
|
|
return [
|
|
indicator
|
|
]
|
|
printerr("No Recharge Station found...")
|
|
return []
|
|
|
|
func is_step_over(p : Player) -> bool:
|
|
if p.planet == null :
|
|
return false
|
|
return p.planet.day > 1
|
|
|
|
class WaitMaturePlant extends Step:
|
|
func generate_indicators(_p: Player) -> Array[InGameIndicator]:
|
|
return []
|
|
|
|
func is_step_over(p : Player) -> bool:
|
|
if p.planet == null :
|
|
return false
|
|
for entity in p.planet.entity_container.get_children():
|
|
if entity is Plant and entity.state == Plant.State.MATURE:
|
|
return true
|
|
return false
|
|
|
|
class HarvestMaturePlant extends Step:
|
|
|
|
var mature_plant_number : int = 0
|
|
|
|
func generate_indicators(p: Player) -> Array[InGameIndicator]:
|
|
var indicators : Array[InGameIndicator] = []
|
|
for entity in p.planet.entity_container.get_children():
|
|
if entity is Plant and entity.state == Plant.State.MATURE:
|
|
var indicator = generate_indicator("Harvest mature plants with shovel")
|
|
indicator.follow_entity(entity)
|
|
indicators.append(
|
|
indicator
|
|
)
|
|
mature_plant_number += 1
|
|
return indicators
|
|
|
|
func is_step_over(p : Player) -> bool:
|
|
if p.planet == null :
|
|
return false
|
|
var actual_mature_plant_number = 0
|
|
for entity in p.planet.entity_container.get_children():
|
|
if entity is Plant and entity.state == Plant.State.MATURE:
|
|
actual_mature_plant_number += 1
|
|
return mature_plant_number != actual_mature_plant_number
|