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

Method storageCommand

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

Source from the content-addressed store, hash-verified

277}
278
279func (m *StorageModule) storageCommand(rest string, user *users.UserRecord, room *rooms.Room, flags events.EventFlag) (bool, error) {
280
281 if !roomIsStorage(room) {
282 user.SendText(`You are not at a storage location.` + term.CRLFStr)
283
284 if len(room.Containers) > 0 {
285 cName := ``
286 for k := range room.Containers {
287 cName = k
288 break
289 }
290 user.SendText(fmt.Sprintf(`Maybe you meant to use the <ansi fg="command">put</ansi> command to <ansi fg="command">put</ansi> something into the <ansi fg="container">%s</ansi>?`, cName) + term.CRLFStr)
291 }
292
293 return true, nil
294 }
295
296 data := m.storage[user.UserId]
297 itemsInStorage := data.getItems()
298
299 if rest == `` || rest == `remove` {
300
301 itemNames := []string{}
302 for _, item := range itemsInStorage {
303 itemNames = append(itemNames, item.NameComplex())
304 }
305
306 storageTxt := buildStorageText(itemNames)
307 user.SendText(storageTxt)
308
309 return true, nil
310 }
311
312 if rest == `add` || rest == `remove` {
313 user.SendText(fmt.Sprintf(`%s what?%s`, rest, term.CRLFStr))
314 return true, nil
315 }
316
317 args := util.SplitButRespectQuotes(strings.ToLower(rest))
318
319 if len(args) < 2 || (args[0] != `add` && args[0] != `remove`) {
320 user.SendText(`Try <ansi fg="command">help storage</ansi> for more information about storage.` + term.CRLFStr)
321 return true, nil
322 }
323
324 action := args[0]
325 itemName := strings.Join(args[1:], ` `)
326
327 if action == `add` {
328
329 spaceLeft := maxItems - len(itemsInStorage)
330 if spaceLeft < 1 {
331 user.SendText(fmt.Sprintf(`You can have %d objects in storage`, maxItems))
332 return true, nil
333 }
334
335 if itemName == `all` {
336 for _, itm := range user.Character.GetAllBackpackItems() {

Callers

nothing calls this directly

Calls 15

DisplayNameMethod · 0.95
SplitButRespectQuotesFunction · 0.92
AddToQueueFunction · 0.92
roomIsStorageFunction · 0.85
buildStorageTextFunction · 0.85
getItemsMethod · 0.80
GetAllBackpackItemsMethod · 0.80
addItemMethod · 0.80
findItemMethod · 0.80
removeItemMethod · 0.80
SendTextMethod · 0.45
NameComplexMethod · 0.45

Tested by

no test coverage detected