Advertisement
Guest User

aCis Double Click Augment

a guest
May 20th, 2024
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.75 KB | Source Code | 0 0
  1. package net.sf.l2j.mods.itemhandlers;
  2.  
  3. import net.sf.l2j.gameserver.data.xml.AugmentationData;
  4. import net.sf.l2j.gameserver.enums.Paperdoll;
  5. import net.sf.l2j.gameserver.enums.SayType;
  6. import net.sf.l2j.gameserver.handler.IItemHandler;
  7. import net.sf.l2j.gameserver.model.Augmentation;
  8. import net.sf.l2j.gameserver.model.actor.Playable;
  9. import net.sf.l2j.gameserver.model.actor.Player;
  10. import net.sf.l2j.gameserver.model.item.instance.ItemInstance;
  11. import net.sf.l2j.gameserver.network.serverpackets.CreatureSay;
  12. import net.sf.l2j.gameserver.network.serverpackets.ExShowScreenMessage;
  13. import net.sf.l2j.gameserver.network.serverpackets.InventoryUpdate;
  14. import net.sf.l2j.gameserver.network.serverpackets.SocialAction;
  15.  
  16. /**
  17.  * @author RKolibri
  18.  */
  19. public class FastAugmentation implements IItemHandler {
  20.     @Override
  21.     public void useItem(Playable playable, ItemInstance item, boolean forceUse) {
  22.         Player player = (Player) playable;
  23.         ItemInstance weapon = player.getInventory().getItemFrom(Paperdoll.RHAND);
  24.         Augmentation topLs = AugmentationData.getInstance().generateRandomAugmentation(76, 3);
  25.         Augmentation highLs = AugmentationData.getInstance().generateRandomAugmentation(76, 2);
  26.         Augmentation midLs = AugmentationData.getInstance().generateRandomAugmentation(76, 1);
  27.         Augmentation noGradeLs = AugmentationData.getInstance().generateRandomAugmentation(76, 0);
  28.         InventoryUpdate iu = new InventoryUpdate();
  29.         int ls = item.getItemId();
  30.         if (weapon == null) {
  31.             player.sendMessage("You have to equip a weapon first.");
  32.             return;
  33.         }
  34.         if (weapon.getItem().getCrystalType().getId() <= 3) {
  35.             player.sendMessage("Fast Augmentation available only for A and S grade  Weapons!");
  36.             return;
  37.         }
  38.         if (weapon.isHeroItem()) {
  39.             player.sendMessage("Hero weapons can't be augmented!");
  40.             return;
  41.         }
  42.         if (weapon.isAugmented()) {
  43.             removeAug(playable);
  44.         } else {
  45.             player.destroyItem("Consume", item.getObjectId(), 1, null, false);
  46.             Augmentation augmentation;
  47.             if (ls == 8762) {
  48.                 augmentation = topLs;
  49.             } else if (ls == 8752) {
  50.                 augmentation = highLs;
  51.             } else if (ls == 8742) {
  52.                 augmentation = midLs;
  53.             } else if (ls == 8732) {
  54.                 augmentation = noGradeLs;
  55.             } else {
  56.                 return;
  57.             }
  58.             weapon.setAugmentation(augmentation);
  59.             iu.addModifiedItem(weapon);
  60.             player.sendPacket(iu);
  61.             player.broadcastUserInfo();
  62.             if (weapon.getAugmentation().getSkill() == null) {
  63.                 player.sendMessage("No luck try again!");
  64.             } else {
  65.                 checkAugmentResult(playable);
  66.             }
  67.         }
  68.     }
  69.  
  70.     public static boolean removeAug(Playable playable) {
  71.         Player player = (Player) playable;
  72.         ItemInstance weapon = player.getInventory().getItemFrom(Paperdoll.RHAND);
  73.         InventoryUpdate iu = new InventoryUpdate();
  74.         weapon.getAugmentation().removeBonus(player);
  75.         weapon.removeAugmentation(true);
  76.         iu.addModifiedItem(weapon);
  77.         player.sendPacket(iu);
  78.         player.broadcastUserInfo();
  79.         return true;
  80.     }
  81.  
  82.     private static void checkAugmentResult(Playable playable) {
  83.         Player player = (Player) playable;
  84.         ItemInstance weapon = player.getInventory().getItemFrom(Paperdoll.RHAND);
  85.         String name = weapon.getAugmentation().getSkill().getName();
  86.         boolean isChance = weapon.getAugmentation().getSkill().isChance();
  87.         boolean isActive = weapon.getAugmentation().getSkill().isActive();
  88.         boolean isPassive = weapon.getAugmentation().getSkill().isPassive() && !isChance;
  89.         InventoryUpdate iu = new InventoryUpdate();
  90.  
  91.         String type;
  92.         if (isChance) {
  93.             type = "CHANCE";
  94.         } else if (isActive) {
  95.             type = "ACTIVE";
  96.         } else if (isPassive) {
  97.             type = "PASSIVE";
  98.         } else {
  99.             return;
  100.         }
  101.  
  102.         player.sendPacket(new CreatureSay(0, SayType.HERO_VOICE, "[" + type + "]", "You got " + name));
  103.         sendMessage(player, type + " : You got " + name);
  104.         player.broadcastPacket(new SocialAction(player, 3));
  105.         player.disarmWeapon(true);
  106.         iu.addModifiedItem(weapon);
  107.         player.sendPacket(iu);
  108.         player.broadcastUserInfo();
  109.     }
  110.  
  111.     public static void sendMessage(final Player player, final String message) {
  112.         player.sendPacket(new ExShowScreenMessage(message, 3000, ExShowScreenMessage.SMPOS.TOP_CENTER, true));
  113.         player.sendMessage(message);
  114.     }
  115.  
  116. }
Tags: l2j aCis
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement