Lançamento
|
@ -0,0 +1,32 @@
|
|||
API.txt
|
||||
|
||||
Pontos importantes
|
||||
* Jamais pode existir dois item como o mesmo nome (description)
|
||||
* So pode montar 1 item especial por vez (jamais quantidades acima de 1 por vez)
|
||||
* Pode ter de 1 a 6 tipos de itens requisitados podem variar suas quantidades individuais
|
||||
* Apos o jogador sair do servidor os seus dados nao serao mais encontrados ate que entre novamente
|
||||
* Nao pode existir itens cujo tempo total de montagem seja menor que 1 minuto (minimo 1 minuto)
|
||||
* A principio nao deve existir mais de 10 receitas por oficio para nao travar muito o sistema e os jogadores
|
||||
* Jamais usar itens com o profixo group nas strings dos itens (ex.: "groups:stick", "groups") ou qualquer outro prefixo
|
||||
|
||||
Funcoao de insercao no banco de dados (todos os valores sao obrigatorios)
|
||||
oficios.montar_receita(
|
||||
|
||||
oficio, -- Nome do oficio que podera realizar (ex. "cozinheiro")
|
||||
|
||||
item, -- Item a ser criado (ex. "default:wood")
|
||||
|
||||
nivel, -- Nivel requerido (ex. 5)
|
||||
|
||||
desc, -- Breve descricao do item com ate 4 linhas com ate 26 caracteres de largura mediana
|
||||
(ex. "Esse item pode ser util \nem varios casos e lhe traz \nmelhor desempenho no jogo.")
|
||||
|
||||
xp, -- Quantidade de XP recebido ao terminar (ex. 20)
|
||||
|
||||
item_requisitado, -- Tabela de itens requeridos (de 1 a 6 itens) (ex. {{"default:stone", 5},{"default:stick", 1}})
|
||||
|
||||
tempo -- Tempo que demora para concluir em dias(0 a 25), horas(0 a 23) e minutos(0 a 59) no formato {dd,hh,mm}
|
||||
(ex. {00,00,05})
|
||||
|
||||
)
|
||||
|
|
@ -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.
|
30
README.md
|
@ -1 +1,29 @@
|
|||
oficios
|
||||
# Oficios v1.0.0
|
||||
|
||||
[![Baixar](https://img.shields.io/badge/Baixar-v1.0.0-green.svg)](https://github.com/BrunoMine/oficios/archive/v1.0.0.zip)
|
||||
[![Projeto](https://img.shields.io/badge/Git-Projeto-green.svg)](https://github.com/BrunoMine/oficios)
|
||||
[![Licença](https://img.shields.io/badge/Licença-LGPL_v3.0-blue.svg)](https://github.com/BrunoMine/oficios/blob/master/LICENSE)
|
||||
|
||||
## Descrição
|
||||
API de oficios
|
||||
|
||||
## Recursos do projeto
|
||||
|
||||
* [Baixar](https://github.com/BrunoMine/oficios/archive/v1.0.0.zip)
|
||||
* [Projeto](https://github.com/BrunoMine/oficios)
|
||||
|
||||
## Requisitos
|
||||
|
||||
* Minetest 0.4.15 ou superior
|
||||
* Mod default
|
||||
|
||||
## 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 os que não estão listados aqui são de autoria de
|
||||
BrunoMine, Bruno Borges <borgesdossantosbruno@gmail.com> (CC BY-SA 3.0)
|
||||
|
||||
|
|
|
@ -0,0 +1,162 @@
|
|||
--[[
|
||||
Mod Oficios para Minetest
|
||||
Copyright (C) 2017 BrunoMine (https://github.com/BrunoMine)
|
||||
|
||||
Recebeste uma cópia da GNU Lesser General
|
||||
Public License junto com esse software,
|
||||
se não, veja em <http://www.gnu.org/licenses/>.
|
||||
|
||||
Banco de Dados
|
||||
]]
|
||||
|
||||
oficios.bd = {}
|
||||
|
||||
-- Variavel de registros
|
||||
registros_oficios = {}
|
||||
|
||||
-- Carregar registros de oficios salvos
|
||||
local path = minetest.get_worldpath() .. "/oficios"
|
||||
-- Cria o diretorio caso nao exista ainda
|
||||
local function mkdir(path)
|
||||
if minetest.mkdir then
|
||||
minetest.mkdir(path)
|
||||
else
|
||||
os.execute('mkdir "' .. path .. '"')
|
||||
end
|
||||
end
|
||||
mkdir(path)
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
local input = io.open(path .. "/oficios_"..name, "r")
|
||||
if input then
|
||||
registros_oficios[name] = minetest.deserialize(input:read("*l"))
|
||||
io.close(input)
|
||||
end
|
||||
end)
|
||||
|
||||
-- Retira da memoria quando o jogador sai
|
||||
minetest.register_on_leaveplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
registros_oficios[name] = nil
|
||||
end)
|
||||
|
||||
-- Salvar registros de oficios
|
||||
oficios.bd.salvar = function(name)
|
||||
local output = io.open(path .. "/oficios_"..name, "w")
|
||||
output:write(minetest.serialize(registros_oficios[name]))
|
||||
io.close(output)
|
||||
end
|
||||
|
||||
-- Inserir registro
|
||||
oficios.bd.inserir = function(name)
|
||||
if not name then
|
||||
minetest.log("error", "[Oficios]: variavel name invalida (name = "..dump(name)..")")
|
||||
return false
|
||||
end
|
||||
registros_oficios[name] = {
|
||||
oficio = "nenhum", -- Tipo de Ofício
|
||||
nivel = 1, -- Nível
|
||||
xp = 0, -- Quantidade de experiencia
|
||||
montagem = {
|
||||
status = false, -- Se está montando
|
||||
item = "", -- Nome do item que está sendo montado
|
||||
data_fim = 0 -- Data de termino da montagem
|
||||
},
|
||||
total_itens = 0, -- Total de itens feitos
|
||||
coletar = "" -- Item a coletar
|
||||
}
|
||||
oficios.bd.salvar(name)
|
||||
end
|
||||
|
||||
-- Coletou o item
|
||||
oficios.bd.coletou_item = function(name)
|
||||
registros_oficios[name].coletar = ""
|
||||
oficios.bd.salvar(name)
|
||||
end
|
||||
|
||||
-- Iniciar montagem
|
||||
oficios.bd.iniciar_montagem = function(name, item, data_fim)
|
||||
registros_oficios[name].montagem.status = true
|
||||
registros_oficios[name].montagem.item = item
|
||||
registros_oficios[name].montagem.data_fim = data_fim
|
||||
oficios.bd.salvar(name)
|
||||
end
|
||||
|
||||
-- Concluir montagem
|
||||
oficios.bd.conluir_montagem = function(name, xp)
|
||||
registros_oficios[name].montagem.status = false
|
||||
registros_oficios[name].coletar = oficios.receitas[registros_oficios[name].montagem.item].item
|
||||
registros_oficios[name].montagem.item = ""
|
||||
registros_oficios[name].montagem.data_fim = 0
|
||||
registros_oficios[name].total_itens = registros_oficios[name].total_itens + 1
|
||||
if (registros_oficios[name].xp + xp) > LIMITE_DE_XP then
|
||||
registros_oficios[name].xp = LIMITE_DE_XP
|
||||
else
|
||||
registros_oficios[name].xp = registros_oficios[name].xp + xp
|
||||
end
|
||||
-- atualizar nivel
|
||||
local nivel_atual = 1
|
||||
if registros_oficios[name].xp == LIMITE_DE_XP then
|
||||
nivel_atual = LIMITE_DE_NIVEL
|
||||
else
|
||||
while registros_oficios[name].xp >= OFICIOS_NIVEIS[nivel_atual+1] do
|
||||
nivel_atual = nivel_atual + 1
|
||||
end
|
||||
end
|
||||
registros_oficios[name].nivel = nivel_atual
|
||||
oficios.bd.salvar(name)
|
||||
end
|
||||
|
||||
-- Definir Oficio
|
||||
oficios.bd.definir_oficio = function(name, oficio)
|
||||
registros_oficios[name].oficio = oficio
|
||||
oficios.bd.salvar(name)
|
||||
end
|
||||
|
||||
-- Aumentar experiencia
|
||||
oficios.bd.aumentar_xp = function(name, valor)
|
||||
if (registros_oficios[name].xp + valor) > LIMITE_DE_XP then
|
||||
registros_oficios[name].xp = LIMITE_DE_XP
|
||||
else
|
||||
registros_oficios[name].xp = registros_oficios[name].xp + valor
|
||||
end
|
||||
-- atualizar nivel
|
||||
local nivel_atual = 1
|
||||
if registros_oficios[name].xp == LIMITE_DE_XP then
|
||||
nivel_atual = LIMITE_DE_NIVEL
|
||||
else
|
||||
while registros_oficios[name].xp >= OFICIOS_NIVEIS[nivel_atual+1] do
|
||||
nivel_atual = nivel_atual + 1
|
||||
end
|
||||
end
|
||||
registros_oficios[name].nivel = nivel_atual
|
||||
oficios.bd.salvar(name)
|
||||
end
|
||||
|
||||
-- Diminuir experiencia
|
||||
oficios.bd.diminuir_xp = function(name, valor)
|
||||
if registros_oficios[name].xp < valor then
|
||||
registros_oficios[name].xp = 0
|
||||
else
|
||||
registros_oficios[name].xp = registros_oficios[name].xp - valor
|
||||
end
|
||||
-- atualizar nivel
|
||||
local nivel_atual = 1
|
||||
if registros_oficios[name].xp == LIMITE_DE_XP then
|
||||
nivel_atual = LIMITE_DE_NIVEL
|
||||
else
|
||||
while registros_oficios[name].xp >= OFICIOS_NIVEIS[nivel_atual+1] do
|
||||
nivel_atual = nivel_atual + 1
|
||||
end
|
||||
end
|
||||
registros_oficios[name].nivel = nivel_atual
|
||||
oficios.bd.salvar(name)
|
||||
end
|
||||
|
||||
-- Registra apenas novos jogadores
|
||||
minetest.register_on_newplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
oficios.bd.inserir(name)
|
||||
end)
|
||||
|
||||
|
|
@ -0,0 +1,208 @@
|
|||
--[[
|
||||
Mod Oficios para Minetest
|
||||
Copyright (C) 2017 BrunoMine (https://github.com/BrunoMine)
|
||||
|
||||
Recebeste uma cópia da GNU Lesser General
|
||||
Public License junto com esse software,
|
||||
se não, veja em <http://www.gnu.org/licenses/>.
|
||||
|
||||
Contador de tempo
|
||||
]]
|
||||
|
||||
-- Quantos dias tem cada mes
|
||||
local dias_meses = {
|
||||
31, -- Janeiro
|
||||
28, -- Fevereiro (29 em ano bissexto)
|
||||
31, -- Março
|
||||
30, -- Abril
|
||||
31, -- Maio
|
||||
30, -- Junho
|
||||
31, -- Julho
|
||||
31, -- Agosto
|
||||
30, -- Setembro
|
||||
31, -- Outubro
|
||||
30, -- Novembro
|
||||
31 -- Dezembro
|
||||
}
|
||||
|
||||
-- Pegar dias do mes naquele ano
|
||||
local pegar_dias_mes = function(mes, ano)
|
||||
|
||||
-- converter para valor numerico
|
||||
mes = tonumber(mes)
|
||||
ano = tonumber(ano)
|
||||
|
||||
-- ajustando para numero entre 1 e 12
|
||||
if mes > 12 then mes = mes - (math.floor(mes/12)*12) end
|
||||
|
||||
-- caso o mes de zero
|
||||
if mes == 0 then mes = 12 end
|
||||
|
||||
if mes == 2 and math.fmod(ano, 4) == 0 then
|
||||
return dias_meses[mes] + 1
|
||||
else
|
||||
return dias_meses[mes]
|
||||
end
|
||||
end
|
||||
|
||||
-- Pegar numero maior
|
||||
local pegar_maior = function(n1, n2)
|
||||
if tonumber(n1) > tonumber(n2) then
|
||||
return n1
|
||||
else
|
||||
return n2
|
||||
end
|
||||
end
|
||||
|
||||
-- Pegar numero menor
|
||||
local pegar_menor = function(n1, n2)
|
||||
if n1 < n2 then
|
||||
return n1
|
||||
else
|
||||
return n2
|
||||
end
|
||||
end
|
||||
|
||||
-- Comparar data
|
||||
--[[
|
||||
Esse metodo recebe uma data como argumento e retorna
|
||||
as quantidades de dias, horas e minutos em relação à
|
||||
data atual
|
||||
Retorno:
|
||||
<diferença de dias>
|
||||
<diferença de horas>
|
||||
<diferença de minutos>
|
||||
Argumentos:
|
||||
<ano da data>
|
||||
<mes da data>
|
||||
<dia do mes da data>
|
||||
<hora do dia da data>
|
||||
<minutos da hora do dia da data>
|
||||
]]
|
||||
oficios.comparar_data = function(ano, mes, dia, hora, minuto)
|
||||
if not ano or not tonumber(ano) then
|
||||
minetest.log("error", "[Oficios] Ano invalido em especificado (em oficios.comparar_data)")
|
||||
return false
|
||||
end
|
||||
if not mes or not tonumber(mes) then
|
||||
minetest.log("error", "[Oficios] Mes invalido em especificado (em oficios.comparar_data)")
|
||||
return false
|
||||
end
|
||||
if not dia or not tonumber(dia) then
|
||||
minetest.log("error", "[Oficios] Dia invalido em especificado (em oficios.comparar_data)")
|
||||
return false
|
||||
end
|
||||
if not hora or not tonumber(hora) then
|
||||
minetest.log("error", "[Oficios] Hora invalido em especificado (em oficios.comparar_data)")
|
||||
return false
|
||||
end
|
||||
if not minuto or not tonumber(minuto) then
|
||||
minetest.log("error", "[Oficios] Minuto invalido em especificado (em oficios.comparar_data)")
|
||||
return false
|
||||
end
|
||||
|
||||
-- Conversoes
|
||||
ano = tonumber(ano)
|
||||
mes = tonumber(mes)
|
||||
dia = tonumber(dia)
|
||||
hora = tonumber(hora)
|
||||
minuto = tonumber(minuto)
|
||||
|
||||
-- Pegando data atual
|
||||
local ano_atual = tonumber(os.date("%Y"))
|
||||
local mes_atual = tonumber(os.date("%m"))
|
||||
local dia_atual = tonumber(os.date("%d"))
|
||||
local hora_atual = tonumber(os.date("%H"))
|
||||
local minuto_atual = tonumber(os.date("%M"))
|
||||
|
||||
-- Pegar diferença de ano
|
||||
local dif_ano = ano - ano_atual
|
||||
|
||||
-- Pegar diferença de meses
|
||||
local dif_meses = mes - (mes_atual - (dif_ano*12)) -- (considerando os meses de um ano para outro)
|
||||
|
||||
-- Pegar a diferença de dias
|
||||
local dif_dias = 0
|
||||
-- Pegar dias dos meses que passaram
|
||||
if dif_meses > 0 then -- do mes atual ate o mes futuro (apenas os meses inteiros, logo o ultimo nao conta, por isso o menos 1)
|
||||
local a = ano_atual -- ano do mes contado
|
||||
local n = mes_atual -- qual mes do ano contado
|
||||
for m=mes_atual, mes_atual+dif_meses-1 do
|
||||
if n > 12 then
|
||||
n = n - 12
|
||||
a = a + 1
|
||||
end
|
||||
dif_dias = dif_dias + pegar_dias_mes(m, a)
|
||||
n = n + 1
|
||||
end
|
||||
elseif dif_meses < 0 then -- do mes passado do passado ate o mes atual
|
||||
local a = ano -- ano do mes contado
|
||||
local n = mes -- qual mes do ano contado
|
||||
for m=mes, mes+math.abs(dif_meses)-1 do
|
||||
if n > 12 then
|
||||
n = n - 12
|
||||
a = a + 1
|
||||
end
|
||||
dif_dias = dif_dias + pegar_dias_mes(m, a)
|
||||
n = n + 1
|
||||
end
|
||||
dif_dias = dif_dias * (-1) -- mantem valor negativo por estar no passado
|
||||
end
|
||||
-- Adiciona a diferença de dias conforme os dias do mes de cada data
|
||||
dif_dias = dif_dias + (dia - dia_atual)
|
||||
|
||||
-- Pegar diferença de horas
|
||||
local dif_horas = 0
|
||||
if dif_dias > 0 then
|
||||
if hora >= hora_atual then
|
||||
dif_horas = hora - hora_atual
|
||||
else
|
||||
dif_dias = dif_dias - 1
|
||||
dif_horas = (hora + 24) - hora_atual
|
||||
end
|
||||
elseif dif_dias < 0 then
|
||||
dif_dias = dif_dias + 1 -- (1 dia é tirado para ser fracionado em horas pois 1 desses dias não foi inteiro)
|
||||
dif_horas = (24-hora) + hora_atual -- (desconta as horas de 24 horas de um dia que foi descontado)
|
||||
if dif_horas >= 24 then
|
||||
dif_dias = dif_dias - 1
|
||||
dif_horas = dif_horas - 24
|
||||
end
|
||||
dif_horas = dif_horas * (-1) -- mantem valor negativo por estar no passado
|
||||
else -- A data é do mesmo dia
|
||||
dif_horas = hora - hora_atual
|
||||
end
|
||||
|
||||
-- Pegar diferença de minutos
|
||||
local dif_minutos = 0
|
||||
if dif_horas > 0 then
|
||||
if minuto >= minuto_atual then
|
||||
dif_minutos = minuto - minuto_atual
|
||||
else
|
||||
dif_horas = dif_horas - 1
|
||||
dif_minutos = (minuto + 60) - minuto_atual
|
||||
end
|
||||
elseif dif_horas < 0 then
|
||||
dif_horas = dif_horas + 1 -- (1 dia é tirado para ser fracionado em horas pois 1 desses dias não foi inteiro)
|
||||
dif_minutos = (60-minuto) + minuto_atual -- (desconta as horas de 24 horas de um dia que foi descontado)
|
||||
if dif_minutos >= 60 then
|
||||
dif_horas = dif_horas - 1
|
||||
dif_minutos = dif_minutos - 60
|
||||
end
|
||||
dif_minutos = dif_minutos * (-1) -- mantem valor negativo por estar no passado
|
||||
else -- A data é da mesma hora
|
||||
dif_minutos = minuto - minuto_atual
|
||||
end
|
||||
|
||||
-- Reajuste de valores (caso o saldo de horas esteja incompativel com saldo de dias)
|
||||
if dif_horas > 1 and dif_dias < 1 then
|
||||
dif_dias = dif_dias + 1
|
||||
dif_horas = dif_horas - 24
|
||||
end
|
||||
if dif_horas < 1 and dif_dias > 1 then
|
||||
dif_dias = dif_dias - 1
|
||||
dif_horas = dif_horas + 24
|
||||
end
|
||||
|
||||
return dif_dias, dif_horas, dif_minutos
|
||||
|
||||
end
|
|
@ -0,0 +1 @@
|
|||
default
|
|
@ -0,0 +1,33 @@
|
|||
--[[
|
||||
Mod Oficios para Minetest
|
||||
Copyright (C) 2017 BrunoMine (https://github.com/BrunoMine)
|
||||
|
||||
Recebeste uma cópia da GNU Lesser General
|
||||
Public License junto com esse software,
|
||||
se não, veja em <http://www.gnu.org/licenses/>.
|
||||
|
||||
Diretrizes
|
||||
]]
|
||||
|
||||
-- Uso de sistema de registro emergencial
|
||||
-- (para caso não esteja ativo desde o inicio do servidor)
|
||||
SISTEMA_DE_REGISTRO_EMERGENCIAL = true
|
||||
|
||||
-- Escala de niveis (jamais alterar apos iniciar o uso no servidor)
|
||||
OFICIOS_NIVEIS = {
|
||||
00000, -- 1
|
||||
00500, -- 2
|
||||
01500, -- 3
|
||||
02500, -- 4
|
||||
04000, -- 5
|
||||
06000, -- 6
|
||||
08500, -- 7
|
||||
11500, -- 8
|
||||
14500, -- 9
|
||||
20000 -- 10
|
||||
}
|
||||
|
||||
-- Calculando limiteis de nível e experiência
|
||||
local lim =table.maxn(OFICIOS_NIVEIS)
|
||||
LIMITE_DE_XP = OFICIOS_NIVEIS[lim]
|
||||
LIMITE_DE_NIVEL = lim
|
|
@ -0,0 +1,136 @@
|
|||
--[[
|
||||
Mod Oficios para Minetest
|
||||
Copyright (C) 2017 BrunoMine (https://github.com/BrunoMine)
|
||||
|
||||
Recebeste uma cópia da GNU Lesser General
|
||||
Public License junto com esse software,
|
||||
se não, veja em <http://www.gnu.org/licenses/>.
|
||||
|
||||
Formulários
|
||||
]]
|
||||
|
||||
oficios.form = {}
|
||||
|
||||
-- Menu de Escolha
|
||||
oficios.form.inicial = "size[8,4.5]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
"label[0,0;Escolha o seu Oficio]"..
|
||||
"button_exit[5,0;3,1;;Escolher depois]"..
|
||||
-- Nomes dos Oficios
|
||||
"label[0.2,1.1;Ferreiro]"..
|
||||
"label[2.2,1.1;Cientista]"..
|
||||
"label[4.2,1.1;Cozinheiro]"..
|
||||
"label[6.2,1.1;Construtor]"..
|
||||
-- Imagens dos Oficios
|
||||
"image[0.1,1.5;2,2;oficios_ferreiro.png]"..
|
||||
"image[2.1,1.5;2,2;oficios_cientista.png]"..
|
||||
"image[4.1,1.5;2,2;oficios_cozinheiro.png]"..
|
||||
"image[6.1,1.5;2,2;oficios_construtor.png]"..
|
||||
-- Botoes de escolha de Oficio
|
||||
"button[0.25,3.3;1.55,1;escolher_ferreiro;Escolher]"..
|
||||
"button[2.25,3.3;1.55,1;escolher_cientista;Escolher]"..
|
||||
"button[4.25,3.3;1.55,1;escolher_cozinheiro;Escolher]"..
|
||||
"button[6.25,3.3;1.55,1;escolher_construtor;Escolher]"
|
||||
|
||||
-- Descricao de Ferreiro
|
||||
oficios.form.desc_ferreiro = "size[9,4.5]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
"label[1.4,0;FERREIRO]"..
|
||||
-- Image do Oficio
|
||||
"image[1.1,0.5;3,3;oficios_ferreiro.png]"..
|
||||
-- Descricao
|
||||
"label[4,0.5;O Ferreiro pode montar "..
|
||||
"\nvarios itens compostos de "..
|
||||
"\nmetais. "..
|
||||
"\nSeu foco maior acaba por ser "..
|
||||
"\nem itens para combate onde "..
|
||||
"\npode causar maior dano. ]"..
|
||||
"label[2.2,4.3;SUA ESCOLHA NAO TEM VOLTA]"..
|
||||
"button[1.5,3.5;3,1;aceitar;Ser Ferreiro]"..
|
||||
"button[4.5,3.5;3,1;voltar;Voltar]"
|
||||
|
||||
-- Descricao de Cientista
|
||||
oficios.form.desc_cientista = "size[9,4.5]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
"label[1.4,0;CIENTISTA]"..
|
||||
-- Image do Oficio
|
||||
"image[1.1,0.5;3,3;oficios_cientista.png]"..
|
||||
-- Descricao
|
||||
"label[4,0.5;O Cientista possui uma "..
|
||||
"\ncaracteristica especial de "..
|
||||
"\nmontar itens diversificados. "..
|
||||
"\nSeu foco costuma estar em "..
|
||||
"\nutilidades nada convensionais "..
|
||||
"\nque as vezes pode surpreender. ]"..
|
||||
"label[2.2,4.3;SUA ESCOLHA NAO TEM VOLTA]"..
|
||||
"button[1.5,3.5;3,1;aceitar;Ser Cientista]"..
|
||||
"button[4.5,3.5;3,1;voltar;Voltar]"
|
||||
|
||||
-- Descricao de Cientista
|
||||
oficios.form.desc_cozinheiro = "size[9,4.5]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
"label[1.4,0;COZINHEIRO]"..
|
||||
-- Image do Oficio
|
||||
"image[1.1,0.5;3,3;oficios_cozinheiro.png]"..
|
||||
-- Descricao
|
||||
"label[4,0.5;O Cozinheiro consegue "..
|
||||
"\nperceber o que existe de "..
|
||||
"\nmelhor para comer e prepara "..
|
||||
"\nsempre bons pratos. "..
|
||||
"\nSeu enfoque se encontra nos "..
|
||||
"\ncomestiveis. ]"..
|
||||
"label[2.2,4.3;SUA ESCOLHA NAO TEM VOLTA]"..
|
||||
"button[1.5,3.5;3,1;aceitar;Ser Cozinheiro]"..
|
||||
"button[4.5,3.5;3,1;voltar;Voltar]"
|
||||
|
||||
-- Descricao de Construtor
|
||||
oficios.form.desc_construtor = "size[9,4.5]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
"label[1.4,0;CONSTRUTOR]"..
|
||||
-- Image do Oficio
|
||||
"image[1.1,0.5;3,3;oficios_construtor.png]"..
|
||||
-- Descricao
|
||||
"label[4,0.5;O Construtor sempre sabe "..
|
||||
"\ncomo erguer uma bela "..
|
||||
"\nestrutura seja qual for "..
|
||||
"\no material ou necessidade. "..
|
||||
"\nSeu enfoque vai em itens"..
|
||||
"\npara estruturar. ]"..
|
||||
"label[2.2,4.3;SUA ESCOLHA NAO TEM VOLTA]"..
|
||||
"button[1.5,3.5;3,1;aceitar;Ser Construtor]"..
|
||||
"button[4.5,3.5;3,1;voltar;Voltar]"
|
||||
|
||||
-- Aviso de falta de itens
|
||||
oficios.form.aviso_falta_item = "size[6,2]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
"label[0,0;Precisar ter os itens requisitados \npara iniciar a montagem]"..
|
||||
"button_exit[2,1;2,1;voltar_ao_item;Voltar]"
|
||||
|
||||
-- Aviso de falta espaco no inventario
|
||||
oficios.form.aviso_inv_lotado = "size[6,2]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
"label[0,0;Inventario lotado \nEsvazie um pouco]"..
|
||||
"button_exit[2,1;2,1;voltar_ao_item;Voltar]"
|
||||
|
||||
-- Aviso de nivel insuficiente
|
||||
oficios.form.aviso_nivel_insuficiente = "size[6,2]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
"label[0,0;Nivel muito baixo. Precisa ter um \nnivel maior para montar esse item]"..
|
||||
"button_exit[2,1;2,1;voltar_ao_item;Voltar]"
|
||||
|
||||
-- Aviso de falta de receitas em algum oficio
|
||||
oficios.form.aviso_sem_receita = "size[6,2]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
"label[0,0;Faltam receitas e algum oficios \nPrecisa existir ao menos uma receita \npara cada oficio]"
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,567 @@
|
|||
--[[
|
||||
Mod Oficios para Minetest
|
||||
Copyright (C) 2017 BrunoMine (https://github.com/BrunoMine)
|
||||
|
||||
Recebeste uma cópia da GNU Lesser General
|
||||
Public License junto com esse software,
|
||||
se não, veja em <http://www.gnu.org/licenses/>.
|
||||
|
||||
Funcoes
|
||||
]]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
--
|
||||
-----
|
||||
--------
|
||||
-- Montar Receitas
|
||||
-- Ordenar vetor
|
||||
local ordenar_por_nivel = function(vetor, lim)
|
||||
local i = 1
|
||||
local j = 1
|
||||
while (i <= lim) do
|
||||
j = i + 1
|
||||
while (j <= lim) do
|
||||
if (tonumber(vetor[i].nivel) > tonumber(vetor[j].nivel)) then
|
||||
local aux = vetor[i]
|
||||
vetor[i] = vetor[j]
|
||||
vetor[j] = aux
|
||||
end
|
||||
j = j + 1
|
||||
end
|
||||
i = i + 1
|
||||
end
|
||||
return vetor
|
||||
end
|
||||
-- Vetores de niveis
|
||||
local vetor_niveis = {["ferreiro"]={},["cientista"]={},["cozinheiro"]={},["construtor"]={}}
|
||||
-- Listas
|
||||
local lista_receitas = {["ferreiro"]="",["cientista"]="",["cozinheiro"]="",["construtor"]=""}
|
||||
-- Tabela de relacionamento IDItem-NomeItem
|
||||
local tabela_IDNome = {}
|
||||
-- Tabela de relacionamento de sequencia NomeItem-IDItem
|
||||
local dropdown_NomeID = {["ferreiro"]={},["cientista"]={},["cozinheiro"]={},["construtor"]={}}
|
||||
oficios.montar_receita = function(oficio, item, nivel, desc, xp, item_requisitado, tempo)
|
||||
|
||||
-- Inserindo novos dados nas tabelas
|
||||
oficios.receitas[minetest.registered_items[item].description] = {
|
||||
item=item,
|
||||
nivel=nivel,
|
||||
desc=desc,
|
||||
xp=xp,
|
||||
item_requisitado=item_requisitado,
|
||||
tempo=tempo
|
||||
}
|
||||
table.insert(vetor_niveis[oficio], {nivel=nivel, nome=minetest.registered_items[item].description, item=item})
|
||||
tabela_IDNome["(Nivel "..nivel..") "..minetest.registered_items[item].description]={
|
||||
item_id=item,
|
||||
item_nome_real=minetest.registered_items[item].description
|
||||
}
|
||||
|
||||
-- Calcular maior indice da tabela
|
||||
local lim = table.maxn(vetor_niveis[oficio])
|
||||
|
||||
-- Ordenar
|
||||
vetor_niveis[oficio] = ordenar_por_nivel(vetor_niveis[oficio], lim)
|
||||
|
||||
-- Escrever lista
|
||||
lista_receitas[oficio] = "(Nivel "..vetor_niveis[oficio][1].nivel..") "..vetor_niveis[oficio][1].nome
|
||||
dropdown_NomeID[oficio]["(Nivel "..vetor_niveis[oficio][1].nivel..") "..vetor_niveis[oficio][1].nome]=1
|
||||
local i = 2
|
||||
while (i <= lim) do
|
||||
dropdown_NomeID[oficio]["(Nivel "..vetor_niveis[oficio][i].nivel..") "..vetor_niveis[oficio][i].nome]=i
|
||||
lista_receitas[oficio] = lista_receitas[oficio]..",(Nivel "..vetor_niveis[oficio][i].nivel..") "..vetor_niveis[oficio][i].nome
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
-- Fim de Montar Receitas
|
||||
--------
|
||||
-----
|
||||
--
|
||||
|
||||
|
||||
|
||||
--
|
||||
-----
|
||||
--------
|
||||
-- Receptor de Botoes
|
||||
local receita_visualizada = {}
|
||||
local visualizando_desc = {}
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
|
||||
-- Menu de Escolha
|
||||
if formname == "oficios:menu_de_escolha" then
|
||||
local name = player:get_player_name()
|
||||
if fields.escolher_ferreiro then
|
||||
minetest.show_formspec(name, "oficios:desc_ferreiro", oficios.form.desc_ferreiro)
|
||||
elseif fields.escolher_cientista then
|
||||
minetest.show_formspec(name, "oficios:desc_cientista", oficios.form.desc_cientista)
|
||||
elseif fields.escolher_cozinheiro then
|
||||
minetest.show_formspec(name, "oficios:desc_cozinheiro", oficios.form.desc_cozinheiro)
|
||||
elseif fields.escolher_construtor then
|
||||
minetest.show_formspec(name, "oficios:desc_construtor", oficios.form.desc_construtor)
|
||||
end
|
||||
end
|
||||
|
||||
--
|
||||
-- Menus de Descricao
|
||||
--
|
||||
if formname == "oficios:desc_ferreiro"
|
||||
or formname == "oficios:desc_cientista"
|
||||
or formname == "oficios:desc_cozinheiro"
|
||||
or formname == "oficios:desc_construtor"
|
||||
then
|
||||
local name = player:get_player_name()
|
||||
if fields.voltar then
|
||||
minetest.show_formspec(name, "oficios:menu_de_escolha", oficios.form.inicial)
|
||||
elseif fields.aceitar then
|
||||
if formname == "oficios:desc_ferreiro" then
|
||||
oficios.bd.definir_oficio(name, "ferreiro")
|
||||
oficios.gerar_menu_oficio(name)
|
||||
elseif formname == "oficios:desc_cientista" then
|
||||
oficios.bd.definir_oficio(name, "cientista")
|
||||
oficios.gerar_menu_oficio(name)
|
||||
elseif formname == "oficios:desc_cozinheiro" then
|
||||
oficios.bd.definir_oficio(name, "cozinheiro")
|
||||
oficios.gerar_menu_oficio(name)
|
||||
elseif formname == "oficios:desc_construtor" then
|
||||
oficios.bd.definir_oficio(name, "construtor")
|
||||
oficios.gerar_menu_oficio(name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--
|
||||
-- Painel do Oficio
|
||||
--
|
||||
if formname == "oficios:menu_ferreiro"
|
||||
or formname == "oficios:menu_cientista"
|
||||
or formname == "oficios:menu_cozinheiro"
|
||||
or formname == "oficios:menu_construtor"
|
||||
then
|
||||
local name = player:get_player_name()
|
||||
|
||||
-- Atualizar painel
|
||||
local n = 0 -- Verificar se o jogador apenas mudou o dropdown
|
||||
for campo,item in pairs(fields) do
|
||||
n = n + 1
|
||||
end
|
||||
if n == 1 and fields.item_selecionado then
|
||||
receita_visualizada[name] = fields.item_selecionado
|
||||
oficios.gerar_menu_oficio(name, fields.item_selecionado)
|
||||
end
|
||||
|
||||
|
||||
-- voltar
|
||||
if fields.voltar then
|
||||
oficios.gerar_menu_oficio(name)
|
||||
end
|
||||
-- voltar ao item
|
||||
if fields.voltar_ao_item then
|
||||
visualizando_desc[name] = false
|
||||
oficios.gerar_menu_oficio(name, receita_visualizada[name])
|
||||
end
|
||||
|
||||
-- Ver descricao
|
||||
if fields.desc then
|
||||
visualizando_desc[name] = true
|
||||
oficios.gerar_menu_oficio(name, receita_visualizada[name])
|
||||
end
|
||||
-- Coletar
|
||||
if fields.coletar then
|
||||
if player:get_inventory():room_for_item("main", registros_oficios[name].coletar) then
|
||||
player:get_inventory():add_item("main", registros_oficios[name].coletar)
|
||||
oficios.bd.coletou_item(name)
|
||||
oficios.gerar_menu_oficio(name)
|
||||
else
|
||||
return minetest.show_formspec(name, "oficios:aviso_montagem", oficios.form.aviso_inv_lotado)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
-- Iniciar montagem
|
||||
if fields.iniciar then
|
||||
local dados = oficios.receitas[tabela_IDNome[receita_visualizada[name]].item_nome_real]
|
||||
-- Verifica o nivel
|
||||
if registros_oficios[name].nivel < dados.nivel then
|
||||
return minetest.show_formspec(name, "oficios:aviso_montagem", oficios.form.aviso_nivel_insuficiente)
|
||||
else
|
||||
|
||||
local player_inv = player:get_inventory()
|
||||
|
||||
|
||||
-- Verificar se possui os itens
|
||||
local possui_itens = true
|
||||
for _, valor in ipairs(dados.item_requisitado) do
|
||||
if player_inv:contains_item("main", valor[1].." "..valor[2]) == false then
|
||||
possui_itens = false
|
||||
end
|
||||
end
|
||||
if possui_itens == false then
|
||||
return minetest.show_formspec(name, "oficios:aviso_montagem", oficios.form.aviso_falta_item)
|
||||
end
|
||||
|
||||
-- Retirar itens
|
||||
for _, valor in ipairs(dados.item_requisitado) do
|
||||
player_inv:remove_item("listname", valor[1].." "..valor[2])
|
||||
end
|
||||
|
||||
-- Calcular Data fim
|
||||
local data_atual = os.date("%Y %m %d %H %M")
|
||||
data_atual = string.split(data_atual, " ")
|
||||
local data_fim = {tonumber(data_atual[1]), tonumber(data_atual[2]), (tonumber(data_atual[3])+dados.tempo[1]), (tonumber(data_atual[4])+dados.tempo[2]), (tonumber(data_atual[5])+dados.tempo[3])}
|
||||
if data_fim[5] >= 60 then
|
||||
data_fim[4] = data_fim[4] + 1
|
||||
data_fim[5] = data_fim[5] - 60
|
||||
end
|
||||
if data_fim[4] >= 24 then
|
||||
data_fim[3] = data_fim[3] + 1
|
||||
data_fim[4] = data_fim[4] - 24
|
||||
end
|
||||
if data_fim[3] > 30 then
|
||||
data_fim[2] = data_fim[2] + 1
|
||||
data_fim[3] = data_fim[3] - 30
|
||||
end
|
||||
if data_fim[2] > 12 then
|
||||
data_fim[1] = data_fim[1] + 1
|
||||
data_fim[2] = data_fim[2] - 12
|
||||
end
|
||||
|
||||
|
||||
-- Iniciar tarefa no banco de dados
|
||||
oficios.bd.iniciar_montagem(name, tabela_IDNome[receita_visualizada[name]].item_nome_real, data_fim)
|
||||
|
||||
return oficios.gerar_menu_oficio(name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Retorno dos avisos de montagem
|
||||
if formname == "oficios:aviso_montagem" then
|
||||
local name = player:get_player_name()
|
||||
|
||||
if fields.voltar_ao_item then
|
||||
return oficios.gerar_menu_oficio(name, receita_visualizada[name])
|
||||
end
|
||||
end
|
||||
|
||||
end)
|
||||
-- Fim do Receptor de Botoes
|
||||
--------
|
||||
-----
|
||||
--
|
||||
|
||||
|
||||
|
||||
|
||||
--
|
||||
-----
|
||||
--------
|
||||
-- Gerar Menu de Oficio
|
||||
-- Calcular_termino (retorna true se terminou caso contrario retorna quantos minutos faltam)
|
||||
local calcular_se_terminou = function(data_fim)
|
||||
local data_atual = os.date("%Y %m %d %H %M")
|
||||
data_atual = string.split(data_atual, " ")
|
||||
local total_atual = (tonumber(data_atual[1])*518400) + (tonumber(data_atual[2])*43200) + (tonumber(data_atual[3])*1440) + (tonumber(data_atual[4])*60) + tonumber(data_atual[5])
|
||||
local total_fim = (data_fim[1]*518400) + (data_fim[2]*43200) + (data_fim[3]*1440) + (data_fim[4]*60) + data_fim[5]
|
||||
local resultado = total_fim - total_atual
|
||||
if resultado > 0 then
|
||||
return resultado
|
||||
else
|
||||
return true
|
||||
end
|
||||
end
|
||||
oficios.gerar_menu_oficio = function(name, item_nome)
|
||||
local oficio = registros_oficios[name].oficio
|
||||
local formspec = ""
|
||||
if item_nome == nil then
|
||||
|
||||
if registros_oficios[name].montagem.status == true then
|
||||
local item_id = oficios.receitas[registros_oficios[name].montagem.item].item
|
||||
|
||||
-- Verificar se a data termino ja passou
|
||||
local data_fim = registros_oficios[name].montagem.data_fim
|
||||
local dias, horas, minutos = oficios.comparar_data(data_fim[1], data_fim[2], data_fim[3], data_fim[4], data_fim[5])
|
||||
|
||||
if dias < 0 or horas < 0 or minutos < 0 or dias+horas+minutos == 0 then
|
||||
|
||||
-- Dar xp/ concluir
|
||||
oficios.bd.conluir_montagem(name, oficios.receitas[registros_oficios[name].montagem.item].xp)
|
||||
|
||||
-- Iniciar novo processo de geracao do menu
|
||||
oficios.gerar_menu_oficio(name)
|
||||
return
|
||||
|
||||
else
|
||||
|
||||
-- Pegando valores absolutos
|
||||
dias, horas, minutos = math.abs(dias), math.abs(horas), math.abs(minutos)
|
||||
|
||||
-- Calcular tempo restante
|
||||
local tempo = {dias,horas,minutos}
|
||||
local tempo_escrito = ""
|
||||
if tempo[1] > 0 then
|
||||
if tempo[1] == 1 then
|
||||
tempo[1] = tempo[1].." dia"
|
||||
else
|
||||
tempo[1] = tempo[1].." dias"
|
||||
end
|
||||
end
|
||||
if tempo[2] > 0 then
|
||||
if tempo[2] == 1 then
|
||||
tempo[2] = tempo[2].." hora"
|
||||
else
|
||||
tempo[2] = tempo[2].." horas"
|
||||
end
|
||||
end
|
||||
if tempo[3] > 0 then
|
||||
if tempo[3] == 1 then
|
||||
tempo[3] = tempo[3].." minuto"
|
||||
else
|
||||
tempo[3] = tempo[3].." minutos"
|
||||
end
|
||||
end
|
||||
|
||||
if dias > 0 and horas > 0 then
|
||||
tempo_escrito = tempo[1].." e "..tempo[2]
|
||||
else
|
||||
if horas > 0 and minutos > 0 then
|
||||
tempo_escrito = tempo[2].." e "..tempo[3]
|
||||
else
|
||||
if dias > 0 then
|
||||
tempo_escrito = tempo[1]
|
||||
else
|
||||
if horas > 0 then
|
||||
tempo_escrito = tempo[2]
|
||||
else
|
||||
tempo_escrito = tempo[3]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Gerar Painel de esperar
|
||||
formspec = "size[8,8.5]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
"list[current_player;main;0,4.25;8,1;]"..
|
||||
"list[current_player;main;0,5.5;8,3;8]"..
|
||||
default.get_hotbar_bg(0,4.25)..
|
||||
-- Cabecalho do Oficio
|
||||
"image[0,0;2.5,2.5;oficios_"..oficio..".png]"..
|
||||
"label[2.2,-0.1;"..string.upper(oficio).." Nivel "..registros_oficios[name].nivel.."]"..
|
||||
-- Painel de espera
|
||||
"label[4.3,0.6;Montando \n"..registros_oficios[name].montagem.item..
|
||||
"\n\nTermina em \n"..tempo_escrito.."]"..
|
||||
"item_image_button[2.2,0.6;2,2;"..item_id..";;]"..
|
||||
-- Botao sair
|
||||
"button_exit[6.9,3.3;1.2,1;;Sair]"
|
||||
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
if registros_oficios[name].coletar == "" then
|
||||
|
||||
|
||||
-- Gerar painel normal
|
||||
local xp_prox_nivel = OFICIOS_NIVEIS[(registros_oficios[name].nivel+1)]
|
||||
formspec = "size[8,8.5]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
"list[current_player;main;0,4.25;8,1;]"..
|
||||
"list[current_player;main;0,5.5;8,3;8]"..
|
||||
default.get_hotbar_bg(0,4.25)..
|
||||
-- Cabecalho do Oficio
|
||||
"image[0,0;2.5,2.5;oficios_"..oficio..".png]"..
|
||||
"label[2.2,-0.1;"..string.upper(oficio).." Nivel "..registros_oficios[name].nivel.."]"..
|
||||
-- Botao sair
|
||||
"button_exit[6.9,3.3;1.2,1;;Sair]"..
|
||||
-- Painel de Montagem
|
||||
"dropdown[2.2,0.35;6.15,1;item_selecionado;"..lista_receitas[oficio]..";]"..
|
||||
"label[2.2,1.1;Selecione algo para produzir]"
|
||||
-- Calcular e inserir dados de desempenho
|
||||
formspec = formspec .. "label[0.2,2.3;Seu Desempenho \nAtualmente "..registros_oficios[name].xp.." XP "
|
||||
if registros_oficios[name].nivel < LIMITE_DE_NIVEL then
|
||||
formspec = formspec .. "\nProximo Nivel "..xp_prox_nivel.." XP"
|
||||
end
|
||||
formspec = formspec .. "\nTotal de "..registros_oficios[name].total_itens.." itens montados]"
|
||||
|
||||
else
|
||||
|
||||
-- Gerar painel para coletar item
|
||||
formspec = "size[8,8.5]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
"list[current_player;main;0,4.25;8,1;]"..
|
||||
"list[current_player;main;0,5.5;8,3;8]"..
|
||||
default.get_hotbar_bg(0,4.25)..
|
||||
-- Cabecalho do Oficio
|
||||
"image[0,0;2.5,2.5;oficios_"..oficio..".png]"..
|
||||
"label[2.2,-0.1;"..string.upper(oficio).." Nivel "..registros_oficios[name].nivel.."]"..
|
||||
-- Painel de conclusao
|
||||
"label[2.3,0.4;"..minetest.registered_items[registros_oficios[name].coletar].description.."]"..
|
||||
"label[5.2,1;Montado]"..
|
||||
"item_image_button[2.2,1;3,3;"..registros_oficios[name].coletar..";coletar;Coletar]"..
|
||||
-- Botao sair
|
||||
"button_exit[6.9,3.3;1.2,1;;Sair]"
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
if visualizando_desc[name] == true then
|
||||
-- Gerar painel descritivo de um item
|
||||
local item_nome_real = tabela_IDNome[receita_visualizada[name]].item_nome_real
|
||||
local dados = oficios.receitas[item_nome_real]
|
||||
formspec = formspec .. "size[8,8.8]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
"list[current_player;main;0,4.75;8,1;]"..
|
||||
"list[current_player;main;0,6;8,3;8]"..
|
||||
default.get_hotbar_bg(0,4.75)..
|
||||
-- Cabecalho do Oficio
|
||||
"image[0,0;2.5,2.5;oficios_"..oficio..".png]"..
|
||||
"label[2.2,-0.1;"..string.upper(oficio).." Nivel "..registros_oficios[name].nivel.."]"..
|
||||
-- Dados sobre a Montagem
|
||||
"label[2.2,1.1;"..item_nome_real.."]"..
|
||||
"item_image_button[0.1,2.5;2,2;"..dados.item..";item;]"..
|
||||
-- descricao
|
||||
"label[2.2,1.7;"..dados.desc.."]"..
|
||||
-- Botao voltar
|
||||
"button[6.9,3.3;1.2,1;voltar_ao_item;Voltar]"..
|
||||
-- Painel de Montagem
|
||||
"dropdown[2.2,0.35;6.15,1;item_selecionado;"..lista_receitas[oficio]..";"..dropdown_NomeID[oficio][receita_visualizada[name]].."]"
|
||||
|
||||
else
|
||||
|
||||
-- Gerar um Painel de montagem de um item
|
||||
local item_id = tabela_IDNome[item_nome].item_id
|
||||
local item_nome_real = tabela_IDNome[item_nome].item_nome_real
|
||||
local item_requisitado = oficios.receitas[item_nome_real].item_requisitado
|
||||
-- Colocando itens requisitados
|
||||
formspec = formspec .. "size[8,8.8]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
"list[current_player;main;0,4.75;8,1;]"..
|
||||
"list[current_player;main;0,6;8,3;8]"..
|
||||
default.get_hotbar_bg(0,4.75)..
|
||||
"label[2.2,3.1;Itens requisitados]"
|
||||
if item_requisitado[1] ~= nil then
|
||||
formspec = formspec .. "item_image_button[2.2,3.5;1,1;"..item_requisitado[1][1].." "..item_requisitado[1][2]..";item_req1;]"
|
||||
end
|
||||
if item_requisitado[2] ~= nil then
|
||||
formspec = formspec .. "item_image_button[3.1,3.5;1,1;"..item_requisitado[2][1].." "..item_requisitado[2][2]..";item_req2;]"
|
||||
end
|
||||
if item_requisitado[3] ~= nil then
|
||||
formspec = formspec .. "item_image_button[4.0,3.5;1,1;"..item_requisitado[3][1].." "..item_requisitado[3][2]..";item_req3;]"
|
||||
end
|
||||
if item_requisitado[4] ~= nil then
|
||||
formspec = formspec .. "item_image_button[4.9,3.5;1,1;"..item_requisitado[4][1].." "..item_requisitado[4][2]..";item_req4;]"
|
||||
end
|
||||
if item_requisitado[5] ~= nil then
|
||||
formspec = formspec .. "item_image_button[5.8,3.5;1,1;"..item_requisitado[5][1].." "..item_requisitado[5][2]..";item_req5;]"
|
||||
end
|
||||
if item_requisitado[6] ~= nil then
|
||||
formspec = formspec .. "item_image_button[6.7,3.5;1,1;"..item_requisitado[6][1].." "..item_requisitado[6][2]..";item_req6;]"
|
||||
end
|
||||
-- Colocando Tempo de montagem
|
||||
local tempo = oficios.receitas[item_nome_real].tempo
|
||||
formspec = formspec .. "label[2.2,1.6;Tempo estimado \n"
|
||||
if tempo[1] > 0 then
|
||||
if tempo[1] == 1 then
|
||||
formspec = formspec .. tempo[1].." dia"
|
||||
else
|
||||
formspec = formspec .. tempo[1].." dias"
|
||||
end
|
||||
if tempo[2] > 0 then
|
||||
if tempo[2] == 1 then
|
||||
formspec = formspec .. " e "..tempo[2].." hora"
|
||||
else
|
||||
formspec = formspec .. " e "..tempo[2].." horas"
|
||||
end
|
||||
end
|
||||
elseif tempo[2] > 0 then
|
||||
if tempo[2] == 1 then
|
||||
formspec = formspec .. tempo[2].." hora"
|
||||
else
|
||||
formspec = formspec .. tempo[2].." horas"
|
||||
end
|
||||
if tempo[3] > 0 then
|
||||
if tempo[3] == 1 then
|
||||
formspec = formspec .. " e "..tempo[3].." minuto"
|
||||
else
|
||||
formspec = formspec .. " e "..tempo[3].." minutos"
|
||||
end
|
||||
end
|
||||
else
|
||||
if tempo[3] == 1 then
|
||||
formspec = formspec .. tempo[3].." minuto"
|
||||
else
|
||||
formspec = formspec .. tempo[3].." minutos"
|
||||
end
|
||||
end
|
||||
formspec = formspec .. "]"
|
||||
|
||||
formspec = formspec ..
|
||||
-- Cabecalho do Oficio
|
||||
"image[0,0;2.5,2.5;oficios_"..oficio..".png]"..
|
||||
"label[2.2,-0.1;"..string.upper(oficio).." Nivel "..registros_oficios[name].nivel.."]"..
|
||||
-- Painel de Montagem
|
||||
"dropdown[2.2,0.35;6.15,1;item_selecionado;"..lista_receitas[oficio]..";"..dropdown_NomeID[oficio][item_nome].."]"..
|
||||
-- Dados sobre a Montagem
|
||||
"label[2.2,1.1;Montar "..item_nome_real.."]"..
|
||||
"item_image_button[0.1,2.5;2,2;"..item_id..";iniciar;Iniciar]"..
|
||||
"label[2.2,2.5;Recebe "..core.colorize("#00FF00", oficios.receitas[item_nome_real].xp.." XP").."]"..
|
||||
"image_button[7,1.3;1,1;oficios_botao_desc.png;desc;]"..
|
||||
-- Botao voltar
|
||||
"button[6.9,2.3;1.2,1;voltar;Voltar]"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
minetest.show_formspec(name, "oficios:menu_"..oficio, formspec)
|
||||
end
|
||||
-- Fim de Gerar Menu de Oficio
|
||||
--------
|
||||
-----
|
||||
--
|
||||
|
||||
|
||||
-- Abrir o menu de oficios
|
||||
local acesso_ok = false -- variavel que informa se todos os oficios possuem receitas (para evitar bugs)
|
||||
oficios.abrir_menu = function(name)
|
||||
|
||||
if acesso_ok == false then
|
||||
-- Verifica se ja todos oficios possuem receita
|
||||
if table.maxn(vetor_niveis.ferreiro) > 0
|
||||
and table.maxn(vetor_niveis.cozinheiro) > 0
|
||||
and table.maxn(vetor_niveis.cientista) > 0
|
||||
and table.maxn(vetor_niveis.construtor) > 0
|
||||
then
|
||||
acesso_ok = true
|
||||
else
|
||||
-- Bloqueia o acesso
|
||||
return minetest.show_formspec(name, "oficios:aviso_sem_receita", oficios.form.aviso_sem_receita)
|
||||
end
|
||||
end
|
||||
|
||||
if registros_oficios[name].oficio == "ferreiro"
|
||||
or registros_oficios[name].oficio == "cientista"
|
||||
or registros_oficios[name].oficio == "cozinheiro"
|
||||
or registros_oficios[name].oficio == "construtor"
|
||||
then
|
||||
oficios.gerar_menu_oficio(name)
|
||||
else
|
||||
minetest.show_formspec(name, "oficios:menu_de_escolha", oficios.form.inicial)
|
||||
end
|
||||
end
|
||||
|
After Width: | Height: | Size: 4.4 KiB |
After Width: | Height: | Size: 4.4 KiB |
After Width: | Height: | Size: 4.4 KiB |
After Width: | Height: | Size: 4.4 KiB |
After Width: | Height: | Size: 20 KiB |
After Width: | Height: | Size: 9.3 KiB |
After Width: | Height: | Size: 6.6 KiB |
After Width: | Height: | Size: 8.8 KiB |
After Width: | Height: | Size: 3.8 KiB |
After Width: | Height: | Size: 9.1 KiB |
After Width: | Height: | Size: 6.8 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 5.1 KiB |
After Width: | Height: | Size: 2.6 KiB |
|
@ -0,0 +1,36 @@
|
|||
--[[
|
||||
Mod Oficios para Minetest
|
||||
Copyright (C) 2017 BrunoMine (https://github.com/BrunoMine)
|
||||
|
||||
Recebeste uma cópia da GNU Lesser General
|
||||
Public License junto com esse software,
|
||||
se não, veja em <http://www.gnu.org/licenses/>.
|
||||
|
||||
Inicialização de scripts
|
||||
]]
|
||||
|
||||
|
||||
local path = minetest.get_modpath("oficios")
|
||||
|
||||
oficios = {}
|
||||
oficios.receitas = {}
|
||||
|
||||
minetest.log('verbose',"[OFICIOS] iniciando carreamento...")
|
||||
|
||||
dofile(path.."/diretrizes.lua")
|
||||
minetest.log('verbose',"[OFICIOS] diretrizes carregadas...")
|
||||
|
||||
dofile(path.."/formularios.lua")
|
||||
minetest.log('verbose',"[OFICIOS] formularios carregados...")
|
||||
|
||||
dofile(path.."/banco_de_dados.lua")
|
||||
minetest.log('verbose',"[OFICIOS] Banco de Dados carregado...")
|
||||
|
||||
dofile(path.."/contador_tempo.lua")
|
||||
minetest.log('verbose',"[OFICIOS] Contador de tempo carregado...")
|
||||
|
||||
dofile(path.."/funcoes.lua")
|
||||
minetest.log('verbose',"[OFICIOS] funcoes carregadas...")
|
||||
|
||||
minetest.log('action',"[OFICIOS] carregado.")
|
||||
|
After Width: | Height: | Size: 8.2 KiB |
After Width: | Height: | Size: 402 B |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 14 KiB |