212 lines
8.0 KiB
GDScript
212 lines
8.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
|
|
@export var planet : Planet
|
|
|
|
@onready var steps : Array[Step] = [
|
|
TakeShovelStep.new(),
|
|
DigSeedStep.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 planet.data.tutorial_step < len(steps):
|
|
destroy_indicators()
|
|
pass_to_step(steps[planet.data.tutorial_step])
|
|
|
|
if player and actual_step and actual_step.is_step_over(player, planet):
|
|
destroy_indicators()
|
|
planet.data.tutorial_step += 1
|
|
if planet.data.tutorial_step < len(steps):
|
|
pass_to_step(steps[planet.data.tutorial_step])
|
|
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, planet)
|
|
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, _planet : Planet) -> Array[InGameIndicator]:
|
|
return []
|
|
|
|
func is_step_over(_p : Player, _planet : Planet) -> bool:
|
|
return true
|
|
|
|
class TakeShovelStep extends Step:
|
|
func generate_indicators(_p: Player, planet : Planet) -> Array[InGameIndicator]:
|
|
for entity in planet.entity_container.get_children():
|
|
if entity is ItemObject and entity.item is Shovel:
|
|
var indicator = generate_indicator(tr("TAKE_THE_SHOVEL"))
|
|
indicator.follow_entity(entity)
|
|
return [
|
|
indicator
|
|
]
|
|
printerr("No Shovel found...")
|
|
return []
|
|
|
|
func is_step_over(p : Player, _planet : Planet) -> bool:
|
|
for item in p.data.inventory.items:
|
|
if item is Shovel:
|
|
return true
|
|
return false
|
|
|
|
class DigSeedStep extends Step:
|
|
func generate_indicators(p: Player, planet : Planet) -> Array[InGameIndicator]:
|
|
var closest_seed = null
|
|
var limit_distance = 1000
|
|
|
|
var actual_distance = 100
|
|
var player_tile = Math.get_tile_from_pos(p.global_position)
|
|
|
|
while closest_seed == null and actual_distance < limit_distance:
|
|
print(player_tile)
|
|
for x in range(actual_distance):
|
|
for y in range(actual_distance):
|
|
var coord = Vector2i(x,y) - Vector2i.ONE * floori(actual_distance/2.) + player_tile
|
|
if planet.rock_layer.get_tile_type(coord) == RockLayer.TileType.CRISTAL:
|
|
if closest_seed == null or player_tile.distance_to(coord) < player_tile.distance_to(closest_seed):
|
|
closest_seed = coord
|
|
|
|
actual_distance += 100
|
|
|
|
if closest_seed:
|
|
var indicator = generate_indicator(tr("DIG_UNDERGROUND_LOOT"))
|
|
indicator.follow_game_position(closest_seed * Planet.TILE_SIZE + Vector2i.ONE * floori(Planet.TILE_SIZE/2.))
|
|
return [indicator]
|
|
return []
|
|
|
|
func is_step_over(_p : Player, planet : Planet) -> bool:
|
|
for entity in planet.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, planet : Planet) -> Array[InGameIndicator]:
|
|
var indicators : Array[InGameIndicator] = []
|
|
for entity in planet.entity_container.get_children():
|
|
if entity is ItemObject and entity.item is Seed:
|
|
var indicator = generate_indicator(tr("TAKE_A_SEED"))
|
|
indicator.follow_entity(entity)
|
|
indicators.append(
|
|
indicator
|
|
)
|
|
return indicators
|
|
|
|
func is_step_over(p : Player, _planet : Planet) -> bool:
|
|
for item in p.data.inventory.items:
|
|
if item is Seed:
|
|
return true
|
|
return false
|
|
|
|
class PlantSeedStep extends Step:
|
|
func generate_indicators(p: Player, planet : Planet) -> Array[InGameIndicator]:
|
|
|
|
var closest_decontamination = null
|
|
var limit_distance = 1000
|
|
|
|
var actual_distance = 100
|
|
var player_tile = Math.get_tile_from_pos(p.global_position)
|
|
|
|
while closest_decontamination == null and actual_distance < limit_distance:
|
|
print(player_tile)
|
|
for x in range(actual_distance):
|
|
for y in range(actual_distance):
|
|
var coord = Vector2i(x,y) - Vector2i.ONE * floori(actual_distance/2.) + player_tile
|
|
if planet.decontamination_layer.is_decontamined(coord):
|
|
if closest_decontamination == null or player_tile.distance_to(coord) < player_tile.distance_to(closest_decontamination):
|
|
closest_decontamination = coord
|
|
|
|
actual_distance += 100
|
|
|
|
if closest_decontamination:
|
|
var indicator = generate_indicator(tr("PLANT_THE_SEED_IN_DECONTAMINED_ZONE"))
|
|
indicator.follow_game_position(closest_decontamination * Planet.TILE_SIZE + Vector2i.ONE * floori(Planet.TILE_SIZE/2.))
|
|
return [indicator]
|
|
return []
|
|
|
|
func is_step_over(_p : Player, planet : Planet) -> bool:
|
|
for entity in planet.entity_container.get_children():
|
|
if entity is Plant:
|
|
return true
|
|
return false
|
|
|
|
class RechargeStep extends Step:
|
|
func generate_indicators(_p: Player, planet : Planet) -> Array[InGameIndicator]:
|
|
for entity in planet.entity_container.get_children():
|
|
var indicator = generate_indicator(tr("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, planet : Planet) -> bool:
|
|
if planet == null :
|
|
return false
|
|
return planet.data.day > 1
|
|
|
|
class WaitMaturePlant extends Step:
|
|
func generate_indicators(_p: Player, _planet : Planet) -> Array[InGameIndicator]:
|
|
return []
|
|
|
|
func is_step_over(_p : Player, planet : Planet) -> bool:
|
|
if planet == null :
|
|
return false
|
|
for entity in 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, planet : Planet) -> Array[InGameIndicator]:
|
|
var indicators : Array[InGameIndicator] = []
|
|
for entity in planet.entity_container.get_children():
|
|
if entity is Plant and entity.state == Plant.State.MATURE:
|
|
var indicator = generate_indicator(tr("HARVEST_MATURE_PLANTS_WITH_SHOVEL"))
|
|
indicator.follow_entity(entity)
|
|
indicators.append(
|
|
indicator
|
|
)
|
|
mature_plant_number += 1
|
|
return indicators
|
|
|
|
func is_step_over(_p : Player, planet : Planet) -> bool:
|
|
if planet == null :
|
|
return false
|
|
var actual_mature_plant_number = 0
|
|
for entity in 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
|