Lançamento
parent
4262446774
commit
dddb15fa8a
|
@ -0,0 +1,165 @@
|
|||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser General Public License from time to time. Such new
|
||||
versions will be similar in spirit to the present version, but may
|
||||
differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
39
README.md
39
README.md
|
@ -1 +1,38 @@
|
|||
macroloja
|
||||
# Macroloja v1.0.0
|
||||
|
||||
[![Baixar](https://img.shields.io/badge/Baixar-v1.0.0-green.svg)](https://github.com/BrunoMine/macroloja/archive/v1.0.0.zip)
|
||||
[![Projeto](https://img.shields.io/badge/Git-Projeto-green.svg)](https://github.com/BrunoMine/macroloja)
|
||||
[![!Bower](https://img.shields.io/badge/Bower-Projeto-green.svg)](https://minetest-bower.herokuapp.com/mods/macroloja)
|
||||
[![Licença](https://img.shields.io/badge/Licença-LGPL_v3.0-blue.svg)](https://github.com/BrunoMine/macroloja/blob/master/LICENSE)
|
||||
|
||||
## Descrição
|
||||
Adiciona um bau de troca de itens para lojas
|
||||
|
||||
## Recursos do projeto
|
||||
|
||||
* [Baixar](https://github.com/BrunoMine/macroloja/archive/v1.0.0.zip)
|
||||
* [Projeto](https://github.com/BrunoMine/macroloja)
|
||||
* [Bower](https://minetest-bower.herokuapp.com/mods/macroloja)
|
||||
|
||||
## Requisitos
|
||||
|
||||
* Minetest 0.4.16 ou superior
|
||||
* Mod default
|
||||
* Mod wool
|
||||
|
||||
## Privilégios
|
||||
|
||||
* `macroloja_admin` : Permite ver baus como administrador
|
||||
|
||||
## Licença
|
||||
Veja LICENSE.txt para informações detalhadas da licença LGPL 3.0
|
||||
|
||||
### Autores do código fonte
|
||||
Originalmente por BrunoMine, Bruno Borges <borgesdossantosbruno@gmail.com> (LGPL 3.0)
|
||||
|
||||
### Autores de mídias (texturas, modelos and sons)
|
||||
Todos que não estao listados aqui:
|
||||
BrunoMine, Bruno Borges <borgesdossantosbruno@gmail.com> (CC BY-SA 3.0)
|
||||
|
||||
Sir Smith (CC Sampling Plus 1.0)
|
||||
macroloja_troca.ogg
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
default
|
||||
wool
|
|
@ -0,0 +1,62 @@
|
|||
|
||||
-- Arredondar coordenada
|
||||
local arredondar = function(pos)
|
||||
local r = {}
|
||||
if pos.x > (math.floor(pos.x)+0.5) then
|
||||
r.x = math.ceil(pos.x)
|
||||
else
|
||||
r.x = math.floor(pos.x)
|
||||
end
|
||||
if pos.y > (math.floor(pos.y)+0.5) then
|
||||
r.y = math.ceil(pos.y)
|
||||
else
|
||||
r.y = math.floor(pos.y)
|
||||
end
|
||||
if pos.z > (math.floor(pos.z)+0.5) then
|
||||
r.z = math.ceil(pos.z)
|
||||
else
|
||||
r.z = math.floor(pos.z)
|
||||
end
|
||||
return r
|
||||
end
|
||||
|
||||
-- Puxar item para o centro
|
||||
local puxar_centro = function(pos)
|
||||
local cp = arredondar(pos)
|
||||
local r = {x=pos.x, y=pos.y, z=pos.z}
|
||||
|
||||
if pos.x > cp.x + 0.25 then
|
||||
r.x = cp.x + 0.25
|
||||
elseif pos.x < cp.x - 0.25 then
|
||||
r.x = cp.x - 0.25
|
||||
end
|
||||
if pos.z > cp.z + 0.25 then
|
||||
r.z = cp.z + 0.25
|
||||
elseif pos.z < cp.z - 0.25 then
|
||||
r.z = cp.z - 0.25
|
||||
end
|
||||
|
||||
return r
|
||||
end
|
||||
|
||||
-- Dropar itens de um inventario
|
||||
macroloja.drop_inventory = function(pos, inv, name)
|
||||
if not inv or not pos or not name then return false end
|
||||
|
||||
local size = inv:get_size(name)
|
||||
|
||||
for i = 1, size, 1 do
|
||||
local item = inv:get_stack(name, i)
|
||||
|
||||
if item ~= nil then
|
||||
local pd = {x = pos.x + (math.random(1, 60)/100)*2-0.6, y = pos.y+0.5, z = pos.z + (math.random(1, 60)/100)*2-0.6}
|
||||
if minetest.get_node(pd).name ~= "air" then
|
||||
pd = {x = pos.x + (math.random(1, 30)/100)*2-0.3, y = pos.y+0.5, z = pos.z + (math.random(1, 30)/100)*2-0.3}
|
||||
end
|
||||
|
||||
minetest.add_item(puxar_centro(pd), item)
|
||||
inv:set_stack(name, i, "")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,27 @@
|
|||
--
|
||||
-- Mod macroloja
|
||||
--
|
||||
-- Inicializador
|
||||
--
|
||||
|
||||
-- Notificador de Inicializador
|
||||
local notificar = function(msg)
|
||||
if minetest.setting_get("log_mods") then
|
||||
minetest.debug("[Macroloja] "..msg)
|
||||
end
|
||||
end
|
||||
|
||||
local modpath = minetest.get_modpath("macroloja")
|
||||
|
||||
-- Variavel global
|
||||
macroloja = {}
|
||||
|
||||
-- Carregar scripts
|
||||
notificar("Carregando...")
|
||||
dofile(modpath.."/shop.lua")
|
||||
dofile(modpath.."/drop.lua")
|
||||
notificar("OK")
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,439 @@
|
|||
|
||||
-- Criar verificador se o bau está sendo editado
|
||||
|
||||
-- Verificador de ultimo bau
|
||||
|
||||
|
||||
-- Privilegio para administradores verem e mexerem nos baus
|
||||
minetest.register_privilege("macroloja_admin", "Mexer em todos os baus de venda")
|
||||
|
||||
|
||||
-- Controle de bau acessado
|
||||
local acesso_bau = {}
|
||||
-- Remove valor quando jogador sair
|
||||
minetest.register_on_leaveplayer(function(player)
|
||||
acesso_bau[player:get_player_name()] = nil
|
||||
end)
|
||||
|
||||
-- Tocar som de troca feita
|
||||
local tocar_som_troca = function(pos)
|
||||
minetest.sound_play("macroloja_troca", {
|
||||
pos = pos,
|
||||
max_hear_distance = 5,
|
||||
gain = 1.0,
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
-- Trocar
|
||||
--[[
|
||||
Retorna nil caso os dados sejam invalidos
|
||||
Retorna 1 quando tudo deu certo
|
||||
Retorna 2 quando o vendedor esta lotado
|
||||
Retorna 3 quando o vendedor nao tem mais estoque
|
||||
Retorna 4 quando o jogador esta lotado
|
||||
Retorna 5 quando o jogador nao consegue pagar
|
||||
]]
|
||||
local trocar = function(inv_comprador, list_pagante, list_recebedor, inv_vendedor, list_estoque, list_lucro, list_custo, list_oferta)
|
||||
|
||||
-- Ajustar tabelas
|
||||
local tb_custo = {}
|
||||
local tb_oferta = {}
|
||||
for i=1, 4, 1 do
|
||||
local item = inv_vendedor:get_stack(list_custo, i)
|
||||
if item:get_name() ~= "" then
|
||||
if not tb_custo[item:get_name()] then
|
||||
tb_custo[item:get_name()] = item:get_count()
|
||||
else
|
||||
tb_custo[item:get_name()] = tb_custo[item:get_name()] + item:get_count()
|
||||
end
|
||||
end
|
||||
end
|
||||
for i=1, 4, 1 do
|
||||
local item = inv_vendedor:get_stack(list_oferta, i)
|
||||
if item:get_name() ~= "" then
|
||||
if not tb_oferta[item:get_name()] then
|
||||
tb_oferta[item:get_name()] = item:get_count()
|
||||
else
|
||||
tb_oferta[item:get_name()] = tb_oferta[item:get_name()] + item:get_count()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Verificar se vendedor consegue vender
|
||||
-- Verifica se vendedor possui estoque
|
||||
for item, qtd in pairs(tb_oferta) do
|
||||
if inv_vendedor:contains_item(list_estoque, item.." "..qtd) == false then
|
||||
return 3
|
||||
end
|
||||
end
|
||||
-- Verifica se vendedor esta lotado
|
||||
for item, qtd in pairs(tb_custo) do
|
||||
if inv_vendedor:room_for_item(list_lucro, item.." "..qtd) == false then
|
||||
return 2
|
||||
end
|
||||
end
|
||||
|
||||
-- Veriica se o comprador consegue comprar
|
||||
-- Verifica se comprador consegue pagar
|
||||
for item, qtd in pairs(tb_custo) do
|
||||
if inv_comprador:contains_item(list_pagante, item.." "..qtd) == false then
|
||||
return 5
|
||||
end
|
||||
end
|
||||
-- Verifica se comprador esta lotado
|
||||
for item, qtd in pairs(tb_oferta) do
|
||||
if inv_comprador:room_for_item(list_recebedor, item.." "..qtd) == false then
|
||||
return 4
|
||||
end
|
||||
end
|
||||
|
||||
-- Realiza a troca
|
||||
-- Retira itens do comprador e passa para o vendedor
|
||||
for item, qtd in pairs(tb_custo) do
|
||||
-- Retira itens do comprador
|
||||
inv_comprador:remove_item(list_pagante, item.." "..qtd)
|
||||
-- Adiciona itens ao vendedor
|
||||
inv_vendedor:add_item(list_lucro, item.." "..qtd)
|
||||
end
|
||||
-- Retira itens do vendedor e passa para o comprador
|
||||
for item, qtd in pairs(tb_oferta) do
|
||||
-- Retira itens do vendedor
|
||||
inv_vendedor:remove_item(list_estoque, item.." "..qtd)
|
||||
-- Adiciona itens ao comprador
|
||||
inv_comprador:add_item(list_recebedor, item.." "..qtd)
|
||||
end
|
||||
|
||||
return 1
|
||||
|
||||
end
|
||||
|
||||
-- Verificar se bau pode estar ativo
|
||||
local verif_bau_ativo = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
|
||||
-- Zerar numero de vendas
|
||||
meta:set_float("vendas", 0)
|
||||
|
||||
-- Verifica se um dos dois esta vazio
|
||||
if inv:is_empty("oferta") == true or inv:is_empty("custo") == true then
|
||||
meta:set_string("status", "inativo")
|
||||
return
|
||||
end
|
||||
|
||||
-- Verifica cada um dos itens de oferta
|
||||
for i=1, 4, 1 do
|
||||
local item = inv:get_stack("oferta", i)
|
||||
if item:get_wear() ~= 0 or item:get_metadata() ~= "" then
|
||||
meta:set_string("status", "inativo")
|
||||
return
|
||||
end
|
||||
end
|
||||
-- Verifica cada um dos itens de custo
|
||||
for i=1, 4, 1 do
|
||||
local item = inv:get_stack("custo", i)
|
||||
if item:get_wear() ~= 0 or item:get_metadata() ~= "" then
|
||||
meta:set_string("status", "inativo")
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
-- Ativa o bau para vendas
|
||||
meta:set_string("status", "ativo")
|
||||
|
||||
end
|
||||
|
||||
-- Bau de venda
|
||||
minetest.register_node("macroloja:shop", {
|
||||
|
||||
description = "Bau de Venda",
|
||||
paramtype2 = "facedir",
|
||||
tiles = {
|
||||
"default_chest_top.png",
|
||||
"default_chest_top.png^macroloja_shop_top.png",
|
||||
"default_chest_side.png",
|
||||
"default_chest_side.png",
|
||||
"default_chest_front.png",
|
||||
"default_chest_inside.png^macroloja_shop_front.png"
|
||||
},
|
||||
tiles = {
|
||||
"default_chest_top.png^macroloja_shop_top.png",
|
||||
"default_chest_top.png",
|
||||
"default_chest_side.png",
|
||||
"default_chest_side.png",
|
||||
"default_chest_side.png",
|
||||
"default_chest_front.png^macroloja_shop_front.png"
|
||||
},
|
||||
groups = {choppy=2,oddly_breakable_by_hand=2},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
|
||||
|
||||
can_dig = function(pos, player)
|
||||
if player:get_player_name() == minetest.get_meta(pos):get_string("dono")
|
||||
or minetest.check_player_privs(player:get_player_name(), {macroloja_admin=true})
|
||||
then
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end,
|
||||
|
||||
after_place_node = function(pos, placer, itemstack)
|
||||
|
||||
-- Salvar metadados iniciais
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("infotext", "Bau de Venda (Vendedor "..placer:get_player_name()..")")
|
||||
meta:set_string("dono", placer:get_player_name())
|
||||
meta:set_string("status", "inativo")
|
||||
meta:set_float("vendas", 0)
|
||||
|
||||
-- Inventarios do bau
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("oferta", 4*1)
|
||||
inv:set_size("custo", 4*1)
|
||||
inv:set_size("estoque", 2*4)
|
||||
inv:set_size("lucro", 2*4)
|
||||
|
||||
end,
|
||||
|
||||
on_rightclick = function(pos, node, clicker, itemstack)
|
||||
|
||||
local name = clicker:get_player_name()
|
||||
local meta = minetest.get_meta(pos)
|
||||
|
||||
-- Armazena o bau acessado
|
||||
acesso_bau[name] = pos
|
||||
|
||||
-- Acesso do dono
|
||||
if name == minetest.get_meta(pos):get_string("dono")
|
||||
or minetest.check_player_privs(name, {macroloja_admin=true})
|
||||
then
|
||||
|
||||
-- Exibe formspec
|
||||
minetest.show_formspec(name, "macroloja:shop_dono",
|
||||
"size[10,9]"
|
||||
|
||||
-- Inventario do jogador
|
||||
..default.gui_bg
|
||||
..default.gui_bg_img
|
||||
..default.gui_slots
|
||||
.."list[current_player;main;1,4.85;8,1;]"
|
||||
.."list[current_player;main;1,6.08;8,3;8]"
|
||||
.."listring[current_player;main]"
|
||||
..default.get_hotbar_bg(1,4.85)
|
||||
|
||||
-- Estoque
|
||||
.."label[0,-0.1;Estoque]"
|
||||
.."list[nodemeta:"..pos.x..","..pos.y..","..pos.z..";estoque;0,0.3;2,4;]"
|
||||
.."listring[nodemeta:"..pos.x..","..pos.y..","..pos.z..";estoque]"
|
||||
|
||||
-- Lucro
|
||||
.."label[8,-0.1;Lucro]"
|
||||
.."list[nodemeta:"..pos.x..","..pos.y..","..pos.z..";lucro;8,0.3;2,4;]"
|
||||
.."listring[nodemeta:"..pos.x..","..pos.y..","..pos.z..";lucro]"
|
||||
|
||||
-- Oferta
|
||||
.."label[3,0.3;Oferta]"
|
||||
.."list[nodemeta:"..pos.x..","..pos.y..","..pos.z..";oferta;3,0.8;4,1;]"
|
||||
.."listring[nodemeta:"..pos.x..","..pos.y..","..pos.z..";oferta]"
|
||||
.."image[2,0.8;1,1;gui_furnace_arrow_bg.png^[transformR270]"
|
||||
|
||||
-- Custo
|
||||
.."label[3,2.3;Custo]"
|
||||
.."list[nodemeta:"..pos.x..","..pos.y..","..pos.z..";custo;3,2.8;4,1;]"
|
||||
.."listring[nodemeta:"..pos.x..","..pos.y..","..pos.z..";custo]"
|
||||
.."image[7,2.8;1,1;gui_furnace_arrow_bg.png^[transformR270]"
|
||||
|
||||
-- Seta pra baixo
|
||||
.."image[4.5,1.8;1,1;gui_furnace_arrow_bg.png^[transformR180]"
|
||||
|
||||
-- Trocas feitas
|
||||
.."label[3,3.8;Vendas feitas: "..meta:get_float("vendas").."]"
|
||||
|
||||
-- Botoes de troca rapida [CANCELADOS]
|
||||
--.."image_button[0,4.3;1,1;macroloja_bt_fast_up.png;reabastecer;]"
|
||||
--.."image_button[9,4.3;1,1;macroloja_bt_fast_down.png;receber;]"
|
||||
|
||||
)
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
-- Exibe formspec
|
||||
minetest.show_formspec(name, "macroloja:shop",
|
||||
"size[8,9]"
|
||||
|
||||
-- Inventario do jogador
|
||||
..default.gui_bg
|
||||
..default.gui_bg_img
|
||||
..default.gui_slots
|
||||
.."list[current_player;main;0,4.85;8,1;]"
|
||||
.."list[current_player;main;0,6.08;8,3;8]"
|
||||
.."listring[current_player;main]"
|
||||
..default.get_hotbar_bg(0,4.85)
|
||||
|
||||
-- Custo
|
||||
.."label[2,0.3;Custo]"
|
||||
.."list[nodemeta:"..pos.x..","..pos.y..","..pos.z..";custo;2,0.8;4,1;]"
|
||||
.."listring[nodemeta:"..pos.x..","..pos.y..","..pos.z..";custo]"
|
||||
|
||||
-- Oferta
|
||||
.."label[2,2.8;Oferta]"
|
||||
.."list[nodemeta:"..pos.x..","..pos.y..","..pos.z..";oferta;2,3.3;4,1;]"
|
||||
.."listring[nodemeta:"..pos.x..","..pos.y..","..pos.z..";oferta]"
|
||||
|
||||
-- Seta pra baixo
|
||||
.."image[2,1.8;1,1;gui_furnace_arrow_bg.png^[transformR180]"
|
||||
|
||||
-- Botão de troca
|
||||
.."button[3,1.8;2,1;trocar;Comprar]"
|
||||
|
||||
-- Botoes de troca rapida
|
||||
.."image_button[5,1.8;1,1;macroloja_bt_fast_down.png;trocar10x;10x]"
|
||||
|
||||
)
|
||||
|
||||
end,
|
||||
|
||||
on_destruct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
|
||||
-- Dropar itens
|
||||
macroloja.drop_inventory(pos, inv, "estoque")
|
||||
macroloja.drop_inventory(pos, inv, "oferta")
|
||||
macroloja.drop_inventory(pos, inv, "custo")
|
||||
macroloja.drop_inventory(pos, inv, "lucro")
|
||||
|
||||
end,
|
||||
|
||||
-- Verificar permissão de acesso ao bau
|
||||
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||
if player:get_player_name() == minetest.get_meta(pos):get_string("dono")
|
||||
or minetest.check_player_privs(player:get_player_name(), {macroloja_admin=true})
|
||||
then return count else return 0 end
|
||||
end,
|
||||
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||
if player:get_player_name() == minetest.get_meta(pos):get_string("dono")
|
||||
or minetest.check_player_privs(player:get_player_name(), {macroloja_admin=true})
|
||||
then return stack:get_count() else return 0 end
|
||||
end,
|
||||
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||
if player:get_player_name() == minetest.get_meta(pos):get_string("dono")
|
||||
or minetest.check_player_privs(player:get_player_name(), {macroloja_admin=true})
|
||||
then return stack:get_count() else return 0 end
|
||||
end,
|
||||
|
||||
-- Verificar se mudança no inventario permite ativar trocas
|
||||
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||
if from_list == "oferta" or from_list == "custo"
|
||||
or to_list == "oferta" or to_list == "custo"
|
||||
then verif_bau_ativo(pos) end
|
||||
end,
|
||||
on_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||
if listname == "custo" or listname == "oferta" then verif_bau_ativo(pos) end
|
||||
end,
|
||||
on_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||
if listname == "custo" or listname == "oferta" then verif_bau_ativo(pos) end
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
|
||||
-- Clientes
|
||||
if formname == "macroloja:shop" then
|
||||
local name = player:get_player_name()
|
||||
local pos = acesso_bau[name]
|
||||
local meta = minetest.get_meta(pos)
|
||||
|
||||
|
||||
-- Troca
|
||||
if fields.trocar and meta:get_string("status") == "ativo" then
|
||||
|
||||
-- Tentativa de troca
|
||||
local troca = trocar(player:get_inventory(), "main", "main", meta:get_inventory(), "estoque", "lucro", "custo", "oferta")
|
||||
|
||||
if troca == 2 then
|
||||
minetest.chat_send_player(name, "Bau com problemas de estoque. Aguarde o vendedor verificar.")
|
||||
elseif troca == 3 then
|
||||
minetest.chat_send_player(name, "Bau com problemas de estoque. Aguarde o vendedor verificar.")
|
||||
elseif troca == 4 then
|
||||
minetest.chat_send_player(name, "Inventario lotado. Esvazie um pouco seu inventario.")
|
||||
elseif troca == 5 then
|
||||
minetest.chat_send_player(name, "Itens insuficientes para pagar pela compra.")
|
||||
end
|
||||
|
||||
if troca == 1 then
|
||||
|
||||
meta:set_float("vendas", meta:get_float("vendas") + 1)
|
||||
|
||||
-- Tocar som de troca feita
|
||||
tocar_som_troca(pos)
|
||||
|
||||
end
|
||||
|
||||
return
|
||||
|
||||
elseif fields.trocar10x then
|
||||
|
||||
-- Tentativa de primeira troca
|
||||
local troca = trocar(player:get_inventory(), "main", "main", meta:get_inventory(), "estoque", "lucro", "custo", "oferta")
|
||||
|
||||
if troca == 2 then
|
||||
minetest.chat_send_player(name, "Bau com problemas de estoque. Aguarde o vendedor verificar.")
|
||||
elseif troca == 3 then
|
||||
minetest.chat_send_player(name, "Bau com problemas de estoque. Aguarde o vendedor verificar.")
|
||||
elseif troca == 4 then
|
||||
minetest.chat_send_player(name, "Inventario lotado. Esvazie um pouco seu inventario.")
|
||||
elseif troca == 5 then
|
||||
minetest.chat_send_player(name, "Itens insuficientes para pagar pela compra.")
|
||||
end
|
||||
|
||||
if troca == 1 then
|
||||
|
||||
meta:set_float("vendas", meta:get_float("vendas") + 1)
|
||||
|
||||
-- Tocar som de troca feita
|
||||
tocar_som_troca(pos)
|
||||
|
||||
-- Tenta trocar mais 9
|
||||
do
|
||||
local i = 0
|
||||
while i < 9
|
||||
and trocar(player:get_inventory(), "main", "main", meta:get_inventory(), "estoque", "lucro", "custo", "oferta") == 1
|
||||
do
|
||||
meta:set_float("vendas", meta:get_float("vendas") + 1)
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-- Tocar som de troca feita
|
||||
tocar_som_troca(pos)
|
||||
|
||||
return
|
||||
|
||||
elseif fields.quit then
|
||||
|
||||
return
|
||||
|
||||
-- Nenhum botao valido ate aqui
|
||||
else
|
||||
minetest.chat_send_player(name, "Bau de venda inativo")
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
-- Bau de Venda
|
||||
minetest.register_craft({
|
||||
output = 'macroloja:shop',
|
||||
recipe = {
|
||||
{'wool:green', 'wool:white', 'wool:green'},
|
||||
{'wool:blue', 'default:chest_locked', 'wool:blue'},
|
||||
{'default:wood', 'default:wood', 'default:wood'},
|
||||
}
|
||||
})
|
||||
|
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 9.4 KiB |
Binary file not shown.
After Width: | Height: | Size: 505 B |
Binary file not shown.
After Width: | Height: | Size: 617 B |
Loading…
Reference in New Issue