fix/death-logic #28
@ -40,6 +40,7 @@ end
|
||||
function level:update(dt)
|
||||
utils.each(self.deadIds, function(id)
|
||||
self.characters[id] = nil
|
||||
self.turnOrder:remove(id)
|
||||
end)
|
||||
self.deadIds = {}
|
||||
|
||||
|
||||
@ -108,4 +108,19 @@ function turnOrder:add(id)
|
||||
self.actedQueue:insert(id) -- новые персонажи по умолчанию попадают в очередь следующего хода
|
||||
end
|
||||
|
||||
--- Удалить персонажа из очереди хода (например, при смерти)
|
||||
--- @param id Id
|
||||
function turnOrder:remove(id)
|
||||
if self.current == id then
|
||||
self.current = self.pendingQueue:pop()
|
||||
if not self.current then
|
||||
self:endRound()
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
self.actedQueue:remove(id)
|
||||
self.pendingQueue:remove(id)
|
||||
end
|
||||
|
||||
return { new = new }
|
||||
|
||||
@ -115,4 +115,29 @@ function PriorityQueue:copy()
|
||||
}, PriorityQueue)
|
||||
end
|
||||
|
||||
--- Удалить элемент из очереди.
|
||||
--- Осторожно: O(n), так как нужно найти индекс элемента.
|
||||
---@param x any
|
||||
function PriorityQueue:remove(x)
|
||||
local index = nil
|
||||
for i, v in ipairs(self.data) do
|
||||
if v == x then
|
||||
index = i
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if not index then return end
|
||||
|
||||
local n = #self.data
|
||||
if index == n then
|
||||
self.data[n] = nil
|
||||
else
|
||||
self.data[index] = self.data[n]
|
||||
self.data[n] = nil
|
||||
self:_sift_up(index)
|
||||
self:_sift_down(index)
|
||||
end
|
||||
end
|
||||
|
||||
return PriorityQueue
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user