ajout du déblocage/évolutions des plantes (#89) et fix divers
This commit is contained in:
@@ -1,13 +1,6 @@
|
||||
extends Resource
|
||||
class_name PlantMutation
|
||||
|
||||
const BASE_RARITY_CHANCE : Array[float] = [
|
||||
0.75,
|
||||
0.9,
|
||||
1,
|
||||
1,
|
||||
]
|
||||
|
||||
@export var level : int = 1
|
||||
|
||||
func _init(_level : int = 1):
|
||||
@@ -78,21 +71,15 @@ static func get_rarity_color(rarity : int) -> Color:
|
||||
|
||||
return rarity_colors[min(rarity, len(rarity_colors) - 1)]
|
||||
|
||||
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:
|
||||
static func random_mutation(except_mutations : Array[PlantMutation] = []) -> 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
|
||||
|
||||
all_mutations = all_mutations.filter(
|
||||
func (f1 : PlantMutation):
|
||||
return except_mutations.find_custom(
|
||||
func (f2 : PlantMutation): return f2.get_mutation_name() == f1.get_mutation_name()
|
||||
) == -1
|
||||
)
|
||||
if len(all_mutations):
|
||||
return all_mutations.pick_random()
|
||||
else :
|
||||
return null
|
||||
|
||||
Reference in New Issue
Block a user