Exemple #1
0
 public static void removeMoney(Thing person, int amountInCoppers) {
   if (amountInCoppers <= 0) {
     addMoney(person, -amountInCoppers);
     return;
   }
   int funds = getMoney(person) - amountInCoppers;
   Thing[] cash = person.getFlaggedContents("IsMoney");
   // TODO: make this spend coins effectively
   for (Thing element : cash) {
     element.remove();
   }
   if (funds > 0) {
     addMoney(person, funds);
   }
 }
Exemple #2
0
 /** Add these in the most weight efficent means possible. */
 public static void addMoney(Thing person, int amountInCoppers) {
   if (amountInCoppers == 0) {
     return;
   }
   if (amountInCoppers < 0) {
     removeMoney(person, -amountInCoppers);
     return;
   }
   int unitAmount = COPPER_AMOUNT;
   String unit = COPPER;
   if (amountInCoppers > SOVEREIGN_AMOUNT) {
     unitAmount = SOVEREIGN_AMOUNT;
     unit = SOVEREIGN;
   } else if (amountInCoppers > GOLD_AMOUNT) {
     unitAmount = GOLD_AMOUNT;
     unit = GOLD;
   } else if (amountInCoppers > SILVER_AMOUNT) {
     unitAmount = SILVER_AMOUNT;
     unit = SILVER;
   }
   Thing money = createMoney(amountInCoppers / unitAmount, unit);
   int moneyBeingAdded = valueOf(money);
   person.addThingWithStacking(money);
   addMoney(person, amountInCoppers - moneyBeingAdded);
 }
Exemple #3
0
 // Calculate funds available
 public static int getMoney(Thing t) {
   Thing[] cash = t.getFlaggedContents("IsMoney");
   int tot = 0;
   for (Thing element : cash) {
     tot += valueOf(element);
   }
   return tot;
 }
Exemple #4
0
  /**
   * Create a single money stack. Return a rounded amount.
   *
   * @param amount Amount that will be rounded in units of copper.
   */
  public static Thing createMoney(int amount) {
    int type = 0;

    if (amount >= 1000) {
      type++;
    }
    if (amount >= 100) {
      type++;
    }
    if (RPG.d(2) == 1 && amount >= 10) {
      type++;
    }
    for (int i = 0; i < type; i++) {
      amount /= 10;
    }

    if (amount <= 0) {
      amount = 1;
    }

    String name = "copper coin";
    switch (type) {
      case 1:
        name = "silver coin";
        break;
      case 2:
        name = "gold coin";
        break;
      case 3:
        name = "sovereign";
        break;
    }

    Thing t = Lib.create("Barricade");
    t.set("Number", amount);
    return t;
  }
Exemple #5
0
  public static void init() {
    Thing t = Lib.extend("base coin", "base item");
    t.set("IsMoney", 1);
    t.set("IsCoin", 1);
    t.set("IsStatusKnown", 1);
    t.set("Image", 140);
    t.set("HPS", 6);
    t.set("ItemWeight", 20);
    t.set("LevelMin", 1);
    t.set("RES:water", 100);
    t.set("Z", Thing.Z_ITEM - 2);
    t.set("Frequency", 100);
    t.set("ASCII", "$");
    Lib.add(t);

    t = Lib.extend("copper coin", "base coin");
    t.set("Value", COPPER_AMOUNT);
    t.set("Image", 144);
    t.set("ItemWeight", 20);
    Lib.add(t);

    t = Lib.extend("silver coin", "base coin");
    t.set("Value", SILVER_AMOUNT);
    t.set("Image", 143);
    t.set("ItemWeight", 30);
    t.set("LevelMin", 1);
    Lib.add(t);

    t = Lib.extend("gold coin", "base coin");
    t.set("Value", GOLD_AMOUNT);
    t.set("Image", 140);
    t.set("ItemWeight", 50);
    t.set("LevelMin", 5);
    Lib.add(t);

    t = Lib.extend("sovereign", "base coin");
    t.set("Value", SOVEREIGN_AMOUNT);
    t.set("Image", 140);
    t.set("ItemWeight", 100);
    t.set("LevelMin", 8);
    Lib.add(t);
  }
Exemple #6
0
 protected static int valueOf(Thing coin) {
   return coin.getStat(RPG.ST_ITEMVALUE) * coin.getNumber();
 }