Closed Oliver-Akins closed 3 years ago
The solution is being modified a bit to instead of having the NewCard event, we will just have all clients solely using the the UpdateHand
event listening for updating all forms of the hand, what this means is that the spirit will also have the event listening and we will be storing the Spirit's hand in the team object as well as the medium's hand, this also helps prevent disconnections from losing any gamestate.
Overview
Each team must keep the cards between each of the mediums synchronized, there are few different ways that this can be done listed below:
NewCard
listener,RemoveCard
listener, and aSendCard
function. Then the client will send the card to the spirit by triggering theSendCard
event, from which the server sends aRemoveCard
to all of the other mediums, and then picks a new card from the deck and sends theNewCard
to all the mediums, and simultaneously to all this, the spirit receives theNewCard
event with the card from the medium. This has the downside of being and insanely complex sequence of event firings, so this is not ideal.NewCards
listener,RemoveCard
listener,SendCard
function, a watcher on the questions array, and the server has aGetCards
listener, when the questions array changes on the client, calculate the number the cards needed in order to get to 7, then the trigger theGetCards
event, meanwhile the other mediums get theRemoveCard
event, telling them to remove the cards... which then triggers the watcher to request more cards, meaning the cards that each medium will get may be different, which is not synchronizing the hands to any degree.UpdateHand
listener, and aSendCard
function. So the client triggers theSendCard
to send the card to the spirit, from which the spirit receives aNewCard
event with the new card information. Then the other clients receive anUpdateHand
event with a newly drawn card and the sent card removed from the array. This keeps all the mediums in sync and prevents any race conditions related to drawing a new card for the hands.Solution:
Client:
Event Listeners:
UpdateHand
NewCard
Event Emissions:
SendCard
Server:
Event Listeners:
SendCard
Event Emissions:
UpdateHand
NewCard