diff options
| author | Fuwn <[email protected]> | 2021-05-03 16:38:41 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2021-05-03 16:38:41 -0700 |
| commit | e1e781bb2135ef78592226f1a3eaba4925702f1f (patch) | |
| tree | 8a5b590463ed413e1c6eabb719130e701b95ca63 /NET/worlds/scape/InventoryManager.java | |
| download | worlds.jar-main.tar.xz worlds.jar-main.zip | |
Diffstat (limited to 'NET/worlds/scape/InventoryManager.java')
| -rw-r--r-- | NET/worlds/scape/InventoryManager.java | 435 |
1 files changed, 435 insertions, 0 deletions
diff --git a/NET/worlds/scape/InventoryManager.java b/NET/worlds/scape/InventoryManager.java new file mode 100644 index 0000000..f4e0abe --- /dev/null +++ b/NET/worlds/scape/InventoryManager.java @@ -0,0 +1,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 + */
\ No newline at end of file |