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

Method userTrashCommand

modules/cleanup/cleanup.go:80–126  ·  view source on GitHub ↗
(rest string, user *users.UserRecord, room *rooms.Room, flags events.EventFlag)

Source from the content-addressed store, hash-verified

78}
79
80func (c *CleanupModule) userTrashCommand(rest string, user *users.UserRecord, room *rooms.Room, flags events.EventFlag) (bool, error) {
81
82 // Check whether the user has an item in their inventory that matches
83 matchItem, found := user.Character.FindInBackpack(rest)
84
85 if !found {
86 user.SendText(fmt.Sprintf(`You don't have a "%s" to trash.`, rest))
87 } else {
88
89 c.loadConfig()
90
91 isSneaking := user.Character.HasBuffFlag(buffs.Hidden)
92
93 user.Character.RemoveItem(matchItem)
94
95 events.AddToQueue(events.ItemOwnership{
96 UserId: user.UserId,
97 Item: matchItem,
98 Gained: false,
99 })
100
101 user.SendText(
102 fmt.Sprintf(`You trash the <ansi fg="item">%s</ansi> for good.`, matchItem.DisplayName()))
103
104 if !isSneaking {
105 room.SendText(
106 fmt.Sprintf(`<ansi fg="username">%s</ansi> destroys <ansi fg="item">%s</ansi>...`, user.Character.Name, matchItem.DisplayName()),
107 user.UserId)
108 }
109
110 if c.DefaultTrashExperienceValue > 0 {
111
112 // Grant experience equal to a tenth of the item value
113 iSpec := matchItem.GetSpec()
114
115 xpGrant := int(float64(iSpec.Value) / 10)
116 if xpGrant < c.DefaultTrashExperienceValue {
117 xpGrant = c.DefaultTrashExperienceValue
118 }
119 user.GrantXP(xpGrant, `trash cleanup`)
120
121 }
122
123 }
124
125 return true, nil
126}
127
128func (c *CleanupModule) mobTrashCommand(rest string, mob *mobs.Mob, room *rooms.Room) (bool, error) {
129

Callers

nothing calls this directly

Calls 9

loadConfigMethod · 0.95
AddToQueueFunction · 0.92
FindInBackpackMethod · 0.45
SendTextMethod · 0.45
HasBuffFlagMethod · 0.45
RemoveItemMethod · 0.45
DisplayNameMethod · 0.45
GetSpecMethod · 0.45
GrantXPMethod · 0.45

Tested by

no test coverage detected