add player effects, initial support for arbitrary scrying

This commit is contained in:
stryan 2021-11-11 15:08:47 -05:00
parent bfd48cb069
commit 59cfb71a5e
2 changed files with 35 additions and 6 deletions

View File

@ -23,7 +23,16 @@ func RemoveEffect(source uuid.UUID, c *Card) {
}
}
}
func RemovePlayerEffect(source uuid.UUID, p *Player) {
if p == nil {
return
}
for i, e := range p.Effects {
if e.Owner == source {
p.Effects = append(p.Effects[:i], p.Effects[i+1:]...)
}
}
}
func AddEffect(c *Card, e *Effect) {
if c.Type == EmptyValue {
//can't apply effect to empty card
@ -46,3 +55,22 @@ func AddEffect(c *Card, e *Effect) {
log.Printf("applying %v to %v", e, c)
c.Effects = append(c.Effects, e)
}
func AddPlayerEffect(p *Player, e *Effect) {
if p == nil || e == nil {
log.Println("adding nil player efect")
return
}
if e.Target != uuid.Nil {
log.Println("trying to apply targeted effect to player set")
return
}
for _, v := range p.Effects {
if v.Owner == e.Owner && v.ID == e.ID {
//can't stack effects
return
}
}
log.Printf("applying %v to player %v", e, p)
p.Effects = append(p.Effects, e)
}

View File

@ -1,9 +1,10 @@
package tome_lib
type Player struct {
Name string `json:"name"`
Id int `json:"id"`
Hand []*Card `json:"hand"`
Life int `json:"life"`
Ready bool `json:"ready"`
Name string `json:"name"`
Id int `json:"id"`
Hand []*Card `json:"hand"`
Life int `json:"life"`
Ready bool `json:"ready"`
Effects []*Effect
}