-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsocedit.py
More file actions
210 lines (195 loc) · 6.78 KB
/
socedit.py
File metadata and controls
210 lines (195 loc) · 6.78 KB
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
"""
socedit is a set of tools for editing socials online. Socedit requires that
olc2 be installed.
"""
import olc
from enum import Enum
from mudsys import cmd_exists, add_cmd
class Socedit(Enum):
"""
Enumeration class for holding the menu selections for the OLC social
editor.
"""
char_notgt = 1
room_notgt = 2
char_self = 3
room_self = 4
char_tgt = 5
vict_tgt = 6
room_tgt = 7
adverb = 8
adjective = 9
require_tgt = 10
min_pos = 11
max_pos = 12
class Position(Enum):
none = -1
unconscious = 0
sleeping = 1
sitting = 2
standing = 3
flying = 4
def getMembers(self):
return Position.__members__
def socedit_menu(sock, social):
"""
Creates the menu for the OLC for social editing.
:param sock: the player socket editing the social
:param social: the name of the social editing
:return: None
"""
sock.send("{y[{c%s{y]\r\n"
"{g 1) to char notgt: {c%s\r\n"
"{g 2) to room notgt: {c%s\r\n"
"{g 3) to char self : {c%s\r\n"
"{g 4) to room self : {c%s\r\n"
"{g 5) to char tgt : {c%s\r\n"
"{g 6) to vict tgt : {c%s\r\n"
"{g 7) to room tgt : {c%s\r\n"
"{g 8) default adv : {c%s\r\n"
"{g 9) default adj : {c%s\r\n"
"{g10) require tgt : {c%s\r\n"
"{g11) minimum pos : {c%s\r\n"
"{g12) maximum pos : {c%s\r\n"
"\r\n"
"{gTo assocciate/unassociate commands, use soclink and socunlink"
% ( social.get_cmds(), social.get_to_char_notgt(), social.get_to_room_notgt(),
social.get_to_char_self(), social.get_to_room_self(), social.get_to_char_tgt(),
social.get_to_vict_tgt(), social.get_to_room_tgt(), social.get_adverb(),
social.get_adjective(), social.get_require_tgt(), social.get_min_pos(),
social.get_max_pos()))
def socedit_chooser(sock, social, option):
if option == '1':
sock.send(
"The message to character when no target is supplied : ")
return Socedit.char_notgt.value
elif option == '2':
sock.send(
"The message to room when no target is supplied : ")
return Socedit.room_notgt.value
elif option == '3':
sock.send(
"The message to character when target is self : ")
return Socedit.char_self.value
elif option == '4':
sock.send(
"The message to room when target is self : ")
return Socedit.room_self.value
elif option == '5':
sock.send(
"The message to character when a target is found : ")
return Socedit.char_tgt.value
elif option == '6':
sock.send(
"The message to target when a target is found : ")
return Socedit.vict_tgt.value
elif option == '7':
sock.send(
"The message to room when a target is found : ")
return Socedit.room_tgt.value
elif option == '8':
sock.send(
"The default adverb for this social (replaces $M): ")
return Socedit.adverb.value
elif option == '9':
sock.send(
"The default adjective for this social (replaces $m): ")
return Socedit.adjective.value
elif option == '10':
sock.send(
"Whether this social requires a target when used (1=yes, 2=no): ")
return Socedit.require_tgt.value
elif option == '11':
sock.send("{gValid Positions:")
for name, member in Position.__members__.items():
sock.send(" {c%2d{y) {g%-15s" % (member.value, name))
sock.send("Pick a minimum position: ")
return Socedit.min_pos.value
elif option == '12':
sock.send("{gValid Positions:")
for name, member in Position.__members__.items():
sock.send(" {c%2d{y) {g%-15s" % (member.value, name))
sock.send("Pick a maximum position: ")
return Socedit.max_pos.value
else:
return -1
def socedit_parser(sock, social, choice, arg):
if int(choice) == 1:
social.set_to_char_notgt(arg)
return True
elif choice == Socedit.room_notgt.value:
social.set_to_room_notgt(arg)
return True
elif choice == Socedit.char_self.value:
social.set_to_char_self(arg)
return True
elif choice == Socedit.room_self.value:
social.set_to_room_self(arg)
return True
elif choice == Socedit.char_tgt.value:
social.set_to_char_tgt(arg)
return True
elif choice == Socedit.vict_tgt.value:
social.set_to_vict_tgt(arg)
return True
elif choice == Socedit.room_tgt.value:
social.set_to_room_tgt(arg)
return True
elif choice == Socedit.adverb.value:
social.set_adverb(arg)
return True
elif choice == Socedit.adjective.value:
social.set_adjective(arg)
return True
elif choice == Socedit.require_tgt.value:
if arg == "1" or arg == "0":
social.set_require_tgt(arg)
return True
return False
elif choice == Socedit.min_pos.value:
try:
val = int(arg)
except:
return False
x = social.set_min_pos(val)
if x == val:
return True
return False
elif choice == Socedit.max_pos.value:
try:
val = int(arg)
except:
return False
x = social.set_max_pos(val) # Fixed: was set_min_pos
if x == val:
return True
return False
else:
return False
def cmd_socedit(ch, cmd, arg):
"""
This starts the social editor olc process, allowing you to edit or create new socials
for the mud. The minimum permissions required for this is builder.
syntax: socedit <social name>
"""
from .socials import add_social, save_social, get_social, Social
if arg == '' or arg is None:
ch.send("Which social are you trying to edit?")
return
else:
# strip down to one argument
arg = arg.split(" ",1)[0]
# find the social
social = get_social(arg)
# make sure we're not trying to edit a command
if social is None and cmd_exists(arg):
ch.send("A command already exists with that name!\r\n")
else:
if social is None:
ch.send("Social doesn't exist. Creating new social.")
social = Social(cmds=arg, to_char_notgt="You emote $M.", to_room_notgt="$n emotes $M.",
adverb="smartly", min_pos="sitting", max_pos="flying")
add_social(social)
ch.send("%s" % social.get_cmds())
olc.do_olc(ch.sock, socedit_menu, socedit_chooser, socedit_parser, save_social, social)
add_cmd("socedit", None, cmd_socedit, "player", False)