tome_lib/effect.go

44 lines
799 B
Go
Raw Normal View History

2021-10-01 12:43:55 -04:00
package tome_lib
import (
"log"
"github.com/google/uuid"
)
type Effect struct {
2021-11-08 15:33:55 -05:00
Owner uuid.UUID
Target uuid.UUID
ID int
Modifier int
2021-10-01 12:43:55 -04:00
}
func RemoveEffect(source uuid.UUID, c *Card) {
if c.Type == EmptyValue {
return
}
for i, e := range c.Effects {
if e.Owner == source {
c.Effects = append(c.Effects[:i], c.Effects[i+1:]...)
}
}
}
func AddEffect(c *Card, e *Effect) {
if c.Type == EmptyValue {
2021-10-07 12:46:59 -04:00
//can't apply effect to empty card
2021-10-01 12:43:55 -04:00
return
}
2021-10-07 12:46:59 -04:00
if c.Position < 0 || c.Position > 3 {
2021-10-01 12:43:55 -04:00
log.Println("trying to apply effect to card not on the board")
}
for _, v := range c.Effects {
if v.Owner == e.Owner && v.ID == e.ID && v.Target == e.Target {
2021-10-07 12:46:59 -04:00
//can't stack effects
2021-10-01 12:43:55 -04:00
return
}
}
log.Printf("applying %v to %v", e, c)
c.Effects = append(c.Effects, e)
}