Ejemplo n.º 1
0
  public Hit unmarshall(JsonUnmarshallerContext context) throws Exception {
    Hit hit = new Hit();

    int originalDepth = context.getCurrentDepth();
    String currentParentElement = context.getCurrentParentElement();
    int targetDepth = originalDepth + 1;

    JsonToken token = context.getCurrentToken();
    if (token == null) token = context.nextToken();
    if (token == VALUE_NULL) return null;

    while (true) {
      if (token == null) break;

      if (token == FIELD_NAME || token == START_OBJECT) {
        if (context.testExpression("id", targetDepth)) {
          context.nextToken();
          hit.setId(context.getUnmarshaller(String.class).unmarshall(context));
        }
        if (context.testExpression("fields", targetDepth)) {
          context.nextToken();
          hit.setFields(
              new MapUnmarshaller<String, java.util.List<String>>(
                      context.getUnmarshaller(String.class),
                      new ListUnmarshaller<String>(context.getUnmarshaller(String.class)))
                  .unmarshall(context));
        }
        if (context.testExpression("exprs", targetDepth)) {
          context.nextToken();
          hit.setExprs(
              new MapUnmarshaller<String, String>(
                      context.getUnmarshaller(String.class), context.getUnmarshaller(String.class))
                  .unmarshall(context));
        }
        if (context.testExpression("highlights", targetDepth)) {
          context.nextToken();
          hit.setHighlights(
              new MapUnmarshaller<String, String>(
                      context.getUnmarshaller(String.class), context.getUnmarshaller(String.class))
                  .unmarshall(context));
        }
      } else if (token == END_ARRAY || token == END_OBJECT) {
        if (context.getLastParsedParentElement() == null
            || context.getLastParsedParentElement().equals(currentParentElement)) {
          if (context.getCurrentDepth() <= originalDepth) break;
        }
      }
      token = context.nextToken();
    }

    return hit;
  }
  /**
   * 1. Votingverfahren fuer Strahl-Auswahl: Verfahren testet, ob der getroffene Strahl und der
   * Ausgangsstrahl die gleiche Richtung besitzen
   *
   * @param currentHit Treffer-Instanz, deren Strahlenrichtung ueberprueft wird
   * @param currentRay Strahlen-Instanz, fuer die ein Nachfolger gesucht wird
   * @return True, falls der Ausgangsstrahl die gleiche Richtung besitzt, wie der getroffene Strahl,
   *     False sonst
   */
  private boolean hasSameDirection(Hit currentHit, Ray currentRay) {

    MyVector3f currentHitDirection = currentHit.getHitRay().getDirection();
    MyVector3f currentRayDirection = currentRay.getDirection();

    // teste, ob die Strahlen parallel sind
    return mMathHelper.isParallel(currentHitDirection, currentRayDirection);
  }
 /*
  * (non-Javadoc)
  *
  * @see java.lang.Object#equals(java.lang.Object)
  */
 @Override
 public boolean equals(Object obj) {
   if (this == obj) return true;
   if (obj == null) return false;
   if (getClass() != obj.getClass()) return false;
   Hit other = (Hit) obj;
   if (!getOuterType().equals(other.getOuterType())) return false;
   if (mDistance == null) {
     if (other.mDistance != null) return false;
   } else if (!mDistance.equals(other.mDistance)) return false;
   if (mHitRay == null) {
     if (other.mHitRay != null) return false;
   } else if (!mHitRay.equals(other.mHitRay)) return false;
   if (mIntersection == null) {
     if (other.mIntersection != null) return false;
   } else if (!mIntersection.equals(other.mIntersection)) return false;
   return true;
 }
Ejemplo n.º 4
0
  boolean intersect(Ray r, Hit h, Range range) {
    // ToDo:
    boolean retVal = false;
    double Aq = r.getDirection().dot(r.getDirection());
    double Bq =
        2
            * r.getDirection()
                .dot(
                    new Vector3d(
                        r.getOrigin().x - center.x,
                        r.getOrigin().y - center.y,
                        r.getOrigin().z - center.z));
    double Cq =
        (Math.pow(r.getOrigin().x - center.x, 2)
                + Math.pow(r.getOrigin().y - center.y, 2)
                + Math.pow(r.getOrigin().z - center.z, 2))
            - Math.pow(radius, 2);

    double discriminant = Math.pow(Bq, 2) - (4 * Aq * Cq);
    // Hay intersección, si se cumple esta condición... solo se ne
    // necesita el primer valor que es el de la primera intersección
    if (discriminant >= 0) {
      discriminant = Math.sqrt(discriminant);
      double firstT = (-Bq - discriminant) / (2 * Aq);
      if (firstT > range.minT && firstT < range.maxT) {
        h.setColor(this.color);
        range.maxT = firstT;
        h.setT(firstT);
        // se debe retornar T
      }
      retVal = true;
    }
    return retVal;

    // Compute the intersection of the ray with the
    // Sphere and update what needs to be updated
    // Valid values for t must be within the "range"

    // ...
  }
Ejemplo n.º 5
0
  /**
   * 匹配词段
   *
   * @param charArray
   * @param begin
   * @param length
   * @param searchHit
   * @return Hit
   */
  public Hit match(char[] charArray, int begin, int length, Hit searchHit) {
    if (searchHit == null) {
      // 如果hit为空,新建
      searchHit = new Hit();
      // 设置hit的其实文本位置
      searchHit.setBegin(begin);
    } else {
      // 否则要将HIT状态重置
      searchHit.setUnmatch();
    }
    // 设置hit的当前处理位置
    searchHit.setEnd(begin);

    Character keyChar = new Character(charArray[begin]);
    DictSegment ds = null;

    // 引用实例变量为本地变量,避免查询时遇到更新的同步问题
    DictSegment[] segmentArray = this.childrenArray;
    Map<Character, DictSegment> segmentMap = this.childrenMap;

    // STEP1 在节点中查找keyChar对应的DictSegment
    if (segmentArray != null) {
      // 在数组中查找
      for (DictSegment seg : segmentArray) {
        if (seg != null && seg.nodeChar.equals(keyChar)) {
          // 找到匹配的段
          ds = seg;
        }
      }
    } else if (segmentMap != null) {
      // 在map中查找
      ds = (DictSegment) segmentMap.get(keyChar);
    }

    // STEP2 找到DictSegment,判断词的匹配状态,是否继续递归,还是返回结果
    if (ds != null) {
      if (length > 1) {
        // 词未匹配完,继续往下搜索
        return ds.match(charArray, begin + 1, length - 1, searchHit);
      } else if (length == 1) {
        // 搜索最后一个char
        if (ds.nodeState == 1) {
          // 添加HIT状态为完全匹配
          searchHit.setMatch();
        }
        if (ds.hasNextNode()) {
          // 添加HIT状态为前缀匹配
          searchHit.setPrefix();
          // 记录当前位置的DictSegment
          searchHit.setMatchedDictSegment(ds);
        }
        return searchHit;
      }
    }
    // STEP3 没有找到DictSegment, 将HIT设置为不匹配
    return searchHit;
  }
Ejemplo n.º 6
0
  public HitDetails getDetails(Hit hit) throws IOException {

    Document doc = luceneSearcher.doc(Integer.valueOf(hit.getUniqueKey()));

    List docFields = doc.getFields();
    String[] fields = new String[docFields.size()];
    String[] values = new String[docFields.size()];
    for (int i = 0; i < docFields.size(); i++) {
      Field field = (Field) docFields.get(i);
      fields[i] = field.name();
      values[i] = field.stringValue();
    }

    return new HitDetails(fields, values);
  }
  /**
   * 2. Votingverfahren fuer Strahlauswahl: Methode testet, ob der getroffene Strahl und der
   * Ausgangsstrahl Teil des gleichen Ausgangspolygons sind
   *
   * @param currentHit Treffer-Instanz, fuer deren Strahl getestet wird, ob dieser zum gleichen
   *     Polygon gehoert, wie der Ausgangsstrahl
   * @param currentRay Strahlen-Instanz, fuer die ein Nachfolger gesucht wird
   * @param bucket Eimer, fuer den aktuell ein gemergter Grundriss errechnet wird
   * @return True, falls beide Strahlen Kanten des gleichen Polygons sind, False sonst
   */
  private boolean isPartOfSameObject(
      final Hit currentHit, final Ray currentRay, final FootprintBucket bucket) {

    // bestimme die Quellpolygone fuer den Trefferstrahl und den Teststrahl
    List<Footprint> footprints = bucket.getFootprints();
    MyPolygon currentPolygon = null;
    Ray hitRay = currentHit.getHitRay();

    LOGGER.debug("CURRENT RAY: " + currentRay + " HITRAY: " + hitRay);

    for (int i = 0; i < footprints.size(); i++) {
      currentPolygon = footprints.get(i).getFootprintPoly();

      // wenn beide Strahlen im Polygon enthalten sind, gebe True zurueck
      if (currentPolygon.isRayInPolygon(hitRay) && currentPolygon.isRayInPolygon(currentRay)) {
        LOGGER.debug("SAME POLY");
        LOGGER.debug("CUR POLY: " + currentPolygon);
        return true;
      }
    }
    return false;
  }
Ejemplo n.º 8
0
 public String getExplanation(Query query, Hit hit) throws IOException {
   return luceneSearcher
       .explain(this.queryFilters.filter(query), Integer.valueOf(hit.getUniqueKey()))
       .toHtml();
 }
Ejemplo n.º 9
0
 public void onHitByBullet(HitByBulletEvent e) {
   Hit h = new Hit();
   h.heading = e.getHeadingRadians();
   h.time = e.getTime();
   hits.add(h);
 }
public class oifeyStats {
  Attack attackStat = new Attack();
  FillSkillList fSL = new FillSkillList();
  Avoid avoidStat = new Avoid();
  Critical criticalStat = new Critical();
  Hit hitStat = new Hit();
  equippedWeapon eW = new equippedWeapon();
  randomBloodType rBT = new randomBloodType();
  setBonus sB = new setBonus();

  noWeaponStats n = new noWeaponStats();
  genItem nW = new genItem(n.allStats, n.remainingStats);
  armorslayerStats a = new armorslayerStats();
  genItem armorslayer =
      new genItem(
          a.allStats,
          new boolean[] {
            true, false, false, false, false, false, false, false, false, false, false
          });
  javelinStats j = new javelinStats();
  genItem javelin = new genItem(j.allStats, j.remainingStats);
  public int team = 0;
  public int characterID = 28;
  public int classID = 46;
  public int baseClass = 3;
  public int level = 1;
  public int maxLevel = 20;
  public int exp = 0;
  public int[] currentStats = new int[] {40, 40, 28, 14, 28, 27, 12, 30, 14, 9};
  // Baldo, Odo, Hezul, Noba, Dain, Neir, Ulir, Blagi, Fala, Tordo, Holsety, Narga, Loputousu
  public int[] bloodTypePercents = new int[] {16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  public int[] basePercents = new int[] {1000, 400, 50, 500, 300, 400, 300, 100};
  public int[] bonusPercents = rBT.getBloodPercent(bloodTypePercents);
  // 0->1 "-", 1->30 "D", 30->70 "C", 70->120 "B", 120->180 "A", 180->250 "S"
  public int[] weaponEXP = new int[] {71, 71, 71, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  public int[] skills = new int[] {3, 7, 32, 33, 0, 0};
  public int[] skillList = fSL.getSkillList();
  public int kills = 0;
  public int gold = 5000;
  public int sex = 0;
  public int marriedID = 0;
  public int[] childOne = new int[] {-1, -1};
  public int[] childTwo = new int[] {-1, -1};
  public int[] childThree = new int[] {-1, -1};
  public boolean isLeader = false;
  public int leadershipStars = 0;
  public item[] weapons = new item[] {armorslayer, javelin, nW, nW, nW, nW, nW};

  public int[] bonusStats = sB.getBonus(skills, eW.getEquippedWeapon(weapons));
  public int attack = attackStat.getAttack(eW.getEquippedWeapon(weapons), currentStats, bonusStats);
  public int hit =
      hitStat.getHit(
          eW.getEquippedWeapon(weapons),
          currentStats[4],
          bonusStats[3],
          currentStats[6],
          bonusStats[5],
          skills);
  public int crit =
      criticalStat.getCritical(
          eW.getEquippedWeapon(weapons), currentStats[4], bonusStats[3], skills, kills);
  public int avoid =
      avoidStat.getAvoid(currentStats[5], bonusStats[4], currentStats[6], bonusStats[5], skills);
}
 /**
  * 从已匹配的Hit中直接取出DictSegment,继续向下匹配
  *
  * @return Hit
  */
 public Hit matchWithHit(char[] charArray, int currentIndex, Hit matchedHit) {
   DictSegment ds = matchedHit.getMatchedDictSegment();
   return ds.match(charArray, currentIndex, 1, matchedHit);
 }
  /**
   * Methode berechnet fuer den uebergebenen Grundriss-Bucket einen gemergeten Grundriss und gibt
   * diesen als Vektor von Vertex3d-Instanzen zurueck.
   *
   * @param bucket Bucket mit Grundrissen, die innerhalb der Methode gemerged werden
   * @return Vektor mit Vertex3d-Instanzen, die den gemergten Grundriss beschreiben
   */
  public List<Vertex3d> computeMergedFootprint(FootprintBucket bucket) {

    LOGGER.info("Footprintbucket enthaelt: " + bucket.getFootprints().size() + " Eingabepolygone!");
    Ray startRay = findStartRay(bucket);

    LOGGER.trace("Startray fuer Schnittberechnungen: " + startRay);
    assert startRay != null : "FEHLER: Es konnte kein Anfangsstrahl ermittelt werden!";

    List<Vertex3d> resultVertices = new ArrayList<Vertex3d>();

    // sammele erneut alle Strahlen aller Grundrisse ein
    List<Ray> allRays = new ArrayList<Ray>();
    List<Footprint> allFootprints = bucket.getFootprints();
    Iterator<Footprint> footprintIter = allFootprints.iterator();
    while (footprintIter.hasNext()) {
      allRays.addAll(footprintIter.next().getRays());
    }

    Iterator<Ray> rayIter = allRays.iterator();
    LOGGER.trace("Insgesamt befinden sich " + allRays.size() + " Rays im Eimer");

    while (rayIter.hasNext()) {
      LOGGER.trace(rayIter.next());
    }

    Ray currentRay = null, lastRay = null, intersectionRay = null;
    MyVector3f intersectionPoint = null;
    Vertex3d resultVertex = null;

    // fuege Startpunkt des Startstrahls als erstes Vertex hinzu
    resultVertex = new Vertex3d(startRay.getStart());
    resultVertices.add(resultVertex);

    // Steuervariable fuer Iterationen
    Boolean doContinue = true;

    // erster Treffer des Startstrahls, wird fuer Abbruchkriterium benoetigt
    MyVector3f firstHit = null;

    // Iteration laeuft so lange, bis Abbruchkriterium erfuellt wurde
    while (doContinue) {
      // 1. Iteration
      if (currentRay == null) {
        currentRay = startRay;
      }

      Hit resultHit = findIntersectingRay(currentRay, bucket, lastRay, intersectionPoint);

      assert resultHit != null : "Es konnte kein Schnittstrahl ermittelt werden";
      // System.out.println("Gefundener Strahl: " + intersectionRay);

      intersectionRay = resultHit.getHitRay();
      intersectionPoint = resultHit.getIntersection();

      // speichere den ersten gefundenen Treffer
      if (firstHit == null) firstHit = intersectionPoint;

      // erzeuge eine Vertex3d-Instanz fuer den Schnittpunkt und fuege sie
      // zum Result-Vektor hinzu
      resultVertex = new Vertex3d(intersectionPoint);

      // breche ab, wenn ein Vertex geadded werden soll, das bereits
      // vorhanden ist
      LOGGER.trace("Adde Vertex: " + resultVertex);
      if (resultVertices.contains(resultVertex)) break;
      else resultVertices.add(resultVertex);

      // naechste Iteration vorbereiten
      lastRay = currentRay;
      currentRay = intersectionRay;

      // Abbruchkriterium pruefen
      doContinue = checkTermination(startRay, firstHit, currentRay, intersectionPoint);
    }

    return resultVertices;
  }
  /**
   * Methode waehlt den Ergebnisstrahl aus dem uebergebenen Vektor aus und gibt diesen zurueck.
   * Dadurch kapselt die Methode die gesamte Auswahllogik.
   *
   * @param hits Liste mit saemtlichen Trefferinstanzen
   * @param current Strahl, fuer den nach Schnitten mit allen anderen Strahlen gesucht wird
   * @param bucket Eimer, fuer den aktuell ein gemergter Grundriss erstellt wird
   * @return Hit-Datenstruktur, die als Ausgangspunkt der naechsten Iteration dient
   */
  private Hit chooseResultRay(
      final List<Hit> hits, final Ray current, final FootprintBucket bucket) {

    Hit currentHit = null;

    // kommen mehrere Hits mit gleicher Distanz vor, fuellt man diese
    // zunaechst in einen Buffer-Vector um
    List<Hit> buffer = new ArrayList<Hit>();

    sortHitsByDistance(hits);
    float distance = Float.MAX_VALUE;

    // befuelle den Buffer-Vector mit allen Hits, die die minimale Distanz
    // besitzen
    // 1. Hit nehmen und distance initialisieren
    buffer.add(hits.get(0));
    distance = hits.get(0).getDistance();

    for (int i = 1; i < hits.size(); i++) {
      currentHit = hits.get(i);
      if (currentHit.getDistance() > distance) break;
      else buffer.add(currentHit);
    }

    hits.clear();

    // wurde nur ein Hit mit dieser Distanz gefunden, gebe diesen als
    // Ergebnis zurueck
    if (buffer.size() == 1) return buffer.get(0);

    // an diesem Punkt hat man mehrere Strahlen mit gleicher Distanz
    // fuehre einen Votingansatz durch, bei dem fuer jeden Strahl Tests
    // gerechnet werden => je nach Ausgang dieser Tests wird der Vote-Count
    // fuer den jeweiligen Treffer erhoeht, am Ende waehlt man den Strahl
    // mit den meisten Stimmen
    Iterator<Hit> hitIter = buffer.iterator();

    while (hitIter.hasNext()) {
      currentHit = hitIter.next();
      // bevorzuge Strahlen mit unterschiedlicher Richtung
      if (!hasSameDirection(currentHit, current)) currentHit.vote(1);

      // bevorzuge Strahlen, die nicht zum gleichen Objekt gehoeren, wie
      // der Ausgangsstrahl
      // es ist wichtiger, dass der Strahl nicht zum gleichen Objekt
      // gehoert, darum 2 Stimmen!
      if (!isPartOfSameObject(currentHit, current, bucket)) {
        currentHit.vote(2);
      }
    }

    // sortiere die Strahlen anhand der Stimmen, die sie durch die
    // Votingmethoden bekommen haben
    sortHitsByVoteCount(buffer);

    /*
     * logger.debug("Gevotete Hits: "); for (int i = 0; i < buffer.size();
     * i++) logger.debug(buffer.get(i));
     */
    return buffer.get(buffer.size() - 1);
  }
Ejemplo n.º 14
0
  public Color trace(Scene scene) {
    // find first intersection point with scene objects
    Hit firstHit = scene.intersect(this);
    // calculate light intensity/color at hit point
    if (firstHit == null) {
      return new Color(0, 0, 0);
    }

    Material material = firstHit.getShape().getMaterial();

    Color result = new Color(0, 0, 0);

    result = result.add(material.computeAmbient(scene.getAmbientLight()));

    for (LightSource light : scene.getLightSources()) {
      Vector direction = light.getPosition().sub(firstHit.getIntersectionPoint()).normalize();
      Vector offset = direction.mult(OFFSET);

      Ray shadowRay =
          new Ray(direction, firstHit.getIntersectionPoint().add(offset), recursionDepth);

      Hit intersection = scene.intersect(shadowRay);

      if (intersection == null) {
        result = result.add(material.computeDiffuseLight(firstHit, light));
        result = result.add(material.computeSpecularLight(firstHit, light));
      }
    }

    if (recursionDepth > 0) {
      float n1 = material.getRefractionMediumOutside();
      float n2 = material.getRefractionMediumInside();

      float reflectionAbility = 1;

      if (n1 > 0 && n2 > 0) {
        Refraction refractionIn = getRefraction(direction, firstHit.getNormal(), n1, n2);

        if (refractionIn != null) {
          reflectionAbility = refractionIn.reflectionAbility;
          Vector offset = refractionIn.direction.mult(OFFSET);
          Ray refractionRay =
              new Ray(
                  refractionIn.direction,
                  firstHit.getIntersectionPoint().add(offset),
                  recursionDepth);

          Hit outHit = scene.intersect(refractionRay);

          Refraction refractionOut =
              getRefraction(refractionRay.direction, outHit.getNormal().mult(-1), n2, n1);

          if (refractionOut != null) {
            Ray outRay =
                new Ray(
                    refractionOut.direction,
                    outHit.getIntersectionPoint().add(refractionOut.direction.mult(OFFSET)),
                    recursionDepth - 1);

            result = result.add(outRay.trace(scene).modulate(refractionIn.transmissionAbility));
          }
        }
      }

      if (material.getReflectionCo() > 0) {
        Vector direction = getReflection(this.direction, firstHit.getNormal());
        Vector offset = direction.mult(OFFSET);

        Ray reflectionRay =
            new Ray(direction, firstHit.getIntersectionPoint().add(offset), recursionDepth - 1);

        result =
            result.add(
                reflectionRay
                    .trace(scene)
                    .modulate(material.getReflectionCo() * reflectionAbility));
      }
    }

    return result;
  }
public class juliusStats // This Character's Mother is Diadora (Father is always Alvis)
 {
  Attack attackStat = new Attack();
  FillSkillList fSL = new FillSkillList();
  Avoid avoidStat = new Avoid();
  Critical criticalStat = new Critical();
  Hit hitStat = new Hit();
  equippedWeapon eW = new equippedWeapon();
  randomBloodType rBT = new randomBloodType();
  setBonus sB = new setBonus();
  characterDatabaseGenOne cD = new characterDatabaseGenOne();
  inheritance inh = new inheritance();

  genCharacter mother = cD.diadora;
  genCharacter father = cD.alvis;

  noWeaponStats n = new noWeaponStats();
  genItem nW = new genItem(n.allStats, n.remainingStats);
  loputousuStats l = new loputousuStats();
  genItem loputousu =
      new genItem(
          l.allStats,
          new boolean[] {
            true, false, false, false, false, false, false, false, false, false, false
          });
  maxStats mX = new maxStats();
  public int team = 2;
  public int characterID = 128;
  public int sex = 0;
  public int classID = 145;
  public int baseClass = 145;
  public int level = 20;
  public int maxLevel = 20;
  public int exp = 0;
  // Baldo, Odo, Hezul, Noba, Dain, Neir, Ulir, Blagi, Fala, Tordo, Holsety, Narga, Loputousu
  public int[] bloodTypePercents = inh.getBloodType(mother, father, sex);
  public int[] basePercents = inh.getGrowth(mother, father, sex);
  public int[] bonusPercents = rBT.getBloodPercent(bloodTypePercents);
  public int[] currentStats =
      inh.childStartingStats(
          mother, father, level, basePercents, bonusPercents, level, classID, sex);
  // 0->1 "-", 1->30 "D", 30->70 "C", 70->120 "B", 120->180 "A", 180->250 "S"
  public int[] weaponEXP = new int[] {0, 0, 0, 0, 0, 0, 121, 121, 121, 0, 251, 0};
  int[] defaultSkills = new int[] {3, 4, 6, 0, 0, 0};
  public int[] skills = inh.inheritSkill(mother, father, defaultSkills);
  public int[] skillList = fSL.getSkillList();
  public int kills = 0;
  public int gold = inh.getGold(mother, father);
  public int marriedID = 0;
  public int[] childOne = new int[] {-1, -1};
  public int[] childTwo = new int[] {-1, -1};
  public int[] childThree = new int[] {-1, -1};
  public boolean isLeader = false;
  public int leadershipStars = 5;
  public item[] weapons = new item[] {loputousu, nW, nW, nW, nW, nW, nW};

  public int[] bonusStats = sB.getBonus(skills, eW.getEquippedWeapon(weapons));
  public int attack = attackStat.getAttack(eW.getEquippedWeapon(weapons), currentStats, bonusStats);
  public int hit =
      hitStat.getHit(
          eW.getEquippedWeapon(weapons),
          currentStats[4],
          bonusStats[3],
          currentStats[6],
          bonusStats[5],
          skills);
  public int crit =
      criticalStat.getCritical(
          eW.getEquippedWeapon(weapons), currentStats[4], bonusStats[3], skills, kills);
  public int avoid =
      avoidStat.getAvoid(currentStats[5], bonusStats[4], currentStats[6], bonusStats[5], skills);
}
public class bowFighterThreeStats {
  Attack attackStat = new Attack();
  FillSkillList fSL = new FillSkillList();
  Avoid avoidStat = new Avoid();
  Critical criticalStat = new Critical();
  Hit hitStat = new Hit();
  equippedWeapon eW = new equippedWeapon();
  randomBloodType rBT = new randomBloodType();

  setBonus sB = new setBonus();

  noWeaponStats n = new noWeaponStats();
  genItem nW = new genItem(n.allStats, n.remainingStats);
  ironBowStats i = new ironBowStats();
  genItem ironBow =
      new genItem(
          i.allStats,
          new boolean[] {
            true, false, false, false, false, false, false, false, false, false, false
          });

  static final Random r = new Random();
  public int team = 2;
  public int characterID = 187;
  public int classID = 23;
  public int baseClass = 23;
  public int level = 1;
  public int maxLevel = 20;
  public int exp = 0;
  public int internalLevel = 15;
  // Baldo, Odo, Hezul, Noba, Dain, Neir, Ulir, Blagi, Fala, Tordo, Holsety, Narga, Loputousu
  public int[] bloodTypePercents = new int[13];
  static int randomHP = r.nextInt(100);
  static int randomStr = r.nextInt(200);
  static int randomMgc = r.nextInt(100);
  static int randomSkl = r.nextInt(200);
  static int randomSpd = r.nextInt(200);
  static int randomLck = r.nextInt(300);
  static int randomDef = r.nextInt(200);
  static int randomRes = r.nextInt(200);
  public int[] basePercents =
      new int[] {
        600 + randomHP,
        400 + randomStr,
        100 + randomMgc,
        300 + randomSkl,
        300 + randomSpd,
        100 + randomLck,
        300 + randomDef,
        100 + randomRes
      };
  public int[] bonusPercents = rBT.getBloodPercent(bloodTypePercents);
  public int hpAddition = rBT.getRandomStats(internalLevel, basePercents[0]);
  public int[] currentStats =
      new int[] {
        20 + hpAddition,
        20 + hpAddition,
        rBT.getRandomStats(internalLevel, basePercents[1]),
        rBT.getRandomStats(internalLevel, basePercents[2]),
        rBT.getRandomStats(internalLevel, basePercents[3]),
        rBT.getRandomStats(internalLevel, basePercents[4]),
        rBT.getRandomStats(internalLevel, basePercents[5]),
        rBT.getRandomStats(internalLevel, basePercents[6]),
        rBT.getRandomStats(internalLevel, basePercents[7]),
        5
      };
  // 0->1 "-"
  // 1->30 "D"
  // 30->70 "C"
  // 70->120 "B"
  // 120->180 "A"
  // 180->250 "S"
  public int[] weaponEXP = new int[] {0, 0, 0, 71, 0, 0, 0, 0, 0, 0, 0, 0};
  public static int randomSkill = 53;

  public static int getRandomSkill() {
    while (randomSkill == 53) {
      randomSkill = r.nextInt(112) + 1;
    }
    return randomSkill;
  }

  public int[] skills = new int[] {53, getRandomSkill(), 0, 0, 0, 0};
  public int[] skillList = fSL.getSkillList();
  public int kills = 0;
  public int gold = 2000;
  public int sex = 0;
  public int marriedID = 0;
  public int[] childOne = new int[] {-1, -1};
  public int[] childTwo = new int[] {-1, -1};
  public int[] childThree = new int[] {-1, -1};
  public boolean isLeader = false;
  public int leadershipStars = 0;
  public static int randomKills = r.nextInt(100);
  public item[] weapons = new item[] {ironBow, nW, nW, nW, nW, nW, nW};

  public int[] bonusStats = sB.getBonus(skills, eW.getEquippedWeapon(weapons));
  public int attack = attackStat.getAttack(eW.getEquippedWeapon(weapons), currentStats, bonusStats);
  public int hit =
      hitStat.getHit(
          eW.getEquippedWeapon(weapons),
          currentStats[4],
          bonusStats[3],
          currentStats[6],
          bonusStats[5],
          skills);
  public int crit =
      criticalStat.getCritical(
          eW.getEquippedWeapon(weapons), currentStats[4], bonusStats[3], skills, kills);
  public int avoid =
      avoidStat.getAvoid(currentStats[5], bonusStats[4], currentStats[6], bonusStats[5], skills);
}
Ejemplo n.º 17
0
  /**
   * Search for pages matching a query, eliminating excessive hits with matching values for a named
   * field. Hits after the first <code>maxHitsPerDup</code> are removed from results. The remaining
   * hits have {@link Hit#moreFromDupExcluded()} set.
   *
   * <p>If maxHitsPerDup is zero then all hits are returned.
   *
   * @param query query
   * @param numHits number of requested hits
   * @param maxHitsPerDup the maximum hits returned with matching values, or zero
   * @param dedupField field name to check for duplicates
   * @param sortField Field to sort on (or null if no sorting).
   * @param reverse True if we are to reverse sort by <code>sortField</code>.
   * @return Hits the matching hits
   * @throws IOException
   */
  public Hits search(
      Query query,
      int numHits,
      int maxHitsPerDup,
      String dedupField,
      String sortField,
      boolean reverse)
      throws IOException {
    if (maxHitsPerDup <= 0) // disable dup checking
    return search(query, numHits, dedupField, sortField, reverse);

    final float rawHitsFactor = this.conf.getFloat("searcher.hostgrouping.rawhits.factor", 2.0f);
    int numHitsRaw = (int) (numHits * rawHitsFactor);
    if (LOG.isInfoEnabled()) {
      LOG.info("searching for " + numHitsRaw + " raw hits");
    }
    Hits hits = searchBean.search(query, numHitsRaw, dedupField, sortField, reverse);
    final long total = hits.getTotal();
    final Map<String, DupHits> dupToHits = new HashMap<String, DupHits>();
    final List<Hit> resultList = new ArrayList<Hit>();
    final Set<Hit> seen = new HashSet<Hit>();
    final List<String> excludedValues = new ArrayList<String>();
    boolean totalIsExact = true;
    for (int rawHitNum = 0; rawHitNum < hits.getTotal(); rawHitNum++) {
      // get the next raw hit
      if (rawHitNum >= hits.getLength()) {
        // optimize query by prohibiting more matches on some excluded values
        final Query optQuery = (Query) query.clone();
        for (int i = 0; i < excludedValues.size(); i++) {
          if (i == MAX_PROHIBITED_TERMS) break;
          optQuery.addProhibitedTerm(excludedValues.get(i), dedupField);
        }
        numHitsRaw = (int) (numHitsRaw * rawHitsFactor);
        if (LOG.isInfoEnabled()) {
          LOG.info("re-searching for " + numHitsRaw + " raw hits, query: " + optQuery);
        }
        hits = searchBean.search(optQuery, numHitsRaw, dedupField, sortField, reverse);
        if (LOG.isInfoEnabled()) {
          LOG.info("found " + hits.getTotal() + " raw hits");
        }
        rawHitNum = -1;
        continue;
      }

      final Hit hit = hits.getHit(rawHitNum);
      if (seen.contains(hit)) continue;
      seen.add(hit);

      // get dup hits for its value
      final String value = hit.getDedupValue();
      DupHits dupHits = dupToHits.get(value);
      if (dupHits == null) dupToHits.put(value, dupHits = new DupHits());

      // does this hit exceed maxHitsPerDup?
      if (dupHits.size() == maxHitsPerDup) { // yes -- ignore the hit
        if (!dupHits.maxSizeExceeded) {

          // mark prior hits with moreFromDupExcluded
          for (int i = 0; i < dupHits.size(); i++) {
            dupHits.get(i).setMoreFromDupExcluded(true);
          }
          dupHits.maxSizeExceeded = true;

          excludedValues.add(value); // exclude dup
        }
        totalIsExact = false;
      } else { // no -- collect the hit
        resultList.add(hit);
        dupHits.add(hit);

        // are we done?
        // we need to find one more than asked for, so that we can tell if
        // there are more hits to be shown
        if (resultList.size() > numHits) break;
      }
    }

    final Hits results = new Hits(total, resultList.toArray(new Hit[resultList.size()]));
    results.setTotalIsExact(totalIsExact);
    return results;
  }
  public void dispatch(BusinessObject... businessObjects) {
    ArrayList<BusinessObject> trackerObjects;
    for (BusinessObject businessObject : businessObjects) {
      businessObject.setEvent();

      if (businessObject instanceof AbstractScreen) {
        trackerObjects =
            new ArrayList<BusinessObject>() {
              {
                addAll(tracker.getBusinessObjects().values());
              }
            };

        boolean hasOrder = false;

        for (BusinessObject object : trackerObjects) {
          if (((object instanceof OnAppAd && ((OnAppAd) object).getAction() == OnAppAd.Action.View)
                  || object instanceof Order
                  || object instanceof InternalSearch
                  || object instanceof ScreenInfo)
              && object.getTimestamp() < businessObject.getTimestamp()) {

            if (object instanceof Order) {
              hasOrder = true;
            }

            object.setEvent();
            tracker.getBusinessObjects().remove(object.getId());
          }
        }

        if (tracker.Cart().getCartId() != null
            && (((Screen) businessObject).isBasketScreen() || hasOrder)) {
          tracker.Cart().setEvent();
        }
      } else if (businessObject instanceof Gesture) {
        trackerObjects =
            new ArrayList<BusinessObject>() {
              {
                addAll(tracker.getBusinessObjects().values());
              }
            };

        if (((Gesture) businessObject).getAction() == Gesture.Action.InternalSearch) {
          for (BusinessObject object : trackerObjects) {
            if ((object instanceof InternalSearch)
                && object.getTimestamp() < businessObject.getTimestamp()) {
              object.setEvent();
              tracker.getBusinessObjects().remove(object.getId());
            }
          }
        }
      }

      tracker.getBusinessObjects().remove(businessObject.getId());
      trackerObjects =
          new ArrayList<BusinessObject>() {
            {
              addAll(tracker.getBusinessObjects().values());
            }
          };

      for (BusinessObject object : trackerObjects) {
        if ((object instanceof CustomObject || object instanceof NuggAd)
            && object.getTimestamp() < businessObject.getTimestamp()) {
          object.setEvent();
          tracker.getBusinessObjects().remove(object.getId());
        }
      }
    }

    if (Hit.getHitType(
            tracker.getBuffer().getVolatileParams(), tracker.getBuffer().getPersistentParams())
        == Hit.HitType.Screen) {
      TechnicalContext.screenName =
          Tool.appendParameterValues(
              Hit.HitParam.Screen.stringValue(),
              tracker.getBuffer().getVolatileParams(),
              tracker.getBuffer().getPersistentParams());
      CrashDetectionHandler.setCrashLastScreen(TechnicalContext.screenName);

      String level2 =
          Tool.appendParameterValues(
              Hit.HitParam.Level2.stringValue(),
              tracker.getBuffer().getVolatileParams(),
              tracker.getBuffer().getPersistentParams());
      TechnicalContext.level2 = (!TextUtils.isEmpty(level2)) ? Integer.parseInt(level2) : 0;

      SharedPreferences preferences = Tracker.getPreferences();
      if (!preferences.getBoolean(TrackerConfigurationKeys.CAMPAIGN_ADDED_KEY, false)) {
        String xtor =
            preferences.getString(TrackerConfigurationKeys.MARKETING_CAMPAIGN_SAVED, null);
        if (xtor != null) {
          ParamOption beforeStcPositionWithEncoding =
              new ParamOption()
                  .setRelativePosition(ParamOption.RelativePosition.before)
                  .setRelativeParameterKey(Hit.HitParam.JSON.stringValue())
                  .setEncode(true);

          if (preferences.getBoolean(
              TrackerConfigurationKeys.IS_FIRST_AFTER_INSTALL_HIT_KEY, true)) {
            tracker.setParam(
                Hit.HitParam.Source.stringValue(), xtor, beforeStcPositionWithEncoding);
            preferences
                .edit()
                .putBoolean(TrackerConfigurationKeys.IS_FIRST_AFTER_INSTALL_HIT_KEY, false)
                .apply();
          } else {
            tracker.setParam(
                Hit.HitParam.RemanentSource.stringValue(), xtor, beforeStcPositionWithEncoding);
          }
          preferences.edit().putBoolean(TrackerConfigurationKeys.CAMPAIGN_ADDED_KEY, true).apply();
        }
      }
    }

    setIdentifiedVisitorInfos();

    ParamOption appendWithEncoding = new ParamOption().setAppend(true).setEncode(true);
    tracker.setParam(
        Hit.HitParam.JSON.stringValue(),
        LifeCycle.getMetrics(Tracker.getPreferences()),
        appendWithEncoding);
    if ((Boolean) tracker.getConfiguration().get(TrackerConfigurationKeys.ENABLE_CRASH_DETECTION)) {
      tracker.setParam(
          Hit.HitParam.JSON.stringValue(),
          CrashDetectionHandler.getCrashInformation(),
          appendWithEncoding);
    }

    String referrer = Tracker.getPreferences().getString(TrackerConfigurationKeys.REFERRER, null);
    if (!TextUtils.isEmpty(referrer)) {
      tracker.setParam(Hit.HitParam.Refstore.stringValue(), referrer);
      Tracker.getPreferences().edit().putString(TrackerConfigurationKeys.REFERRER, null).apply();
    }

    Builder builder = new Builder(tracker);
    tracker.getBuffer().getVolatileParams().clear();
    TrackerQueue.getInstance().put(builder);

    tracker.Context().setLevel2(tracker.Context().getLevel2());
  }