snengame/internal/game/effect.go

40 lines
668 B
Go
Raw Normal View History

2021-07-25 15:33:47 -04:00
package game
2021-07-26 11:17:45 -04:00
import (
"log"
"github.com/google/uuid"
)
2021-07-25 15:33:47 -04:00
type Effect struct {
Owner uuid.UUID
Target uuid.UUID
ID int
}
func RemoveEffect(source uuid.UUID, c *Card) {
2021-07-25 17:23:12 -04:00
if c.Type == EmptyValue {
return
}
2021-07-25 15:33:47 -04:00
for i, e := range c.Effects {
if e.Owner == source {
c.Effects = append(c.Effects[:i], c.Effects[i+1:]...)
}
}
}
2021-07-26 11:17:45 -04:00
func AddEffect(c *Card, e *Effect) {
2021-07-25 17:23:12 -04:00
if c.Type == EmptyValue {
2021-07-26 11:17:45 -04:00
log.Println("Can't add effect to empty card")
2021-07-25 17:23:12 -04:00
return
}
2021-07-25 15:33:47 -04:00
for _, v := range c.Effects {
if v.Owner == e.Owner && v.ID == e.ID {
2021-07-26 11:17:45 -04:00
log.Println("can't stack effects")
2021-07-25 15:33:47 -04:00
return
}
}
2021-07-26 11:17:45 -04:00
log.Printf("applying %v to %v", e, c)
2021-07-25 15:33:47 -04:00
c.Effects = append(c.Effects, e)
}