diff --git a/msagent.js/src/agent.ts b/msagent.js/src/agent.ts index 635a81d..1b5d415 100644 --- a/msagent.js/src/agent.ts +++ b/msagent.js/src/agent.ts @@ -15,6 +15,10 @@ function dwAlign(off: number): number { return ul; } +function randint(min: number, max: number) { + return Math.floor(Math.random() * (max - min) + min); +} + // animation state (used during animation playback) class AgentAnimationState { char: Agent; @@ -308,6 +312,9 @@ export class Agent { } show() { + this.x = randint(0, document.documentElement.clientWidth - this.data.characterInfo.charWidth); + this.y = randint(0, document.documentElement.clientHeight - this.data.characterInfo.charHeight); + this.setLoc(); this.cnv.style.display = 'block'; this.playAnimationByName('Show', () => {}); } diff --git a/webapp/src/ts/client.ts b/webapp/src/ts/client.ts index f56f134..8774389 100644 --- a/webapp/src/ts/client.ts +++ b/webapp/src/ts/client.ts @@ -188,11 +188,11 @@ export class MSAgentClient { this.playingAudio.set(user!.username, audio); audio.addEventListener('ended', () => { - this.playingAudio.delete(user!.username); - // give a bit of time before the wordballoon disappears setTimeout(() => { - user!.agent.stopSpeaking(); + if (this.playingAudio.get(user!.username) === audio) + user!.agent.stopSpeaking(); + this.playingAudio.delete(user!.username); }, 1000); });