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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
|
/* */ package NET.worlds.scape;
/* */
/* */ import NET.worlds.console.ActionsPart;
/* */ import NET.worlds.console.Console;
/* */ import NET.worlds.console.TradeDialog;
/* */ import NET.worlds.console.WhisperManager;
/* */ import NET.worlds.core.ServerTableManager;
/* */ import NET.worlds.network.URL;
/* */ import java.io.PrintStream;
/* */ import java.net.MalformedURLException;
/* */ import java.util.Enumeration;
/* */ import java.util.Hashtable;
/* */ import java.util.Vector;
/* */
/* */
/* */
/* */
/* */
/* */ public class InventoryManager
/* */ {
/* */ private static InventoryManager manager_;
/* */ private Hashtable<String, InventoryItem> masterList_;
/* */ private Hashtable<String, InventoryItem> inventory_;
/* */ private boolean initialized_;
/* */ private Vector<InventoryItem> equipped_;
/* */
/* */ public synchronized void setEquippedItems(Vector<InventoryItem> equippedItems)
/* */ {
/* 29 */ removeEquippedItems();
/* 30 */ this.equipped_ = equippedItems;
/* 31 */ equipItems();
/* */ }
/* */
/* */ public synchronized Vector<InventoryItem> getEquippedItems() {
/* 35 */ return this.equipped_;
/* */ }
/* */
/* */ private synchronized void removeEquippedItems() {
/* 39 */ for (int i = 0; i < this.equipped_.size(); i++) {
/* 40 */ EquippableItem itemToEquip =
/* 41 */ (EquippableItem)this.equipped_.elementAt(i);
/* 42 */ Shape ownedShape = itemToEquip.getOwnedShape();
/* 43 */ if (ownedShape != null) {
/* 44 */ ownedShape.detach();
/* */ }
/* 46 */ itemToEquip.setOwnedShape(null);
/* */ }
/* */ }
/* */
/* */ private synchronized void equipItems() {
/* 51 */ System.out.println("Equipped Items Size: " + this.equipped_.size());
/* 52 */ for (int i = 0; i < this.equipped_.size(); i++) {
/* 53 */ Shape itemShape = new Shape();
/* */
/* */
/* */
/* 57 */ EquippableItem itemToEquip =
/* 58 */ (EquippableItem)this.equipped_.elementAt(i);
/* */
/* 60 */ if (itemToEquip != null) {
/* */ try {
/* 62 */ itemShape.setURL(new URL(itemToEquip.getModelLocation()));
/* */ } catch (MalformedURLException url) {
/* 64 */ System.out.println("Badly formed URL for " +
/* 65 */ itemToEquip.getItemName());
/* 66 */ continue;
/* */ }
/* */
/* 69 */ float s = itemToEquip.getScale();
/* 70 */ itemShape.scale(s, s, s);
/* 71 */ itemShape.pitch(itemToEquip.getPitch());
/* 72 */ itemShape.roll(itemToEquip.getRoll());
/* 73 */ itemShape.yaw(itemToEquip.getYaw());
/* 74 */ itemShape.moveBy(itemToEquip.getXPos(), itemToEquip.getYPos(),
/* 75 */ itemToEquip.getZPos());
/* 76 */ int properLoc = itemToEquip.getBodyLocation();
/* */
/* */
/* 79 */ DeepEnumeration<?> de = new DeepEnumeration();
/* 80 */ Pilot.getActive().getChildren(de);
/* */
/* 82 */ while (de.hasMoreElements()) {
/* 83 */ Object obj = de.nextElement();
/* 84 */ if ((obj instanceof Shape)) {
/* 85 */ Shape objShape = (Shape)obj;
/* 86 */ int partType = objShape.getBodPartNum();
/* 87 */ if (partType == properLoc) {
/* 88 */ objShape.add(itemShape);
/* 89 */ itemToEquip.setOwnedShape(itemShape);
/* 90 */ break;
/* */ }
/* */ }
/* */ }
/* */ }
/* */ }
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */ public Vector<InventoryItem> getEquippableItems()
/* */ {
/* 104 */ Vector<InventoryItem> retVal = new Vector();
/* 105 */ Enumeration<InventoryItem> invEnum = this.inventory_.elements();
/* */
/* */
/* */
/* 109 */ while (invEnum.hasMoreElements()) {
/* 110 */ InventoryItem obj = (InventoryItem)invEnum.nextElement();
/* 111 */ if ((obj instanceof EquippableItem)) {
/* 112 */ retVal.addElement(obj);
/* */ }
/* */ }
/* */
/* */
/* 117 */ return retVal;
/* */ }
/* */
/* */ public Vector<InventoryItem> getInventoryAvatars() {
/* 121 */ Vector<InventoryItem> retVal = new Vector();
/* 122 */ Enumeration<InventoryItem> invEnum = this.inventory_.elements();
/* */
/* */
/* */
/* 126 */ while (invEnum.hasMoreElements()) {
/* 127 */ InventoryItem obj = (InventoryItem)invEnum.nextElement();
/* 128 */ if ((obj instanceof InventoryAvatar)) {
/* 129 */ retVal.addElement(obj);
/* */ }
/* */ }
/* */
/* */
/* 134 */ return retVal;
/* */ }
/* */
/* */ public Hashtable<String, InventoryItem> getInventoryItems() {
/* 138 */ return this.inventory_;
/* */ }
/* */
/* */ public int checkInventoryFor(String nm) {
/* 142 */ InventoryItem it = (InventoryItem)this.inventory_.get(nm);
/* 143 */ if (it != null) {
/* 144 */ return it.getItemQuantity();
/* */ }
/* 146 */ return 0;
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public Vector<InventoryItem> getInventoryActionList()
/* */ {
/* 173 */ Vector<InventoryItem> retVal = new Vector();
/* 174 */ Enumeration<InventoryItem> invEnum = this.inventory_.elements();
/* */
/* */
/* */
/* 178 */ while (invEnum.hasMoreElements()) {
/* 179 */ InventoryItem obj = (InventoryItem)invEnum.nextElement();
/* 180 */ if ((obj instanceof InventoryAction)) {
/* 181 */ retVal.addElement(obj);
/* */ }
/* */ }
/* */
/* */
/* 186 */ return retVal;
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */ public void doInventoryAction(String act)
/* */ {
/* 195 */ Vector<InventoryItem> actVector = getInventoryActionList();
/* 196 */ for (int i = 0; i < actVector.size(); i++) {
/* 197 */ InventoryAction invAct = (InventoryAction)actVector.elementAt(i);
/* */
/* 199 */ if (invAct.getItemName().equalsIgnoreCase(act)) {
/* 200 */ invAct.doAction();
/* 201 */ String msg = "&|+deal>trade " + invAct.getItemId() + ",";
/* 202 */ TradeDialog.sendTradeMessage(msg);
/* */ }
/* */ }
/* */ }
/* */
/* */ public void setInventory(String invString) {
/* 208 */ this.initialized_ = true;
/* 209 */ Hashtable<String, InventoryItem> newInv = parseInventoryString(invString);
/* 210 */ this.inventory_ = newInv;
/* */
/* 212 */ Enumeration<TradeDialog> e = WhisperManager.whisperManager().tradeDialogs()
/* 213 */ .elements(); while (e.hasMoreElements()) {
/* 214 */ TradeDialog wd = (TradeDialog)e.nextElement();
/* 215 */ wd.setTrading(true);
/* */ }
/* */
/* */
/* 219 */ if (Console.getActive() != null) {
/* 220 */ Console a = Console.getActive();
/* */
/* 222 */ a.inventoryChanged();
/* */
/* */
/* 225 */ if (a.targetValid != a.isValidAv()) {
/* 226 */ a.resetAvatar();
/* */ }
/* */ }
/* */
/* 230 */ ActionsPart.updateActionDialog();
/* */ }
/* */
/* */
/* */
/* */ public Hashtable<String, InventoryItem> parseInventoryString(String invString)
/* */ {
/* 237 */ Hashtable<String, InventoryItem> newInventory = new Hashtable();
/* */
/* 239 */ if (invString == null) {
/* 240 */ return newInventory;
/* */ }
/* */
/* 243 */ int len = invString.length();
/* */
/* 245 */ for (int itemStart = 0; itemStart < len;) {
/* 246 */ char ch = invString.charAt(itemStart);
/* 247 */ if ((ch < 'A') || (ch > 'Z')) {
/* 248 */ System.out.println("Bad inventory: " + invString);
/* 249 */ return newInventory;
/* */ }
/* */
/* 252 */ for (int descLen = 1;
/* */
/* 254 */ itemStart + descLen < len; descLen++) {
/* 255 */ ch = invString.charAt(itemStart + descLen);
/* 256 */ if ((ch < 'a') || (ch > 'z')) {
/* */ break;
/* */ }
/* */ }
/* 260 */ String shortName = invString.substring(itemStart, itemStart +
/* 261 */ descLen);
/* */
/* 263 */ int countStart = itemStart + descLen;
/* 264 */ for (int countLen = 0;
/* */
/* 266 */ countLen + countStart < len; countLen++) {
/* 267 */ ch = invString.charAt(countStart + countLen);
/* 268 */ if ((ch < '0') || (ch > '9')) {
/* */ break;
/* */ }
/* */ }
/* 272 */ int count = 1;
/* 273 */ if (countLen > 0) {
/* 274 */ count = Integer.parseInt(invString.substring(countStart,
/* 275 */ countStart + countLen));
/* */ }
/* */
/* 278 */ InventoryItem foundItem =
/* 279 */ (InventoryItem)this.masterList_.get(shortName);
/* 280 */ if (foundItem != null) {
/* 281 */ InventoryItem newItem = foundItem.cloneItem();
/* */
/* 283 */ newItem.setQuantity(count);
/* 284 */ newInventory.put(shortName, newItem);
/* */ }
/* */
/* 287 */ itemStart = countStart + countLen;
/* */ }
/* */
/* */
/* 291 */ return newInventory;
/* */ }
/* */
/* */
/* */ public String properCase(String s)
/* */ {
/* 297 */ if (s.equals("")) {
/* 298 */ return s;
/* */ }
/* 300 */ return s.substring(0, 1).toUpperCase() + s.substring(1);
/* */ }
/* */
/* */ public String getSingular(String sn) {
/* 304 */ InventoryItem item = (InventoryItem)this.masterList_.get(sn);
/* */
/* 306 */ if (item != null) {
/* 307 */ return item.getItemName();
/* */ }
/* 309 */ return "unknown" + sn;
/* */ }
/* */
/* */ public String getPlural(String sn)
/* */ {
/* 314 */ return getSingular(sn) + "s";
/* */ }
/* */
/* */ public String itemName(String sn, int num) {
/* 318 */ if (num == 1) {
/* 319 */ return "a " + getSingular(sn);
/* */ }
/* 321 */ String retVal = num + " " + getPlural(sn);
/* 322 */ return retVal;
/* */ }
/* */
/* */ public String itemName(InventoryItem item)
/* */ {
/* 327 */ return itemName(item.getItemId(), item.getItemQuantity());
/* */ }
/* */
/* */
/* */ private InventoryManager()
/* */ {
/* 333 */ this.inventory_ = new Hashtable();
/* 334 */ this.masterList_ = new Hashtable();
/* 335 */ this.initialized_ = false;
/* 336 */ this.equipped_ = new Vector();
/* */
/* */
/* */
/* */
/* 341 */ ServerTableManager stm = ServerTableManager.instance();
/* */
/* 343 */ int invVersion = stm.getFileVersion();
/* */
/* 345 */ String[] invStrings = stm.getTable("invList");
/* 346 */ String[] graphicStrings = new String[0];
/* 347 */ if (invVersion > 1) {
/* 348 */ graphicStrings = stm.getTable("graphicList");
/* */ }
/* */
/* 351 */ URL defaultImageURL = URL.make("home:..\\default.gif");
/* */
/* 353 */ if (invStrings != null) {
/* 354 */ int numStringsPerItem = 12;
/* */
/* */
/* */
/* */
/* */
/* */
/* 361 */ for (int i = 0; i < invStrings.length; i += numStringsPerItem) {
/* 362 */ String id = invStrings[i];
/* 363 */ String name = invStrings[(i + 2)];
/* 364 */ String model = invStrings[(i + 3)];
/* 365 */ int loc = Double.valueOf(invStrings[(i + 4)]).intValue();
/* 366 */ float scale = Double.valueOf(invStrings[(i + 5)]).floatValue();
/* 367 */ int pitch = Double.valueOf(invStrings[(i + 6)]).intValue();
/* 368 */ int roll = Double.valueOf(invStrings[(i + 7)]).intValue();
/* 369 */ int yaw = Double.valueOf(invStrings[(i + 8)]).intValue();
/* 370 */ float xPos = Double.valueOf(invStrings[(i + 9)]).floatValue();
/* 371 */ float yPos = Double.valueOf(invStrings[(i + 10)]).floatValue();
/* 372 */ float zPos = Double.valueOf(invStrings[(i + 11)]).floatValue();
/* */
/* 374 */ URL graphic = null;
/* */
/* 376 */ if ((invVersion > 1) && (graphicStrings.length > i / 6 + 1)) {
/* 377 */ String gString = graphicStrings[(i / 6 + 1)];
/* 378 */ if (gString != "default") {
/* 379 */ graphic = URL.make(gString);
/* */ }
/* */ }
/* */
/* 383 */ if (graphic == null) {
/* 384 */ graphic = defaultImageURL;
/* */ }
/* */
/* */ InventoryItem newItem;
/* */ InventoryItem newItem;
/* 389 */ if (id.charAt(0) == 'H') {
/* 390 */ newItem = InventoryAction.createAction(id, name, 1); } else { InventoryItem newItem;
/* 391 */ if (id.charAt(0) == 'W') {
/* 392 */ newItem = new EquippableItem(id, name, 1, model, scale,
/* 393 */ loc, xPos, yPos, zPos, pitch, roll, yaw); } else { InventoryItem newItem;
/* 394 */ if (id.charAt(0) == 'V') {
/* 395 */ newItem = new InventoryAvatar(id, name, 1);
/* */ } else
/* 397 */ newItem = new InventoryItem(id, name, 1);
/* */ }
/* */ }
/* 400 */ newItem.setItemGraphicLocation(graphic);
/* */
/* 402 */ this.masterList_.put(id, newItem);
/* */ }
/* */ }
/* */ }
/* */
/* */ public static InventoryManager getInventoryManager() {
/* 408 */ if (manager_ == null) {
/* 409 */ manager_ = new InventoryManager();
/* */ }
/* */
/* 412 */ return manager_;
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public boolean inventoryInitialized()
/* */ {
/* 427 */ return this.initialized_;
/* */ }
/* */ }
/* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\scape\InventoryManager.class
* Java compiler version: 6 (50.0)
* JD-Core Version: 0.7.1
*/
|