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:
2025-10-12 01:03:08 +02:00
parent bb24efe46b
commit ef392595de
108 changed files with 1921 additions and 477 deletions

View File

@@ -1,11 +1,9 @@
[gd_scene load_steps=10 format=3 uid="uid://2hrg6yjk0yt0"]
[gd_scene load_steps=9 format=3 uid="uid://2hrg6yjk0yt0"]
[ext_resource type="Script" uid="uid://bmjjpk4lvijws" path="res://entities/plants/scripts/plant_sprite.gd" id="1_pq8o7"]
[ext_resource type="Texture2D" uid="uid://pltmnkqd5ut2" path="res://entities/plants/assets/sprites/seeds/grille_seeds.png" id="3_j6jm5"]
[ext_resource type="Texture2D" uid="uid://bu26h0iqutnky" path="res://entities/underground_loot/assets/sprites/underground_loot.svg" id="4_j6jm5"]
[sub_resource type="CompressedTexture2D" id="CompressedTexture2D_rbgiq"]
[sub_resource type="AtlasTexture" id="AtlasTexture_wyuub"]
atlas = ExtResource("3_j6jm5")
region = Rect2(76, 75, 124, 135)
@@ -106,7 +104,7 @@ script = ExtResource("1_pq8o7")
[node name="Sprite" type="Sprite2D" parent="."]
unique_name_in_owner = true
scale = Vector2(0.15, 0.15)
texture = SubResource("CompressedTexture2D_rbgiq")
offset = Vector2(0, -151.56)
[node name="PlantedSeed" type="Sprite2D" parent="Sprite"]
unique_name_in_owner = true

View File

@@ -0,0 +1,7 @@
[gd_resource type="Resource" script_class="AncientMutation" load_steps=2 format=3 uid="uid://dys1ehlg4kwh7"]
[ext_resource type="Script" uid="uid://c7po0bstyg80u" path="res://entities/plants/scripts/plant_mutation/ancient_mutation.gd" id="1_5g2qg"]
[resource]
script = ExtResource("1_5g2qg")
metadata/_custom_type_script = "uid://c7po0bstyg80u"

View File

@@ -0,0 +1,6 @@
[gd_resource type="Resource" script_class="ElitistMutation" load_steps=2 format=3 uid="uid://d38alhstybdtf"]
[ext_resource type="Script" uid="uid://bt1xh7ss13e5e" path="res://entities/plants/scripts/plant_mutation/elitist_mutation.gd" id="1_jevqj"]
[resource]
script = ExtResource("1_jevqj")

View File

@@ -0,0 +1,6 @@
[gd_resource type="Resource" script_class="ErmitMutation" load_steps=2 format=3 uid="uid://dktlbpira5kxb"]
[ext_resource type="Script" uid="uid://domy822vgxfxs" path="res://entities/plants/scripts/plant_mutation/ermit_mutation.gd" id="1_yqhf5"]
[resource]
script = ExtResource("1_yqhf5")

View File

@@ -0,0 +1,7 @@
[gd_resource type="Resource" script_class="PrecociousMutation" load_steps=2 format=3 uid="uid://c3am7s5bjy8qk"]
[ext_resource type="Script" uid="uid://cx5mg5vf62bia" path="res://entities/plants/scripts/plant_mutation/precocious_mutation.gd" id="1_wjcm0"]
[resource]
script = ExtResource("1_wjcm0")
metadata/_custom_type_script = "uid://cx5mg5vf62bia"

View File

@@ -0,0 +1,7 @@
[gd_resource type="Resource" script_class="QualityMutation" load_steps=2 format=3 uid="uid://uabbkvg1rciq"]
[ext_resource type="Script" uid="uid://bdobyk2j625lb" path="res://entities/plants/scripts/plant_mutation/quality_mutation.gd" id="1_u0ku1"]
[resource]
script = ExtResource("1_u0ku1")
metadata/_custom_type_script = "uid://bdobyk2j625lb"

View File

@@ -0,0 +1,7 @@
[gd_resource type="Resource" script_class="QuickMutation" load_steps=2 format=3 uid="uid://b04gaipu237sx"]
[ext_resource type="Script" uid="uid://bhtq0cbrgu58v" path="res://entities/plants/scripts/plant_mutation/quick_mutation.gd" id="1_hr7tm"]
[resource]
script = ExtResource("1_hr7tm")
metadata/_custom_type_script = "uid://bhtq0cbrgu58v"

View File

@@ -0,0 +1,7 @@
[gd_resource type="Resource" script_class="SociableMutation" load_steps=2 format=3 uid="uid://bpkvdvael2ojh"]
[ext_resource type="Script" uid="uid://b8q5xgvy85qeb" path="res://entities/plants/scripts/plant_mutation/sociable_mutation.gd" id="1_7u0mw"]
[resource]
script = ExtResource("1_7u0mw")
metadata/_custom_type_script = "uid://b8q5xgvy85qeb"

View File

@@ -0,0 +1,7 @@
[gd_resource type="Resource" script_class="StrongMutation" load_steps=2 format=3 uid="uid://co2r0jnkf8hyb"]
[ext_resource type="Script" uid="uid://cwj3k4p6ci5t4" path="res://entities/plants/scripts/plant_mutation/strong_mutation.gd" id="1_c0ieg"]
[resource]
script = ExtResource("1_c0ieg")
metadata/_custom_type_script = "uid://cwj3k4p6ci5t4"

View File

@@ -1,15 +1,18 @@
[gd_resource type="Resource" script_class="PlantType" load_steps=8 format=3 uid="uid://cxrc5wchpqm18"]
[gd_resource type="Resource" script_class="PlantType" load_steps=10 format=3 uid="uid://cxrc5wchpqm18"]
[ext_resource type="Script" uid="uid://ceqx5va1ormau" path="res://entities/plants/scripts/plant_effects/produce_seeds.gd" id="1_cf34j"]
[ext_resource type="Script" uid="uid://jnye5pe1bgqw" path="res://entities/plants/scripts/plant_type.gd" id="1_ipcpv"]
[ext_resource type="Script" uid="uid://bpycohqas4hff" path="res://entities/plants/scripts/plant_effect.gd" id="1_l2hi3"]
[ext_resource type="Texture2D" uid="uid://dmsls8siudy1u" path="res://entities/plants/assets/sprites/champ/growing.png" id="2_l2hi3"]
[ext_resource type="Texture2D" uid="uid://crc4aop6ajiau" path="res://entities/plants/assets/sprites/champ/mature.png" id="3_y8qve"]
[ext_resource type="Texture2D" uid="uid://pltmnkqd5ut2" path="res://entities/plants/assets/sprites/seeds/grille_seeds.png" id="6_liopn"]
[sub_resource type="Resource" id="Resource_5hyy8"]
[sub_resource type="Resource" id="Resource_l2hi3"]
script = ExtResource("1_cf34j")
metadata/_custom_type_script = "uid://ceqx5va1ormau"
[sub_resource type="Resource" id="Resource_cf34j"]
script = ExtResource("1_cf34j")
produce_types_path = Array[String](["uid://cxrc5wchpqm18", "uid://b04vho33bl52b", "uid://dsctivn1vrem2", "uid://c5oxxif3h5yxo"])
produce_number = Array[int]([1, 0])
metadata/_custom_type_script = "uid://ceqx5va1ormau"
[sub_resource type="AtlasTexture" id="AtlasTexture_my6by"]
@@ -19,11 +22,11 @@ region = Rect2(610, 315, 124, 180)
[resource]
script = ExtResource("1_ipcpv")
name = "Champ"
description = "When mature, can produce one seed every day."
growing_time = 1
description = "A cool fluorescent plant. Some say that it has a big network of roots underground."
default_growing_time = 3
seed_texture = SubResource("AtlasTexture_my6by")
growing_texture = ExtResource("2_l2hi3")
mature_texture = ExtResource("3_y8qve")
cyclic_effect = SubResource("Resource_5hyy8")
harvest_types_path = Array[String](["uid://cxrc5wchpqm18"])
default_harvest_effects = Array[ExtResource("1_l2hi3")]([SubResource("Resource_cf34j"), null])
default_cyclic_effects = Array[ExtResource("1_l2hi3")]([SubResource("Resource_l2hi3")])
metadata/_custom_type_script = "uid://jnye5pe1bgqw"

View File

@@ -1,14 +1,20 @@
[gd_resource type="Resource" script_class="PlantType" load_steps=8 format=3 uid="uid://b04vho33bl52b"]
[gd_resource type="Resource" script_class="PlantType" load_steps=11 format=3 uid="uid://b04vho33bl52b"]
[ext_resource type="Script" uid="uid://bpycohqas4hff" path="res://entities/plants/scripts/plant_effect.gd" id="1_40c3e"]
[ext_resource type="Script" uid="uid://jnye5pe1bgqw" path="res://entities/plants/scripts/plant_type.gd" id="1_moyj3"]
[ext_resource type="Texture2D" uid="uid://c7mp7tkkkk6o5" path="res://entities/plants/assets/sprites/chardi/growing.png" id="1_prk5s"]
[ext_resource type="Script" uid="uid://cgscbuxe4dawb" path="res://entities/plants/scripts/plant_effects/decontaminate_terrain_effect.gd" id="2_cky1j"]
[ext_resource type="Script" uid="uid://ceqx5va1ormau" path="res://entities/plants/scripts/plant_effects/produce_seeds.gd" id="2_prk5s"]
[ext_resource type="Texture2D" uid="uid://bupl1y0cfj21q" path="res://entities/plants/assets/sprites/chardi/mature.png" id="3_40c3e"]
[ext_resource type="Script" uid="uid://cgscbuxe4dawb" path="res://entities/plants/scripts/plant_effects/decontaminate_terrain_effect.gd" id="3_ajihu"]
[ext_resource type="Texture2D" uid="uid://pltmnkqd5ut2" path="res://entities/plants/assets/sprites/seeds/grille_seeds.png" id="6_cky1j"]
[sub_resource type="Resource" id="Resource_c76qk"]
script = ExtResource("2_cky1j")
improve_by_lifetime_max = 300
[sub_resource type="Resource" id="Resource_40c3e"]
script = ExtResource("2_prk5s")
metadata/_custom_type_script = "uid://ceqx5va1ormau"
[sub_resource type="Resource" id="Resource_k7yib"]
script = ExtResource("3_ajihu")
level = 1
metadata/_custom_type_script = "uid://cgscbuxe4dawb"
[sub_resource type="AtlasTexture" id="AtlasTexture_qt76e"]
@@ -19,11 +25,9 @@ region = Rect2(1140, 345, 141, 128)
script = ExtResource("1_moyj3")
name = "Chardi"
description = "This plant remove a lot of contamination around when it becomes mature."
growing_time = 1
seed_texture = SubResource("AtlasTexture_qt76e")
growing_texture = ExtResource("1_prk5s")
mature_texture = ExtResource("3_40c3e")
mature_effect = SubResource("Resource_c76qk")
harvest_types_path = Array[String](["uid://b04vho33bl52b"])
harvest_number = Array[int]([1, 2, 1])
default_harvest_effects = Array[ExtResource("1_40c3e")]([SubResource("Resource_40c3e")])
default_mature_effects = Array[ExtResource("1_40c3e")]([SubResource("Resource_k7yib")])
metadata/_custom_type_script = "uid://jnye5pe1bgqw"

View File

@@ -1,15 +1,16 @@
[gd_resource type="Resource" script_class="PlantType" load_steps=8 format=3 uid="uid://dsctivn1vrem2"]
[gd_resource type="Resource" script_class="PlantType" load_steps=9 format=3 uid="uid://dsctivn1vrem2"]
[ext_resource type="Script" uid="uid://bpycohqas4hff" path="res://entities/plants/scripts/plant_effect.gd" id="1_740j2"]
[ext_resource type="Script" uid="uid://jnye5pe1bgqw" path="res://entities/plants/scripts/plant_type.gd" id="1_eqtut"]
[ext_resource type="Texture2D" uid="uid://dwr3c6r6piwaa" path="res://entities/plants/assets/sprites/maias/growing.png" id="1_vyplc"]
[ext_resource type="Script" uid="uid://cgscbuxe4dawb" path="res://entities/plants/scripts/plant_effects/decontaminate_terrain_effect.gd" id="2_vyplc"]
[ext_resource type="Script" uid="uid://ceqx5va1ormau" path="res://entities/plants/scripts/plant_effects/produce_seeds.gd" id="2_740j2"]
[ext_resource type="Texture2D" uid="uid://d3apfwbqsg5ha" path="res://entities/plants/assets/sprites/maias/mature.png" id="3_pi4ie"]
[ext_resource type="Texture2D" uid="uid://pltmnkqd5ut2" path="res://entities/plants/assets/sprites/seeds/grille_seeds.png" id="6_mwrj8"]
[sub_resource type="Resource" id="Resource_q4pje"]
script = ExtResource("2_vyplc")
impact_radius = 20
metadata/_custom_type_script = "uid://cgscbuxe4dawb"
[sub_resource type="Resource" id="Resource_1llfc"]
script = ExtResource("2_740j2")
level = 2
metadata/_custom_type_script = "uid://ceqx5va1ormau"
[sub_resource type="AtlasTexture" id="AtlasTexture_sri3b"]
atlas = ExtResource("6_mwrj8")
@@ -18,12 +19,9 @@ region = Rect2(1697, 331, 125, 158)
[resource]
script = ExtResource("1_eqtut")
name = "Maias"
description = "This gorgeous flower produce a lot of seeds of Maias and Chardi when harvested."
growing_time = 1
description = "This gorgeous flower produce a lot of seeds when harvested."
seed_texture = SubResource("AtlasTexture_sri3b")
growing_texture = ExtResource("1_vyplc")
mature_texture = ExtResource("3_pi4ie")
mature_effect = SubResource("Resource_q4pje")
harvest_types_path = Array[String](["uid://b04vho33bl52b", "uid://dsctivn1vrem2"])
harvest_number = Array[int]([3, 4])
default_harvest_effects = Array[ExtResource("1_740j2")]([SubResource("Resource_1llfc")])
metadata/_custom_type_script = "uid://jnye5pe1bgqw"

View File

@@ -1,18 +1,22 @@
[gd_resource type="Resource" script_class="PlantType" load_steps=8 format=3 uid="uid://c5oxxif3h5yxo"]
[gd_resource type="Resource" script_class="PlantType" load_steps=11 format=3 uid="uid://c5oxxif3h5yxo"]
[ext_resource type="Script" uid="uid://cgscbuxe4dawb" path="res://entities/plants/scripts/plant_effects/decontaminate_terrain_effect.gd" id="1_8wi4i"]
[ext_resource type="Script" uid="uid://bpycohqas4hff" path="res://entities/plants/scripts/plant_effect.gd" id="1_8fstu"]
[ext_resource type="Script" uid="uid://jnye5pe1bgqw" path="res://entities/plants/scripts/plant_type.gd" id="1_vn146"]
[ext_resource type="Script" uid="uid://cgscbuxe4dawb" path="res://entities/plants/scripts/plant_effects/decontaminate_terrain_effect.gd" id="2_8fstu"]
[ext_resource type="Texture2D" uid="uid://xw47qw12d3dv" path="res://entities/plants/assets/sprites/pili/growing.png" id="2_k4b1k"]
[ext_resource type="Texture2D" uid="uid://4mh1w1f4q2sa" path="res://entities/plants/assets/sprites/pili/mature.png" id="3_8fstu"]
[ext_resource type="Script" uid="uid://ceqx5va1ormau" path="res://entities/plants/scripts/plant_effects/produce_seeds.gd" id="3_26e4l"]
[ext_resource type="Texture2D" uid="uid://pltmnkqd5ut2" path="res://entities/plants/assets/sprites/seeds/grille_seeds.png" id="5_26e4l"]
[sub_resource type="Resource" id="Resource_eytxu"]
script = ExtResource("1_8wi4i")
impact_radius = 50
improve_by_lifetime = true
improve_by_lifetime_value = 50
script = ExtResource("2_8fstu")
level = 2
metadata/_custom_type_script = "uid://cgscbuxe4dawb"
[sub_resource type="Resource" id="Resource_kidty"]
script = ExtResource("3_26e4l")
metadata/_custom_type_script = "uid://ceqx5va1ormau"
[sub_resource type="AtlasTexture" id="AtlasTexture_kidty"]
atlas = ExtResource("5_26e4l")
region = Rect2(1415, 91, 149, 102)
@@ -21,10 +25,11 @@ region = Rect2(1415, 91, 149, 102)
script = ExtResource("1_vn146")
name = "Pili"
description = "Pili slowly decontaminate each day when mature. Effect end in four days."
growing_time = 1
default_growing_time = 4
default_plant_score = 2
seed_texture = SubResource("AtlasTexture_kidty")
growing_texture = ExtResource("2_k4b1k")
mature_texture = ExtResource("3_8fstu")
cyclic_effect = SubResource("Resource_eytxu")
harvest_types_path = Array[String](["uid://c5oxxif3h5yxo"])
default_harvest_effects = Array[ExtResource("1_8fstu")]([SubResource("Resource_kidty"), null])
default_cyclic_effects = Array[ExtResource("1_8fstu")]([SubResource("Resource_eytxu")])
metadata/_custom_type_script = "uid://jnye5pe1bgqw"

View File

@@ -1,10 +1,15 @@
extends InspectableEntity
class_name Plant
const PLANT_AREA_WIDTH = 20
const PLANT_AREA_RADIUS = 20
const PLANT_INFLUENCE_RADIUS = 100
const HARVESTED_SEED_DISPLACEMENT_FACTOR = 100
const RANDOM_MAX_GROW_INTERVAL = Planet.PASS_DAY_ANIMATION_TIME/2. - 0.1
const PLANT_POINT_ICON = preload("res://common/icons/growth.svg")
const LIFETIME_ICON = preload("res://common/icons/calendar-week.svg")
const SHOVEL_ICON = preload("res://common/icons/shovel.svg")
const GROWING_ICON = preload("res://common/icons/chevrons-up.svg")
const SPRITE_SCENE : PackedScene = preload("res://entities/plants/plant_sprite.tscn")
@@ -18,82 +23,167 @@ var state: State = State.PLANTED: set = change_state
@onready var plant_sprite: PlantSprite = generate_sprite()
@onready var collision_shape: CollisionShape2D = generate_collision_shape()
@onready var influence_zone : PlantInfluenceZone = generate_influence_zone()
func _init(_plant_type = null, _planet = null):
var harvest_effects = []
var mature_effects = []
var cyclic_effects = []
var plant_score = 0
var plant_mutations : Array[PlantMutation] = []
func _init(
_plant_type : PlantType,
_planet : Planet,
_plant_mutations : Array[PlantMutation] = []
):
plant_type = _plant_type
harvest_effects = plant_type.default_harvest_effects.duplicate_deep()
mature_effects = plant_type.default_mature_effects.duplicate_deep()
cyclic_effects = plant_type.default_cyclic_effects.duplicate_deep()
planet = _planet
plant_mutations = _plant_mutations
func pointer_text():
var state_text = "Growing"
if state == State.MATURE: state_text = "Mature"
return state_text + " " + plant_type.name
func inspect(is_inspected : bool = true):
modulate = MODULATE_INSPECTED_COLOR if is_inspected else default_modulate
influence_zone.show_influence = is_inspected
func inspector_info() -> Inspector.Info:
return Inspector.Info.new(
var info = Inspector.Info.new(
pointer_text(),
plant_type.description,
"",
plant_type.mature_texture
)
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(
mature_effects, harvest_effects, cyclic_effects
)
)
info.stat_infos.append(
Inspector.StatInfo.new(
"Day [b]%d[/b]" % day,
LIFETIME_ICON
)
)
if state != State.MATURE:
info.stat_infos.append_array([
Inspector.StatInfo.new(
"Mature on day [b]%d[/b]" % calculate_grow_time(),
GROWING_ICON,
),
Inspector.StatInfo.new(
"[b]%d[/b]" % [
calculate_plant_score()
],
PLANT_POINT_ICON
),
])
else:
info.stat_infos.append(
Inspector.StatInfo.new(
"[b]%d[/b] point%s" % [
calculate_plant_score(),
"s" if calculate_plant_score() > 0 else ""
],
PLANT_POINT_ICON
),
)
return info
func generate_sprite() -> PlantSprite:
var spriteObject : PlantSprite = SPRITE_SCENE.instantiate()
var sprite_object : PlantSprite = SPRITE_SCENE.instantiate()
add_child(spriteObject)
spriteObject.update_plant_sprite(self)
add_child(sprite_object)
sprite_object.update_plant_sprite(self)
sprite_object.generate_mutation_effects(self)
return spriteObject
return sprite_object
func generate_collision_shape() -> CollisionShape2D:
var collision = CollisionShape2D.new()
var shape = CircleShape2D.new()
shape.radius = PLANT_AREA_WIDTH
shape.radius = PLANT_AREA_RADIUS
collision.shape = shape
add_child(collision)
return collision
func generate_influence_zone() -> PlantInfluenceZone:
var zone = PlantInfluenceZone.new(PLANT_INFLUENCE_RADIUS)
add_child(zone)
return zone
# Méthode déclenchée par la classe planet
func _pass_day():
await get_tree().create_timer(randf_range(0., RANDOM_MAX_GROW_INTERVAL)).timeout
if state == State.MATURE and plant_type.cyclic_effect:
plant_type.cyclic_effect.effect(self)
if state == State.MATURE and len(cyclic_effects):
for effect in cyclic_effects:
effect.effect(self)
day += 1
func set_day(d):
day = d
if day == 0:
change_state(State.PLANTED)
if day > plant_type.growing_time:
if day + 1 > calculate_grow_time():
if state != State.MATURE:
change_state(State.MATURE)
elif day == 0:
change_state(State.PLANTED)
else:
if state != State.GROWING:
change_state(State.GROWING)
func calculate_plant_score() -> int:
var mutated_plant_score = plant_type.default_plant_score if state == State.MATURE else 0
for m in plant_mutations:
mutated_plant_score = m.mutate_score(self, mutated_plant_score)
return mutated_plant_score
func calculate_grow_time() -> int:
var mutated_grow_time = plant_type.default_growing_time
for m in plant_mutations:
mutated_grow_time = m.mutate_grow_time(self, mutated_grow_time)
return mutated_grow_time
func change_state(_state: State):
state = _state
if state == State.MATURE and plant_type.mature_effect:
plant_type.mature_effect.effect(self)
if state == State.MATURE and len(mature_effects):
for effect in mature_effects:
if effect : effect.effect(self)
for effect in cyclic_effects:
if effect : effect.effect(self)
plant_sprite.update_plant_sprite(self, true)
func harvest():
if state == State.MATURE:
var seed_number = plant_type.harvest_number.pick_random()
for i in range(seed_number):
var seed_plant_type : PlantType = plant_type
if len(plant_type.harvest_types_path):
seed_plant_type = load(plant_type.harvest_types_path.pick_random())
planet.drop_item(
Seed.new(seed_plant_type),
global_position,
HARVESTED_SEED_DISPLACEMENT_FACTOR,
)
for effect in harvest_effects:
if effect : effect.effect(self)
plant_sprite.start_harvest_animation()
await plant_sprite.harvest_animation_finished
queue_free()

View File

@@ -2,6 +2,87 @@
extends Resource
class_name PlantEffect
func effect(plant):
printerr("Classe abstraite PlantEffect appelée")
const HARVEST_EFFECT_ICON = preload("res://common/icons/shovel.svg")
const MATURE_EFFECT_ICON = preload("res://common/icons/chevrons-up.svg")
const CYCLIC_EFFECT_ICON = preload("res://common/icons/rotate-rectangle.svg")
@export var level : int
func _init(_level : int = 1):
level = _level
func get_effect_name() -> String:
printerr("Classe abstraite PlantEffect appelée")
return ""
func get_effect_description() -> String:
printerr("Classe abstraite PlantEffect appelée")
return ""
func effect(plant):
printerr("Classe abstraite PlantEffect appelée")
static func get_framed_info_from_effects(
effects : Array[PlantEffect],
trigger_text = "",
trigger_icon: Texture = null
) -> Array[Inspector.FramedInfo]:
if len(effects) == 0 : return []
var desc = "%s %s" % [PlantEffect.get_framed_info_effect_name(effects[0]), effects[0].get_effect_description()]
for i in range(1, len(effects)):
if effects[i]:
desc += "\n%s %s" % [PlantEffect.get_framed_info_effect_name(effects[i]), effects[i].get_effect_description()]
return [Inspector.FramedInfo.new(
trigger_text,
desc,
trigger_icon
)]
static func get_framed_info_effect_name(e : PlantEffect):
var levels_bbcode = [
"[color=#ffffff][b]%s[/b][/color]",
"[color=#FFBE0B][b]%s %d[/b][/color]",
"[color=#FB5607][b]%s %d[/b][/color]",
"[color=#3A86FF][b]%s %d[/b][/color]",
"[color=#8338EC][b]%s %d[/b][/color]",
"[color=#FF006E][b]%s %d[/b][/color]",
"[rainbow][b]%s %d[/b][/rainbow]"
]
if e.level == 1:
return levels_bbcode[0] % e.get_effect_name()
else :
return levels_bbcode[min(e.level - 1, len(levels_bbcode) - 1)] % [e.get_effect_name(), e.level]
static func get_framed_info_from_all_trigger_effects(
mature_effects : Array[PlantEffect],
harvest_effects : Array[PlantEffect],
cyclic_effects : Array[PlantEffect],
) -> Array[Inspector.FramedInfo] :
var framed_infos : Array[Inspector.FramedInfo] = []
framed_infos.append_array(
PlantEffect.get_framed_info_from_effects(
mature_effects,
"On maturation",
MATURE_EFFECT_ICON
)
)
framed_infos.append_array(
PlantEffect.get_framed_info_from_effects(
harvest_effects,
"When harvested",
HARVEST_EFFECT_ICON
)
)
framed_infos.append_array(
PlantEffect.get_framed_info_from_effects(
cyclic_effects,
"Each days",
CYCLIC_EFFECT_ICON
)
)
return framed_infos

View File

@@ -1,17 +1,18 @@
extends PlantEffect
class_name DecontaminateTerrainEffect
@export var impact_radius = 100
@export var improve_by_lifetime := false
@export var improve_by_lifetime_value := 20
@export var improve_by_lifetime_max := 200
func get_decontamination_radius():
return 100 * level
func get_effect_name() -> String:
return "Decontaminate"
func get_effect_description() -> String:
var ret = "Decontaminate %d unit around it" % [get_decontamination_radius()]
return ret
func effect(plant):
var radius = impact_radius
if improve_by_lifetime:
radius = min(radius + improve_by_lifetime_value * plant.day, improve_by_lifetime_max)
var radius = get_decontamination_radius()
plant.planet.impact_contamination(
plant.global_position,

View File

@@ -1,15 +1,29 @@
extends PlantEffect
class_name ProduceSeedsEffect
@export_file var produce_types_path : Array[String] = []
@export var produce_number : Array[int] = [1]
func get_produce_number():
return [level - 1, level, level + 1]
func get_effect_name() -> String:
return "Seed Production"
func get_effect_description() -> String:
var number_str = ""
for i in range(len(get_produce_number())):
if i != 0:
if i == len(get_produce_number()) - 1:
number_str += " or "
else :
number_str += ", "
number_str += str(get_produce_number()[i])
return "Produce %s seeds" % [number_str]
func effect(plant):
for _i in range(produce_number.pick_random()):
if len(produce_types_path):
var seed_plant_type = load(produce_types_path.pick_random())
plant.planet.drop_item(
Seed.new(seed_plant_type),
plant.global_position,
plant.HARVESTED_SEED_DISPLACEMENT_FACTOR,
)
for _i in range(get_produce_number().pick_random()):
plant.planet.drop_item(
Seed.new(plant.plant_type, plant.plant_mutations),
plant.global_position,
plant.HARVESTED_SEED_DISPLACEMENT_FACTOR,
)

View File

@@ -0,0 +1,31 @@
extends Area2D
class_name PlantInfluenceZone
var radius : int
var sprite : Circle
var collision_shape : CollisionShape2D
var show_influence : bool = false :
set(v):
show_influence = v
if sprite:
sprite.visible = v
print(sprite.visible)
func _init(_radius = 100):
radius = _radius
func _ready():
sprite = Circle.new()
# sprite.z_index = 100
sprite.radius = 100
sprite.fill = false
sprite.width = 1
sprite.opacity = 0.2
sprite.visible = show_influence
add_child(sprite)
collision_shape = CollisionShape2D.new()
var circle_shape : CircleShape2D = CircleShape2D.new()
circle_shape.radius = radius
collision_shape.shape = circle_shape
add_child(collision_shape)

View File

@@ -0,0 +1 @@
uid://cmm3ar0ikkvkb

View File

@@ -0,0 +1,111 @@
extends Resource
class_name PlantMutation
const BASE_RARITY_CHANCE : Array[float] = [
0.6,
0.8,
0.9,
0.95,
1
]
@export var level : int = 1
func _init(_level : int = 1):
level = _level
func get_icon() -> Texture:
return preload("res://common/icons/dna.svg")
func get_base_rarity() -> int:
return 0
func get_mutation_name() -> String:
printerr("Classe abstraite PlantMutation appelée")
return ""
func get_mutation_description() -> String:
printerr("Classe abstraite PlantMutation appelée")
return ""
func mutate_score(_plant : Plant, score) -> int:
return score
func mutate_grow_time(_plant : Plant, grow_time : int) -> int:
return grow_time
func mutate_plant(_plant : Plant):
pass
func get_level_for_rarity(rarity : int) -> int :
return rarity - get_base_rarity() + 1
static func get_rarity(mutation : PlantMutation) -> int:
return mutation.get_base_rarity() + mutation.level - 1
static func get_rarity_text(mutation : PlantMutation) -> String:
var rarity_text : Array[String] = [
"Common",
"Rare",
"Very rare",
"Impossible",
"Absurd",
]
var rarity = PlantMutation.get_rarity(mutation)
if rarity < len(rarity_text):
return rarity_text[rarity]
else :
return rarity_text[len(rarity_text) - 1] + " " + str(rarity - len(rarity_text) + 2)
static func get_rarity_bg_color(mutation : PlantMutation) -> Color:
var rarity_colors : Array[Color] = [
Color("4b3700"),
Color("6d2300"),
Color("001f50"),
Color("311558"),
Color("780235"),
]
return rarity_colors[min(PlantMutation.get_rarity(mutation), len(rarity_colors) - 1)]
static func get_rarity_color(mutation : PlantMutation) -> Color:
var rarity_colors : Array[Color] = [
Color("FFBE0B"),
Color("FB5607"),
Color("3A86FF"),
Color("8338EC"),
Color("FF006E"),
]
return rarity_colors[min(PlantMutation.get_rarity(mutation), len(rarity_colors) - 1)]
static func get_framed_info_from_mutation(
mutation : PlantMutation
) -> Inspector.FramedInfo:
return Inspector.FramedInfo.new(
mutation.get_mutation_name() + (" %d" % mutation.level if mutation.level > 1 else ""),
"[b]%s[/b] %s" % [PlantMutation.get_rarity_text(mutation), mutation.get_mutation_description()],
mutation.get_icon(),
PlantMutation.get_rarity_bg_color(mutation)
)
static func random_rarity() -> int:
var random_float = randf()
for i in range(len(BASE_RARITY_CHANCE) - 1):
if random_float < BASE_RARITY_CHANCE[i]:
return i
return len(BASE_RARITY_CHANCE) - 1
static func random_mutation(rarity = PlantMutation.random_rarity()) -> PlantMutation:
var all_mutations = GameInfo.game_data.unlocked_plant_mutations.duplicate_deep()
all_mutations.shuffle()
for new_mutation in all_mutations:
var level_for_rarity = new_mutation.get_level_for_rarity(rarity)
if level_for_rarity >= 1:
new_mutation.level = level_for_rarity
return new_mutation
return null

View File

@@ -0,0 +1 @@
uid://c1lsjc2cwjupa

View File

@@ -0,0 +1,23 @@
extends PlantMutation
class_name AncientMutation
const DEFAULT_DAY_FACTOR = 5
func get_icon() -> Texture:
return preload("res://common/icons/wood.svg")
func get_base_rarity() -> int:
return 0
func get_mutation_name() -> String:
return "Ancient"
func get_mutation_description() -> String:
return "Add [b]1[/b] to the score for each [b]%d[/b] days passed" % get_day_factor()
func get_day_factor():
return max(1, DEFAULT_DAY_FACTOR - level + 1)
func mutate_score(plant : Plant, score) -> int:
return score + floori(plant.day / get_day_factor())

View File

@@ -0,0 +1 @@
uid://c7po0bstyg80u

View File

@@ -0,0 +1,26 @@
extends PlantMutation
class_name ElitistMutation
func get_icon() -> Texture:
return preload("res://common/icons/copy.svg")
func get_base_rarity() -> int:
return 0
func get_mutation_name() -> String:
return "Intolerant"
func get_mutation_description() -> String:
return "Add [b]%d[/b] to the score for each plant of the same species around, but score become 0 if none is around." % level
func mutate_score(plant : Plant, score) -> int:
var plant_count = 0
for area in plant.influence_zone.get_overlapping_areas():
if area is Plant and area.plant_type.name == plant.plant_type.name:
plant_count += 1
if plant_count == 0:
return 0
else :
return score + level * plant_count

View File

@@ -0,0 +1 @@
uid://bt1xh7ss13e5e

View File

@@ -0,0 +1,21 @@
extends PlantMutation
class_name ErmitMutation
func get_icon() -> Texture:
return preload("res://common/icons/seedling-off.svg")
func get_base_rarity() -> int:
return 0
func get_mutation_name() -> String:
return "Ermit"
func get_mutation_description() -> String:
return "Multiply the score by %d if no plant is near, but set it to 0 otherwise." % level
func mutate_score(plant : Plant, score) -> int:
for area in plant.influence_zone.get_overlapping_areas():
if area is Plant:
return 0
return score * 2

View File

@@ -0,0 +1 @@
uid://domy822vgxfxs

View File

@@ -0,0 +1,17 @@
extends PlantMutation
class_name PrecociousMutation
func get_icon() -> Texture:
return preload("res://common/icons/hourglass-empty.svg")
func get_base_rarity() -> int:
return 0
func get_mutation_name() -> String:
return "Precocious"
func get_mutation_description() -> String:
return "Add [b]%d[/b] to the score while the plant is growing" % level
func mutate_score(plant : Plant, score) -> int:
return score + (0 if plant.state == Plant.State.MATURE else level)

View File

@@ -0,0 +1 @@
uid://cx5mg5vf62bia

View File

@@ -0,0 +1,17 @@
extends PlantMutation
class_name QualityMutation
func get_icon() -> Texture:
return preload("res://common/icons/north-star.svg")
func get_base_rarity() -> int:
return 0
func get_mutation_name() -> String:
return "Quality"
func get_mutation_description() -> String:
return "Add [b]%d[/b] to the score if the plant is mature." % level
func mutate_score(plant : Plant, score : int) -> int:
return score + (level if plant.state == Plant.State.MATURE else 0)

View File

@@ -0,0 +1 @@
uid://bdobyk2j625lb

View File

@@ -0,0 +1,17 @@
extends PlantMutation
class_name QuickMutation
func get_icon() -> Texture:
return preload("res://common/icons/chevrons-up.svg")
func get_base_rarity() -> int:
return 0
func get_mutation_name() -> String:
return "Quick"
func get_mutation_description() -> String:
return "Reduce the grow time by %d" % level
func mutate_grow_time(_plant : Plant, grow_time : int) -> int:
return max(grow_time - level, 0)

View File

@@ -0,0 +1 @@
uid://bhtq0cbrgu58v

View File

@@ -0,0 +1,28 @@
extends PlantMutation
class_name SociableMutation
const NEAR_PLANT_NEEDED = 2
func get_icon() -> Texture:
return preload("res://common/icons/seedling.svg")
func get_base_rarity() -> int:
return 0
func get_mutation_name() -> String:
return "Sociable"
func get_mutation_description() -> String:
return "Add [b]%d[/b] to the score if near %d other plants" % [get_score_bonus(), NEAR_PLANT_NEEDED]
func get_score_bonus():
return (level + 2)
func mutate_score(plant : Plant, score) -> int:
var plant_count = 0
for area in plant.influence_zone.get_overlapping_areas():
if area is Plant:
plant_count += 1
return score + (get_score_bonus() if plant_count >= NEAR_PLANT_NEEDED else 0)

View File

@@ -0,0 +1 @@
uid://b8q5xgvy85qeb

View File

@@ -0,0 +1,20 @@
extends PlantMutation
class_name StrongMutation
func get_icon() -> Texture:
return preload("res://common/icons/dna.svg")
func get_base_rarity() -> int:
return 0
func get_mutation_name() -> String:
return "Strong"
func get_mutation_description() -> String:
return "Plus [b]%d[/b] percent of the score" % roundi(get_score_multiplier() * 100)
func get_score_multiplier():
return float(level)/2.
func mutate_score(_plant : Plant, score: int) -> int:
return score + roundi(score * get_score_multiplier())

View File

@@ -0,0 +1 @@
uid://cwj3k4p6ci5t4

View File

@@ -2,7 +2,9 @@ extends Node2D
class_name PlantSprite
const PLANTED_SEED_CROP_WIDTH = 50
const PLANTED_SEED_POS_Y = -50
const PLANTED_SEED_POS_Y = 0
const PARTICLES_SCENE : PackedScene = preload("res://common/vfx/particles/particles.tscn")
signal harvest_animation_finished
@@ -35,6 +37,16 @@ func get_state_texture(s: Plant.State, plant_type : PlantType) -> Texture2D:
return plant_type.mature_texture
return null
func generate_mutation_effects(plant : Plant):
for m in plant.plant_mutations:
var particles_emitter : Particles = PARTICLES_SCENE.instantiate() as CPUParticles2D
particles_emitter.setup_particles(
Particles.Parameters.new(
m.get_icon(),
PlantMutation.get_rarity_color(m)
)
)
add_child(particles_emitter)
func start_harvest_animation():
$AnimationPlayer.play("harvest")

View File

@@ -4,14 +4,13 @@ class_name PlantType
@export var name : String
@export_multiline var description : String
@export var growing_time : int
@export var default_growing_time : int = 2
@export var default_plant_score : int = 1
@export var seed_texture : Texture
@export var growing_texture : Texture
@export var mature_texture : Texture
@export var mature_effect : PlantEffect
@export var cyclic_effect : PlantEffect
@export_file var harvest_types_path : Array[String] = []
@export var harvest_number : Array[int] = [1,2]
@export var default_harvest_effects : Array[PlantEffect] = []
@export var default_mature_effects : Array[PlantEffect] = []
@export var default_cyclic_effects : Array[PlantEffect] = []