Skip to content

Commit

Permalink
Fix some bugs/issues, make aliens spawn during the day
Browse files Browse the repository at this point in the history
  • Loading branch information
LoneWolfHT committed Dec 1, 2023
1 parent 5345c2c commit 759e781
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 26 deletions.
1 change: 1 addition & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ globals = {

"creatura", "fire", "player_api",

"unpack",
"VoxelManip", "VoxelArea", "PseudoRandom", "ItemStack",
"Settings",
"vector", "table", "string", "dump",
Expand Down
38 changes: 22 additions & 16 deletions mods/torrl_aliens/init.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
torrl_aliens = {
target_list = {},
target_list_trecs = {},
current_ships = {},
}

local modpath = minetest.get_modpath(minetest.get_current_modname()) .. "/"
Expand Down Expand Up @@ -82,15 +83,13 @@ local ALIEN_SHIP_PR = 40
local SHIP_SIZE = 20
local MAX_ALIEN_COUNT = 6 + (#minetest.get_connected_players() * 2)

local current_ships = {}

local function delete_ships()
if #current_ships > 0 then
for i, pos in pairs(current_ships) do
if #torrl_aliens.current_ships > 0 then
for i, pos in pairs(torrl_aliens.current_ships) do
minetest.delete_area(pos:subtract(SHIP_SIZE), pos:add(SHIP_SIZE))
end

current_ships = {}
torrl_aliens.current_ships = {}
end
end

Expand All @@ -110,7 +109,7 @@ local function shoot(ship)

repeat
if i then table.remove(ship.turrets, i) end
if #ship.turrets < 1 or #current_ships < 1 then return end -- ship is dead
if #ship.turrets < 1 or #torrl_aliens.current_ships < 1 then return end -- ship is dead

i = math.random(#ship.turrets)

Expand All @@ -128,11 +127,6 @@ local function shoot(ship)
return
end

local time = minetest.get_timeofday()
if time <= 0.82 and time >= 0.18 then
return delete_ships()
end

local dir = pos:direction(ppos)

ppos = ppos:add(dir:multiply(5))
Expand Down Expand Up @@ -191,7 +185,9 @@ end
local timer = 0
local target_timer = 0
local creative = minetest.settings:get_bool("creative_mode", false)
local target_interval = 20
local alien_interval = 120
local alien_interval_night = 20
local trec_placed = false
minetest.register_globalstep(function(dtime)
target_timer = target_timer + dtime

Expand All @@ -210,6 +206,8 @@ minetest.register_globalstep(function(dtime)
end

if meta:get_string("torrl_player:trec_unit_status") == "placed" then
trec_placed = true

local trecpos = minetest.string_to_pos(meta:get_string("torrl_player:trec_unit_pos"))

table.insert(torrl_aliens.target_list, trecpos)
Expand All @@ -220,13 +218,21 @@ minetest.register_globalstep(function(dtime)

if creative then return end

local target = alien_interval
local time = minetest.get_timeofday()
if time >= 0.82 or time <= 0.18 then
torrl_voiceover.say_followed()
target = alien_interval_night
end

if (time >= 0.82 or time <= 0.18) or trec_placed then
timer = timer + dtime
if timer >= target_interval then
target_interval = ALIEN_SHIP_INTERVAL()

if (timer - (target - 30)) >= 3 then
torrl_voiceover.say_followed()
end

if timer >= target then
alien_interval_night = ALIEN_SHIP_INTERVAL()
timer = 0

local players = minetest.get_connected_players()
Expand All @@ -253,7 +259,7 @@ minetest.register_globalstep(function(dtime)

local nodes = minetest.find_nodes_in_area(pos1, pos2, "torrl_aliens:ship_turret")

table.insert(current_ships, pos)
table.insert(torrl_aliens.current_ships, pos)
shoot({turrets = nodes})
end)
end)
Expand Down
1 change: 1 addition & 0 deletions mods/torrl_map/torrl_meteors/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ minetest.register_entity("torrl_meteors:meteor", {

torrl_effects.explosion(pos, 5, torrl_effects.type.fire, function()
minetest.set_node(pos, {name = "torrl_meteors:meteorite"})
minetest.check_for_falling(pos)
minetest.sound_play({name = "torrl_meteors_meteor_explode"}, {
pos = pos,
gain = 3.0,
Expand Down
2 changes: 1 addition & 1 deletion mods/torrl_players/torrl_bgm/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ minetest.register_globalstep(function(dtime)
local time = minetest.get_timeofday()
local day = "day"

if time >= 0.82 or time <= 0.18 then
if #torrl_aliens.current_ships > 0 or (time >= 0.82 or time <= 0.18) then
day = "night"
end

Expand Down
14 changes: 13 additions & 1 deletion mods/torrl_players/torrl_player/comp_unit.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
local companions = {}

function torrl_player.get_companion(pname)
return companions[pname]
end

local function spawn_companion(player)
if not player or not player:is_player() then
minetest.log("error", "[spawn_companion]: Given invalid player")
Expand All @@ -12,6 +18,8 @@ local function spawn_companion(player)
obj:get_luaentity().owner = player:get_player_name()
obj:get_luaentity().follow = player

companions[player:get_player_name()] = obj:get_luaentity()

return obj
end

Expand Down Expand Up @@ -68,7 +76,7 @@ minetest.register_entity("torrl_player:comp_unit", {
local target_pos = self.follow:get_pos():offset(0, 1.5, 0)
local distance = self.object:get_pos():distance(target_pos)
if distance > 3 and not self.started then
self.object:set_velocity(self.object:get_pos():direction(target_pos):multiply(math.min(distance, 15)))
self.object:set_velocity(self.object:get_pos():direction(target_pos):multiply(math.min(distance, 30)))
self.started = true
self.stopped = false
elseif not self.stopped then
Expand Down Expand Up @@ -113,3 +121,7 @@ minetest.register_entity("torrl_player:comp_unit", {
minetest.register_on_joinplayer(function(player)
spawn_companion(player)
end)

minetest.register_on_leaveplayer(function(player)
companions[player:get_player_name()] = nil
end)
6 changes: 3 additions & 3 deletions mods/torrl_players/torrl_tools/hammer_of_power.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ minetest.register_tool("torrl_tools:hammer", {
wield_scale = {x = 1, z = 3, y = 1},
tool_capabilities = {
full_punch_interval = 1,
max_drop_level = 1,
punch_attack_uses = 0,
groupcaps = {
breakable = {times={[1] = 0.2}, uses = 0, maxlevel = 1},
blastable = {times={[1] = 7.0}, uses = 0, maxlevel = 1},
blastable = {times={[1] = 5.0}, uses = 0, maxlevel = 1},
meltable = {times={[1] = 1.0}, uses = 0, maxlevel = 1},
},
damage_groups = {alien = 4},
punch_attack_uses = 0,
},
after_use = function(_, user)
if user and user:is_player() then
Expand Down
5 changes: 2 additions & 3 deletions mods/torrl_players/torrl_tools/sword_of_fire.lua
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,13 @@ minetest.register_tool("torrl_tools:sword", {
inventory_image = "torrl_tools_sword.png",
tool_capabilities = {
full_punch_interval = 0.8,
max_drop_level = 1,
punch_attack_uses = 0,
groupcaps = {
breakable = {times={[1] = 0.5}, uses = 0, maxlevel = 1},
breakable = {times={[1] = 0.2}, uses = 0, maxlevel = 1},
blastable = {times={[1] = 5.0}, uses = 0, maxlevel = 1},
meltable = {times={[1] = 1.0}, uses = 0, maxlevel = 1},
},
damage_groups = {alien = 8},
punch_attack_uses = 0,
},
after_use = function(_, user)
if user and user:is_player() then
Expand Down
9 changes: 7 additions & 2 deletions mods/torrl_players/torrl_voiceover/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ local function say(pname, file, time, text)
end

local function next(pname)
assert(pname)
if not saying[pname] then return end

if saying[pname]._timer then
Expand All @@ -36,6 +37,7 @@ local function next(pname)

minetest.sound_play({name = "torrl_voiceover_skip"}, {
to_player = pname,
object = torrl_player.get_companion(pname).object,
gain = 0.5,
}, true)
end
Expand All @@ -49,14 +51,16 @@ local function next(pname)
end

function say(pname, file, time, text)
assert(pname and file and time and text)
saying[pname]._name = file

minetest.after(0.5, function()
if not saying[pname] then return end

saying[pname]._soundhandle = minetest.sound_play({name = "torrl_voiceover_"..file}, {
to_player = pname,
gain = 1,
object = torrl_player.get_companion(pname).object,
gain = 1.2,
})

minetest.chat_send_player(pname, minetest.colorize(
Expand All @@ -68,12 +72,13 @@ function say(pname, file, time, text)
saying[pname]._timer = nil
saying[pname]._soundhandle = nil

next()
next(pname)
end)
end)
end

local function get_say(times, file, time, text)
assert(times and file and time and text)
local said = {}

local function init(pname)
Expand Down

0 comments on commit 759e781

Please sign in to comment.