Package marauroa.common.game

Examples of marauroa.common.game.Definition


   * Tests for isParsableByInteger.
   */
  @Test
  public final void testIsParsableByInteger() {
    AlterAction action = new AlterAction();
      Definition def = new Definition();
       def.setType(BYTE);
    assertTrue(action.isParsableByInteger(def));   

    def.setType(FLAG);
    assertFalse(action.isParsableByInteger(def));   

   
    def.setType(INT);
    assertTrue(action.isParsableByInteger(def));   

    def.setType(LONG_STRING);
    assertFalse(action.isParsableByInteger(def));   

    def.setType(NOTYPE);
    assertFalse(action.isParsableByInteger(def));   

    def.setType(SHORT);
    assertTrue(action.isParsableByInteger(def));   

    def.setType(STRING);
    assertFalse(action.isParsableByInteger(def));   

    def.setType(VERY_LONG_STRING);
    assertFalse(action.isParsableByInteger(def));

    def.setType(FLOAT);
    assertFalse(action.isParsableByInteger(def));   

  }
View Full Code Here


      }

      final RPClass clazz = changed.getRPClass();


      final Definition type = clazz.getDefinition(DefinitionClass.ATTRIBUTE, stat);
      if (type == null) {
        player.sendPrivateText("Attribute you are altering is not defined in RPClass("
            + changed.getRPClass().getName() + ")");
        return;
      } else {
        final String value = action.get(VALUE);
        final String mode = action.get(MODE);

        if ((mode.length() > 0) && !mode.equalsIgnoreCase(ADD)
            && !mode.equalsIgnoreCase(SUB) && !mode.equalsIgnoreCase(SET) && !mode.equalsIgnoreCase(UNSET)) {
          player.sendPrivateText("Please issue one of the modes 'add', 'sub', 'set' or 'unset'.");
          return;
        }

        if (isParsableByInteger(type)) {
          int numberValue;

          try {
            numberValue = Integer.parseInt(value);
          } catch (final NumberFormatException e) {
            player.sendPrivateText("Please issue a numeric value instead of '" + value + "'");
            return;
          }

          if (mode.equalsIgnoreCase(ADD)) {
            numberValue = changed.getInt(stat) + numberValue;
          }

          if (mode.equalsIgnoreCase(SUB)) {
            numberValue = changed.getInt(stat) - numberValue;
          }

          if (ATTR_HP.equals(stat) && (changed.getInt("base_hp") < numberValue)) {
            logger.info("Admin " + player.getName() + " trying to set entity "
                + Grammar.suffix_s(action.get(TARGET)) + " HP over its Base HP, "
                + "we instead restored entity " + action.get(TARGET) + " to full health.");
            numberValue = changed.getInt("base_hp");
          }

          if (ATTR_HP.equals(stat) && (numberValue <= 0)) {
            logger.error("DENIED: Admin " + player.getName() + " trying to set entity "
                + Grammar.suffix_s(action.get(TARGET)) + " HP to 0, making it so unkillable.");
            return;
          }

          switch (type.getType()) {
          case BYTE:
            if ((numberValue > Byte.MAX_VALUE)
                || (numberValue < Byte.MIN_VALUE)) {
              return;
            }
            break;
          case SHORT:
            if ((numberValue > Short.MAX_VALUE)
                || (numberValue < Short.MIN_VALUE)) {
              return;
            }
            break;
          case INT:
            /*
             * as numberValue is currently of type integer, this is
             * pointless: if ((numberValue > Integer.MAX_VALUE) ||
             * (numberValue < Integer.MIN_VALUE)) { return; }
             */
            break;
          default:
              // we switch over an enum
              break;
          }
         
          new GameEvent(player.getName(), ALTER, action.get(TARGET), stat, Integer.toString(numberValue)).raise();
          changed.put(stat, numberValue);
        } else {
          // If value is not a number, only SET and UNSET can be used
          if (mode.equalsIgnoreCase(SET)) {
            new GameEvent(player.getName(), ALTER, action.get(TARGET), stat, action.get(VALUE)).raise();
            changed.put(stat, action.get(VALUE));

          } else if (mode.equalsIgnoreCase(UNSET)) {
            if (type.getType() != Type.FLAG) {
              player.sendPrivateText("Attribute to be unset is not of type 'flag'.");
              return;
            }
            new GameEvent(player.getName(), ALTER, action.get(TARGET), stat, "unset").raise();
            changed.remove(stat);
View Full Code Here

TOP

Related Classes of marauroa.common.game.Definition

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.