* ajout d'une aide de jeu directement dans l'interface * ajout de 8 nouvelles mutations (Productif, pressé, pur, vivace, généreux, robuste, protecteur et prolifique) * changements d'icône pour plus de clarté * changement de l'animation de recharge pour montrer le temps qui passe * ajout des mutations rare et de la possibilité d'avoir des mutation niveau 2 dès le départ * ajout d'un zoom * correction de bugs (déplacement au dialogue, problème de score au load d'une région)
154 lines
3.7 KiB
GDScript
154 lines
3.7 KiB
GDScript
extends EntityData
|
|
class_name PlantData
|
|
|
|
signal updated(p: PlantData)
|
|
signal disappeared(p: PlantData)
|
|
signal nearby_plant_updated()
|
|
|
|
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
|
|
|
|
# var texture_builder: TextureBuilder = preload("res://entities/plants/scripts/texture_builder/texture_builder.tres")
|
|
|
|
var decontamination_area_factor = 0.
|
|
var nearby_plants : Array[PlantData]
|
|
|
|
func _init(
|
|
_position: Vector2 = Vector2.ZERO,
|
|
_archetype: PlantArchetype = PlantArchetype.get_random(),
|
|
_plant_name: String = Random.generate_random_word(),
|
|
_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)
|
|
|
|
for pd in nearby_plants:
|
|
lifetime += pd.get_lifetime_buff()
|
|
|
|
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
|
|
|
|
var mult := 1
|
|
|
|
for m in mutations:
|
|
score = m.mutate_score(self , score)
|
|
mult = m.mutate_score_multiplier(self , mult)
|
|
|
|
for pd in nearby_plants:
|
|
score += pd.get_score_buff()
|
|
|
|
return max(0,score) * mult
|
|
|
|
func get_state() -> State:
|
|
if day >= get_lifetime():
|
|
return State.DEAD
|
|
elif day == 0:
|
|
return State.PLANTED
|
|
elif day < get_growing_time():
|
|
return State.GROWING
|
|
return State.MATURE
|
|
|
|
func is_mature() -> bool:
|
|
return get_state() == State.MATURE
|
|
|
|
func get_seed_number(state = get_state()):
|
|
var seed_number = archetype.seed_number if (state == State.MATURE or state == State.DEAD) else 0
|
|
|
|
for m in mutations:
|
|
seed_number = m.mutate_seed_number(self , seed_number)
|
|
|
|
for pd in nearby_plants:
|
|
seed_number += pd.get_seed_buff()
|
|
|
|
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 get_lifetime_buff() -> int:
|
|
var buff = 0
|
|
|
|
for m in mutations:
|
|
buff = m.mutate_lifetime_buff(self, buff)
|
|
|
|
return buff
|
|
|
|
func get_seed_buff() -> int:
|
|
var buff = 0
|
|
|
|
for m in mutations:
|
|
buff = m.mutate_seed_buff(self, buff)
|
|
|
|
return buff
|
|
|
|
func get_score_buff() -> int:
|
|
var buff = 0
|
|
|
|
for m in mutations:
|
|
buff = m.mutate_score_buff(self, buff)
|
|
|
|
return buff
|
|
|
|
func disappear():
|
|
disappeared.emit(self )
|