Beispiel #1
0
 private void talk(int p, final Thing t) {
   int subtype = getStat("SubType");
   Thing h = Game.hero();
   try {
     switch (p) {
       case CHATTER:
         t.incStat("ChatCount", 1);
         handleChatter(subtype, t.getStat("ChatCount"), t);
         return;
       case TEACHER:
         if (h.getStat(RPG.ST_SKILLPOINTS) > 0) {
           Game.message("\"I see you have potential\"");
           Game.message("\"I can teach you for a small fee...\"");
         } else {
           Game.message("\"There is nothing more I can teach you now.\"");
         }
         return;
         // added by ppirrip
       case BLACKSMITH:
         Game.message("\"I can repair your gear for a small fee...\"");
         return;
       default:
         Game.message("You get no response.");
     }
   } catch (Exception e) {
     e.printStackTrace();
     Game.message("\"Mumble mumble mumble\"");
   }
 }
Beispiel #2
0
  // can't do anything in monster action phase
  // but allow for hunger effects
  public static void action(Thing h, int t) {
    // hunger
    int hunger = h.getStat(RPG.ST_HUNGER);
    int hungerThreshold = h.getStat("HungerThreshold");
    hunger = RPG.min(hungerThreshold * 3, hunger + (t * 6) / (6 + h.getStat(Skill.SURVIVAL)));
    h.set(RPG.ST_HUNGER, hunger);

    // bad things
    int hl = hunger / hungerThreshold;
    switch (hl) {
      case 0:
      case 1:
        // OK
        break;
      case 2:
        for (int i = RPG.po(t, 10000); i > 0; i--) {
          Game.message("You feel weak with hunger!");
          String stat = RPG.pick(hungerDecayStats);
          int sv = h.getBaseStat(stat);
          if (!h.getFlag("IsImmortal")) h.set(stat, RPG.max(sv - 1, 1));
        }
        break;
      case 3:
        // dying of hunger
        int loss = RPG.po(t / 1000.0);
        if (loss > 0) Game.message("You are dying of hunger!!");
        if (!h.getFlag("IsImmortal")) h.incStat("HPSMAX", -loss);
        if (!h.getFlag("IsImmortal")) h.incStat("HPS", -loss * 2);
        break;
    }

    // SPECIAL ABILITIES
    // thief searches
    for (int i = RPG.po(t * h.getStat(Skill.ALERTNESS) * h.getStat(RPG.ST_CR), 10000); i > 0; i--) {
      Secret.search();
    }
  }
Beispiel #3
0
 private void handleChatter(final int subtype, final int chats, final Thing t) {
   final ChatterComment cc = chattercomments[subtype];
   switch (chats) {
     case 1:
       // -this is first converstaion to Hero - try to say hello
       if (cc.hello.length != 0 && RPG.p(cc.helloProbability)) {
         Game.quotedMessage(RPG.pick(cc.hello));
         break;
       }
     default:
       // say comment
       Game.message("\"" + RPG.pick(cc.comments) + "\"");
       t.set("ChatCount", 100);
   }
 }
Beispiel #4
0
  public String getHeroName(boolean notNull) {

    // ss.invalidate();
    // ss.validate();
    // ss.repaint();

    // get hero name
    String hname = null;

    Game.message("");
    while ((hname == null) || hname.equals("")) {
      hname = Game.getLine("Enter your name: ");
      if (hname.equals("ESC")) {
        return null;
      }
      if ((!notNull) && hname.equals("")) return null;
    }
    return hname;
  }
Beispiel #5
0
  // called to check for random encounters
  public static void encounter(Map map, int x, int y) {
    if (Rand.d(20) > 1) return;

    Thing h = Game.hero();

    // don't have encounters on location squares
    Thing[] ts = map.getPortals(x, y);
    if (ts.length > 0) return;

    int tile = map.getTile(x, y);
    if (tile == Tile.SEA) {
      return;
    }

    switch (Rand.d(8)) {
      case 1:
        {
          Game.message("You see somebody in the distance");
          break;
        }

      case 2:
        {
          Thing c = Lib.createType("IsHostile", Game.hero().getStat(RPG.ST_LEVEL) + Rand.r(6));
          Game.message("You see " + c.getAName() + " waiting to ambush travellers");
          Game.message("Do you want to attack? (y/n)");

          if (Game.getOption("yn") == 'y') {
            Game.message("");

            // create location map
            Map nm = createArea(map, x, y);

            nm.addThing(Game.hero(), 32, 32);
            nm.addThing(c, 32, 25);

            // companions
            if (Rand.d(2) == 1) {
              for (int i = Rand.d(6); i > 0; i--) {
                int gx = 28 + Rand.r(9);
                int gy = 18 + Rand.r(7);
                if (!nm.isBlocked(gx, gy)) {
                  nm.addThing(c.cloneType(), gx, gy);
                }
              }
              if ((Rand.d(2) == 1) && (!nm.isBlocked(32, 20))) {
                nm.addThing(Lib.createFoe(Game.hero().getStat(RPG.ST_LEVEL) + 1), 32, 20);
              }
            }
          } else {
            Game.message("You avoid the encounter");
          }
          break;
        }

      case 3:
        {
          Thing c = Lib.createFoe(Game.hero().getStat(RPG.ST_LEVEL) + 2);
          Game.message("You see some villagers being attacked by " + c.getPluralName());
          Game.message("Do you want to aid them? (y/n)");

          if (Game.getOption("yn") == 'y') {
            // create location map
            Map nm = createArea(map, x, y);

            nm.addThing(Game.hero(), 32, 32);

            // villages
            for (int i = Rand.d(2, 3); i > 0; i--) {
              int gx = 29 + Rand.r(7);
              int gy = 28 + Rand.r(7);
              if (!nm.isBlocked(gx, gy))
                switch (Rand.d(3)) {
                  case 1:
                    nm.addThing(Lib.create("farmer"), gx, gy);
                    break;
                  case 2:
                    nm.addThing(Lib.create("village girl"), gx, gy);
                    break;
                  case 3:
                    nm.addThing(Lib.create("townswoman"), gx, gy);
                    break;
                }
            }

            // critters
            for (int i = Rand.d(2, 6); i > 0; i--) {
              int gx = 28 + Rand.r(9);
              int gy = 21 + Rand.r(7);
              if (!nm.isBlocked(gx, gy)) {
                nm.addThing(c.cloneType(), gx, gy);
              }
            }
            // boss critter
            nm.addThing(Lib.createFoe(Game.hero().getStat(RPG.ST_LEVEL) + 4), 32, 20);
          } else {
            Game.message("You leave them to their fate");
          }
          break;
        }

      case 4:
        {
          Game.message("You are slowed by bad weather conditions.");
          h.incStat("APS", -1000);
          break;
        }

      case 5:
        {
          int level = h.getLevel();
          if (level <= 2) break;

          Game.message("You are ambushed by a horde of fearsome monsters!");
          Game.message("[Press space to continue]");
          Game.getOption(" ");

          Map nm = createArea(map, x, y);
          nm.set("IsHostile", 1);

          nm.addThing(Game.hero(), 32, 32);

          for (int i = 0; i < 40 + 3 * level; i++) {
            nm.addThing(Lib.createType("IsMonster", level));
          }

          break;
        }

      case 6:
        {
          Thing[] its = h.getItems();
          Thing it = (its.length > 0) ? its[Rand.r(its.length)] : null;
          if ((it != null) && !it.getFlag("IsCursed") && (Item.value(it) > 0)) {

            Game.message("You encounter a band of nasty goblinoids!");
            Game.message("They demand " + it.getYourName() + " as 'tax'");
            Game.message("Do you want to fight them? (y/n)");
            char c = Game.getOption("yn");
            while (!((c == 'y') || (c == 'n'))) c = Game.getOption("yn");

            if (c == 'n') {
              it.remove();
              if (Rand.d(50) <= h.getLevel()) {
                Game.message("They decide to attack you anyway!");
                c = 'y';
              } else {
                Game.message("They take " + it.getYourName() + " and run away gleefully");
              }
            } else {
              // don't lose an item
              it = null;
            }

            if (c == 'y') {
              Map nm = createArea(map, x, y);
              nm.set("IsHostile", 1);

              nm.addThing(Game.hero(), 32, 32);
              nm.addThing(it, 32, 36);
              int level = h.getLevel();

              for (int i = 0; i < (2 + level); i++) {
                nm.addThing(
                    Lib.createType("IsGoblinoid", level), h.x - 3, h.y + 1, h.x + 3, h.y + 4);
              }
            }
          }

          break;
        }
    }
  }
Beispiel #6
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();
  }
Beispiel #7
0
  // this is the actual game thread start
  // it loops for each complete game played
  public void run() {
    while (true) {

      Screen ss = new Screen(this);
      ss.setBackground(new Color(0, 0, 0));
      ss.setLayout(new BorderLayout());
      {
        TitleScreen ts = new TitleScreen(this);
        ts.setBackground(new Color(0, 0, 0));
        ss.add("Center", ts);
      }
      MessagePanel mp = new MessagePanel(this);
      Game.messagepanel = mp;
      ss.add("South", mp);

      switchScreen(ss);

      repaint();

      if (!isapplet && gameFileFromCommandLine != null) {
        Game.message("Loading " + gameFileFromCommandLine + " game file...");
        final String ret = Game.tryToRestore(gameFileFromCommandLine);
        if (ret == null) {
          setupScreen();
          getScreen().mainLoop();
          continue;
        }

        Game.message("Load game failed: " + ret);
        Game.message("Press any key (except Tab) to continue");
        Game.getInput(false); // !!! not very good - this does not
        // recognize Tab key, for instance

      }

      Game.message("");
      Game.message(
          "Welcome to Tyrant. You are playing version " + Game.VERSION + ". Would you like to:");
      Game.message(" [a] Create a new character");
      Game.message(" [b] Load a previously saved game");
      Game.message(" [c] Play in debug mode");
      Game.message(" [d] QuickStart debug mode");
      Game.message(" [e] Edit a map");
      mp.repaint();

      // create lib in background
      Game.asynchronousCreateLib();

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

      Game.setDebug(false);
      Game.visuals = true;

      if (c == 'b') {
        if (Game.restore()) {
          setupScreen();
          getScreen().mainLoop();
        }

      } else if (c == 'c') {
        // do hero creation
        Game.create();
        Thing h = createHero(true);
        if (h == null) continue;

        Game.setDebug(true);
        setupScreen();
        gameStart();

      } else if (c == 'e') {
        // Designer
        Game.message("");
        Game.message("Launching Designer...");
        mikera.tyrant.author.Designer.main(new String[] {"embedded"});
        continue;

      } else {

        Game.create();
        Thing h = createHero(true);

        if (h == null) continue;

        // first display starting info....
        InfoScreen l =
            new InfoScreen(
                this,
                "                                 Introduction\n"
                    + "\n"
                    + "Times are hard for the humble adventurer. Lawlessness has ravaged the land, and few can afford to pay for your services.\n"
                    + "\n"
                    + "After many weeks of travel, you find yourself in the valley of North Karrain. This region has suffered less badly from the incursions of evil, and you hear that some small towns are still prosperous. Perhaps here you can find a way to make your fortune.\n"
                    + "\n"
                    + "After a long day of travel, you see a small inn to the west. Perhaps this would be a good place to meet some and learn some more about these strange lands.\n"
                    + "\n"
                    + "                           [ Press a key to continue ]\n"
                    + "\n"
                    + "\n"
                    + "\n"
                    + "\n"
                    + "\n");

        l.setForeground(new Color(192, 160, 64));
        l.setBackground(new Color(0, 0, 0));
        switchScreen(l);
        Game.getInput();
        setupScreen();
        gameStart();

        // Debug mode should not start when pressing Enter!!
        // Game.create();
        // Game.setDebug(true);
        // createHero(false);
        // setupScreen();
        // gameStart();
      }
    }
  }