-
Notifications
You must be signed in to change notification settings - Fork 0
/
card.gd
122 lines (111 loc) · 3.96 KB
/
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
@tool
extends Resource
class_name Card
enum AreaType {
RECTANGLE,
FRONT_AND_SIDES, # Covers 3 tiles in front and both sides.
CONE, # Starts in front of player at given width, and expands outwards for length, expanding by cone step.
DIAMOND, # Starts in position and expands outwards based on area_length. 1 is a "cross".
}
@export var card_name: String
@export var upgrade_name: String
@export var basic = false
@export var upgrade_level = 0
@export var base_card: Card
@export var cost: int
# If false, card can't be played.
@export var playable = true
@export var texture: Texture2D
@export var target_mode: Enum.TargetMode
# Should be "on_play_animation".
@export var target_animation: Enum.TargetAnimationType
@export var on_damage_animation: Enum.TargetAnimationType
@export var target_distance: int
@export var damage_value: CardEffectValue
# Use on_play_self_effects when creating a card that has
# extra side effect on self besides target. They are played before
# on_play_effects are played.
@export var on_play_self_effects: Array[CardEffect]
@export var on_play_effects: Array[CardEffect]
# Effects applied to target on attacks if attack causes damage (i.e.,
# it wasn't fully blocked or dodged).
@export var on_damage_effects: Array[CardEffect]
# Effects to be applied to self after rest of effects.
@export var on_play_after_effects: Array[CardEffect]
# Effects to be applied if this attack kills an enemy.
@export var on_kill_effects: Array[CardEffect]
# Those effects take place next turn if unit is still alive.
@export var on_next_turn_effects: Array[CardEffect]
@export var area_type: AreaType = AreaType.RECTANGLE
@export var area_length: int = 1
# Area width should in general be odd.
@export var area_width: int = 1
@export var cone_step: int = 1
@export var power_relic: Relic
@export var exhaust: bool
func should_exhaust():
if exhaust:
return true
# Consider manually setting "exhaust" in power
# so some of them could not "exhaust".
if power_relic:
return true
return false
func is_attack():
return damage_value != null
func apply_card_change(change: CardChange):
cost += change.cost_change
if cost < 0:
cost = 0
if change.exhaust:
exhaust = true
# Returns a list of tiles that will be affected
# by card, with (0, 0) being the tile chosen by
# human. We support basic area types through
# properties, but a particular card could override.
func effect_area(direction: Vector2):
var tiles = []
if area_type == AreaType.RECTANGLE:
@warning_ignore("integer_division")
var width_idx = (area_width-1)/2
for i in range(area_length):
for j in range(-width_idx, width_idx+1):
tiles.push_back(Vector2i(i, j))
elif area_type == AreaType.FRONT_AND_SIDES:
tiles = [
Vector2i(0, 0), Vector2i(0, 1), Vector2i(0, -1),
Vector2i(-1, -1), Vector2i(-1, 1)
]
elif area_type == AreaType.CONE:
@warning_ignore("integer_division")
var width_idx = (area_width-1)/2
for i in range(area_length):
for j in range(-width_idx, width_idx+1):
tiles.push_back(Vector2i(i, j))
width_idx += cone_step
elif area_type == AreaType.DIAMOND:
for i in range(-area_length, area_length+1):
for j in range(-area_length, area_length+1):
if abs(i) + abs(j) <= area_length:
tiles.push_back(Vector2i(i, j))
var new_effect_area = []
var angle = Vector2.RIGHT.angle_to(direction)
for pos in tiles:
var rotated_pos = Vector2(pos).rotated(angle)
rotated_pos.x = round(rotated_pos.x)
rotated_pos.y = round(rotated_pos.y)
new_effect_area.append(Vector2i(rotated_pos))
return new_effect_area
func extra_tooltips() -> Dictionary:
var tooltips = {}
if power_relic:
tooltips[power_relic.name.to_lower()] = power_relic.tooltip
return tooltips
static func filter_condition(card_filter: CardFilter):
var property_conditions = {
CardFilter.Property.ANY: func(c: Card): return true,
CardFilter.Property.ATTACK: func(c: Card): return c.is_attack(),
}
if card_filter:
return property_conditions[card_filter.property]
return (func(c: Card): return true)