private async Task Process(BattleAdded bat) { var newBattle = new Battle(); newBattle.UpdateWith(bat.Header); ExistingBattles[newBattle.BattleID] = newBattle; //newBattle.Founder.IsInBattleRoom = true; BattleFound(this, newBattle); }
User UserGetter(string n) { User us; if (existingUsers.TryGetValue(n, out us)) { return(us); } else { return new User() { Name = n } }; } async Task Process(BattleAdded bat) { var newBattle = new Battle(); newBattle.UpdateWith(bat.Header, UserGetter); existingBattles[newBattle.BattleID] = newBattle; newBattle.Founder.IsInBattleRoom = true; BattleFound(this, new EventArgs <Battle>(newBattle)); } async Task Process(JoinedBattle bat) { User user; existingUsers.TryGetValue(bat.User, out user); Battle battle; ExistingBattles.TryGetValue(bat.BattleID, out battle); if (user != null && battle != null) { battle.Users[user.Name] = new UserBattleStatus(user.Name, user); user.IsInBattleRoom = true; BattleUserJoined(this, new BattleUserEventArgs(user.Name, bat.BattleID)); if (user.Name == UserName) { MyBattle = battle; if (battle.Founder.Name == UserName) { BattleOpened(this, new EventArgs <Battle>(battle)); } BattleJoined(this, new EventArgs <Battle>(MyBattle)); } } } async Task Process(LeftBattle left) { User user; Battle bat; existingUsers.TryGetValue(left.User, out user); existingBattles.TryGetValue(left.BattleID, out bat); if (bat != null && user != null) { user.IsInBattleRoom = false; UserBattleStatus removed; bat.Users.TryRemove(left.User, out removed); if (MyBattle != null && left.BattleID == MyBattleID) { if (UserName == left.User) { bat.Rectangles.Clear(); bat.Bots.Clear(); bat.ModOptions.Clear(); MyBattle = null; BattleClosed(this, new EventArgs <Battle>(bat)); } } BattleUserLeft(this, new BattleUserEventArgs(user.Name, left.BattleID)); } } async Task Process(BattleRemoved br) { Battle battle; if (!existingBattles.TryGetValue(br.BattleID, out battle)) { return; } foreach (var u in battle.Users.Keys) { User user; if (ExistingUsers.TryGetValue(u, out user)) { user.IsInBattleRoom = false; } } existingBattles.Remove(br.BattleID); if (battle == MyBattle) { BattleClosed(this, new EventArgs <Battle>(battle)); MyBattleRemoved(this, new EventArgs <Battle>(battle)); } BattleRemoved(this, new EventArgs <Battle>(battle)); } async Task Process(LoginResponse loginResponse) { if (loginResponse.ResultCode == LoginResponse.Code.Ok) { isLoggedIn = true; LoginAccepted(this, new TasEventArgs()); } else { isLoggedIn = false; LoginDenied(this, new EventArgs <LoginResponse>(loginResponse)); } } async Task Process(Ping ping) { lastPing = DateTime.UtcNow; } async Task Process(User userUpdate) { User user; User old = null; existingUsers.TryGetValue(userUpdate.Name, out user); if (user != null) { old = user.Clone(); user.UpdateWith(userUpdate); } else { user = userUpdate; } existingUsers[user.Name] = user; if (old == null) { UserAdded(this, new EventArgs <User>(user)); } if (old != null) { var bat = MyBattle; if (bat != null && bat.Founder.Name == user.Name) { if (user.IsInGame && !old.IsInGame) { MyBattleStarted(this, new EventArgs <Battle>(bat)); } if (!user.IsInGame && old.IsInGame) { MyBattleHostExited(this, new EventArgs <Battle>(bat)); } } } UserStatusChanged(this, new EventArgs <OldNewPair <User> >(new OldNewPair <User>(old, user))); } async Task Process(RegisterResponse registerResponse) { if (registerResponse.ResultCode == RegisterResponse.Code.Ok) { RegistrationAccepted(this, new TasEventArgs()); } else { RegistrationDenied(this, new EventArgs <RegisterResponse>(registerResponse)); } } async Task Process(Say say) { InvokeSaid(new TasSayEventArgs(say.Place, say.Target, say.User, say.Text, say.IsEmote)); if (say.Ring) { Rang(this, new EventArgs <Say>(say)); } }