Exemplo n.º 1
0
  // enter a world map square
  //  - if there is a portal to a special location then use it
  //  - else create the appropraite outdoor area map
  //
  public static void exitWorldMap(Map m, int tx, int ty) {
    Thing h = Game.hero();

    // record movement time
    Time.logTime(Movement.moveCost(m, h, tx, ty));

    Thing p = m.getFlaggedObject(tx, ty, "IsPortal");
    if (p != null) {
      Portal.travel(p, h);
    } else {
      // put hero into a local area map
      Map nm = WorldMap.createArea(m, tx, ty);

      // phantom Portal
      p = Portal.create();
      Thing t = nm.getEntrance();
      Portal.setDestination(p, nm, t.x, t.y);

      // could build a portal here so we can return to exact location map
      // Don't think we really want this though
      //   addThing(p,tx,ty);

      Portal.travel(p, h);
    }
  }
Exemplo n.º 2
0
  @Test
  public void creatingANavigationShouldLinkNavigationAndNode() {
    Id<Portal> classic = gateIn.siteId(Site.Type.PORTAL, "classic");
    Portal portal = gateIn.get(classic);
    assert portal.equals(gateIn.getPortal(classic));

    Page page = portal.getPageRegistry().get(classic.getIdforChild("page"));
    Id<Page> pageId = page.getId();
    assert page.equals(gateIn.get(pageId));

    Navigation nav = portal.getNavigation().get("page");
    assert page.equals(nav.getTargetPage());

    Page sub = portal.getPageRegistry().get("sub");
    assert sub.equals(gateIn.get(pageId.getIdforChild("sub")));

    Navigation navigation = portal.createNavigationTo(sub, portal.getNavigation());
    assert sub.equals(navigation.getTargetPage());
    assert sub.getInboundNavigations().contains(navigation.getId());
    assert portal.getNavigation().contains(navigation.getName());

    Navigation inboundNavigation = sub.createInboundNavigationIn(portal, portal.getNavigation());
    assert sub.equals(inboundNavigation.getTargetPage());
    assert sub.getInboundNavigations().contains(inboundNavigation.getId());
    assert portal.getNavigation().contains(inboundNavigation.getName());
  }
Exemplo n.º 3
0
 public static Location getEvacuation(Player player) {
   World world = player.getWorld();
   String[] portalnames;
   if (Permission.has(player, "world.spawn") || Permission.has(player, "tpp")) {
     for (Position pos : getSpawnPoints()) {
       Location loc = pos.toLocation();
       if (loc.getWorld() == null) continue;
       if (Permission.canEnter(player, loc.getWorld())) {
         return loc;
       }
     }
     portalnames = Portal.getPortals();
   } else {
     portalnames = Portal.getPortals(world);
   }
   for (String name : portalnames) {
     if (Permission.canEnterPortal(player, name)) {
       Location loc = Portal.getPortalLocation(name, player.getWorld().getName(), true);
       if (loc == null) continue;
       if (loc.getWorld() == null) continue;
       if (Permission.canEnter(player, loc.getWorld())) {
         return loc;
       }
     }
   }
   return null;
 }
Exemplo n.º 4
0
 private void _buildDestinations() {
   for (String portalName : _ini.keys("destinations")) {
     String destName = _ini.get("destinations", portalName);
     Portal portal = _portals.get(portalName);
     Space space = _spaces.get(destName);
     if (space == null) {
       System.out.println("error,there's nowhere to go");
       System.exit(1);
     } else {
       portal.setDestination(space);
     }
   }
 }
Exemplo n.º 5
0
  @Test
  public void creatingASimplePage() {
    Portal portal = gateIn.getDefaultPortal();

    String name = "name", title = "title";
    Page page = portal.getPageRegistry().createAndAdd(name);
    assert name.equals(page.getId().toString());
    assert name.equals(page.getTitle())
        : "By default, a Page's title should be the same as its name";
    assert portal.equals(page.getSite());

    page.setTitle(title);
    assert title.equals(page.getTitle());
  }
Exemplo n.º 6
0
  public static Map createWorld() {
    Map m = Portal.loadFromFile("/maps/world/karrain.txt");

    m.set("EnterMessage", "This fertile valley is known as North Karrain");
    m.set("OnAction", new EncounterAction());

    return m;
  }
Exemplo n.º 7
0
  // create Outdoor Area for specified square
  // can drop hero strainght into this
  private static Map createArea(Map m, int tx, int ty) {
    Map newmap = Outdoors.create(m.getTile(tx, ty));

    // link back to worldmap
    Portal.setDestination(newmap.getEntrance(), m, tx, ty);

    return newmap;
  }
Exemplo n.º 8
0
 @Override
 public boolean canFork(HttpServletRequest req) {
   //
   String pagePath = getRequestPath(req);
   Map<String, String> params = getRequestParams(req);
   //
   PageConfig pageConfig = pageLoader.load(pagePath, params);
   Portal.setPageConfig(req, pageConfig);
   //
   return pageConfig != null;
 }
Exemplo n.º 9
0
  public void gameStart() {
    Game.setQuestapp(this);
    Thing h = Game.hero();
    if (h == null) throw new Error("Hero not created");
    Game.instance().initialize(h);

    Map world = Game.instance().createWorld();

    Quest.addQuest(h, Quest.createVisitMapQuest("Vist a town", "town"));

    Thing port = world.find("tutorial inn");
    Map tm = Portal.getTargetMap(port);
    gameStart(tm, tm.getEntrance().x, tm.getEntrance().y);
  }
Exemplo n.º 10
0
 @Override
 public List<ForkedRequestAndResponse> fork(HttpServletRequest req, HttpServletResponse res) {
   //
   PageConfig pageConfig = Portal.getPageConfig(req);
   //
   List<ForkedRequestAndResponse> forkedList = new ArrayList<ForkedRequestAndResponse>();
   for (PageletConfig pageletConfig : pageConfig.getAllPageletConfig()) {
     String forkedName = pageletConfig.getId();
     String forkedPath = pageletConfig.getPath();
     //
     ForkedHttpServletRequest forkedReq = new ForkedHttpServletRequest(req, forkedPath);
     ForkedHttpServletResponse forkedRes = new ForkedHttpServletResponse(res);
     //
     forkedList.add(new ForkedRequestAndResponse(forkedName, forkedReq, forkedRes));
   }
   //
   return forkedList;
 }
Exemplo n.º 11
0
 private void process() throws IOException {
   int x;
   if (initDone) {
     x = dataInRaw.read();
     if (x < 0) {
       stop = true;
       return;
     }
   } else {
     x = 0;
   }
   int len = dataInRaw.readInt();
   len -= 4;
   byte[] data = DataUtils.newBytes(len);
   dataInRaw.readFully(data, 0, len);
   dataIn = new DataInputStream(new ByteArrayInputStream(data, 0, len));
   switchBlock:
   switch (x) {
     case 0:
       server.trace("Init");
       int version = readInt();
       if (version == 80877102) {
         server.trace("CancelRequest (not supported)");
         server.trace(" pid: " + readInt());
         server.trace(" key: " + readInt());
       } else if (version == 80877103) {
         server.trace("SSLRequest");
         out.write('N');
       } else {
         server.trace("StartupMessage");
         server.trace(
             " version " + version + " (" + (version >> 16) + "." + (version & 0xff) + ")");
         while (true) {
           String param = readString();
           if (param.length() == 0) {
             break;
           }
           String value = readString();
           if ("user".equals(param)) {
             this.userName = value;
           } else if ("database".equals(param)) {
             this.databaseName = value;
           } else if ("client_encoding".equals(param)) {
             // UTF8
             clientEncoding = value;
           } else if ("DateStyle".equals(param)) {
             dateStyle = value;
           }
           // extra_float_digits 2
           // geqo on (Genetic Query Optimization)
           server.trace(" param " + param + "=" + value);
         }
         sendAuthenticationCleartextPassword();
         initDone = true;
       }
       break;
     case 'p':
       {
         server.trace("PasswordMessage");
         String password = readString();
         try {
           //                Properties info = new Properties();
           //                info.put("MODE", "PostgreSQL");
           //                info.put("USER", userName);
           //                info.put("PASSWORD", password);
           //                String url = "jdbc:lealone:" + databaseName;
           //                ConnectionInfo ci = new ConnectionInfo(url, info);
           //                String baseDir = server.getBaseDir();
           //                if (baseDir == null) {
           //                    baseDir = SysProperties.getBaseDir();
           //                }
           //                if (baseDir != null) {
           //                    ci.setBaseDir(baseDir);
           //                }
           //                if (server.getIfExists()) {
           //                    ci.setProperty("IFEXISTS", "TRUE");
           //                }
           //                conn = new JdbcConnection(ci, false);
           conn = createJdbcConnection(password);
           // can not do this because when called inside
           // DriverManager.getConnection, a deadlock occurs
           // conn = DriverManager.getConnection(url, userName, password);
           initDb();
           sendAuthenticationOk();
         } catch (Exception e) {
           e.printStackTrace();
           stop = true;
         }
         break;
       }
     case 'P':
       {
         server.trace("Parse");
         Prepared p = new Prepared();
         p.name = readString();
         p.sql = getSQL(readString());
         int count = readShort();
         p.paramType = new int[count];
         for (int i = 0; i < count; i++) {
           int type = readInt();
           server.checkType(type);
           p.paramType[i] = type;
         }
         try {
           p.prep = (JdbcPreparedStatement) conn.prepareStatement(p.sql);
           prepared.put(p.name, p);
           sendParseComplete();
         } catch (Exception e) {
           sendErrorResponse(e);
         }
         break;
       }
     case 'B':
       {
         server.trace("Bind");
         Portal portal = new Portal();
         portal.name = readString();
         String prepName = readString();
         Prepared prep = prepared.get(prepName);
         if (prep == null) {
           sendErrorResponse("Prepared not found");
           break;
         }
         portal.prep = prep;
         portals.put(portal.name, portal);
         int formatCodeCount = readShort();
         int[] formatCodes = new int[formatCodeCount];
         for (int i = 0; i < formatCodeCount; i++) {
           formatCodes[i] = readShort();
         }
         int paramCount = readShort();
         for (int i = 0; i < paramCount; i++) {
           int paramLen = readInt();
           byte[] d2 = DataUtils.newBytes(paramLen);
           readFully(d2);
           try {
             setParameter(prep.prep, i, d2, formatCodes);
           } catch (Exception e) {
             sendErrorResponse(e);
             break switchBlock;
           }
         }
         int resultCodeCount = readShort();
         portal.resultColumnFormat = new int[resultCodeCount];
         for (int i = 0; i < resultCodeCount; i++) {
           portal.resultColumnFormat[i] = readShort();
         }
         sendBindComplete();
         break;
       }
     case 'C':
       {
         char type = (char) readByte();
         String name = readString();
         server.trace("Close");
         if (type == 'S') {
           Prepared p = prepared.remove(name);
           if (p != null) {
             JdbcUtils.closeSilently(p.prep);
           }
         } else if (type == 'P') {
           portals.remove(name);
         } else {
           server.trace("expected S or P, got " + type);
           sendErrorResponse("expected S or P");
           break;
         }
         sendCloseComplete();
         break;
       }
     case 'D':
       {
         char type = (char) readByte();
         String name = readString();
         server.trace("Describe");
         if (type == 'S') {
           Prepared p = prepared.get(name);
           if (p == null) {
             sendErrorResponse("Prepared not found: " + name);
           } else {
             sendParameterDescription(p);
           }
         } else if (type == 'P') {
           Portal p = portals.get(name);
           if (p == null) {
             sendErrorResponse("Portal not found: " + name);
           } else {
             PreparedStatement prep = p.prep.prep;
             try {
               ResultSetMetaData meta = prep.getMetaData();
               sendRowDescription(meta);
             } catch (Exception e) {
               sendErrorResponse(e);
             }
           }
         } else {
           server.trace("expected S or P, got " + type);
           sendErrorResponse("expected S or P");
         }
         break;
       }
     case 'E':
       {
         String name = readString();
         server.trace("Execute");
         Portal p = portals.get(name);
         if (p == null) {
           sendErrorResponse("Portal not found: " + name);
           break;
         }
         int maxRows = readShort();
         Prepared prepared = p.prep;
         JdbcPreparedStatement prep = prepared.prep;
         server.trace(prepared.sql);
         try {
           prep.setMaxRows(maxRows);
           boolean result = prep.execute();
           if (result) {
             try {
               ResultSet rs = prep.getResultSet();
               ResultSetMetaData meta = rs.getMetaData();
               sendRowDescription(meta);
               while (rs.next()) {
                 sendDataRow(rs);
               }
               sendCommandComplete(prep, 0);
             } catch (Exception e) {
               sendErrorResponse(e);
             }
           } else {
             sendCommandComplete(prep, prep.getUpdateCount());
           }
         } catch (Exception e) {
           sendErrorResponse(e);
         }
         break;
       }
     case 'S':
       {
         server.trace("Sync");
         sendReadyForQuery();
         break;
       }
     case 'Q':
       {
         server.trace("Query");
         String query = readString();
         ScriptReader reader = new ScriptReader(new StringReader(query));
         while (true) {
           JdbcStatement stat = null;
           try {
             String s = reader.readStatement();
             if (s == null) {
               break;
             }
             s = getSQL(s);
             stat = (JdbcStatement) conn.createStatement();
             boolean result = stat.execute(s);
             if (result) {
               ResultSet rs = stat.getResultSet();
               ResultSetMetaData meta = rs.getMetaData();
               try {
                 sendRowDescription(meta);
                 while (rs.next()) {
                   sendDataRow(rs);
                 }
                 sendCommandComplete(stat, 0);
               } catch (Exception e) {
                 sendErrorResponse(e);
                 break;
               }
             } else {
               sendCommandComplete(stat, stat.getUpdateCount());
             }
           } catch (SQLException e) {
             sendErrorResponse(e);
             break;
           } finally {
             JdbcUtils.closeSilently(stat);
           }
         }
         sendReadyForQuery();
         break;
       }
     case 'X':
       {
         server.trace("Terminate");
         close();
         break;
       }
     default:
       server.trace("Unsupported: " + x + " (" + (char) x + ")");
       break;
   }
 }
Exemplo n.º 12
0
  private void processMap() throws SlickException {
    // clears array of walls
    for (int x = 0; x < mapa.getWidth(); x++) {
      for (int y = 0; y < mapa.getHeight(); y++) {
        wallMap[x][y] = 0;
      }
    }
    // detects all objects in the tiled map, sets their position and adds them into level
    for (int i = 0; i < mapa.getObjectCount(0); i++) {
      switch (mapa.getObjectType(0, i)) {
        case "player":
          Player hrac = new Player();
          hrac.setPosition(mapa.getObjectX(0, i), mapa.getObjectY(0, i));
          level.addToLevel(hrac);
          level.setPlayer(hrac);
          break;
        case "blob":
          Blob blob = new Blob();
          blob.setPosition(mapa.getObjectX(0, i), mapa.getObjectY(0, i));
          level.addToLevel(blob);
          break;
        case "cron":
          Cron cron = new Cron();
          cron.setPosition(mapa.getObjectX(0, i), mapa.getObjectY(0, i));
          level.addToLevel(cron);
          break;
        case "broom":
          Broom broom = new Broom();
          broom.setPosition(mapa.getObjectX(0, i), mapa.getObjectY(0, i));
          level.addToLevel(broom);
          break;
        case "fantom":
          Fantom fantom = new Fantom();
          fantom.setPosition(mapa.getObjectX(0, i), mapa.getObjectY(0, i));
          level.addToLevel(fantom);
          break;
        case "bomb":
          BombsUp bomba = new BombsUp();
          bomba.setPosition(mapa.getObjectX(0, i), mapa.getObjectY(0, i));
          level.addToLevel(bomba);
          break;
        case "speed":
          SpeedUp speed = new SpeedUp();
          speed.setPosition(mapa.getObjectX(0, i), mapa.getObjectY(0, i));
          level.addToLevel(speed);
          break;
        case "kick":
          KickUp kick = new KickUp();
          kick.setPosition(mapa.getObjectX(0, i), mapa.getObjectY(0, i));
          level.addToLevel(kick);
          break;
        case "range":
          RangeUp range = new RangeUp();
          range.setPosition(mapa.getObjectX(0, i), mapa.getObjectY(0, i));
          level.addToLevel(range);
          break;
        case "portal":
          Portal portal = new Portal();
          portal.setPosition(mapa.getObjectX(0, i), mapa.getObjectY(0, i));
          level.addToLevel(portal);
          break;
        case "dragon":
          Dragon dragon = new Dragon(mapa.getObjectX(0, i), mapa.getObjectY(0, i));
          //    dragon.setPosition(mapa.getObjectX(0, i), mapa.getObjectY(0, i));
          level.addToLevel(dragon);
          break;
      }
    }
    // detects all walls in tiled map, sets their position and adds them
    // into list and array of walls
    int wallX;
    int wallY;
    for (int i = 0; i < mapa.getObjectCount(1); i++) {
      wallX = mapa.getObjectX(1, i);
      wallY = mapa.getObjectY(1, i);
      wallMap[wallX / 32][wallY / 32] = 1;
      switch (mapa.getObjectType(1, i)) {
        case "wall":
          Wall stena = new Wall();
          Walls.add(stena);
          stena.setPosition(wallX, wallY);
          break;

        case "block":
          Block blok = new Block();
          Walls.add(blok);
          blok.setPosition(wallX, wallY);
          break;
      }
    }
  }
Exemplo n.º 13
0
  public static Map createWorldMap(int w, int h) {
    Map m = new Map(w, h);

    m.set("EnterMessage", "This fertile valley is known as North Karrain");
    m.set("Description", "North Karrain Valley");
    m.set("WanderingRate", 0);
    m.set("IsWorldMap", 1);
    m.set("Level", 1);
    m.set("VisionRange", 7);
    m.set("OnAction", new EncounterAction());

    // TODO: Increased move costs and times

    for (int x = 0; x < w; x += 4) {
      m.setTile(x, 0, Tile.MOUNTAINS);
      m.setTile(x, h - 1, Tile.MOUNTAINS);
    }
    for (int y = 0; y < h; y += 4) {
      m.setTile(0, y, Tile.MOUNTAINS);
      m.setTile(w - 1, y, Tile.SEA);
    }

    for (int y = 4; y < h - 4; y += 4)
      for (int x = 4; x < w - 4; x += 4) {
        m.setTile(x, y, terrains[Rand.r(terrains.length)]);
      }

    m.setTile(16, 8, Tile.FORESTS);
    m.setTile(16, 12, Tile.FORESTS);
    m.setTile(16, 16, Tile.PLAINS);
    m.setTile(12, 12, Tile.FORESTS);
    m.setTile(8, 12, Tile.HILLS);

    m.fractalizeBlock(0, 0, w - 1, h - 1, 4);

    // starting town + quest
    m.addThing(Portal.create("town"), 16, 16);
    m.addThing(Portal.create("ruin"), 16, 8);

    // mutable thing!
    // addThing(new Mutable("beefcake"),15,15);

    // some other towns
    m.addThing(Portal.create("town"), 0, 0, m.width - 1, m.height - 1);
    m.addThing(Portal.create("town"), 0, 0, m.width - 1, m.height - 1);

    // caves
    m.addThing(Portal.create("caves"), 0, 0, m.width - 1, m.height - 1);

    // graveyard
    m.addThing(Portal.create("graveyard"), 0, 0, m.width - 1, m.height - 1);

    // goblin grotto
    m.addThing(Portal.create("grotto"));

    // graveyard
    m.addThing(Portal.create("deep dungeon"), 0, 0, m.width - 1, m.height - 1);

    // special for Christmas!
    Calendar cal = Calendar.getInstance();
    if ((cal.get(Calendar.MONTH) == Calendar.DECEMBER) && (cal.get(Calendar.DAY_OF_MONTH) == 25)) {
      Game.warn("Merry Christmas!!");
      m.addThing(Portal.create("Old Nyck's hut"), 0, 0, m.width - 1, m.height - 1);
    }

    // goblin villae
    m.addThing(Portal.create("goblin village"), 0, 0, m.width - 1, m.height - 1);

    // wood temple
    Point wp = null;
    for (int i = 0; i < 1000; i++) {
      wp = m.findFreeSquare();
      if (m.getTile(wp.x, wp.y) == Tile.FORESTS) break;
    }
    m.addThing(Portal.create("dark forest"), wp.x, wp.y);

    // dark tower
    m.addThing(Portal.create("dark tower"));

    return m;
  }