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); }