public static void addDebugModifications(Thing h) { h.set("IsImmortal", 1); h.set("IsDebugMode", 1); if ("QuickTester".equals(h.getString("HeroName"))) { h.addThing(Spell.create("Annihilation")); h.addThing(Spell.create("Blaze")); h.addThing(Spell.create("Ultimate Destruction")); Wish.makeWish("skills", 100); } }
public static void improveSlightly(Thing h) { h.incStat(RPG.ST_MOVESPEED, 100); h.incStat(RPG.ST_ATTACKSPEED, 100); h.incStat("ARM", 10); h.incStat(RPG.ST_REGENERATE, 50); h.incStat(RPG.ST_RECHARGE, 50); }
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 static void addSubQuest(Thing q, Thing sq) { ArrayList qs = (ArrayList) q.get("Quests"); if (qs == null) { qs = new ArrayList(); q.set("Quests", qs); } sq.set("Parent", q); qs.add(sq); }
public static void addQuest(Thing h, Thing q) { ArrayList qs = (ArrayList) h.get("Quests"); if (qs == null) { qs = new ArrayList(); h.set("Quests", qs); } q.set("Hero", h); qs.add(q); }
private static HashMap getKillHashMap() { Thing h = Game.hero(); HashMap hm = (HashMap) h.get("Kills"); if (hm == null) { hm = new HashMap(); h.set("Kills", hm); } return hm; }
public static Thing createKillNumberQuest(String desc, String name, int number) { Thing t = Lib.create("kill number quest"); if (name.startsWith("[")) { t.set("TargetType", name.substring(1, name.length() - 1)); } else { t.set("TargetName", name); } t.set("TargetCount", number); t.set("Description", desc); return t; }
private static boolean notify(Event e) { ArrayList qs = getQuests(); for (Iterator it = qs.iterator(); it.hasNext(); ) { Thing q = (Thing) it.next(); if (q.getFlag("IsActive")) { q.handle(e); } } return false; }
@Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub width = frame.getWidth(); height = frame.getHeight(); sizeControl.width = width; sizeControl.height = height; if (info.pressed == true && !showGuide) { showGuide = true; } if (back.pressed == true && showGuide) { showGuide = false; } go.x = width / 2; go.y = height / 2; info.x = width / 2; info.y = height / 2 + 150; back.x = 3 * width / 4; back.y = height / 2 + 150; for (int i = 0; i < boomList.size(); i++) { boomList.get(i).updatePosition(); if (Integer.parseInt(boomList.get(i).toString()) <= 0) { boomList.remove(i); } else { for (int ii = 0; ii < gravList.size(); ii++) { gravList.get(ii).pull(boomList.get(i)); if (boomList.get(i).collide(gravList.get(ii))) { boomList.remove(i); } } } } count--; if (count <= 0) { double rand1 = Math.random(); double rand2 = Math.random(); for (int ii = 0; ii < num; ii++) { boomList.add(new boom(rand1 * width, rand2 * height)); } count = delay; } repaint(); }
public static String hungerString(Thing h) { int threshold = h.getStat(RPG.ST_HUNGERTHRESHOLD); int hp = (threshold > 0) ? (h.getStat(RPG.ST_HUNGER) * 100) / threshold : 0; if (hp < -50) return "bloated"; if (hp < 0) return "satiated"; if (hp < 20) return "well fed"; if (hp < 70) return "contented"; if (hp < 100) return "peckish"; if (hp < 150) return "hungry"; if (hp < 200) return "very hungry"; if (hp < 250) return "ravenous"; if (hp < 300) return "starving"; return "starving!"; }
public static int getKillCount(Thing t) { HashMap hm = getKillHashMap(); Integer i = (Integer) hm.get(t.name()); if (i == null) return 0; return i.intValue(); }
/* * Gives a number of experience points to the hero */ public static void gainExperience(int x) { Thing h = Game.hero(); // if (QuestApp.debug) Game.warn("You gain "+x+" experience points"); int exp = h.getBaseStat(RPG.ST_EXP) + x; int level = h.getBaseStat(RPG.ST_LEVEL); int requiredForNextLevel = calcXPRequirement(level + 1); while (exp >= requiredForNextLevel) { if (level < 50) { Being.gainLevel(h); exp -= requiredForNextLevel; level++; requiredForNextLevel = calcXPRequirement(level + 1); } else { exp = requiredForNextLevel - 1; } } h.set(RPG.ST_EXP, exp); }
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; }
private static void getQuestText(StringBuffer sb, String prefix, Thing q) { String desc = q.getString("Description"); if (desc != null) { sb.append(prefix); sb.append(Text.capitalise(desc)); if (q.getFlag("IsComplete")) { sb.append(" (complete)"); } if (q.getFlag("IsFailed")) { sb.append(" (failed)"); } sb.append("\n"); ArrayList qs = getSubQuests(q); for (Iterator it = qs.iterator(); it.hasNext(); ) { Thing sq = (Thing) it.next(); getQuestText(sb, prefix + " - ", sq); } } }
public static int incKillCount(Thing t) { HashMap hm = getKillHashMap(); String name = t.name(); Integer i = (Integer) hm.get(name); if (i == null) { i = new Integer(0); } int newKillCount = i.intValue() + 1; hm.put(name, new Integer(newKillCount)); return newKillCount; }
public static void setComplete(Thing q) { if (!q.getFlag("IsActive")) { throw new Error("Trying to complete a non-active quest"); } q.set("IsComplete", 1); q.set("IsActive", 0); if (q.handles("OnQuestComplete")) { Event e = new Event("QuestComplete"); e.set("Quest", q); q.handle(e); } Thing parent = q.getThing("Parent"); if (parent != null) { Event e = new Event("SubQuestComplete"); e.set("Quest", q); q.handle(e); } }
public static Thing createVisitMapQuest(String desc, String targetString) { Thing t = Lib.create("visit map quest"); t.set("TargetMapName", targetString); t.set("Description", desc); return t; }
public static void createHeroHistory(Thing h) { StringBuffer sb = new StringBuffer(); /////////////// // Birth-day Calendar today = Calendar.getInstance(); int day = today.get(Calendar.DAY_OF_MONTH); int month = today.get(Calendar.MONTH) + 1; String birthDay = (day) + "/" + (month); String dayString = Text.ordinal(day); String monthString = months[month]; String r = h.getString("Race"); sb.append( "You are born " + (Text.isVowel(r.charAt(0)) ? "an" : "a") + " " + r + " on the " + dayString + " of " + monthString + ". "); if (birthDay.equals("14/2")) { sb.append("Everyone agreed you were a charming baby. "); h.incStat("CH", RPG.d(6)); h.incStat(Skill.SEDUCTION, 1); } if (birthDay.equals("1/1")) { sb.append("A bright star shone in the sky when you were born. "); h.incStat("WP", RPG.d(6)); } sb.append("\n\n"); ////////////////// // childhood switch (RPG.d(7)) { case 1: sb.append("You had an unhappy childhood, finding it hard to relate to your peers."); h.incStat("WP", RPG.d(3)); h.incStat("CH", -1); break; case 2: sb.append("You had a happy childhood, with supportive parents who taught you well."); h.incStat("IN", RPG.d(3)); h.incStat("CH", -1); break; case 3: sb.append( "You were always getting into trouble as a child, but somehow everything seemed to work out for you. Wise elders were convinced that fortune favoured you. "); h.incStat("Luck", 5); break; case 4: sb.append( "You enjoyed playing outdoors as a child, and excelled in particular at sports. Your peers developed a healthy respect for your talents."); h.incStat(Skill.ATHLETICS, 1); h.incStat("CH", RPG.d(4)); h.incStat("IN", -2); break; case 5: sb.append( "You were badly behaved as a child. You bullied smaller children relentlessly. You came to lead an impressive gang, though they followed you more out of fear than respect."); h.incStat("CH", -1); h.incStat("IN", -3); h.incStat("ST", 2); break; default: sb.append("You had an uneventful childhood, and yearned for adventure."); break; } sb.append("\n\n"); ///////////// // religion String god = h.getString("Religion"); sb.append("You were brough up to worship " + god + ". "); switch (RPG.d(5)) { case 1: sb.append( "You avoided religious ceremonies, as you disliked your priest intensely. You even came to feel that he had laid a curse upon you. "); h.incStat("Luck", -4); break; case 2: sb.append( "You were extremely devout. It caused you great anguish because you never felt that " + god + " was truly close to you. "); h.incStat("WP", 1); h.incStat("CH", -1); break; case 3: sb.append( "You were extremely devout, and your priest praised you for having earnt the blessing of " + god + ". "); h.incStat("Luck", 4); h.incStat(RPG.ST_FATE, 1); break; default: sb.append( "You were not particularly devout, but still felt that " + god + " would protect you. "); break; } sb.append(Gods.get(god).getString("UpbringingText") + " "); sb.append("\n\n"); //////////////// // growing up switch (RPG.d(5)) { case 1: sb.append( "As you grew up, you felt that you were destined for greatness. Everyone else thought that you were merely arrogant. "); h.incStat(RPG.ST_SKILLPOINTS, 1); h.incStat("CH", -3); break; case 2: sb.append( "As you grew up, you found yourself with the remarkable ability to learn creative skills. You had a tendency to dedicate too much time to creative pursuits at the expense of other activities. "); h.incStat( RPG.pick(new String[] {Skill.SMITHING, Skill.PAINTING, Skill.MUSIC, Skill.COOKING}), 1); h.incStat("ST", -1); h.incStat("IN", -1); case 3: sb.append( "Later in your youth, you fell hopelessly in love. Sadly, this was not returned. Heartbroken, you spent countless days wandering alone trying to fathom the meaning of life. "); h.incStat("CH", -1); h.incStat("ST", -1); h.incStat("IN", 2); h.incStat(Skill.PERCEPTION, 1); break; default: sb.append( "You grew up without any particularly great events shaping your life. But you still knew that one day you would set out to achieve greatness. "); break; } sb.append("\n\n"); ///////////// // training String p = h.getString("Profession"); sb.append( "Determined to make something of your life, you began your " + p + " training as soon as you were old enough. "); switch (RPG.d(5)) { default: sb.append( "You showed a good aptitude for your chosen career, and before too long your tutor proclaimed you as a fully trained " + p + "."); break; } sb.append("\n\n"); // ensure all stats are >=1 String[] sks = Being.statNames(); for (int i = 0; i < sks.length; i++) { if (h.getStat(sks[i]) <= 0) { h.set(sks[i], 1); } } h.set("HeroHistory", sb.toString()); }
public static void init() { // initialise base quest templates where needed Thing q; q = Lib.extend("base quest", "base thing"); q.set("LevelMin", 1); q.set("IsQuest", 1); q.set("IsActive", 1); q.set("IsPhysical", 0); q.set("Frequency", 50); q.set( "OnQuestComplete", new Script() { public boolean handle(Thing q, Event e) { String desc = q.getString("Description"); if (desc != null) { Game.message("Quest objective complete: " + desc); } return false; } }); Lib.add(q); q = Lib.extend("kill quest", "base quest"); q.addHandler( "OnKill", new Script() { public boolean handle(Thing q, Event e) { Thing target = q.getThing("Target"); if ((target != null) && target.isDead()) { setComplete(q); } return false; } }); Lib.add(q); q = Lib.extend("kill number quest", "base quest"); q.addHandler( "OnKill", new Script() { public boolean handle(Thing q, Event e) { int target = q.getStat("TargetCount"); int current = q.getStat("CurrentCount"); // get the thing that was killed Thing killed = e.getThing("Target"); String targetName = q.getString("TargetName"); boolean countKill = false; if (targetName != null) { if (targetName.equals(killed.name())) { countKill = true; } } else { String targetType = q.getString("TargetType"); if ((targetType != null) && killed.getFlag(targetType)) { countKill = true; } } if (countKill) { current++; q.set("CurrentCount", current); if (current >= target) { setComplete(q); } } return false; } }); Lib.add(q); q = Lib.extend("visit map quest", "base quest"); q.addHandler( "OnAction", new Script() { public boolean handle(Thing q, Event e) { Map targetMap = (Map) q.get("TargetMap"); Map heroMap = Game.hero().getMap(); if (targetMap == null) { String targetMapName = q.getString("TargetMapName"); if (heroMap.name().startsWith(targetMapName)) { setComplete(q); } } else { if (heroMap == targetMap) { setComplete(q); } } return false; } }); Lib.add(q); q = Lib.extend("meet quest", "base quest"); q.addHandler( "OnAction", new Script() { public boolean handle(Thing q, Event e) { Thing target = q.getThing("Target"); Thing h = Game.hero(); if (target.isDead()) { setFailed(q); return false; } if (h.place != target.place) return false; // check if character is adjacent to hero if ((RPG.abs(h.x - target.x) <= 1) && (RPG.abs(h.y - target.y) <= 1)) { setComplete(q); } return false; } }); Lib.add(q); q = Lib.extend("sequence quest", "base quest"); Script subQuestScript = new Script() { public boolean handle(Thing q, Event e) { ArrayList sqs = getSubQuests(q); boolean complete = true; boolean failed = true; for (Iterator it = sqs.iterator(); it.hasNext(); ) { Thing sq = (Thing) it.next(); if (sq.getFlag("IsFailed")) { failed = true; } if (!sq.getFlag("IsComplete")) { complete = false; } } if (failed) { setFailed(q); } else if (complete) { setComplete(q); } return false; } }; q.addHandler("OnSubQuestComplete", subQuestScript); q.addHandler("OnSubQuestFailed", subQuestScript); Lib.add(q); }
private static ArrayList getSubQuests(Thing q) { ArrayList qs = (ArrayList) q.get("Quests"); if (qs == null) qs = new ArrayList(); return qs; }
public static Thing createMeetQuest(String desc, Thing target) { Thing t = Lib.create("meet quest"); t.set("Target", target); t.set("Description", desc); return t; }
// 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(); } }
public static void setHeroName(Thing h, String name) { h.set("HeroName", name); }
public static int getHunger(Thing t) { int hunger = t.getStat(RPG.ST_HUNGER); return (hunger >= t.getStat("HungerThreshold")) ? 1 : 0; }
private static void applyRace(Thing h, String r) { if (r.equals("human")) { // humans are the most common inhabitants in the world of Tyrant // they are good all-round characters Coin.addMoney(h, 10 * RPG.d(4, 10)); h.addThing(Lib.create("[IsDagger]")); h.addThing(Lib.create("[IsFood]")); } else if (r.equals("dwarf")) { // dwarves are sturdy and industrious cave dwellers // they are famed for their skill in smithing and mining Coin.addMoney(h, 10 * RPG.d(5, 10)); h.addThing(Lib.create("iron hand axe")); h.addThing(Lib.create("loaf of dwarf bread")); } else if (r.equals("hobbit")) { // hobbits are just three feet high // they are peaceful folk, renowned as farmers Coin.addMoney(h, RPG.d(6, 10)); h.addThing(Lib.create("stone knife")); h.addThing(Lib.create("[IsFood]")); h.addThing(Lib.create("[IsFood]")); h.addThing(Lib.create("[IsFood]")); h.addThing(Lib.create("[IsEquipment]")); h.addThing(Lib.create("sling")); h.addThing(Lib.create("10 pebble")); } else if (r.equals("high elf")) { // high elves are noble and wise Coin.addMoney(h, 10 * RPG.d(6, 10)); h.addThing(Lib.create("ornate mithril ring")); h.addThing(Lib.create("elven steel dagger")); } else if (r.equals("wood elf")) { // wood elves are shy of other races // they are agile and talented archers h.addThing(Lib.create("short bow")); h.addThing(Lib.create("lesser elven arrow")); } else if (r.equals("dark elf")) { // dark elves are vicious and powerful // they prefer throwing weapons, darts and shurikens h.addThing(Lib.create("iron dagger")); h.addThing(Lib.create("[IsPotion]")); } else if (r.equals("gnome")) { // gnomes are disadvantage by their small size // they make up for this with igenuity Thing n = Lib.createType("IsMagicItem", 5); Item.identify(n); h.addThing(n); Coin.addMoney(h, 100 * RPG.d(10, 10)); } else if (r.equals("half orc")) { // half orcs are volatile and dangerous h.addThing(Lib.createType("IsWeapon", RPG.d(3))); h.addThing(Lib.create("[IsMeat]")); Coin.addMoney(h, RPG.d(4, 10)); } else if (r.equals("half troll")) { // trolls are lumbering hunks of muscle // with fearsome regenerative powers // they are not very bright h.incStat(RPG.ST_SKILLPOINTS, -1); h.addThing(Lib.createType("IsClub", RPG.d(6))); h.addThing(Lib.create("[IsMeat]")); h.addThing(Lib.create("[IsMeat]")); h.addThing(Lib.create("meat ration")); } else if (r.equals("argonian")) { // some equipment // in line with argonian style h.addThing(Lib.create("[IsTrident]")); h.addThing(Lib.create("[IsMeat]")); h.addThing(Lib.create("[IsFish]")); } else if (r.equals("hawken")) { // some equipment // in line with hawken style h.addThing(Lib.create("[IsDagger]")); h.addThing(Lib.create("[IsMeat]")); Coin.addMoney(h, RPG.d(4, 10)); } else if (r.equals("pensadorian")) { // some equipment // in line with pensadorian style h.addThing(Lib.create("[IsDagger]")); h.addThing(Lib.create("[IsFruit]")); Coin.addMoney(h, RPG.d(4, 10)); } else { throw new Error("Race [" + r + "] not recognised"); } }
public class CSVEntryToEntity { private static final String PREPOSITION_REGEX = "(above|at|but|for|in|of|over|with||without)"; private static final String PREPOSITION_REGEX_WITH_CAPTURE = "(.*?)\\s+" + PREPOSITION_REGEX + "\\s+(.*)"; private static final Pattern patternWithCapture = Pattern.compile(PREPOSITION_REGEX_WITH_CAPTURE, Pattern.CASE_INSENSITIVE); private static final Pattern pattern = Pattern.compile(PREPOSITION_REGEX, Pattern.CASE_INSENSITIVE); private static final String SPACE = " "; private static Map<String, Integer> method_count = new HashMap<>(); private final Map<String, Thing> alreadyExistingElements = new HashMap<>(); private final Thing annotationEntity = new Annotation("annotations"); private final Thing classesEntity = new Entity("classes"); private Matcher matcher; private List<RdfElement> rdfElements; private DisjointClasses disjointClasses = new DisjointClasses(annotationEntity.getName(), classesEntity.getName()); public void convert(List<CSVEntry> itemsToConvert) { rdfElements = new ArrayList<>(); addTopLevelElements(); for (CSVEntry csvEntry : itemsToConvert) { rdfElements.addAll(processAnnotations(csvEntry)); if (descriptionNeedsSpecialHandling(csvEntry)) { rdfElements.addAll(processSpecialCases(csvEntry)); } else { rdfElements.addAll(processCompoundWords(csvEntry)); rdfElements.addAll(processDescription(csvEntry)); } } } private void addTopLevelElements() { rdfElements.add(annotationEntity); rdfElements.add(classesEntity); rdfElements.add(disjointClasses); Property property = new Property.PropertyBuilder() .name("has_annotation") .functional() .domain(classesEntity) .range(annotationEntity) .build(); rdfElements.add(property); } private List<Thing> processAnnotations(CSVEntry csvEntry) { List<Thing> newAnnotations = new ArrayList<>(); for (String annotation : csvEntry.getAnnotations()) { if (alreadyExistingElements.containsKey(getAnnotationName(annotation))) { continue; } Thing newAnnotation = new Annotation(annotationEntity, annotation); newAnnotations.add(newAnnotation); alreadyExistingElements.put(getAnnotationName(annotation), newAnnotation); } return newAnnotations; } private boolean descriptionNeedsSpecialHandling(CSVEntry nature) { return "text".equals(nature.getNature()) || nature.getDescription().contains("ideograph"); } private List<Thing> processSpecialCases(CSVEntry csvEntry) { Thing parent = getParentFromPreposition(csvEntry); Thing subClasses = new Entity(parent, csvEntry.getDescription(), csvEntry.getAnnotations()); alreadyExistingElements.put(csvEntry.getDescription(), subClasses); return Arrays.asList(parent, subClasses); } private Thing getParentFromPreposition(CSVEntry csvEntry) { if ("text".equals(csvEntry.getNature())) { return new Entity("text"); } else { return new Entity(classesEntity, "ideograph", Collections.emptyList()); } } private List<Thing> processCompoundWords(CSVEntry csvEntry) { String description = csvEntry.getDescription(); if (hasPreposition(description)) { return handlePrepositions(csvEntry); } else { return processIndividualWords(description, csvEntry); } } private boolean hasPreposition(String description) { matcher = patternWithCapture.matcher(description); return matcher.find(); } private List<Thing> handlePrepositions(CSVEntry csvEntry) { List<Thing> entities = new ArrayList<>(); String key1 = getLeftHandSideOfPreposition(); entities.addAll(processIndividualWords(key1, csvEntry)); entities.addAll(handleElementOfPreposition(key1, csvEntry)); return entities; } private String getLeftHandSideOfPreposition() { return matcher.group(1); } private List<Thing> processIndividualWords(String descriptions, CSVEntry csvEntry) { List<Thing> lineEntities = new ArrayList<>(); String lastWord = getLastWord(descriptions); if (!isPreposition(lastWord)) { if (!alreadyExistingElements.containsKey(lastWord)) { final Entity entity = new Entity(classesEntity, lastWord, getMatchingAnnotations(lastWord, csvEntry)); lineEntities.add(entity); alreadyExistingElements.put(lastWord, entity); } } return lineEntities; } private String getLastWord(String descriptions) { return descriptions.replaceAll("^.*?(\\w+)\\W*$", "$1"); } private boolean isPreposition(String description) { return pattern.matcher(description).matches(); } private List<Thing> processDescription(CSVEntry csvEntry) { if (alreadyExistingElements.containsKey(csvEntry.getDescription())) { return Collections.emptyList(); } Thing parent = getParent(csvEntry); Thing entity = new Entity(parent, csvEntry.getDescription(), csvEntry.getAnnotations()); alreadyExistingElements.put(csvEntry.getDescription(), entity); return Collections.singletonList(entity); } private Thing getParent(CSVEntry csvEntry) { if (hasPreposition(csvEntry.getDescription())) { return getParentFromPreposition(getLeftHandSideOfPreposition()); } return getParentUsingFullDescription(csvEntry.getDescription()); } private Thing getParentFromPreposition(String description) { if (hasMultipleWordParent(description)) { return getMultipleWordParent(description); } return alreadyExistingElements.get(description); } private Thing getParentUsingFullDescription(String description) { if (hasMultipleWordParent(description)) { return getMultipleWordParent(description); } String lastWord = getLastWord(description); if (alreadyExistingElements.containsKey(lastWord)) { return alreadyExistingElements.get(lastWord); } return new NullEntity(); } private Thing getMultipleWordParent(String parent) { if (alreadyExistingElements.containsKey(parent)) { return alreadyExistingElements.get(parent); } return getParentAfterRemovingFirstWord(parent); } private Thing getParentAfterRemovingFirstWord(String parent) { String[] splitWords = parent.split(SPACE, 2); while (splitWords.length == 2) { if (alreadyExistingElements.containsKey(splitWords[1])) { return alreadyExistingElements.get(splitWords[1]); } else { splitWords = splitWords[1].split(SPACE, 2); } } return alreadyExistingElements.get(splitWords[0]); } private boolean hasMultipleWordParent(String leftHandSideOfPreposition) { if (alreadyExistingElements.containsKey(leftHandSideOfPreposition)) { return true; } String[] headAndTail = leftHandSideOfPreposition.split(SPACE, 2); while (headAndTail.length == 2) { String tail = headAndTail[1]; if (alreadyExistingElements.containsKey(tail)) { return true; } headAndTail = tail.split(SPACE, 2); } return false; } private List<String> getMatchingAnnotations(String name, CSVEntry csvEntry) { for (String annotation : csvEntry.getAnnotations()) { if (annotation.equals(name)) { return Collections.singletonList(name); } } return csvEntry.getAnnotations(); } private List<Thing> handleElementOfPreposition(String key, CSVEntry csvEntry) { if (alreadyExistingElements.containsKey(key)) { return Collections.emptyList(); } Thing possibleParent = getParentFromIndividualWords(key); Thing entity = new Entity(possibleParent, key, csvEntry.getAnnotations()); alreadyExistingElements.put(key, entity); return Collections.singletonList(entity); } private Thing getParentFromIndividualWords(String key) { for (String keyPart : key.split(SPACE)) { if (alreadyExistingElements.containsKey(keyPart)) { return alreadyExistingElements.get(keyPart); } } return new NullEntity(); } public List<RdfElement> getElements() { return rdfElements; } }
private static void applyProfession(Thing h, String p) { h.set("Profession", p); if (p.equals("fighter")) { h.set("Image", 7); h.incStat(RPG.ST_SK, RPG.r(5)); h.incStat(RPG.ST_ST, RPG.r(5)); h.incStat(RPG.ST_AG, RPG.r(4)); h.incStat(RPG.ST_TG, RPG.r(6)); h.incStat(RPG.ST_IN, RPG.r(0)); h.incStat(RPG.ST_WP, RPG.r(0)); h.incStat(RPG.ST_CH, RPG.r(0)); h.incStat(RPG.ST_CR, RPG.r(0)); h.incStat(Skill.ATTACK, 1); h.incStat(Skill.DEFENCE, 1); h.incStat(Skill.UNARMED, RPG.d(2)); h.incStat(Skill.WEAPONLORE, RPG.d(2)); } else if (p.equals("wizard")) { h.set("Image", 6); h.incStat(RPG.ST_SK, RPG.r(0)); h.incStat(RPG.ST_ST, RPG.r(0)); h.incStat(RPG.ST_AG, RPG.r(0)); h.incStat(RPG.ST_TG, RPG.r(0) - 1); h.incStat(RPG.ST_IN, RPG.r(7)); h.incStat(RPG.ST_WP, RPG.r(5)); h.incStat(RPG.ST_CH, RPG.r(2)); h.incStat(RPG.ST_CR, RPG.r(4)); h.incStat(Skill.IDENTIFY, RPG.r(2)); h.incStat(Skill.LITERACY, RPG.d(3)); h.incStat(Skill.TRUEMAGIC, RPG.d(2)); h.incStat(Skill.CASTING, RPG.d(2)); h.incStat(Skill.FOCUS, RPG.d(2)); h.addThing(Spell.randomOffensiveSpell(Skill.TRUEMAGIC, 3)); h.incStat("Luck", -5); // book and scroll h.addThing(SpellBook.create(Skill.TRUEMAGIC, RPG.d(6))); h.addThing(Lib.create("[IsScroll]")); } else if (p.equals("shaman")) { h.set("Image", 6); h.incStat(RPG.ST_SK, RPG.r(0)); h.incStat(RPG.ST_ST, RPG.r(0)); h.incStat(RPG.ST_AG, RPG.r(0)); h.incStat(RPG.ST_TG, RPG.r(0)); h.incStat(RPG.ST_IN, RPG.r(4)); h.incStat(RPG.ST_WP, RPG.r(4)); h.incStat(RPG.ST_CH, RPG.r(5)); h.incStat(RPG.ST_CR, RPG.r(6)); h.incStat(Skill.IDENTIFY, RPG.r(2)); h.incStat(Skill.LITERACY, RPG.r(2)); h.incStat(Skill.BLACKMAGIC, RPG.d(3)); h.incStat(Skill.CASTING, RPG.d(2)); h.incStat(Skill.HERBLORE, RPG.d(2)); h.addThing(Spell.randomSpell(Skill.BLACKMAGIC, 3)); h.incStat("Luck", 15); // herbs and monster parts for (int i = 0; i < 10; i++) h.addThingWithStacking(Lib.createType("IsHerb", RPG.d(10))); for (int i = 0; i < 6; i++) h.addThingWithStacking(Lib.createType("IsMonsterPart", RPG.d(10))); } else if (p.equals("witch")) { h.set("Image", 32); h.incStat(RPG.ST_SK, RPG.r(0)); h.incStat(RPG.ST_ST, RPG.r(0)); h.incStat(RPG.ST_AG, RPG.r(0)); h.incStat(RPG.ST_TG, RPG.r(0)); h.incStat(RPG.ST_IN, RPG.r(5)); h.incStat(RPG.ST_WP, RPG.r(4)); h.incStat(RPG.ST_CH, RPG.r(4)); h.incStat(RPG.ST_CR, RPG.r(6)); h.incStat(Skill.LITERACY, 1); h.incStat(Skill.BLACKMAGIC, 1); h.incStat(Skill.CASTING, 1); h.incStat(Skill.HERBLORE, RPG.r(3)); h.incStat(Skill.COOKING, RPG.r(3)); for (int i = 0; i < 10; i++) h.addThingWithStacking(Lib.createType("IsHerb", RPG.d(10))); h.addThing(Spell.randomSpell(Skill.BLACKMAGIC, 3)); h.incStat("Luck", 10); h.addThing(Lib.create("[IsScroll]")); h.addThing(SpellBook.create(Skill.BLACKMAGIC, RPG.d(8))); } else if (p.equals("war-mage")) { h.set("Image", 6); h.incStat(RPG.ST_SK, RPG.r(2)); h.incStat(RPG.ST_ST, RPG.r(2)); h.incStat(RPG.ST_AG, RPG.r(2)); h.incStat(RPG.ST_TG, RPG.r(2)); h.incStat(RPG.ST_IN, RPG.r(2)); h.incStat(RPG.ST_WP, RPG.r(4)); h.incStat(RPG.ST_CH, RPG.r(2)); h.incStat(RPG.ST_CR, RPG.r(4)); h.incStat(Skill.LITERACY, 1); h.incStat(Skill.TRUEMAGIC, RPG.r(3)); h.incStat(Skill.HEALING, RPG.d(2)); h.incStat(Skill.CASTING, RPG.d(2)); h.addThing(Spell.randomSpell(Skill.TRUEMAGIC, 3)); h.incStat("Luck", 0); } else if (p.equals("runecaster")) { h.set("Image", 6); h.incStat(RPG.ST_SK, RPG.r(0)); h.incStat(RPG.ST_ST, RPG.r(0)); h.incStat(RPG.ST_AG, RPG.r(0)); h.incStat(RPG.ST_TG, RPG.r(0)); h.incStat(RPG.ST_IN, RPG.r(6)); h.incStat(RPG.ST_WP, RPG.r(5)); h.incStat(RPG.ST_CH, RPG.r(4)); h.incStat(RPG.ST_CR, RPG.r(8)); h.incStat(Skill.ALCHEMY, RPG.r(3)); h.incStat(Skill.HERBLORE, RPG.r(2)); h.incStat(Skill.IDENTIFY, RPG.d(2)); h.incStat(Skill.LITERACY, RPG.d(4)); h.incStat(Skill.RUNELORE, RPG.d(2)); h.incStat("Luck", -10); { Thing n = Lib.create("scroll of Teleport Self"); Item.identify(n); h.addThing(n); } { Thing n = Lib.createType("IsWeaponRunestone", RPG.d(17)); Item.identify(n); h.addThing(n); } for (int i = RPG.d(6); i > 0; i--) { Thing n = Lib.createType("IsRunestone", RPG.d(10)); Item.identify(n); h.addThing(n); } for (int i = RPG.r(3); i > 0; i--) { Thing n = Lib.createType("IsRuneRecipeScroll", RPG.d(10)); Item.identify(n); h.addThing(n); } } else if (p.equals("priest")) { h.set("Image", 11); h.incStat(RPG.ST_SK, RPG.r(0)); h.incStat(RPG.ST_ST, RPG.r(0)); h.incStat(RPG.ST_AG, RPG.r(0)); h.incStat(RPG.ST_TG, RPG.r(3)); h.incStat(RPG.ST_IN, RPG.r(4)); h.incStat(RPG.ST_WP, RPG.r(8)); h.incStat(RPG.ST_CH, RPG.r(5)); h.incStat(RPG.ST_CR, RPG.r(0)); h.incStat(Skill.PRAYER, RPG.d(2)); h.incStat(Skill.LITERACY, RPG.d(2)); h.incStat(Skill.HOLYMAGIC, RPG.d(2)); h.incStat(Skill.HEALING, RPG.r(3)); h.incStat(Skill.MEDITATION, RPG.r(2)); h.incStat(Skill.FOCUS, RPG.r(2)); h.incStat("Luck", 5); h.addThing(Spell.randomSpell(Skill.HOLYMAGIC, 5)); Thing n = Lib.create("potion of healing"); Item.identify(n); h.addThing(n); } else if (p.equals("healer")) { h.set("Image", 11); h.incStat(RPG.ST_SK, RPG.r(0)); h.incStat(RPG.ST_ST, RPG.r(0)); h.incStat(RPG.ST_AG, RPG.r(0)); h.incStat(RPG.ST_TG, RPG.r(3)); h.incStat(RPG.ST_IN, RPG.r(4)); h.incStat(RPG.ST_WP, RPG.r(4)); h.incStat(RPG.ST_CH, RPG.r(5)); h.incStat(RPG.ST_CR, RPG.r(4)); h.incStat(Skill.IDENTIFY, RPG.d(2)); h.incStat(Skill.LITERACY, RPG.d(2)); h.incStat(Skill.HEALING, RPG.d(3)); h.incStat(Skill.HERBLORE, RPG.d(2)); h.incStat(Skill.MEDITATION, RPG.r(2)); h.incStat(Skill.FOCUS, RPG.r(2)); h.incStat("Luck", 15); Thing n = Lib.create("potion of healing"); Item.identify(n); h.addThing(n); h.addThing(Lib.create("potion of healing")); h.addThing(Lib.create("potion of healing")); h.addThing(Lib.createType("IsHerb", RPG.d(10))); h.addThing(Lib.createType("IsHerb", RPG.d(10))); h.addThing(Lib.createType("IsHerb", RPG.d(10))); h.addThing(Lib.createType("IsHerb", RPG.d(10))); h.addThing(Lib.createType("IsHerb", RPG.d(10))); } else if (p.equals("bard")) { h.set("Image", 7); h.incStat(RPG.ST_SK, RPG.r(3)); h.incStat(RPG.ST_ST, RPG.r(0)); h.incStat(RPG.ST_AG, RPG.r(3)); h.incStat(RPG.ST_TG, RPG.r(0)); h.incStat(RPG.ST_IN, RPG.r(3)); h.incStat(RPG.ST_WP, RPG.r(3)); h.incStat(RPG.ST_CH, RPG.r(6)); h.incStat(RPG.ST_CR, RPG.r(6)); h.incStat(Skill.MUSIC, RPG.po(0.5)); h.incStat(Skill.PERCEPTION, 1); h.incStat(Skill.SLEIGHT, RPG.po(0.5)); h.incStat(Skill.STORYTELLING, RPG.po(0.5)); h.incStat(Skill.SEDUCTION, RPG.po(1.2)); h.incStat(Skill.LITERACY, RPG.po(0.8)); h.incStat("Luck", 20); Thing n = Lib.createType("IsRing", 5); Item.identify(n); h.addThing(n); } else if (p.equals("paladin")) { h.set("Image", 7); h.incStat(RPG.ST_SK, RPG.r(4)); h.incStat(RPG.ST_ST, RPG.r(4)); h.incStat(RPG.ST_AG, RPG.r(0)); h.incStat(RPG.ST_TG, RPG.r(4)); h.incStat(RPG.ST_IN, RPG.r(4)); h.incStat(RPG.ST_WP, RPG.r(4)); h.incStat(RPG.ST_CH, RPG.r(0)); h.incStat(RPG.ST_CR, RPG.r(0)); h.incStat(Skill.PRAYER, RPG.d(2)); h.incStat(Skill.ATTACK, RPG.r(2)); h.incStat(Skill.DEFENCE, RPG.r(2)); h.incStat(Skill.BRAVERY, RPG.d(3)); h.addThing(Weapon.createWeapon(RPG.d(4))); Thing n = Lib.createType("IsWand", RPG.d(4)); Item.identify(n); h.addThing(n); } else if (p.equals("barbarian")) { h.set("Image", 3); h.incStat(RPG.ST_SK, RPG.r(3)); h.incStat(RPG.ST_ST, RPG.r(3)); h.incStat(RPG.ST_AG, RPG.r(5)); h.incStat(RPG.ST_TG, RPG.r(5)); h.incStat(RPG.ST_IN, RPG.r(0)); h.incStat(RPG.ST_WP, RPG.r(0)); h.incStat(RPG.ST_CH, RPG.r(0)); h.incStat(RPG.ST_CR, RPG.r(0)); h.incStat(RPG.ST_ATTACKSPEED, 10); h.incStat(Skill.ATTACK, RPG.r(2)); h.incStat(Skill.FEROCITY, 1); h.incStat(Skill.ATHLETICS, 1); h.incStat(Skill.ALERTNESS, RPG.r(3)); h.incStat(Skill.SURVIVAL, RPG.d(2)); h.incStat(Skill.PICKPOCKET, RPG.r(2)); h.incStat(Skill.UNARMED, 1); h.incStat(Skill.TRACKING, RPG.r(2)); Thing n = Lib.create("potion of speed"); Item.identify(n); h.addThing(n); } else if (p.equals("thief")) { h.set("Image", 10); h.incStat(RPG.ST_SK, RPG.r(5)); h.incStat(RPG.ST_ST, RPG.r(0)); h.incStat(RPG.ST_AG, RPG.r(6)); h.incStat(RPG.ST_TG, RPG.r(0)); h.incStat(RPG.ST_IN, RPG.r(0)); h.incStat(RPG.ST_WP, RPG.r(0)); h.incStat(RPG.ST_CH, RPG.r(4)); h.incStat(RPG.ST_CR, RPG.r(3)); h.incStat(RPG.ST_ATTACKSPEED, 120); h.incStat(Skill.ALERTNESS, RPG.d(3)); h.incStat(Skill.PICKPOCKET, RPG.r(3)); h.incStat(Skill.PICKLOCK, RPG.r(3)); h.incStat(Skill.DISARM, RPG.r(2)); Thing n = Lib.create("wand of Teleport Self"); Item.identify(n); h.addThing(n); } else if (p.equals("ranger")) { h.set("Image", 10); h.incStat(RPG.ST_SK, RPG.r(8)); h.incStat(RPG.ST_ST, RPG.r(3)); h.incStat(RPG.ST_AG, RPG.r(6)); h.incStat(RPG.ST_TG, RPG.r(0)); h.incStat(RPG.ST_IN, RPG.r(0)); h.incStat(RPG.ST_WP, RPG.r(0)); h.incStat(RPG.ST_CH, RPG.r(4)); h.incStat(RPG.ST_CR, RPG.r(0)); h.incStat(Skill.ARCHERY, RPG.r(3)); h.incStat(Skill.THROWING, RPG.r(3)); h.incStat(Skill.SURVIVAL, RPG.d(1)); h.incStat(Skill.SWIMMING, RPG.r(2)); h.incStat(Skill.RIDING, RPG.r(2)); h.incStat(Skill.TRACKING, RPG.d(3)); Thing n = Lib.create("healing potion"); h.addThing(n); } else if (p.equals("farmer")) { h.set("Image", 10); h.incStat(RPG.ST_SK, RPG.r(0)); h.incStat(RPG.ST_ST, RPG.r(4)); h.incStat(RPG.ST_AG, RPG.r(0)); h.incStat(RPG.ST_TG, RPG.r(4)); h.incStat(RPG.ST_IN, RPG.r(0)); h.incStat(RPG.ST_WP, RPG.r(6)); h.incStat(RPG.ST_CH, RPG.r(4)); h.incStat(RPG.ST_CR, RPG.r(6)); h.incStat(Skill.THROWING, RPG.r(3)); h.incStat(Skill.SURVIVAL, RPG.r(3)); h.incStat(Skill.SWIMMING, RPG.r(2)); h.incStat(Skill.COOKING, RPG.r(3)); h.incStat(Skill.HERBLORE, RPG.d(2)); // a healing potion Thing n = Lib.create("potion of healing"); Item.identify(n); h.addThing(n); } else { throw new Error("Profession [" + p + "] not recognised"); } }
public static Thing createBaseHero(String race) { Thing h = Lib.extend("you", race); h.set("IsHero", 1); h.set("Gods", Lib.instance().getObject("Gods")); h.set("IsGiftReceiver", 0); // don't count as gift receiver h.set("Image", 7); h.set("Z", Thing.Z_MOBILE + 5); h.set(RPG.ST_RECHARGE, 60); h.set(RPG.ST_REGENERATE, 20); h.set("HungerThreshold", 300000); h.set("NameType", Description.NAMETYPE_PROPER); h.set("OnAction", new HeroAction()); h.set("Seed", RPG.r(1000000000)); h.set("ASCII", "@"); h.set("IsDisplaceable", 0); // initial fate points h.incStat(RPG.ST_FATE, 1); // Starting Game stats h.set(RPG.ST_LEVEL, 1); h.incStat(RPG.ST_SKILLPOINTS, 1); // dummy map Map m = new Map(1, 1); m.addThing(h, 0, 0); return h; }
/** * This function awards some bonus items based on the hero's professional skills. * * @param h */ private static void applyBonusItems(Thing h) { if (h.getFlag(Skill.PRAYER)) { Thing t = Lib.create("potion of holy water"); t.set("Number", h.getStat(Skill.PRAYER)); h.addThingWithStacking(t); } if (h.getFlag(Skill.TRADING)) { Thing t = Lib.create("sovereign"); t.set("Number", h.getStat(Skill.TRADING)); h.addThingWithStacking(t); } if (h.getFlag(Skill.WEAPONLORE)) { Thing t = Lib.createType("IsWeapon", RPG.d(2, 6)); h.addThingWithStacking(t); } if (h.getFlag(Skill.COOKING)) { Thing t = Lib.createType("IsFood", 25); t.set("Number", h.getStat(Skill.COOKING)); h.addThingWithStacking(t); } if (h.getFlag(Skill.ARCHERY)) { // a reanged weapon + ammo Thing t = Lib.createType("IsRangedWeapon", RPG.d(h.getStat(Skill.ARCHERY), 6)); Thing ms = RangedWeapon.createAmmo(t, RPG.d(h.getStat(Skill.ARCHERY), 6)); h.addThing(t); h.addThing(ms); } Thing[] ws = h.getFlaggedContents("IsWeapon"); if (ws.length == 0) { h.addThing(Lib.createType("IsWeapon", 1)); } }