public void makePuddle(Room R, int oldWeather, int newWeather) { for (int i = 0; i < R.numItems(); i++) { final Item I = R.getItem(i); if ((I instanceof Drink) && (!CMLib.flags().isGettable(I)) && ((I.name().toLowerCase().indexOf("puddle") >= 0) || (I.name().toLowerCase().indexOf("snow") >= 0))) return; } final Item I = CMClass.getItem("GenLiquidResource"); CMLib.flags().setGettable(I, false); ((Drink) I).setLiquidHeld(100); ((Drink) I).setLiquidRemaining(100); ((Drink) I).setLiquidType(RawMaterial.RESOURCE_FRESHWATER); I.setMaterial(RawMaterial.RESOURCE_FRESHWATER); I.basePhyStats().setDisposition(I.basePhyStats().disposition() | PhyStats.IS_UNSAVABLE); CMLib.materials().addEffectsToResource(I); I.recoverPhyStats(); if (coldWetWeather(oldWeather)) { I.setName(L("some snow")); I.setDisplayText(L("some snow rests on the ground here.")); I.setDescription(L("the snow is white and still quite cold!")); } else { I.setName(L("a puddle of water")); I.setDisplayText(L("a puddle of water has formed here.")); I.setDescription(L("It looks drinkable.")); } R.addItem(I, ItemPossessor.Expire.Monster_EQ); R.recoverRoomStats(); }
public static Item buildPlant(MOB mob, Room room) { Item newItem = CMClass.getItem("GenItem"); newItem.setMaterial(RawMaterial.RESOURCE_GREENS); switch (CMLib.dice().roll(1, 5, 0)) { case 1: newItem.setName("some happy flowers"); newItem.setDisplayText("some happy flowers are growing here."); newItem.setDescription("Happy flowers with little red and yellow blooms."); break; case 2: newItem.setName("some happy weeds"); newItem.setDisplayText("some happy weeds are growing here."); newItem.setDescription("Long stalked little plants with tiny bulbs on top."); break; case 3: newItem.setName("a pretty fern"); newItem.setDisplayText("a pretty fern is growing here."); newItem.setDescription("Like a tiny bush, this dark green plant is lovely."); break; case 4: newItem.setName("a patch of sunflowers"); newItem.setDisplayText("a patch of sunflowers is growing here."); newItem.setDescription("Happy flowers with little yellow blooms."); break; case 5: newItem.setName("a patch of bluebonnets"); newItem.setDisplayText("a patch of bluebonnets is growing here."); newItem.setDescription("Happy flowers with little blue and purple blooms."); break; } Chant_SummonPlants newChant = new Chant_SummonPlants(); newItem.basePhyStats().setLevel(10 + (10 * newChant.getX1Level(mob))); newItem.basePhyStats().setWeight(1); newItem.setSecretIdentity(mob.Name()); newItem.setMiscText(newItem.text()); room.addItem(newItem); newItem.setExpirationDate(0); room.showHappens(CMMsg.MSG_OK_ACTION, "Suddenly, " + newItem.name() + " sprout(s) up here."); newChant.PlantsLocation = room; newChant.littlePlants = newItem; if (CMLib.law().doesOwnThisProperty(mob, room)) { newChant.setInvoker(mob); newChant.setMiscText(mob.Name()); newItem.addNonUninvokableEffect(newChant); } else newChant.beneficialAffect(mob, newItem, 0, (newChant.adjustedLevel(mob, 0) * 240) + 450); room.recoverPhyStats(); return newItem; }
@Override protected Item buildMyPlant(MOB mob, Room room) { final int code = material & RawMaterial.RESOURCE_MASK; final Item newItem = CMClass.getBasicItem("GenItem"); final String name = CMLib.english().startWithAorAn(RawMaterial.CODES.NAME(code).toLowerCase() + " tree"); newItem.setName(name); newItem.setDisplayText(L("@x1 grows here.", newItem.name())); newItem.setDescription(""); newItem.basePhyStats().setWeight(10000); CMLib.flags().setGettable(newItem, false); newItem.setMaterial(material); newItem.setSecretIdentity(mob.Name()); newItem.setMiscText(newItem.text()); room.addItem(newItem); final Chant_SummonTree newChant = new Chant_SummonTree(); newItem.basePhyStats().setLevel(10 + newChant.getX1Level(mob)); newItem.setExpirationDate(0); room.showHappens( CMMsg.MSG_OK_ACTION, L("a tall, healthy @x1 tree sprouts up.", RawMaterial.CODES.NAME(code).toLowerCase())); room.recoverPhyStats(); newChant.plantsLocationR = room; newChant.littlePlantsI = newItem; if (CMLib.law().doesOwnThisLand(mob, room)) { newChant.setInvoker(mob); newChant.setMiscText(mob.Name()); newItem.addNonUninvokableEffect(newChant); } else newChant.beneficialAffect(mob, newItem, 0, (newChant.adjustedLevel(mob, 0) * 240) + 450); room.recoverPhyStats(); return newItem; }
@Override public void executeMsg(final Environmental myHost, final CMMsg msg) { super.executeMsg(myHost, msg); if (msg.amITarget(this) && (msg.targetMinor() == CMMsg.TYP_DRINK)) { final MOB mob = msg.source(); final boolean thirsty = mob.curState().getThirst() <= 0; final boolean full = !mob.curState().adjThirst(thirstQuenched(), mob.maxState().maxThirst(mob.baseWeight())); if (thirsty) mob.tell(L("You are no longer thirsty.")); else if (full) mob.tell(L("You have drunk all you can.")); } else if ((msg.tool() == this) && (msg.targetMinor() == CMMsg.TYP_FILL) && (msg.target() instanceof Container) && (((Container) msg.target()).capacity() > 0)) { final Container container = (Container) msg.target(); final Item I = CMClass.getItem("GenLiquidResource"); I.setName(L("some milk")); I.setDisplayText(L("some milk has been left here.")); I.setDescription(L("It looks like milk")); I.setMaterial(RawMaterial.RESOURCE_MILK); I.setBaseValue(RawMaterial.CODES.VALUE(RawMaterial.RESOURCE_MILK)); I.basePhyStats().setWeight(1); CMLib.materials().addEffectsToResource(I); I.recoverPhyStats(); I.setContainer(container); if (container.owner() != null) if (container.owner() instanceof MOB) ((MOB) container.owner()).addItem(I); else if (container.owner() instanceof Room) ((Room) container.owner()).addItem(I, ItemPossessor.Expire.Resource); } }
private void text(String text) { switch (state) { case ITEM_TITLE: currentItem.setTitle(text); break; case ITEM_DESCRIPTION: currentItem.setDescription(text); break; case ITEM_CONTENT: currentItem.setContent(text); break; case ITEM_PUB_DATE: Date date; try { date = dateFormat.parse(text); } catch (ParseException e) { e.printStackTrace(); return; } currentItem.setPubDate(date.getTime()); break; default: break; } }
// parsing the XML public void parseXMLAndStoreIt(XmlPullParser myParser) { int event; String text = null; // Create item try { event = myParser.getEventType(); Item item = null; boolean checkItem = true; boolean newItem = false; while (event != XmlPullParser.END_DOCUMENT) { String name = myParser.getName(); if (checkItem) { item = new Item(); checkItem = false; } switch (event) { case XmlPullParser.START_TAG: if (name.equals("item")) { newItem = true; } break; case XmlPullParser.TEXT: text = myParser.getText(); break; case XmlPullParser.END_TAG: switch (name) { case "title": if (newItem) { item.setTitle(text); } break; case "description": if (newItem) { item.setDescription(text); } break; case "link": if (newItem) { item.setLink(text); } break; } break; } // add to an array list if (item.itemReady()) { feed.addItem(item); newItem = false; checkItem = true; } event = myParser.next(); } } catch (Exception e) { e.printStackTrace(); } }
/** * An insert operation to the MDSItemStorage. * * @param id * @param price * @param description * @param size * @return */ int insert(long id, double price, long[] description, int size) { if (find(id) != 0) { Item previousItem = findItem(id); Double previousPrice = previousItem.getPrice(); List<Long> previousDescription = previousItem.getDescription(); if (size > 0) { Integer previousDescriptionHash = previousItem.getDescriptionHash(); // Description of item is in description[0..size-1]. copy them into your data structure. previousItem.setDescription(size, (size == 0) ? null : description); // adjust previousDescription getStorage() .updateDescriptionDataSet( previousItem, previousDescription, price, (previousPrice == price ? null : previousPrice)); // adjust previousPrice getStorage().updatePriceDataSet(previousItem, previousPrice); // refresh and re-check associated same-same hash with the previous item. getStorage().addressSameSameHashing(previousItem, previousDescriptionHash); } else { if (previousPrice != price) { if (size == 0) getStorage().updateDescriptionDataSet(previousItem, null, price, previousPrice); // adjust previousPrice getStorage().updatePriceDataSet(previousItem, previousPrice); } } return 0; } // create the Item object. Item item = new Item(); item.setId(id).setPrice(price).setDescription(size, (size == 0) ? null : description); // register new item getStorage().registerItem(item); return 1; }
/** * Handle PUT requests. * * @throws IOException */ @Put public void storeItem(Representation entity) throws IOException { // The PUT request updates or creates the resource. if (item == null) { item = new Item(itemName); } // Update the description. Form form = new Form(entity); item.setDescription(form.getFirstValue("description")); if (getItems().putIfAbsent(item.getName(), item) == null) { setStatus(Status.SUCCESS_CREATED); } else { setStatus(Status.SUCCESS_OK); } }
/** * Month conversion from jaxb model to entity object. * * @param model jaxb model of month * @return month entity object */ public static org.kaleta.scheduler.backend.entity.Month transformMonthToData(Month model) { org.kaleta.scheduler.backend.entity.Month data = new org.kaleta.scheduler.backend.entity.Month(); data.setId(Integer.valueOf(model.getId())); data.setName(model.getSpecification().getName()); data.setDaysNumber(Integer.valueOf(model.getSpecification().getDays())); data.setDayStartsWith(Integer.valueOf(model.getSpecification().getFirstDay())); for (Month.Specification.FreeDay freeDay : model.getSpecification().getFreeDayList()) { data.getPublicFreeDays().add(Integer.valueOf(freeDay.getDay())); } for (Month.Schedule.Task modelTask : model.getSchedule().getTaskList()) { Task task = new Task(); task.setId(Integer.valueOf(modelTask.getId())); task.setType(modelTask.getType()); task.setDescription(modelTask.getDescription()); task.setDay(Integer.valueOf(modelTask.getDay())); Time starts = new Time(); starts.setFromString(modelTask.getStarts()); task.setStarts(starts); Time duration = new Time(); duration.setFromString(modelTask.getDuration()); task.setDuration(duration); task.setPriority(Boolean.valueOf(modelTask.getPriority())); task.setSuccessful(Boolean.valueOf(modelTask.getSuccessful())); data.getTasks().add(task); } for (Month.Accounting.Item modelItem : model.getAccounting().getItemList()) { Item item = new Item(); item.setId(Integer.valueOf(modelItem.getId())); item.setType(modelItem.getType()); item.setDescription(modelItem.getDescription()); item.setDay(Integer.valueOf(modelItem.getDay())); item.setIncome(Boolean.valueOf(modelItem.getIncome())); item.setAmount(new BigDecimal(modelItem.getAmount())); data.getItems().add(item); } return data; }
public static void colorForSale(Room R, boolean rental, boolean reset) { synchronized (("SYNC" + R.roomID()).intern()) { R = CMLib.map().getRoom(R); final String theStr = rental ? RENTSTR : SALESTR; final String otherStr = rental ? SALESTR : RENTSTR; int x = R.description().indexOf(otherStr); while (x >= 0) { R.setDescription(R.description().substring(0, x)); CMLib.database().DBUpdateRoom(R); x = R.description().indexOf(otherStr); } final String oldDescription = R.description(); x = R.description().indexOf(theStr.trim()); if ((x < 0) || (reset && (!R.displayText() .equals(CMath.bset(R.domainType(), Room.INDOORS) ? INDOORSTR : OUTDOORSTR)))) { if (reset) { R.setDescription(""); R.setDisplayText(CMath.bset(R.domainType(), Room.INDOORS) ? INDOORSTR : OUTDOORSTR); x = -1; } if (x < 0) R.setDescription(R.description() + theStr); else if (!reset) R.setDescription(R.description().substring(0, x + theStr.trim().length())); if (!R.description().equals(oldDescription)) CMLib.database().DBUpdateRoom(R); } else { R.setDescription(R.description().substring(0, x + theStr.trim().length())); if (!R.description().equals(oldDescription)) CMLib.database().DBUpdateRoom(R); } Item I = R.findItem(null, "$id$"); if ((I == null) || (!I.ID().equals("GenWallpaper"))) { I = CMClass.getItem("GenWallpaper"); CMLib.flags().setReadable(I, true); I.setName(("id")); I.setReadableText(CMLib.lang().L("This room is " + CMLib.map().getExtendedRoomID(R))); I.setDescription(CMLib.lang().L("This room is @x1", CMLib.map().getExtendedRoomID(R))); R.addItem(I); CMLib.database().DBUpdateItems(R); } } }
private void createMessage(java.awt.event.ActionEvent evt) { // GEN-FIRST:event_createMessage String itemTitle = itemTitleTextField.getText().trim(); String itemDescription = itemDescriptionTextArea.getText().trim(); if (itemTitle.length() > 0 && itemDescription.length() > 0) { Item tmp = null; int currentSelectedItemIndex = itemList.getSelectedIndex(); if (currentSelectedItemIndex >= 0) { tmp = listModel.getElementAt(currentSelectedItemIndex); } else { tmp = new Item(); } tmp.setTitle(itemTitle); tmp.setDescription(itemDescription); if (currentSelectedItemIndex < 0) { listModel.addElement(tmp); } createItemButton.setText("Create"); itemList.clearSelection(); clearItemFields(); if (!deleteItemButton.isEnabled()) { deleteItemButton.setEnabled(true); } } else { JOptionPane.showMessageDialog( null, "Item Title and Description can not be empty", "Input Error", JOptionPane.ERROR_MESSAGE); } } // GEN-LAST:event_createMessage
@Test public void testIndexEmbedded() throws Exception { FullTextSession s = Search.getFullTextSession(openSession()); Transaction tx = s.beginTransaction(); ProductCatalog productCatalog = new ProductCatalog(); productCatalog.setName("Cars"); Item item = new Item(); item.setId(1); item.setDescription("Ferrari"); item.setProductCatalog(productCatalog); productCatalog.addItem(item); s.persist(item); s.persist(productCatalog); tx.commit(); s.clear(); tx = s.beginTransaction(); QueryParser parser = new QueryParser("id", TestConstants.standardAnalyzer); org.apache.lucene.search.Query luceneQuery = parser.parse("items.description:Ferrari"); FullTextQuery query = s.createFullTextQuery(luceneQuery).setProjection(FullTextQuery.THIS, FullTextQuery.SCORE); assertEquals("expecting 1 results", 1, query.getResultSize()); @SuppressWarnings("unchecked") List<Object[]> results = query.list(); for (Object[] result : results) { s.delete(result[0]); } tx.commit(); s.close(); }
public Item isRuinedLoot(DVector policies, Item I) { if (I == null) return null; if ((CMath.bset(I.envStats().disposition(), EnvStats.IS_UNSAVABLE)) || (CMath.bset(I.envStats().sensesMask(), EnvStats.SENSE_ITEMNORUIN)) || (I instanceof Coins)) return I; if (I.name().toLowerCase().indexOf("ruined ") >= 0) return I; for (int d = 0; d < policies.size(); d++) { if ((((Vector) policies.elementAt(d, 3)).size() > 0) && (!CMLib.masking().maskCheck((Vector) policies.elementAt(d, 3), I, true))) continue; if (CMLib.dice().rollPercentage() > ((Integer) policies.elementAt(d, 1)).intValue()) continue; int flags = ((Integer) policies.elementAt(d, 2)).intValue(); if (CMath.bset(flags, CMMiscUtils.LOOTFLAG_WORN) && I.amWearingAt(Wearable.IN_INVENTORY)) continue; else if (CMath.bset(flags, CMMiscUtils.LOOTFLAG_UNWORN) && (!I.amWearingAt(Wearable.IN_INVENTORY))) continue; if (CMath.bset(flags, CMMiscUtils.LOOTFLAG_LOSS)) return null; Item I2 = CMClass.getItem("GenItem"); I2.baseEnvStats().setWeight(I.baseEnvStats().weight()); I2.setName(I.Name()); I2.setDisplayText(I.displayText()); I2.setDescription(I2.description()); I2.recoverEnvStats(); I2.setMaterial(I.material()); String ruinDescAdder = null; switch (I2.material() & RawMaterial.MATERIAL_MASK) { case RawMaterial.MATERIAL_LEATHER: case RawMaterial.MATERIAL_CLOTH: case RawMaterial.MATERIAL_VEGETATION: case RawMaterial.MATERIAL_FLESH: case RawMaterial.MATERIAL_PAPER: ruinDescAdder = CMStrings.capitalizeFirstLetter(I2.name()) + " is torn and ruined beyond repair."; break; case RawMaterial.MATERIAL_METAL: case RawMaterial.MATERIAL_MITHRIL: case RawMaterial.MATERIAL_WOODEN: ruinDescAdder = CMStrings.capitalizeFirstLetter(I2.name()) + " is battered and ruined beyond repair."; break; case RawMaterial.MATERIAL_GLASS: ruinDescAdder = CMStrings.capitalizeFirstLetter(I2.name()) + " is shattered and ruined beyond repair."; break; case RawMaterial.MATERIAL_ROCK: case RawMaterial.MATERIAL_PRECIOUS: case RawMaterial.MATERIAL_PLASTIC: ruinDescAdder = CMStrings.capitalizeFirstLetter(I2.name()) + " is cracked and ruined beyond repair."; break; case RawMaterial.MATERIAL_UNKNOWN: case RawMaterial.MATERIAL_ENERGY: case RawMaterial.MATERIAL_LIQUID: default: ruinDescAdder = CMStrings.capitalizeFirstLetter(I2.name()) + " is ruined beyond repair."; break; } I2.setDescription(CMStrings.endWithAPeriod(I2.description()) + " " + ruinDescAdder); String oldName = I2.Name(); I2.setName(CMLib.english().insertUnColoredAdjective(I2.Name(), "ruined")); int x = I2.displayText().toUpperCase().indexOf(oldName.toUpperCase()); I2.setBaseValue(0); if (x >= 0) I2.setDisplayText( I2.displayText().substring(0, x) + I2.Name() + I2.displayText().substring(x + oldName.length())); return I2; } return I; }
/** * 查询商品明细 * * @param xml * @return * @throws DocumentException */ public static Item getItem(String xml) throws Exception { Item item = new Item(); Document document = formatStr2Doc(xml); Element rootElt = document.getRootElement(); Element element = rootElt.element("Item"); item.setTitle(element.elementText("Title")); item.setCurrency(element.elementText("Currency")); item.setCountry(element.elementText("Country")); item.setSite(element.elementText("Site")); item.setPostalCode(element.elementText("PostalCode")); item.setLocation(element.elementText("Location")); item.setItemID(element.elementText("ItemID")); item.setHitCounter(element.elementText("HitCounter")); item.setAutoPay(element.elementText("AutoPay").equals("true") ? true : false); item.setGiftIcon(element.elementText("GiftIcon")); item.setListingDuration(element.elementText("ListingDuration")); item.setQuantity(Integer.parseInt(element.elementText("Quantity"))); item.setPayPalEmailAddress(element.elementText("PayPalEmailAddress")); item.setGetItFast("false".equals(element.elementText("GetItFast")) ? false : true); item.setPrivateListing("true".equals(element.elementText("PrivateListing")) ? true : false); item.setDispatchTimeMax(Integer.parseInt(element.elementText("DispatchTimeMax"))); item.setListingDuration(element.elementText("ListingDuration")); item.setDescription(element.elementText("Description")); item.setSKU(element.elementText("SKU")); item.setConditionID( Integer.parseInt( element.elementText("CategoryID") == null ? "1000" : element.elementText("CategoryID"))); PrimaryCategory pc = new PrimaryCategory(); pc.setCategoryID(element.element("PrimaryCategory").elementText("CategoryID")); item.setPrimaryCategory(pc); String listType = ""; if ("FixedPriceItem".equals(element.elementText("ListingType"))) { if (element.element("Variations") != null) { listType = "2"; } else { listType = element.elementText("ListingType"); } } else { listType = element.elementText("ListingType"); } item.setListingType(listType); // 自定义属性 Element elspe = element.element("ItemSpecifics"); if (elspe != null) { ItemSpecifics itemSpecifics = new ItemSpecifics(); Iterator<Element> itnvl = elspe.elementIterator("NameValueList"); List<NameValueList> linvl = new ArrayList<NameValueList>(); while (itnvl.hasNext()) { Element nvl = itnvl.next(); NameValueList nvli = new NameValueList(); nvli.setName(nvl.elementText("Name")); List<String> listr = new ArrayList(); Iterator<Element> itval = nvl.elementIterator("Value"); while (itval.hasNext()) { listr.add(itval.next().getText()); } nvli.setValue(listr); linvl.add(nvli); } itemSpecifics.setNameValueList(linvl); } // 图片信息 Element pice = element.element("PictureDetails"); if (pice != null) { PictureDetails pd = new PictureDetails(); if (pice.elementText("GalleryType") != null) { pd.setGalleryType(pice.elementText("GalleryType")); } if (pice.elementText("PhotoDisplay") != null) { pd.setPhotoDisplay(pice.elementText("PhotoDisplay")); } if (pice.elementText("GalleryURL") != null) { String url = pice.elementText("GalleryURL"); if (url.indexOf("?") > 0) { url.substring(0, url.indexOf("?")); } pd.setGalleryURL(url); } Iterator<Element> itpicurl = pice.elementIterator("PictureURL"); List<String> urlli = new ArrayList(); while (itpicurl.hasNext()) { Element url = itpicurl.next(); String urlstr = url.getStringValue(); if (urlstr.indexOf("?") > 0) { urlstr = urlstr.substring(0, urlstr.indexOf("?")); } urlli.add(urlstr); } pd.setPictureURL(urlli); item.setPictureDetails(pd); } // 取得退货政策并封装 Element returne = element.element("ReturnPolicy"); ReturnPolicy rp = new ReturnPolicy(); rp.setRefundOption(returne.elementText("RefundOption")); rp.setReturnsWithinOption(returne.elementText("ReturnsWithinOption")); rp.setReturnsAcceptedOption(returne.elementText("ReturnsAcceptedOption")); rp.setDescription(returne.elementText("Description")); rp.setShippingCostPaidByOption(returne.elementText("ShippingCostPaidByOption")); item.setReturnPolicy(rp); // 买家要求 BuyerRequirementDetails brd = new BuyerRequirementDetails(); MaximumItemRequirements mirs = new MaximumItemRequirements(); Element buyere = element.element("BuyerRequirementDetails"); if (buyere != null) { Element maxiteme = buyere.element("MaximumItemRequirements"); if (maxiteme != null) { if (maxiteme.elementText("MaximumItemCount") != null) { mirs.setMaximumItemCount(Integer.parseInt(maxiteme.elementText("MaximumItemCount"))); } if (maxiteme.elementText("MinimumFeedbackScore") != null) { mirs.setMinimumFeedbackScore( Integer.parseInt(maxiteme.elementText("MinimumFeedbackScore"))); } brd.setMaximumItemRequirements(mirs); } Element maxUnpaid = buyere.element("MaximumUnpaidItemStrikesInfo"); if (maxUnpaid != null) { MaximumUnpaidItemStrikesInfo muis = new MaximumUnpaidItemStrikesInfo(); String count = maxUnpaid.elementText("Count"); muis.setCount(Integer.parseInt(count)); muis.setPeriod(maxUnpaid.elementText("Period")); brd.setMaximumUnpaidItemStrikesInfo(muis); } Element maxPolicy = buyere.element("MaximumBuyerPolicyViolations"); if (maxPolicy != null) { MaximumBuyerPolicyViolations mbpv = new MaximumBuyerPolicyViolations(); mbpv.setCount(Integer.parseInt(maxPolicy.elementText("Count"))); mbpv.setPeriod(maxPolicy.elementText("Period")); brd.setMaximumBuyerPolicyViolations(mbpv); } if (buyere.elementText("LinkedPayPalAccount") != null) { brd.setLinkedPayPalAccount( buyere.elementText("LinkedPayPalAccount").equals("true") ? true : false); } if (buyere.elementText("ShipToRegistrationCountry") != null) { brd.setShipToRegistrationCountry( buyere.elementText("ShipToRegistrationCountry").equals("true") ? true : false); } item.setBuyerRequirementDetails(brd); } // 运输选项 ShippingDetails sd = new ShippingDetails(); Element elsd = element.element("ShippingDetails"); Iterator<Element> itershipping = elsd.elementIterator("ShippingServiceOptions"); List<ShippingServiceOptions> lisso = new ArrayList(); // 国内运输 while (itershipping.hasNext()) { Element shipping = itershipping.next(); ShippingServiceOptions sso = new ShippingServiceOptions(); sso.setShippingService(shipping.elementText("ShippingService")); if (shipping.elementText("ShippingServiceCost") != null) { sso.setShippingServiceCost( new ShippingServiceCost( shipping.attributeValue("currencyID"), Double.parseDouble(shipping.elementText("ShippingServiceCost")))); } sso.setShippingServicePriority( Integer.parseInt(shipping.elementText("ShippingServicePriority"))); if (shipping.elementText("FreeShipping") != null) { sso.setFreeShipping(shipping.elementText("FreeShipping").equals("true") ? true : false); } ShippingServiceAdditionalCost ssac = new ShippingServiceAdditionalCost(); ssac.setValue( Double.parseDouble( shipping.elementText("ShippingServiceAdditionalCost") != null ? shipping.elementText("ShippingServiceAdditionalCost") : "0")); sso.setShippingServiceAdditionalCost(ssac); ShippingSurcharge ss = new ShippingSurcharge(); ss.setValue( Double.parseDouble( shipping.elementText("ShippingSurcharge") != null ? shipping.elementText("ShippingSurcharge") : "0")); sso.setShippingSurcharge(ss); lisso.add(sso); } if (lisso.size() > 0) { sd.setShippingServiceOptions(lisso); } // 不运送到的国家 Iterator<Element> excEl = elsd.elementIterator("ExcludeShipToLocation"); List<String> liex = new ArrayList<String>(); while (excEl.hasNext()) { Element els = excEl.next(); liex.add(els.getText()); } if (liex.size() > 0) { sd.setExcludeShipToLocation(liex); } // 国际运输 Iterator<Element> iteInt = elsd.elementIterator("InternationalShippingServiceOption"); List<InternationalShippingServiceOption> liint = new ArrayList<InternationalShippingServiceOption>(); while (iteInt.hasNext()) { Element intel = iteInt.next(); InternationalShippingServiceOption isso = new InternationalShippingServiceOption(); isso.setShippingService(intel.elementText("ShippingService")); isso.setShippingServiceCost( new ShippingServiceCost( intel.attributeValue("currencyID"), Double.parseDouble(intel.elementText("ShippingServiceCost")))); Iterator<Element> iteto = intel.elementIterator("ShipToLocation"); List<String> listr = new ArrayList(); while (iteto.hasNext()) { listr.add(iteto.next().getText()); } isso.setShipToLocation(listr); isso.setShippingServicePriority( Integer.parseInt(intel.elementText("ShippingServicePriority"))); ShippingServiceAdditionalCost ssac = new ShippingServiceAdditionalCost(); ssac.setValue( Double.parseDouble( intel.elementText("ShippingServiceAdditionalCost") != null ? intel.elementText("ShippingServiceAdditionalCost") : "0")); isso.setShippingServiceAdditionalCost(ssac); liint.add(isso); } if (liint.size() > 0) { sd.setInternationalShippingServiceOption(liint); } // 计算所需的长宽高 Element re = elsd.element("CalculatedShippingRate"); if (re != null) { CalculatedShippingRate csr = new CalculatedShippingRate(); if (re.elementText("InternationalPackagingHandlingCosts") != null) { csr.setPackagingHandlingCosts( new PackagingHandlingCosts( re.attributeValue("currencyID"), Double.parseDouble(re.elementText("InternationalPackagingHandlingCosts")))); } if (re.elementText("OriginatingPostalCode") != null) { csr.setOriginatingPostalCode(re.elementText("OriginatingPostalCode")); } if (re.elementText("PackageDepth") != null) { csr.setPackageDepth(Double.parseDouble(re.elementText("PackageDepth"))); } if (re.elementText("PackageLength") != null) { csr.setPackageLength(Double.parseDouble(re.elementText("PackageLength"))); } if (re.elementText("PackageWidth") != null) { csr.setPackageWidth(Double.parseDouble(re.elementText("PackageWidth"))); } if (re.elementText("ShippingIrregular") != null) { csr.setShippingIrregular(Boolean.parseBoolean(re.elementText("ShippingIrregular"))); } if (re.elementText("ShippingPackage") != null) { csr.setShippingPackage(re.elementText("ShippingPackage")); } if (re.elementText("WeightMajor") != null) { csr.setWeightMajor(Double.parseDouble(re.elementText("WeightMajor"))); } if (re.elementText("WeightMinor") != null) { csr.setWeightMinor(Double.parseDouble(re.elementText("WeightMinor"))); } sd.setCalculatedShippingRate(csr); } sd.setShippingType(elsd.elementText("ShippingType")); item.setShippingDetails(sd); // 卖家信息 Seller seller = new Seller(); Element elsel = element.element("Seller"); seller.setUserID(elsel.elementText("UserID")); seller.setEmail(elsel.elementText("Email")); item.setSeller(seller); // 多属性 Element vartions = element.element("Variations"); if (vartions != null) { Iterator<Element> elvar = vartions.elementIterator("Variation"); List<Variation> livar = new ArrayList(); while (elvar.hasNext()) { Element ele = elvar.next(); Variation var = new Variation(); var.setSKU(ele.elementText("SKU")); var.setQuantity( Integer.parseInt(ele.elementText("Quantity")) - Integer.parseInt(ele.element("SellingStatus").elementText("QuantitySold"))); var.setStartPrice( new StartPrice( ele.attributeValue("currencyID"), Double.parseDouble(ele.elementText("StartPrice")))); Element elvs = ele.element("VariationSpecifics"); Iterator<Element> elnvl = elvs.elementIterator("NameValueList"); List<NameValueList> linvl = new ArrayList(); while (elnvl.hasNext()) { Element elment = elnvl.next(); NameValueList nvl = new NameValueList(); nvl.setName(elment.elementText("Name")); List<String> li = new ArrayList<String>(); li.add(elment.elementText("Value")); nvl.setValue(li); linvl.add(nvl); } List<VariationSpecifics> livs = new ArrayList(); VariationSpecifics vs = new VariationSpecifics(); vs.setNameValueList(linvl); livs.add(vs); var.setVariationSpecifics(livs); livar.add(var); } Variations vtions = new Variations(); vtions.setVariation(livar); // 多属性值 Element elvss = vartions.element("VariationSpecificsSet"); Iterator<Element> itele = elvss.elementIterator("NameValueList"); List<NameValueList> linvl = new ArrayList(); while (itele.hasNext()) { Element nvlel = itele.next(); NameValueList nvl = new NameValueList(); nvl.setName(nvlel.elementText("Name")); Iterator<Element> itvalue = nvlel.elementIterator("Value"); List<String> livalue = new ArrayList(); while (itvalue.hasNext()) { Element value = itvalue.next(); livalue.add(value.getText()); } nvl.setValue(livalue); linvl.add(nvl); } VariationSpecificsSet vss = new VariationSpecificsSet(); vss.setNameValueList(linvl); vtions.setVariationSpecificsSet(vss); // 多属性图片信息 Pictures pic = new Pictures(); Element elpic = vartions.element("Pictures"); pic.setVariationSpecificName(elpic.elementText("VariationSpecificName")); Iterator<Element> iturl = elpic.elementIterator("VariationSpecificPictureSet"); List<VariationSpecificPictureSet> livsps = new ArrayList(); while (iturl.hasNext()) { Element urle = iturl.next(); VariationSpecificPictureSet vsps = new VariationSpecificPictureSet(); vsps.setVariationSpecificValue(urle.elementText("VariationSpecificValue")); Iterator<Element> url = urle.elementIterator("PictureURL"); List li = new ArrayList(); while (url.hasNext()) { Element e = url.next(); String urlstr = e.getText(); if (urlstr.indexOf("?") > 0) { urlstr = urlstr.substring(0, urlstr.indexOf("?")); } li.add(urlstr); } vsps.setPictureURL(li); livsps.add(vsps); } pic.setVariationSpecificPictureSet(livsps); vtions.setPictures(pic); item.setVariations(vtions); } else { Element el = element.element("StartPrice"); item.setStartPrice( new StartPrice(el.attributeValue("currencyID"), Double.parseDouble(el.getText()))); if (element.element("BuyItNowPrice") != null) { item.setBuyItNowPrice(Double.parseDouble(element.elementText("BuyItNowPrice"))); } if (element.element("ReservePrice") != null) { item.setReservePrice(Double.parseDouble(element.elementText("ReservePrice"))); } } return item; }
public boolean invoke(MOB mob, Vector commands, Physical givenTarget, boolean auto, int asLevel) { int autoGenerate = 0; if ((auto) && (commands.size() > 0) && (commands.firstElement() instanceof Integer)) { autoGenerate = ((Integer) commands.firstElement()).intValue(); commands.removeElementAt(0); givenTarget = null; } DVector enhancedTypes = enhancedTypes(mob, commands); randomRecipeFix(mob, addRecipes(mob, loadRecipes()), commands, autoGenerate); if (commands.size() == 0) { commonTell( mob, "Weave what? Enter \"weave list\" for a list, \"weave refit <item>\" to resize, \"weave learn <item>\", \"weave scan\", or \"weave mend <item>\"."); return false; } if ((!auto) && (commands.size() > 0) && (((String) commands.firstElement()).equalsIgnoreCase("bundle"))) { bundling = true; if (super.invoke(mob, commands, givenTarget, auto, asLevel)) return super.bundle(mob, commands); return false; } List<List<String>> recipes = addRecipes(mob, loadRecipes()); String str = (String) commands.elementAt(0); bundling = false; String startStr = null; int duration = 4; if (str.equalsIgnoreCase("list")) { String mask = CMParms.combine(commands, 1); StringBuffer buf = new StringBuffer(""); int toggler = 1; int toggleTop = 2; for (int r = 0; r < toggleTop; r++) buf.append( CMStrings.padRight("Item", 22) + " " + CMStrings.padRight("Lvl", 3) + " " + CMStrings.padRight("Material", 10) + " "); buf.append("\n\r"); for (int r = 0; r < recipes.size(); r++) { List<String> V = recipes.get(r); if (V.size() > 0) { String item = replacePercent((String) V.get(RCP_FINALNAME), ""); int level = CMath.s_int((String) V.get(RCP_LEVEL)); String wood = getComponentDescription(mob, V, RCP_WOOD); if (wood.length() > 5) { if (toggler > 1) buf.append("\n\r"); toggler = toggleTop; } if ((level <= xlevel(mob)) && ((mask == null) || (mask.length() == 0) || mask.equalsIgnoreCase("all") || CMLib.english().containsString(item, mask))) { buf.append( CMStrings.padRight(item, 22) + " " + CMStrings.padRight("" + level, 3) + " " + CMStrings.padRightPreserve("" + wood, 10) + ((toggler != toggleTop) ? " " : "\n\r")); if (++toggler > toggleTop) toggler = 1; } } } if (toggler != 1) buf.append("\n\r"); commonTell(mob, buf.toString()); enhanceList(mob); return true; } else if ((commands.firstElement() instanceof String) && (((String) commands.firstElement())).equalsIgnoreCase("learn")) { return doLearnRecipe(mob, commands, givenTarget, auto, asLevel); } else if (str.equalsIgnoreCase("scan")) return publicScan(mob, commands); else if (str.equalsIgnoreCase("mend")) { building = null; activity = CraftingActivity.CRAFTING; messedUp = false; key = null; Vector newCommands = CMParms.parse(CMParms.combine(commands, 1)); building = getTarget(mob, mob.location(), givenTarget, newCommands, Wearable.FILTER_UNWORNONLY); if (!canMend(mob, building, false)) return false; activity = CraftingActivity.MENDING; if (!super.invoke(mob, commands, givenTarget, auto, asLevel)) return false; startStr = "<S-NAME> start(s) mending " + building.name() + "."; displayText = "You are mending " + building.name(); verb = "mending " + building.name(); } else if (str.equalsIgnoreCase("refit")) { building = null; activity = CraftingActivity.CRAFTING; key = null; messedUp = false; Vector newCommands = CMParms.parse(CMParms.combine(commands, 1)); building = getTarget(mob, mob.location(), givenTarget, newCommands, Wearable.FILTER_UNWORNONLY); if (building == null) return false; if ((building.material() != RawMaterial.RESOURCE_COTTON) && (building.material() != RawMaterial.RESOURCE_SILK) && (building.material() != RawMaterial.RESOURCE_HEMP) && (building.material() != RawMaterial.RESOURCE_VINE) && (building.material() != RawMaterial.RESOURCE_WHEAT) && (building.material() != RawMaterial.RESOURCE_SEAWEED)) { commonTell(mob, "That's not made of any sort of weavable material. It can't be refitted."); return false; } if (!(building instanceof Armor)) { commonTell(mob, "You don't know how to refit that sort of thing."); return false; } if (building.phyStats().height() == 0) { commonTell(mob, building.name() + " is already the right size."); return false; } activity = CraftingActivity.REFITTING; if (!super.invoke(mob, commands, givenTarget, auto, asLevel)) return false; startStr = "<S-NAME> start(s) refitting " + building.name() + "."; displayText = "You are refitting " + building.name(); verb = "refitting " + building.name(); } else { building = null; activity = CraftingActivity.CRAFTING; messedUp = false; aborted = false; key = null; int amount = -1; if ((commands.size() > 1) && (CMath.isNumber((String) commands.lastElement()))) { amount = CMath.s_int((String) commands.lastElement()); commands.removeElementAt(commands.size() - 1); } String recipeName = CMParms.combine(commands, 0); List<String> foundRecipe = null; List<List<String>> matches = matchingRecipeNames(recipes, recipeName, true); for (int r = 0; r < matches.size(); r++) { List<String> V = matches.get(r); if (V.size() > 0) { int level = CMath.s_int((String) V.get(RCP_LEVEL)); if (level <= xlevel(mob)) { foundRecipe = V; break; } } } if (foundRecipe == null) { commonTell( mob, "You don't know how to weave a '" + recipeName + "'. Try \"weave list\" for a list."); return false; } final String woodRequiredStr = (String) foundRecipe.get(RCP_WOOD); final List<Object> componentsFoundList = getAbilityComponents( mob, woodRequiredStr, "make " + CMLib.english().startWithAorAn(recipeName), autoGenerate); if (componentsFoundList == null) return false; int woodRequired = CMath.s_int(woodRequiredStr); woodRequired = adjustWoodRequired(woodRequired, mob); if (amount > woodRequired) woodRequired = amount; int[] pm = { RawMaterial.RESOURCE_COTTON, RawMaterial.RESOURCE_SILK, RawMaterial.RESOURCE_HEMP, RawMaterial.RESOURCE_VINE, RawMaterial.RESOURCE_WHEAT, RawMaterial.RESOURCE_SEAWEED }; String misctype = (String) foundRecipe.get(RCP_MISCTYPE); String spell = (foundRecipe.size() > RCP_SPELL) ? ((String) foundRecipe.get(RCP_SPELL)).trim() : ""; bundling = spell.equalsIgnoreCase("BUNDLE") || misctype.equalsIgnoreCase("BUNDLE"); int[][] data = fetchFoundResourceData( mob, woodRequired, "weavable material", pm, 0, null, null, false, autoGenerate, enhancedTypes); if (data == null) return false; fixDataForComponents(data, componentsFoundList); woodRequired = data[0][FOUND_AMT]; if (!super.invoke(mob, commands, givenTarget, auto, asLevel)) return false; int lostValue = autoGenerate > 0 ? 0 : CMLib.materials() .destroyResources(mob.location(), woodRequired, data[0][FOUND_CODE], 0, null) + CMLib.ableMapper().destroyAbilityComponents(componentsFoundList); building = CMClass.getItem((String) foundRecipe.get(RCP_CLASSTYPE)); if (building == null) { commonTell(mob, "There's no such thing as a " + foundRecipe.get(RCP_CLASSTYPE) + "!!!"); return false; } duration = getDuration( CMath.s_int((String) foundRecipe.get(RCP_TICKS)), mob, CMath.s_int((String) foundRecipe.get(RCP_LEVEL)), 4); String itemName = replacePercent( (String) foundRecipe.get(RCP_FINALNAME), RawMaterial.CODES.NAME(data[0][FOUND_CODE])) .toLowerCase(); if (bundling) itemName = "a " + woodRequired + "# " + itemName; else if (itemName.endsWith("s")) itemName = "some " + itemName; else itemName = CMLib.english().startWithAorAn(itemName); building.setName(itemName); startStr = "<S-NAME> start(s) weaving " + building.name() + "."; displayText = "You are weaving " + building.name(); verb = "weaving " + building.name(); building.setDisplayText(itemName + " lies here"); building.setDescription(itemName + ". "); building .basePhyStats() .setWeight( (int) Math.round((double) woodRequired * this.getItemWeightMultiplier(bundling))); building.setBaseValue(CMath.s_int((String) foundRecipe.get(RCP_VALUE))); building.setMaterial(data[0][FOUND_CODE]); building.basePhyStats().setLevel(CMath.s_int((String) foundRecipe.get(RCP_LEVEL))); building.setSecretIdentity(getBrand(mob)); int capacity = CMath.s_int((String) foundRecipe.get(RCP_CAPACITY)); long canContain = getContainerType((String) foundRecipe.get(RCP_CONTAINMASK)); int armordmg = CMath.s_int((String) foundRecipe.get(RCP_ARMORDMG)); if (bundling) { building.setBaseValue(lostValue); building.basePhyStats().setWeight(woodRequired); } addSpells(building, spell); if (building instanceof Weapon) { ((Weapon) building).setWeaponClassification(Weapon.CLASS_FLAILED); for (int cl = 0; cl < Weapon.CLASS_DESCS.length; cl++) { if (misctype.equalsIgnoreCase(Weapon.CLASS_DESCS[cl])) ((Weapon) building).setWeaponClassification(cl); } building.basePhyStats().setDamage(armordmg); ((Weapon) building).setRawProperLocationBitmap(Wearable.WORN_WIELD | Wearable.WORN_HELD); ((Weapon) building).setRawLogicalAnd((capacity > 1)); } key = null; if (building instanceof Armor) { if (capacity > 0) { ((Armor) building).setCapacity(capacity + woodRequired); ((Armor) building).setContainTypes(canContain); } ((Armor) building).basePhyStats().setArmor(0); if (armordmg != 0) ((Armor) building).basePhyStats().setArmor(armordmg + (abilityCode() - 1)); setWearLocation(building, misctype, 0); } else if (building instanceof Container) { if (capacity > 0) { ((Container) building).setCapacity(capacity + woodRequired); ((Container) building).setContainTypes(canContain); } if (misctype.equalsIgnoreCase("LID")) ((Container) building).setLidsNLocks(true, false, false, false); else if (misctype.equalsIgnoreCase("LOCK")) { ((Container) building).setLidsNLocks(true, false, true, false); ((Container) building).setKeyName(Double.toString(Math.random())); key = CMClass.getItem("GenKey"); ((DoorKey) key).setKey(((Container) building).keyName()); key.setName("a key"); key.setDisplayText("a small key sits here"); key.setDescription("looks like a key to " + building.name()); key.recoverPhyStats(); key.text(); } } if (building instanceof Rideable) { setRideBasis((Rideable) building, misctype); } building.recoverPhyStats(); building.text(); building.recoverPhyStats(); } messedUp = !proficiencyCheck(mob, 0, auto); if (bundling) { messedUp = false; duration = 1; verb = "bundling " + RawMaterial.CODES.NAME(building.material()).toLowerCase(); startStr = "<S-NAME> start(s) " + verb + "."; displayText = "You are " + verb; } if (autoGenerate > 0) { if (key != null) commands.addElement(key); commands.addElement(building); return true; } CMMsg msg = CMClass.getMsg(mob, building, this, CMMsg.MSG_NOISYMOVEMENT, startStr); if (mob.location().okMessage(mob, msg)) { mob.location().send(mob, msg); building = (Item) msg.target(); beneficialAffect(mob, mob, asLevel, duration); enhanceItem(mob, building, enhancedTypes); } else if (bundling) { messedUp = false; aborted = false; unInvoke(); } return true; }
public boolean invoke(MOB mob, Vector commands, Physical givenTarget, boolean auto, int asLevel) { String s = CMParms.combine(commands, 0); StringBuffer buf = new StringBuffer("Seed types known:\n\r"); int material = 0; String foundShortName = null; int col = 0; List<Integer> codes = RawMaterial.CODES.COMPOSE_RESOURCES(RawMaterial.MATERIAL_VEGETATION); for (Integer code : codes) { if (!CMParms.contains(Chant_SummonSeed.NON_SEEDS, code)) { String str = RawMaterial.CODES.NAME(code.intValue()); if (str.toUpperCase().equalsIgnoreCase(s)) { material = code.intValue(); foundShortName = CMStrings.capitalizeAndLower(str); break; } if (col == 4) { buf.append("\n\r"); col = 0; } col++; buf.append(CMStrings.padRight(CMStrings.capitalizeAndLower(str), 15)); } } if (s.equalsIgnoreCase("list")) { mob.tell(buf.toString() + "\n\r\n\r"); return true; } if (s.length() == 0) { mob.tell("Summon what kind of seed? Try LIST as a parameter..."); return false; } if (foundShortName == null) { mob.tell("'" + s + "' is an unknown type of vegetation."); return false; } if (!super.invoke(mob, commands, givenTarget, auto, asLevel)) return false; // now see if it worked boolean success = proficiencyCheck(mob, 0, auto); if (success) { CMMsg msg = CMClass.getMsg( mob, null, this, verbalCastCode(mob, null, auto), auto ? "" : "^S<S-NAME> chant(s) to <S-HIS-HER> hands.^?"); if (mob.location().okMessage(mob, msg)) { mob.location().send(mob, msg); for (int i = 2; i < (2 + (adjustedLevel(mob, asLevel) / 4)); i++) { Item newItem = CMClass.getBasicItem("GenResource"); String name = foundShortName.toLowerCase(); if (name.endsWith("ies")) name = name.substring(0, name.length() - 3) + "y"; if (name.endsWith("s")) name = name.substring(0, name.length() - 1); newItem.setName(CMLib.english().startWithAorAn(name + " seed")); newItem.setDisplayText(newItem.name() + " is here."); newItem.setDescription(""); newItem.setMaterial(material); newItem.basePhyStats().setWeight(0); newItem.recoverPhyStats(); newItem.setMiscText(newItem.text()); mob.addItem(newItem); } mob.location().showHappens(CMMsg.MSG_OK_ACTION, "Some seeds appear!"); mob.location().recoverPhyStats(); } } else return beneficialWordsFizzle( mob, null, "<S-NAME> chant(s) to <S-HIS-HER> hands, but nothing happens."); // return whether it worked return success; }