2021-10-01 12:43:55 -04:00
|
|
|
package tome_lib
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"github.com/google/uuid"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Effect struct {
|
2021-11-14 14:43:04 -05:00
|
|
|
Owner uuid.UUID
|
|
|
|
Target uuid.UUID
|
|
|
|
ID int
|
|
|
|
Modifier int
|
|
|
|
NeedsCard bool
|
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:]...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-11-11 15:08:47 -05:00
|
|
|
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:]...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-10-01 12:43:55 -04:00
|
|
|
func AddEffect(c *Card, e *Effect) {
|
2021-11-14 14:43:04 -05:00
|
|
|
if c.Type == EmptyValue && e.NeedsCard {
|
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-11-10 17:44:54 -05:00
|
|
|
if e.Target == uuid.Nil {
|
|
|
|
log.Println("trying to apply targeted effect before target set")
|
|
|
|
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")
|
2021-11-10 17:44:54 -05:00
|
|
|
return
|
2021-10-01 12:43:55 -04:00
|
|
|
}
|
|
|
|
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)
|
|
|
|
}
|
2021-11-11 15:08:47 -05:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|