@Override public String getStat(String code) { if (CMLib.coffeeMaker().getGenItemCodeNum(code) >= 0) return CMLib.coffeeMaker().getGenItemStat(this, code); switch (getCodeNum(code)) { case 0: return "" + hasALock(); case 1: return "" + hasADoor(); case 2: return "" + capacity(); case 3: return "" + containTypes(); case 4: return "" + openDelayTicks(); case 5: return "" + getClothingLayer(); case 6: return "" + getLayerAttributes(); case 7: return "" + defaultsClosed(); case 8: return "" + defaultsLocked(); default: return CMProps.getStatCodeExtensionValue(getStatCodes(), xtraValues, code); } }
@Override public String text() { if (CMProps.getBoolVar(CMProps.Bool.MOBCOMPRESS)) miscText = CMLib.encoder().compressString(CMLib.coffeeMaker().getPropertiesStr(this, false)); else miscText = CMLib.coffeeMaker().getPropertiesStr(this, false); return super.text(); }
@Override public void setStat(String code, String val) { if (CMLib.coffeeMaker().getGenMobCodeNum(code) >= 0) CMLib.coffeeMaker().setGenMobStat(this, code, val); else switch (getCodeNum(code)) { case 0: setClericRequirements(val); break; case 1: setClericRitual(val); break; case 2: setWorshipRequirements(val); break; case 3: setWorshipRitual(val); break; case 4: setServiceRitual(val); break; default: CMProps.setStatCodeExtensionValue(getStatCodes(), xtraValues, code, val); break; } }
public void setStat(String code, String val) { if (CMLib.coffeeMaker().getGenItemCodeNum(code) >= 0) CMLib.coffeeMaker().setGenItemStat(this, code, val); else switch (getCodeNum(code)) { case 0: setLidsNLocks(hasALid(), isOpen(), CMath.s_bool(val), false); break; case 1: setLidsNLocks(CMath.s_bool(val), isOpen(), hasALock(), false); break; case 2: setCapacity(CMath.s_parseIntExpression(val)); break; case 3: setContainTypes(CMath.s_parseBitLongExpression(Container.CONTAIN_DESCS, val)); break; case 4: { int x = CMath.s_parseListIntExpression(RawMaterial.CODES.NAMES(), val); x = ((x >= 0) && (x < RawMaterial.RESOURCE_MASK)) ? RawMaterial.CODES.GET(x) : x; setFuelType(x); break; } case 5: setPowerCapacity(CMath.s_parseLongExpression(val)); break; default: CMProps.setStatCodeExtensionValue(getStatCodes(), xtraValues, code, val); break; } }
@Override public void setStat(String code, String val) { if (CMLib.coffeeMaker().getGenItemCodeNum(code) >= 0) CMLib.coffeeMaker().setGenItemStat(this, code, val); else switch (getCodeNum(code)) { case 0: setDoorsNLocks( hasADoor(), isOpen(), defaultsClosed(), CMath.s_bool(val), false, CMath.s_bool(val) && defaultsLocked()); break; case 1: setDoorsNLocks( CMath.s_bool(val), isOpen(), CMath.s_bool(val) && defaultsClosed(), hasALock(), false, defaultsLocked()); break; case 2: setCapacity(CMath.s_parseIntExpression(val)); break; case 3: setContainTypes(CMath.s_parseBitLongExpression(Container.CONTAIN_DESCS, val)); break; case 4: setOpenDelayTicks(CMath.s_parseIntExpression(val)); break; case 5: setClothingLayer((short) CMath.s_parseIntExpression(val)); break; case 6: setLayerAttributes((short) CMath.s_parseListLongExpression(Armor.LAYERMASK_DESCS, val)); break; case 7: setDoorsNLocks( hasADoor(), isOpen(), CMath.s_bool(val), hasALock(), isLocked(), defaultsLocked()); break; case 8: setDoorsNLocks( hasADoor(), isOpen(), defaultsClosed(), hasALock(), isLocked(), CMath.s_bool(val)); break; default: CMProps.setStatCodeExtensionValue(getStatCodes(), xtraValues, code, val); break; } }
@Override public String getStat(String code) { if (CMLib.coffeeMaker().getGenItemCodeNum(code) >= 0) return CMLib.coffeeMaker().getGenItemStat(this, code); switch (getCodeNum(code)) { case 0: return "" + getClothingLayer(); case 1: return "" + getLayerAttributes(); default: return CMProps.getStatCodeExtensionValue(getStatCodes(), xtraValues, code); } }
@Override public void setStat(String code, String val) { if (CMLib.coffeeMaker().getGenItemCodeNum(code) >= 0) CMLib.coffeeMaker().setGenItemStat(this, code, val); else switch (getCodeNum(code)) { case 0: setClothingLayer((short) CMath.s_parseIntExpression(val)); break; case 1: setLayerAttributes((short) CMath.s_parseListLongExpression(Armor.LAYERMASK_DESCS, val)); break; default: CMProps.setStatCodeExtensionValue(getStatCodes(), xtraValues, code, val); break; } }
@Override public String getStat(String code) { if (CMLib.coffeeMaker().getGenItemCodeNum(code) >= 0) return CMLib.coffeeMaker().getGenItemStat(this, code); switch (getCodeNum(code)) { case 0: return "" + hasALock(); case 1: return "" + hasADoor(); case 2: return "" + capacity(); case 3: return "" + containTypes(); case 4: return "" + openDelayTicks(); case 5: return "" + powerCapacity(); case 6: { final StringBuilder str = new StringBuilder(""); for (int i = 0; i < getConsumedFuelTypes().length; i++) { if (i > 0) str.append(", "); str.append(RawMaterial.CODES.NAME(getConsumedFuelTypes()[i])); } return str.toString(); } case 7: return "" + powerRemaining(); case 8: return "" + getGeneratedAmountPerTick(); case 9: return "" + activated(); case 10: return "" + getManufacturerName(); case 11: return "" + getInstalledFactor(); case 12: return "" + defaultsClosed(); case 13: return "" + defaultsLocked(); default: return CMProps.getStatCodeExtensionValue(getStatCodes(), xtraValues, code); } }
@Override public String getStat(String code) { if (CMLib.coffeeMaker().getGenMobCodeNum(code) >= 0) return CMLib.coffeeMaker().getGenMobStat(this, code); switch (getCodeNum(code)) { case 0: return getClericRequirements(); case 1: return getClericRitual(); case 2: return getWorshipRequirements(); case 3: return getWorshipRitual(); case 4: return getServiceRitual(); default: return CMProps.getStatCodeExtensionValue(getStatCodes(), xtraValues, code); } }
public String getStat(String code) { if (CMLib.coffeeMaker().getGenItemCodeNum(code) >= 0) return CMLib.coffeeMaker().getGenItemStat(this, code); switch (getCodeNum(code)) { case 0: return "" + hasALock(); case 1: return "" + hasALid(); case 2: return "" + capacity(); case 3: return "" + containTypes(); case 4: return "" + fuelType(); case 5: return "" + powerCapacity(); default: return CMProps.getStatCodeExtensionValue(getStatCodes(), xtraValues, code); } }
@Override public void setStat(String code, String val) { if (CMLib.coffeeMaker().getGenMobCodeNum(code) >= 0) CMLib.coffeeMaker().setGenMobStat(this, code, val); else switch (getCodeNum(code)) { case 0: { if ((val.length() == 0) || (CMath.isLong(val))) setWhatIsSoldMask(CMath.s_long(val)); else if (CMParms.containsIgnoreCase(ShopKeeper.DEAL_DESCS, val)) setWhatIsSoldMask(CMParms.indexOfIgnoreCase(ShopKeeper.DEAL_DESCS, val)); break; } case 1: setPrejudiceFactors(val); break; case 2: setBudget(val); break; case 3: setDevalueRate(val); break; case 4: setInvResetRate(CMath.s_parseIntExpression(val)); break; case 5: setIgnoreMask(val); break; case 6: setItemPricingAdjustments( (val.trim().length() == 0) ? new String[0] : CMParms.toStringArray(CMParms.parseCommas(val, true))); break; default: CMProps.setStatCodeExtensionValue(getStatCodes(), xtraValues, code, val); break; } }
@Override public String getStat(String code) { if (CMLib.coffeeMaker().getGenMobCodeNum(code) >= 0) return CMLib.coffeeMaker().getGenMobStat(this, code); switch (getCodeNum(code)) { case 0: return "" + getWhatIsSoldMask(); case 1: return prejudiceFactors(); case 2: return budget(); case 3: return devalueRate(); case 4: return "" + invResetRate(); case 5: return ignoreMask(); case 6: return CMParms.toStringList(itemPricingAdjustments()); default: return CMProps.getStatCodeExtensionValue(getStatCodes(), xtraValues, code); } }
@Override public void setStat(String code, String val) { if (CMLib.coffeeMaker().getGenItemCodeNum(code) >= 0) CMLib.coffeeMaker().setGenItemStat(this, code, val); CMProps.setStatCodeExtensionValue(getStatCodes(), xtraValues, code, val); }
@Override public String getStat(String code) { if (CMLib.coffeeMaker().getGenItemCodeNum(code) >= 0) return CMLib.coffeeMaker().getGenItemStat(this, code); return CMProps.getStatCodeExtensionValue(getStatCodes(), xtraValues, code); }
@Override public void setMiscText(String newText) { miscText = ""; CMLib.coffeeMaker().setPropertiesStr(this, newText, false); recoverPhyStats(); }
@Override public String text() { return CMLib.coffeeMaker().getPropertiesStr(this, false); }
@Override public boolean execute(MOB mob, Vector commands, int metaFlags) throws java.io.IOException { final boolean noisy = CMSecurity.isDebugging(CMSecurity.DbgFlag.MERGE); Vector placesToDo = new Vector(); commands.remove(0); if (commands.size() == 0) { mob.tell(L("Merge what? Try DATABASE or a filename")); return false; } if (mob.isMonster()) { mob.tell(L("No can do.")); return false; } if ((commands.size() > 0) && ((String) commands.get(0)).equalsIgnoreCase("noprompt")) commands.remove(0); if ((commands.size() > 0) && ((String) commands.get(0)).equalsIgnoreCase("?")) { final StringBuffer allFieldsMsg = new StringBuffer(""); final Vector allKnownFields = new Vector(); sortEnumeratedList(CMClass.mobTypes(), allKnownFields, allFieldsMsg); sortEnumeratedList(CMClass.basicItems(), allKnownFields, allFieldsMsg); sortEnumeratedList(CMClass.weapons(), allKnownFields, allFieldsMsg); sortEnumeratedList(CMClass.armor(), allKnownFields, allFieldsMsg); sortEnumeratedList(CMClass.clanItems(), allKnownFields, allFieldsMsg); sortEnumeratedList(CMClass.miscMagic(), allKnownFields, allFieldsMsg); sortEnumeratedList(CMClass.tech(), allKnownFields, allFieldsMsg); mob.tell(L("Valid field names are @x1", allFieldsMsg.toString())); return false; } String scope = "WORLD"; if ((commands.size() > 0) && ((String) commands.get(0)).equalsIgnoreCase("room")) { if (!CMSecurity.isAllowed(mob, mob.location(), CMSecurity.SecFlag.MERGE)) { mob.tell(L("You are not allowed to do that here.")); return false; } commands.remove(0); placesToDo.add(mob.location()); scope = "ROOM"; } if ((commands.size() > 0) && ((String) commands.get(0)).equalsIgnoreCase("area")) { if (!CMSecurity.isAllowed(mob, mob.location(), CMSecurity.SecFlag.MERGE)) { mob.tell(L("You are not allowed to do that here.")); return false; } commands.remove(0); placesToDo.add(mob.location().getArea()); scope = "AREA"; } if ((commands.size() > 0) && ((String) commands.get(0)).equalsIgnoreCase("world")) { if (!CMSecurity.isAllowedEverywhere(mob, CMSecurity.SecFlag.MERGE)) { mob.tell(L("You are not allowed to do that.")); return false; } commands.remove(0); placesToDo = new Vector(); scope = "WORLD"; } if (commands.size() == 0) { mob.tell(L("Merge what? DATABASE or filename")); return false; } String firstWord = (String) commands.get(0); if (firstWord.equalsIgnoreCase("DATABASE")) { commands.remove(0); if (commands.size() == 0) { mob.tell(L("Merge parameters missing: DBCLASS, DBSERVICE, DBUSER, DBPASS")); return false; } firstWord = (String) commands.get(0); return doArchonDBCompare(mob, scope, firstWord, commands); } final String filename = (String) commands.lastElement(); commands.remove(filename); final StringBuffer buf = new CMFile(filename, mob, CMFile.FLAG_LOGERRORS).text(); if ((buf == null) || (buf.length() == 0)) { mob.tell(L("File not found at: '@x1'!", filename)); return false; } final List<String> changes = new Vector(); final List<String> onfields = new Vector(); final List<String> ignore = new Vector(); List<String> use = null; final List<String> allKnownFields = new Vector(); final List things = new Vector(); boolean aremobs = false; if ((buf.length() > 20) && (buf.substring(0, 20).indexOf("<MOBS>") >= 0)) { if (mob.session() != null) mob.session().rawPrint(L("Unpacking mobs from file: '@x1'...", filename)); final String error = CMLib.coffeeMaker().addMOBsFromXML(buf.toString(), things, mob.session()); if (mob.session() != null) mob.session().rawPrintln("!"); if (error.length() > 0) { mob.tell(L("An error occurred on merge: @x1", error)); mob.tell(L("Please correct the problem and try the import again.")); return false; } aremobs = true; } else if ((buf.length() > 20) && (buf.substring(0, 20).indexOf("<ITEMS>") >= 0)) { if (mob.session() != null) mob.session().rawPrint(L("Unpacking items from file: '@x1'...", filename)); final String error = CMLib.coffeeMaker().addItemsFromXML(buf.toString(), things, mob.session()); if (mob.session() != null) mob.session().rawPrintln("!"); if (error.length() > 0) { mob.tell(L("An error occurred on merge: @x1", error)); mob.tell(L("Please correct the problem and try the import again.")); return false; } } else { mob.tell( L( "Files of this type are not yet supported by MERGE. You must merge an ITEMS or MOBS file at this time.")); return false; } if (things.size() == 0) { mob.tell(L("Nothing was found in the file to merge!")); return false; } final StringBuffer allFieldsMsg = new StringBuffer(""); if (aremobs) sortEnumeratedList(CMClass.mobTypes(), allKnownFields, allFieldsMsg); else { sortEnumeratedList(CMClass.basicItems(), allKnownFields, allFieldsMsg); sortEnumeratedList(CMClass.weapons(), allKnownFields, allFieldsMsg); sortEnumeratedList(CMClass.armor(), allKnownFields, allFieldsMsg); sortEnumeratedList(CMClass.clanItems(), allKnownFields, allFieldsMsg); sortEnumeratedList(CMClass.miscMagic(), allKnownFields, allFieldsMsg); sortEnumeratedList(CMClass.tech(), allKnownFields, allFieldsMsg); } allKnownFields.add("REJUV"); allFieldsMsg.append(L("REJUV ")); for (int i = 0; i < commands.size(); i++) { String str = ((String) commands.get(i)).toUpperCase(); if (str.startsWith("CHANGE=")) { use = changes; str = str.substring(7).trim(); } if (str.startsWith("ON=")) { use = onfields; str = str.substring(3).trim(); } if (str.startsWith("IGNORE=")) { use = ignore; str = str.substring(7).trim(); } int x = str.indexOf(','); while (x >= 0) { final String s = str.substring(0, x).trim(); if (s.length() > 0) { if (use == null) { mob.tell(L("'@x1' is an unknown parameter!", str)); return false; } if (allKnownFields.contains(s)) use.add(s); else { mob.tell( L( "'@x1' is an unknown field name. Valid fields include: @x2", s, allFieldsMsg.toString())); return false; } } str = str.substring(x + 1).trim(); x = str.indexOf(','); } if (str.length() > 0) { if (use == null) { mob.tell(L("'@x1' is an unknown parameter!", str)); return false; } if (allKnownFields.contains(str)) use.add(str); else { mob.tell( L( "'@x1' is an unknown field name. Valid fields include: @x2", str, allFieldsMsg.toString())); return false; } } } if ((onfields.size() == 0) && (ignore.size() == 0) && (changes.size() == 0)) { mob.tell( L( "You must specify either an ON, CHANGES, or IGNORE parameter for valid matches to be made.")); return false; } if (placesToDo.size() == 0) for (final Enumeration a = CMLib.map().areas(); a.hasMoreElements(); ) { final Area A = (Area) a.nextElement(); if (A.getCompleteMap().hasMoreElements() && CMSecurity.isAllowed( mob, (A.getCompleteMap().nextElement()), CMSecurity.SecFlag.MERGE)) placesToDo.add(A); } if (placesToDo.size() == 0) { mob.tell(L("There are no rooms to merge into!")); return false; } for (int i = placesToDo.size() - 1; i >= 0; i--) { if (placesToDo.get(i) instanceof Area) { final Area A = (Area) placesToDo.get(i); placesToDo.removeElement(A); for (final Enumeration r = A.getCompleteMap(); r.hasMoreElements(); ) { final Room R = (Room) r.nextElement(); if (CMSecurity.isAllowed(mob, R, CMSecurity.SecFlag.MERGE)) placesToDo.add(R); } } else if (placesToDo.get(i) instanceof Room) if (mob.session() != null) mob.session().rawPrint("."); else return false; } // now do the merge... if (mob.session() != null) mob.session().rawPrint(L("Merging and saving...")); if (noisy) mergedebugtell(mob, "Rooms to do: " + placesToDo.size()); if (noisy) mergedebugtell(mob, "Things loaded: " + things.size()); if (noisy) mergedebugtell(mob, "On fields=" + CMParms.toStringList(onfields)); if (noisy) mergedebugtell(mob, "Ignore fields=" + CMParms.toStringList(ignore)); if (noisy) mergedebugtell(mob, "Change fields=" + CMParms.toStringList(changes)); Log.sysOut("Import", mob.Name() + " merge '" + filename + "'."); for (int r = 0; r < placesToDo.size(); r++) { Room R = (Room) placesToDo.get(r); if (!CMSecurity.isAllowed(mob, R, CMSecurity.SecFlag.MERGE)) continue; if (R.roomID().length() == 0) continue; synchronized (("SYNC" + R.roomID()).intern()) { R = CMLib.map().getRoom(R); final Area.State oldFlags = R.getArea().getAreaState(); R.getArea().setAreaState(Area.State.FROZEN); CMLib.map().resetRoom(R); boolean savemobs = false; boolean saveitems = false; if (aremobs) { for (int m = 0; m < R.numInhabitants(); m++) { final MOB M = R.fetchInhabitant(m); if ((M != null) && (M.isSavable())) if (tryMerge(mob, R, M, things, changes, onfields, ignore, noisy)) savemobs = true; } } else { for (int i = 0; i < R.numItems(); i++) { final Item I = R.getItem(i); if ((I != null) && (tryMerge(mob, R, I, things, changes, onfields, ignore, noisy))) saveitems = true; } for (int m = 0; m < R.numInhabitants(); m++) { final MOB M = R.fetchInhabitant(m); if ((M != null) && (M.isSavable())) { for (int i = 0; i < M.numItems(); i++) { final Item I = M.getItem(i); if ((I != null) && (tryMerge(mob, R, I, things, changes, onfields, ignore, noisy))) savemobs = true; } final ShopKeeper SK = CMLib.coffeeShops().getShopKeeper(M); if (SK != null) { for (final Iterator<Environmental> i = SK.getShop().getStoreInventory(); i.hasNext(); ) { final Environmental E = i.next(); if (E instanceof Item) { final Item I = (Item) E; if (tryMerge(mob, R, I, things, changes, onfields, ignore, noisy)) savemobs = true; } } } } } } if (saveitems) CMLib.database().DBUpdateItems(R); if (savemobs) CMLib.database().DBUpdateMOBs(R); if (mob.session() != null) mob.session().rawPrint("."); R.getArea().setAreaState(oldFlags); } } if (mob.session() != null) mob.session().rawPrintln(L("!\n\rDone!")); Area A = null; for (int i = 0; i < placesToDo.size(); i++) { A = ((Room) placesToDo.get(i)).getArea(); if ((A != null) && (A.getAreaState() != Area.State.ACTIVE)) A.setAreaState(Area.State.ACTIVE); } return false; }
@Override public void setMiscText(String newText) { super.setMiscText(newText); CMLib.coffeeMaker().resetGenMOB(this, newText); }
@Override public void setStat(String code, String val) { if (CMLib.coffeeMaker().getGenItemCodeNum(code) >= 0) CMLib.coffeeMaker().setGenItemStat(this, code, val); else switch (getCodeNum(code)) { case 0: setDoorsNLocks( hasADoor(), isOpen(), defaultsClosed(), CMath.s_bool(val), false, CMath.s_bool(val) && defaultsLocked()); break; case 1: setDoorsNLocks( CMath.s_bool(val), isOpen(), CMath.s_bool(val) && defaultsClosed(), hasALock(), isLocked(), defaultsLocked()); break; case 2: setCapacity(CMath.s_parseIntExpression(val)); break; case 3: setContainTypes(CMath.s_parseBitLongExpression(Container.CONTAIN_DESCS, val)); break; case 4: setOpenDelayTicks(CMath.s_parseIntExpression(val)); break; case 5: setPowerCapacity(CMath.s_parseLongExpression(val)); break; case 6: { final List<String> mats = CMParms.parseCommas(val, true); final int[] newMats = new int[mats.size()]; for (int x = 0; x < mats.size(); x++) { final int rsccode = RawMaterial.CODES.FIND_CaseSensitive(mats.get(x).trim()); if (rsccode > 0) newMats[x] = rsccode; } super.setConsumedFuelType(newMats); break; } case 7: setPowerCapacity(CMath.s_parseLongExpression(val)); break; case 8: setGeneratedAmountPerTick(CMath.s_parseIntExpression(val)); break; case 9: activate(CMath.s_bool(val)); break; case 10: setManufacturerName(val); break; case 11: setInstalledFactor(CMath.s_float(val)); break; case 12: setDoorsNLocks( hasADoor(), isOpen(), CMath.s_bool(val), hasALock(), isLocked(), defaultsLocked()); break; case 13: setDoorsNLocks( hasADoor(), isOpen(), defaultsClosed(), hasALock(), isLocked(), CMath.s_bool(val)); break; default: CMProps.setStatCodeExtensionValue(getStatCodes(), xtraValues, code, val); break; } }