mtd/Scripts/card_printer.gd

64 lines
1.8 KiB
GDScript3
Raw Normal View History

2024-02-22 06:22:22 +11:00
class_name CardPrinter extends StaticBody3D
2024-02-22 06:22:22 +11:00
@export var cards: Array[CardInHand]
@export var item_card_scene: PackedScene
@export var button_collider: CollisionShape3D
@export var button_box: Node3D
@export var choice_colliders: Array[CollisionShape3D]
2024-02-22 06:22:22 +11:00
var card_available: bool = false
2024-02-22 06:22:22 +11:00
func randomize_cards() -> void:
var weight_total: int = 0
for rarity: String in Data.Rarity:
weight_total += Data.rarity_weights[rarity]
2024-02-22 06:22:22 +11:00
var generated_rarity: int = randi_range(0, weight_total)
var decided_rarity: int = 0
2024-02-22 06:22:22 +11:00
for rarity: String in Data.Rarity:
weight_total -= Data.rarity_weights[rarity]
if generated_rarity >= weight_total:
decided_rarity = Data.Rarity[rarity]
break
2024-02-22 06:22:22 +11:00
var card_array: Array = []
for x: Card in Data.cards:
if x.rarity == decided_rarity:
card_array.append(x)
2024-02-22 06:22:22 +11:00
var card: Card
for x: CardInHand in cards:
if card_array.size() > 0:
card = card_array.pick_random()
card_array.erase(card)
x.set_card(card)
2023-11-16 00:07:41 +11:00
#TODO: in reality this should just show the icon and then hovering over it lets you see either side at the players own discretion
x.view_tower()
$Node3D.set_visible(true)
2024-02-22 06:22:22 +11:00
for x: CollisionShape3D in choice_colliders:
x.disabled = false
card_available = true
2024-02-22 06:22:22 +11:00
func retrieve_card(i: int) -> void:
$Node3D.set_visible(false)
2024-02-22 06:22:22 +11:00
for x: CollisionShape3D in choice_colliders:
x.disabled = true
if card_available:
2024-02-22 06:22:22 +11:00
var card: Card = cards[i].stats
var item: ItemCard = item_card_scene.instantiate() as ItemCard
item.card = card
2023-11-19 18:47:52 +11:00
item.position = Vector3(1.683, 0, 0)
add_child(item)
button_collider.disabled = false
button_box.position = Vector3(0,0,0)
$AudioStreamPlayer3D.play()
2024-02-22 06:22:22 +11:00
func _on_static_body_3d_button_interacted(_value: int) -> void:
button_collider.disabled = true
button_box.position = Vector3(0,0,-0.2)
$AudioStreamPlayer3D.play()
randomize_cards()