Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 0 additions & 1 deletion _datafiles/world/default/keywords.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ help:
- online
- quit
parties:
- follow
- party
- share
locks:
Expand Down
1 change: 0 additions & 1 deletion _datafiles/world/empty/keywords.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ help:
- online
- quit
parties:
- follow
- party
- share
locks:
Expand Down
9 changes: 0 additions & 9 deletions _datafiles/world/empty/templates/help/follow.template

This file was deleted.

9 changes: 0 additions & 9 deletions internal/characters/character.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ type Character struct {
roomHistory []int // A stack FILO of the last X rooms the character has been in
PlayerDamage map[int]int `yaml:"-"` // key = who, value = how much
LastPlayerDamage uint64 `yaml:"-"` // last round a player damaged this character
followers []int // everyone following this user
permaBuffIds []int // Buff Id's that are always present for this character
userId int // User ID of the character if any
}
Expand Down Expand Up @@ -532,10 +531,6 @@ func (c *Character) GetRandomItem() (items.Item, bool) {
return c.Items[util.Rand(len(c.Items))], true
}

func (c *Character) AddFollower(uId int) {
c.followers = append(c.followers, uId)
}

// USERNAME appears to be <BLANK>
func (c *Character) GetHealthAppearance() string {

Expand All @@ -561,10 +556,6 @@ func (c *Character) GetHealthAppearance() string {
return fmt.Sprintf(`<ansi fg="username">%s</ansi> is in <ansi fg="%s">perfect health.</ansi>`, c.Name, className)
}

func (c *Character) GetFollowers() []int {
return append([]int{}, c.followers...)
}

func (c *Character) GetAllSkillRanks() map[string]int {
retMap := make(map[string]int)
for skillName, skillLevel := range c.Skills {
Expand Down
9 changes: 9 additions & 0 deletions internal/events/eventtypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,13 @@ type NewTurn struct {

func (n NewTurn) Type() string { return `NewTurn` }

// Anytime a mob is idle
type MobIdle struct {
MobInstanceId int
}

func (i MobIdle) Type() string { return `MobIdle` }

// Gained or lost an item
type EquipmentChange struct {
UserId int
Expand Down Expand Up @@ -339,6 +346,8 @@ type Party struct {
Position map[int]string
}

func (p Party) Type() string { return `Party` }

type RedrawPrompt struct {
UserId int
OnlyIfChanged bool
Expand Down
10 changes: 5 additions & 5 deletions internal/events/listeners.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,16 @@ func RegisterListener(emptyEvent any, cbFunc Listener, qFlag ...QueueFlag) Liste
} else if listenerDetails.isFinal {
eventListeners[eType] = append(eventListeners[eType], listenerDetails)

} else {
} else { // end of the list, but before any "final" listeners

insertPosition := 0
for idx := 0; idx < len(eventListeners[eType]); idx++ {

for idx := len(eventListeners[eType]) - 1; idx >= 0; idx-- {
// If we're looking at a "final" listener, we can't go any farther down the list
if !eventListeners[eType][idx].isFinal {
insertPosition = idx
continue
insertPosition = idx + 1
break
}
break
}

eventListeners[eType] = append(eventListeners[eType], ListenerWrapper{})
Expand Down
73 changes: 73 additions & 0 deletions internal/hooks/MobIdle_HandleIdleMobs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package hooks

import (
"github.com/GoMudEngine/GoMud/internal/configs"
"github.com/GoMudEngine/GoMud/internal/events"
"github.com/GoMudEngine/GoMud/internal/mobcommands"
"github.com/GoMudEngine/GoMud/internal/mobs"
"github.com/GoMudEngine/GoMud/internal/rooms"
"github.com/GoMudEngine/GoMud/internal/scripting"
"github.com/GoMudEngine/GoMud/internal/util"
)

//
// Handles default mob idle behavior
//

func HandleIdleMobs(e events.Event) events.ListenerReturn {

evt := e.(events.MobIdle)

mob := mobs.GetInstance(evt.MobInstanceId)
if mob == nil {
return events.Cancel
}

// if a mob shouldn't be allowed to leave their area (via wandering)
// but has somehow been displaced, such as pulling through combat, spells, or otherwise
// tell them to path back home
if mob.MaxWander == 0 && mob.Character.RoomId != mob.HomeRoomId {
mob.Command("pathto home")
}

if mob.CanConverse() && util.Rand(100) < int(configs.GetGamePlayConfig().MobConverseChance) {
if mobRoom := rooms.LoadRoom(mob.Character.RoomId); mobRoom != nil {
mobcommands.Converse(``, mob, mobRoom) // Execute this directly so that target mob doesn't leave the room before this command executes
}
}

// If they have idle commands, maybe do one of them?
handled, _ := scripting.TryMobScriptEvent("onIdle", mob.InstanceId, 0, ``, nil)
if !handled {

if !mob.Character.IsCharmed() { // Won't do this stuff if befriended

if mob.MaxWander > -1 && mob.WanderCount > mob.MaxWander {
mob.Command(`pathto home`)
}

}

//
// Look for trouble
//
if mob.Character.IsCharmed() {
// Only some mobs can apply first aid
if mob.Character.KnowsFirstAid() {
mob.Command(`lookforaid`)
}
} else {

idleCmd := `lookfortrouble`
if util.Rand(100) < mob.ActivityLevel {
idleCmd = mob.GetIdleCommand()
if idleCmd == `` {
idleCmd = `lookfortrouble`
}
}
mob.Command(idleCmd)
}
}

return events.Continue
}
54 changes: 1 addition & 53 deletions internal/hooks/NewRound_IdleMobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import (

"github.com/GoMudEngine/GoMud/internal/configs"
"github.com/GoMudEngine/GoMud/internal/events"
"github.com/GoMudEngine/GoMud/internal/mobcommands"
"github.com/GoMudEngine/GoMud/internal/mobs"
"github.com/GoMudEngine/GoMud/internal/rooms"
"github.com/GoMudEngine/GoMud/internal/scripting"
"github.com/GoMudEngine/GoMud/internal/users"
"github.com/GoMudEngine/GoMud/internal/util"
)
Expand All @@ -25,10 +23,8 @@ func IdleMobs(e events.Event) events.ListenerReturn {
mobPathAnnounce := false // useful for debugging purposes.

mc := configs.GetMemoryConfig()
gp := configs.GetGamePlayConfig()

maxBoredom := uint8(mc.MaxMobBoredom)
globalConverseChance := int(gp.MobConverseChance)

allMobInstances := mobs.GetAllMobInstanceIds()

Expand Down Expand Up @@ -143,55 +139,7 @@ func IdleMobs(e events.Event) events.ListenerReturn {
mob.Path.Clear()
}

// if a mob shouldn't be allowed to leave their area (via wandering)
// but has somehow been displaced, such as pulling through combat, spells, or otherwise
// tell them to path back home
if mob.MaxWander == 0 && mob.Character.RoomId != mob.HomeRoomId {
mob.Command("pathto home")
continue
}

if mob.CanConverse() && util.Rand(100) < globalConverseChance {
if mobRoom := rooms.LoadRoom(mob.Character.RoomId); mobRoom != nil {
mobcommands.Converse(``, mob, mobRoom) // Execute this directly so that target mob doesn't leave the room before this command executes
//mob.Command(`converse`)
}
continue
}

// If they have idle commands, maybe do one of them?
handled, _ := scripting.TryMobScriptEvent("onIdle", mob.InstanceId, 0, ``, nil)
if !handled {

if !mob.Character.IsCharmed() { // Won't do this stuff if befriended

if mob.MaxWander > -1 && mob.WanderCount > mob.MaxWander {
mob.Command(`pathto home`)
continue
}

}

//
// Look for trouble
//
if mob.Character.IsCharmed() {
// Only some mobs can apply first aid
if mob.Character.KnowsFirstAid() {
mob.Command(`lookforaid`)
}
} else {

idleCmd := `lookfortrouble`
if util.Rand(100) < mob.ActivityLevel {
idleCmd = mob.GetIdleCommand()
if idleCmd == `` {
idleCmd = `lookfortrouble`
}
}
mob.Command(idleCmd)
}
}
events.AddToQueue(events.MobIdle{MobInstanceId: mobId})

}

Expand Down
1 change: 1 addition & 0 deletions internal/hooks/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func RegisterListeners() {
//
events.RegisterListener(events.NewRound{}, AutoHeal)
events.RegisterListener(events.NewRound{}, IdleMobs)
events.RegisterListener(events.MobIdle{}, HandleIdleMobs)

// Turn Hooks
events.RegisterListener(events.NewTurn{}, CleanupZombies)
Expand Down
18 changes: 18 additions & 0 deletions internal/mobcommands/mobcommands.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,24 @@ func TryCommand(cmd string, rest string, mobId int) (bool, error) {
}
*/

if alias := keywords.TryCommandAlias(cmd); alias != cmd {
// If it's a multi-word aliase, we need to extract the first word to replace the command
// The rest will be combined with any "rest" the mob provided.
if strings.Contains(alias, ` `) {
parts := strings.Split(alias, ` `)
// grab the first word as the new cmd
cmd = parts[0]
// Add the "rest" to the end if any
if len(rest) > 0 {
rest = strings.TrimPrefix(alias, cmd+` `) + ` ` + rest
} else {
rest = strings.TrimPrefix(alias, cmd+` `)
}
} else {
cmd = alias
}
}

if cmdInfo, ok := mobCommands[cmd]; ok {
if mobDisabled && !cmdInfo.AllowedWhenDowned {

Expand Down
46 changes: 0 additions & 46 deletions internal/usercommands/follow.go

This file was deleted.

25 changes: 20 additions & 5 deletions internal/usercommands/usercommands.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ var (
`experience`: {Experience, true, false},
`equip`: {Equip, false, false},
`flee`: {Flee, false, false},
`follow`: {Follow, false, false},
`gearup`: {Gearup, false, false},
`get`: {Get, false, false},
`give`: {Give, false, false},
Expand Down Expand Up @@ -283,20 +282,36 @@ func TryCommand(cmd string, rest string, userId int, flags events.EventFlag) (bo
} else {

if alias := user.TryCommandAlias(cmd); alias != cmd {
// If it's a multi-word aliase, we need to extract the first word to replace the command
// The rest will be combined with any "rest" the player provided.
if strings.Contains(alias, ` `) {
parts := strings.Split(alias, ` `)
cmd = parts[0] // grab the first word as the new cmd
rest = strings.TrimPrefix(alias, cmd+` `) + ` ` + rest // add the remaining alias to the rest
// grab the first word as the new cmd
cmd = parts[0]
// Add the "rest" to the end if any
if len(rest) > 0 {
rest = strings.TrimPrefix(alias, cmd+` `) + ` ` + rest
} else {
rest = strings.TrimPrefix(alias, cmd+` `)
}
} else {
cmd = alias
}
}

if alias := keywords.TryCommandAlias(cmd); alias != cmd {
// If it's a multi-word aliase, we need to extract the first word to replace the command
// The rest will be combined with any "rest" the player provided.
if strings.Contains(alias, ` `) {
parts := strings.Split(alias, ` `)
cmd = parts[0] // grab the first word as the new cmd
rest = strings.TrimPrefix(alias, cmd+` `) + ` ` + rest // add the remaining alias to the rest
// grab the first word as the new cmd
cmd = parts[0]
// Add the "rest" to the end if any
if len(rest) > 0 {
rest = strings.TrimPrefix(alias, cmd+` `) + ` ` + rest
} else {
rest = strings.TrimPrefix(alias, cmd+` `)
}
} else {
cmd = alias
}
Expand Down
7 changes: 7 additions & 0 deletions modules/follow/files/data-overlays/keywords.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
help:
command:
parties:
- follow
command-aliases:
'follow stop': ['unfollow']
'follow lose': ['lose']
Loading