Exemplo n.º 1
0
 /**
  * Send the current config update to the specified player.
  *
  * @param player The player to recieve the update.
  */
 public void sendConfig(Player player) {
   Team team = getTeam(player, GameType.ACTIVE);
   CastleWarsTeams sara = teams.get(Team.SARADOMIN), zammy = teams.get(Team.ZAMORAK);
   int config = zammy.getHealth();
   if (team == Team.ZAMORAK ? zammy.getAttribute(0) : sara.getAttribute(0)) {
     config += 128;
   }
   if (!sara.getAttribute(1)) {
     config += 256;
   }
   if (!sara.getAttribute(2)) {
     config += 512;
   }
   if (team == Team.ZAMORAK ? !zammy.getAttribute(3) : !sara.getAttribute(3)) {
     config += 1024;
   }
   if (team == Team.ZAMORAK ? zammy.getAttribute(4) : sara.getAttribute(4)) {
     config += 2097152;
   }
   config += 16777216 * (team == Team.ZAMORAK ? zammy.getScore() : sara.getScore());
   player.send(new ConfigEvent(team == Team.ZAMORAK ? 377 : 378, config));
   config = sara.getHealth();
   if (team == Team.ZAMORAK ? zammy.getAttribute(0) : sara.getAttribute(0)) {
     config += 128;
   }
   if (!zammy.getAttribute(1)) {
     config += 256;
   }
   if (!zammy.getAttribute(2)) {
     config += 512;
   }
   if (!sara.getAttribute(3)) {
     config += 1024;
   }
   if (team == Team.ZAMORAK ? sara.getAttribute(4) : zammy.getAttribute(4)) {
     config += 2097152;
   }
   config += 16777216 * (team == Team.ZAMORAK ? sara.getScore() : zammy.getScore());
   player.send(new ConfigEvent(team == Team.ZAMORAK ? 378 : 377, config));
 }
Exemplo n.º 2
0
 /**
  * Buys a item from the store.
  *
  * @param player The player.
  * @param item The item to buy.
  */
 public void buyItem(Player player, SlottedItem item) {
   if (player.getInventory().freeSlots() >= item.getItem().getAmount()) {
     if (payment.buyItem(player, item)) {
       player.getInventory().add(item.getItem());
       player.send(new UpdateItemsEvent(3823, player.getInventory().getItems()));
       if (!type.equals(ShopType.UNLIMITED_BUY_ONLY)) {
         items.remove(item.getItem());
       }
     }
   } else {
     player.getInventory().forceCapacityExceeded();
   }
 }
Exemplo n.º 3
0
 /**
  * Sells a item to the store.
  *
  * @param player The player that is selling this item.
  * @param slot The item slot.
  * @param item The item.
  */
 public void sellItem(Player player, Item item) {
   if (type.equals(ShopType.BUY_AND_SELL)) {
     if (player.getInventory().contains(item)) {
       if (payment.sellItem(player, item)) {
         player.getInventory().remove(item);
         player.send(new UpdateItemsEvent(3823, player.getInventory().getItems()));
         items.add(item);
       }
     }
   } else {
     player.sendMessage("You cannot sell items in this shop.");
   }
 }
Exemplo n.º 4
0
 /**
  * Refresh the shop for all viewers.
  *
  * @param si The slotted item to refresh.
  */
 public void refresh(SlottedItem si) {
   for (Player player : players) {
     player.send(new UpdateSlottedItemsEvent(3900, si));
   }
 }
Exemplo n.º 5
0
 /** Refresh the shop for all viewers. */
 public void refresh() {
   for (Player player : players) {
     player.send(new UpdateItemsEvent(3900, items.getItems()));
   }
 }
Exemplo n.º 6
0
 /** The ticker, called every second. */
 public void process() {
   if (getAttribute(0)) {
     if (tick <= 0) {
       for (Player player : getPlayers(GameType.ACTIVE)) {
         player.teleport(new Position(2440, 3090, 0), false);
         player.getInterfaceSet().openWalkable(-1);
       }
       setAttribute(0, false);
       clear(GameType.ACTIVE);
     } else {
       ArrayList<Player> players = getPlayers(GameType.ACTIVE);
       if (getAttribute(1)) {
         for (Player player : players) {
           sendConfig(player);
         }
         setAttribute(1, false);
       }
       if (getAttribute(2)) {
         int time = tick / 60 == 0 ? 1 : tick / 60;
         for (Player player : players) {
           player.send(new ConfigEvent(380, time));
         }
         for (Player player : getPlayers(GameType.WAITING)) {
           player.send(new ConfigEvent(380, time));
         }
         setAttribute(2, false);
       }
       if (getAttribute(3)) {
         for (Player player : players) {
           updateFlag(player, Team.SARADOMIN);
         }
         setAttribute(3, false);
       }
       if (getAttribute(4)) {
         for (Player player : players) {
           updateFlag(player, Team.ZAMORAK);
         }
         setAttribute(4, false);
       }
       tick--;
     }
   } else if (tick <= 0) {
     for (Player player : getPlayers(GameType.WAITING)) {
       Team team = getTeam(player, GameType.WAITING);
       if (addPlayer(team, GameType.ACTIVE, player)) {
         player.teleport(teams.get(team).getGame(), false);
       }
     }
     setAttribute(0, true);
     clear(GameType.WAITING);
   } else {
     if (getAttribute(2)) {
       int time = tick / 60 == 0 ? 1 : tick / 60;
       for (Player player : getPlayers(GameType.WAITING)) {
         player.send(new ConfigEvent(380, time));
       }
       setAttribute(2, false);
     }
     tick--;
   }
 }
Exemplo n.º 7
0
  /* handle compost bin updating */
  private void updateCompostBin(int index) {
    CompostBinStages compostBinStages =
        CompostBinStages.forId(CompostBinLocations.forId(index).getBinObjectId());

    if (compostBinStages == null) {
      return;
    }
    int x = CompostBinLocations.forId(index).getBinPosition().getX();
    int y = CompostBinLocations.forId(index).getBinPosition().getY();
    int z = CompostBinLocations.forId(index).getBinPosition().getHeight();
    int finalObject;

    // handling the different ways to fill a compost bin
    if (compostBins[index] > 0) {
      if (compostBins[index] % 17 == 0) {
        finalObject = compostBinStages.getBinWithSuperCompostable();
      } else if (compostBins[index] % 77 == 0) {
        finalObject = compostBinStages.getBinWithTomatoes();
      } else {
        finalObject = compostBinStages.getBinWithCompostable();
      }
    } else {
      finalObject = compostBinStages.getBinEmpty();
    }

    // handling the different ways to complete a compost bin
    if (compostBins[index] == 255) {
      finalObject = compostBinStages.getBinFullOFSuperCompostable();
      tempCompostState = 2;
    } else if (compostBins[index] == 1155) {
      finalObject = compostBinStages.getBinFullOfTomatoes();
      tempCompostState = 3;
    } else if (organicItemAdded[index] == 15) {
      finalObject = compostBinStages.getBinFullOfCompostable();
      tempCompostState = 1;
    }
    // handling the closed state of the compost bin
    switch (compostBins[index]) {
      case 100:
      case 200:
      case 300:
        finalObject = compostBinStages.getClosedBin();
        break;

        // handling the rotted state of the compost in the bin
      case 150:
        finalObject = compostBinStages.getBinFullOfCompost();
        break;
      case 250:
        finalObject = compostBinStages.getBinFullOfSuperCompost();
        break;
      case 350:
        finalObject = compostBinStages.getBinFullOfRottenTomatoes();
        break;
    }

    // handle the compost bin state when the player retrieve the compost
    if (compostBins[index] == 150 && organicItemAdded[index] < 15) {
      finalObject = compostBinStages.getBinWithCompost();
    } else if (compostBins[index] == 250 && organicItemAdded[index] < 15) {
      finalObject = compostBinStages.getBinWithSuperCompost();
    }
    if (compostBins[index] == 350 && organicItemAdded[index] < 15) {
      finalObject = compostBinStages.getBinWithRottenTomatoes();
    }

    final Position pos = new Position(x, y, z);
    GameObject object =
        new GameObject(
            ObjectDefinition.forId(finalObject),
            pos,
            10,
            CompostBinLocations.forId(index).getObjectFace());
    player.send(new PositionEvent(player.getLastKnownRegion(), pos));
    player.send(new CreateObjectEvent(object));
  }