Skip to content

Commit

Permalink
fix(fun): add offline flag
Browse files Browse the repository at this point in the history
  • Loading branch information
CyanSalt committed Mar 18, 2022
1 parent f3615f8 commit f0d3944
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions addons/fun/src/renderer/FunPane.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const generateID = commas.helperRenderer.createIDGenerator()
interface Player {
id: number,
offline: boolean,
color: string,
speed: number,
base: number,
Expand Down Expand Up @@ -43,6 +44,7 @@ function initializePlayers() {
for (let index = 0; index < colors.length; index++) {
players[index] = {
id: generateID(),
offline: false,
color: colors[index],
speed: 1,
base: 1,
Expand Down Expand Up @@ -127,6 +129,7 @@ async function attack(player: Player) {
const target = sample(targets)!
target.color = player.color
await nextFrame()
if (player.offline) return
player.army -= 1
if (player.army) {
attack(player)
Expand All @@ -151,6 +154,7 @@ function isAlive(player: Player) {
async function handleDial(player: Player, result: DialItem | undefined) {
await sleep(500)
if (player.offline) return
if (!isAlive(player)) return
if (!result) {
player.mainPosition = Math.random()
Expand Down Expand Up @@ -184,6 +188,9 @@ async function handleDial(player: Player, result: DialItem | undefined) {
}
async function refresh() {
players.forEach(player => {
player.offline = true
})
initializePlayers()
initializeTerritory()
await nextTick()
Expand Down

0 comments on commit f0d3944

Please sign in to comment.