forked from gdquest-demos/godot-4-new-features
-
Notifications
You must be signed in to change notification settings - Fork 0
/
070-autodoc.gd
77 lines (63 loc) · 1.98 KB
/
070-autodoc.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
## Used as a base class for all items in the game
## Can itself contain items, and so is also the base class for all container
class_name AutodocExampleItem extends Resource
## Used for grouping or quick sorting
enum TYPE{
WEAPON,
DEFENSE,
CONTAINER
}
## Returns the complete title of the item, which is composed of its status name
## and its item name
var full_title := "":
set(value):
var name = value.split(" ")
item_name = name[1]
status_name = name[0]
get:
return status_name + " " + item_name
## Used when grouping items
@export var item_type: TYPE = TYPE.CONTAINER
## How much is this item worth, when sold
@export_range(0, 100, 0, "suffix:Gils") var price := 5
@export_group("Base", "item_")
## How the item is called. This is used to bundle items together and is case
## sensitive
@export var item_name := "Pouch"
## The item's base weight.
@export var item_weight := 10
@export_group("Special", "status_")
## The status' name. This is free and only used in item labels
@export var status_name := "Magical"
@export_group("Sub Items")
## If this value is true, then this item can contain other items
@export var is_container := true:
set(value):
is_container = value
if not is_container:
maximum_countenance = 0
else:
maximum_countenance = max(maximum_countenance, 1)
## How many items can this item contain. If the maximum countenance
@export var maximum_countenance := 10
## An array of items.
@export var contents: Array[AutodocExampleItem] = []:
set(value):
value.resize(maximum_countenance)
contents = value
## If this item can contain other items, those item's weight will be added to
## the total weight
var total_weight := 0:
get:
return contents.reduce(
func(acc: int, item: AutodocExampleItem):
return item.total_weight + acc
, item_weight
)
## Total item's value, as well as its contents' value
func get_total_price() -> int:
return contents.reduce(
func(acc: int, item: AutodocExampleItem):
return item.get_total_price() + acc
, price
)