The command function definition has changed over time as we gain experience in how we actually use it vs. the original ideation. This is another step in simplicity.
Commands accept an argument (userId int or mobInstanceId int) which defines who is invoking the command. As a result every command function must do a lookup of the userId or mobInstanceId as well as validate it (make sure it's not null), which is a lot of redundant code. Originally it was thought that not all commands would need access to the user object. This is true, but not true very often. So, to simplify we will just pass the user/mob object pointer to the function instead of their identifier.
Additionally updated to pass a pointer to the Room object to the command for the same reasons.
Changes
Improved messaging of character command menu/responses.
type UserCommand func(rest string, userId int) (bool, error)
changed to type UserCommand func(rest string, user *users.UserRecord, room *rooms.Room) (bool, error)
Lots of redundant user := users.GetByUserId(userId) removed as a result
Lots of redundant room := rooms.LoadRoom(user.Character.RoomId) removed as a result
type MobCommand func(rest string, mobId int) (bool, error)
changed to type UserCommand func(rest string, mob *mobs.Mob, room *rooms.Room) (bool, error)
Lots of redundant mob := mobs.GetInstance(mobId) removed as a result
Lots of redundant room := rooms.LoadRoom(mob.Character.RoomId) removed as a result
Motivation
The command function definition has changed over time as we gain experience in how we actually use it vs. the original ideation. This is another step in simplicity.
Commands accept an argument (
userId int
ormobInstanceId int
) which defines who is invoking the command. As a result every command function must do a lookup of the userId or mobInstanceId as well as validate it (make sure it's not null), which is a lot of redundant code. Originally it was thought that not all commands would need access to the user object. This is true, but not true very often. So, to simplify we will just pass the user/mob object pointer to the function instead of their identifier.Additionally updated to pass a pointer to the
Room
object to the command for the same reasons.Changes
character
command menu/responses.type UserCommand func(rest string, userId int) (bool, error)
type UserCommand func(rest string, user *users.UserRecord, room *rooms.Room) (bool, error)
user := users.GetByUserId(userId)
removed as a resultroom := rooms.LoadRoom(user.Character.RoomId)
removed as a resulttype MobCommand func(rest string, mobId int) (bool, error)
type UserCommand func(rest string, mob *mobs.Mob, room *rooms.Room) (bool, error)
mob := mobs.GetInstance(mobId)
removed as a resultroom := rooms.LoadRoom(mob.Character.RoomId)
removed as a result