Revamp potion effects
This commit is contained in:
parent
19d492ba3c
commit
52eea966d9
@ -18,6 +18,12 @@ Game Changes:
|
||||
- Added guns
|
||||
- Added Electrified Mithril
|
||||
- Improved Windballs
|
||||
- Added Sea Master potion effect
|
||||
- Added silver color
|
||||
|
||||
Code Changes:
|
||||
|
||||
- Revamped status effect system
|
||||
|
||||
Bugfixes:
|
||||
|
||||
|
@ -70,6 +70,7 @@ PyuTest.COLORS = {
|
||||
peach = { "Peach", "#FFE5B4"},
|
||||
bloodred = { "Blood Red", "#660000"},
|
||||
grey = { "Grey", "#606060" },
|
||||
silver = { "Silver", "#C0C0C0" },
|
||||
}
|
||||
|
||||
PyuTest.WORLD_GRAVITY = core.settings:get("movement_gravity")
|
||||
|
@ -4,27 +4,28 @@ local class = {
|
||||
}
|
||||
|
||||
function class:on_step(dtime, moveresult)
|
||||
local slowdown_speed = self._slowdown_speed or 0.98
|
||||
local slowdown = self._slowdown
|
||||
local godown = self._godown
|
||||
local slow_down_speed = self._slow_down_speed or 0.98
|
||||
|
||||
if slowdown == nil then
|
||||
slowdown = true
|
||||
local slow_down = self._slow_down
|
||||
local go_down = self._go_down
|
||||
|
||||
if slow_down == nil then
|
||||
slow_down = false
|
||||
end
|
||||
|
||||
if godown == nil then
|
||||
godown = false
|
||||
if go_down == nil then
|
||||
go_down = true
|
||||
end
|
||||
|
||||
if slowdown then
|
||||
if slow_down and not go_down then
|
||||
local vel = self.object:get_velocity()
|
||||
vel = vector.multiply(vel, slowdown_speed)
|
||||
vel = vector.multiply(vel, slow_down_speed)
|
||||
self.object:set_velocity(vel)
|
||||
end
|
||||
|
||||
if godown and not slowdown then
|
||||
if go_down and not slow_down then
|
||||
local vel = self.object:get_velocity()
|
||||
vel.y = vel.y - (5 * dtime)
|
||||
vel.y = vel.y - (15 * dtime)
|
||||
self.object:set_velocity(vel)
|
||||
end
|
||||
|
||||
|
@ -10,7 +10,7 @@ PyuTest.make_projectile("pyutest_projectiles:fireball", {
|
||||
"pyutest-fireball.png",
|
||||
}
|
||||
}, {
|
||||
_slowdown = false
|
||||
_go_down = false
|
||||
}, {
|
||||
on_hit_node = function (self, pos, node)
|
||||
PyuTest.create_explosion(pos, 3, false, 12)
|
||||
@ -28,7 +28,6 @@ PyuTest.make_projectile("pyutest_projectiles:arrow", {
|
||||
"pyutest-arrow.png",
|
||||
}
|
||||
}, {
|
||||
_slowdown = false
|
||||
}, {
|
||||
on_hit_node = function (self, pos, node)
|
||||
end,
|
||||
|
@ -24,7 +24,6 @@ PyuTest.make_projectile("pyutest_projectiles:snowball", {
|
||||
"pyutest-snowball.png",
|
||||
}
|
||||
}, {
|
||||
_slowdown = false,
|
||||
}, {
|
||||
on_hit_node = function (self, pos, node)
|
||||
do_particles(pos + vector.new(0, 1, 0))
|
||||
|
@ -33,8 +33,6 @@ PyuTest.make_gun = function(name, desc, texture, cooldown, damage, extra)
|
||||
"pyutest-bullet.png",
|
||||
}
|
||||
}, {
|
||||
_slowdown = false,
|
||||
_godown = true,
|
||||
}, {
|
||||
on_hit_node = function(self, pos, node) end,
|
||||
on_hit_object = function(self, object)
|
||||
|
@ -2,7 +2,6 @@ PyuTest.make_wand = function (id, desc, texture, mana, properties, fns)
|
||||
local e_id = id .. "_projectile"
|
||||
|
||||
PyuTest.make_projectile(e_id, properties, {
|
||||
_slowdown = false
|
||||
}, {
|
||||
on_hit_node = fns.on_hit_node,
|
||||
on_hit_object = fns.on_hit_object
|
||||
|
@ -75,7 +75,6 @@ PyuTest.make_potion = function (name, desc, options)
|
||||
visual = "sprite",
|
||||
textures = {texture},
|
||||
}, {
|
||||
_slowdown = false,
|
||||
}, {
|
||||
on_hit_node = function (self, pos, node)
|
||||
splash(pos + vector.new(0, 1, 0))
|
||||
|
@ -1,8 +1,10 @@
|
||||
PyuTest.POTION_LENGTH = 90
|
||||
|
||||
PyuTest.make_potion("pyutest_potions:speed", "Speed Potion", {
|
||||
color = PyuTest.COLORS.turquoise[2],
|
||||
color = PyuTest.COLORS.teal[2],
|
||||
effect = "speed",
|
||||
multiplier = 2.5,
|
||||
length = 60,
|
||||
length = PyuTest.POTION_LENGTH,
|
||||
craft = "pyutest_tools:sugar"
|
||||
})
|
||||
|
||||
@ -10,26 +12,34 @@ PyuTest.make_potion("pyutest_potions:slowness", "Slowness Potion", {
|
||||
color = PyuTest.COLORS.grey[2],
|
||||
effect = "speed",
|
||||
multiplier = 0.45,
|
||||
length = 60,
|
||||
length = PyuTest.POTION_LENGTH,
|
||||
craft = "pyutest_tools:ash"
|
||||
})
|
||||
|
||||
PyuTest.make_potion("pyutest_potions:jump_boost", "Jump Boost Potion", {
|
||||
color = PyuTest.COLORS.pink[2],
|
||||
PyuTest.make_potion("pyutest_potions:jump_boost", "Leaping Potion", {
|
||||
color = PyuTest.COLORS.khaki[2],
|
||||
effect = "jump_boost",
|
||||
multiplier = 2.5,
|
||||
length = 60,
|
||||
length = PyuTest.POTION_LENGTH,
|
||||
craft = "pyutest_tools:paper"
|
||||
})
|
||||
|
||||
PyuTest.make_potion("pyutest_potions:low_gravity", "Low Gravity Potion", {
|
||||
color = PyuTest.COLORS.chartreuse[2],
|
||||
effect = "low_gravity",
|
||||
color = PyuTest.COLORS.silver[2],
|
||||
effect = "gravity",
|
||||
multiplier = 0.25,
|
||||
length = 30,
|
||||
length = PyuTest.POTION_LENGTH,
|
||||
craft = "pyutest_magic:windball"
|
||||
})
|
||||
|
||||
PyuTest.make_potion("pyutest_potions:sea_master", "Sea Master Potion", {
|
||||
color = PyuTest.COLORS.indigo[2],
|
||||
effect = "sea_master",
|
||||
multiplier = 0.25,
|
||||
length = PyuTest.POTION_LENGTH,
|
||||
craft = "pyutest_buckets:water_bucket"
|
||||
})
|
||||
|
||||
PyuTest.make_potion("pyutest_potions:instant_damage", "Instant Damage Potion", {
|
||||
color = PyuTest.COLORS.bloodred[2],
|
||||
action = function (itemstack, user, pointed_thing)
|
||||
|
63
mods/PLAYER/pyutest_effects/api.lua
Normal file
63
mods/PLAYER/pyutest_effects/api.lua
Normal file
@ -0,0 +1,63 @@
|
||||
local effects = {}
|
||||
|
||||
PyuTest.STATUS_EFFECTS = {}
|
||||
|
||||
PyuTest.register_status_effect = function(id, func, oih)
|
||||
PyuTest.STATUS_EFFECTS[id] = func or function(ObjectRef)end
|
||||
end
|
||||
|
||||
PyuTest.status_effect_add = function(player, name, multiplier, length)
|
||||
effects[player][name] = multiplier
|
||||
|
||||
if length ~= nil then
|
||||
core.after(length, function()
|
||||
PyuTest.status_effect_remove(player, name)
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
PyuTest.status_effect_remove = function(player, name)
|
||||
effects[player][name] = false
|
||||
end
|
||||
|
||||
PyuTest.status_effect_get = function(player, name)
|
||||
if effects[player][name] ~= false and effects[player][name] ~= nil then
|
||||
return effects[player][name]
|
||||
end
|
||||
return 1
|
||||
end
|
||||
|
||||
PyuTest.status_effect_has = function(player, name)
|
||||
return effects[player][name] ~= false
|
||||
end
|
||||
|
||||
core.register_on_joinplayer(function (player)
|
||||
local name = player:get_player_name()
|
||||
if effects[name] == nil then
|
||||
effects[name] = {}
|
||||
end
|
||||
|
||||
for _, v in pairs(PyuTest.STATUS_EFFECTS) do
|
||||
if effects[name][v] == nil then
|
||||
effects[name][v] = false
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
core.register_on_respawnplayer(function (player)
|
||||
local name = player:get_player_name()
|
||||
|
||||
for k, _ in pairs(PyuTest.STATUS_EFFECTS) do
|
||||
effects[name][k] = false
|
||||
end
|
||||
end)
|
||||
|
||||
core.register_globalstep(function ()
|
||||
for _, v in pairs(core.get_connected_players()) do
|
||||
local name = v:get_player_name()
|
||||
|
||||
for k, f in pairs(PyuTest.STATUS_EFFECTS) do
|
||||
f(v, name)
|
||||
end
|
||||
end
|
||||
end)
|
35
mods/PLAYER/pyutest_effects/command.lua
Normal file
35
mods/PLAYER/pyutest_effects/command.lua
Normal file
@ -0,0 +1,35 @@
|
||||
core.register_chatcommand("effect", {
|
||||
params = "add|remove <player> <effect> <time> <multiplier>",
|
||||
description = "Add or Remove <effect> from <player>",
|
||||
privs = {give = 1},
|
||||
func = function (name, param)
|
||||
local split = param:split(" ")
|
||||
|
||||
if #split < 3 then
|
||||
return false, "Invalid syntax: " .. param
|
||||
end
|
||||
|
||||
local option = split[1]
|
||||
local targets = PyuTest.chatcommand_entity_selector(name, split[2])
|
||||
local effect = split[3]
|
||||
|
||||
for _, v in pairs(targets) do
|
||||
if not core.get_player_by_name(v) then
|
||||
core.chat_send_player(name, "Invalid player: " .. v)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
if option == "add" and #split == 5 then
|
||||
local time = tonumber(split[4])
|
||||
local multiplier = tonumber(split[5]) or 2
|
||||
for _, v in pairs(targets) do
|
||||
PyuTest.status_effect_add(v, effect, multiplier, time)
|
||||
end
|
||||
elseif option == "remove" and #split == 3 then
|
||||
for _, v in pairs(targets) do
|
||||
PyuTest.status_effect_remove(v, effect)
|
||||
end
|
||||
end
|
||||
end
|
||||
})
|
49
mods/PLAYER/pyutest_effects/effects.lua
Normal file
49
mods/PLAYER/pyutest_effects/effects.lua
Normal file
@ -0,0 +1,49 @@
|
||||
PyuTest.register_status_effect("speed", function(object, name)
|
||||
local speed_multiplier = PyuTest.status_effect_get(name, "speed")
|
||||
local sprint_addition = 0.35
|
||||
|
||||
if object:get_player_control().aux1 and PyuTest.hunger_get(name) > 6 then
|
||||
speed_multiplier = speed_multiplier + sprint_addition
|
||||
PyuTest.hunger_multiplier(name, 4)
|
||||
else
|
||||
PyuTest.hunger_multiplier(name, 1)
|
||||
end
|
||||
local fovm = (1 + (speed_multiplier) * sprint_addition)
|
||||
|
||||
object:set_physics_override({
|
||||
speed = speed_multiplier,
|
||||
})
|
||||
|
||||
object:set_fov(fovm, true, 0.15)
|
||||
end)
|
||||
|
||||
PyuTest.register_status_effect("jump_boost", function(object, name)
|
||||
local jump_boost = PyuTest.status_effect_get(name, "jump_boost")
|
||||
|
||||
object:set_physics_override({
|
||||
jump = jump_boost
|
||||
})
|
||||
end)
|
||||
|
||||
PyuTest.register_status_effect("gravity", function(object, name)
|
||||
local gravity = PyuTest.status_effect_get(name, "gravity")
|
||||
|
||||
object:set_physics_override({
|
||||
gravity = gravity
|
||||
})
|
||||
end)
|
||||
|
||||
PyuTest.register_status_effect("sea_master", function(object, name)
|
||||
local sea_master = PyuTest.status_effect_has(name, "sea_master")
|
||||
local liquid_fluidity = (sea_master and math.huge or 1)
|
||||
local liquid_sink = (sea_master and 0 or 1)
|
||||
|
||||
if sea_master then
|
||||
object:set_breath(object:get_properties().breath_max)
|
||||
end
|
||||
|
||||
object:set_physics_override({
|
||||
liquid_fluidity = liquid_fluidity,
|
||||
liquid_sink = liquid_sink,
|
||||
})
|
||||
end)
|
@ -1,116 +1,5 @@
|
||||
local storage = core.get_mod_storage()
|
||||
local effects = {}
|
||||
local modpath = core.get_modpath(core.get_current_modname())
|
||||
|
||||
PyuTest.STATUS_EFFECTS = {
|
||||
"speed",
|
||||
"jump_boost",
|
||||
"low_gravity"
|
||||
}
|
||||
|
||||
PyuTest.status_effect_add = function(player, name, multiplier, length)
|
||||
effects[player][name] = multiplier
|
||||
|
||||
if length ~= nil then
|
||||
core.after(length, function()
|
||||
PyuTest.status_effect_remove(player, name)
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
PyuTest.status_effect_remove = function (player, name)
|
||||
effects[player][name] = false
|
||||
end
|
||||
|
||||
PyuTest.status_effect_get = function (player, name)
|
||||
if effects[player][name] ~= false then
|
||||
return effects[player][name]
|
||||
end
|
||||
return 1
|
||||
end
|
||||
|
||||
core.register_on_joinplayer(function (player)
|
||||
local name = player:get_player_name()
|
||||
if effects[name] == nil then
|
||||
effects[name] = {}
|
||||
end
|
||||
|
||||
for _, v in pairs(PyuTest.STATUS_EFFECTS) do
|
||||
if effects[name][v] == nil then
|
||||
effects[name][v] = false
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
core.register_on_respawnplayer(function (player)
|
||||
local name = player:get_player_name()
|
||||
|
||||
for _, v in pairs(PyuTest.STATUS_EFFECTS) do
|
||||
effects[name][v] = false
|
||||
end
|
||||
end)
|
||||
|
||||
core.register_globalstep(function ()
|
||||
for _, v in pairs(core.get_connected_players()) do
|
||||
local name = v:get_player_name()
|
||||
|
||||
-- speed calculation
|
||||
local speed_multiplier = 1 * PyuTest.status_effect_get(name, "speed")
|
||||
local sprint_addition = 0.35
|
||||
|
||||
if v:get_player_control().aux1 and PyuTest.hunger_get(name) > 6 then
|
||||
speed_multiplier = speed_multiplier + sprint_addition
|
||||
PyuTest.hunger_multiplier(name, 4)
|
||||
else
|
||||
PyuTest.hunger_multiplier(name, 1)
|
||||
end
|
||||
-- end speed calculation
|
||||
|
||||
local jump_boost = 1 * PyuTest.status_effect_get(name, "jump_boost")
|
||||
local gravity = 1 * PyuTest.status_effect_get(name, "low_gravity")
|
||||
|
||||
v:set_physics_override({
|
||||
speed = 1 * speed_multiplier,
|
||||
jump = 1 * jump_boost,
|
||||
gravity = 1 * gravity
|
||||
})
|
||||
|
||||
local fovm = (1 + (speed_multiplier) * sprint_addition)
|
||||
v:set_fov(fovm, true, 0.15)
|
||||
end
|
||||
end)
|
||||
|
||||
core.register_chatcommand("effect", {
|
||||
params = "add|remove <player> <effect> <time> <multiplier>",
|
||||
description = "Add or Remove <effect> from <player>",
|
||||
privs = {give = 1},
|
||||
func = function (name, param)
|
||||
local split = param:split(" ")
|
||||
|
||||
if #split < 3 then
|
||||
return false, "Invalid syntax: " .. param
|
||||
end
|
||||
|
||||
local option = split[1]
|
||||
local targets = PyuTest.chatcommand_entity_selector(name, split[2])
|
||||
local effect = split[3]
|
||||
|
||||
for _, v in pairs(targets) do
|
||||
if not core.get_player_by_name(v) then
|
||||
core.chat_send_player(name, "Invalid player: " .. v)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
if option == "add" and #split == 5 then
|
||||
local time = tonumber(split[4])
|
||||
local multiplier = tonumber(split[5])
|
||||
for _, v in pairs(targets) do
|
||||
PyuTest.status_effect_add(v, effect, multiplier, time)
|
||||
end
|
||||
elseif option == "remove" and #split == 3 then
|
||||
for _, v in pairs(targets) do
|
||||
PyuTest.status_effect_remove(v, effect)
|
||||
end
|
||||
end
|
||||
end
|
||||
})
|
||||
dofile(modpath .. "/api.lua")
|
||||
dofile(modpath .. "/effects.lua")
|
||||
dofile(modpath .. "/command.lua")
|
||||
|
Loading…
x
Reference in New Issue
Block a user