2024-01-20 22:06:56 -06:00
|
|
|
package game
|
|
|
|
|
2024-04-07 15:14:57 -05:00
|
|
|
import "math/rand/v2"
|
|
|
|
|
2024-02-04 10:37:15 -06:00
|
|
|
type item int8
|
2024-01-20 22:06:56 -06:00
|
|
|
|
|
|
|
const (
|
2024-02-04 10:37:15 -06:00
|
|
|
itemNone item = iota
|
|
|
|
itemLens
|
|
|
|
itemCig
|
|
|
|
itemBeer
|
|
|
|
itemCuff
|
|
|
|
itemKnife
|
2024-04-07 16:04:38 -05:00
|
|
|
itemAdrenaline
|
|
|
|
itemPhone
|
|
|
|
itemInverter
|
|
|
|
itemPill
|
2024-01-20 22:06:56 -06:00
|
|
|
)
|
|
|
|
|
2024-04-07 15:14:57 -05:00
|
|
|
func newItem() item {
|
2024-04-07 16:04:38 -05:00
|
|
|
return item(rand.IntN(9)) + 1
|
2024-01-20 22:06:56 -06:00
|
|
|
}
|
2024-01-20 22:52:44 -06:00
|
|
|
|
2024-02-04 10:37:15 -06:00
|
|
|
func (i item) apply(g *Match) bool {
|
2024-01-20 22:52:44 -06:00
|
|
|
switch i {
|
2024-02-04 10:37:15 -06:00
|
|
|
case itemNone:
|
2024-01-20 22:52:44 -06:00
|
|
|
return false
|
2024-02-04 10:37:15 -06:00
|
|
|
case itemLens:
|
2024-02-03 11:44:11 -06:00
|
|
|
// Lenses are always used, even if they have no effect.
|
|
|
|
g.action = actLens
|
2024-01-21 04:16:48 -06:00
|
|
|
g.reveal = true
|
2024-01-20 22:52:44 -06:00
|
|
|
return true
|
2024-02-04 10:37:15 -06:00
|
|
|
case itemCig:
|
2024-01-20 23:39:59 -06:00
|
|
|
cur := g.CurrentPlayer()
|
2024-01-21 04:16:48 -06:00
|
|
|
if cur.hp < g.hp {
|
|
|
|
cur.hp++
|
2024-01-21 18:41:43 -06:00
|
|
|
// Cigs are always used, even if they have no effect.
|
2024-01-20 22:52:44 -06:00
|
|
|
}
|
2024-02-03 11:44:11 -06:00
|
|
|
g.action = actCig
|
2024-01-21 18:41:43 -06:00
|
|
|
return true
|
2024-02-04 10:37:15 -06:00
|
|
|
case itemBeer:
|
2024-01-28 12:42:42 -06:00
|
|
|
g.popShell()
|
2024-02-03 11:44:11 -06:00
|
|
|
g.action = actBeer
|
2024-01-20 22:52:44 -06:00
|
|
|
if g.Empty() {
|
2024-02-03 11:44:11 -06:00
|
|
|
g.action = actBeerGameEnd
|
2024-01-28 12:42:42 -06:00
|
|
|
g.NextGame()
|
2024-01-20 22:52:44 -06:00
|
|
|
}
|
|
|
|
return true
|
2024-02-04 10:37:15 -06:00
|
|
|
case itemCuff:
|
2024-01-20 22:52:44 -06:00
|
|
|
opp := g.Opponent()
|
2024-02-04 10:37:15 -06:00
|
|
|
if opp.cuffs != uncuffed {
|
2024-01-20 22:52:44 -06:00
|
|
|
return false
|
|
|
|
}
|
2024-02-03 11:44:11 -06:00
|
|
|
g.action = actCuff
|
2024-02-04 10:37:15 -06:00
|
|
|
opp.cuffs = cuffedSkip
|
2024-01-20 22:52:44 -06:00
|
|
|
return true
|
2024-02-04 10:37:15 -06:00
|
|
|
case itemKnife:
|
2024-01-21 04:16:48 -06:00
|
|
|
if g.damage != 1 {
|
2024-01-20 22:52:44 -06:00
|
|
|
return false
|
|
|
|
}
|
2024-02-03 11:44:11 -06:00
|
|
|
g.action = actKnife
|
2024-01-21 04:16:48 -06:00
|
|
|
g.damage = 2
|
2024-01-20 22:52:44 -06:00
|
|
|
return true
|
2024-04-07 16:04:38 -05:00
|
|
|
case itemAdrenaline:
|
2024-04-07 20:40:01 -05:00
|
|
|
if g.adrenaline {
|
|
|
|
// Adrenaline forbids using adrenaline.
|
|
|
|
return false
|
|
|
|
}
|
2024-04-07 16:04:38 -05:00
|
|
|
g.action = actAdrenaline
|
2024-04-07 20:40:01 -05:00
|
|
|
g.adrenaline = true
|
2024-04-07 16:04:38 -05:00
|
|
|
return true
|
|
|
|
case itemPhone:
|
|
|
|
g.action = actPhone
|
|
|
|
// TODO(zeph): implement
|
|
|
|
return true
|
|
|
|
case itemInverter:
|
|
|
|
g.action = actInverter
|
|
|
|
g.shells[0] = !g.shells[0]
|
|
|
|
return true
|
|
|
|
case itemPill:
|
|
|
|
cur := g.CurrentPlayer()
|
|
|
|
if rand.Uint64() <= (1<<65)/5 {
|
|
|
|
g.action = actPillsHeal
|
|
|
|
cur.hp = min(cur.hp+2, g.hp)
|
|
|
|
} else {
|
|
|
|
g.action = actPillsHurt
|
|
|
|
cur.hp--
|
|
|
|
}
|
|
|
|
return true
|
2024-01-20 22:52:44 -06:00
|
|
|
default:
|
|
|
|
panic("shotgun: unknown item")
|
|
|
|
}
|
|
|
|
}
|
2024-01-21 00:47:12 -06:00
|
|
|
|
2024-04-07 16:04:38 -05:00
|
|
|
var itemNames = [...]string{
|
|
|
|
itemNone: "",
|
|
|
|
itemLens: "🔍",
|
|
|
|
itemCig: "🚬",
|
|
|
|
itemBeer: "🍺",
|
|
|
|
itemCuff: "👮",
|
|
|
|
itemKnife: "🔪",
|
|
|
|
itemAdrenaline: "💉",
|
|
|
|
itemPhone: "📱",
|
|
|
|
itemInverter: "🧲",
|
|
|
|
itemPill: "💊",
|
|
|
|
}
|
2024-02-03 11:44:11 -06:00
|
|
|
|
2024-02-04 10:37:15 -06:00
|
|
|
func (i item) String() string {
|
2024-02-03 11:44:11 -06:00
|
|
|
return itemNames[i]
|
2024-01-21 00:47:12 -06:00
|
|
|
}
|