Example #1
0
 public static boolean robberyCheck(LandTitle A, CMMsg msg) {
   if (((msg.targetMinor() == CMMsg.TYP_GET) && (!msg.isTarget(CMMsg.MASK_INTERMSG)))
       || (msg.targetMinor() == CMMsg.TYP_PUSH)
       || (msg.targetMinor() == CMMsg.TYP_PULL)) {
     if ((msg.target() instanceof Item)
         && (((Item) msg.target()).owner() == msg.source().location())
         && ((!(msg.tool() instanceof Item)) || (msg.source().isMine(msg.tool())))
         && (!msg.sourceMajor(CMMsg.MASK_ALWAYS))
         && (A.getOwnerName().length() > 0)
         && (msg.source().location() != null)
         && (msg.othersMessage() != null)
         && (msg.othersMessage().length() > 0)
         && (!shopkeeperMobPresent(msg.source().location()))
         && (!CMLib.law().doesHavePriviledgesHere(msg.source(), msg.source().location()))) {
       final Room R = msg.source().location();
       final LegalBehavior B = CMLib.law().getLegalBehavior(R);
       if (B != null) {
         for (int m = 0; m < R.numInhabitants(); m++) {
           final MOB M = R.fetchInhabitant(m);
           if (CMLib.law().doesHavePriviledgesHere(M, R)) return true;
         }
         MOB D = null;
         final Clan C = CMLib.clans().getClan(A.getOwnerName());
         if (C != null) D = C.getResponsibleMember();
         else D = CMLib.players().getLoadPlayer(A.getOwnerName());
         if (D == null) return true;
         B.accuse(
             CMLib.law().getLegalObject(R),
             msg.source(),
             D,
             new String[] {"PROPERTYROB", "THIEF_ROBBERY"});
       }
     }
     return true;
   }
   return false;
 }
Example #2
0
  public static int updateLotWithThisData(
      Room R,
      LandTitle T,
      boolean resetRoomName,
      boolean clearAllItems,
      List optPlayerList,
      int lastNumItems) {
    boolean updateItems = false;
    boolean updateExits = false;
    boolean updateRoom = false;
    synchronized (("SYNC" + R.roomID()).intern()) {
      R = CMLib.map().getRoom(R);
      if (T.getOwnerName().length() == 0) {
        Item I = null;
        for (int i = R.numItems() - 1; i >= 0; i--) {
          I = R.getItem(i);
          if ((I == null) || (I.Name().equalsIgnoreCase("id"))) continue;
          CMLib.catalog().updateCatalogIntegrity(I);
          if (clearAllItems) {
            I.destroy();
            updateItems = true;
          } else {
            if (I.expirationDate() == 0) {
              long now = System.currentTimeMillis();
              now += (TimeManager.MILI_MINUTE * CMProps.getIntVar(CMProps.Int.EXPIRE_PLAYER_DROP));
              I.setExpirationDate(now);
            }
            if ((I.phyStats().rejuv() != PhyStats.NO_REJUV) && (I.phyStats().rejuv() != 0)) {
              I.basePhyStats().setRejuv(PhyStats.NO_REJUV);
              I.recoverPhyStats();
            }
          }
        }
        Ability A = null;
        if (clearAllItems)
          for (final Enumeration<Ability> a = R.effects(); a.hasMoreElements(); ) {
            A = a.nextElement();
            if (((A != null)
                && ((A.classificationCode() & Ability.ALL_ACODES) != Ability.ACODE_PROPERTY))) {
              A.unInvoke();
              R.delEffect(A);
              updateRoom = true;
            }
          }
        for (int d = Directions.NUM_DIRECTIONS() - 1; d >= 0; d--) {
          final Room R2 = R.rawDoors()[d];
          Exit E = R.getRawExit(d);
          if ((E != null) && (E.hasALock()) && (E.isGeneric())) {
            E.setKeyName("");
            E.setDoorsNLocks(E.hasADoor(), E.isOpen(), E.defaultsClosed(), false, false, false);
            updateExits = true;
            if (R2 != null) {
              E = R2.getRawExit(Directions.getOpDirectionCode(d));
              if ((E != null) && (E.hasALock()) && (E.isGeneric())) {
                E.setKeyName("");
                E.setDoorsNLocks(E.hasADoor(), E.isOpen(), E.defaultsClosed(), false, false, false);
                CMLib.database().DBUpdateExits(R2);
                R2.getArea().fillInAreaRoom(R2);
              }
            }
          }
        }
        if (updateExits) {
          CMLib.database().DBUpdateExits(R);
          R.getArea().fillInAreaRoom(R);
        }
        if (updateItems) CMLib.database().DBUpdateItems(R);
        if (updateRoom) CMLib.database().DBUpdateRoom(R);
        colorForSale(R, T.rentalProperty(), resetRoomName);
        return -1;
      }

      if ((lastNumItems < 0)
          && (!CMSecurity.isDisabled(CMSecurity.DisFlag.PROPERTYOWNERCHECKS))
          && (optPlayerList != null)) {
        boolean playerExists = (CMLib.players().getPlayer(T.getOwnerName()) != null);
        if (!playerExists) playerExists = (CMLib.clans().getClan(T.getOwnerName()) != null);
        if (!playerExists) playerExists = optPlayerList.contains(T.getOwnerName());
        if (!playerExists)
          for (int i = 0; i < optPlayerList.size(); i++)
            if (((String) optPlayerList.get(i)).equalsIgnoreCase(T.getOwnerName())) {
              playerExists = true;
              break;
            }
        if (!playerExists) {
          T.setOwnerName("");
          T.updateLot(null);
          return -1;
        }
      }

      int x = R.description().indexOf(SALESTR);
      if (x >= 0) {
        R.setDescription(R.description().substring(0, x));
        CMLib.database().DBUpdateRoom(R);
      }
      x = R.description().indexOf(RENTSTR);
      if (x >= 0) {
        R.setDescription(R.description().substring(0, x));
        CMLib.database().DBUpdateRoom(R);
      }

      // this works on the priciple that
      // 1. if an item has ONLY been removed, the lastNumItems will be != current # items
      // 2. if an item has ONLY been added, the dispossessiontime will be != null
      // 3. if an item has been added AND removed, the dispossession time will be != null on the
      // added
      if ((lastNumItems >= 0) && (R.numItems() != lastNumItems)) updateItems = true;

      for (int i = 0; i < R.numItems(); i++) {
        final Item I = R.getItem(i);
        if ((I.expirationDate() != 0)
            && ((I.isSavable()) || (I.Name().equalsIgnoreCase("id")))
            && ((!(I instanceof DeadBody)) || (((DeadBody) I).isPlayerCorpse()))) {
          I.setExpirationDate(0);
          updateItems = true;
        }

        if ((I.phyStats().rejuv() != Integer.MAX_VALUE) && (I.phyStats().rejuv() != 0)) {
          I.basePhyStats().setRejuv(PhyStats.NO_REJUV);
          I.recoverPhyStats();
          updateItems = true;
        }
      }
      lastNumItems = R.numItems();
      if ((!CMSecurity.isSaveFlag(CMSecurity.SaveFlag.NOPROPERTYITEMS)) && (updateItems))
        CMLib.database().DBUpdateItems(R);
    }
    return lastNumItems;
  }
Example #3
0
  @Override
  public boolean okMessage(final Environmental myHost, final CMMsg msg) {
    if ((clanID().length() > 0) && (msg.amITarget(this))) {
      if (msg.source().getClanRole(clanID()) == null) {
        if ((msg.targetMinor() == CMMsg.TYP_GET)
            || (msg.targetMinor() == CMMsg.TYP_PUSH)
            || (msg.targetMinor() == CMMsg.TYP_PULL)
            || (msg.targetMinor() == CMMsg.TYP_CAST_SPELL)) {
          final Room R = CMLib.map().roomLocation(this);
          if (CMLib.clans().findRivalrousClan(msg.source()) == null) {
            msg.source().tell(L("You must belong to an elligible clan to take a clan item."));
            return false;
          } else if (R != null) {
            for (int i = 0; i < R.numInhabitants(); i++) {
              final MOB M = R.fetchInhabitant(i);
              if ((M != null)
                  && (M.isMonster())
                  && (M.getClanRole(clanID()) != null)
                  && (CMLib.flags().aliveAwakeMobileUnbound(M, true))
                  && (CMLib.flags().canBeSeenBy(this, M))
                  && (!CMLib.flags().isAnimalIntelligence(M))) {
                R.show(
                    M, null, CMMsg.MSG_QUIETMOVEMENT, L("<S-NAME> guard(s) @x1 closely.", name()));
                return false;
              }
            }
            String rulingClan = "";
            final LegalBehavior B = CMLib.law().getLegalBehavior(R);
            if (B != null) rulingClan = B.rulingOrganization();
            if (msg.source().getClanRole(rulingClan) == null) {
              msg.source()
                  .tell(L("You must conquer and fully control this area to take the clan flag."));
              return false;
            }
            if ((B != null) && (!B.isFullyControlled())) {
              msg.source().tell(L("Your clan does not yet fully control the area."));
              return false;
            }
          }
        } else if ((msg.targetMinor() == CMMsg.TYP_DROP)
            && (!CMath.bset(msg.targetMajor(), CMMsg.MASK_INTERMSG))) {
          final Room R = msg.source().location();
          LandTitle T = null;
          Area A = null;
          LegalBehavior B = null;
          if (R != null) {
            A = R.getArea();
            T = CMLib.law().getLandTitle(R);
          }
          if ((T == null)
              || ((!T.getOwnerName().equals(clanID()))
                  && ((!T.getOwnerName().equals(msg.source().getLiegeID()))
                      || (!msg.source().isMarriedToLiege()))
                  && (!T.getOwnerName().equals(msg.source().Name())))) {
            boolean ok = false;
            if (A != null) {
              B = CMLib.law().getLegalBehavior(R);
              if (B != null) ok = B.controlPoints() > 0;
            }
            if (!ok) {
              msg.source()
                  .tell(
                      L("You can not place a flag here, this place is controlled by the Archons."));
              return false;
            }
          }
        }
      } else if ((msg.targetMinor() == CMMsg.TYP_GET)
          && (msg.source().location() != null)
          && (msg.source().isMonster())) {
        boolean foundOne = false;
        for (int i = 0; i < msg.source().location().numInhabitants(); i++) {
          final MOB M = msg.source().location().fetchInhabitant(i);
          if ((M != null) && (!M.isMonster()) && (M.getClanRole(clanID()) != null)) {
            foundOne = true;
            break;
          }
        }
        if (!foundOne) {
          msg.source().tell(L("You are guarding @x1 too closely.", name()));
          return false;
        }
      }
    }

    if (StdClanItem.stdOkMessage(this, msg)) {
      if ((clanID().length() > 0)
          && (msg.amITarget(this))
          && (msg.targetMinor() == CMMsg.TYP_DROP)) {
        final LegalBehavior B = CMLib.law().getLegalBehavior(msg.source().location());
        final String rulingClan = (B != null) ? B.rulingOrganization() : "";
        if (rulingClan.length() == 0)
          msg.source()
              .tell(
                  L("Area '@x1' is presently neutral.", msg.source().location().getArea().name()));
        else {
          msg.source()
              .tell(
                  L(
                      "Area '@x1' is presently controlled by @x2.",
                      msg.source().location().getArea().name(),
                      rulingClan));
          if (!rulingClan.equals(clanID())) {
            int relation = Clan.REL_WAR;
            final Clan C = CMLib.clans().getClan(clanID());
            if (C == null) {
              msg.source().tell(L("This ancient relic from a lost clan fades out of existence."));
              this.destroy();
              return false;
            }
            relation = C.getClanRelations(rulingClan);
            if (relation != Clan.REL_WAR) {
              msg.source()
                  .tell(
                      L("You must be at war with this clan to put down your flag on their area."));
              return false;
            }
          }
        }
      }
      return super.okMessage(myHost, msg);
    }
    return false;
  }