Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions internal/handler/games/wavinghands/spells/cause-heavy-wounds.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,36 @@ type CauseHeavyWounds struct {
Description string `json:"description"`
Usage string `json:"usage"`
Damage int `json:"damage"`
Resistences string `json:"resistences"`
Resistances string `json:"resistances"`
Protections string `json:"protections"`
}

func (cHW CauseHeavyWounds) Cast(wizard *wavinghands.Wizard, target *wavinghands.Living) (string, error) {
if (len(wizard.Right.Sequence) >= len(cHW.Sequence) && strings.HasSuffix(wizard.Right.Sequence, cHW.Sequence)) ||
(len(wizard.Left.Sequence) >= len(cHW.Sequence) && strings.HasSuffix(wizard.Left.Sequence, cHW.ShSequence)) {
func (cHW *CauseHeavyWounds) Cast(wizard *wavinghands.Wizard, target *wavinghands.Living) (string, error) {
var returnString string = ""
if strings.HasSuffix(wizard.Right.Sequence, cHW.Sequence) {

if strings.Contains(target.Wards, "cureHeavyWounds") {
target.HitPoints -= 1
return fmt.Sprintf("%s caused heavy wounds on %s but they were protected and only sustained minimal damage", wizard.Name, target.Selector), nil
target.HitPoints -= cHW.Damage - 2
returnString = fmt.Sprintf("%s caused heavy wounds on %s but they were protected and only sustained minimal damage", wizard.Name, target.Selector)
} else {
target.HitPoints -= 3
return fmt.Sprintf("%s caused heavy wounds on %s", wizard.Name, target.Selector), nil
target.HitPoints -= cHW.Damage
returnString = fmt.Sprintf("%s caused heavy wounds on %s", wizard.Name, target.Selector)
}
}
if strings.HasSuffix(wizard.Left.Sequence, cHW.Sequence) {
if returnString != "" {
returnString = returnString + "\n"
}
if strings.Contains(target.Wards, "cureHeavyWounds") {
target.HitPoints -= cHW.Damage - 2
returnString += fmt.Sprintf("%s caused heavy wounds on %s but they were protected and only sustained minimal damage", wizard.Name, target.Selector)
} else {
target.HitPoints -= cHW.Damage
returnString += fmt.Sprintf("%s caused heavy wounds on %s", wizard.Name, target.Selector)
}
}

return "", nil
return returnString, nil
}
func GetCauseHeavyWoundsSpell(s *wavinghands.Spell, e error) (*CauseHeavyWounds, error) {
if e != nil {
Expand All @@ -44,7 +56,7 @@ func GetCauseHeavyWoundsSpell(s *wavinghands.Spell, e error) (*CauseHeavyWounds,
Description: s.Description,
Usage: s.Usage,
Damage: s.Damage,
Resistences: s.Resistances,
Resistances: s.Resistances,
Protections: s.Protections,
}, nil
}
42 changes: 32 additions & 10 deletions internal/handler/games/wavinghands/spells/cure-heavy-wounds.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,44 @@ import (
"strings"
)

const HealingPoints = 2

type CureHeavyWounds struct {
Name string `json:"name"`
Sequence string `json:"sequence"`
ShSequence string `json:"sh-sequence"`
Description string `json:"description"`
Usage string `json:"usage"`
Damage int `json:"damage"`
Resistences string `json:"resistences"`
Resistances string `json:"resistances"`
Protections string `json:"protections"`
}

func (cHW CureHeavyWounds) Cast(wizard *wavinghands.Wizard, target *wavinghands.Living) (string, error) {
if (len(wizard.Right.Sequence) >= len(cHW.Sequence) && strings.HasSuffix(wizard.Right.Sequence, cHW.Sequence)) ||
(len(wizard.Left.Sequence) >= len(cHW.Sequence) && strings.HasSuffix(wizard.Left.Sequence, cHW.ShSequence)) {
func (cHW *CureHeavyWounds) Cast(wizard *wavinghands.Wizard, target *wavinghands.Living) (string, error) {
var returnString string = ""
if strings.HasSuffix(wizard.Right.Sequence, cHW.Sequence) {
wards := strings.Split(target.Wards, ",")
wards = append(wards, "cureHeavyWounds") // Lasts one round
target.Wards = strings.Join(wards, ",")

return fmt.Sprintf("%s has cast Cure Heavy Wounds on %s", wizard.Name, target.Selector), nil
returnString += fmt.Sprintf("%s has cast Cure Heavy Wounds on %s", wizard.Name, target.Selector)
}
if strings.HasSuffix(wizard.Left.Sequence, cHW.Sequence) {
if returnString != "" {
returnString += "\n"
}
wards := strings.Split(target.Wards, ",")
wards = append(wards, "cureHeavyWounds") // Lasts one round
target.Wards = strings.Join(wards, ",")

return "", nil
target.HitPoints += HealingPoints
if target.HitPoints > wavinghands.MaxWhHp {
target.HitPoints = wavinghands.MaxWhHp
}
returnString += fmt.Sprintf("%s has cast Cure Heavy Wounds on %s", wizard.Name, target.Selector)
}

return returnString, nil
}

func GetCureHeavyWoundsSpell(s *wavinghands.Spell, e error) (*CureHeavyWounds, error) {
Expand All @@ -43,15 +59,21 @@ func GetCureHeavyWoundsSpell(s *wavinghands.Spell, e error) (*CureHeavyWounds, e
Description: s.Description,
Usage: s.Usage,
Damage: s.Damage,
Resistences: s.Resistances,
Resistances: s.Resistances,
Protections: s.Protections,
}, nil
}

func (cHW CureHeavyWounds) clear(target *wavinghands.Living) error {
func (cHW CureHeavyWounds) Clear(target *wavinghands.Living) error {
wards := strings.Split(target.Wards, ",")
idx := slices.Index(wards, "cureHeavyWounds")
wavinghands.Remove(wards, idx)
target.Wards = strings.Join(wards, ",")
if idx >= 0 {
wavinghands.Remove(wards, idx)
}
if len(wards) > 0 {
target.Wards = strings.Join(wards, ",")
} else {
target.Wards = ""
}
return nil
}
61 changes: 61 additions & 0 deletions internal/handler/games/wavinghands/spells/missile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package spells

import (
"fmt"
"github.com/pyrousnet/pyrous-gobot/internal/handler/games/wavinghands"
"strings"
)

type Missile struct {
Name string `json:"name"`
Sequence string `json:"sequence"`
ShSequence string `json:"sh-sequence"`
Description string `json:"description"`
Usage string `json:"usage"`
Damage int `json:"damage"`
Resistances string `json:"resistances"`
Protections string `json:"protections"`
}

func (m *Missile) Cast(wizard *wavinghands.Wizard, target *wavinghands.Living) (string, error) {
var returnString string = ""
if strings.HasSuffix(wizard.Right.Sequence, m.Sequence) {

if strings.Contains(target.Wards, "shield") {
returnString += fmt.Sprintf("%s cast a missile at %s but they were protected by a shield and took no damage", wizard.Name, target.Selector)
} else {
target.HitPoints -= m.Damage
returnString += fmt.Sprintf("%s cast a missile at %s", wizard.Name, target.Selector)
}
}
if strings.HasSuffix(wizard.Left.Sequence, m.Sequence) {
if returnString != "" {
returnString += "\n"
}
if strings.Contains(target.Wards, "shield") {
returnString += fmt.Sprintf("%s cast a missile at %s but they were protected by a shield and took no damage", wizard.Name, target.Selector)
} else {
target.HitPoints -= m.Damage
returnString += fmt.Sprintf("%s cast a missile at %s", wizard.Name, target.Selector)
}
}

return returnString, nil
}

func GetMissileSpell(s *wavinghands.Spell, e error) (*Missile, error) {
if e != nil {
return &Missile{}, e
}

return &Missile{
Name: s.Name,
Sequence: s.Sequence,
ShSequence: s.ShSequence,
Description: s.Description,
Usage: s.Usage,
Damage: s.Damage,
Resistances: s.Resistances,
Protections: s.Protections,
}, nil
}
77 changes: 77 additions & 0 deletions internal/handler/games/wavinghands/spells/shield.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package spells

import (
"fmt"
"github.com/pyrousnet/pyrous-gobot/internal/handler/games/wavinghands"
"golang.org/x/exp/slices"
"strings"
)

type Shield struct {
Name string `json:"name"`
Sequence string `json:"sequence"`
ShSequence string `json:"sh-sequence"`
Description string `json:"description"`
Usage string `json:"usage"`
Damage int `json:"damage"`
Resistances string `json:"resistances"`
Protections string `json:"protections"`
}

func (s *Shield) Cast(wizard *wavinghands.Wizard, target *wavinghands.Living) (string, error) {
var returnString string
if strings.HasSuffix(wizard.Right.Sequence, s.Sequence) || strings.HasSuffix(wizard.Left.Sequence, s.Sequence) {
wards := strings.Split(target.Wards, ",")
wards = append(wards, "shield")
target.Wards = strings.Join(wards, ",")

returnString = fmt.Sprintf("%s has cast Shield on %s", wizard.Name, target.Selector)
}
return returnString, nil
}

func GetShieldSpell(s *wavinghands.Spell, e error) (*Shield, error) {
if e != nil {
return &Shield{}, e
}

return &Shield{
Name: s.Name,
Sequence: s.Sequence,
ShSequence: s.ShSequence,
Description: s.Description,
Usage: s.Usage,
Damage: s.Damage,
Resistances: s.Resistances,
Protections: s.Protections,
}, nil
}

func (s *Shield) Clear(target *wavinghands.Living) error {
if target.Wards == "" {
return nil
}
wards := strings.Split(target.Wards, ",")
idx := slices.Index(wards, "shield")
if idx >= 0 {
wards = wavinghands.Remove(wards, idx)
}
wards = removeEmptyValues(wards)
if len(wards) > 0 {
target.Wards = strings.Join(wards, ",")
} else {
target.Wards = ""
}
return nil
}

func removeEmptyValues(items []string) []string {
var result []string
for _, str := range items {
if str != "" {
result = append(result, str)
}
}

return result
}
63 changes: 63 additions & 0 deletions internal/handler/games/wavinghands/spells/stab.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package spells

import (
"fmt"
"github.com/pyrousnet/pyrous-gobot/internal/handler/games/wavinghands"
"strings"
)

type Stab struct {
Name string `json:"name"`
Sequence string `json:"sequence"`
ShSequence string `json:"sh-sequence"`
Description string `json:"description"`
Usage string `json:"usage"`
Damage int `json:"damage"`
Resistances string `json:"resistances"`
Protections string `json:"protections"`
}

func (s *Stab) Cast(wizard *wavinghands.Wizard, target *wavinghands.Living) (string, error) {
var returnString string = ""
if strings.HasSuffix(wizard.Right.Sequence, "1") {
wizard.Right.Set(strings.TrimRight(wizard.Right.Sequence, "1"))

if strings.Contains(target.Wards, "shield") {
returnString += fmt.Sprintf("%s tries to stab %s with right hand but they were protected by a shield and took no damage", wizard.Name, target.Selector)
} else {
target.HitPoints -= s.Damage
returnString += fmt.Sprintf("%s stabbed %s with right hand", wizard.Name, target.Selector)
}
}
if strings.HasSuffix(wizard.Left.Sequence, "1") {
wizard.Left.Set(strings.TrimRight(wizard.Left.Sequence, "1"))
if returnString != "" {
returnString += "\n"
}
if strings.Contains(target.Wards, "shield") {
returnString += fmt.Sprintf("%s tries to stab %s with left hand but they were protected by a shield and took no damage", wizard.Name, target.Selector)
} else {
target.HitPoints -= s.Damage
returnString += fmt.Sprintf("%s stabbed %s with left hand", wizard.Name, target.Selector)
}
}

return returnString, nil
}

func GetStabSpell(s *wavinghands.Spell, e error) (*Stab, error) {
if e != nil {
return &Stab{}, e
}

return &Stab{
Name: s.Name,
Sequence: s.Sequence,
ShSequence: s.ShSequence,
Description: s.Description,
Usage: s.Usage,
Damage: s.Damage,
Resistances: s.Resistances,
Protections: s.Protections,
}, nil
}
6 changes: 3 additions & 3 deletions internal/handler/games/wavinghands/spells/surrender.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ type Surrender struct {
Description string `json:"description"`
Usage string `json:"usage"`
Damage int `json:"damage"`
Resistences string `json:"resistences"`
Resistances string `json:"resistances"`
Protections string `json:"protections"`
}

func (s Surrender) Cast(wizard *wavinghands.Wizard, target *wavinghands.Living) (string, error) {
func (s *Surrender) Cast(wizard *wavinghands.Wizard, target *wavinghands.Living) (string, error) {
if strings.HasSuffix(wizard.Right.Sequence, s.Sequence) && strings.HasSuffix(wizard.Left.Sequence, s.ShSequence) {
wizard.Living.HitPoints = 0

Expand All @@ -38,7 +38,7 @@ func GetSurrenderSpell(s *wavinghands.Spell, e error) (*Surrender, error) {
Description: s.Description,
Usage: s.Usage,
Damage: s.Damage,
Resistences: s.Resistances,
Resistances: s.Resistances,
Protections: s.Protections,
}, nil
}
14 changes: 9 additions & 5 deletions internal/handler/games/wavinghands/wavinghands.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import (

const (
minTeams = 2
maxTeams = 6
maxTeams = 2
PREFIX = "wh-"
MaxWhHp = 15
)

type (
Expand Down Expand Up @@ -62,11 +63,14 @@ func (h *Hand) Set(s string) {
h.Sequence = s
}

func (h Hand) Get() []byte {
func (h *Hand) Get() []byte {
return []byte(h.Sequence)
}

func (h Hand) GetAt(index int) byte {
func (h *Hand) GetAt(index int) byte {
if index < 0 {
return ' '
}
return h.Sequence[index]
}

Expand Down Expand Up @@ -107,9 +111,9 @@ func GetHelpSpell(chSp string) string {

var response string
if spell.Name == "" {
response = fmt.Sprintf("/echo %s wasn't a spell.\n", chSp)
response = fmt.Sprintf("%s wasn't a spell.\n", chSp)
} else {
response = fmt.Sprintf("/echo %s is defined as follows:\n```\n", spell.Name)
response = fmt.Sprintf("%s is defined as follows:\n```\n", spell.Name)
response += fmt.Sprintf("Description: %s\n", spell.Description)
response += fmt.Sprintf("Usage: %s\n", spell.Usage)
response += "```\n"
Expand Down
Loading