public static int gainKillExperience(Thing h, Thing t) { int hlevel = h.getLevel(); int tlevel = t.getLevel(); int killcount = 0; if (h.isHero()) { killcount = incKillCount(t); if (killcount == 1) { Score.scoreFirstKill(t); } } int base = t.getStat("XPValue"); double xp = base; xp = xp * Math.pow(experienceDecay, killcount); xp = xp * Math.pow(experienceLevelMultiplier, tlevel - 1); // decrease xp gain for killing lower level monsters if (hlevel > tlevel) xp = xp / (hlevel - tlevel); int gain = (int) xp; Hero.gainExperience(gain); return gain; }
public boolean handle(Thing h, Event e) { int time = e.getStat("Time"); Hero.action(h, time); Being.recover(h, time); return false; }
public void setUp() { RPG.setRandSeed(0); Lib.clear(); hero = Hero.createHero("bob", "human", "fighter"); TyrantTestCase.setTestHero(hero); NullHandler.installNullMessageHandler(); Game.setUserinterface(null); String mapString = "################################" + "\n" + "#@.............................#" + "\n" + "##.............................#" + "\n" + "#..............................#" + "\n" + "################################"; map = new MapHelper().createMap(mapString); for (int x = hero.x; x < map.getWidth(); x++) { if (!map.isBlocked(x, 1)) { map.addThing(Lib.create("[IsMonster]"), x, 1); map.addThing(Lib.create("[IsItem]"), x, 1); map.addThing(Lib.create("menhir"), x, 2); map.addThing(Lib.create("[IsMonster]"), x, 3); map.addThing(Lib.create("[IsItem]"), x, 3); } } hero.set("IsImmortal", true); gameScreen = new GameScreen(new QuestApp()); gameScreen.map = map; }
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(); }
// 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; }