From 17eb95157b7c48b5cf81fcb9bce8463a9c0ba0de Mon Sep 17 00:00:00 2001 From: Beha Date: Sat, 7 Jan 2017 14:58:33 -0500 Subject: [PATCH] Add short teleportation. --- kingdoms/utils.lua | 18 ++++++++++++++++++ magic/defaults.lua | 5 +++-- magic/spells.lua | 1 + magic/spells/teleportation.lua | 27 +++++++++++++++++++++++++++ magic/throwing.lua | 6 ++++++ magic/turrets.lua | 2 +- 6 files changed, 56 insertions(+), 3 deletions(-) diff --git a/kingdoms/utils.lua b/kingdoms/utils.lua index 01fb6c0..b7634fa 100644 --- a/kingdoms/utils.lua +++ b/kingdoms/utils.lua @@ -83,3 +83,21 @@ function kingdoms.utils.shuffled(t_in) end return ret end + +kingdoms.db.forceloaded = kingdoms.db.forceloaded or {} + +for _,pos in ipairs(kingdoms.db.forceloaded) do + minetest.forceload_free_block(pos) +end + +function kingdoms.utils.load_pos(pos) + minetest.setting_set("max_forceloaded_blocks", tostring((minetest.setting_get("max_forceloaded_blocks") or 16) + 1)) + if not minetest.forceload_block(pos) then + error("Could not forceload at "..minetest.pos_to_string(pos)) + end + table.insert(kingdoms.db.forceloaded, pos) + minetest.after(1, function(pos) + minetest.forceload_free_block(pos) + minetest.setting_set("max_forceloaded_blocks", tostring((minetest.setting_get("max_forceloaded_blocks") or 16) - 1)) + end, pos) +end diff --git a/magic/defaults.lua b/magic/defaults.lua index 42ef446..e845ae0 100644 --- a/magic/defaults.lua +++ b/magic/defaults.lua @@ -3,10 +3,8 @@ magic.config.max_mana = 20 -- Seconds to regnerate one mana point. (Faster if mana_fast_regen_threshold applies.) magic.config.mana_regen = 6 - -- If player HP is >= this, mana will regenerate faster. magic.config.mana_fast_regen_threshold = 18 - -- Fast regeneration multiplier. magic.config.mana_fast_regen = 2 @@ -17,3 +15,6 @@ magic.config.turret_shield_radius = 5 -- Delay before actually teleporting. magic.config.teleportation_delay = 5 + +-- Enable short teleports. +magic.config.enable_short_teleports = true diff --git a/magic/spells.lua b/magic/spells.lua index 3ccf097..1d9ba87 100644 --- a/magic/spells.lua +++ b/magic/spells.lua @@ -38,6 +38,7 @@ end -- Convert all damage to fleshy. function magic.damage_obj(obj, g) local groups = table.copy(g) + -- If the target is a player, apply shields. if obj:is_player() then local heldstack = obj:get_wielded_item() local def = minetest.registered_items[heldstack:get_name()] diff --git a/magic/spells/teleportation.lua b/magic/spells/teleportation.lua index 8b71c3e..b4171dc 100644 --- a/magic/spells/teleportation.lua +++ b/magic/spells/teleportation.lua @@ -90,3 +90,30 @@ minetest.register_craft({ {"group:minor_spellbinding", "default:junglesapling"}, }, }) + +if magic.config.enable_short_teleports then + magic.register_spell("magic:spell_short_teleport", { + description = "Short Teleportation Spell", + type = "missile", + color = "#F0F", + emblem = "action", + speed = 10, + cost = 7, + gravity = 0.35, + forceload = true, + hit_node = function(self, pos, last_empty_pos) + if self.player then + self.player:setpos(last_empty_pos) + end + return true + end, + hit_object = function() return false end + }) + minetest.register_craft({ + output = "magic:spell_short_teleport", + recipe = { + {"magic:concentrated_warp_essence", "magic:control_essence"}, + {"group:minor_spellbinding", ""}, + }, + }) +end diff --git a/magic/throwing.lua b/magic/throwing.lua index f3f3dbf..247d64f 100644 --- a/magic/throwing.lua +++ b/magic/throwing.lua @@ -205,6 +205,12 @@ function magic.register_missile(name, texture, def, item_def) return false end + if def.forceload then + for pos in rayIter(line.start, vector.normalize(self.object:getvelocity()), math.max(64, vector.distance(line.start, line.finish) * 2)) do + kingdoms.utils.load_pos(pos) + end + end + for _,pos in ipairs(kingdoms.utils.find_nodes_by_area(pos, magic.config.turret_shield_radius, {"magic:turret"})) do if self.kingdom == minetest.get_meta(pos):get_string("kingdom.id") then break diff --git a/magic/turrets.lua b/magic/turrets.lua index e646edc..d03bf08 100644 --- a/magic/turrets.lua +++ b/magic/turrets.lua @@ -6,7 +6,7 @@ local function update_formspec(pos) meta:set_string("formspec", ([[ size[8,6] label[0,0.1;Input spells. Current: ]]..tostring(name).." qty "..tostring(count)..[[] - button[0,1;8,1;setp_%d;Only Players (Current: %s)] + button[0,1;8,1;setp_%d;Only target players (current: %s)] list[context;input;7,0;1,1;] list[current_player;main;0,2;8,4;] ]]):format(meta:get_int("onlyplayers"), (meta:get_int("onlyplayers") == 1) and "yes" or "no"))