add adrenaline to dto
This commit is contained in:
parent
93716a7f0f
commit
d0b3cbd47a
21
game/game.go
21
game/game.go
@ -272,16 +272,17 @@ func (g *Match) DTO(id player.ID, deadline time.Time) serve.Game {
|
|||||||
g.players[0].dto(),
|
g.players[0].dto(),
|
||||||
g.players[1].dto(),
|
g.players[1].dto(),
|
||||||
},
|
},
|
||||||
Action: g.action.String(),
|
Action: g.action.String(),
|
||||||
Winner: w,
|
Winner: w,
|
||||||
Round: g.round,
|
Round: g.round,
|
||||||
Dealer: g.CurrentPlayer() == &g.players[0],
|
Dealer: g.CurrentPlayer() == &g.players[0],
|
||||||
Damage: g.damage,
|
Damage: g.damage,
|
||||||
Shell: g.Peek(id),
|
Adrenaline: g.adrenaline,
|
||||||
Previous: g.prev,
|
Shell: g.Peek(id),
|
||||||
Deadline: deadline.UnixMilli(),
|
Previous: g.prev,
|
||||||
Live: live,
|
Deadline: deadline.UnixMilli(),
|
||||||
Blank: blank,
|
Live: live,
|
||||||
|
Blank: blank,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@ func TestNewGame(t *testing.T) {
|
|||||||
{g.hp < 2 || g.hp > 4, "hp is %d, want 2-4", []any{g.hp}},
|
{g.hp < 2 || g.hp > 4, "hp is %d, want 2-4", []any{g.hp}},
|
||||||
{g.damage != 1, "damage is %d, want 1", []any{g.damage}},
|
{g.damage != 1, "damage is %d, want 1", []any{g.damage}},
|
||||||
{g.reveal, "revealed at start", nil},
|
{g.reveal, "revealed at start", nil},
|
||||||
|
{g.adrenaline, "adrenaline at start", nil},
|
||||||
{g.prev != nil, "already discharged", nil},
|
{g.prev != nil, "already discharged", nil},
|
||||||
}
|
}
|
||||||
for _, c := range checks {
|
for _, c := range checks {
|
||||||
@ -60,6 +61,7 @@ func TestGameStartRound(t *testing.T) {
|
|||||||
{g.hp < 2 || g.hp > 4, "hp is %d, want 2-4", []any{g.hp}},
|
{g.hp < 2 || g.hp > 4, "hp is %d, want 2-4", []any{g.hp}},
|
||||||
{g.damage != 1, "damage is %d, want 1", []any{g.damage}},
|
{g.damage != 1, "damage is %d, want 1", []any{g.damage}},
|
||||||
{g.reveal, "revealed at start", nil},
|
{g.reveal, "revealed at start", nil},
|
||||||
|
{g.adrenaline, "adrenaline at start", nil},
|
||||||
{g.prev != nil, "already discharged", nil},
|
{g.prev != nil, "already discharged", nil},
|
||||||
}
|
}
|
||||||
for _, c := range checks {
|
for _, c := range checks {
|
||||||
@ -95,6 +97,7 @@ func TestGameStartGroup(t *testing.T) {
|
|||||||
{g.turn != 1, "turn is %d, want 1", []any{g.turn}},
|
{g.turn != 1, "turn is %d, want 1", []any{g.turn}},
|
||||||
{g.damage != 1, "damage is %d, want 1", []any{g.damage}},
|
{g.damage != 1, "damage is %d, want 1", []any{g.damage}},
|
||||||
{g.reveal, "revealed at start", nil},
|
{g.reveal, "revealed at start", nil},
|
||||||
|
{g.adrenaline, "adrenaline at start", nil},
|
||||||
{g.prev != nil, "already discharged", nil},
|
{g.prev != nil, "already discharged", nil},
|
||||||
}
|
}
|
||||||
for _, c := range checks {
|
for _, c := range checks {
|
||||||
@ -128,6 +131,7 @@ func TestGameNextTurn(t *testing.T) {
|
|||||||
{g.turn != i, "turn is %d, want %d", []any{g.turn, i}},
|
{g.turn != i, "turn is %d, want %d", []any{g.turn, i}},
|
||||||
{g.damage != 1, "damage is %d, want 1", []any{g.damage}},
|
{g.damage != 1, "damage is %d, want 1", []any{g.damage}},
|
||||||
{g.reveal, "revealed at start", nil},
|
{g.reveal, "revealed at start", nil},
|
||||||
|
{g.adrenaline, "adrenaline at start", nil},
|
||||||
{g.CurrentPlayer().cuffs != uncuffed, "cuffs is %d, want %d", []any{g.CurrentPlayer().cuffs, uncuffed}},
|
{g.CurrentPlayer().cuffs != uncuffed, "cuffs is %d, want %d", []any{g.CurrentPlayer().cuffs, uncuffed}},
|
||||||
}
|
}
|
||||||
for _, c := range checks {
|
for _, c := range checks {
|
||||||
@ -447,14 +451,15 @@ func TestGameDTO(t *testing.T) {
|
|||||||
g.players[0].dto(),
|
g.players[0].dto(),
|
||||||
g.players[1].dto(),
|
g.players[1].dto(),
|
||||||
},
|
},
|
||||||
Action: "Start",
|
Action: "Start",
|
||||||
Round: g.round,
|
Round: g.round,
|
||||||
Dealer: false,
|
Dealer: false,
|
||||||
Damage: g.damage,
|
Damage: g.damage,
|
||||||
Shell: nil,
|
Adrenaline: false,
|
||||||
Previous: nil,
|
Shell: nil,
|
||||||
Live: len(g.shells) / 2,
|
Previous: nil,
|
||||||
Blank: (len(g.shells) + 1) / 2,
|
Live: len(g.shells) / 2,
|
||||||
|
Blank: (len(g.shells) + 1) / 2,
|
||||||
}
|
}
|
||||||
if got := g.DTO(dealer, time.UnixMilli(0)); want != got {
|
if got := g.DTO(dealer, time.UnixMilli(0)); want != got {
|
||||||
t.Errorf("dealer sees the wrong thing:\nwant %+v\ngot %+v", want, got)
|
t.Errorf("dealer sees the wrong thing:\nwant %+v\ngot %+v", want, got)
|
||||||
@ -473,14 +478,15 @@ func TestGameDTO(t *testing.T) {
|
|||||||
g.players[0].dto(),
|
g.players[0].dto(),
|
||||||
g.players[1].dto(),
|
g.players[1].dto(),
|
||||||
},
|
},
|
||||||
Action: "Shoot",
|
Action: "Shoot",
|
||||||
Round: g.round,
|
Round: g.round,
|
||||||
Dealer: true,
|
Dealer: true,
|
||||||
Damage: g.damage,
|
Damage: g.damage,
|
||||||
Shell: nil,
|
Adrenaline: false,
|
||||||
Previous: &g.shellArray[0],
|
Shell: nil,
|
||||||
Live: 0,
|
Previous: &g.shellArray[0],
|
||||||
Blank: 0,
|
Live: 0,
|
||||||
|
Blank: 0,
|
||||||
}
|
}
|
||||||
if got := g.DTO(dealer, time.UnixMilli(0)); want != got {
|
if got := g.DTO(dealer, time.UnixMilli(0)); want != got {
|
||||||
t.Errorf("dealer sees the wrong thing:\nwant %+v\ngot %+v", want, got)
|
t.Errorf("dealer sees the wrong thing:\nwant %+v\ngot %+v", want, got)
|
||||||
|
@ -17,6 +17,8 @@ type Game struct {
|
|||||||
Dealer bool `json:"dealer"`
|
Dealer bool `json:"dealer"`
|
||||||
// Damage is the damage a live shell will deal this turn.
|
// Damage is the damage a live shell will deal this turn.
|
||||||
Damage int8 `json:"damage"`
|
Damage int8 `json:"damage"`
|
||||||
|
// Adrenaline indicates whether the current player has adrenaline.
|
||||||
|
Adrenaline bool `json:"adrenaline"`
|
||||||
// Shell gives whether the current shell is live if it is revealed.
|
// Shell gives whether the current shell is live if it is revealed.
|
||||||
// Undefined if this game state is not for the current player or if the
|
// Undefined if this game state is not for the current player or if the
|
||||||
// current player hasn't revealed it.
|
// current player hasn't revealed it.
|
||||||
|
Loading…
Reference in New Issue
Block a user