2019-07-07 01:56:26 +00:00
|
|
|
package velouremon
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2019-07-08 00:28:06 +00:00
|
|
|
"strings"
|
2019-07-07 01:56:26 +00:00
|
|
|
"math/rand"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/velour/catbase/bot"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Interaction struct {
|
2019-07-08 00:28:06 +00:00
|
|
|
id string
|
2019-07-07 01:56:26 +00:00
|
|
|
players []*Player
|
|
|
|
creatures []*Creature
|
2019-07-08 00:28:06 +00:00
|
|
|
started bool
|
2019-07-07 01:56:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func randomInteraction(c bot.Connector, vp *VelouremonPlugin) {
|
|
|
|
for {
|
|
|
|
<-vp.timer.C
|
|
|
|
if vp.channel != "" {
|
|
|
|
creature := vp.creatures[rand.Intn(len(vp.creatures))]
|
|
|
|
message := fmt.Sprintf("A wild %s appeared.", creature.Name)
|
2019-07-08 00:28:06 +00:00
|
|
|
id, _ := vp.bot.Send(c, bot.Message, vp.channel, message)
|
|
|
|
|
|
|
|
vp.threads[id] = &Interaction {
|
|
|
|
id: id,
|
|
|
|
players: []*Player{},
|
|
|
|
creatures: []*Creature{
|
|
|
|
vp.buildOutCreature(creature),
|
|
|
|
},
|
|
|
|
started: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
vp.bot.Send(c, bot.Reply, vp.channel, "A wild %s appeared.", id)
|
|
|
|
}
|
|
|
|
|
|
|
|
vp.timer.Reset(1 * time.Hour)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *Interaction) handleMessage(vp *VelouremonPlugin, c bot.Connector, player *Player, tokens []string) bool {
|
|
|
|
if len(tokens) > 0 {
|
|
|
|
command := strings.ToLower(tokens[0])
|
|
|
|
if command == "join" {
|
|
|
|
return i.handleJoin(vp, c, player)
|
|
|
|
} else if command == "run" {
|
|
|
|
return i.handleRun(vp, c, player)
|
2019-07-07 01:56:26 +00:00
|
|
|
}
|
2019-07-08 00:28:06 +00:00
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
2019-07-07 01:56:26 +00:00
|
|
|
|
2019-07-08 00:28:06 +00:00
|
|
|
func (i *Interaction) handleJoin(vp *VelouremonPlugin, c bot.Connector, player *Player) bool {
|
|
|
|
for _, p := range i.players {
|
|
|
|
if player == p {
|
|
|
|
vp.bot.Send(c, bot.Reply, vp.channel, player.Name + " is already in the party.", i.id)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
i.players = append(i.players, player)
|
|
|
|
vp.bot.Send(c, bot.Reply, vp.channel, player.Name + " has just joined the party.", i.id)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *Interaction) handleRun(vp *VelouremonPlugin, c bot.Connector, player *Player) bool {
|
|
|
|
for index, p := range i.players {
|
|
|
|
if player == p {
|
|
|
|
i.players = append(i.players[:index], i.players[index+1:]...)
|
|
|
|
vp.bot.Send(c, bot.Reply, vp.channel, player.Name + " has just left the party.", i.id)
|
|
|
|
return true
|
|
|
|
}
|
2019-07-07 01:56:26 +00:00
|
|
|
}
|
2019-07-08 00:28:06 +00:00
|
|
|
vp.bot.Send(c, bot.Reply, vp.channel, player.Name + " is not currently in the party.", i.id)
|
|
|
|
return true
|
2019-07-07 01:56:26 +00:00
|
|
|
}
|