affects/functions.lua

62 lines
2.1 KiB
Lua
Raw Normal View History

2014-01-18 10:14:04 -08:00
function applyAffect(name,affectid)
minetest.log("action","Applying affect "..affectid.." on "..name)
2014-01-31 11:32:19 -08:00
whoison.updateStats(name)
2014-01-18 10:14:04 -08:00
local player = minetest.get_player_by_name(name)
local oStage = affects._affectedPlayers[name][affectid].stage
-- see if they need advanced into the next stage
2014-01-31 11:32:19 -08:00
if ( affects._affectedPlayers[name][affectid].nextStage < whoison.getTimeOnline(name) ) then
local nextStageNum = affects._affectedPlayers[name][affectid].stage + 1
affects._affectedPlayers[name][affectid].stage = nextStageNum
2014-01-18 10:14:04 -08:00
affects._affectedPlayers[name][affectid].ran = false
2014-01-31 11:32:19 -08:00
minetest.log("action","Advancing "..affectid.." to the next stage for "..name)
if ( #affects._affects[affectid].stages < nextStageNum ) then
2014-01-18 10:14:04 -08:00
minetest.log("action","Affect "..affectid.." has worn off of "..name)
affects.removeAffect(name,affectid)
return
2014-01-31 11:32:19 -08:00
end
affects._affectedPlayers[name][affectid].nextStage = (whoison.getTimeOnline(name) + affects._affects[affectid].stages[nextStageNum].time)
2014-01-18 10:14:04 -08:00
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