From 0560f30ec2dd6eac3acff8ed7d4bcfe2cfcd3ed7 Mon Sep 17 00:00:00 2001 From: Beha Date: Sat, 7 Jan 2017 12:58:32 -0500 Subject: [PATCH] Add teleportation. --- kingdoms/defaults.lua | 2 +- magic/crystals.lua | 11 +++- magic/defaults.lua | 4 +- magic/init.lua | 1 + magic/spells.lua | 8 +++ magic/spells/teleportation.lua | 92 ++++++++++++++++++++++++++++++++++ magic/throwing.lua | 1 + manual.md | 8 +-- 8 files changed, 119 insertions(+), 8 deletions(-) create mode 100644 magic/spells/teleportation.lua diff --git a/kingdoms/defaults.lua b/kingdoms/defaults.lua index 82033ad..13a1995 100644 --- a/kingdoms/defaults.lua +++ b/kingdoms/defaults.lua @@ -34,7 +34,7 @@ kingdoms.config.default_level_talk = 1 -- Talk in the kingdom's main channel. -- A corestone extends in a radius of . kingdoms.config.corestone_radius = 32 -kingdoms.config.corestone_overlap_multiplier = 4 +kingdoms.config.corestone_overlap_multiplier = 3 -- A corestone can be placed only above . kingdoms.config.corestone_miny = -32 diff --git a/magic/crystals.lua b/magic/crystals.lua index 97d1afd..8b63a10 100644 --- a/magic/crystals.lua +++ b/magic/crystals.lua @@ -24,9 +24,16 @@ magic.crystals = { { name = "area", desc = "Area", - color = "#0CC", + color = "#033", light = 8, }, + { + name = "warp", + desc = "Warp", + color = "#0CC", + light = 13, + rarity = 0.5, + }, { name = "control", desc = "Control", @@ -136,7 +143,7 @@ function magic.register_crystal(def, nocraft) sounds = default.node_sound_stone_defaults(), }) - kingdoms.at_mod_load("kingdoms", function() kingdoms.register_dungeon_node("magic:concentrated_crystal_"..def.name, 4 / #magic.crystals) end) + kingdoms.at_mod_load("kingdoms", function() kingdoms.register_dungeon_node("magic:concentrated_crystal_"..def.name, (4 / #magic.crystals) * (def.rarity or 1)) end) minetest.register_craftitem("magic:"..def.name.."_essence", { description = def.desc.." Essence", diff --git a/magic/defaults.lua b/magic/defaults.lua index a058e18..42ef446 100644 --- a/magic/defaults.lua +++ b/magic/defaults.lua @@ -12,6 +12,8 @@ magic.config.mana_fast_regen = 2 -- Search radius of a missile turret. magic.config.turret_missile_radius = 24 - -- Block radius of a defense turret. magic.config.turret_shield_radius = 5 + +-- Delay before actually teleporting. +magic.config.teleportation_delay = 5 diff --git a/magic/init.lua b/magic/init.lua index eb6dde3..61a300a 100644 --- a/magic/init.lua +++ b/magic/init.lua @@ -36,6 +36,7 @@ domodfile("turrets.lua") domodfile("spells/action.lua") domodfile("spells/attack.lua") domodfile("spells/defense.lua") +domodfile("spells/teleportation.lua") magic.log("action", "Loaded.") kingdoms.mod_ready("magic") diff --git a/magic/spells.lua b/magic/spells.lua index 6f5505e..3ccf097 100644 --- a/magic/spells.lua +++ b/magic/spells.lua @@ -19,6 +19,14 @@ function magic.register_spell(name, def) if not docost(player) then return end return f(itemstack, player, pointed_thing) end + elseif def.type == "action" then + function item_def.on_use(itemstack, player, pointed_thing) + if not docost(player) then return end + if def.on_use(itemstack, player, pointed_thing) then + itemstack:take_item() + end + return itemstack + end elseif def.type == "shield" then -- magic.damage_obj handles shields. else diff --git a/magic/spells/teleportation.lua b/magic/spells/teleportation.lua new file mode 100644 index 0000000..8b71c3e --- /dev/null +++ b/magic/spells/teleportation.lua @@ -0,0 +1,92 @@ +local teleporting = {} +minetest.register_globalstep(function(dtime) + for _, player in pairs(minetest.get_connected_players()) do + local name = player:get_player_name() + local tp = teleporting[name] + if tp then + tp.timer = tp.timer + dtime + if vector.distance(player:getpos(), tp.start) > 0.1 then + magic.cancel_teleportation(name) + elseif tp.timer >= tp.delay then + minetest.registered_items[tp.item].original.go(player) + teleporting[name] = nil + end + end + end +end) + +function magic.start_teleportation(player, item, delay) + local name = player:get_player_name() + if teleporting[name] then + magic.cancel_teleportation(name) + end + teleporting[name] = { + timer = 0, + delay = delay, + item = item, + start = player:getpos(), + } + minetest.chat_send_player(name, "Teleportation will occur in "..tostring(delay).." seconds. Remain still.") +end + +function magic.cancel_teleportation(name) + minetest.chat_send_player(name, "Teleportation has been canceled.") + teleporting[name] = nil +end + +minetest.register_on_leaveplayer(function(player) + magic.cancel_teleportation(player:get_player_name()) +end) + +magic.register_spell("magic:spell_teleport_spawn", { + description = "Spawn Teleportation Spell", + type = "action", + color = "#0A0", + emblem = "action", + cost = 15, + on_use = function(itemstack, player) + magic.start_teleportation(player, itemstack:get_name(), magic.config.teleportation_delay) + return true + end, + go = function(player) + if not kingdoms.db.servercorestone then + minetest.chat_send_player(player:get_player_name(), "There is no destination.") + return + end + player:setpos(vector.add(kingdoms.db.servercorestone, {x=0, y=1, z=0})) + end, +}) +minetest.register_craft({ + output = "magic:spell_teleport_spawn", + recipe = { + {"magic:concentrated_warp_essence", "magic:control_essence"}, + {"group:minor_spellbinding", "default:sapling"}, + }, +}) + +magic.register_spell("magic:spell_teleport_kingdom", { + description = "Kingdom Teleportation Spell", + type = "action", + color = "#FA0", + emblem = "action", + cost = 15, + on_use = function(itemstack, player) + magic.start_teleportation(player, itemstack:get_name(), magic.config.teleportation_delay) + return true + end, + go = function(player) + local kingdom = kingdoms.player.kingdom(player:get_player_name()) + if not kingdom or not kingdom.corestone.pos then + minetest.chat_send_player(player:get_player_name(), "There is no destination.") + return + end + player:setpos(vector.add(kingdom.corestone.pos, {x=0, y=1, z=0})) + end, +}) +minetest.register_craft({ + output = "magic:spell_teleport_kingdom", + recipe = { + {"magic:concentrated_warp_essence", "magic:control_essence"}, + {"group:minor_spellbinding", "default:junglesapling"}, + }, +}) diff --git a/magic/throwing.lua b/magic/throwing.lua index 036a091..f3f3dbf 100644 --- a/magic/throwing.lua +++ b/magic/throwing.lua @@ -97,6 +97,7 @@ function magic.register_missile(name, texture, def, item_def) local ent_def = { physical = false, + hp_max = math.ceil(def.cost / 2), timer=0, particletimer = 0, visual = "sprite", diff --git a/manual.md b/manual.md index 6ab3401..db51858 100644 --- a/manual.md +++ b/manual.md @@ -7,10 +7,10 @@ Either way you join a kindom, you will be greeted with the standard kingdoms int ## Claiming Land -Without a land claim, you would be forced to hide from other players who would have unrestricted ability to destroy your work. This is solved by the presence of *Corestones*, which, once placed, claim a 50x50x50 cube of land where nobody else can build or access devices unless they have an appropriate level in the kingdom. -These claims cannot overlap with other claims, and must be spaced with at least 50 nodes between their areas so that there is plenty of neutral land that cannot be claimed. They also cannot be placed below -32y, avoiding claiming of mining zones. +Without a land claim, you would be forced to hide from other players who would have unrestricted ability to destroy your work. This is solved by the presence of *Corestones*, which, once placed, claim a 64x64x64 cube of land where nobody else can build or access devices unless they have an appropriate level in the kingdom. +These claims cannot overlap with other claims, and must be spaced with at least 64 nodes between their areas so that there is plenty of neutral land that cannot be claimed. They also cannot be placed below -32y, avoiding claiming of mining zones. -50x50x50 is somewhat restrictive, however, and even the neutral area around a corestone could be consumed by larger kingdoms. Outside of the neutral area, there is a possibility that a new corestone could be placed, undermining all the building you have done there. To counter this, you can place *Claim wards*, which prevent corestones from being placed if the ward would land inside the claimed zone. +64x64x64 is somewhat restrictive, however, and even the neutral area around a corestone could be consumed by larger kingdoms. Outside of the neutral area, there is a possibility that a new corestone could be placed, undermining all the building you have done there. To counter this, you can place *Claim wards*, which prevent corestones from being placed if the ward would land inside the claimed zone. ## Defending Land @@ -21,7 +21,7 @@ Defending a neutral area, or even preventing enemies from entering your clamied ## Destroying a Corestone -The ability to take over another kingdom's claim is a large part of the game, and this is facilitated by *Core Disruptors*. When placed within a 75x75x75 cube centered around the target corestone, the target's *corestone score* will begin to decrease slowly, lowering faster depending on how many disruptors you can place. When this score reaches zero, the corestone will vanish and you can pillage the now-unprotected area. +The ability to take over another kingdom's claim is a large part of the game, and this is facilitated by *Core Disruptors*. When placed within a 96x96x96 cube centered around the target corestone, the target's *corestone score* will begin to decrease slowly, lowering faster depending on how many disruptors you can place. When this score reaches zero, the corestone will vanish and you can pillage the now-unprotected area. ### Defense