MCPcopy Create free account
hub / github.com/GoMudEngine/GoMud / followMobCommand

Method followMobCommand

modules/follow/follow.go:527–632  ·  view source on GitHub ↗
(rest string, mob *mobs.Mob, room *rooms.Room)

Source from the content-addressed store, hash-verified

525}
526
527func (f *FollowModule) followMobCommand(rest string, mob *mobs.Mob, room *rooms.Room) (bool, error) {
528
529 if rest == "" {
530 return true, nil
531 }
532
533 args := util.SplitButRespectQuotes(strings.ToLower(rest))
534
535 followTargetName := args[0]
536 followAction := `follow`
537 followEndRound := uint64(0)
538
539 if rest == `stop` || rest == `lose` {
540 followAction = rest
541 followTargetName = ``
542 }
543
544 gd := gametime.GetDate(util.GetRoundCount())
545
546 if len(args) > 1 {
547 followEndRound = gd.AddPeriod(strings.Join(args[1:], ` `))
548 } else if followPeriod, ok := f.plug.Config.Get(`DefaultFollowPeriod`).(string); ok {
549 followEndRound = gd.AddPeriod(followPeriod)
550 }
551
552 // in case something went wrong, we still want to cap it.
553 if followEndRound <= util.GetRoundCount() {
554 followEndRound = gd.AddPeriod(`5 real minutes`)
555 }
556
557 userId, mobInstId := 0, 0
558 if len(followTargetName) > 0 {
559 userId, mobInstId = room.FindByName(followTargetName)
560 }
561
562 followCommandTarget := followId{userId: userId, mobInstanceId: mobInstId}
563 followCommandSource := followId{mobInstanceId: mob.InstanceId}
564
565 if followCommandTarget.mobInstanceId == followCommandSource.mobInstanceId {
566 return true, nil
567 }
568
569 // Lose any followers
570 if followAction == `lose` {
571
572 if lostFollowers := f.loseFollowers(followCommandSource); len(lostFollowers) > 0 {
573
574 // Tell all the followers they
575 for _, fId := range lostFollowers {
576 if fId.userId == 0 {
577 continue
578 }
579
580 if followerUser := users.GetByUserId(fId.userId); followerUser != nil {
581 followerUser.SendText(fmt.Sprintf(`You are no longer following <ansi fg="mobname">%s</ansi>.`, mob.Character.Name))
582 }
583 }
584

Callers

nothing calls this directly

Calls 12

loseFollowersMethod · 0.95
stopFollowingMethod · 0.95
startFollowMethod · 0.95
SplitButRespectQuotesFunction · 0.92
GetDateFunction · 0.92
GetRoundCountFunction · 0.92
GetByUserIdFunction · 0.92
AddPeriodMethod · 0.80
FindByNameMethod · 0.80
GetMethod · 0.45
SendTextMethod · 0.45
ClearMethod · 0.45

Tested by

no test coverage detected