forked from loudsmilestudios/TetraForce
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
extends Node | ||
|
||
var index : int = 0 | ||
var pool : Array = [] | ||
var rng : RandomNumberGenerator = RandomNumberGenerator.new() | ||
var chance : float = 0.5 | ||
|
||
func _ready(): | ||
rng.randomize() | ||
|
||
func _init(items : Array, threshold : float): | ||
pool = items | ||
chance = threshold | ||
|
||
# returns the loot drop item for the current kill count in the prize pack | ||
# keeps track of which item to drop and only provides an item if a random | ||
# value matches the chance to drop an item | ||
func get_drop() -> String: | ||
var drop = "" | ||
if rng.randf() <= chance: | ||
drop = pool[index % pool.size()] | ||
index += 1 | ||
if index > pool.size() * 100: | ||
index = 0 | ||
return drop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
extends Node | ||
class_name prizepacks | ||
|
||
# will hold an array of prizepack objects | ||
var packs : Array = [] | ||
|
||
# will remap prizepack indexes, usefull for randomized games | ||
var remapped : Array = [] | ||
|
||
func _init(): | ||
# default prize pack definitions, array of items to drop and the chance to drop | ||
var packdefs : Array = [ | ||
{"pool": [""], "chance": 1.0}, | ||
{"pool": ["smallheart","whitetetran"], "chance": 0.5}, | ||
{"pool": ["whitetetran","whitetetran","smallheart","redtetran"], "chance" : 0.5}, | ||
{"pool": ["smallheart","redtetran","smallheart","bluetetran"], "chance": 0.5}, | ||
{"pool": ["whitetetran","redtetran","bluetetran","greentetran"], "chance": 0.5} | ||
] | ||
var pp = load("res://engine/prizepack.gd") | ||
for p in packdefs: | ||
packs.append(pp.new(packdefs[p].pool, packdefs[p].chance)) | ||
|
||
func remap(): | ||
if packs.size() > 0: | ||
for i in range(packs.size()): | ||
remapped[i] = i | ||
else: | ||
remapped = [] | ||
|
||
func set_map(map : Array): | ||
if map.size() > packs.size(): | ||
remap() | ||
else: | ||
remapped = map | ||
|
||
func _ready(): | ||
remap() | ||
|
||
# each enemy should have a prizepack property (integer) to pass to this function on kill | ||
func get_drop_from_pack(pack : int) -> String: | ||
if pack >= packs.size(): | ||
return "" | ||
return packs[remapped[pack]].get_drop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters