Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
bitchange
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Illuna-Minetest
bitchange
Commits
70f31b76
Commit
70f31b76
authored
8 years ago
by
SmallJoker
Browse files
Options
Downloads
Patches
Plain Diff
Shop: Clean up code, fix item repair cheat
parent
b52f70c0
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
shop.lua
+76
-61
76 additions, 61 deletions
shop.lua
with
76 additions
and
61 deletions
shop.lua
+
76
−
61
View file @
70f31b76
...
...
@@ -128,121 +128,134 @@ minetest.register_on_player_receive_fields(function(sender, formname, fields)
if
fields
.
exchange
then
local
shop_inv
=
meta
:
get_inventory
()
if
shop_inv
:
is_empty
(
"cust_ow"
)
and
shop_inv
:
is_empty
(
"cust_og"
)
then
if
shop_inv
:
is_empty
(
"cust_ow"
)
and
shop_inv
:
is_empty
(
"cust_og"
)
then
return
end
if
not
shop_inv
:
is_empty
(
"cust_ej"
)
or
not
shop_inv
:
is_empty
(
"custm_ej"
)
then
minetest
.
chat_send_player
(
player_name
,
"Exchange shop: Error, ejected items detected!"
)
if
not
shop_inv
:
is_empty
(
"cust_ej"
)
or
not
shop_inv
:
is_empty
(
"custm_ej"
)
then
minetest
.
chat_send_player
(
player_name
,
"One or multiple ejection fields are filled. "
..
"Please empty them or contact the shop owner."
)
return
end
local
player_inv
=
sender
:
get_inventory
()
local
err_msg
=
""
local
cust_ow
=
shop_inv
:
get_list
(
"cust_ow"
)
local
cust_og
=
shop_inv
:
get_list
(
"cust_og"
)
local
cust_ow_legal
=
true
local
cust_og_legal
=
true
--?shop configured well
-- Check validness of stack "owner wants"
local
cust_ow_ok
=
true
for
i1
,
item1
in
pairs
(
cust_ow
)
do
local
name1
=
item1
:
get_name
()
for
i2
,
item2
in
pairs
(
cust_ow
)
do
if
item1
:
get_name
()
==
item2
:
get_name
()
and
i1
~=
i2
and
item1
:
get_name
()
~=
""
then
cust_ow_legal
=
false
--break
if
name1
==
""
then
break
end
if
i1
~=
i2
and
name1
==
item2
:
get_name
()
then
cust_ow_ok
=
false
break
end
end
if
not
cust_ow_legal
then
if
not
cust_ow_ok
then
err_msg
=
"The field 'Owner needs' can not contain multiple "
..
"times the same items. Please contact the shop owner."
break
end
end
if
not
cust_ow_legal
then
err_msg
=
"The 'Owner needs' field can not contain multiple times the same items, contact the shop owner.
"
en
d
if
err_msg
==
""
then
--?shop configured well
-- Check validness of stack "owner gives
"
if
err_msg
==
""
th
en
local
cust_og_ok
=
true
for
i1
,
item1
in
pairs
(
cust_og
)
do
local
name1
=
item1
:
get_name
()
for
i2
,
item2
in
pairs
(
cust_og
)
do
if
item1
:
get_name
()
==
item2
:
get_name
()
and
i1
~=
i2
and
item1
:
get_name
()
~=
""
then
cust_og_legal
=
false
if
name1
==
""
then
break
end
if
i1
~=
i2
and
name1
==
item2
:
get_name
()
then
cust_og_ok
=
false
break
end
end
if
not
cust_og_legal
then
if
not
cust_og_ok
then
err_msg
=
"The field 'Owner gives' can not contain multiple "
..
"times the same items. Please contact the shop owner."
break
end
end
if
not
cust_og_legal
then
err_msg
=
"The 'Owner gives' field can not contain multiple times the same items, contact the shop owner."
end
end
if
err_msg
==
""
then
--?shop has space
local
shop_has_space
=
true
-- Check for space in the shop
if
err_msg
==
""
then
for
i
,
item
in
pairs
(
cust_ow
)
do
if
not
shop_inv
:
room_for_item
(
"custm"
,
item
)
then
shop_has_space
=
false
err_msg
=
"The stock in this shop is full. "
..
"Please contact the shop owner."
break
end
end
if
not
shop_has_space
then
err_msg
=
"The stock in the shop is full."
end
end
if
err_msg
==
""
then
--?shop has items
local
shop_has_items
=
true
-- Check availability of the shop's items
if
err_msg
==
""
then
for
i
,
item
in
pairs
(
cust_og
)
do
if
not
shop_inv
:
contains_item
(
"stock"
,
item
)
then
shop_has_items
=
false
err_msg
=
"This shop is sold out."
break
end
end
if
not
shop_has_items
then
err_msg
=
"The shop is empty and can not give you anything."
end
end
if
err_msg
==
""
then
--?player has space
local
player_has_space
=
true
-- Check for space in the player's inventory
if
err_msg
==
""
then
for
i
,
item
in
pairs
(
cust_og
)
do
if
not
player_inv
:
room_for_item
(
"main"
,
item
)
then
player_has_space
=
false
err_msg
=
"You do not have enough space in your inventory."
break
end
end
if
not
player_has_space
then
err_msg
=
"You do not have the space in your inventory."
end
end
if
err_msg
==
""
then
--?player has items
local
player_has_items
=
true
-- Check availability of the player's items
if
err_msg
==
""
then
for
i
,
item
in
pairs
(
cust_ow
)
do
if
not
player_inv
:
contains_item
(
"main"
,
item
)
then
player_has_items
=
false
err_msg
=
"You do not have the required items."
break
end
end
if
not
player_has_items
then
err_msg
=
"You do not have the needed items."
end
end
if
err_msg
==
""
then
--?exchange
-- Do the exchange!
if
err_msg
==
""
then
local
fully_exchanged
=
true
for
i
,
item
in
pairs
(
cust_ow
)
do
player_inv
:
remove_item
(
"main"
,
item
)
--player inv. to stock else to eject fields
if
shop_inv
:
room_for_item
(
"custm"
,
item
)
then
shop_inv
:
add_item
(
"custm"
,
item
)
local
stack
=
player_inv
:
remove_item
(
"main"
,
item
)
if
shop_inv
:
room_for_item
(
"custm"
,
stack
)
then
shop_inv
:
add_item
(
"custm"
,
stack
)
else
shop_inv
:
add_item
(
"custm_ej"
,
item
)
-- Move to ejection field
shop_inv
:
add_item
(
"custm_ej"
,
stack
)
fully_exchanged
=
false
end
end
for
i
,
item
in
pairs
(
cust_og
)
do
shop_inv
:
remove_item
(
"stock"
,
item
)
--stock to player inv. else to eject fields
if
player_inv
:
room_for_item
(
"main"
,
item
)
then
player_inv
:
add_item
(
"main"
,
item
)
local
stack
=
shop_inv
:
remove_item
(
"stock"
,
item
)
if
player_inv
:
room_for_item
(
"main"
,
stack
)
then
player_inv
:
add_item
(
"main"
,
stack
)
else
shop_inv
:
add_item
(
"cust_ej"
,
item
)
-- Move to ejection field
shop_inv
:
add_item
(
"cust_ej"
,
stack
)
fully_exchanged
=
false
end
end
if
not
fully_exchanged
then
err_msg
=
"
Fatal error
! St
o
cks are overflowing somewhere!"
err_msg
=
"
Warning
! St
a
cks are overflowing somewhere!"
end
end
-- Throw error message
if
err_msg
~=
""
then
minetest
.
chat_send_player
(
player_name
,
"Exchange shop: "
..
err_msg
)
end
...
...
@@ -290,12 +303,12 @@ minetest.register_node("bitchange:shop", {
can_dig
=
function
(
pos
,
player
)
local
meta
=
minetest
.
get_meta
(
pos
);
local
inv
=
meta
:
get_inventory
()
if
(
inv
:
is_empty
(
"stock"
)
and
inv
:
is_empty
(
"custm"
)
and
inv
:
is_empty
(
"custm_ej"
)
and
inv
:
is_empty
(
"cust_ow"
)
and
inv
:
is_empty
(
"cust_og"
)
and
inv
:
is_empty
(
"cust_ej"
)
)
then
if
inv
:
is_empty
(
"stock"
)
and
inv
:
is_empty
(
"custm"
)
and
inv
:
is_empty
(
"cust_ow"
)
and
inv
:
is_empty
(
"custm_ej"
)
and
inv
:
is_empty
(
"cust_og"
)
and
inv
:
is_empty
(
"cust_ej"
)
then
return
true
end
minetest
.
chat_send_player
(
player
:
get_player_name
(),
"Can
not dig exchange shop
,
one or multiple stocks are in use."
)
minetest
.
chat_send_player
(
player
:
get_player_name
(),
"Cannot dig exchange shop
:
one or multiple stocks are in use."
)
return
false
end
,
on_rightclick
=
function
(
pos
,
node
,
clicker
,
itemstack
)
...
...
@@ -330,8 +343,9 @@ minetest.register_node("bitchange:shop", {
return
0
end
local
meta
=
minetest
.
get_meta
(
pos
)
if
bitchange
.
has_access
(
meta
:
get_string
(
"owner"
),
player
:
get_player_name
())
and
listname
~=
"cust_ej"
and
listname
~=
"custm_ej"
then
if
bitchange
.
has_access
(
meta
:
get_string
(
"owner"
),
player
:
get_player_name
())
and
listname
~=
"cust_ej"
and
listname
~=
"custm_ej"
then
return
stack
:
get_count
()
end
return
0
...
...
@@ -341,7 +355,8 @@ minetest.register_node("bitchange:shop", {
return
stack
:
get_count
()
end
local
meta
=
minetest
.
get_meta
(
pos
)
if
bitchange
.
has_access
(
meta
:
get_string
(
"owner"
),
player
:
get_player_name
())
or
listname
==
"cust_ej"
then
if
bitchange
.
has_access
(
meta
:
get_string
(
"owner"
),
player
:
get_player_name
())
or
listname
==
"cust_ej"
then
return
stack
:
get_count
()
end
return
0
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment