ajout des mutation et refonte de l'inspecteur
* ajout des mutations #86 * changement de l'objectif #85 * refonte de l'inspecteur #71 * changement léger de la plantation * les plantes ne donnent que des graines de leurs espèces * refonte partielle du code, refacto
This commit is contained in:
@@ -25,11 +25,21 @@ func get_usage_zone_radius() -> int:
|
||||
func is_one_time_use():
|
||||
return false
|
||||
|
||||
func can_use(_player : Player, zone: Area2D) -> bool:
|
||||
func can_use(_player : Player, zone: Player.ActionZone) -> bool:
|
||||
return false
|
||||
|
||||
func use_text() -> String:
|
||||
return ""
|
||||
|
||||
func use(_player : Player, zone: Area2D):
|
||||
func use(_player : Player, zone: Player.ActionZone):
|
||||
return false
|
||||
|
||||
func inspector_info() -> Inspector.Info:
|
||||
return Inspector.Info.new(
|
||||
get_item_name(),
|
||||
get_description(),
|
||||
get_icon()
|
||||
)
|
||||
|
||||
func get_particles() -> Array[Particles.Parameters]:
|
||||
return []
|
||||
@@ -29,11 +29,11 @@ func use_text() -> String:
|
||||
func is_one_time_use():
|
||||
return true
|
||||
|
||||
func can_use(player : Player, zone : Area2D) -> bool:
|
||||
return player.planet.is_in_base(zone.global_position)
|
||||
func can_use(player : Player, zone : Player.ActionZone) -> bool:
|
||||
return player.planet.is_in_base(zone.get_global_position())
|
||||
|
||||
func use(player : Player, zone : Area2D) -> bool:
|
||||
func use(player : Player, zone : Player.ActionZone) -> bool:
|
||||
if machine_type and machine_level:
|
||||
player.planet.instantiate_machine(machine_type, machine_level, zone.global_position)
|
||||
player.planet.instantiate_machine(machine_type, machine_level, zone.get_global_position())
|
||||
return true
|
||||
return false
|
||||
|
||||
@@ -24,9 +24,9 @@ func use_text() -> String:
|
||||
func is_one_time_use():
|
||||
return true
|
||||
|
||||
func can_use(player : Player, zone : Area2D) -> bool:
|
||||
func can_use(player : Player, zone : Player.ActionZone) -> bool:
|
||||
return true
|
||||
|
||||
func use(player : Player, zone : Area2D) -> bool:
|
||||
player.planet.instantiate_entity(scene, zone.global_position)
|
||||
func use(player : Player, zone : Player.ActionZone) -> bool:
|
||||
player.planet.instantiate_entity(scene, zone.get_global_position())
|
||||
return true
|
||||
|
||||
@@ -1,13 +1,20 @@
|
||||
extends Item
|
||||
class_name Seed
|
||||
|
||||
const MUTATION_PROBABILITY = 0.2
|
||||
|
||||
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 plant_type.description
|
||||
return ""
|
||||
|
||||
func get_icon() -> Texture2D:
|
||||
return plant_type.seed_texture
|
||||
@@ -15,8 +22,15 @@ func get_icon() -> Texture2D:
|
||||
func get_energy_used() -> int:
|
||||
return 1
|
||||
|
||||
func _init(_plant_type : PlantType = null):
|
||||
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
|
||||
@@ -24,14 +38,134 @@ func use_text() -> String:
|
||||
func is_one_time_use():
|
||||
return true
|
||||
|
||||
func can_use(player : Player, zone : Area2D) -> bool:
|
||||
func can_use(player : Player, zone : Player.ActionZone) -> bool:
|
||||
var is_there_a_plant_here = false
|
||||
for area in zone.get_overlapping_areas() :
|
||||
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 player.planet.is_there_contamination(zone.global_position)
|
||||
return not is_there_a_plant_here and not is_there_contamination_in_zone
|
||||
|
||||
func use(player : Player, zone : Area2D) -> bool:
|
||||
func use(player : Player, zone : Player.ActionZone) -> bool:
|
||||
player.play_sfx("dig")
|
||||
return player.planet.plant(plant_type, zone.global_position)
|
||||
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
|
||||
|
||||
@@ -2,7 +2,7 @@ extends Item
|
||||
class_name Shovel
|
||||
|
||||
const USE_INTERVAL = 0.15
|
||||
const SHOVEL_ZONE_RADIUS = 50
|
||||
const SHOVEL_ZONE_RADIUS = 30
|
||||
|
||||
func get_item_name() -> String:
|
||||
return "Shovel"
|
||||
@@ -22,16 +22,16 @@ func get_usage_zone_radius() -> int:
|
||||
func use_text() -> String:
|
||||
return "Dig"
|
||||
|
||||
func can_use(_player : Player, zone : Area2D) -> bool:
|
||||
var areas = zone.get_overlapping_areas()
|
||||
func can_use(_player : Player, zone : Player.ActionZone) -> bool:
|
||||
var areas = zone.area.get_overlapping_areas()
|
||||
for area in areas :
|
||||
if area is Plant or area is UndergroundLoot:
|
||||
return true
|
||||
return false
|
||||
|
||||
func use(player : Player, zone : Area2D) -> bool:
|
||||
func use(player : Player, zone : Player.ActionZone) -> bool:
|
||||
dig(
|
||||
zone.get_overlapping_areas(),
|
||||
zone.area.get_overlapping_areas(),
|
||||
player
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user