示例#1
0
  public boolean tryDamageSkill(String rem, String cut, String output) {

    if (cut.length() > 0)
      if (rem.indexOf(cut) == 0) {
        rem = rem.substring(cut.length(), rem.length());
        rem = Utility.clearWhiteSpace(rem);
      }

    target = owner.getRoom().findEntity(owner, rem);

    if ((target == null) && (owner.getPlayerState() == Utility.PSTATE_FIGHTING))
      target = owner.getTarget();

    if (target == null) {
      owner.echo(output);
      return false;
    }

    if (!Combat.canAttack(owner, target, false, true)) return false;

    tn = target.getName();
    Tn = target.getPName();
    ty = Utility.possessive(tn);
    Ty = Utility.possessive(Tn);

    return true;
  }
示例#2
0
  @SuppressWarnings("rawtypes")
  public static void initDevPackage(DEVPackage devPackage) {

    Gson gson = new Gson();
    if (devPackage != null && devPackage.getOwnedElements() != null) {
      List ownedElements = (List) devPackage.getOwnedElements();

      /*
      Entity entityManageApi = new Entity();
      entityManageApi.setName(devPackage.getName() + "EntityManageApi");
      entityManageApi.set_parent(new StarUmlReference(devPackage.get_id()));
      entityManageApi.setTemplatePath(devPackage.getTemplatePath());
      entityManageApi.setStereotype("Api");
      devPackage.getOwnedElements().add(entityManageApi);*/

      for (int i = 0; i < ownedElements.size(); i++) {
        Entity entity = null;
        Object aa = ownedElements.get(i);
        if (aa.getClass().toString().contains("Entity")) {
          entity = (Entity) aa;
        } else {
          LinkedHashMap data = (LinkedHashMap) ownedElements.get(i);
          String type = (String) data.get("_type");
          String id = (String) data.get("_id");
          String stereotype = (String) data.get("stereotype");
          if (type.equals("UMLClass")) {
            String eleJson = gson.toJson(data);
            entity = gson.fromJson(eleJson, Entity.class);
          }
        }

        if (entity != null) {
          entity.collectExtraAttributes();
          entity.setDevPackage(devPackage);
          entity.setTemplatePath(devPackage.getTemplatePath());
          StarUmlObjectContainer.addObject(entity.get_id(), entity);
          StarUmlObjectContainer.addObjectByName(entity.getName(), entity);
          devPackage.addEntity(entity.get_id(), entity);
          StarUmlReference ref = new StarUmlReference(devPackage.get_id());
          entity.set_parent(ref);
          ownedElements.set(i, entity);

          // auto generate ApiManage Entity
          /*
          if (entity.getStereotype() != null && entity.getStereotype().equals("Entity")) {
              EntityOperation entityManageOp = new EntityOperation(entityManageApi);
              entityManageOp.setName("manage" + entity.getName());
              entityManageApi.addOperation(entityManageOp);
              entityManageApi.addDepend(entity.getName(), entity);
          }*/
        }
      }
      //	devPackage.normalizeTypes();
    }
  }
示例#3
0
  public void init(Entity Owner, int Level) {

    owner = Owner;
    level = Level;

    if (Owner != null) {

      mn = owner.getName();
      Mn = owner.getPName();
      my = Utility.possessive(mn);
      My = Utility.possessive(Mn);
    }
  }
 public void die(DamageSource damagesource) {
   if (village != null) {
     Entity entity = damagesource.getEntity();
     if (entity != null) {
       if (entity instanceof EntityHuman) village.a(entity.getName(), -2);
       else if (entity instanceof IMonster) village.h();
     } else if (entity == null) {
       EntityHuman entityhuman = world.findNearbyPlayer(this, 16D);
       if (entityhuman != null) village.h();
     }
   }
   super.die(damagesource);
 }
  @Override
  public Value solveEquation(final User user, final Calculation calculation)
      throws NimbitsException {

    final MathEvaluator m = new MathEvaluatorImpl(calculation.getFormula());
    log.info(calculation.getFormula());

    if (!Utils.isEmptyString(calculation.getX()) && calculation.getFormula().contains("x")) {
      //  Point p = PointServiceFactory.getInstance().getPointByKey(calculation.getX());
      final Entity p =
          EntityServiceFactory.getInstance()
              .getEntityByKey(user, calculation.getX(), EntityType.point)
              .get(0);

      if (p != null) {
        log.info("calc has an x car and i found " + p.getName());
        final List<Value> val = ValueServiceFactory.getInstance().getCurrentValue(p);

        final double d = val.isEmpty() ? 0.0 : val.get(0).getDoubleValue();

        m.addVariable("x", d);
      } else {
        log.severe("calc has an x car and x not found");
      }
    }
    if (!Utils.isEmptyString(calculation.getY()) && calculation.getFormula().contains("y")) {
      final Entity p =
          EntityServiceFactory.getInstance()
              .getEntityByKey(user, calculation.getY(), EntityType.point)
              .get(0);

      // Point p = PointServiceFactory.getInstance().getPointByKey(calculation.getY());
      if (p != null) {
        final List<Value> val = ValueServiceFactory.getInstance().getCurrentValue(p);
        final double d = val.isEmpty() ? 0.0 : val.get(0).getDoubleValue();
        m.addVariable("y", d);
      }
    }
    if (!Utils.isEmptyString(calculation.getZ()) && calculation.getFormula().contains("z")) {
      final Entity p =
          EntityServiceFactory.getInstance()
              .getEntityByKey(user, calculation.getZ(), EntityType.point)
              .get(0);

      //  Point p = PointServiceFactory.getInstance().getPointByKey(calculation.getZ());
      if (p != null) {
        final List<Value> val = ValueServiceFactory.getInstance().getCurrentValue(p);
        final double d = val.isEmpty() ? 0.0 : val.get(0).getDoubleValue();
        m.addVariable("z", d);
      }
    }

    final Double retVal = m.getValue();

    if (retVal == null) {

      throw new NimbitsException("Formula returned a null value: " + calculation.getFormula());
    }

    return ValueFactory.createValueModel(retVal, "CV");
  }