if you're not shooting, you're not part of any games, also if afk

This commit is contained in:
whosit 2024-11-26 21:53:21 +03:00
parent ae9e626b0b
commit 02583495f1
3 changed files with 26 additions and 19 deletions

View File

@ -220,33 +220,39 @@ function snowgame.register_hit(shooter_name, target_name)
local s_game = games_by_player[shooter_name]
local t_game = games_by_player[target_name]
if s_game and t_game and (s_game ~= t_game) then
-- if both player but different games, merge
s_game:merge(t_game)
end
local game = s_game or t_game
if not game then
-- none are playing, make a new one
game = Game()
end
if not s_game then
-- add shooter to current
game:add_player(shooter_name)
game:register_shot(shooter_name)
-- somehow landed a hit before being in a game
-- probably because left and rejoined?
s_game = Game()
s_game:add_player(shooter_name)
s_game:register_shot(shooter_name) -- if was in the game, then shot was registered in on_use
end
if not t_game then
-- add target to current (if played diff game, was merged)
game:add_player(target_name)
if afk_api.is_afk(target_name, yl_snowball.AFK_TIME) then
-- don't count hits on afk people
return
end
game:register_hit(shooter_name, target_name)
if s_game and t_game then
if (s_game ~= t_game) then
-- if both playing, but different games, then merge
s_game:merge(t_game)
end
-- either same game, or was merged into one
s_game:register_hit(shooter_name, target_name)
end
end
function snowgame.register_shot(shooter_name)
local s_game = games_by_player[shooter_name]
if s_game then
s_game:register_shot(shooter_name)
if not s_game then
-- started shooting first time, started a game
s_game = Game()
s_game:add_player(shooter_name)
end
s_game:register_shot(shooter_name)
end

View File

@ -13,6 +13,7 @@ yl_snowball.COOLDOWN = 0.4 -- TODO make configurable
yl_snowball.SNOWBALL_SPEED = 17 -- 17 was good
yl_snowball.SNOWBALL_GRAVITY = -8 -- -8 was good
yl_snowball.AFK_TIME = 3*60
local player_last_throw_time = {}

View File

@ -2,4 +2,4 @@ description = Adds throwable snowballs and a snowball minigame
author = whosit
title = yl_snowball
name = yl_snowball
depends = ballistics, futil, y_bows
depends = ballistics, futil, y_bows, afk_api