seeding-planets/common/inventory/scripts/items/seed.gd
Zacharie Guet d90d4c5df6 ajout du camion #87
* 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
2025-10-12 19:59:53 +02:00

178 lines
4.4 KiB
GDScript

extends Item
class_name Seed
const MUTATION_PROBABILITY = 0.3
const SHOVEL_ICON = preload("res://common/icons/shovel.svg")
const GROWING_ICON = preload("res://common/icons/chevrons-up.svg")
const SCORE_ICON = preload("res://common/icons/growth.svg")
@export var plant_type: PlantType
@export var plant_mutations: Array[PlantMutation]
func get_item_name() -> String:
return plant_type.name
func get_description() -> String:
return ""
func get_icon() -> Texture2D:
return plant_type.seed_texture
func get_energy_used() -> int:
return 1
func get_usage_zone_radius() -> int:
return 30
func _init(
_plant_type : PlantType = null,
_parent_mutation : Array[PlantMutation] = []
):
plant_type = _plant_type
plant_mutations = Seed.mutate(_parent_mutation)
func use_text() -> String:
return "Plant " + plant_type.name
func is_one_time_use():
return true
func can_use(player : Player, zone : Player.ActionZone) -> bool:
if player.planet == null:
return false
var is_there_a_plant_here = false
for area in zone.area.get_overlapping_areas() :
if area is Plant:
is_there_a_plant_here = true
var is_there_contamination_in_zone = false
for point in zone.get_points_in_zone():
if player.planet.is_there_contamination(point):
is_there_contamination_in_zone = true
return not is_there_a_plant_here and not is_there_contamination_in_zone
func use(player : Player, zone : Player.ActionZone) -> bool:
if player.planet == null:
return false
player.play_sfx("dig")
return player.planet.plant(
plant_type,
zone.get_global_position(),
plant_mutations
)
func inspector_info() -> Inspector.Info:
var info = Inspector.Info.new(
get_item_name(),
get_description(),
get_icon()
)
for m in plant_mutations:
info.framed_infos.append(
PlantMutation.get_framed_info_from_mutation(m)
)
info.framed_infos.append_array(
PlantEffect.get_framed_info_from_all_trigger_effects(
plant_type.default_mature_effects,
plant_type.default_harvest_effects,
plant_type.default_cyclic_effects
)
)
info.stat_infos = [
Inspector.StatInfo.new(
"[b]%d[/b] points when mature" % plant_type.default_plant_score,
SCORE_ICON
),
Inspector.StatInfo.new(
"Grow in [b]%d[/b] days" % plant_type.default_growing_time,
GROWING_ICON
)
]
return info
func get_particles() -> Array[Particles.Parameters]:
var param : Array[Particles.Parameters] = []
for m in plant_mutations:
param.append(
Particles.Parameters.new(
m.get_icon(),
PlantMutation.get_rarity_color(m)
)
)
return param
static func mutate(parent_mutation : Array[PlantMutation] = []) -> Array[PlantMutation]:
if randf() > MUTATION_PROBABILITY:
return parent_mutation
var possible_mutations : Array[MutationPossibility] = [
AddMutation.new()
]
if len(parent_mutation):
possible_mutations.append_array( [
UpgradeMutation.new(),
RemoveMutation.new(),
])
var chosen_mutation = possible_mutations.pick_random()
return chosen_mutation.mutate(parent_mutation)
class MutationPossibility:
func mutate(_parent_mutation : Array[PlantMutation] = [])-> Array[PlantMutation]:
return []
class DontMutate extends MutationPossibility:
func mutate(parent_mutation : Array[PlantMutation] = [])-> Array[PlantMutation]:
return parent_mutation
class AddMutation extends MutationPossibility:
func mutate(parent_mutation : Array[PlantMutation] = [])-> Array[PlantMutation]:
var new_mutations = parent_mutation.duplicate_deep()
var mut = PlantMutation.random_mutation()
if mut:
var existing_mut_id = new_mutations.find_custom(func(m:PlantMutation): m.get_mutation_name() == mut.get_mutation_name())
if existing_mut_id >= 0:
new_mutations[existing_mut_id].level += 1
else :
new_mutations.append(mut)
return new_mutations
class UpgradeMutation extends MutationPossibility:
func mutate(
parent_mutation : Array[PlantMutation] = []
) -> Array[PlantMutation]:
var new_mutations = parent_mutation.duplicate_deep()
new_mutations.pick_random().level += 1
return new_mutations
class RemoveMutation extends MutationPossibility:
func mutate(parent_mutation : Array[PlantMutation] = [])-> Array[PlantMutation]:
var new_mutations :Array[PlantMutation] = parent_mutation.duplicate_deep()
var mut_to_remove = new_mutations.pick_random()
if mut_to_remove.level > 1:
mut_to_remove.level -= 1
else:
new_mutations.remove_at(new_mutations.find(mut_to_remove))
return new_mutations