Documented Item Spawn Code
This commit is contained in:
parent
a404950b92
commit
20dea147ba
1 changed files with 8 additions and 0 deletions
|
|
@ -15,19 +15,24 @@ static var item_pool = ResourceLoader.load("res://items/generic/item_pool.tres",
|
||||||
|
|
||||||
var remove_after_spawn = false
|
var remove_after_spawn = false
|
||||||
|
|
||||||
|
# Choose the item pool this spawn location draws from
|
||||||
func choose_pool() -> Array[PackedScene]:
|
func choose_pool() -> Array[PackedScene]:
|
||||||
var unique_chance = unique_base_chance + unique_bonus_multiplier * rarity_bonus
|
var unique_chance = unique_base_chance + unique_bonus_multiplier * rarity_bonus
|
||||||
var rare_chance = rare_base_chance + rare_bonus_multiplier * rarity_bonus
|
var rare_chance = rare_base_chance + rare_bonus_multiplier * rarity_bonus
|
||||||
|
|
||||||
var random = randf()
|
var random = randf()
|
||||||
if random < unique_chance && item_pool.unique.size() > 0:
|
if random < unique_chance && item_pool.unique.size() > 0:
|
||||||
|
# Unique items are removed from the pool when picked
|
||||||
remove_after_spawn = true
|
remove_after_spawn = true
|
||||||
return item_pool.unique
|
return item_pool.unique
|
||||||
elif random < unique_chance + rare_chance || guarantee_rare:
|
elif random < unique_chance + rare_chance || guarantee_rare:
|
||||||
return item_pool.rare
|
return item_pool.rare
|
||||||
|
|
||||||
|
# If an item is common, no petal spawns
|
||||||
spawn_petal = false
|
spawn_petal = false
|
||||||
return item_pool.common
|
return item_pool.common
|
||||||
|
|
||||||
|
# Places a petal holding this item
|
||||||
func instantiate_petal(item):
|
func instantiate_petal(item):
|
||||||
var petal : Petal = petal_scene.instantiate()
|
var petal : Petal = petal_scene.instantiate()
|
||||||
get_parent().call_deferred("add_child", petal)
|
get_parent().call_deferred("add_child", petal)
|
||||||
|
|
@ -35,11 +40,14 @@ func instantiate_petal(item):
|
||||||
petal.global_position = global_position
|
petal.global_position = global_position
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
|
# Pick a random pool and a random item from it, then remove it if unique.
|
||||||
var pool = choose_pool()
|
var pool = choose_pool()
|
||||||
var index = randi_range(0, pool.size() - 1)
|
var index = randi_range(0, pool.size() - 1)
|
||||||
var packed_scene : PackedScene = pool[index]
|
var packed_scene : PackedScene = pool[index]
|
||||||
if remove_after_spawn:
|
if remove_after_spawn:
|
||||||
item_pool.unique.remove_at(index)
|
item_pool.unique.remove_at(index)
|
||||||
|
|
||||||
|
# Place the item, possibly inside a petal
|
||||||
var object = packed_scene.instantiate()
|
var object = packed_scene.instantiate()
|
||||||
add_child.call_deferred(object)
|
add_child.call_deferred(object)
|
||||||
object.reparent.call_deferred(get_parent())
|
object.reparent.call_deferred(get_parent())
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue