Exemplo n.º 1
0
  @Override
  public boolean invoke(
      MOB mob, List<String> commands, Physical givenTarget, boolean auto, int asLevel) {
    final Room trapThis = mob.location();

    Item resource =
        CMLib.materials().findMostOfMaterial(mob.location(), RawMaterial.MATERIAL_METAL);
    if (resource == null)
      resource = CMLib.materials().findMostOfMaterial(mob.location(), RawMaterial.MATERIAL_MITHRIL);
    int amount = 0;
    if (resource != null)
      amount = CMLib.materials().findNumberOfResource(mob.location(), resource.material());
    if (amount < 100) {
      mob.tell(L("You need 100 pounds of raw metal to build this trap."));
      return false;
    }
    if (mob.isInCombat()) {
      mob.tell(L("You are too busy to get that done right now."));
      return false;
    }

    if (!super.invoke(mob, commands, givenTarget, auto, asLevel)) return false;

    final boolean success = proficiencyCheck(mob, 0, auto);

    if (resource != null)
      CMLib.materials().destroyResourcesValue(mob.location(), 100, resource.material(), -1, null);

    final CMMsg msg =
        CMClass.getMsg(
            mob,
            trapThis,
            this,
            auto ? CMMsg.MSG_OK_ACTION : CMMsg.MSG_THIEF_ACT,
            CMMsg.MASK_ALWAYS | CMMsg.MSG_DELICATE_HANDS_ACT,
            CMMsg.MSG_OK_ACTION,
            (auto
                ? L("@x1 begins to glow!", trapThis.name())
                : L("<S-NAME> attempt(s) to lay a trap here.")));
    if (mob.location().okMessage(mob, msg)) {
      mob.location().send(mob, msg);
      if (success) {
        mob.tell(L("You have set the trap."));
        setTrap(
            mob,
            trapThis,
            mob.charStats().getClassLevel(mob.charStats().getCurrentClass()),
            (CMLib.ableMapper().qualifyingClassLevel(mob, this)
                    - CMLib.ableMapper().lowestQualifyingLevel(ID()))
                + 1,
            false);
        final Thief_DeathTrap T = (Thief_DeathTrap) trapThis.fetchEffect(ID());
        if (T != null) T.setMiscText(mob.Name());
      } else {
        if (CMLib.dice().rollPercentage() > 50) {
          final Trap T =
              setTrap(
                  mob,
                  trapThis,
                  mob.charStats().getClassLevel(mob.charStats().getCurrentClass()),
                  (CMLib.ableMapper().qualifyingClassLevel(mob, this)
                          - CMLib.ableMapper().lowestQualifyingLevel(ID()))
                      + 1,
                  false);
          mob.location()
              .show(mob, null, CMMsg.MSG_OK_ACTION, L("<S-NAME> trigger(s) the trap on accident!"));
          T.spring(mob);
        } else {
          mob.tell(L("You fail in your attempt to set the death trap."));
        }
      }
    }
    return success;
  }