80% complete

master
ExeVirus 2020-12-06 23:10:41 -05:00
parent 15db73a418
commit 34d3af5273
9 changed files with 342 additions and 77 deletions

14
api.lua
View File

@ -1,7 +1,7 @@
-- API
local function load_pouch(name)
local pouch = minetest.deserialize(adv_core.mod_storage:get_string(tostring(name)))
function adv_core.load_pouch(name)
local pouch = minetest.deserialize(adv_core.mod_storage:get_string(tostring(name) .. "pouch"))
--init if nil
if pouch == nil then
@ -12,7 +12,7 @@ local function load_pouch(name)
air = 0,
}
--store it back
adv_core.mod_storage:set_string(player_name, minetest.serialize(pouch))
adv_core.mod_storage:set_string(name .. "pouch", minetest.serialize(pouch))
end
return pouch
@ -26,7 +26,7 @@ function adv_core.player_can_afford_object(name, object_name)
end
--load player pouch
local player_pouch = load_pouch(name)
local player_pouch = adv_core.load_pouch(name)
local fire_ok = player_pouch.fire >= objectTable.object_name.fire
local water_ok = player_pouch.water >= objectTable.object_name.water
@ -43,7 +43,7 @@ end
function adv_core.player_can_afford(name, fire, water, earth, air)
--load player pouch
local player_pouch = load_pouch(name)
local player_pouch = adv_core.load_pouch(name)
local fire_ok = player_pouch.fire >= fire
local water_ok = player_pouch.water >= water
@ -59,7 +59,7 @@ end
-- (reward player with elements, pay with elements, register nodes to purchase for shop)
function adv_core.reward_player(name, fire, water, earth, air, notify)
local player_pouch = load_pouch(name)
local player_pouch = adv_core.load_pouch(name)
player_pouch.fire = player_pouch.fire + fire
player_pouch.water = player_pouch.water + water
@ -82,7 +82,7 @@ function adv_core.reward_player(name, fire, water, earth, air, notify)
end
function adv_core.take_from_player(name, fire, water, earth, air)
local player_pouch = load_pouch(name)
local player_pouch = adv_core.load_pouch(name)
--Don't reduce below zero, that's silly

View File

@ -13,8 +13,39 @@ if adv_core.setting("enable_chat_commands",true) then
end,
})
minetest.register_chatcommand("pouch", {
params = "<name> <privilege>",
description = "Check your element pouch",
privs = {interact = true},
func = function (name)
minetest.show_formspec(name, "adventure_core:pouch", adv_core.pouch_formspec(name))
return true
end,
})
--Priv only API commands
--Set player pouch contents
--Priv Specific API commands
end
--spawn elements
--
end
minetest.register_chatcommand("guidebook", {
params = "<name> <privilege>",
description = "Read the Adventure_Core Guide",
privs = {interact = true},
func = function (name)
minetest.show_formspec(name, "adventure_core:guidebook", adv_core.guide_formspec(name))
return true
end,
})

View File

@ -36,7 +36,7 @@ end
local function reward_player(player_name, element_type)
if player_name ~= "" then
--load player pouch
local player_pouch = minetest.deserialize(adv_core.mod_storage:get_string(player_name))
local player_pouch = minetest.deserialize(adv_core.mod_storage:get_string(player_name .. "pouch"))
--init, if nil
if player_pouch == nil then
@ -67,12 +67,8 @@ local function reward_player(player_name, element_type)
minetest.get_color_escape_sequence("yellow") .. " Air: " .. player_pouch.air)
end
if adv_core.setting("enable_element_sounds", true) then
minetest.sound_play("adv_core_capture", {to_player = player_name, gain=0.5})
end
--store it back
adv_core.mod_storage:set_string(player_name, minetest.serialize(player_pouch))
adv_core.mod_storage:set_string(player_name .. "pouch", minetest.serialize(player_pouch))
end
end
@ -99,9 +95,7 @@ local fire_element_def = {
if adv_core.setting("enable_element_particles", true) then
self.particles = create_particles(self.object:get_pos(), "fire")
end
if adv_core.setting("enable_element_sounds", true) then
self.sound = minetest.sound_play("adv_core_spawn_sound", {object = self.object, gain=0.5, max_hear_distance=80, loop = false})
end
self.sound = minetest.sound_play("adv_core_spawn_sound", {object = self.object, gain=0.5, max_hear_distance=80, loop = false})
self.lifetime = minetest.get_us_time() + adv_core.setting("element_lifetime", 60)*1000000
end,
@ -111,9 +105,7 @@ local fire_element_def = {
if adv_core.setting("enable_element_particles", true) then
minetest.delete_particlespawner(self.particles)
end
if adv_core.setting("enable_element_sounds", true) then
minetest.sound_stop(self.sound)
end
minetest.sound_stop(self.sound)
end
end,
@ -123,9 +115,7 @@ local fire_element_def = {
if adv_core.setting("enable_element_particles", true) then
minetest.delete_particlespawner(self.particles)
end
if adv_core.setting("enable_element_sounds", true) then
minetest.sound_stop(self.sound)
end
minetest.sound_stop(self.sound)
end,
on_punch = function(self, puncher)
@ -134,9 +124,7 @@ local fire_element_def = {
if adv_core.setting("enable_element_particles", true) then
minetest.delete_particlespawner(self.particles)
end
if adv_core.setting("enable_element_sounds", true) then
minetest.sound_stop(self.sound)
end
minetest.sound_stop(self.sound)
end,
}
minetest.register_entity("adventure_core:fire_element", fire_element_def)
@ -164,9 +152,7 @@ local water_element_def = {
if adv_core.setting("enable_element_particles", true) then
self.particles = create_particles(self.object:get_pos(), "water")
end
if adv_core.setting("enable_element_sounds", true) then
self.sound = minetest.sound_play("adv_core_spawn_sound", {object = self.object, gain=0.5, max_hear_distance=80, loop = false})
end
self.sound = minetest.sound_play("adv_core_spawn_sound", {object = self.object, gain=0.5, max_hear_distance=80, loop = false})
self.lifetime = minetest.get_us_time() + adv_core.setting("element_lifetime", 60)*1000000
end,
@ -176,9 +162,7 @@ local water_element_def = {
if adv_core.setting("enable_element_particles", true) then
minetest.delete_particlespawner(self.particles)
end
if adv_core.setting("enable_element_sounds", true) then
minetest.sound_stop(self.sound)
end
minetest.sound_stop(self.sound)
end
end,
@ -188,9 +172,7 @@ local water_element_def = {
if adv_core.setting("enable_element_particles", true) then
minetest.delete_particlespawner(self.particles)
end
if adv_core.setting("enable_element_sounds", true) then
minetest.sound_stop(self.sound)
end
minetest.sound_stop(self.sound)
end,
on_punch = function(self, puncher)
@ -199,9 +181,7 @@ local water_element_def = {
if adv_core.setting("enable_element_particles", true) then
minetest.delete_particlespawner(self.particles)
end
if adv_core.setting("enable_element_sounds", true) then
minetest.sound_stop(self.sound)
end
minetest.sound_stop(self.sound)
end,
}
minetest.register_entity("adventure_core:water_element", water_element_def)
@ -229,9 +209,7 @@ local earth_element_def = {
if adv_core.setting("enable_element_particles", true) then
self.particles = create_particles(self.object:get_pos(), "earth")
end
if adv_core.setting("enable_element_sounds", true) then
self.sound = minetest.sound_play("adv_core_spawn_sound", {object = self.object, gain=0.5, max_hear_distance=80, loop = false})
end
self.sound = minetest.sound_play("adv_core_spawn_sound", {object = self.object, gain=0.5, max_hear_distance=80, loop = false})
self.lifetime = minetest.get_us_time() + adv_core.setting("element_lifetime", 60)*1000000
end,
@ -241,9 +219,7 @@ local earth_element_def = {
if adv_core.setting("enable_element_particles", true) then
minetest.delete_particlespawner(self.particles)
end
if adv_core.setting("enable_element_sounds", true) then
minetest.sound_stop(self.sound)
end
minetest.sound_stop(self.sound)
end
end,
@ -253,9 +229,7 @@ local earth_element_def = {
if adv_core.setting("enable_element_particles", true) then
minetest.delete_particlespawner(self.particles)
end
if adv_core.setting("enable_element_sounds", true) then
minetest.sound_stop(self.sound)
end
minetest.sound_stop(self.sound)
end,
on_punch = function(self, puncher)
@ -264,9 +238,7 @@ local earth_element_def = {
if adv_core.setting("enable_element_particles", true) then
minetest.delete_particlespawner(self.particles)
end
if adv_core.setting("enable_element_sounds", true) then
minetest.sound_stop(self.sound)
end
minetest.sound_stop(self.sound)
return true
end,
}
@ -295,9 +267,7 @@ local air_element_def = {
if adv_core.setting("enable_element_particles", true) then
self.particles = create_particles(self.object:get_pos(), "air")
end
if adv_core.setting("enable_element_sounds", true) then
self.sound = minetest.sound_play("adv_core_spawn_sound", {object = self.object, gain=0.5, max_hear_distance=80, loop = false})
end
self.sound = minetest.sound_play("adv_core_spawn_sound", {object = self.object, gain=0.5, max_hear_distance=80, loop = false})
self.lifetime = minetest.get_us_time() + adv_core.setting("element_lifetime", 60)*1000000
end,
@ -307,9 +277,7 @@ local air_element_def = {
if adv_core.setting("enable_element_particles", true) then
minetest.delete_particlespawner(self.particles)
end
if adv_core.setting("enable_element_sounds", true) then
minetest.sound_stop(self.sound)
end
minetest.sound_stop(self.sound)
end
end,
@ -319,9 +287,7 @@ local air_element_def = {
if adv_core.setting("enable_element_particles", true) then
minetest.delete_particlespawner(self.particles)
end
if adv_core.setting("enable_element_sounds", true) then
minetest.sound_stop(self.sound)
end
minetest.sound_stop(self.sound)
end,
on_punch = function(self, puncher)
@ -330,9 +296,7 @@ local air_element_def = {
if adv_core.setting("enable_element_particles", true) then
minetest.delete_particlespawner(self.particles)
end
if adv_core.setting("enable_element_sounds", true) then
minetest.sound_stop(self.sound)
end
minetest.sound_stop(self.sound)
end,
}
minetest.register_entity("adventure_core:air_element", air_element_def)

View File

@ -1,15 +1,109 @@
-- FORMSPECS
local red = minetest.get_color_escape_sequence("red")
local blue = minetest.get_color_escape_sequence("blue")
local green = minetest.get_color_escape_sequence("green")
local yellow = minetest.get_color_escape_sequence("yellow")
local black = minetest.get_color_escape_sequence("#111111")
-- Guidebook formspec (with or without default)
function adv_core.guide_formspec(name)
--Display Guide (scrollable formspec)
local formspec = {
"formspec_version[3]",
"size[8,12]",
"position[0.5,0.5]",
"anchor[0.5,0.5]",
"no_prepend[]",
"bgcolor[#EAD994FF;both;#00000080]",
"box[0.6,0.4;6.8,1.2;#00000030]",
"image[0.7,0.5;6.6,1;title.png]",
"box[2.73,2.77;0.55,0.4;#00000030]", --fire
"box[3.35,2.77;0.75,0.4;#00000030]", --water
"box[4.15,2.77;0.7,0.4;#00000030]", --earth
"box[4.87,2.77;0.41,0.4;#00000030]", --air
"image[2.8,5.2;0.5,0.5;fire.png]",
"button[6.12,4.24;1.5,0.5;play;This Sound]",
"style[label;font=mono]",
"label[1,2;",black,
"----------- Adventure Core is a discovery mod! -----------\n", black,
"]",
"label[0.3,2.5;",black,
"You are encourged to search far and wide in search of the\n", black,
" Four Elements: ",red," Fire ", blue, "Water ", green, "Earth ", yellow, "Air\n\n",black,
"These elements are found more commonly the further you wander,\n",black,
"dig, and climb from spawn, and you must be ready for:\n",black, --This sound
"When you hear it, an element has just spawned near you!\n",black,
"Look for something like glowing and floating above the terrain.\n",black,
"Click/Punch to capture it, and you have collected a piece of element!\n",black,
"To view how much element you have collected ",
}
--optional display based on settings, very handy
if adv_core.setting("enable_chat_commands",true) then
table.insert(formspec, "type '/pouch' in chat, or\n")
table.insert(formspec, black)
end
table.insert(formspec, "craft a 'guidebook'.\n\n")
table.insert(formspec, black)
table.insert(formspec, " There is also a Adventure shop!\n")
table.insert(formspec, black)
if adv_core.setting("enable_adventure_shop",true) then
if adv_core.setting("enable_chat_commands",true) then
table.insert(formspec, "You can craft this shop, or use the '/shop' command.\n")
table.insert(formspec, black)
else
table.insert(formspec, "You can craft this shop and place it in the world.\n")
table.insert(formspec, black)
end
else
if adv_core.setting("enable_chat_commands",true) then
table.insert(formspec, "You can use the '/shop' command to access it.\n")
table.insert(formspec, black)
else
table.insert(formspec, "You will have to search the map for these special places.\n")
table.insert(formspec, black)
end
end
table.insert(formspec, " There, you can buy unique objects and items.\n\n")
table.insert(formspec, black)
if(minetest.get_modpath("default")) ~= nil and adv_core.setting("enable_spawn_biome", true) then
table.insert(formspec, "Hint: Elements will spawn according to what biome you are in.\n\n")
table.insert(formspec, black)
end
--table.insert(formspec, ""
table.insert(formspec, " ------------- Happy Adventuring! -------------")
table.insert(formspec, "]")
return table.concat(formspec, "")
end
-- Pouch Formspec
function adv_core.pouch_formspec(name)
-- Display Pouch
local pouch = adv_core.load_pouch(name)
local formspec = {
"formspec_version[3]",
"size[6,6]",
"position[0.5,0.6]",
"anchor[0.5,0.5]",
"no_prepend[]",
"bgcolor[#00000000;both;#00000080]",
"background[0,0;6,6;pouch.png]",
"image[0.8,0.4;2,2;fire.png]",
"label[1.4,2.5;", red, "Fire: " , pouch.fire , "]",
"image[3.14,0.4;2,2;water.png]",
"label[3.67,2.5;", blue, "Water: ", pouch.water, "]",
"image[0.8,2.9;2,2;earth.png]",
"label[1.3,5;", green, "Earth: ", pouch.earth, "]",
"image[3.11,2.9;2,2;air.png]",
"label[3.82,5;", yellow,"Air: " , pouch.air , "]",
}
return table.concat(formspec, "")
end
@ -25,13 +119,19 @@ function adv_core.store_formspec(name, page, search, selected)
-- Create Button, bottom of left half.
end
--
-- formspec callbacks
minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname ~= "adventure_core:store" then
local name = player:get_player_name()
if formname ~= "adventure_core:store" and formname ~= "adventure_core:guidebook" then
return
end
if fields.create and fields.selected then
end
if formname == "adventure_core:guidebook" then
if fields.play then
minetest.sound_play("adv_core_spawn_sound", {to_player = name, gain=0.8})
end
else -- must be store
if fields.create and fields.selected then
end
end
end)

View File

@ -1,7 +1,7 @@
-- __ ____ _ _ ____ __ _ ____ _ _ ____ ____ ___ __ ____ ____
-- / _\( \/ )( ( __| ( (_ _) )( ( _ ( __) / __) ( _ ( __)
--/ \) D (\ \/ /) _)/ / )( ) \/ () /) _) ( (_( O ) /) _)
--\_/\_(____/ \__/(____)_)__)(__)\____(__\_|____) \___)__(__\_|____)
-- / \) D (\ \/ /) _)/ / )( ) \/ () /) _) ( (_( O ) /) _)
-- \_/\_(____/ \__/(____)_)__)(__)\____(__\_|____) \___)__(__\_|____)
--
-- Core Mod by ExeVirus
-- Font used in title: Graceful

View File

@ -12,15 +12,15 @@ adventure_core.enable_chat_commands (Enable Chat Commands) bool true
#Spawn elements according to biome (if default is present) [random otherwise]
adventure_core.enable_spawn_biome (Spawns based on Biomes) bool true
#Spawn elements within this distance of player (in nodes0
adventure_core.distance_from_player (Element Max Distance From Player) int 12 1 40
#Element Lifetime, in seconds. [0-200]
adventure_core.element_lifetime (Element Lifetime [s]) int 60 0 200
#Enable Element Particles
adventure_core.enable_element_particles (Enable Element Particles) bool true
#Enable Element Sounds
adventure_core.enable_element_sounds (Enable Element Sounds) bool true
#Give Players the starting guidebook and pouch
adventure_core.enable_starting_items (Enable Starting Items) bool true

View File

@ -1 +1,171 @@
-- SPAWNING
-- SPAWNING
--If default, and with biomes, spawn with biomes, otherwise randomly chosen.
--Here are the four combos:
-- | High Heat | Low Heat |
--------------------------------
--High Humidity | Earth | Water |
--Low Humidity | Fire | Air |
-- --------------------------------
--Returns true on success, false on failure
local time_between = adv_core.setting("base_time_between_spawns", 80)
local spread = adv_core.setting("spawn_time_spread", 15)
local base_dist = adv_core.setting("base_distance", 500)
local spawn_adjust = adv_core.setting("spawn_adjustment_time", 180)
local dist_adjust = adv_core.setting("distance_adjustment_time", 2)
local min_time = adv_core.setting("minimum_spawn_time", 30)
local spawn_point = adv_core.setting("spawn_location",{x=0,y=0,z=0})
local biome_spawns = adv_core.setting("enable_spawn_biome", true)
local spawn_dist = adv_core.setting("distance_from_player", 12)
local default_en = (minetest.get_modpath("default")) ~= nil
local air_id = minetest.get_content_id("air")
local ignore_id = minetest.get_content_id("ignore")
--local init_time = (time_between + spawn_adjust) * 1000000
local init_time = 1000000
--Used to randomly spawn element near a player
local function spawn_element(player, with_biomes)
local function biome_spawn(environment, position)
if environment.heat > 50 then
if environment.humidity > 50 then --Earth
adv_core.spawn_element("earth", position)
else --Fire
adv_core.spawn_element("fire", position)
end
else
if environment.humidity > 50 then --Water
adv_core.spawn_element("water", position)
else --Air
adv_core.spawn_element("air", position)
end
end
end
local function random_spawn(position)
local rand = math.random(0,3)
if rand == 0 then
adv_core.spawn_element("fire", position)
elseif rand == 1 then
adv_core.spawn_element("water", position)
elseif rand == 2 then
adv_core.spawn_element("earth", position)
else
adv_core.spawn_element("air", position)
end
end
local position = player:get_pos()
position.x = math.floor(position.x + math.random(-spawn_dist,spawn_dist))
position.z = math.floor(position.z + math.random(-spawn_dist,spawn_dist))
position.y = math.floor(position.y + math.random(0 , 10))
if (minetest.get_node(position).name == "air") then
minetest.chat_send_all("starting: ".. minetest.serialize(position))
--find lowest node that's not air
local vm = minetest.get_voxel_manip()
local position2 = position
position2.y = position2.y - 2
local emin, emax = vm:read_from_map(position, position2)
local a = VoxelArea:new{
MinEdge = emin,
MaxEdge = emax,
}
local data = vm:get_data()
local stop = position.y-10
for y = position.y, stop, -1 do
local idx = a:index(position.x, y, position.z)
if data[idx] ~= air_id or data[idx] == ignore_id then
position.y = y+3
if with_biomes then
biome_spawn(minetest.get_biome_data(position), position)
minetest.chat_send_all("ending: " .. minetest.serialize(position))
else
random_spawn(position)
end
return true
end
end
--Didn't find the ground, spawn at low position
position.y = position.y - 7
if with_biomes then
biome_spawn(minetest.get_biome_data(position), position)
minetest.chat_send_all("ending: " .. minetest.serialize(position))
else
random_spawn(position)
end
return true
else
return false
end
end
minetest.register_globalstep(function(dtime)
local new_time = minetest.get_us_time()
local old_time = tonumber(adv_core.mod_storage:get_string("time"))
if old_time ~= nil then
--Every second:
if old_time + 1000000 < new_time then
for _,player in ipairs(minetest.get_connected_players()) do
local name = player:get_player_name()
local player_old_time = tonumber(adv_core.mod_storage:get_string(name .. "old_time"))
if player_old_time == nil then
adv_core.mod_storage:set_string(name .. "old_time", new_time)
player_old_time = new_time
end
local player_countdown = tonumber(adv_core.mod_storage:get_string(name .. "countdown")) or init_time
minetest.chat_send_all("old_time: " .. player_old_time .. "countdown: " .. player_countdown)
if player_old_time + player_countdown < new_time then
minetest.chat_send_all("attempting spawn")
local spawned = nil
if biome_spawns and default_en then
spawned = spawn_element(player, true)
else
spawned = spawn_element(player, false)
end
if spawned then
minetest.chat_send_all("spawn_successful")
local countdown = time_between + math.random(-spread,spread)
local dist = vector.distance(player:get_pos(), spawn_point)
if dist > base_dist then
countdown = countdown - math.floor(base_dist / 1000) * dist_adjust
else
countdown = countdown + spawn_adjust
end
adv_core.mod_storage:set_string(name .. "countdown", 3000000)--math.max(countdown, min_time) * 1000000)
else
minetest.chat_send_all("spawn_unsuccessful")
adv_core.mod_storage:set_string(name .. "countdown", 1000000) -- try again in 1 seconds...
end
adv_core.mod_storage:set_string(name .. "old_time", new_time)
end
end
adv_core.mod_storage:set_string("time",tostring(new_time))
end
else
adv_core.mod_storage:set_string("time",tostring(new_time))
end
end)
--Do players respawn/spawn with a guidebook and pouch?
if adv_core.setting("enable_starting_items", true) then
minetest.register_on_newplayer(function(playerRef)
local inv = player:get_inventory()
local main = inv:get_list("main")
--for loop through main stacks
--check if empty
--add guidebook
--break
--for loop though main stacks
--check if empty
--add pouch
--break
end
)
end

BIN
textures/pouch.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 974 B

BIN
textures/title.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB