Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion handlers/ClientGameJudgements.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ func handleClientGameJudgements(user *sessions.User, packet *packets.ClientGameJ
}

game.RunLocked(func() {
game.HandlePlayerJudgements(user.Info.Id, packet.Judgements)
game.HandlePlayerJudgements(user.Info.Id, packet.Judgements, packet.MineHitDelta)
})
}
7 changes: 4 additions & 3 deletions multiplayer/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -786,17 +786,17 @@ func (game *Game) SetPlayerSkippedSong(userId int) {
}

// HandlePlayerJudgements Handles when a player sends judgement data during a multiplayer match
func (game *Game) HandlePlayerJudgements(userId int, judgements []common.Judgements) {
func (game *Game) HandlePlayerJudgements(userId int, judgements []common.Judgements, mineHitDelta int) {
if !game.Data.InProgress || !utils.Includes(game.playersInMatch, userId) {
return
}

if score, ok := game.playerScores[userId]; ok {
score.AddJudgements(judgements)
score.AddJudgements(judgements, mineHitDelta)
game.cachePlayerScore(userId, score)
}

packet := packets.NewServerGameJudgements(userId, judgements)
packet := packets.NewServerGameJudgements(userId, judgements, mineHitDelta)

for _, playerId := range game.playersInMatch {
if playerId == userId {
Expand Down Expand Up @@ -1085,6 +1085,7 @@ func (game *Game) insertMatchIntoDatabase() {
CountGood: score.Judgements[common.JudgementGood],
CountOkay: score.Judgements[common.JudgementOkay],
CountMiss: score.Judgements[common.JudgementMiss],
CountMineHit: score.CountMineHit,
Won: int(winResult),
}

Expand Down
3 changes: 2 additions & 1 deletion packets/ClientGameJudgements.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ import "example.com/Quaver/Z/common"

type ClientGameJudgements struct {
Packet
Judgements []common.Judgements `json:"j"`
Judgements []common.Judgements `json:"j"`
MineHitDelta int `json:"m"`
}
14 changes: 8 additions & 6 deletions packets/ServerGameJudgements.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import "example.com/Quaver/Z/common"

type ServerGameJudgements struct {
Packet
UserId int `json:"u"`
Judgements []common.Judgements `json:"j"`
UserId int `json:"u"`
Judgements []common.Judgements `json:"j"`
MineHitDelta int `json:"m"`
}

func NewServerGameJudgements(userId int, judgements []common.Judgements) *ServerGameJudgements {
func NewServerGameJudgements(userId int, judgements []common.Judgements, mineHitDelta int) *ServerGameJudgements {
return &ServerGameJudgements{
Packet: Packet{Id: PacketIdServerGameJudgements},
UserId: userId,
Judgements: judgements,
Packet: Packet{Id: PacketIdServerGameJudgements},
UserId: userId,
Judgements: judgements,
MineHitDelta: mineHitDelta,
}
}
9 changes: 8 additions & 1 deletion scoring/score_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type ScoreProcessor struct {
Combo int
MaxCombo int
Judgements map[common.Judgements]int
CountMineHit int
}

func NewScoreProcessor(difficultyRating float64, modifiers common.Mods) *ScoreProcessor {
Expand All @@ -24,10 +25,11 @@ func NewScoreProcessor(difficultyRating float64, modifiers common.Mods) *ScorePr
}

// AddJudgements Adds new judgements to the score
func (sp *ScoreProcessor) AddJudgements(judgements []common.Judgements) {
func (sp *ScoreProcessor) AddJudgements(judgements []common.Judgements, mineHitDelta int) {
for _, j := range judgements {
sp.addJudgement(j)
}
sp.addMineHits(mineHitDelta)

sp.calculateAccuracy()
sp.calculatePerformanceRating()
Expand All @@ -48,6 +50,11 @@ func (sp *ScoreProcessor) addJudgement(judgement common.Judgements) {
}
}

// addMineHits Adds a number of new mine hits to the score
func (sp *ScoreProcessor) addMineHits(count int) {
sp.CountMineHit += count
}

// Calculates the accuracy of the current score
func (sp *ScoreProcessor) calculateAccuracy() {
var acc float64 = 0
Expand Down
Loading