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:
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
|
||||
31
entities/plants/scripts/plant_influence_zone.gd
Normal file
31
entities/plants/scripts/plant_influence_zone.gd
Normal 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)
|
||||
1
entities/plants/scripts/plant_influence_zone.gd.uid
Normal file
1
entities/plants/scripts/plant_influence_zone.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cmm3ar0ikkvkb
|
||||
111
entities/plants/scripts/plant_mutation.gd
Normal file
111
entities/plants/scripts/plant_mutation.gd
Normal 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
|
||||
|
||||
1
entities/plants/scripts/plant_mutation.gd.uid
Normal file
1
entities/plants/scripts/plant_mutation.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://c1lsjc2cwjupa
|
||||
23
entities/plants/scripts/plant_mutation/ancient_mutation.gd
Normal file
23
entities/plants/scripts/plant_mutation/ancient_mutation.gd
Normal 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())
|
||||
@@ -0,0 +1 @@
|
||||
uid://c7po0bstyg80u
|
||||
26
entities/plants/scripts/plant_mutation/elitist_mutation.gd
Normal file
26
entities/plants/scripts/plant_mutation/elitist_mutation.gd
Normal 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
|
||||
@@ -0,0 +1 @@
|
||||
uid://bt1xh7ss13e5e
|
||||
21
entities/plants/scripts/plant_mutation/ermit_mutation.gd
Normal file
21
entities/plants/scripts/plant_mutation/ermit_mutation.gd
Normal 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
|
||||
@@ -0,0 +1 @@
|
||||
uid://domy822vgxfxs
|
||||
@@ -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)
|
||||
@@ -0,0 +1 @@
|
||||
uid://cx5mg5vf62bia
|
||||
17
entities/plants/scripts/plant_mutation/quality_mutation.gd
Normal file
17
entities/plants/scripts/plant_mutation/quality_mutation.gd
Normal 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)
|
||||
@@ -0,0 +1 @@
|
||||
uid://bdobyk2j625lb
|
||||
17
entities/plants/scripts/plant_mutation/quick_mutation.gd
Normal file
17
entities/plants/scripts/plant_mutation/quick_mutation.gd
Normal 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)
|
||||
@@ -0,0 +1 @@
|
||||
uid://bhtq0cbrgu58v
|
||||
28
entities/plants/scripts/plant_mutation/sociable_mutation.gd
Normal file
28
entities/plants/scripts/plant_mutation/sociable_mutation.gd
Normal 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)
|
||||
@@ -0,0 +1 @@
|
||||
uid://b8q5xgvy85qeb
|
||||
20
entities/plants/scripts/plant_mutation/strong_mutation.gd
Normal file
20
entities/plants/scripts/plant_mutation/strong_mutation.gd
Normal 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())
|
||||
@@ -0,0 +1 @@
|
||||
uid://cwj3k4p6ci5t4
|
||||
@@ -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")
|
||||
|
||||
@@ -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] = []
|
||||
|
||||
Reference in New Issue
Block a user