Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 17.50 KB | None | 0 0
  1. package org.hyperion.rs2.model.container;
  2.  
  3.  
  4. import org.hyperion.rs2.model.*;
  5. import org.hyperion.rs2.model.container.impl.InterfaceContainerListener;
  6. import org.hyperion.rs2.model.content.minigame.FightPits;
  7. import org.hyperion.rs2.model.content.misc.ItemSpawning;
  8. import org.hyperion.rs2.model.content.misc2.Food;
  9. import org.hyperion.rs2.util.PushMessage;
  10.  
  11.  
  12. /**
  13.  * Banking utility class.
  14.  *
  15.  * @author Martin
  16.  */
  17. public class BoB {
  18.  
  19.     /**
  20.      * The BoB size.
  21.      */
  22.     public static final int SIZE = 30;
  23.  
  24.     /**
  25.      * The player inventory interface.
  26.      */
  27.     public static final int PLAYER_INVENTORY_INTERFACE = 5065;
  28.  
  29.     /**
  30.      * The BoB Inventory interface.
  31.      */
  32.     public static final int BOB_INVENTORY_INTERFACE = 7423;
  33.  
  34.  
  35.     /**
  36.      * Opens the Bob Inventory box for the certain player
  37.      *
  38.      * @param player The player to have a opened deposit Box
  39.      */
  40.     public static void openInventory(Player player) {
  41.         if(player.cE.summonedNpc == null){
  42.             PushMessage.pushStaffMessage("Trying to view BOB inventory with no familiar", player);
  43.             return;
  44.         }
  45.         player.openedBoB = true;
  46.  
  47.         player.getBoB().shift();
  48.         player.getActionSender().sendInterfaceInventory(4465, 5063);
  49.         player.getActionSender().sendString("Summoning BoB", 7421);
  50.  
  51.         player.getInterfaceState().addListener(player.getBoB(),
  52.                 new InterfaceContainerListener(player, BOB_INVENTORY_INTERFACE));
  53.         player.getInterfaceState().addListener(player.getInventory(),
  54.                 new InterfaceContainerListener(player, PLAYER_INVENTORY_INTERFACE - 1));
  55.  
  56.     }
  57.  
  58.     public static void dropBoB(Position loc, Player player) {
  59.         if(player == null || player.getBoB() == null || player.isHidden()) return;
  60.         for(int i = 0; i < player.getBoB().capacity(); i++) {
  61.             if(player.getBoB().get(i) != null) {
  62.                 GlobalItemManager.newDropItem(player, new GlobalItem(player, loc, player.getBoB().get(i)));
  63.             }
  64.         }
  65.         //player.getLogManager().add(LogEntry.bob(player.getName(),player.getBoB().getItems()));
  66.         player.getBoB().clear();
  67.     }
  68.  
  69.     /**
  70.      * Withdraws an item.
  71.      *
  72.      * @param player The player.
  73.      * @param slot   The slot in the player's inventory.
  74.      * @param id     The item id.
  75.      * @param amount The amount of the item to deposit.
  76.      */
  77.     public static void withdraw(Player player, int slot, int id, int amount) {
  78.         if(player.cE.summonedNpc == null){
  79.             PushMessage.pushStaffMessage("@red@[Important] " + player.getSafeDisplayName() + " is trying to withdraw", player);
  80.             PushMessage.pushStaffMessage("@red@[Important] from BoB without any summoned followers.", player);
  81.             return;
  82.         }
  83.         if(player.duelAttackable > 0 || FightPits.inPits(player)) {
  84.             player.getActionSender().sendMessage("I shouldn't be doing this here..");
  85.             return;
  86.         }
  87.         if(slot < 0 || slot > player.getBoB().capacity() || id < 0 || id > ItemDefinition.MAX_ID)
  88.             return;
  89.         Item item = player.getBoB().get(slot);
  90.         if(item == null) {
  91.             return; // invalid packet, or client out of sync
  92.         }
  93.         if(item.getId() != id) {
  94.             return; // invalid packet, or client out of sync
  95.         }
  96.         int transferAmount = item.getCount();
  97.         if(transferAmount >= amount) {
  98.             transferAmount = amount;
  99.         } else if(transferAmount == 0) {
  100.             return; // invalid packet, or client out of sync
  101.         }
  102.         int newId = item.getId(); // TODO deal with withdraw as notes!
  103.         if(player.getSettings().isWithdrawingAsNotes()) {
  104.             if(item.getDefinition().isNoteable()) {
  105.                 newId = item.getDefinition().getNotedId();
  106.             }
  107.         }
  108.         ItemDefinition def = ItemDefinition.forId(newId);
  109.         if(def.isStackable()) {
  110.             if(player.getInventory().freeSlots() <= 0
  111.                     && player.getInventory().getById(newId) == null) {
  112.                 player.getActionSender()
  113.                         .sendMessage(
  114.                                 "You don't have enough inventory space to withdraw that many."); // this
  115.                 // is
  116.                 // the
  117.                 // real
  118.                 // message
  119.             }
  120.         } else {
  121.             int free = player.getInventory().freeSlots();
  122.             if(transferAmount > free) {
  123.                 player.getActionSender()
  124.                         .sendMessage(
  125.                                 "You don't have enough inventory space to withdraw that many."); // this
  126.                 // is
  127.                 // the
  128.                 // real
  129.                 // message
  130.                 transferAmount = free;
  131.             }
  132.         }
  133.         // now add it to inv
  134.         if(player.getInventory().add(new Item(newId, transferAmount))) {
  135.             // all items in the bank are stacked, makes it very easy!
  136.             int newAmount = item.getCount() - transferAmount;
  137.             if(newAmount <= 0) {
  138.                 player.getBoB().set(slot, null);
  139.             } else {
  140.                 player.getBoB().set(slot, new Item(item.getId(), newAmount));
  141.             }
  142.         } else {
  143.             player.getActionSender()
  144.                     .sendMessage(
  145.                             "You don't have enough inventory space to withdraw that many."); // this
  146.             // is
  147.             // the
  148.             // real
  149.             // message
  150.         }
  151.     }
  152.  
  153.     /**
  154.      * Deposits an item.
  155.      *
  156.      * @param player The player.
  157.      * @param slot   The slot in the player's inventory.
  158.      * @param id     The item id.
  159.      * @param amount The amount of the item to deposit.
  160.      */
  161.     public static void deposit(Player player, int slot, int id, int amount) {
  162.         deposit(player, slot, id, amount, player.getInventory());
  163.     }
  164.  
  165.     public static void deposit(Player player, int slot, int id, int amount, Container container) {
  166.         if(player.cE.summonedNpc == null){
  167.             PushMessage.pushStaffMessage("Trying to deposit into BOB with no summoned npc", player);
  168.             return;
  169.         }
  170.         if(FightPits.inPits(player) || FightPits.inGame(player) || FightPits.inPitsFightArea(player.getPosition().getX(), player.getPosition().getY()))
  171.             return;
  172.         if(slot < 0 || slot > container.capacity() || id < 0 || id > ItemDefinition.MAX_ID)
  173.             return;
  174.         if(Food.get(id) == null && !ItemSpawning.canSpawn(id)) {
  175.             player.getActionSender().sendMessage("You cannot store this item.");
  176.             return;
  177.         }
  178.         boolean inventoryFiringEvents = container.isFiringEvents();
  179.         container.setFiringEvents(false);
  180.         try {
  181.             Item item = container.get(slot);
  182.             if(item == null) {
  183.                 return; // invalid packet, or client out of sync
  184.             }
  185.             if(item.getId() != id || item.getDefinition().isNoted()) {
  186.                 return; // invalid packet, or client out of sync
  187.             }
  188.             int transferAmount = container.getCount(id);
  189.             if(transferAmount >= amount) {
  190.                 transferAmount = amount;
  191.             } else if(transferAmount == 0) {
  192.                 return; // invalid packet, or client out of sync
  193.             }
  194.             boolean noted = item.getDefinition().isNoted();
  195.             if(item.getDefinition().isStackable() || noted) {
  196.                 int bankedId = noted ? item.getDefinition().getNormalId()
  197.                         : item.getId();
  198.                 if(player.getBoB().freeSlots() < 1
  199.                         && player.getBoB().getById(bankedId) == null) {
  200.                     player.getActionSender()
  201.                             .sendMessage(
  202.                                     "You don't have enough space in your summon's pouch."); // this
  203.                     // is
  204.                     // the
  205.                     // real
  206.                     // message
  207.                 }
  208.                 // we only need to remove from one stack
  209.                 int newInventoryAmount = item.getCount() - transferAmount;
  210.                 Item newItem;
  211.                 if(newInventoryAmount <= 0) {
  212.                     newItem = null;
  213.                 } else {
  214.                     newItem = new Item(item.getId(), newInventoryAmount);
  215.                 }
  216.                 if(! player.getBoB().add(new Item(bankedId, transferAmount))) {
  217.                     player.getActionSender()
  218.                             .sendMessage(
  219.                                     "You don't have enough space in your summon's pouch."); // this
  220.                     // is
  221.                     // the
  222.                     // real
  223.                     // message
  224.                 } else {
  225.                     container.set(slot, newItem);
  226.                     container.fireItemsChanged();
  227.                     player.getBoB().fireItemsChanged();
  228.                 }
  229.             } else {
  230.                 if(player.getBoB().freeSlots() < transferAmount) {
  231.                     player.getActionSender()
  232.                             .sendMessage(
  233.                                     "You don't have enough space in your summon's pouch."); // this
  234.                     // is
  235.                     // the
  236.                     // real
  237.                     // message
  238.                 }
  239.                 if(! player.getBoB().add(
  240.                         new Item(item.getId(), transferAmount))) {
  241.                     player.getActionSender()
  242.                             .sendMessage(
  243.                                     "You don't have enough space in your summon's pouch."); // this
  244.                     // is
  245.                     // the
  246.                     // real
  247.                     // message
  248.                 } else {
  249.                     // we need to remove multiple items
  250.                     for(int i = 0; i < transferAmount; i++) {
  251.                         if(i == 0) {
  252.                             container.set(slot, null);
  253.                         } else {
  254.                             container.set(container.getSlotById(item.getId()),
  255.                                     null);
  256.                         }
  257.                     }
  258.                     container.fireItemsChanged();
  259.                 }
  260.             }
  261.         } finally {
  262.             container.setFiringEvents(inventoryFiringEvents);
  263.         }
  264.     }
  265.  
  266. }
  267.  
  268. package org.hyperion.rs2.model.combat;
  269.  
  270. import org.hyperion.rs2.model.combat.summoning.SummoningSpecial;
  271. import org.hyperion.util.Time;
  272.  
  273. import java.util.HashMap;
  274. import java.util.Map;
  275.  
  276.  
  277. public class SummoningData {
  278.  
  279.  
  280.     public static final int ATTACK = 0;
  281.     public static final int MAGIC = 6;
  282.     public static final int DEFENCE = 1;
  283.     public static final int MELEE = 3;
  284.     public static final int RANGE = 4;
  285.     public static final int STRENGTH = 2;
  286.     public static final int NOTHING = - 1;
  287.  
  288.  
  289.     /* Npc id, Pouch id, Name, Level required, Time living */
  290.  
  291.     /**
  292.      * {@link SummoningSpecial}
  293.      */
  294.     public enum SummonType {
  295.         SPIRIT_WOLF(6829, 12047, 1, 600, ATTACK),
  296.         DREADFOWL(6825, 12043, 4, 400, MAGIC),//dreadfowl
  297.         SPIRITSPIDER(6841, 12059, 10, 1500, MELEE),//Spirit spider
  298.         THORNYSNAIL(6806, 12019, 13, 1600, RANGE),//Thorny snail
  299.         GRANITECRAB(6796, 12009, 16, 1800, DEFENCE),//Granite crab
  300.         SPIRIT_MOSQUITO(7331, 12778, 17, 1200, ATTACK),//spirit mosquito
  301.         DESERT_WYRM(9470, 12049, 18, 1900, STRENGTH),//Desert wyrm
  302.         SPIRIT_SCORPION(6838, 12055, 19, 1700, MELEE),//Spirit scorpion
  303.         SPIRITTZKIH(7361, 12808, 22, 1800, MAGIC),//Spirit tz-kih
  304.         ALBINORAT(6847, 12067, 23, 2200, ATTACK),//Albino rat
  305.         COMPOSTMOUND(6871, 12091, 28, 2400, STRENGTH),//compost mound
  306.         GIANTCHINCHOMPA(7353, 12800, 29, 3100, RANGE),//Giant chinchompa
  307.         VAMPIREBAT(9474, 12053, 31, 3300, MELEE),//Vampire bat
  308.         HONEYBADGER(6845, 12065, 32, 2500, STRENGTH),//honey badger
  309.         BEAVER(6808, 12021, 33, 2700, NOTHING),//beaver
  310.         VOIDRANGER(9476, 12818, 34, 2700, STRENGTH),//void ravager
  311.         VOIDSPINNER(7334, 12780, 34, 2700, DEFENCE),//void spinner
  312.         VOIDSHIFTER(7367, 12814, 34, 9400, ATTACK),//void shifter
  313.         VOICTORCHER(7352, 12798, 34, 9400, MAGIC),//void torcher
  314.         BRONZEMINO(6853, 12073, 36, 3000, DEFENCE),//bronze minotaur
  315.         BULANT(6867, 12087, 40, 3000, MELEE),//bul ant
  316.         MACAW(6851, 12071, 41, 3100, NOTHING),//macaw
  317.         EVILTURNIP(6834, 12051, 42, 3000, RANGE),//evil turnip
  318.         SPIRIT_COCKA(6875, 12095, 43, 3600, MAGIC),//spirit cockatrice
  319.         SPIRIT_SARAT(6879, 12099, 43, 3600, MAGIC),//spirit saratrice
  320.         SPIRIT_GUATRICE(6877, 12097, 43, 3600, MAGIC),//spirit gutatrice
  321.         SPIRIT_ZAMA(6881, 12101, 43, 3600, MAGIC),//spirit zamatrice
  322.         SPIRIT_PENGA(6883, 12103, 43, 3600, MAGIC),//spirit pengatrice
  323.         SPIRIT_CORXA(6885, 12105, 43, 3600, MAGIC),//spirit coraxatrice
  324.         SPIRIT_VULA(6887, 12107, 43, 3600, MAGIC),//spirit vulatrice
  325.         PYRELORD(7377, 12816, 46, 3200, STRENGTH),//Pyrelord
  326.         IRONMINO(6855, 12075, 46, 3700, DEFENCE),//iron minotaur
  327.         MAGPIE(6824, 12041, 47, 3400, NOTHING),//magpie
  328.         BLOATEDLEECH(6843, 12061, 49, 3400, ATTACK),//bloated leech
  329.         SPIRITTERRORBIRD(6794, 12007, 52, 3600, MELEE),//spirit terrorbird
  330.         ABYSSALPARA(6819, 12035, 54, 3000, MAGIC),//abyssal parasite
  331.         SPIRITJELLY(6992, 12027, 55, 4300, STRENGTH),//spirit jelly
  332.         STEELMINOT(6857, 12077, 56, 3800, DEFENCE),//steel minotaur
  333.         IBIS(6991, 12531, 56, 4600, NOTHING),//ibis
  334.         GRAAHK(7363, 12810, 57, 4900, STRENGTH),//spirit graahk
  335.         KYAY(7365, 12812, 57, 4900, ATTACK),//Spirit kyat
  336.         LARUPIA(7337, 12784, 57, 4900, MELEE),//spirit larupia
  337.         KARMTHLU(6809, 12023, 58, 4400, RANGE),//karmthulu overlord
  338.         SMOKEDEVIL(6866, 12085, 61, 4800, MAGIC),//smoke devil
  339.         LURKER(6821, 12037, 62, 4100, MELEE),//abyssal lurker
  340.         COBRA(6802, 12015, 63, 5600, ATTACK),//spirit cobra
  341.         PLANT(6827, 12045, 64, 4900, MELEE),//stranger plant
  342.         MITHMINO(6859, 12079, 66, 5500, DEFENCE),//mithril minotaur
  343.         BARKERTOAD(6889, 12123, 66, 800, STRENGTH),//barker toad
  344.         WARTORTISE(6815, 12031, 67, 4300, DEFENCE),//war tortoise
  345.         BUNYIP(6813, 12029, 68, 4400, ATTACK),//bunyip
  346.         FRUITBAT(6817, 12033, 69, 2400, NOTHING),//fruit bat
  347.         LOCUSTS(7373, 12820, 70, 2800, ATTACK),//ravenous locust
  348.         ARTICBEAR(6839, 12057, 71, 3000, MELEE),//arctic bear
  349.         PHOENIX(8538, 14623, 72, 5500, MAGIC),//phoenix
  350.         GOLEMOBSD(9485, 12792, 73, 4700, STRENGTH),//obsidian golem
  351.         GRANITELOBY(6850, 12069, 74, 6900, DEFENCE),//granite lobster
  352.         PRAYINGMANTIS(6798, 12011, 75, 6900, ATTACK),//praying mantis
  353.         ADDYMINO(6861, 12081, 76, 6600, DEFENCE),//adamant minotaur
  354.         FORGEREGENT(7335, 12782, 76, 4500, RANGE),//forge regent
  355.         TALONBEAST(7347, 12794, 77, 4900, STRENGTH),//talon beast
  356.         GIANTENT(6800, 12013, 78, 4900, MELEE),//giant ent
  357.         FIRETITAN(7355, 12802, 79, 6200, MAGIC),//fire titan
  358.         ICETITAN(7357, 12804, 79, 6400, ATTACK),//ice titan
  359.         MOSSTITAN(7359, 12806, 79, 5800, STRENGTH),//moss titan
  360.         HYDRA(6811, 12025, 80, 4900, RANGE),//hydra
  361.         DAGANNOTH(6804, 12017, 83, 5700, MELEE),//spirit dagannoth
  362.         LAVATITAN(7341, 12788, 83, 6100, STRENGTH),//lava titan
  363.         SWAMPTITAN(7329, 12776, 85, 5600, ATTACK),//swamp titan
  364.         RUNEMINO(6863, 12083, 86, 15100, DEFENCE),//rune minotaur
  365.         UNICORNSTALLION(6823, 12039, 88, 5400, MELEE),//unicorn stallion
  366.         GEYSERTITAN(7339, 12786, 89, 6900, RANGE),//geyser titan
  367.         WOLPERTINGER(6869, 12089, 92, 6200, MAGIC),//wolpertinger
  368.         ABBYTITAN(7349, 12796, 93, 3200, ATTACK),//abyssal titan
  369.         IRONTITAN(7375, 12822, 95, 6000, DEFENCE),//iron titan
  370.         PACKYAK(6873, 12093, 96, 5800, STRENGTH),//pack yak
  371.         STEELTITAN(7343, 12790, 99, 6400, RANGE),//Steel titan
  372.         REV_KNIGHT(6692, 17989, 99, (int)Time.TEN_MINUTES, MAGIC),
  373.         REV_BEAST(6691, 17988, 90,(int) Time.TEN_MINUTES, MAGIC),
  374.         REV_ORK(6690, 17987, 80, (int)Time.TEN_MINUTES, MAGIC),
  375.         REV_DEMON(6689, 17986, 75, (int)Time.TEN_MINUTES, MAGIC),
  376.         REV_HELLHOUND(6688, 17985, 70, (int)Time.TEN_MINUTES, MAGIC)
  377.         ; //rev knight
  378.  
  379.         /* Npc id, Pouch id, Name, Level required, Time living */
  380.         SummonType(int npcId, int pouchId, int level, int timeLiving, int skillId) {
  381.             this.npcId = npcId;
  382.             this.pouchId = pouchId;
  383.             this.level = level;
  384.             this.timeLiving = timeLiving;
  385.             this.skillId = skillId;
  386.         }
  387.  
  388.         public int npcId, pouchId, level, timeLiving, skillId;
  389.  
  390.     }
  391.  
  392.     ;
  393.  
  394.     private static Map<Integer, SummonType> summonsNpcId = new HashMap<Integer, SummonType>();
  395.     private static Map<Integer, SummonType> summonsPouchId = new HashMap<Integer, SummonType>();
  396.  
  397.     static {
  398.         for(SummonType summonType : SummonType.values()) {
  399.             summonsNpcId.put(summonType.npcId, summonType);
  400.             summonsPouchId.put(summonType.pouchId, summonType);
  401.         }
  402.     }
  403.  
  404.     public static int getTimerById(int npcId) {
  405.         if(summonsNpcId.get(npcId) == null)
  406.             return 0;
  407.         return summonsNpcId.get(npcId).timeLiving;
  408.     }
  409.  
  410.     public static int getPouchByNpc(int npcId) {
  411.         if(summonsNpcId.get(npcId) == null)
  412.             return 0;
  413.         return summonsNpcId.get(npcId).pouchId;
  414.     }
  415.  
  416.     public static int getNpcbyPouchId(int pouchId) {
  417.         if(summonsPouchId.get(pouchId) == null)
  418.             return 0;
  419.         return summonsPouchId.get(pouchId).npcId;//+1 is u can attack in wild
  420.     }
  421.  
  422.     public static int getRequirementForNpcId(int npcId) {
  423.         if(summonsNpcId.get(npcId) == null)
  424.             return 0;
  425.         return summonsNpcId.get(npcId).level;
  426.     }
  427.  
  428.  
  429. }
  430.  
  431. package org.hyperion.rs2.model.combat.summoning;
  432.  
  433. import org.hyperion.rs2.model.*;
  434. import org.hyperion.rs2.model.combat.SummoningData;
  435. import org.hyperion.rs2.model.combat.SummoningData.SummonType;
  436. import org.hyperion.rs2.model.combat.summoning.impl.PackYak;
  437. import org.hyperion.rs2.model.combat.summoning.impl.SteelTitanSpecial;
  438. import org.hyperion.rs2.model.combat.summoning.impl.Unicorn;
  439. import org.hyperion.rs2.model.combat.summoning.impl.WolpertingerSpecial;
  440. import org.hyperion.rs2.model.container.BoB;
  441. import org.hyperion.rs2.model.content.ContentEntity;
  442. import org.hyperion.rs2.model.content.skill.Summoning;
  443. import org.hyperion.rs2.model.Animation;
  444.  
  445. /**
  446.  * @author Wasay
  447.  *         Concrete class to preform summoning specials
  448.  */
  449. public final class SummoningSpecial {
  450.     public static void preformSpecial(Player p, AbstractSummoningSpecial ass) { //didn't see that abbreviation coming
  451.         if(ass != null) {
  452.             if(ass.checkRequirements(p)) {
  453.                 performSpecialBlock:{
  454.                     if(System.currentTimeMillis() - p.getSummBar().getLast() < SummoningBar.DELAY) {
  455.                         p.getActionSender().sendMessage("You need to wait before using another special!");
  456.                         break performSpecialBlock;
  457.                     }
  458.                     if(ass.requiredSpecial() > p.getSummBar().getAmount()) {
  459.                         p.getActionSender().sendMessage("You need "+ass.requiredSpecial()+"% special to perform this attack");
  460.                         break performSpecialBlock;
  461.                     }
  462.                     try {
  463.                         if(ass.requiresOpponent())
  464.                             ass.executeOpponent(p.getCombat().getOpponent().getEntity());
  465.                     } catch(NullPointerException e) {
  466.                         p.getActionSender().sendMessage("You can't use the special on this opponent!");
  467.                         break performSpecialBlock;
  468.                     }
  469.                     ass.execute(p);
  470.                     ass.executeFamiliar(p.getCombat().getFamiliar());
  471.                     p.getSummBar().setLast(System.currentTimeMillis());
  472.                     p.getSummBar().decrement(ass.requiredSpecial());
  473.                     p.getInventory().remove(new Item(ass.getScrollId()));
  474.                 }
  475.             }
  476.         } else {
  477.             p.getActionSender().sendMessage("You do not have a familiar with a special attack!");
  478.         }
  479.     }
  480.  
  481.     /**
  482.      * @param npcId player's familiar Id
  483.      * @return proper instance of AbstractSummoningSpecial based on their familiar id - {@link SummonType}
  484.      */
  485.     public static AbstractSummoningSpecial getCorrectSpecial(int npcId) {
  486.        
  487.         switch(npcId) {
  488.             default:
  489.                 return null;
  490.             case 7343:
  491.                 return SteelTitanSpecial.getInstance();
  492.             case 6869:
  493.                 return WolpertingerSpecial.getInstance();
  494.             case 6823:
  495.                 return Unicorn.getInstance();
  496.         }
  497.     }
  498. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement