48 lines
873 B
Go
48 lines
873 B
Go
package card
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"git.tuxpa.in/a/card_id/common/data"
|
|
"lukechampine.com/frand"
|
|
)
|
|
|
|
type Card struct {
|
|
Id int `json:"id"`
|
|
Name string `json:"name"`
|
|
CleanName string `json:"clean_name"`
|
|
|
|
Rate float64 `json:"rate"`
|
|
|
|
BonusLife bool `json:"bonus_life"`
|
|
}
|
|
|
|
func (c *Card) FromResult(d data.Result) Card {
|
|
c.Id = d.Id
|
|
c.Name = d.Name
|
|
c.Rate = d.Rate
|
|
c.CleanName = strings.ReplaceAll(strings.TrimSpace(stripNum(c.Name)), " ", " ")
|
|
return *c
|
|
}
|
|
|
|
func (c *Card) CopyWithBonus(chance float64) Card {
|
|
return Card{
|
|
Id: c.Id,
|
|
Rate: c.Rate,
|
|
Name: c.Name,
|
|
CleanName: c.CleanName,
|
|
BonusLife: (frand.Float64() <= chance),
|
|
}
|
|
}
|
|
|
|
func stripNum(s string) string {
|
|
var result strings.Builder
|
|
for i := 0; i < len(s); i++ {
|
|
b := s[i]
|
|
if !('0' <= b && b <= '9') {
|
|
result.WriteByte(b)
|
|
}
|
|
}
|
|
return result.String()
|
|
}
|