123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502 |
- lottpotion = {}
- dofile(minetest.get_modpath("lottpotion").."/cauldron.lua")
- lottpotion = {
- players = {},
- deaths = {},
- effects = {
- phys_override = function(sname, name, fname, time, sdata, flags)
- local def = {
- on_use = function(itemstack, user, pointed_thing)
- lottpotion.grant(time, user:get_player_name(), fname.."_"..flags.type..sdata.type, name, flags)
- itemstack:take_item()
- return itemstack
- end,
- lottpotion = {
- speed = 0,
- jump = 0,
- gravity = 0,
- air = 0,
- hp = 0,
- alive = 1,
- },
- }
- return def
- end,
- fixhp = function(sname, name, fname, time, sdata, flags)
- local def = {
- on_use = function(itemstack, user, pointed_thing)
- local hp_change = sdata.hp or 3
- if flags.inv == true then
- hp_change = -hp_change
- end
- local h = lottpotion.players[user:get_player_name()].hp
- lottpotion.players[user:get_player_name()].hp = h + hp_change
- minetest.after(sdata.time, function()
- if user ~= nil then
- h = lottpotion.players[user:get_player_name()].hp
- lottpotion.players[user:get_player_name()].hp = h - hp_change
- end
- end)
- itemstack:take_item()
- return itemstack
- end,
- }
- def.mobs = {
- on_near = def.on_use,
- }
- return def
- end,
- air = function(sname, name, fname, time, sdata, flags)
- local def = {
- on_use = function(itemstack, user, pointed_thing)
- local br_change = sdata.br or 3
- if flags.inv == true then
- br_change = -br_change
- end
- local b = lottpotion.players[user:get_player_name()].air
- lottpotion.players[user:get_player_name()].air = br_change
- minetest.after(sdata.time, function()
- if user ~= nil then
- b = lottpotion.players[user:get_player_name()].air
- lottpotion.players[user:get_player_name()].air = b - br_change
- end
- end)
- itemstack:take_item()
- return itemstack
- end,
- }
- return def
- end,
- },
- grant = function(time, playername, potion_name, type, flags)
- local rootdef = minetest.registered_items[potion_name]
- if rootdef == nil then
- return
- end
- if rootdef.lottpotion == nil then
- return
- end
- local def = {}
- for name, val in pairs(rootdef.lottpotion) do
- def[name] = val
- end
- if flags.inv==true then
- def.gravity = 0 - def.gravity
- def.speed = 0 - def.speed
- def.jump = 0 - def.jump
- end
- lottpotion.addPrefs(playername, def.speed, def.jump, def.gravity)
- lottpotion.refresh(playername)
- local deaths = lottpotion.deaths or 0
- minetest.chat_send_player(playername, "You are under the effects of the "..type.." potion.")
- minetest.after(time, function()
- local new_deaths = lottpotion.deaths or 0
- if new_deaths == deaths then
- lottpotion.addPrefs(playername, 0-def.speed, 0-def.jump, 0-def.gravity)
- lottpotion.refresh(playername)
- minetest.chat_send_player(playername, "The effects of the "..type.." potion have worn off.")
- end
- end)
- end,
- addPrefs = function(playername, speed, jump, gravity)
- local prefs = lottpotion.players[playername]
- prefs.speed = prefs.speed + speed
- if prefs.speed > 5 then
- prefs.speed = 5
- elseif prefs.speed < 0 then
- prefs.speed = 0
- end
- prefs.jump = prefs.jump + jump
- if prefs.jump > 2.5 then
- prefs.jump = 2.5
- elseif prefs.jump < 0 then
- prefs.jump = 0
- end
- prefs.gravity = prefs.gravity + gravity
- if prefs.gravity > 4 then
- prefs.gravity = 4
- elseif prefs.gravity < 0 then
- prefs.gravity = 0
- end
- end,
- refresh = function(playername)
- if minetest.get_player_by_name(playername)~=nil then
- local prefs = lottpotion.players[playername]
- minetest.get_player_by_name(playername):set_physics_override(prefs.speed, prefs.jump, prefs.gravity)
- end
- end,
- register_potion = function(sname, name, fname, time, def)
- local tps = {"power", "corruption"}
- for t=1, #tps do
- for i=1, #def.types do
- local sdata = def.types[i]
- local item_def = {
- description = name .. "\nStrength: " .. tps[t]:gsub("^%l", string.upper)
- .. " " .. sdata.type,
- inventory_image = "lottpotion_bottle.png^lottpotion_"..
- (def.texture or sname)..".png^lottpotion_"..
- tps[t]..sdata.type..".png",
- drawtype = "plantlike",
- paramtype = "light",
- walkable = false,
- groups = {dig_immediate=3,attached_node=1,vessel=1},
- sounds = default.node_sound_glass_defaults(),
- }
- item_def.tiles = {item_def.inventory_image}
- local flags = {
- inv = false,
- type = tps[t],
- }
- if t == 2 then
- flags.inv = true
- end
- for name, val in pairs(lottpotion.effects[def.effect](sname, name, fname, time, sdata, flags)) do
- item_def[name] = val
- end
- for name, val in pairs(sdata.set) do
- item_def[name] = val
- end
- for name, val in pairs(sdata.effects) do
- item_def.lottpotion[name] = val
- end
- minetest.register_node(fname.."_"..tps[t]..sdata.type, item_def)
- --potions.register_liquid(i..tps[t]..sname, name.." ("..tps[t].." "..i..")", item_def.on_use)
- if minetest.get_modpath("lottthrowing")~=nil then
- lottpotion.register_arrow(
- fname.."_"..tps[t]..sdata.type,
- i..tps[t]..sname,
- name.." ("..tps[t].." "..i..")",
- item_def.on_use,
- item_def.description,
- item_def.inventory_image
- )
- end
- end
- end
- end,
- }
- dofile(minetest.get_modpath("lottpotion").."/arrows.lua")
- local time = 0
- minetest.register_globalstep(function(dtime)
- time = time + dtime
- if time > 1 then
- time = 0
- for _, player in pairs(minetest.get_connected_players()) do
- local name = player:get_player_name()
- local hp_change = lottpotion.players[name].hp or 0
- if hp_change ~= 0 then
- local hp = player:get_hp()
- hp = hp + hp_change
- hp = math.min(20, hp)
- hp = math.max(0, hp)
- player:set_hp(hp)
- end
- local br_change = lottpotion.players[name].air or 0
- if br_change ~= 0 then
- local br = player:get_breath()
- br = br + br_change
- br = math.min(20, br)
- br = math.max(0, br)
- player:set_breath(br)
- end
- if lottpotion.players[name].alive ~= 1 then
- lottpotion.players[name].alive = 1
- end
- end
- end
- end)
- minetest.register_on_dieplayer(function(player)
- local name = player:get_player_name()
- lottpotion.players[name] = {
- speed = 1,
- jump = 1,
- gravity = 1,
- air = 0,
- hp = 0,
- alive = 0,
- }
- lottpotion.refresh(name)
- if lottpotion.deaths[name] == nil then
- lottpotion.deaths[name] = 1
- end
- lottpotion.deaths[name] = lottpotion.deaths[name] + 1
- end)
- lottpotion.register_potion("athelasbrew", "Athelas Brew", "lottpotion:athelasbrew", 100, {
- effect = "fixhp",
- types = {
- {
- type = 1,
- hp = 1,
- time = 20,
- set = {},
- effects = {
- },
- },
- {
- type = 2,
- hp = 2,
- time = 50,
- set = {},
- effects = {
- },
- },
- {
- type = 3,
- hp = 4,
- time = 100,
- set = {},
- effects = {
- },
- },
- }
- })
- lottpotion.register_potion("limpe", "Limpe", "lottpotion:limpe", 240, {
- effect = "air",
- types = {
- {
- type = 1,
- br = 2,
- hp = 10,
- time = 60,
- set = {},
- effects = {
- },
- },
- {
- type = 2,
- br = 5,
- time = 120,
- set = {},
- effects = {
- },
- },
- {
- type = 3,
- br = 10,
- time = 240,
- set = {},
- effects = {
- },
- },
- }
- })
- lottpotion.register_potion("miruvor", "Miruvor", "lottpotion:miruvor", 240, {
- effect = "phys_override",
- types = {
- {
- type = 1,
- set = {},
- time = 60,
- effects = {
- jump = 0.3,
- },
- },
- {
- type = 2,
- set = {},
- time = 120,
- effects = {
- jump = 0.6,
- },
- },
- {
- type = 3,
- set = {},
- time = 240,
- effects = {
- jump = 1.0,
- },
- },
- }
- })
- lottpotion.register_potion("spiderpoison", "Spider Poison", "lottpotion:spiderpoison", 20, {
- effect = "phys_override",
- types = {
- {
- type = 1,
- set = {},
- effects = {
- speed = -0.2,
- jump = -0.2,
- },
- },
- {
- type = 2,
- set = {},
- effects = {
- speed = -0.5,
- jump = -0.5,
- },
- },
- {
- type = 3,
- set = {},
- effects = {
- speed = -1,
- jump = -1,
- },
- },
- }
- })
- lottpotion.register_potion("orcdraught", "Orc Draught", "lottpotion:orcdraught", 100, {
- effect = "fixhp",
- types = {
- {
- type = 1,
- hp = -1,
- time = 20,
- set = {},
- effects = {
- },
- },
- {
- type = 2,
- hp = -1,
- time = 50,
- set = {},
- effects = {
- },
- },
- {
- type = 3,
- hp = -1,
- time = 100,
- set = {},
- effects = {
- },
- },
- }
- })
- lottpotion.register_potion("entdraught", "Ent Draught", "lottpotion:entdraught", 240, {
- effect = "phys_override",
- types = {
- {
- type = 1,
- set = {},
- effects = {
- speed = 1,
- jump = -0.2,
- },
- },
- {
- type = 2,
- set = {},
- effects = {
- speed = 2,
- jump = -0.5,
- },
- },
- {
- type = 3,
- set = {},
- effects = {
- speed = 3,
- jump = -1,
- },
- },
- }
- })
- minetest.register_on_joinplayer(function(player)
- lottpotion.players[player:get_player_name()] = {
- speed = 1,
- jump = 1,
- gravity = 1,
- air = 0,
- hp = 0,
- alive = 1,
- }
- end)
- minetest.register_on_leaveplayer(function(player)
- lottpotion.players[player:get_player_name()] = nil
- lottpotion.deaths[player:get_player_name()] = nil
- end)
- minetest.register_chatcommand("effect", {
- params = "none",
- description = "get effect info",
- func = function(name, param)
- minetest.chat_send_player(name, "effects:")
- local lottpotion_e = lottpotion.players[name]
- if lottpotion_e~=nil then
- for potion_name, val in pairs(lottpotion_e) do
- if potion_name ~= "alive" then
- minetest.chat_send_player(name, potion_name .. "=" .. val)
- end
- end
- end
- end,
- })
- minetest.register_craftitem( "lottpotion:wine", {
- description = "Wine",
- inventory_image = "lottpotion_wine.png",
- wield_image = "lottpotion_wine.png",
- on_use = minetest.item_eat(6),
- })
- minetest.register_craftitem( "lottpotion:beer", {
- description = "Beer",
- inventory_image = "lottpotion_beer.png",
- wield_image = "lottpotion_beer.png",
- on_use = minetest.item_eat(6),
- })
- minetest.register_craftitem( "lottpotion:ale", {
- description = "Ale",
- inventory_image = "lottpotion_ale.png",
- wield_image = "lottpotion_ale.png",
- on_use = minetest.item_eat(5),
- })
- minetest.register_craftitem( "lottpotion:mead", {
- description = "Mead",
- inventory_image = "lottpotion_mead.png",
- wield_image = "lottpotion_mead.png",
- on_use = minetest.item_eat(5),
- })
- minetest.register_craftitem( "lottpotion:cider", {
- description = "Cider",
- inventory_image = "lottpotion_cider.png",
- wield_image = "lottpotion_cider.png",
- on_use = minetest.item_eat(4),
- })
- function lottpotion.can_dig(pos, player)
- local meta = minetest.get_meta(pos)
- local inv = meta:get_inventory()
- if not inv:is_empty("src") or not inv:is_empty("dst") or not inv:is_empty("fuel") or
- not inv:is_empty("upgrade1") or not inv:is_empty("upgrade2") then
- minetest.chat_send_player(player:get_player_name(),
- "Brewer cannot be removed because it is not empty")
- return false
- else
- return true
- end
- end
- function lottpotion.swap_node(pos, name)
- local node = minetest.get_node(pos)
- if node.name ~= name then
- node.name = name
- minetest.swap_node(pos, node)
- end
- return node.name
- end
- dofile(minetest.get_modpath("lottpotion").."/potionbrewing.lua")
- dofile(minetest.get_modpath("lottpotion").."/brewing.lua")
|