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

Method spawnGuide

modules/newbieguide/newbieguide.go:63–132  ·  view source on GitHub ↗
(e events.Event)

Source from the content-addressed store, hash-verified

61}
62
63func (m *newbieGuideModule) spawnGuide(e events.Event) events.ListenerReturn {
64
65 evt := e.(events.RoomChange)
66
67 if evt.UserId == 0 {
68 return events.Continue
69 }
70
71 if evt.ToRoomId < 1 {
72 return events.Continue
73 }
74
75 user := users.GetByUserId(evt.UserId)
76 if user.Character.Level > m.maximumPlayerLevel() {
77 return events.Continue
78 }
79
80 fromRoomOriginal := rooms.GetOriginalRoom(evt.FromRoomId)
81 if fromRoomOriginal >= 900 && fromRoomOriginal <= 999 {
82 return events.Continue
83 }
84
85 toRoomOriginal := rooms.GetOriginalRoom(evt.ToRoomId)
86 if toRoomOriginal >= 900 && toRoomOriginal <= 999 {
87 return events.Continue
88 }
89
90 roundNow := util.GetRoundCount()
91
92 var lastGuideRound uint64 = 0
93 tmpLGR := user.GetTempData(`lastGuideRound`)
94 if tmpLGRUint, ok := tmpLGR.(uint64); ok {
95 lastGuideRound = tmpLGRUint
96 }
97
98 if (roundNow - lastGuideRound) < uint64(configs.GetTimingConfig().SecondsToRounds(300)) {
99 return events.Continue
100 }
101
102 guideMobId := m.guideMobId()
103
104 for _, miid := range user.Character.GetCharmIds() {
105 if testMob := mobs.GetInstance(miid); testMob != nil && testMob.MobId == mobs.MobId(guideMobId) {
106 return events.Continue
107 }
108 }
109
110 room := rooms.LoadRoom(evt.ToRoomId)
111
112 guideMob := mobs.NewMobById(mobs.MobId(guideMobId), 1)
113
114 guideMob.Character.Name = fmt.Sprintf(`%s's Guide`, user.Character.Name)
115
116 room.AddMob(guideMob.InstanceId)
117
118 guideMob.Character.Charm(evt.UserId, characters.CharmPermanent, characters.CharmExpiredDespawn)
119
120 user.Character.TrackCharmed(guideMob.InstanceId, true)

Callers

nothing calls this directly

Calls 15

maximumPlayerLevelMethod · 0.95
guideMobIdMethod · 0.95
GetByUserIdFunction · 0.92
GetOriginalRoomFunction · 0.92
GetRoundCountFunction · 0.92
GetTimingConfigFunction · 0.92
GetInstanceFunction · 0.92
MobIdTypeAlias · 0.92
LoadRoomFunction · 0.92
NewMobByIdFunction · 0.92
SecondsToRoundsMethod · 0.80
GetCharmIdsMethod · 0.80

Tested by

no test coverage detected