164 lines
4.6 KiB
Go
164 lines
4.6 KiB
Go
package main
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
|
|
"git.chromaticdragon.app/kistaro/CardSimEngine/cardsim"
|
|
)
|
|
|
|
// Type aliases, unlike distinctly named types, are fully substitutable for
|
|
// the original type. This trims off some annoying-to-type things.
|
|
type player = cardsim.Player[*SmokeTestCollection]
|
|
type card = cardsim.Card[*SmokeTestCollection]
|
|
type cardOption = cardsim.CardOption[*SmokeTestCollection]
|
|
|
|
func makeAdditionCard(amt int) cardsim.Card[*SmokeTestCollection] {
|
|
c := &cardsim.BasicCard[*SmokeTestCollection]{
|
|
CardTitle: cardsim.Msgf("Additive %d", amt),
|
|
CardText: cardsim.Msgf("You can change the Number by %d.", amt),
|
|
CardOptions: []cardsim.CardOption[*SmokeTestCollection]{
|
|
&cardsim.BasicOption[*SmokeTestCollection]{
|
|
Text: cardsim.Msgf("Add %d", amt),
|
|
Effect: func(p *player) error {
|
|
p.Stats.Number.Value += amt
|
|
return nil
|
|
},
|
|
Output: cardsim.MsgStr("Added."),
|
|
},
|
|
&cardsim.BasicOption[*SmokeTestCollection]{
|
|
Text: cardsim.Msgf("Subtract %d", amt),
|
|
Effect: func(p *player) error {
|
|
p.Stats.Number.Value -= amt
|
|
return nil
|
|
},
|
|
Output: cardsim.MsgStr("Subtracted."),
|
|
},
|
|
},
|
|
AfterOption: func(c card, p *player, _ cardOption) error {
|
|
p.Deck.InsertRandomBottom(0.5, c)
|
|
return nil
|
|
},
|
|
}
|
|
return c
|
|
}
|
|
|
|
func makeMultiplicationCard(amt int) cardsim.Card[*SmokeTestCollection] {
|
|
c := &cardsim.BasicCard[*SmokeTestCollection]{
|
|
CardTitle: cardsim.Msgf("Multiplicative %d", amt),
|
|
CardText: cardsim.Msgf("You can multiply or divide the Number by %d, or maybe divide the Number by that.", amt),
|
|
CardOptions: []cardsim.CardOption[*SmokeTestCollection]{
|
|
&cardsim.BasicOption[*SmokeTestCollection]{
|
|
Text: cardsim.Msgf("Multiply by %d", amt),
|
|
Effect: func(p *player) error {
|
|
p.Stats.Number.Value *= amt
|
|
return nil
|
|
},
|
|
Output: cardsim.MsgStr("Multiplied."),
|
|
},
|
|
&cardsim.BasicOption[*SmokeTestCollection]{
|
|
Text: cardsim.Msgf("Integer divide by %d", amt),
|
|
Effect: func(p *player) error {
|
|
p.Stats.Number.Value /= amt
|
|
return nil
|
|
},
|
|
Output: cardsim.MsgStr("Divided."),
|
|
},
|
|
inverseDivision(amt),
|
|
},
|
|
AfterOption: func(c card, p *player, _ cardOption) error {
|
|
p.Deck.InsertRandomBottom(0.5, c)
|
|
return nil
|
|
},
|
|
}
|
|
return c
|
|
}
|
|
|
|
type inverseDivision int
|
|
|
|
func (i inverseDivision) OptionText(p *player) (cardsim.Message, error) {
|
|
if p.Stats.Number.Value == 0 {
|
|
return cardsim.MsgStr("You can't divide by zero!"), nil
|
|
}
|
|
return cardsim.Msgf("Divide %d by the Number", int(i)), nil
|
|
}
|
|
|
|
func (i inverseDivision) Enact(p *player) (cardsim.Message, error) {
|
|
if p.Stats.Number.Value == 0 {
|
|
return nil, errors.New("you can't divide by zero")
|
|
}
|
|
p.Stats.Number.Value = int(i) / p.Stats.Number.Value
|
|
return cardsim.MsgStr("Inverse divided."), nil
|
|
}
|
|
|
|
func (i inverseDivision) Enabled(p *player) bool {
|
|
return p.Stats.Number.Value != 0
|
|
}
|
|
|
|
func initDeck(d *cardsim.Deck[*SmokeTestCollection]) {
|
|
addMe := []int{
|
|
0, 1, 2, 5, 10, 50, 100, 1000, 2500, 500000, 9876543,
|
|
}
|
|
for _, n := range addMe {
|
|
d.Insert(cardsim.BottomOfDeck, makeAdditionCard(n))
|
|
}
|
|
|
|
multiplyMe := []int{
|
|
2, 4, 8, 16, 32, 64, 128, 512, 1024, 9999, 84720413,
|
|
}
|
|
for _, n := range multiplyMe {
|
|
d.Insert(cardsim.BottomOfDeck, makeMultiplicationCard(n))
|
|
}
|
|
if err := d.Shuffle(); cardsim.IsSeriousError(err) {
|
|
panic(err)
|
|
} else if err != nil {
|
|
fmt.Printf("Error shuffling: %v\n", err)
|
|
}
|
|
}
|
|
|
|
func installPermanentActions(pa *[]card) {
|
|
*pa = []card{
|
|
&cardsim.BasicCard[*SmokeTestCollection]{
|
|
CardTitle: cardsim.MsgStr("Reset to 0"),
|
|
CardText: cardsim.MsgStr("Resets Number to 0."),
|
|
CardOptions: []cardOption{
|
|
&cardsim.BasicOption[*SmokeTestCollection]{
|
|
Text: cardsim.MsgStr("Reset to 0."),
|
|
Effect: func(p *player) error {
|
|
p.Stats.Number.Value = 0
|
|
return nil
|
|
},
|
|
Output: cardsim.MsgStr("Done."),
|
|
},
|
|
},
|
|
},
|
|
&cardsim.BasicCard[*SmokeTestCollection]{
|
|
CardTitle: cardsim.MsgStr("Reset to 1000000"),
|
|
CardText: cardsim.MsgStr("Resets Number to one million."),
|
|
CardOptions: []cardOption{
|
|
&cardsim.BasicOption[*SmokeTestCollection]{
|
|
Text: cardsim.MsgStr("Reset to 1,000,000"),
|
|
Effect: func(p *player) error {
|
|
p.Stats.Number.Value = 1000000
|
|
return nil
|
|
},
|
|
Output: cardsim.MsgStr("Done."),
|
|
},
|
|
},
|
|
},
|
|
&cardsim.BasicCard[*SmokeTestCollection]{
|
|
CardTitle: cardsim.MsgStr("Draw a card"),
|
|
CardText: cardsim.MsgStr("Draw an extra card."),
|
|
CardOptions: []cardOption{
|
|
&cardsim.BasicOption[*SmokeTestCollection]{
|
|
Text: cardsim.MsgStr("Draw an extra card."),
|
|
Effect: func(p *player) error {
|
|
return p.Draw()
|
|
},
|
|
Output: cardsim.MsgStr("Drawn. Probably."),
|
|
},
|
|
},
|
|
},
|
|
}
|
|
}
|