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

Function Spell

internal/usercommands/admin.spell.go:25–99  ·  view source on GitHub ↗

* * Role Permissions: * spell (All) * spell.create (Create new spells) * spell.list (List all spells) */

(rest string, user *users.UserRecord, room *rooms.Room, flags events.EventFlag)

Source from the content-addressed store, hash-verified

23* spell.list (List all spells)
24 */
25func Spell(rest string, user *users.UserRecord, room *rooms.Room, flags events.EventFlag) (bool, error) {
26
27 args := util.SplitButRespectQuotes(rest)
28
29 if len(args) < 1 {
30 infoOutput, _ := templates.Process("admincommands/help/command.spell", nil, user.UserId)
31 user.SendText(infoOutput)
32 return true, nil
33 }
34
35 // Create a new spell
36 if args[0] == `create` {
37
38 if !user.HasRolePermission(`spell.create`) {
39 user.SendText(`you do not have <ansi fg="command">spell.create</ansi> permission`)
40 return true, nil
41 }
42
43 return spell_Create(strings.TrimSpace(rest[6:]), user, room, flags)
44 }
45
46 // List existing spells
47 if args[0] == `list` {
48
49 if !user.HasRolePermission(`spell.list`) {
50 user.SendText(`you do not have <ansi fg="command">spell.list</ansi> permission`)
51 return true, nil
52 }
53
54 return spell_List(strings.TrimSpace(rest[4:]), user, room, flags)
55 }
56
57 if args[0] == `give` || args[0] == `take` {
58 if len(args) < 3 {
59 infoOutput, _ := templates.Process("admincommands/help/command.spell", nil, user.UserId)
60 user.SendText(infoOutput)
61 return true, nil
62 }
63
64 targetUser := users.GetByCharacterName(args[1])
65 if targetUser == nil {
66 user.SendText(fmt.Sprintf(`Could not find online user "%s".`, args[1]))
67 return true, nil
68 }
69
70 spellName := strings.Join(args[2:], ` `)
71 spellData := spells.FindSpellByName(spellName)
72 if spellData == nil {
73 user.SendText(fmt.Sprintf(`Could not find spell "%s".`, spellName))
74 return true, nil
75 }
76
77 if args[0] == `give` {
78 if targetUser.Character.HasSpell(spellData.SpellId) {
79 user.SendText(fmt.Sprintf(`%s already knows <ansi fg="spell">%s</ansi>.`, targetUser.Character.Name, spellData.Name))
80 return true, nil
81 }
82 targetUser.Character.LearnSpell(spellData.SpellId)

Callers

nothing calls this directly

Calls 11

SplitButRespectQuotesFunction · 0.92
ProcessFunction · 0.92
GetByCharacterNameFunction · 0.92
FindSpellByNameFunction · 0.92
spell_CreateFunction · 0.85
spell_ListFunction · 0.85
HasRolePermissionMethod · 0.80
SendTextMethod · 0.45
HasSpellMethod · 0.45
LearnSpellMethod · 0.45
UnLearnSpellMethod · 0.45

Tested by

no test coverage detected