108 lines
3.2 KiB
Go
108 lines
3.2 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"git.sunturtle.xyz/zephyr/horse/horse"
|
|
"github.com/disgoorg/disgo/discord"
|
|
)
|
|
|
|
func RenderSkill(s horse.Skill) discord.ContainerComponent {
|
|
skilltype := discord.TextDisplayComponent{
|
|
ID: 4,
|
|
Content: "Skill Issue",
|
|
}
|
|
r := discord.ContainerComponent{
|
|
ID: 1, // specify ids so we guarantee we don't get collisions with related skill buttons
|
|
Components: []discord.ContainerSubComponent{
|
|
discord.SectionComponent{
|
|
ID: 2,
|
|
Components: []discord.SectionSubComponent{
|
|
discord.TextDisplayComponent{
|
|
ID: 3,
|
|
Content: "## " + s.Name + "\n" + s.Description,
|
|
},
|
|
&skilltype, // doing something evil :)
|
|
},
|
|
Accessory: discord.NewThumbnail(fmt.Sprintf("https://gametora.com/images/umamusume/skill_icons/utx_ico_skill_%d.png", s.IconID)),
|
|
},
|
|
},
|
|
}
|
|
switch {
|
|
case s.Rarity == 3, s.Rarity == 4, s.Rarity == 5:
|
|
// unique of various star levels
|
|
r.AccentColor = 0xaca4d4
|
|
skilltype.Content = "Unique Skill"
|
|
case s.Rarity == 2:
|
|
// rare (gold)
|
|
r.AccentColor = 0xd7c25b
|
|
skilltype.Content = "Rare Skill"
|
|
case s.GroupRate == -1:
|
|
// negative (purple) skill
|
|
r.AccentColor = 0x9151d4
|
|
skilltype.Content = "Negative Skill"
|
|
case !s.WitCheck:
|
|
// should be passive (green)
|
|
r.AccentColor = 0x66ae1c
|
|
skilltype.Content = "Passive Skill"
|
|
// TODO(zeph): debuff (red)
|
|
case s.Rarity == 1:
|
|
// common (white)
|
|
r.AccentColor = 0xcccccc
|
|
skilltype.Content = "Common Skill"
|
|
}
|
|
r.Components = append(r.Components, discord.SeparatorComponent{ID: 5, Spacing: discord.SeparatorSpacingSizeSmall})
|
|
text := make([]string, 0, 3)
|
|
abils := make([]string, 0, 3)
|
|
for i, act := range s.Activations {
|
|
text, abils = text[:0], abils[:0]
|
|
if act.Precondition != "" {
|
|
text = append(text, "Precondition: "+formatCondition(act.Precondition))
|
|
}
|
|
text = append(text, "Condition: "+formatCondition(act.Condition))
|
|
var t string
|
|
switch {
|
|
case act.Duration < 0:
|
|
// passive; do nothing
|
|
case act.Duration == 0:
|
|
t = "Instantaneous "
|
|
case act.Duration >= 500e4:
|
|
t = "Permanent "
|
|
default:
|
|
t = act.Duration.String() + "s "
|
|
}
|
|
for _, a := range act.Abilities {
|
|
abils = append(abils, a.String())
|
|
}
|
|
t += strings.Join(abils, ", ")
|
|
if act.Cooldown < 500e4 {
|
|
t += " on " + act.Cooldown.String() + "s cooldown"
|
|
}
|
|
text = append(text, t)
|
|
r.Components = append(r.Components, discord.TextDisplayComponent{
|
|
ID: 10 + i,
|
|
Content: strings.Join(text, "\n"),
|
|
})
|
|
}
|
|
r.Components = append(r.Components, discord.SeparatorComponent{ID: 50, Spacing: discord.SeparatorSpacingSizeSmall})
|
|
r.Components = append(r.Components, discord.TextDisplayComponent{
|
|
ID: 51,
|
|
Content: fmt.Sprintf("SP cost %d. Grade value %d.", s.SPCost, s.GradeValue),
|
|
})
|
|
// TODO(zeph): related skills, use a row of buttons with skill numbers for the ids and edit the message when clicked?
|
|
return r
|
|
}
|
|
|
|
func formatCondition(s string) string {
|
|
s = strings.ReplaceAll(s, "&", " & ")
|
|
if strings.ContainsRune(s, '@') {
|
|
return "```\n" + strings.ReplaceAll(s, "@", "\n@\n") + "```"
|
|
}
|
|
return "`" + s + "`"
|
|
}
|
|
|
|
// TODO(zeph): autocomplete
|
|
// if we want to backgroundify construction of an autocomplete map,
|
|
// use sync.OnceValue and launch a goroutine in main to get the value and discard it
|