From 759e781028f17bafad33036d2e030f127de059c6 Mon Sep 17 00:00:00 2001 From: LoneWolfHT Date: Thu, 30 Nov 2023 18:05:07 -0800 Subject: [PATCH] Fix some bugs/issues, make aliens spawn during the day --- .luacheckrc | 1 + mods/torrl_aliens/init.lua | 38 +++++++++++-------- mods/torrl_map/torrl_meteors/init.lua | 1 + mods/torrl_players/torrl_bgm/init.lua | 2 +- mods/torrl_players/torrl_player/comp_unit.lua | 14 ++++++- .../torrl_tools/hammer_of_power.lua | 6 +-- .../torrl_tools/sword_of_fire.lua | 5 +-- mods/torrl_players/torrl_voiceover/init.lua | 9 ++++- 8 files changed, 50 insertions(+), 26 deletions(-) diff --git a/.luacheckrc b/.luacheckrc index 8b349ce..3eb3f1a 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -9,6 +9,7 @@ globals = { "creatura", "fire", "player_api", + "unpack", "VoxelManip", "VoxelArea", "PseudoRandom", "ItemStack", "Settings", "vector", "table", "string", "dump", diff --git a/mods/torrl_aliens/init.lua b/mods/torrl_aliens/init.lua index 4f70fe1..94cd884 100644 --- a/mods/torrl_aliens/init.lua +++ b/mods/torrl_aliens/init.lua @@ -1,6 +1,7 @@ torrl_aliens = { target_list = {}, target_list_trecs = {}, + current_ships = {}, } local modpath = minetest.get_modpath(minetest.get_current_modname()) .. "/" @@ -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 @@ -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) @@ -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)) @@ -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 @@ -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) @@ -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() @@ -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) diff --git a/mods/torrl_map/torrl_meteors/init.lua b/mods/torrl_map/torrl_meteors/init.lua index 5377392..e8eaa49 100644 --- a/mods/torrl_map/torrl_meteors/init.lua +++ b/mods/torrl_map/torrl_meteors/init.lua @@ -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, diff --git a/mods/torrl_players/torrl_bgm/init.lua b/mods/torrl_players/torrl_bgm/init.lua index 79d3d3a..a1270e6 100644 --- a/mods/torrl_players/torrl_bgm/init.lua +++ b/mods/torrl_players/torrl_bgm/init.lua @@ -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 diff --git a/mods/torrl_players/torrl_player/comp_unit.lua b/mods/torrl_players/torrl_player/comp_unit.lua index 4935c16..e0c6994 100644 --- a/mods/torrl_players/torrl_player/comp_unit.lua +++ b/mods/torrl_players/torrl_player/comp_unit.lua @@ -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") @@ -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 @@ -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 @@ -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) \ No newline at end of file diff --git a/mods/torrl_players/torrl_tools/hammer_of_power.lua b/mods/torrl_players/torrl_tools/hammer_of_power.lua index aba67e1..a97d47e 100644 --- a/mods/torrl_players/torrl_tools/hammer_of_power.lua +++ b/mods/torrl_players/torrl_tools/hammer_of_power.lua @@ -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 diff --git a/mods/torrl_players/torrl_tools/sword_of_fire.lua b/mods/torrl_players/torrl_tools/sword_of_fire.lua index 50b126d..2a061dd 100644 --- a/mods/torrl_players/torrl_tools/sword_of_fire.lua +++ b/mods/torrl_players/torrl_tools/sword_of_fire.lua @@ -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 diff --git a/mods/torrl_players/torrl_voiceover/init.lua b/mods/torrl_players/torrl_voiceover/init.lua index 86d3d60..640d7f5 100644 --- a/mods/torrl_players/torrl_voiceover/init.lua +++ b/mods/torrl_players/torrl_voiceover/init.lua @@ -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 @@ -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 @@ -49,6 +51,7 @@ 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() @@ -56,7 +59,8 @@ function say(pname, file, time, text) 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( @@ -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)