Exemplo 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;
  }
Exemplo n.º 2
0
  // creates a hero according to specified parameters
  public Thing createHero(boolean prompts) {
    long start = System.currentTimeMillis();
    String race = null;
    String profession = null;

    if (!prompts) {
      race = "human";
      profession = "fighter";
      Game.setDebug(true);
    }

    // get list of races
    String[] raceherostrings = Hero.heroRaces();
    String[] racedescriptions = Hero.heroRaceDescriptions();
    if (race == null) {
      DetailedListScreen ls =
          new DetailedListScreen("What race are you?", raceherostrings, racedescriptions);
      ls.setForeground(new Color(128, 128, 128));
      ls.setBackground(new Color(0, 0, 0));
      ls.bottomString = "Press a letter key to select your race";
      switchScreen(ls);
      while (true) {
        race = (String) ls.getObject();
        // Game.warn(race);
        if ((race != null) || Game.isDebug()) break;
      }
    }

    if (race == null) {
      // Debug mode only
      // have escaped, so choose randomly
      race = raceherostrings[Rand.r(raceherostrings.length)];
      String[] herostrings = Hero.heroProfessions(race);
      profession = herostrings[Rand.r(herostrings.length)];
    }

    // get list of possible prfessions
    String[] professionstrings = Hero.heroProfessions(race);
    String[] professiondescriptions = Hero.heroProfessionDescriptions(race);
    if (profession == null) {

      DetailedListScreen ls =
          new DetailedListScreen(
              "What is your profession?", professionstrings, professiondescriptions);
      ls.bottomString = "Press a letter key to select your profession";
      ls.setForeground(new Color(128, 128, 128));
      ls.setBackground(new Color(0, 0, 0));
      switchScreen(ls);

      while (profession == null) {
        profession = (String) ls.getObject();
      }
    }

    Thing h = Hero.createHero(prompts ? null : "QuickTester", race, profession);

    // hero name and history display
    String name = "QuickTester";
    if (prompts) {
      // setup screen to get name
      Screen ss = new Screen(this);
      ss.setBackground(new Color(0, 0, 0));
      ss.setLayout(new BorderLayout());
      {
        InfoScreen ts = new InfoScreen(this, h.getString("HeroHistory"));
        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);

      name = getHeroName(true);
      if (name == null) return null;
    }
    Hero.setHeroName(h, name);

    System.out.println((System.currentTimeMillis() - start) + "ms to createHero");
    return h;
  }