Skip to content
This repository has been archived by the owner on Nov 12, 2018. It is now read-only.

Commit

Permalink
Add short teleportation.
Browse files Browse the repository at this point in the history
  • Loading branch information
linewriter1024 committed Jan 7, 2017
1 parent 0560f30 commit 17eb951
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 3 deletions.
18 changes: 18 additions & 0 deletions kingdoms/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions magic/defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
1 change: 1 addition & 0 deletions magic/spells.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
Expand Down
27 changes: 27 additions & 0 deletions magic/spells/teleportation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions magic/throwing.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion magic/turrets.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down

0 comments on commit 17eb951

Please sign in to comment.