-
Notifications
You must be signed in to change notification settings - Fork 0
/
home_pc.lua
369 lines (354 loc) · 12.5 KB
/
home_pc.lua
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
math.randomseed(os.time())
home_boot = 60 -- seconds it takes to boot the computer
home_miner = math.random(450,525) -- seconds it takes to mine one bitcent
home_upgrade_step = 15 -- seconds to subtract from home_miner per upgrade
local function computer_owner(meta, player)
if player:get_player_name() ~= meta:get_string("owner") then
return false
end
return true
end
local function upgrade_timer(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local expansion1 = inv:get_stack("exp1", 1)
local expansion2 = inv:get_stack("exp2", 1)
local expansion3 = inv:get_stack("exp3", 1)
local upgraded_miner = home_miner
if expansion1:get_name()== "cryptocoins:home_computer_video" then
upgraded_miner = upgraded_miner - home_upgrade_step
else
if expansion1:get_name()== "" then
upgraded_miner = upgraded_miner
else
upgraded_miner = upgraded_miner + 99999
end
end
if expansion2:get_name()=="cryptocoins:home_computer_video" then
upgraded_miner = upgraded_miner - home_upgrade_step
else
if expansion2:get_name()== "" then
upgraded_miner = upgraded_miner
else
upgraded_miner = upgraded_miner + 99999
end
end
if expansion3:get_name()== "cryptocoins:home_computer_video" then
upgraded_miner = upgraded_miner - home_upgrade_step
else
if expansion3:get_name()== "" then
upgraded_miner = upgraded_miner
else
upgraded_miner = upgraded_miner + 99999
end
end
return upgraded_miner
end
function default.home_boot_formspec(pos)
local formspec = "invsize[10,10]"..
"image[1,0.5;1.2,1.2;tux.png]"..
"label[2,0.8;Initializing basic system settings ... OK]" ..
"label[2,1.1;Mounting local filesystems ... OK]" ..
"label[2,1.4;Enabling swap space ... OK]" ..
"label[2,1.7;Setting up console ... OK]" ..
"label[2,2;Operaing System Loaded ... OK]" ..
"label[2,2.3;Starting cgminer 3.7.2 ]" ..
"list[current_name;main;1,3;1,1;]"..
"list[current_player;main;3,9.5;4,1;]"
return formspec
end
function default.home_off_formspec(pos)
local formspec = "invsize[10,10]"..
"background[1,2.5;8,7;cryptocoins_home_computer_motherboard.png]"..
"label[2,2;Powered Off...]"..
"list[current_name;main;1,3;1,1;]"..
"list[current_name;exp1;2,5.94;1,1;]"..
"list[current_name;exp2;3,7.11;1,1;]"..
"list[current_name;exp3;2,8.29;1,1;]"..
"list[current_player;main;3,9.5;4,1;]"
return formspec
end
function default.home_active_formspec(pos)
local formspec = "invsize[10,10]"..
"background[1,2.5;8,7;cryptocoins_home_computer_motherboard.png]"..
"label[2,0.0;cgminer version 3.7.2 - Started]" ..
"label[2,0.2;----------------------------------------------------------------------------------]" ..
"label[2,0.4;5s:468.9K avg:468.8Kh/s : A:2304 R:0 HW:0 WU:394.4/m]" ..
"label[2,0.7;ST: 2 SS: 0 NB: 1909 LW: 34901 GF: 14 RF: 7]" ..
"label[2,1;Connected to stratum.max.bitcoin.com diff 1.02k with stratum.]" ..
"label[2,1.3;Block: 31dca6d... Diff:104 Started: 09:24:05 Best share: 618K.]" ..
"label[2,1.5;----------------------------------------------------------------------------------]" ..
"list[current_name;main;1,3;1,1;]"..
"list[current_name;exp1;2,5.94;1,1;]"..
"list[current_name;exp2;3,7.11;1,1;]"..
"list[current_name;exp3;2,8.29;1,1;]"..
"list[current_player;main;3,9.5;4,1;]"
return formspec
end
function default.home_wifi_formspec(pos)
local formspec = "invsize[10,10]"..
"background[1,2.5;8,7;cryptocoins_home_computer_motherboard.png]"..
"label[2,0;No Internet Connection.]" ..
"label[2,0.3;Is your ISP Router On?]"..
"label[2,0.6;Contact Your Network Administrator For More Information.]" ..
"list[current_name;main;1,3;1,1;]"..
"list[current_name;exp1;2,5.94;1,1;]"..
"list[current_name;exp2;3,7.11;1,1;]"..
"list[current_name;exp3;2,8.29;1,1;]"..
"list[current_player;main;3,9.5;4,1;]"
return formspec
end
function default.home_off(pos)
local timer = minetest.get_node_timer(pos)
local meta = minetest.get_meta(pos)
local node = minetest.get_node(pos)
local inv = meta:get_inventory()
minetest.swap_node(pos, {name = 'cryptocoins:home_computer', param2 = node.param2})
meta:set_string("formspec", default.home_off_formspec(pos))
meta:set_string("infotext", "Home Computer (owner "..
meta:get_string("owner")..")")
inv:set_size("main", 1*1)
timer:stop()
end
function default.home_wifi(pos)
local timer = minetest.get_node_timer(pos)
local meta = minetest.get_meta(pos)
local node = minetest.get_node(pos)
local inv = meta:get_inventory()
minetest.swap_node(pos, {name = 'cryptocoins:home_computer', param2 = node.param2})
meta:set_string("formspec", default.home_wifi_formspec(pos))
meta:set_string("infotext", "Home Computer (owner "..
meta:get_string("owner")..")")
inv:set_size("main", 1*1)
timer:stop()
end
function default.home_boot(pos)
local timer = minetest.get_node_timer(pos)
local meta = minetest.get_meta(pos)
local node = minetest.get_node(pos)
local inv = meta:get_inventory()
meta:set_string("formspec", default.home_boot_formspec(pos))
meta:set_string("infotext", "Home Computer (owner "..
meta:get_string("owner")..")")
inv:set_size("main", 1*1)
timer:start(home_boot)
end
-- Home Computer
minetest.register_node("cryptocoins:home_computer",{
drawtype = "nodebox",
description = "Home Computer",
tiles = {"cryptocoins_home_computer_tp.png","cryptocoins_home_computer_bt.png","cryptocoins_home_computer_rt.png","cryptocoins_home_computer_lt.png","cryptocoins_home_computer_bk.png","cryptocoins_home_computer_ft_off.png"},
paramtype = "light",
paramtype2 = "facedir",
drop = "cryptocoins:home_computer",
groups = {cracky=2, oddly_breakable_by_hand=2},
node_box = {
type = "fixed",
fixed = {
{-0.500000,-0.500000,0.03125,0.500000,0.500000,0.40625},
{-0.40625,-0.40625,0.40625,0.40625,0.40625,0.50000},
{-0.500000,-0.500000,-0.500000,0.500000,-0.375,-0.03125},
},
},
sounds = default.node_sound_wood_defaults(),
after_place_node = function(pos, placer)
local meta = minetest.get_meta(pos)
local timer = minetest.get_node_timer(pos)
meta:set_string("owner", placer:get_player_name() or "")
default.home_off(pos)
end,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
meta:set_string("formspec", default.home_boot_formspec(pos))
meta:set_string("infotext", "Home Computer (owner "..
meta:get_string("owner")..")")
inv:set_size("main", 1*1)
inv:set_size("exp1", 1*1)
inv:set_size("exp2", 1*1)
inv:set_size("exp3", 1*1)
end,
on_timer = function(pos)
local isp = minetest.find_node_near(pos, 1, {"cryptocoins:isp_on"})
if isp == nil then
local wifi = minetest.find_node_near(pos, 16, {"cryptocoins:router_on"})
if wifi == nil then
default.home_wifi(pos)
else
local meta = minetest.get_meta(pos)
if ( minetest.get_player_by_name(meta:get_string("owner")) == nil ) then
default.home_off(pos)
else
local timer = minetest.get_node_timer(pos)
local meta = minetest.get_meta(pos)
local node = minetest.get_node(pos)
local inv = meta:get_inventory()
minetest.swap_node(pos, {name = 'cryptocoins:home_computer_active', param2 = node.param2})
meta:set_string("formspec", default.home_active_formspec(pos))
meta:set_string("infotext", "Home Computer (owner "..
meta:get_string("owner")..")")
inv:set_size("main", 1*1)
if ( upgrade_timer(pos) < home_miner ) then
timer:start(upgrade_timer(pos))
else
default.home_off(pos)
end
end
end
else
local meta = minetest.get_meta(pos)
if ( minetest.get_player_by_name(meta:get_string("owner")) == nil ) then
default.home_off(pos)
else
local timer = minetest.get_node_timer(pos)
local meta = minetest.get_meta(pos)
local node = minetest.get_node(pos)
local inv = meta:get_inventory()
minetest.swap_node(pos, {name = 'cryptocoins:home_computer_active', param2 = node.param2})
meta:set_string("formspec", default.home_active_formspec(pos))
meta:set_string("infotext", "Home Computer (owner "..
meta:get_string("owner")..")")
inv:set_size("main", 1*1)
if ( upgrade_timer(pos) < home_miner ) then
timer:start(upgrade_timer(pos))
else
default.home_off(pos)
end
end
end
end,
on_punch = function(pos)
local isp = minetest.find_node_near(pos, 1, {"cryptocoins:isp_on"})
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
if upgrade_timer(pos) < home_miner then
if isp == nil then
local wifi = minetest.find_node_near(pos, 16, {"cryptocoins:router_on"})
if wifi == nil then
default.home_wifi(pos)
else
if ( upgrade_timer(pos) < home_miner ) then
default.home_boot(pos)
else
default.home_off(pos)
end
end
else
default.home_boot(pos)
end
else
default.home_off(pos)
end
end,
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
local meta = minetest.get_meta(pos)
if not computer_owner(meta, player) then
return 0
end
return count
end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
local meta = minetest.env:get_meta(pos)
if not computer_owner(meta, player) then
return 0
end
return stack:get_count()
end,
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
local meta = minetest.get_meta(pos)
if not computer_owner(meta, player) then
return 0
end
return stack:get_count()
end,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
return inv:is_empty("main") and inv:is_empty("exp1") and inv:is_empty("exp2") and inv:is_empty("exp3") and computer_owner(meta, player)
end,
})
minetest.register_node("cryptocoins:home_computer_active",{
drawtype = "nodebox",
description = "Home Computer",
tiles = {"cryptocoins_home_computer_tp.png","cryptocoins_home_computer_bt.png","cryptocoins_home_computer_rt.png","cryptocoins_home_computer_lt.png","cryptocoins_home_computer_bk.png","cryptocoins_home_computer_ft.png"},
paramtype = "light",
paramtype2 = "facedir",
light_source = 8,
drop = "cryptocoins:home_computer",
groups = {cracky=2, not_in_creative_inventory=1, oddly_breakable_by_hand=2},
node_box = {
type = "fixed",
fixed = {
{-0.500000,-0.500000,0.03125,0.500000,0.500000,0.40625},
{-0.40625,-0.40625,0.40625,0.40625,0.40625,0.50000},
{-0.500000,-0.500000,-0.500000,0.500000,-0.375,-0.03125},
},
},
sounds = default.node_sound_wood_defaults(),
on_timer = function(pos)
local timer = minetest.get_node_timer(pos)
local meta = minetest.get_meta(pos)
local node = minetest.get_node(pos)
local inv = meta:get_inventory()
local isp = minetest.find_node_near(pos, 1, {"cryptocoins:isp_on"})
if isp == nil then
local wifi = minetest.find_node_near(pos, 16, {"cryptocoins:router_on"})
if wifi == nil then
default.home_off(pos)
else
local meta = minetest.get_meta(pos)
if ( minetest.get_player_by_name(meta:get_string("owner")) == nil ) then
default.home_off(pos)
else
if ( upgrade_timer(pos) < home_miner ) then
timer:start(upgrade_timer(pos))
minetest.get_meta(pos):get_inventory():add_item("main", "cryptocoins:bitcent")
else
default.home_off(pos)
end
end
end
else
local meta = minetest.get_meta(pos)
if ( minetest.get_player_by_name(meta:get_string("owner")) == nil ) then
default.home_off(pos)
else
if ( upgrade_timer(pos) < home_miner ) then
minetest.get_meta(pos):get_inventory():add_item("main", "cryptocoins:bitcent")
timer:start(upgrade_timer(pos))
else
default.home_off(pos)
end
end
end
end,
on_punch = function(pos)
default.home_off(pos)
end,
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
local meta = minetest.get_meta(pos)
if not computer_owner(meta, player) then
return 0
end
return count
end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
local meta = minetest.env:get_meta(pos)
if not computer_owner(meta, player) then
return 0
end
return stack:get_count()
end,
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
local meta = minetest.get_meta(pos)
if not computer_owner(meta, player) then
return 0
end
return stack:get_count()
end,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
return inv:is_empty("main") and inv:is_empty("exp1") and inv:is_empty("exp2") and inv:is_empty("exp3") and computer_owner(meta, player)
end,
})