Esempio n. 1
0
  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;
  }
Esempio n. 2
0
  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);
  }