Ejemplo n.º 1
0
  public static Thing createHero(String name, String race, String profession) {

    Thing h = createBaseHero(race);
    Game.instance().initialize(h);

    if ((name == null) || (name.equals(""))) name = "Tester";
    setHeroName(h, name);

    // Debug mode modifications
    if (Game.isDebug()) {
      addDebugModifications(h);
    }

    // Race Modifications
    applyRace(h, race);

    // Professions
    applyProfession(h, profession);

    // Bonus items based on skills
    applyBonusItems(h);

    // set up HPS and MPS
    h.set(RPG.ST_HPSMAX, h.getBaseStat(RPG.ST_TG) + RPG.d(6));
    h.set(RPG.ST_MPSMAX, h.getBaseStat(RPG.ST_WP) + RPG.d(6));

    h.set(RPG.ST_HPS, h.getStat(RPG.ST_HPSMAX));
    h.set(RPG.ST_MPS, h.getStat(RPG.ST_MPSMAX));

    Being.utiliseItems(h);

    Wish.makeWish("id", 100);

    // score starts at zero
    h.set("Score", 0);

    // religion
    ArrayList gods = Gods.getPossibleGods(h);
    int gl = gods.size();
    if (gl > 0) {
      h.set("Religion", gods.get(RPG.r(gl)));
    } else {
      Game.warn("No religion available for " + race + " " + profession);
    }

    createHeroHistory(h);

    // performance improvement with flattened properties
    h.flattenProperties();

    return h;
  }
Ejemplo n.º 2
0
 public static void cure(Thing t, int power) {
   Thing[] poisons = t.getFlaggedContents("IsPoison");
   boolean cured = false;
   for (int i = 0; i < poisons.length; i++) {
     Thing p = poisons[i];
     Game.warn("Poison.cure(): " + power);
     if (RPG.test(power, poisons.length * p.getStat("CureDifficulty"))) {
       p.remove();
       cured = true;
     }
   }
   if (cured) {
     t.message("You feel refreshed");
   }
 }
Ejemplo n.º 3
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;
  }
Ejemplo n.º 4
0
  public void gameOver() {
    Wish.makeWish("identification", 100);
    Game.message("");

    Thing h = Game.hero();

    String outcome = getDeathString(h);

    String story = null;

    getScreen().getMappanel().repaint();

    String hresult = "No high score available in debug mode";

    int sc = h.getStat("Score");
    String score = Integer.toString(sc);
    String level = Integer.toString(h.getLevel());
    String seed = Integer.toString(h.getStat("Seed"));
    String name = h.getString("HeroName");
    String profession = h.getString("Profession");
    String race = h.getString("Race");

    try {
      String urldeath = URLEncoder.encode(outcome, fileEncoding);
      String urlname = URLEncoder.encode(name, fileEncoding);

      String check =
          Integer.toString((sc + name.length() * profession.length() * race.length()) ^ 12345678);
      String st =
          "&name="
              + urlname
              + "&race="
              + race
              + "&profession="
              + profession
              + "&level="
              + level
              + "&score="
              + score
              + "&check="
              + check
              + "&version="
              + Game.VERSION
              + "&seed="
              + seed
              + "&death="
              + urldeath;

      String url = "http://tyrant.sourceforge.net/logscore.php?client=tyrant" + st;

      Game.warn((Game.isDebug() ? "NOT " : "") + "Sending data:");
      Game.warn(st);

      if (!Game.isDebug()) {
        URL u = new URL(url);
        InputStream s = u.openStream();

        String returnstring = "";
        int b = s.read();
        while (b >= 0) {
          returnstring = returnstring + (char) b;
          b = s.read();
        }

        int ok = returnstring.indexOf("OK:");
        if (ok >= 0) {
          hresult = "High score logged.\n";
          hresult += "You are in position " + returnstring.substring(ok + 3).trim();
        } else {
          hresult = "Failed to log high score";
          Game.warn(returnstring);
        }
      }
    } catch (Exception e) {
      Game.warn(e.getMessage());
      hresult = "High score feature not available";
    }

    if ((!h.isDead())) {
      story =
          "You have defeated The Tyrant!\n"
              + "\n"
              + "Having saved the world from such malevolent evil, you are crowned as the new Emperor of Daedor, greatly beloved by all the people of the Earth.\n"
              + "\n"
              + "You rule an Empire of peace and prosperity, and enjoy a long and happy life.\n"
              + "\n"
              + "Hurrah for Emperor "
              + h.getString("HeroName")
              + "!!\n";

      if (Game.isDebug()) {
        story =
            "You have defeated The Tyrant in Debug Mode.\n"
                + "\n"
                + "Now go and do it the hard way....\n";
      }

    } else {
      story =
          "\n"
              + "It's all over...... "
              + outcome
              + "\n"
              + "\n"
              + "You have failed in your adventures and died a hideous death.\n"
              + "\n"
              + "You reached level "
              + level
              + "\n"
              + "Your score is "
              + score
              + "\n"
              + "\n"
              + hresult
              + "\n";
    }

    Game.message("GAME OVER - " + outcome);

    Game.message("Would you like to see your final posessions? (y/n)");

    char c = Game.getOption("yn");

    if (c == 'y') {
      Game.selectItem("Your final posessions:", h);
    }

    // display the final story
    Game.scrollTextScreen(story);

    // display the final story
    String killData = Hero.reportKillData();
    Game.scrollTextScreen(killData);

    Game.over = true;

    Lib.clear();

    // recreate lib in background
    Game.asynchronousCreateLib();
  }