|
@@ -18,14 +18,18 @@ type PlayerMeta struct {
|
18
|
18
|
}
|
19
|
19
|
|
20
|
20
|
type Object struct {
|
21
|
|
- ID DBRef `json:"id"`
|
22
|
|
- Next DBRef `json:"next"`
|
23
|
|
- Type string `json:"type"`
|
24
|
|
- Name string `json:"name"`
|
25
|
|
- Description string `json:"description"`
|
26
|
|
- Flags map[string]string `json:"flags"`
|
27
|
|
- Owner DBRef `json:"owner"`
|
|
21
|
+
|
|
22
|
+ ID DBRef `json:"id"`
|
|
23
|
+ Type string `json:"type"`
|
|
24
|
+ Owner DBRef `json:"owner"`
|
|
25
|
+ Next DBRef `json:"next"`
|
|
26
|
+ Name string `json:"name"`
|
|
27
|
+ Description string `json:"description"`
|
|
28
|
+ Flags map[string]bool `json:"flags"`
|
|
29
|
+ Properties map[string]string `json:"properties"`
|
|
30
|
+
|
28
|
31
|
db *DB
|
|
32
|
+
|
29
|
33
|
}
|
30
|
34
|
|
31
|
35
|
type ObjectFactory struct {
|
|
@@ -103,37 +107,6 @@ func (o *Object) Contains(c *Object) error {
|
103
|
107
|
return o.db.Link(o.ID, c.ID, c.Type)
|
104
|
108
|
}
|
105
|
109
|
|
106
|
|
-func (o *Object) MatchLinkNames(matchName string, player DBRef) ObjectList {
|
107
|
|
- if matchName == "here" {
|
108
|
|
- return ObjectList{*o}
|
109
|
|
- }
|
110
|
|
- if matchName == "me" {
|
111
|
|
- p, found := o.db.Fetch(player)
|
112
|
|
- if !found {
|
113
|
|
- return ObjectList{}
|
114
|
|
- } else {
|
115
|
|
- return ObjectList{p}
|
116
|
|
- }
|
117
|
|
- }
|
118
|
|
- r := make(ObjectList, 0)
|
119
|
|
-
|
120
|
|
- children := o.db.GetChildren(o.ID) // map[DBRef]string
|
121
|
|
-
|
122
|
|
- for childID, _ := range children {
|
123
|
|
- o, found := o.db.Fetch(childID)
|
124
|
|
- if found {
|
125
|
|
- idName := fmt.Sprintf("#%d", o.ID)
|
126
|
|
- lowerObjectName := strings.ToLower(o.Name)
|
127
|
|
- lowerMatchName := strings.ToLower(matchName)
|
128
|
|
- if strings.HasPrefix(lowerObjectName, lowerMatchName) || matchName == idName {
|
129
|
|
- r = append(r, o)
|
130
|
|
- }
|
131
|
|
- }
|
132
|
|
- }
|
133
|
|
-
|
134
|
|
- return r
|
135
|
|
-}
|
136
|
|
-
|
137
|
110
|
func (o *Object) MatchExitNames(name string) ObjectList { // so much copypasta
|
138
|
111
|
r := make(ObjectList, 0)
|
139
|
112
|
|
|
@@ -160,7 +133,6 @@ func (o *Object) MatchExitNames(name string) ObjectList { // so much copypasta
|
160
|
133
|
break // no need to look at other aliases
|
161
|
134
|
}
|
162
|
135
|
}
|
163
|
|
-
|
164
|
136
|
}
|
165
|
137
|
}
|
166
|
138
|
|
|
@@ -168,65 +140,74 @@ func (o *Object) MatchExitNames(name string) ObjectList { // so much copypasta
|
168
|
140
|
}
|
169
|
141
|
|
170
|
142
|
func (o *Object) DetailedName() string {
|
171
|
|
- return fmt.Sprintf("%s (#%d)", o.Name, o.ID)
|
|
143
|
+ return fmt.Sprintf("%s <#%d>", o.Name, o.ID)
|
172
|
144
|
}
|
173
|
145
|
|
174
|
|
-func (o *Object) GetLinkNames(matchType string, exclude DBRefList) []string {
|
|
146
|
+func (o *Object) GetContents(exclude DBRef) []string {
|
175
|
147
|
r := make([]string, 0)
|
176
|
|
-
|
177
|
|
- children := o.db.GetChildren(o.ID) // map[DBRef]string
|
178
|
|
-
|
179
|
|
-childLoop:
|
|
148
|
+ children := o.db.GetChildren(o.ID)
|
180
|
149
|
for childID, linkType := range children {
|
181
|
|
- if matchType != "*" && matchType != linkType {
|
182
|
|
- continue
|
183
|
|
- }
|
184
|
|
- for _, excludeID := range exclude {
|
185
|
|
- if excludeID == childID {
|
186
|
|
- continue childLoop
|
187
|
|
- }
|
188
|
|
- }
|
|
150
|
+ if childID == exclude { continue }
|
|
151
|
+ if !(linkType == "player" || linkType == "thing") { continue }
|
189
|
152
|
o, found := o.db.Fetch(childID)
|
190
|
|
- if found {
|
191
|
|
- if linkType == "player" {
|
192
|
|
- if o.GetFlag("online","false") == "true" {
|
193
|
|
- r = append(r, o.DetailedName())
|
194
|
|
- }
|
195
|
|
- } else if linkType == "exit" {
|
196
|
|
- r = append(r, o.Name)
|
197
|
|
- } else {
|
198
|
|
- r = append(r, o.DetailedName())
|
199
|
|
- }
|
200
|
|
- }
|
|
153
|
+ if !found { continue }
|
|
154
|
+ if linkType == "player" && !o.GetFlag("online") { continue }
|
|
155
|
+ r = append(r, o.DetailedName())
|
201
|
156
|
}
|
|
157
|
+ sort.Strings(r)
|
|
158
|
+ return r
|
|
159
|
+}
|
202
|
160
|
|
|
161
|
+func (o *Object) GetExits() []string {
|
|
162
|
+ r := make([]string, 0)
|
|
163
|
+ children := o.db.GetChildren(o.ID)
|
|
164
|
+ for exitID, linkType := range children {
|
|
165
|
+ if linkType != "exit" { continue }
|
|
166
|
+ exit, found := o.db.Fetch(exitID)
|
|
167
|
+ if !found { continue }
|
|
168
|
+ aliases := strings.Split(exit.Name, ";")
|
|
169
|
+ r = append(r, aliases[0])
|
|
170
|
+ }
|
|
171
|
+
|
203
|
172
|
sort.Strings(r)
|
204
|
173
|
return r
|
205
|
174
|
}
|
206
|
175
|
|
207
|
|
-func (o *Object) SetFlag(flag string, value string) {
|
|
176
|
+func (o *Object) SetFlag(flag string, value bool) {
|
208
|
177
|
if o.Flags == nil {
|
209
|
|
- o.Flags = make(map[string]string)
|
|
178
|
+ o.Flags = make(map[string]bool)
|
210
|
179
|
}
|
211
|
180
|
o.Flags[flag]=value
|
212
|
181
|
}
|
213
|
182
|
|
214
|
|
-func (o *Object) GetFlag(flag string, defaultValue string) (string) {
|
215
|
|
-
|
216
|
|
- if o.Flags == nil {
|
217
|
|
- return defaultValue
|
218
|
|
- }
|
|
183
|
+func (o *Object) GetFlag(flag string) bool {
|
219
|
184
|
|
|
185
|
+ if o.Flags == nil { return false }
|
220
|
186
|
value, ok := o.Flags[flag]
|
|
187
|
+ if !ok { return false }
|
221
|
188
|
|
222
|
|
- if !ok {
|
223
|
|
- return defaultValue
|
|
189
|
+ return value
|
|
190
|
+}
|
|
191
|
+
|
|
192
|
+func (o *Object) SetProp(key string, value string) {
|
|
193
|
+ if o.Properties == nil {
|
|
194
|
+ o.Properties = make(map[string]string)
|
224
|
195
|
}
|
|
196
|
+ o.Properties[key]=value
|
|
197
|
+}
|
|
198
|
+
|
|
199
|
+func (o *Object) GetProp(key string) string {
|
|
200
|
+
|
|
201
|
+ if o.Properties == nil { return "" }
|
|
202
|
+ value, ok := o.Properties[key]
|
|
203
|
+ if !ok { return "" }
|
225
|
204
|
|
226
|
205
|
return value
|
227
|
206
|
}
|
228
|
207
|
|
229
|
208
|
|
|
209
|
+
|
|
210
|
+
|
230
|
211
|
type ObjectList []Object
|
231
|
212
|
|
232
|
213
|
func (l ObjectList) First() Object {
|