You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
2.1 KiB

function applyAffect(name,affectid)
minetest.log("action","Applying affect "..affectid.." on "..name)
whoison.updateStats(name)
local player = minetest.get_player_by_name(name)
local oStage = affects._affectedPlayers[name][affectid].stage
-- see if they need advanced into the next stage
if ( affects._affectedPlayers[name][affectid].nextStage < whoison.getTimeOnline(name) ) then
local nextStageNum = affects._affectedPlayers[name][affectid].stage + 1
affects._affectedPlayers[name][affectid].stage = nextStageNum
affects._affectedPlayers[name][affectid].ran = false
minetest.log("action","Advancing "..affectid.." to the next stage for "..name)
if ( #affects._affects[affectid].stages < nextStageNum ) then
minetest.log("action","Affect "..affectid.." has worn off of "..name)
affects.removeAffect(name,affectid)
return
end
affects._affectedPlayers[name][affectid].nextStage = (whoison.getTimeOnline(name) + affects._affects[affectid].stages[nextStageNum].time)
end
local iStage = affects._affectedPlayers[name][affectid].stage
local stage = affects._affects[affectid].stages[iStage]
local oPhysics = stage.physics
if ( oPhysics ~= nil ) then
player:set_physics_override(oPhysics)
end
if ( stage.damage ~= nil ) then
if ( randomChance(stage.damage.chance) ) then
player:set_hp( player:get_hp() - stage.damage.amount )
end
end
if ( stage.emote ~= nil ) then
if ( randomChance(stage.emote.chance) ) then
minetest.chat_send_all(name.." "..stage.emote.action)
end
end
if ( stage.place ~= nil ) then
if ( randomChance(stage.place.chance) ) then
minetest.place_node(player:getpos(),{name=stage.place.node, param1=0, param2=0})
end
end
if ( stage.custom ~= nil ) then
if ( stage.custom.runonce == true and affects._affectedPlayers[name][affectid].ran == true ) then
return
end
if ( randomChance(stage.custom.chance) ) then
affects._affectedPlayers[name][affectid].ran = true
stage.custom.func(name,player,affectid)
end
end
end
function randomChance (percent)
math.randomseed( os.time() )
return percent >= math.random(1, 100)
end