forked from DeadPigeonGames/Arcanum-Fortuna
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshop_card.gd
41 lines (26 loc) · 841 Bytes
/
shop_card.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class_name ShopCard
extends Card
signal clicked(card: ShopCard)
@export var discount := 0.3
var is_trade_card := false
var hovered := false
var affordable := false
func setup():
super.setup()
if card_data:
%Costs.text = str(get_costs())
func can_afford_card(available_money: int) -> bool:
affordable = available_money >= get_costs()
return affordable
func get_costs():
if is_trade_card:
if card_data.trade_override > 0:
return card_data.trade_override
return max(floor(card_data.shop_cost - max(1, ceili(float(card_data.shop_cost) * discount))), 1)
return card_data.shop_cost
func _process(delta):
%selected.visible = hovered and affordable
hovered = Rect2(Vector2.ZERO, get_rect().size).has_point(get_local_mouse_position())
func _gui_input(event):
if event.is_action("pickUpCard"):
clicked.emit(self)