diff --git a/src/app/entity/Auth.ts b/src/app/entity/Auth.ts index 7623978..968e3e3 100644 --- a/src/app/entity/Auth.ts +++ b/src/app/entity/Auth.ts @@ -20,7 +20,7 @@ export interface LoginTokenViewModel { avatarImage: string; role: Role; cellGroup: PastoralDomain; - signalRSessionId; + signalRConnectionId; sessionTabId: string; } diff --git a/src/app/games/games.model.ts b/src/app/games/games.model.ts index 48d618f..943a478 100644 --- a/src/app/games/games.model.ts +++ b/src/app/games/games.model.ts @@ -5,6 +5,7 @@ export interface IGamePlayer { isPlayer: boolean; signalRClientId: string; tabId: string; + isDisconnected: boolean; } export class GamePlayer implements IGamePlayer { @@ -14,4 +15,5 @@ export class GamePlayer implements IGamePlayer { isPlayer: boolean; signalRClientId: string; tabId: string; + isDisconnected: boolean; } \ No newline at end of file diff --git a/src/app/games/massive-darkness2/MD2Base.ts b/src/app/games/massive-darkness2/MD2Base.ts index b80c3cf..4a3ea8a 100644 --- a/src/app/games/massive-darkness2/MD2Base.ts +++ b/src/app/games/massive-darkness2/MD2Base.ts @@ -8,6 +8,7 @@ import { StateService } from "../../services/state.service"; import { ADIcon, MessageBoxConfig } from "../../ui/alert-dlg/alert-dlg.model"; import { MD2HeroInfo, MD2Icon, MobInfo, RoundPhase } from "./massive-darkness2.model"; import { LoginUserService } from "../../services/login-user.service"; +import { GamePlayer } from "../games.model"; @Injectable() export abstract class MD2Base { @@ -59,14 +60,14 @@ export abstract class MD2Base { } imgUrl(imgPath: string) { - return this.md2Service.stateService.imgUrl(imgPath); + return this.md2Service.imgUrl(imgPath); } fileList(folderPath: string) { return this.md2Service.fileList(folderPath); } iconHtml(icon: MD2Icon, cssClass = '') { - return this.md2Service.stateService.iconHtml(icon, cssClass); + return this.md2Service.iconHtml(icon, cssClass); } imgHtml(imgFile: string, cssClass = '') { @@ -82,12 +83,17 @@ export abstract class MD2Base { } abstract refreshUI(); handleSignalRCallback(message: SignalRMessage): void { - // if (message.from.isGroup) { - // if (!this.isHeroDashboard) return; - // } else { - // if (this.isHeroDashboard && this.md2Service.playerHero.playerInfo.signalRClientId == message.from.sessionId) return; - // } + if (message.from) { + if (message.from.isGroup) { + if (!this.isHeroDashboard) return; + } else { + if (this.isHeroDashboard && this.md2Service.playerHero?.playerInfo?.signalRClientId == message.from.connectionId) return; + } + } + if (!this.isHeroDashboard) { + + } switch (message.actionType) { case 'hero': let heroInfo = new MD2HeroInfo(JSON.parse(message.parameters['hero'])); @@ -101,7 +107,7 @@ export abstract class MD2Base { break; case 'updateMyHero': if (this.isHeroDashboard) { - this.md2Service.stateService.playerHero = heroInfo; + this.md2Service.playerHero = heroInfo; } break; @@ -113,24 +119,42 @@ export abstract class MD2Base { case 'heroes': switch (message.actionName) { case 'updateAll': - let allHeroes = (JSON.parse(message.parameters['heros']) as MD2HeroInfo[]).map(h => new MD2HeroInfo(h)); - //Remove heroes that are not in the list - this.md2Service.info.heros = this.md2Service.heros.filter(h => !allHeroes.some(h2 => h2.playerInfo.tabId == h.playerInfo.tabId)); - allHeroes.forEach(heroInfo => { - this.updateHeroInfo(heroInfo); - }); + if (this.isHeroDashboard) { + let allHeroes = (JSON.parse(message.parameters['heros']) as MD2HeroInfo[]).map(h => new MD2HeroInfo(h)); + //Remove heroes that are not in the list + this.md2Service.info.heros = this.md2Service.heros.filter(h => allHeroes.some(h2 => h2.playerInfo.tabId == h.playerInfo.tabId)); + allHeroes.forEach(heroInfo => { + this.updateHeroInfo(heroInfo); + }); + this.detectChanges(); + } + break; } break; case 'GameRoom': switch (message.actionName) { case 'Leaving': - this.md2Service.heros.splice(this.md2Service.heros.findIndex(h => h.playerInfo.tabId == message.from.sessionId)); + let leavingPlayerInfo = message.value as GamePlayer; + let leavingHero = this.md2Service.heros.find(h => h.playerInfo.tabId == leavingPlayerInfo.tabId); + if (leavingHero) { + leavingHero.playerInfo.isDisconnected = true; + } + //var disconnectHero = this.md2Service.heros.splice(this.md2Service.heros.findIndex(h => h.playerInfo.signalRClientId == leavingPlayerInfo.signalRClientId)); + //this.md2Service.info.disconnectedHeroes.push(...disconnectHero); this.detectChanges(); break; case 'update': if (this.isHeroDashboard) { this.md2Service.info = new MD2GameInfo(JSON.parse(message.parameters['gameInfo']) as MD2GameInfo); + let playerHero = this.md2Service.heros.find(h => h.playerInfo.tabId == this.stateService.loginUserService.sessionTabId); + if (playerHero) { + + playerHero.playerInfo = this.md2Service.gameRoomService.currentPlayer(); + playerHero.playerInfo.isDisconnected = false; + this.md2Service.playerHero = playerHero; + this.md2Service.broadcastMyHeroInfo(); + } this.detectChanges(); } break; @@ -140,10 +164,17 @@ export abstract class MD2Base { this.detectChanges(); } break; + case 'getGameInfo': + + if (!this.isHeroDashboard) { + + this.md2Service.broadcastGameInfo(); + } + break; case 'sendJoinInfo': if (this.isHeroDashboard && this.md2Service.playerHero) { this.md2Service.playerHero.playerInfo.signalRClientId = message.parameters['signalrconnid']; - this.md2Service.broadcastService.broadcastMyHeroInfo(); + this.md2Service.broadcastMyHeroInfo(); } break; default: @@ -212,14 +243,15 @@ export abstract class MD2Base { } } updateHeroInfo(heroInfo: MD2HeroInfo) { - let exitingHero = this.md2Service.heros.find(h => h.playerInfo.signalRClientId == heroInfo.playerInfo.signalRClientId); + let exitingHero = this.md2Service.heros.find(h => h.playerInfo.tabId == heroInfo.playerInfo.tabId); if (exitingHero) { + //For boss fight, if the hero finished activating, activate the boss let activateBoss = exitingHero.uiActivating && !heroInfo.uiActivating; this.md2Service.heros[this.md2Service.heros.indexOf(exitingHero)] = heroInfo; //My hero update if (this.isHeroDashboard && this.md2Service.loginUserService.sessionTabId == heroInfo.playerInfo.tabId) { - this.md2Service.stateService.playerHero = heroInfo; + this.md2Service.playerHero = heroInfo; } if (!this.isHeroDashboard && this.md2Service.info.isBossFight && activateBoss) { this.md2Service.activateBoss(); @@ -276,14 +308,14 @@ export abstract class MD2ComponentBase { this.destroy$.complete(); } imgUrl(imgPath: string) { - return this.md2Service.stateService.imgUrl(imgPath); + return this.md2Service.imgUrl(imgPath); } fileList(folderPath: string) { return this.md2Service.fileList(folderPath); } iconHtml(icon: MD2Icon, cssClass = '') { - return this.md2Service.stateService.iconHtml(icon, cssClass); + return this.md2Service.iconHtml(icon, cssClass); } detectChanges() { if (!this.cdRef['destroyed']) { diff --git a/src/app/games/massive-darkness2/boss-fight/boss-fight.component.html b/src/app/games/massive-darkness2/boss-fight/boss-fight.component.html index 6a2b0a5..575aee3 100644 --- a/src/app/games/massive-darkness2/boss-fight/boss-fight.component.html +++ b/src/app/games/massive-darkness2/boss-fight/boss-fight.component.html @@ -11,7 +11,7 @@