-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnomad.anpcscript
106 lines (94 loc) · 3.37 KB
/
nomad.anpcscript
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
define program vegetarian:init
@global.hunger = 0
end
-- This program supports the following arguments:
-- arg1
-- arg2
-- arg3
define program vegetarian:idle
npc:move:stand()
@global.hunger = @global.hunger + 2
if (@global.hunger >= 60) then
npc:execute(name = "vegetarian:feed")
end
-- TODO: Replace this with an scheduled event
if (@time >= 20000) then
npc:execute(name = "vegetarian:sleep")
end
@local.should_ack_obj = false
for (1; @local.for_index <= @objs.all.length; 1) do
if (npc:random(start = 1, end = 100) >= (100 - @args.ack_nearby_objs_chance)) then
@local.obj = @objs.get[@local.for_index]
if (@local.obj ~= nil) then
@local.dist = npc:distance_to(object = @local.obj)
@local.should_ack_obj = (@local.dist <= @args.ack_nearby_objs_dist) && (@local.dist > 0)
end
end
if (@local.should_ack_obj == true) then
@local.ack_times = npc:random(start = 15, end = 30)
for (1; @local.for_index <= @local.ack_times; 1) do
@local.obj_pos = npc:obj:get_pos(object = @local.obj)
npc:move:rotate(target_pos = @local.obj_pos)
end
@global.hunger = @global.hunger + (@local.ack_times * 2)
break
else
if (npc:random(start = 1, end = 10) <= 5) then
npc:execute(name = "vegetarian:wander")
end
end
end
end
-- Super basic wandering program, will take 1-5 steps,
-- and will not repeat previous direction
define program vegetarian:wander
@local.prev_dir = -1
for (1; @local.for_index < npc:random(start = 1, end = 5); 1) do
@local.cardinal_dir = npc:random(start = 0, end = 7)
while (@local.cardinal_dir == @local.prev_dir) do
@local.cardinal_dir = npc:random(start = 0, end = 7)
end
@local.prev_dir = @local.cardinal_dir
npc:move:walk(cardinal_dir = @local.cardinal_dir)
end
npc:move:stand()
end
define program vegetarian:sleep
@local.bed_pos = npc:env:node:find(matches = "single", radius = 35, nodenames = {"beds:bed_bottom"})
if (@local.bed_pos.length > 0) then
npc:execute(name = "npc:walk_to_pos", args = {pos = @local.bed_pos[1]})
npc:env:node:operate(pos = @local.bed_pos[1])
while (((@time > 20000) && (@time < 24000)) || (@time < 6000))) do
npc:wait(time = 30)
end
@global.hunger = 60
end
end
define program vegetarian:feed
while (@global.hunger >= 0) do
-- Go to sleep even if we are still hungry
-- TODO: Replace this with an scheduled event
if (((@time > 20000) && (@time <= 24000)) || (@time < 6000)) then
exit
end
@local.nodes = npc:env:node:find(radius = 5, nodenames = {"default:grass_1", "default:grass_2", "default:grass_3", "default:grass_4", "default:grass_5"})
if (@local.nodes.length > 0) then
@local.random_index = npc:random(start = 1, end = @local.nodes.length)
@local.chosen_node = @local.nodes[@local.random_index]
npc:execute(name = "npc:walk_to_pos", args = {pos = @local.chosen_node, force_accessing_node = true})
npc:env:node:dig(pos = @local.chosen_node)
@global.hunger = @global.hunger - 10
else
npc:execute(name = "vegetarian:wander")
end
end
end
define program vegetarian:own
npc:env:nodes:set_owned(value = @args.value, pos = @args.pos, categories = @args.categories)
end
define program vegetarian:walk_to_owned
@local.target_node = npc:env:node:store:get(only_one = true, categories = @args.categories)
if (@local.target_node ~= nil) then
npc:execute(name = "npc:walk_to_pos", args = {pos = @local.target_node.pos, force_accessing_node = true})
end
end