forked from evennia/ainneve
-
Notifications
You must be signed in to change notification settings - Fork 0
/
equip_commands.py
256 lines (191 loc) · 5.92 KB
/
equip_commands.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
#
# Commands and cmdsetRelated to the equip handler
#
from evennia import CmdSet, utils
from evennia import Command
class EquipCmdSet(CmdSet):
key = "equip_cmdset"
priority = 2
def at_cmdset_creation(self):
"Populate CmdSet"
self.add(CmdEquip())
self.add(CmdWear())
self.add(CmdWield())
self.add(CmdHold())
self.add(CmdRemove())
class CmdEquip(Command):
"""
equip
Usage:
equip
Show your current equipment.
"""
key = "equip"
aliases = ["eq"]
locks = "cmd:all()"
def func(self):
"check equipment"
caller = self.caller
table = utils.prettytable.PrettyTable(["slot", "item"])
table.header = False
table.border = False
for slot, item in caller.equip:
if not item or not item.access(caller, 'view'):
continue
table.add_row(["{C%s{n" % slot.capitalize(), item.name.capitalize()])
if not str(table):
string = "You have nothing in your equipment."
else:
string = "{wYour equipment:\n%s" % table
self.caller.msg(string)
class CmdWear(Command):
"""
wear
Usage:
wear <obj>
Wear an object.
"""
key = "wear"
locks = "cmd:all()"
wield = False
def func(self):
"implements the command."
caller = self.caller
args = self.args.strip()
wield = self.wield
# reset flag, this should stay at the beginning of the command
if wield:
self.wield = False
if not args:
caller.msg("Wear what?")
return
# this will search for a target
obj = caller.search(args)
if not obj:
return
if not obj in caller.contents:
caller.msg("You don't have %s in your inventory." % obj)
slots = utils.make_iter(obj.db.slot)
if wield:
if not caller.equip.primary_hand in slots \
and not caller.equip.secondary_hand in slots:
caller.msg("You can't wield %s." % obj)
return
# equip primary and secondary hands with the proper feedback
if caller.equip.primary_hand in slots \
or caller.equip.secondary_hand in slots:
action = 'wield'
else:
action = 'wear'
if not obj.db.slot or not obj.access(caller, 'equip'):
caller.msg("You can't equip %s." % obj)
return
if obj in caller.equip.items:
caller.msg("You're already %sing %s." % (action, obj.name))
return
if not caller.equip.add(obj):
string = "You can't equip %s." % obj
if [slot for slot in slots if slot in caller.equip.slots]:
string += " You already have something there."
caller.msg(string)
return
# call hook
if hasattr(obj, "at_equip"):
obj.at_equip(caller)
caller.msg("You %s %s." % (action, obj))
caller.location.msg_contents("%s %ss %s." % (caller.name.capitalize(), action, obj),
exclude=caller)
class CmdWield(Command):
"""
wield
Usage:
wield <obj>
Wield an object.
"""
key = "wield"
locks = "cmd:all()"
def func(self):
"implements the command."
caller = self.caller
args = self.args.strip()
if not args:
caller.msg("Wield what?")
return
cmd = self.cmdset.get("wear")
cmd.wield = True
caller.execute_cmd("wear %s" % args)
class CmdHold(Command):
"""
hold
Usage:
hold <obj>
Hold an object.
"""
key = "hold"
locks = "cmd:all()"
def func(self):
"implements the command."
caller = self.caller
args = self.args.strip()
if not args:
caller.msg("Hold what?")
return
# this will search for a target
obj = caller.search(args)
if not obj:
return
if not obj in caller.contents:
caller.msg("You don't have %s in your inventory." % obj)
return
if not obj.access(caller, 'hold'):
caller.msg("You can't hold %s." % obj)
return
if obj in caller.equip.items:
caller.msg("You're already holding %s." % obj)
return
if not 'holds' in caller.equip.slot:
caller.msg("You can't hold %s." % obj)
return
if caller.equip.get('holds'):
caller.msg("You can't hold %s. You're already holding something.")
return
# call hook
if hasattr(obj, "at_hold"):
obj.at_hold(caller)
# Hold command calls 'set' directly, not 'add'
caller.equip.set('holds', obj)
caller.msg("You hold %s." % obj)
caller.location.msg_contents("%s holds %s." % (caller.name.capitalize(), obj),
exclude=caller)
class CmdRemove(Command):
"""
remove
Usage:
remove <obj>
Remove an object from equip.
"""
key = "remove"
aliases = ["rem"]
locks = "cmd:all()"
def func(self):
"implements the command."
caller = self.caller
args = self.args.strip()
if not args:
caller.msg("Remove what?")
return
# this will search for a target
obj = caller.search(args)
if not obj:
return
if not obj in caller.equip.items:
caller.msg("You are not wearing %s." % obj)
return
if not caller.equip.remove(obj):
return
# call hook
if hasattr(obj, "at_remove"):
obj.at_remove(caller)
caller.msg("You remove %s." % obj)
caller.location.msg_contents("%s removes %s." % (caller.name.capitalize(), obj),
exclude=caller)