From 01179777a214f9a9e2924a776f1214eef8184627 Mon Sep 17 00:00:00 2001 From: Long Date: Tue, 27 Mar 2018 00:43:24 -0400 Subject: [PATCH] fix reset --- pokeboot/lib/pokeboot/battle.ex | 17 ++++++++++------- .../pokeboot_web/channels/battles_channel.ex | 1 + 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/pokeboot/lib/pokeboot/battle.ex b/pokeboot/lib/pokeboot/battle.ex index 0f53727..fcd7831 100644 --- a/pokeboot/lib/pokeboot/battle.ex +++ b/pokeboot/lib/pokeboot/battle.ex @@ -31,12 +31,7 @@ defmodule Pokeboot.Battle do starter = payload["starter"] if trainer == battle.trainer1.name || trainer == battle.trainer2.name do - if battle.gameOver do - new() - |> loadTrainer(payload) - else - battle - end + battle else case battle do %{trainer1: %Trainer{name: ""}} -> @@ -231,7 +226,15 @@ defmodule Pokeboot.Battle do battle |> Map.put(:gameOver, true) else - battle + battle + end + end + + def isBattleOver(battle) do + if battle.gameOver == true do + new() + else + battle end end diff --git a/pokeboot/lib/pokeboot_web/channels/battles_channel.ex b/pokeboot/lib/pokeboot_web/channels/battles_channel.ex index 36863e8..fa8e377 100644 --- a/pokeboot/lib/pokeboot_web/channels/battles_channel.ex +++ b/pokeboot/lib/pokeboot_web/channels/battles_channel.ex @@ -6,6 +6,7 @@ defmodule PokebootWeb.BattlesChannel do def join("battles:" <> name, payload, socket) do if authorized?(payload) do battle = (BattleRooms.load(name) || Battle.new()) + |> Battle.isBattleOver() |> Battle.loadTrainer(payload) socket = socket