Files
seeding-planets/entities/plants/scripts/plant_data.gd
Zacharie Guet 83d462f2f4 changement du scene manager, amélioration du cockpit et autres
* refonte du scene manager
* refonte du audio manager
* premier rework des plantes
* nettoyage des dossiers/fichiers
* renommage de planète en region
* fix des run
2026-01-23 18:06:27 +01:00

114 lines
2.8 KiB
GDScript

extends EntityData
class_name PlantData
signal updated(p : PlantData)
signal disappeared(p : PlantData)
enum State {PLANTED, GROWING, MATURE, DEAD}
@export var archetype: PlantArchetype
@export var plant_name : String
@export var mutations : Array[PlantMutation]
@export var day : int :
set(v):
day = v
updated.emit(self)
@export var random_seed : int
@export var leafs = 0 # +1 score
@export var roots = 0 # +1 lifetime
func _init(
_position : Vector2,
_archetype : PlantArchetype,
_plant_name : String = Random.generate_random_name(),
_mutations : Array[PlantMutation] = [],
_day : int = 0,
_random_seed = randi()
):
position = _position
archetype = _archetype
plant_name = _plant_name
mutations = _mutations
day = _day
random_seed = _random_seed
for m in mutations:
m.mutate_plant_data(self)
static func generate_from_seed(plant_seed : Seed, plant_position : Vector2) -> PlantData:
return PlantData.new(
plant_position,
plant_seed.plant_archetype,
plant_seed.plant_name,
plant_seed.plant_mutations
)
func load_entity() -> Entity:
var plant = Plant.new(
self
)
return plant
func get_lifetime() -> int:
var lifetime = archetype.lifetime + roots
for m in mutations:
lifetime = m.mutate_lifetime(self, lifetime)
return lifetime
func get_growing_time() -> int:
var growing_time = archetype.growing_time
for m in mutations:
growing_time = m.mutate_growing_time(self, growing_time)
return growing_time
func get_score(state : State = get_state()) -> int:
var score = archetype.base_score + leafs if state == State.MATURE else 0
for m in mutations:
score = m.mutate_score(self, score)
return score
func get_state() -> State:
if day >= get_lifetime():
return State.DEAD
elif day == 0:
return State.PLANTED
elif day < archetype.growing_time:
return State.GROWING
return State.MATURE
func get_plant_texture() -> Texture:
return archetype.texture_builder.build_plant_texture(self)
func get_seed_texture():
return archetype.texture_builder.build_seed_texture(random_seed)
func get_seed_number(state = get_state()):
var seed_number = archetype.seed_number if state == State.MATURE else 0
for m in mutations:
seed_number = m.mutate_seed_number(self, seed_number)
return seed_number
func get_seed_random_loose():
var seed_random_loose = archetype.seed_random_loose
for m in mutations:
seed_random_loose = m.mutate_seed_random_loose(self, seed_random_loose)
return seed_random_loose
func get_random_seed_income():
return max(
get_seed_number() - randi_range(0, get_seed_random_loose()),
0
)
func disappear():
disappeared.emit(self)