Locked chests and magic!

master
francisco athens 2020-07-28 00:06:44 -07:00
parent cf9e69a058
commit 7db75fe2fe
6 changed files with 236 additions and 55 deletions

View File

@ -38,8 +38,8 @@
-- * cavegen may eat holes into the ground below the house
-- * houses may very seldom overlap
local witches_dungon_cellar_chance = tonumber(minetest.settings:get("witches_dungon_cellar_chance")) or .50
local witches_dungon_cellar_depth = tonumber(minetest.settings:get("witches_dungon_cellar_depth")) or -5
local witches_dungeon_cellar_chance = tonumber(minetest.settings:get("witches_dungeon_cellar_chance")) or .50
local witches_dungeon_cellar_depth = tonumber(minetest.settings:get("witches_dungeon_cellar_depth")) or -5
witches.bh = {};
@ -70,7 +70,7 @@ witches.bh.lamp = "default:torch_wall";
-- floor at the entrance level of the house
witches.bh.floor = "default:cobble";
-- placed randomly in some houses
witches.bh.chest = "default:chest";
witches.bh.chest = "default:chest_locked";
witches.bh.bookshelf ="default:bookshelf"
witches.bh.bed = "beds:bed"
-- glass can be glass panes, iron bars or solid glass
@ -139,8 +139,8 @@ end
--lets see if any dungeons are near
minetest.set_gen_notify("dungeon")
local dungeon_cellar = {
chance = tonumber(witches_dungon_cellar_chance), -- chance to try putting cottage over dungeon instead of anywhere else
max_depth = tonumber(witches_dungon_cellar_depth) -- deepest dungeon depth to check
chance = tonumber(witches_dungeon_cellar_chance), -- chance to try putting cottage over dungeon instead of anywhere else
max_depth = tonumber(witches_dungeon_cellar_depth) -- deepest dungeon depth to check
}
local dungeon_list ={}
@ -172,7 +172,7 @@ end)
-- rotation_1 param2 for materials.wall nodes for the first wall
-- rotation_2 param2 for materials.wall nodes for the second wall
-- vm voxel manipulator
local window_pos = {}
witches.bh.build_two_walls = function( p, sizex, sizez, in_x_direction, materials, vm, pr)
local v = 0;
@ -255,9 +255,7 @@ witches.bh.build_two_walls = function( p, sizex, sizez, in_x_direction, material
-- if there is a window in this wall...
if( materials.window_at_height[ height ]==1 and wall_1_has_window) then
node = node_glass_1;
if minetest.get_modpath("beds") then
window_pos[#window_pos+1] = {x= w1_x, y=p.y+1,z=w1_z}
end
else
--print("wall1: x"..w1_x.." z"..w1_z)
node = node_wall_1;
@ -268,15 +266,13 @@ witches.bh.build_two_walls = function( p, sizex, sizez, in_x_direction, material
end
vm:set_node_at( {x=w1_x, y=p.y+height, z=w1_z}, node);
-- ..or in the other wall
if( materials.window_at_height[ height ]==1 and (wall_2_has_window)) then
node = node_glass_2;
if minetest.get_modpath("beds") then
window_pos[#window_pos+1] = {x= w2_x, y=p.y+1,z=w2_z}
end
else
--print("wall2: x"..w2_x.." z"..w2_z)
node = node_wall_2;
@ -285,7 +281,8 @@ witches.bh.build_two_walls = function( p, sizex, sizez, in_x_direction, material
node = node_wall_1;
end
end
end
vm:set_node_at( {x=w2_x, y=p.y+height, z=w2_z}, node);
end
@ -301,7 +298,6 @@ witches.bh.build_two_walls = function( p, sizex, sizez, in_x_direction, material
return {special_wall_1, special_wall_2, window_at_odd_row};
end
-- roofs may extend in x or z direction
local pswap = function( pos, swap )
if( not( swap )) then
@ -410,7 +406,6 @@ witches.bh.get_random_place = function( p, sizex, sizez, places, use_this_one, a
end
end
-- add a ladder from bottom to top (staircases would be nicer but are too difficult to do well)
-- if flat_roof is false, the ladder needs to be placed on the smaller side so that people can
-- actually climb it;
@ -488,6 +483,7 @@ witches.bh.place_chest = function( p, sizex, sizez, chest_places, wall_with_ladd
-- determine target position
local pos = {x=res.x, y=height+1, z=res.z};
local pos_bk = {x=res.x, y=height_bk+1, z=res.z};
-- if plasterwork is installed: place a machine
@ -506,8 +502,9 @@ witches.bh.place_chest = function( p, sizex, sizez, chest_places, wall_with_ladd
return;
end
-- place the chest
--place bookshelf on first floor
--set place bookshelf on first floor
vm:set_node_at( pos, {name=witches.bh.chest, param2 = res.p2n});
--placed_nodes.pos_bk = {name=witches.bh.bookshelf, param2 = res.p2n};
--if math.random()< 0.50 and not minetest.find_node_near(pos_bk, 2, {witches.bh.door_bottom,witches.bh.ladder}) then
-- vm:set_node_at( pos_bk, {name=witches.bh.bookshelf, param2 = res.p2n});
@ -522,8 +519,25 @@ witches.bh.place_chest = function( p, sizex, sizez, chest_places, wall_with_ladd
end
-- fill chest with building material
minetest.registered_nodes[ witches.bh.chest ].on_construct( pos );
local secret_name = witches.generate_text(witches.name_parts_female)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory();
if witches.bh.chest == "default:chest_locked" then
meta:set_string("secret_type", "witches_chest")
meta:set_string("secret_name", secret_name)
meta:set_string("owner",secret_name)
meta:set_string("infotext", "Sealed chest of "..secret_name)
if minetest.get_modpath("fireflies") then
inv:add_item( "main", {name = "fireflies:bug_net"})
end
inv:add_item( "main", {name = "default:mese_lamp"})
if math.random() < 0.50 then
for i=1,math.random(3) do
inv:add_item( "main", {name = "default:diamond"})
end
end
end
local c = pr:next(1,4);
for i=1,c do
local stack_name = materials.walls.." "..pr:next(1,99);
@ -542,6 +556,20 @@ witches.bh.place_chest = function( p, sizex, sizez, chest_places, wall_with_ladd
inv:add_item( "main", materials.roof.." "..pr:next(1,99) );
inv:add_item( "main", materials.roof_middle.." "..pr:next(1,49) );
end
inv:add_item( "main", {name = witches.bh.bookshelf});
if minetest.get_modpath("beds") then
inv:add_item( "main", {name = witches.bh.bed} );
end
if minetest.get_modpath("fireflies") then
inv:add_item( "main", {name = "fireflies:firefly_bottle"} );
end
if minetest.get_modpath("bucket") then
inv:add_item( "main", {name = "bucket:bucket_empty"} );
end
if minetest.get_modpath("dye") then
local dname = dye.dyes[math.random(1,#dye.dyes)][1]
inv:add_item( "main", {name = "dye:"..dname })
end
end

View File

@ -5,7 +5,7 @@
local path = minetest.get_modpath("witches")
witches = {}
witches.version = "20200726"
witches.version = "20200728"
print("this is Witches "..witches.version)
-- Strips any kind of escape codes (translation, colors) from a string
@ -57,6 +57,7 @@ else
end
dofile(path .. "/utilities.lua")
dofile(path .. "/magic.lua")
dofile(path .. "/ui.lua")
dofile(path .. "/items.lua")
dofile(path .. "/nodes.lua")
@ -126,7 +127,7 @@ local witch_types = {
"flowers:mushroom_brown","flowers:mushroom_red"},
do_custom_addendum = function(self)
if math.random() < .0005 and minetest.registered_nodes["fireflies:firefly"] then
if math.random() < .0001 and minetest.registered_nodes["fireflies:firefly"] then
local pos = self.object:get_pos()
pos.y = pos.y+1
local pos1 = minetest.find_node_near(pos, 3, "air")
@ -137,31 +138,8 @@ local witch_types = {
on_spawn_addendum = function(self)
--print(dump(self.drops).."and"..dump(minetest.registered_tools))
if minetest.registered_tools["fireflies:bug_net"] then
local check = 0
for i=1,#self.drops do
if self.drops[i].name == "fireflies:bug_net" then
check = check +1
end
end
witches.firefly_mod(self)
if check < 1 then
table.insert(self.drops,1,
{name = "fireflies:bug_net",
chance = 1000, min = 0, max = 1})
table.insert(self.drops,
{name = "fireflies:firefly_bottle",
chance = 100, min = 0, max = 2})
end
end
end
}
},
@ -173,6 +151,11 @@ local witch_types = {
special_follow = {"default:diamond", "default:gold_lump", "default:apple",
"default:blueberries", "default:torch", "default:stick",
"flowers:mushroom_brown","flowers:mushroom_red"},
do_custom_addendum = function(self)
end,
on_spawn_addendum = function(self)
witches.claim_witches_chest(self)
end
},
spawning = spawning.cottage,
}
@ -258,11 +241,15 @@ local witch_template = { --your average witch,
special_follow = {"default:diamond", "default:gold_lump", "default:apple",
"default:blueberries", "default:torch", "default:stick",
"flowers:mushroom_brown","flowers:mushroom_red"},
},
},
do_punch = function(self,hitter)
witches.magic.teleport(self,hitter)
end,
on_rightclick = function(self,clicker)
witches.quests(self,clicker)
end,
do_custom = function(self)
if self.do_custom_addendum then
self.do_custom_addendum(self)

63
magic.lua Normal file
View File

@ -0,0 +1,63 @@
witches.magic = {}
local magic_texture = "bubble.png"
local magic_animation = nil
if minetest.registered_nodes["fireflies:firefly"] then
magic_texture = "fireflies_firefly_animated.png"
magic_animation = {
type = "vertical_frames",
aspect_w = 16,
aspect_h = 16,
length = 1.5
}
else
magic_texture = "bubble.png"
magic_animation = nil
end
function witches.magic.teleport(self,target)
local mob_pos = self.object:get_pos()
local player_pos = {}
if target then
if target:is_player() then
player_pos = target:get_pos()
else
end
witches.stop_and_face(self,player_pos)
local new_player_pos = vector.add(player_pos, vector.multiply(vector.direction(mob_pos, player_pos),8))
new_player_pos.y = player_pos.y +5
--print(minetest.pos_to_string(player_pos))
--print(minetest.pos_to_string(mob_pos))
--print(minetest.pos_to_string(new_player_pos))
target:set_pos(new_player_pos)
minetest.add_particlespawner({
amount=50,
time=.1,
minpos= mob_pos,
maxpos= new_player_pos,
minvel={x=0, y=0, z=0},
maxvel={x=0, y=1, z=0},
minacc={x=0, y=0, z=0},
maxacc={x=0, y=1, z=0},
minexptime=.01,
maxexptime=.5,
minsize=1,
maxsize=2,
collisiondetection=false,
texture= magic_texture,
animation = magic_animation,
glow = 10,
player = target:get_player_name()
})
witches.stop_and_face(self,new_player_pos)
end
end

View File

@ -19,6 +19,31 @@ else
})
end
minetest.register_node("witches:tree", {
tiles = {
"default_tree_top.png",
"default_tree_top.png",
"default_tree.png",
"default_tree.png",
"default_tree.png",
"default_tree.png"
},
paramtype2 = "facedir",
is_ground_content = false,
groups = {tree = 1, choppy = 2, oddly_breakable_by_hand = 1, flammable = 2},
sounds = default.node_sound_wood_defaults(),
on_place = minetest.rotate_node,
drawtype = "nodebox",
paramtype = "light",
node_box = {
type = "fixed",
fixed = {
{-0.375, -0.5, -0.5, 0.375, 0.5, 0.5}, -- NodeBox1
{-0.5, -0.5, -0.375, 0.5, 0.5, 0.375}, -- NodeBox2
}
}
})
--]]
-- the following are based on: https://dev.minetest.net/L-system_tree_examples
witches.acacia_tree={

View File

@ -1,10 +1,4 @@
# chance (1-99) of a witch house spawning over a dungeon instead of anywhere else (requires Sokomines handle_schematics mod!)
witches_dungon_cellar_chance (chance as decimal like .5 of a witch house spawning over a dungeon instead of anywhere else) float .5
# depth (1-20) maximum depth of a dungeon to spawn a witch house over (requires Sokomines handle_schematics mod!)
witches_dungon_cellar_depth (maximum depth 0 to -20 of a dungeon to spawn a witch house over) int -5
#maximum number of houses per mapchunk
witches_house_max_per_mapchunk (maximum number of houses per mapchunk) int 2
@ -12,3 +6,11 @@ witches_house_max_per_mapchunk (maximum number of houses per mapchunk) int 2
witches_houses_wanted_per_mapchunk (average number of houses to mapchunks over the world) float .05
# chance (1-99) of a witch house spawning over a dungeon instead of anywhere else (requires Sokomines handle_schematics mod!)
witches_dungeon_cellar_chance (chance as decimal like .5 of a witch house spawning over a dungeon instead of anywhere else) float .5
# depth (1-20) maximum depth of a dungeon to spawn a witch house over (requires Sokomines handle_schematics mod!)
witches_dungeon_cellar_depth (maximum depth 0 to -20 of a dungeon to spawn a witch house over) int -5

View File

@ -267,7 +267,7 @@ function witches.gift(self, pname, drop_chance_min, drop_chance_max, item_wear )
meta:set_string(
"description", S("@1's @2", self.secret_name, org_desc)
)
print("stack meta "..dump(meta))
--print("stack meta "..dump(meta))
for i=1,#inv:get_lists() do
--print(i.." = "..dump(v))
@ -305,18 +305,89 @@ function witches.attachment_check(self)
end
end
local function stop_and_face(self,pos)
function witches.stop_and_face(self,pos)
mobs:yaw_to_pos(self, pos)
self.state = "stand"
self:set_velocity(0)
self:set_animation("stand")
self.attack = nil
self.v_start = false
self.timer = 0
self.timer = -5
self.pause_timer = .25
self.blinktimer = 0
self.path.way = nil
end
local function stop_and_face(self,pos)
witches.stop_and_face(self,pos)
end
function witches.award_witches_chest(self,player)
if player and self.witches_chest and self.witches_chest_owner == self.secret_name then
local pname = ""
local meta = minetest.get_meta(self.witches_chest_pos)
if player:is_player() then pname = player:get_player_name() end
meta:set_string("owner", pname)
local sname = meta:get_string("secret_name")
local info = {self.secret_name,sname,self.witches_chest_pos,pname}
local pos_string = minetest.pos_to_string(info[3])
local reward_text = S("You receive permission from @1 to access the magic chest of @2!\n(@3)",
info[1],info[2],pos_string)
local reward = {r_text = reward_text, r_item = "default:locked_chest"}
meta:set_string("infotext",S("@1's chest of @2",info[1],info[2]))
return reward
end
end
function witches.claim_witches_chest(self)
local pos=self.object:get_pos()
pos.min = vector.subtract(pos,10)
pos.max = vector.add(pos,10)
local meta_table = minetest.find_nodes_with_meta(pos.min, pos.max)
--if meta_table then print(dump(meta_table)) end
for i=1,#meta_table do
local meta = minetest.get_meta(meta_table[i])
if meta:get_string("secret_type") == "witches_chest" then
local sn = meta:get_string("secret_name")
-- if sn then print(sn) end
local o = meta:get_string("owner")
if o and sn and sn == o then
print("unbound chest: "..sn)
meta:set_string("owner", self.secret_name)
meta:set_string("infotext", self.secret_name.."'s sealed chest of ".. sn)
self.witches_chest = sn
self.witches_chest_owner = self.secret_name
self.witches_chest_pos = meta_table[i]
end
end
end
end
function witches.firefly_mod(self)
if minetest.registered_tools["fireflies:bug_net"] then
local check = 0
for i=1,#self.drops do
if self.drops[i].name == "fireflies:bug_net" then
check = check +1
end
end
if check < 1 then
table.insert(self.drops,1,
{name = "fireflies:bug_net",
chance = 1000, min = 0, max = 1})
table.insert(self.drops,
{name = "fireflies:firefly_bottle",
chance = 100, min = 0, max = 2})
end
end
end
function witches.item_request(self,name)
self.speaking_to = name
if not self.item_request then self.item_request = {} end
@ -371,7 +442,12 @@ function witches.found_item(self,clicker)
--print(self.secret_name.." has now received 2 favors"..self.players[pname].favors.." from " ..pname)
if self.players[pname].favors >=3 and math.fmod(18, self.players[pname].favors) == 0 then
reward = witches.special_gifts(self,pname)
if self.witches_chest and self.witches_chest_owner == self.secret_name then
reward = witches.award_witches_chest(self,clicker)
else
reward = witches.special_gifts(self,pname)
end
else
reward = witches.gift(self,pname)