Ejemplo 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;
  }
Ejemplo n.º 2
0
  private void begin() {
    Lib.debug(dbgThread, "Beginning thread: " + toString());

    Lib.assertTrue(this == currentThread);

    restoreState();

    Machine.interrupt().enable();
  }
Ejemplo n.º 3
0
  /**
   * Relinquish the CPU, because the current thread has either finished or it is blocked. This
   * thread must be the current thread.
   *
   * <p>If the current thread is blocked (on a synchronization primitive, i.e. a <tt>Semaphore</tt>,
   * <tt>Lock</tt>, or <tt>Condition</tt>), eventually some thread will wake this thread up, putting
   * it back on the ready queue so that it can be rescheduled. Otherwise, <tt>finish()</tt> should
   * have scheduled this thread to be destroyed by the next thread to run.
   */
  public static void sleep() {
    Lib.debug(dbgThread, "Sleeping thread: " + currentThread.toString());

    Lib.assertTrue(Machine.interrupt().disabled());

    if (currentThread.status != statusFinished) currentThread.status = statusBlocked;

    runNextThread();
  }
Ejemplo n.º 4
0
  /** Moves this thread to the ready state and adds this to the scheduler's ready queue. */
  public void ready() {
    Lib.debug(dbgThread, "Ready thread: " + toString());

    Lib.assertTrue(Machine.interrupt().disabled());
    Lib.assertTrue(status != statusReady);

    status = statusReady;
    if (this != idleThread) readyQueue.waitForAccess(this);

    Machine.autoGrader().readyThread(this);
  }
Ejemplo n.º 5
0
  /**
   * Relinquish the CPU if any other thread is ready to run. If so, put the current thread on the
   * ready queue, so that it will eventually be rescheuled.
   *
   * <p>Returns immediately if no other thread is ready to run. Otherwise returns when the current
   * thread is chosen to run again by <tt>readyQueue.nextThread()</tt>.
   *
   * <p>Interrupts are disabled, so that the current thread can atomically add itself to the ready
   * queue and switch to the next thread. On return, restores interrupts to the previous state, in
   * case <tt>yield()</tt> was called with interrupts disabled.
   */
  public static void yield() {
    Lib.debug(dbgThread, "Yielding thread: " + currentThread.toString());

    Lib.assertTrue(currentThread.status == statusRunning);

    boolean intStatus = Machine.interrupt().disable();

    currentThread.ready();

    runNextThread();

    Machine.interrupt().restore(intStatus);
  }
Ejemplo n.º 6
0
  /**
   * Dispatch the CPU to this thread. Save the state of the current thread, switch to the new thread
   * by calling <tt>TCB.contextSwitch()</tt>, and load the state of the new thread. The new thread
   * becomes the current thread.
   *
   * <p>If the new thread and the old thread are the same, this method must still call
   * <tt>saveState()</tt>, <tt>contextSwitch()</tt>, and <tt>restoreState()</tt>.
   *
   * <p>The state of the previously running thread must already have been changed from running to
   * blocked or ready (depending on whether the thread is sleeping or yielding).
   *
   * @param finishing <tt>true</tt> if the current thread is finished, and should be destroyed by
   *     the new thread.
   */
  private void run() {
    Lib.assertTrue(Machine.interrupt().disabled());

    Machine.yield();

    currentThread.saveState();

    Lib.debug(dbgThread, "Switching from: " + currentThread.toString() + " to: " + toString());

    currentThread = this;

    tcb.contextSwitch();

    currentThread.restoreState();
  }
Ejemplo n.º 7
0
  /**
   * Waits for this thread to finish. If this thread is already finished, return immediately. This
   * method must only be called once; the second call is not guaranteed to return. This thread must
   * not be the current thread.
   */
  public void join() {
    boolean intStatus = Machine.interrupt().disable();
    Lib.debug(dbgThread, "Joining to thread: " + toString());

    Lib.assertTrue(this != currentThread);

    if (cont == 0) {
      cont = 1;
      if (this.status == statusFinished) {
        return;
      } else {
        this.joinList.add(currentThread);
        currentThread.sleep();
      }
    }
    Machine.interrupt().restore(intStatus);
  }
Ejemplo n.º 8
0
  /**
   * Prepare this thread to be run. Set <tt>status</tt> to <tt>statusRunning</tt> and check
   * <tt>toBeDestroyed</tt>.
   */
  protected void restoreState() {
    Lib.debug(dbgThread, "Running thread: " + currentThread.toString());

    Lib.assertTrue(Machine.interrupt().disabled());
    Lib.assertTrue(this == currentThread);
    Lib.assertTrue(tcb == TCB.currentTCB());

    Machine.autoGrader().runningThread(this);

    status = statusRunning;

    if (toBeDestroyed != null) {
      toBeDestroyed.tcb.destroy();
      toBeDestroyed.tcb = null;
      toBeDestroyed = null;
    }
  }
Ejemplo n.º 9
0
 public static String[] heroRaceDescriptions() {
   String[] races = heroRaces();
   String[] descs = new String[races.length];
   for (int i = 0; i < descs.length; i++) {
     String d = Lib.create(races[i]).getString("RaceDescription");
     if (d == null) d = "No description for " + races[i] + " yet...";
     descs[i] = d;
   }
   return descs;
 }
Ejemplo n.º 10
0
  /**
   * Causes this thread to begin execution. The result is that two threads are running concurrently:
   * the current thread (which returns from the call to the <tt>fork</tt> method) and the other
   * thread (which executes its target's <tt>run</tt> method).
   */
  public void fork() {
    Lib.assertTrue(status == statusNew);
    Lib.assertTrue(target != null);

    Lib.debug(dbgThread, "Forking thread: " + toString() + " Runnable: " + target);

    boolean intStatus = Machine.interrupt().disable();

    tcb.start(
        new Runnable() {
          public void run() {
            runThread();
          }
        });

    ready();

    Machine.interrupt().restore(intStatus);
  }
Ejemplo n.º 11
0
 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;
 }
Ejemplo n.º 12
0
  // Inicia self test usando clase PingTest
  public static void selfTest() {

    Lib.debug(dbgThread, "Enter KThread.selfTest");
    cero = new KThread(new PingTest(0)).setName("forked thread0");
    cero.fork();
    uno = new KThread(new PingTest(1)).setName("forked thread1");
    uno.fork();
    dos = new KThread(new PingTest(2)).setName("forked thread2");
    dos.fork();
    tres = new KThread(new PingTest(3)).setName("forked thread3");
    tres.fork();
  }
Ejemplo n.º 13
0
  /**
   * Finish the current thread and schedule it to be destroyed when it is safe to do so. This method
   * is automatically called when a thread's <tt>run</tt> method returns, but it may also be called
   * directly.
   *
   * <p>The current thread cannot be immediately destroyed because its stack and other execution
   * state are still in use. Instead, this thread will be destroyed automatically by the next thread
   * to run, when it is safe to delete this thread.
   */
  public static void finish() {
    Lib.debug(dbgThread, "Finishing thread: " + currentThread.toString());

    Machine.interrupt().disable();

    Machine.autoGrader().finishingCurrentThread();

    Lib.assertTrue(toBeDestroyed == null);
    toBeDestroyed = currentThread;

    currentThread.status = statusFinished;

    KThread aux = null;
    if (joinList.size() > 0) {
      aux = joinList.getFirst();
    }
    if (aux != null) {
      aux.ready();
      joinList.removeFirst();
    }
    sleep();
  }
Ejemplo n.º 14
0
  /**
   * Create the idle thread. Whenever there are no threads ready to be run, and
   * <tt>runNextThread()</tt> is called, it will run the idle thread. The idle thread must never
   * block, and it will only be allowed to run when all other threads are blocked.
   *
   * <p>Note that <tt>ready()</tt> never adds the idle thread to the ready set.
   */
  private static void createIdleThread() {
    Lib.assertTrue(idleThread == null);

    idleThread =
        new KThread(
            new Runnable() {
              public void run() {
                while (true) yield();
              }
            });
    idleThread.setName("idle");

    Machine.autoGrader().setIdleThread(idleThread);

    idleThread.fork();
  }
Ejemplo n.º 15
0
  /**
   * 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));
    }
  }
Ejemplo n.º 16
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");
    }
  }
Ejemplo n.º 17
0
  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");
    }
  }
Ejemplo n.º 18
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);
  }
Ejemplo n.º 19
0
 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;
 }
Ejemplo n.º 20
0
 public static Thing createMeetQuest(String desc, Thing target) {
   Thing t = Lib.create("meet quest");
   t.set("Target", target);
   t.set("Description", desc);
   return t;
 }
Ejemplo n.º 21
0
  /**
   * Set the target of this thread.
   *
   * @param target the object whose <tt>run</tt> method is called.
   * @return this thread.
   */
  public KThread setTarget(Runnable target) {
    Lib.assertTrue(status == statusNew);

    this.target = target;
    return this;
  }
Ejemplo n.º 22
0
 /**
  * Get the current thread.
  *
  * @return the current thread.
  */
 public static KThread currentThread() {
   Lib.assertTrue(currentThread != null);
   return currentThread;
 }
Ejemplo n.º 23
0
 /**
  * Prepare this thread to give up the processor. Kernel threads do not need to do anything here.
  */
 protected void saveState() {
   Lib.assertTrue(Machine.interrupt().disabled());
   Lib.assertTrue(this == currentThread);
 }