public DVector parseLootPolicyFor(MOB mob) { if (mob == null) return new DVector(3); Vector lootPolicy = (!mob.isMonster()) ? new Vector() : CMParms.parseCommas(CMProps.getVar(CMProps.SYSTEM_ITEMLOOTPOLICY), true); DVector policies = new DVector(3); for (int p = 0; p < lootPolicy.size(); p++) { String s = ((String) lootPolicy.elementAt(p)).toUpperCase().trim(); if (s.length() == 0) continue; Vector compiledMask = null; int maskDex = s.indexOf("MASK="); if (maskDex >= 0) { s = s.substring(0, maskDex).trim(); compiledMask = CMLib.masking() .maskCompile(((String) lootPolicy.elementAt(p)).substring(maskDex + 5).trim()); } else compiledMask = new Vector(); Vector parsed = CMParms.parse(s); int pct = 100; for (int x = 0; x < parsed.size(); x++) if (CMath.isInteger((String) parsed.elementAt(x))) pct = CMath.s_int((String) parsed.elementAt(x)); else if (CMath.isPct((String) parsed.elementAt(x))) pct = (int) Math.round(CMath.s_pct((String) parsed.elementAt(x)) * 100.0); int flags = 0; if (parsed.contains("RUIN")) flags |= CMMiscUtils.LOOTFLAG_RUIN; else if (parsed.contains("LOSS")) flags |= CMMiscUtils.LOOTFLAG_LOSS; if (flags == 0) flags |= CMMiscUtils.LOOTFLAG_LOSS; if (parsed.contains("WORN")) flags |= CMMiscUtils.LOOTFLAG_WORN; else if (parsed.contains("UNWORN")) flags |= CMMiscUtils.LOOTFLAG_UNWORN; policies.addElement(Integer.valueOf(pct), Integer.valueOf(flags), compiledMask); } return policies; }
private void clearAbilityFromSpellcraftList(MOB mob, Ability A) { final Ability enabledA = mob.fetchAbility("Skill_Spellcraft"); if (enabledA != null) { final List<String> ables = CMParms.parseCommas(enabledA.text(), true); if (ables.contains(A.ID())) { if (!CMSecurity.isAllowed(mob, mob.location(), CMSecurity.SecFlag.ALLSKILLS)) { ables.remove(A.ID()); enabledA.setMiscText(CMParms.toListString(ables)); mob.delAbility(A); } } } }
private void addAbilityToSpellcraftList(MOB mob, Ability A) { final Ability enabledA = mob.fetchAbility("Skill_Spellcraft"); if (enabledA != null) { final List<String> ables = CMParms.parseCommas(enabledA.text(), true); if (!ables.contains(A.ID())) { if (enabledA.text().length() == 0) enabledA.setMiscText(A.ID()); else enabledA.setMiscText(enabledA.text() + ", " + A.ID()); mob.addAbility(A); } else if (mob.isMine(A) && (A.proficiency() < 75) && (!A.isSavable())) A.setProficiency( A.proficiency() + (mob.baseCharStats().getStat(CharStats.STAT_INTELLIGENCE) / 3)); } }
@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; } }
public boolean doArchonDBCompare(MOB mob, String scope, String firstWord, Vector commands) throws java.io.IOException { CMClass.CMObjectType doType = OBJECT_TYPES.get(firstWord.toUpperCase()); if (doType == null) doType = OBJECT_TYPES.get(firstWord.toUpperCase() + "S"); if (doType != null) commands.remove(0); else doType = CMClass.CMObjectType.LOCALE; final String theRest = CMParms.combineQuoted(commands, 0); DBConnector dbConnector = null; final String dbClass = CMParms.getParmStr(theRest, "DBCLASS", ""); final String dbService = CMParms.getParmStr(theRest, "DBSERVICE", ""); final String dbUser = CMParms.getParmStr(theRest, "DBUSER", ""); final String dbPass = CMParms.getParmStr(theRest, "DBPASS", ""); final int dbConns = CMParms.getParmInt(theRest, "DBCONNECTIONS", 3); final int dbPingIntMins = CMParms.getParmInt(theRest, "DBPINGINTERVALMINS", 30); final boolean dbReuse = CMParms.getParmBool(theRest, "DBREUSE", true); final String ignore = CMParms.getParmStr(theRest, "IGNORE", ""); final String maskStr = CMParms.getParmStr(theRest, "MASK", ""); final Set<String> ignores = new SHashSet(CMParms.parseCommas(ignore.toUpperCase(), true)); final MaskingLibrary.CompiledZapperMask mask = CMLib.masking().maskCompile(maskStr); if (dbClass.length() == 0) { mob.tell(L("This command requires DBCLASS= to be set.")); return false; } if (dbService.length() == 0) { mob.tell(L("This command requires DBSERVICE= to be set.")); return false; } if (dbUser.length() == 0) { mob.tell(L("This command requires DBUSER= to be set.")); return false; } if (dbPass.length() == 0) { mob.tell(L("This command requires DBPASS= to be set.")); return false; } dbConnector = new DBConnector( dbClass, dbService, dbUser, dbPass, dbConns, dbPingIntMins, dbReuse, false, false); dbConnector.reconnect(); final DBInterface dbInterface = new DBInterface(dbConnector, null); final DBConnection DBTEST = dbConnector.DBFetch(); if (DBTEST != null) dbConnector.DBDone(DBTEST); mob.tell(L("Loading database rooms...")); final List<Room> rooms = new LinkedList<Room>(); if ((!dbConnector.amIOk()) || (!dbInterface.isConnected())) { mob.tell(L("Failed to connect to database.")); return false; } if (scope.equalsIgnoreCase("AREA")) rooms.addAll( Arrays.asList(dbInterface.DBReadRoomObjects(mob.location().getArea().Name(), false))); else if (scope.equalsIgnoreCase("ROOM")) { final Room R = dbInterface.DBReadRoomObject(mob.location().roomID(), false); if (R != null) rooms.add(R); } else for (final Enumeration<Area> e = CMLib.map().areas(); e.hasMoreElements(); ) rooms.addAll(Arrays.asList(dbInterface.DBReadRoomObjects(e.nextElement().Name(), false))); if (rooms.size() == 0) { mob.tell(L("No rooms found.")); return false; } for (final Room R : rooms) dbInterface.DBReadContent(R.roomID(), R, false); mob.tell(L("Data loaded, starting scan.")); final Comparator<MOB> convM = new Comparator<MOB>() { @Override public int compare(MOB arg0, MOB arg1) { final int x = arg0.ID().compareTo(arg1.ID()); return (x != 0) ? x : arg0.Name().compareTo(arg1.Name()); } }; final Comparator<Item> convI = new Comparator<Item>() { @Override public int compare(Item arg0, Item arg1) { final int x = arg0.ID().compareTo(arg1.ID()); return (x != 0) ? x : arg0.Name().compareTo(arg1.Name()); } }; try { for (final Room dbR : rooms) { Room R = CMLib.map().getRoom(dbR.roomID()); if (R == null) { if (doType == CMClass.CMObjectType.LOCALE) Log.sysOut("Merge", dbR.roomID() + " not in database"); // import, including exits! continue; } synchronized (("SYNC" + dbR.roomID()).intern()) { final Area.State oldFlags = R.getArea().getAreaState(); R.getArea().setAreaState(Area.State.FROZEN); boolean updateMobs = false; boolean updateItems = false; final boolean updateRoom = false; R = CMLib.map().getRoom(R); CMLib.map().resetRoom(R); final List<MOB> mobSetL = new Vector<MOB>(); for (final Enumeration<MOB> e = dbR.inhabitants(); e.hasMoreElements(); ) mobSetL.add(e.nextElement()); final MOB[] mobSet = mobSetL.toArray(new MOB[0]); Arrays.sort(mobSet, convM); String lastName = ""; int ct = 1; final HashSet<MOB> doneM = new HashSet<MOB>(); for (final MOB dbM : mobSet) { if (!lastName.equals(dbM.Name())) ct = 1; else ct++; final String rName = dbM.Name() + "." + ct; MOB M = null; int ctr = ct; for (final Enumeration<MOB> m = R.inhabitants(); m.hasMoreElements(); ) { final MOB M1 = m.nextElement(); if (M1.Name().equalsIgnoreCase(dbM.Name()) && ((--ctr) <= 0)) { M = M1; break; } } if (M == null) { if (amMerging(doType, mask, dbM) && (!ignore.contains("MISSING"))) { if (mob.session() .confirm( L( "MOB: @x1.@x2 not in local room.\n\rWould you like to add it (y/N)?", dbR.roomID(), rName), L("N"))) { M = (MOB) dbM.copyOf(); M.bringToLife(R, true); doneM.add(M); updateMobs = true; Log.sysOut("Merge", mob.Name() + " added mob " + dbR.roomID() + "." + rName); } } } else { doneM.add(M); if (amMerging(doType, mask, dbM)) { if (!dbM.sameAs(M)) { final MOB oldM = (MOB) M.copyOf(); if ((dbMerge(mob, "^MMOB " + dbR.roomID() + "." + rName + "^N", dbM, M, ignores)) && (!oldM.sameAs(M))) { Log.sysOut("Merge", mob.Name() + " modified mob " + dbR.roomID() + "." + rName); updateMobs = true; } } } final STreeSet<Item> itemSetL = new STreeSet<Item>(convI); for (final Enumeration<Item> e = dbM.items(); e.hasMoreElements(); ) itemSetL.add(e.nextElement()); final Item[] itemSet = itemSetL.toArray(new Item[0]); Arrays.sort(itemSet, convI); String lastIName = ""; int ict = 1; final HashSet<Item> doneI = new HashSet<Item>(); for (final Item dbI : itemSet) { if (!lastIName.equals(dbI.Name())) ict = 1; else ict++; final String rIName = dbI.Name() + "." + ict; Item I = null; ctr = ict; for (final Enumeration<Item> i = M.items(); i.hasMoreElements(); ) { final Item I1 = i.nextElement(); if (I1.Name().equalsIgnoreCase(dbI.Name()) && ((--ctr) <= 0)) { I = I1; break; } } if (I == null) { if (amMerging(doType, mask, dbI) && (!ignore.contains("MISSING"))) { if (mob.session() .confirm( L( "Item: @x1.@x2.@x3 not in local room.\n\rWould you like to add it (y/N)?", dbR.roomID(), dbM.Name(), rIName), L("N"))) { I = (Item) dbI.copyOf(); M.addItem(I); doneI.add(I); final Item cI = (dbI.container() == null) ? null : M.findItem(dbI.container().Name()); if (cI instanceof Container) I.setContainer((Container) cI); updateMobs = true; Log.sysOut( "Merge", mob.Name() + " added item " + dbR.roomID() + "." + dbM.Name() + "." + rIName); } } } else if (amMerging(doType, mask, dbI)) { doneI.add(I); if (!dbI.sameAs(I)) { final Item oldI = (Item) I.copyOf(); if ((dbMerge( mob, "^IITEM ^M" + dbR.roomID() + "." + dbM.Name() + "." + rIName + "^N", dbI, I, ignores)) && (!oldI.sameAs(I))) { Log.sysOut( "Merge", mob.Name() + " modified item " + dbR.roomID() + "." + dbM.Name() + "." + rIName); updateMobs = true; } } } lastIName = dbI.Name(); } for (final Enumeration<Item> i = M.items(); i.hasMoreElements(); ) { final Item I = i.nextElement(); if (amMerging(doType, mask, I) && (!doneI.contains(I)) && (!ignore.contains("EXTRA"))) { if (mob.session() .confirm( L( "Item: @x1.@x2.@x3 not in database.\n\rWould you like to delete it (y/N)?", R.roomID(), M.Name(), I.Name()), L("N"))) { M.delItem(I); updateMobs = true; Log.sysOut( "Merge", mob.Name() + " deleted item " + R.roomID() + "." + M.Name() + "." + I.Name()); } } } } lastName = dbM.Name(); } for (final Enumeration<MOB> r = R.inhabitants(); r.hasMoreElements(); ) { final MOB M = r.nextElement(); if (amMerging(doType, mask, M) && (!doneM.contains(M)) && (M.isMonster()) && (!ignore.contains("EXTRA"))) { if (mob.session() .confirm( L( "MOB: @x1.@x2 not in database.\n\rWould you like to delete it (y/N)?", R.roomID(), M.Name()), L("N"))) { R.delInhabitant(M); updateMobs = true; Log.sysOut("Merge", mob.Name() + " deleted mob " + R.roomID() + "." + M.Name()); } } } final STreeSet<Item> itemSetL = new STreeSet<Item>(convI); for (final Enumeration<Item> e = dbR.items(); e.hasMoreElements(); ) itemSetL.add(e.nextElement()); final Item[] itemSet = itemSetL.toArray(new Item[0]); Arrays.sort(itemSet, convI); lastName = ""; ct = 1; final HashSet<Item> doneI = new HashSet<Item>(); for (final Item dbI : itemSet) { if (!lastName.equals(dbI.Name())) ct = 1; else ct++; final String rName = dbI.Name() + "." + ct; Item I = null; int ctr = ct; for (final Enumeration<Item> i = R.items(); i.hasMoreElements(); ) { final Item I1 = i.nextElement(); if (I1.Name().equalsIgnoreCase(dbI.Name()) && ((--ctr) <= 0)) { I = I1; break; } } if (I == null) { if (amMerging(doType, mask, dbI) && (!ignore.contains("MISSING"))) { if (mob.session() .confirm( L( "Item: @x1.@x2 not in local room.\n\rWould you like to add it (y/N)?", dbR.roomID(), rName), L("N"))) { I = (Item) dbI.copyOf(); R.addItem(I); doneI.add(I); final Item cI = (dbI.container() == null) ? null : R.findItem(dbI.container().Name()); if (cI instanceof Container) I.setContainer((Container) cI); updateItems = true; Log.sysOut("Merge", mob.Name() + " added item " + dbR.roomID() + "." + rName); } } } else if (amMerging(doType, mask, dbI)) { doneI.add(I); if (!dbI.sameAs(I)) { final Item oldI = (Item) I.copyOf(); if ((dbMerge(mob, "^IITEM " + dbR.roomID() + "." + rName + "^N", dbI, I, ignores)) && (!oldI.sameAs(I))) { Log.sysOut("Merge", mob.Name() + " modified item " + dbR.roomID() + "." + rName); updateItems = true; } } } lastName = dbI.Name(); } for (final Enumeration<Item> i = R.items(); i.hasMoreElements(); ) { final Item I = i.nextElement(); if (amMerging(doType, mask, I) && (!doneI.contains(I)) && (!ignore.contains("EXTRA"))) { if (mob.session() .confirm( L( "Item: @x1.@x2 not in database.\n\rWould you like to delete it (y/N)?", R.roomID(), I.Name()), L("N"))) { R.delItem(I); updateItems = true; Log.sysOut("Merge", mob.Name() + " deleted item " + R.roomID() + "." + I.Name()); } } } if (updateRoom) CMLib.database().DBUpdateRoom(R); if (updateItems) CMLib.database().DBUpdateItems(R); if (updateMobs) CMLib.database().DBUpdateMOBs(R); CMLib.map().resetRoom(R); R.getArea().setAreaState(oldFlags); } dbR.destroy(); } mob.tell(L("Done")); } catch (final CMException cme) { mob.tell(L("Cancelled.")); } dbInterface.shutdown(); return true; }
@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; } }
public void setStat(String code, String val) { int num = 0; int numDex = code.length(); while ((numDex > 0) && (Character.isDigit(code.charAt(numDex - 1)))) numDex--; if (numDex < code.length()) { num = CMath.s_int(code.substring(numDex)); code = code.substring(0, numDex); } final GOVT_STAT_CODES stat = getStatIndex(code); if (stat == null) { return; } switch (stat) { case NAME: name = val; break; case AUTOROLE: { ClanPosition P = getPosition(val); if (P != null) autoRole = P.getRoleID(); break; } case ACCEPTPOS: { ClanPosition P = getPosition(val); if (P != null) acceptPos = P.getRoleID(); break; } case SHORTDESC: shortDesc = val; break; case LONGDESC: longDesc = val; break; case XPLEVELFORMULA: setXpCalculationFormulaStr(val); break; case REQUIREDMASK: requiredMaskStr = val; break; case ISPUBLIC: isPublic = CMath.s_bool(val); break; case ISFAMILYONLY: isFamilyOnly = CMath.s_bool(val); break; case OVERRIDEMINMEMBERS: { if (val.length() == 0) overrideMinMembers = null; else overrideMinMembers = Integer.valueOf(CMath.s_int(val)); break; } case CONQUESTENABLED: conquestEnabled = CMath.s_bool(val); break; case CONQUESTITEMLOYALTY: conquestItemLoyalty = CMath.s_bool(val); break; case CONQUESTDEITYBASIS: conquestByWorship = CMath.s_bool(val); break; case MAXVOTEDAYS: maxVoteDays = CMath.s_int(val); break; case VOTEQUORUMPCT: voteQuorumPct = CMath.s_int(val); break; case AUTOPROMOTEBY: { Clan.AutoPromoteFlag flag = (Clan.AutoPromoteFlag) CMath.s_valueOf(Clan.AutoPromoteFlag.values(), val); if (flag != null) autoPromoteBy = flag; break; } case VOTEFUNCS: { final Vector<String> funcs = CMParms.parseCommas(val.toUpperCase().trim(), true); for (ClanPosition pos : positions) { for (int a = 0; a < Function.values().length; a++) if (pos.getFunctionChart()[a] == Authority.MUST_VOTE_ON) pos.getFunctionChart()[a] = Authority.CAN_NOT_DO; for (final String funcName : funcs) { Authority auth = (Authority) CMath.s_valueOf(Function.values(), funcName); if (auth != null) pos.getFunctionChart()[auth.ordinal()] = Authority.MUST_VOTE_ON; } } break; } case NUMRABLE: clanAbilityMap = null; if (CMath.s_int(val) == 0) { clanAbilityNames = null; clanAbilityProficiencies = null; clanAbilityQuals = null; clanAbilityLevels = null; } else { clanAbilityNames = new String[CMath.s_int(val)]; clanAbilityProficiencies = new int[CMath.s_int(val)]; clanAbilityQuals = new boolean[CMath.s_int(val)]; clanAbilityLevels = new int[CMath.s_int(val)]; } break; case GETRABLE: { if (clanAbilityNames == null) clanAbilityNames = new String[num + 1]; clanAbilityNames[num] = val; break; } case GETRABLEPROF: { if (clanAbilityProficiencies == null) clanAbilityProficiencies = new int[num + 1]; clanAbilityProficiencies[num] = CMath.s_parseIntExpression(val); break; } case GETRABLEQUAL: { if (clanAbilityQuals == null) clanAbilityQuals = new boolean[num + 1]; clanAbilityQuals[num] = CMath.s_bool(val); break; } case GETRABLELVL: { if (clanAbilityLevels == null) clanAbilityLevels = new int[num + 1]; clanAbilityLevels[num] = CMath.s_parseIntExpression(val); break; } case NUMREFF: clanEffectMap = null; if (CMath.s_int(val) == 0) { clanEffectNames = null; clanEffectParms = null; clanEffectLevels = null; } else { clanEffectNames = new String[CMath.s_int(val)]; clanEffectParms = new String[CMath.s_int(val)]; clanEffectLevels = new int[CMath.s_int(val)]; } break; case GETREFF: { if (clanEffectNames == null) clanEffectNames = new String[num + 1]; clanEffectNames[num] = val; break; } case GETREFFPARM: { if (clanEffectParms == null) clanEffectParms = new String[num + 1]; clanEffectParms[num] = val; break; } case GETREFFLVL: { if (clanEffectLevels == null) clanEffectLevels = new int[num + 1]; clanEffectLevels[num] = CMath.s_int(val); break; } default: Log.errOut("Clan", "setStat:Unhandled:" + stat.toString()); break; } }