feat: add send message to players with runtime.Notify

This commit is contained in:
Mihail Pestrikov 2025-01-19 23:31:00 +00:00
parent 75f843f700
commit da0c451528

View file

@ -87,9 +87,10 @@ func getRoom(ctx storage.Context, roomId string) Room {
return room
}
// Function to send message to player, now it is default
func sendMessageToPlayer(message string, player Player) {
// todo: Сделать основную логику
// Function to send message to players, event is recorded in blockchain
// Could be read through getapplicationlog or RPC call
func sendMessageToPlayers(notificationName, message string) {
runtime.Notify(notificationName, message)
}
// MAIN METHODS TO PLAY IN GAME
@ -196,9 +197,7 @@ func AskQuestion(roomId string, question string) bool {
room.Rounds = append(room.Rounds, round)
room.Status = RoomStatusAnswering
for _, player := range room.Players {
sendMessageToPlayer(question, player)
}
sendMessageToPlayers("RoundQuestion", question)
// todo: Не забыть про nns
// todo: Добавить списание токенов за создание вопроса
@ -261,11 +260,9 @@ func EndQuestion(roomId string) bool {
var result string
for i, answer := range round.Answers {
result += fmt.Sprintf("index:%d, player:%s, answer:%s\n", i, answer.Wallet, answer.Content)
}
} // todo: нужно проверить нормально ли всё с \n в логах
for _, player := range room.Players {
sendMessageToPlayer(result, player)
}
sendMessageToPlayers("RoundAnswers", result)
setRoom(ctx, &room)
return true
@ -360,9 +357,7 @@ func GetRoundWinner(roomId string) bool {
result += fmt.Sprintf("place:%d, winner:%s, votes:%s\n", i, answer.Wallet, answer.Votes)
}
for _, player := range room.Players {
sendMessageToPlayer(result, player)
}
sendMessageToPlayers("RoundWinners", result)
// todo: Отправка награды победителям
@ -426,7 +421,7 @@ func ManuallyFinishGame(roomId string) bool {
func finishGame(ctx storage.Context, room *Room) bool {
var winners = getGameWinner(room)
// todo: Отправка награды победителям и хосту
// todo: Нотификация результатов всей игры