Package org.mozilla.javascript

Examples of org.mozilla.javascript.ScriptableObject


  @Ignore
  public void processQueuedSettlement() throws GameEngineException {
    API api = new API();
    Long boardId = null;
    String playerName = "one";
    ScriptableObject board = api.joinBoard(boardId, playerName);
    assertEquals(32, board.get("size"));

    board = api.save(board);

    String settlementPoint = "{\"r\":1,\"g\":1,\"b\":1}";
    String resources = "{\"WHEAT\":1,\"FUR\":1,\"STONE\":1}";
    String settlementName = "HAMLET";
    api.queueSettlement(board, playerName, settlementPoint, settlementName,
        resources);

    api.endTurn(board);

    // see if the queued location got cleared
    ScriptableObject scriptableObject3 = (ScriptableObject) ((ScriptableObject) board
        .get("players")).get(playerName);
    ScriptableObject queuedSettlements = (ScriptableObject) scriptableObject3
        .get("queuedSettlements");
    assertEquals(0, queuedSettlements.size());

    // see if the queued resources got cleared
    ScriptableObject queuedSettlementsResources = (ScriptableObject) scriptableObject3
        .get("queuedSettlementsResources");
    assertEquals(0, queuedSettlementsResources.size());

    // see if the settlement got built
    // board.settlementLocations
    assertEquals(1,
        ((ScriptableObject) board.get("settlementLocations")).size());
    assertEquals(settlementName,
        ((ScriptableObject) board.get("settlementLocations"))
            .get(settlementPoint));

    // board.settlementOwnership
    assertEquals(1,
        ((ScriptableObject) board.get("settlementOwnership")).size());
    assertEquals(playerName,
        ((ScriptableObject) board.get("settlementOwnership"))
            .get(settlementPoint));

    // board.players[playerName].settlements
    ScriptableObject scriptableObject2 = (ScriptableObject) scriptableObject3
        .get("settlements");
    assertEquals(1, scriptableObject2.size());
    ScriptableObject scriptableObject = (ScriptableObject) scriptableObject2
        .get(settlementPoint);
    assertEquals(settlementName, scriptableObject.get("name"));

  }
View Full Code Here


  void enterContext() {
    this.cx = Context.enter();
  }

  public ScriptableObject execute(String expresion) {
    ScriptableObject result = null;
    this.cx = Context.enter();
    try {
      result = (ScriptableObject) this.cx.evaluateString(this.scope,
          expresion, "", 1, null);
    } catch (RuntimeException rte) {
View Full Code Here

          json = (String) a;
        } else {
          json = a.toString();
        }

        ScriptableObject mementos = (ScriptableObject) table
            .get("mementos");
        Long mementoId = getLong(result.getProperty("mementoId"));

        Step step1 = MiniProfiler.step("putProperty,valueOf,ge.parse");
        ScriptableObject.putProperty(mementos,
View Full Code Here

  private void completePurchase(final ScriptableObject player)
      throws GameEngineException {
    Step step = MiniProfiler.step("API.completePurchase");
    try {
      final ScriptableObject disks = (ScriptableObject) player
          .get("cart");

      for (final Object diskName : disks.getIds()) {
        final ScriptableObject disk = getDisk((String) diskName);
        // ScriptableObject info = (ScriptableObject)
        // disks.get(diskName);

        final int count = API.getInteger(disks.get(diskName));
        for (int i = 0; i < count; i++) {
View Full Code Here

  private String confirm(final String jwt, final String user)
      throws GameEngineException {
    Step step = MiniProfiler.step("API.confirm");
    try {
      final String sd = deserialize(jwt);
      final ScriptableObject f = ge.execute("_=" + sd);
      final ScriptableObject jwtResponse = (ScriptableObject) f
          .get("response");
      final ScriptableObject jwtRequest = (ScriptableObject) f
          .get("request");
      final String u = (String) jwtRequest.get("sellerData");
      // make sure its still the same person
      if (user != u) {
        return "";
      }

      final String orderId = (String) jwtResponse.get("orderId");
      // add the disks to the player
      final ScriptableObject player = getPlayer(user);
      completePurchase(player);

      savePlayer(player);

      return orderId;
View Full Code Here

  }

  private ScriptableObject createDisk() throws GameEngineException {
    Step step = MiniProfiler.step("API.createDisk");
    try {
      final ScriptableObject disk = (ScriptableObject) ge.invoke("Disk");
      return disk;
    } finally {
      step.close();
    }
  }
View Full Code Here

    Step step = MiniProfiler.step("API.createDisk(...)");
    try {
      // name, attack, defense, toughness, movement, wounds, flying,
      // swashbuckler,cost,
      // faction, alignment, diameter, description, price
      final ScriptableObject disk = (ScriptableObject) ge.invoke("Disk",
          new Object[] { name, type, attack, defense, toughness,
              movement, wounds, flying, swashbuckler, archer,
              arrows, bolts, fireballs, boulders,
              missileImmunity, firstblow, spellcaster, limit,
              cost, faction, alignment, diameter, description,
View Full Code Here

      for (HashMap<String, Object> diskMap : disks.values()) {
        final String diskJson = (String) diskMap.get("json");

        // final ScriptableObject o = ge.execute("_=" + diskJson);

        final ScriptableObject disk = createDisk();

        update(disk, ge.parse(diskJson));

        // header
        if (header) {
          for (final Object id : disk.getIds()) {

            if (disk.get(id) instanceof String
                || disk.get(id) instanceof Number
                || disk.get(id) instanceof Boolean) {
              csv.append(id + ",");
            }
          }
          header = false;
          csv.append("\n");
        }

        // data
        for (final Object id : disk.getIds()) {

          if (disk.get(id) instanceof String) {
            csv.append("\""
                + ((String) disk.get(id)).replaceAll("\"",
                    "\"\"") + "\",");
          } else if (disk.get(id) instanceof Number
              || disk.get(id) instanceof Boolean) {
            csv.append(disk.get(id) + ",");
          }
        }

        csv.append("\n");
      }
View Full Code Here

      throws GameEngineException {
    Step step = MiniProfiler.step("API.createPlayer");

    try {
      // createPlayer
      final ScriptableObject player = (ScriptableObject) ge.invoke(
          "Player", new String[] { username, });
      final LinkedHashMap<String, ScriptableObject[]> disks = new LinkedHashMap<String, ScriptableObject[]>();

      // Knights
      // Pikemen
      disks.put("Pikemen",
          new ScriptableObject[] { createPoint(-3.2, -6.2),
              createPoint(-1.2, -5), createPoint(-2.6, -3.6), });

      // Heavy Horse Cavalry
      disks.put("Heavy Horse Cavalry", new ScriptableObject[] {
          createPoint(-4.5, -4.5), createPoint(-5.7, -2.9),
          createPoint(-4.1, -1.7), createPoint(-6, -.8) });

      // Elf
      // Deepwood Warriors x3
      disks.put("Deepwood Warriors", new ScriptableObject[] {
          createPoint(3.6, -6.4), createPoint(2.4, -5.4),
          createPoint(3.6, -3.8), });
      // Riders of the Wood x4
      disks.put("Riders of the Wood", new ScriptableObject[] {
          createPoint(4.6, -5.4), createPoint(6.5, -4.0),
          createPoint(5.1, -2.1), createPoint(6.5, -.6) });
      // Deepwood Archers x2
      disks.put("Deepwood Archers",
          new ScriptableObject[] { createPoint(7.5, -2.3),
              createPoint(8.8, -1) });

      // Dwarf
      // Damlo Hammerfist
      disks.put("Damlo Hammerfist",
          new ScriptableObject[] { createPoint(-8.7, 1.3), });
      // Grovan of the Deep
      disks.put("Grovan of the Deep",
          new ScriptableObject[] { createPoint(-9.7, 2.2), });
      // Stalwarts x1
      disks.put("Stalwarts",
          new ScriptableObject[] { createPoint(-9.1, 3.8), });

      // Regiment of the Anvil x5
      disks.put("Regiment of the Anvil",
          new ScriptableObject[] { createPoint(-7.6, 2.9),
              createPoint(-6.8, 4.2), createPoint(-8.2, 5),
              createPoint(-7.2, 6.5), createPoint(-5.7, 5.7), });

      // Orc
      // Urgg the Really Mean x1[+][-]
      disks.put("Urgg the Really Mean",
          new ScriptableObject[] { createPoint(9.4, 1.3), });
      // Shieldgrogs x2[+][-]
      disks.put("Shieldgrogs",
          new ScriptableObject[] { createPoint(9.8, 3.4),
              createPoint(10.5, 2.5), });
      // Ghash Zzurkan x1[+][-]
      disks.put("Ghash Zzurkan",
          new ScriptableObject[] { createPoint(8.4, 2.5), });
      // Grugs x5
      disks.put("Grugs",
          new ScriptableObject[] { createPoint(6.6, 6.7),
              createPoint(6.6, 5), createPoint(7.9, 6.1),
              createPoint(7.5, 3.8), createPoint(8.8, 4.8), });

      // Dragon
      // Dragonflight
      disks.put(
          "Dragonflight",
          new ScriptableObject[] { createPoint(-3, 7),
              createPoint(-3, 8.5), createPoint(-1.5, 8.5),
              createPoint(-1.5, 7) });

      // Drake Warriors
      disks.put(
          "Drake Warriors",
          new ScriptableObject[] { createPoint(0, 7),
              createPoint(0, 8.5), createPoint(1.5, 8.5), });

      // Dragonling
      disks.put("Dragonling", new ScriptableObject[] {
          createPoint(1.5, 7), createPoint(3, 7),
          createPoint(3, 8.5), });

      final String knights = "Starter Knights";
      final String elves = "Starter Elf";
      final String dwarfs = "Starter Dwarf";
      final String dragons = "Starter Dragons";
      final String orcs = "Starter Orc";

      for (final Entry<String, ScriptableObject[]> entry : disks
          .entrySet()) {
        final ScriptableObject disk = getDisk(entry.getKey());
        if (disk.get("name") != null) {

          for (final ScriptableObject location : entry.getValue()) {

            // addDisk
            Object diskNumber = ge.invoke(player, "addDisk",
                new Object[] { disk, location });

            // knight disk
            if (disk.get("faction").equals("Knight")) {
              ge.invoke(player, "addDiskToArmy", new Object[] {
                  knights, diskNumber, location });
            }
            // dragon disk
            else if (disk.get("faction").equals("Dragon")) {
              ge.invoke(player, "addDiskToArmy", new Object[] {
                  dragons, diskNumber, location });
            }
            // dwarf disk
            else if (disk.get("faction").equals("Dwarf")) {
              ge.invoke(player, "addDiskToArmy", new Object[] {
                  dwarfs, diskNumber, location });
            }

            // elf disk
            else if (disk.get("faction").equals("Elf")) {
              ge.invoke(player, "addDiskToArmy", new Object[] {
                  elves, diskNumber, location });
            }

            // orc disk
            else if (disk.get("faction").equals("Orc")) {
              ge.invoke(player, "addDiskToArmy", new Object[] {
                  orcs, diskNumber, location });
            }
          }
        }
View Full Code Here

  }

  private ScriptableObject createTable() throws GameEngineException {
    Step step = MiniProfiler.step("API.createTable");
    try {
      final ScriptableObject table = (ScriptableObject) ge
          .invoke("Table");

      return table;
    } finally {
      step.close();
View Full Code Here

TOP

Related Classes of org.mozilla.javascript.ScriptableObject

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.