Date: 2014/07/31 12:32:23 UTC-07:00
Type: Denizen Script
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
"Lumberjack Life":
type: world
events:
on time 0 in BaseWorld:
- foreach <server.get_npcs_assigned[Lumberjack]> {- run "lookfortrees" }
on time 12 in BaseWorld:
- foreach <server.get_npcs_assigned[Lumberjack]> {- walkto <npc.anchor[startPosition]> }
- queue clear
"Lumberjack":
type: assignment
default constants:
logs: oak_log|birch_log|spruce_log
leaves: leaves|birch_leaves|spruce_leaves
initialRange: 30
interact scripts:
- 10 Lumberjack
actions:
on assignment:
- trigger name:click toggle:true
- trigger name:proximity toggle:true range:5
- flag npc ready_to_cut:!
- flag npc actualRange:<cons:initialRange>
- anchor add <npc.location> "id:startPosition"
on complete navigation:
- if <npc.flag[ready_to_cut]> {
- run "defineTree"
}
}
on cancel navigation:
- queue clear
"lookForTrees":
type: task
script:
- flag npc found_trees:!
- foreach <npc.location.find.blocks[<cons:logs>].within[<npc.flag[actualRange]>].as_list> {
- if <proc[isTreeHump].context[%value%]> {
- flag npc found_trees:|:%value%
}
}
- if <npc.flag[found_trees].size.as_int> == 0 {
- flag npc actualRange:++:10
- run "lookForTrees"
} else {
- flag npc current_tree:1
- lookclose <npc> state:false
- walkto <npc> <npc.flag[found_trees].get[<npc.flag[current_tree].as_int>]>
- flag npc ready_to_cut:true
- queue clear
}
"defineTree":
type: task
script:
- look <npc> <npc.flag[found_trees].get[<npc.flag[current_tree].as_int>]>
- flag npc tree_elems:!
- flag npc tree_elems:|:<npc.flag[found_trees].get[<npc.flag[current_tree].as_int>]>
- flag npc current_elem:1
- run "checkBlockAbove"
"checkBlockAbove":
type: task
script:
- define currentBlock <npc.flag[tree_elems].get[<npc.flag[current_elem].as_int>]>
- if <proc[isLogAbove].context[%currentBlock%]> {
- animate <npc> animation:arm_swing
- flag npc tree_elems:|:<%currentBlock%.above>
- flag npc current_elem:++
- run "checkBlockAbove"
} else {
- run "lookForLeaves"
}
"lookForLeaves":
type: task
script:
- define topBlock <npc.flag[tree_elems].get[<npc.flag[tree_elems].size.as_int>]>
- foreach <%topBlock%.find.blocks[<cons:leaves>].within[3].as_list> {
- flag npc tree_elems:|:%value%
}
- run "cutTree"
"cutTree":
type: task
script:
- foreach <npc.flag[tree_elems].as_list> {
- modifyblock %value% 0
}
- modifyblock <npc.flag[found_trees].get[<npc.flag[current_tree].as_int>]> 6
- flag npc current_tree:++
- if <proc[wasLast].context[<npc.flag[current_tree].as_int>|<npc.flag[found_trees].size.as_int>]> {
- run "goToStart"
} else {
- walkto <npc> <npc.flag[found_trees].get[<npc.flag[current_tree].as_int>]>
}
"isLogAbove":
type: procedure
debug: false
definitions: block
script:
- if <%block%.above.material.id> == <%block%.material.id> {
- ^determine true
} else {
- ^determine false
}
"isTreeHump":
type: procedure
debug: false
definitions: block
script:
- ^if <%block%.below.material.id> == 3 || <%block%.below.material.id> == 1 {
- if <%block%.above.material.id> == <%block%.material.id> {
- ^determine true
} else {
- ^determine false
}
} else {
- ^determine false
}
"wasLast":
type: procedure
debug: false
definitions: index|total
script:
- if %index% > %total% {
- ^determine true
} else {
- ^determine false
}
"goToStart":
type: task
script:
- flag npc ready_to_cut:!
- flag npc actualRange:<cons:initialRange>
- walkto <npc> <npc.anchor[startPosition]>