Package com.l2jfrozen.gameserver.model.actor.instance

Examples of com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance


  {
    long totalPrice = 0;
    int slots = 0;
    int totalWeight = 0;

    L2PcInstance player = getClient().getActiveChar();
    if(player == null)
      return;

    if (!getClient().getFloodProtectors().getManor().tryPerformAction("BuySeed"))
      return;

   
    if(_count < 1)
    {
      sendPacket(ActionFailed.STATIC_PACKET);
      return;
    }

    L2Object target = player.getTarget();

    if(!(target instanceof L2ManorManagerInstance))
    {
      target = player.getLastFolkNPC();
    }

    if(!(target instanceof L2ManorManagerInstance))
      return;

    Castle castle = CastleManager.getInstance().getCastleById(_manorId);

    for(int i = 0; i < _count; i++)
    {
      int seedId = _items[i * 2 + 0];
      int count = _items[i * 2 + 1];
      int price = 0;
      int residual = 0;

      SeedProduction seed = castle.getSeed(seedId, CastleManorManager.PERIOD_CURRENT);
      price = seed.getPrice();
      residual = seed.getCanProduce();

      if(price <= 0)
        return;

      if(residual < count)
        return;

      totalPrice += count * price;

      L2Item template = ItemTable.getInstance().getTemplate(seedId);
      totalWeight += count * template.getWeight();
      if(!template.isStackable())
      {
        slots += count;
      }
      else if(player.getInventory().getItemByItemId(seedId) == null)
      {
        slots++;
      }
    }

    if(totalPrice > Integer.MAX_VALUE)
    {
      Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " tried to purchase over " + Integer.MAX_VALUE + " adena worth of goods.", Config.DEFAULT_PUNISH);
      return;
    }

    if(!player.getInventory().validateWeight(totalWeight))
    {
      sendPacket(new SystemMessage(SystemMessageId.WEIGHT_LIMIT_EXCEEDED));
      return;
    }

    if(!player.getInventory().validateCapacity(slots))
    {
      sendPacket(new SystemMessage(SystemMessageId.SLOTS_FULL));
      return;
    }

    // Charge buyer
    if(totalPrice < 0 || !player.reduceAdena("Buy", (int) totalPrice, target, false))
    {
      sendPacket(new SystemMessage(SystemMessageId.YOU_NOT_ENOUGH_ADENA));
      return;
    }

    // Adding to treasury for Manor Castle
    castle.addToTreasuryNoTax((int) totalPrice);

    // Proceed the purchase
    InventoryUpdate playerIU = new InventoryUpdate();
    for(int i = 0; i < _count; i++)
    {
      int seedId = _items[i * 2 + 0];
      int count = _items[i * 2 + 1];

      if(count < 0)
      {
        count = 0;
      }

      // Update Castle Seeds Amount
      SeedProduction seed = castle.getSeed(seedId, CastleManorManager.PERIOD_CURRENT);
      seed.setCanProduce(seed.getCanProduce() - count);
      if(Config.ALT_MANOR_SAVE_ALL_ACTIONS)
      {
        CastleManager.getInstance().getCastleById(_manorId).updateSeed(seed.getId(), seed.getCanProduce(), CastleManorManager.PERIOD_CURRENT);
      }

      // Add item to Inventory and adjust update packet
      L2ItemInstance item = player.getInventory().addItem("Buy", seedId, count, player, target);

      if(item.getCount() > count)
      {
        playerIU.addModifiedItem(item);
      }
      else
      {
        playerIU.addNewItem(item);
      }

      // Send Char Buy Messages
      SystemMessage sm = null;
      sm = new SystemMessage(SystemMessageId.EARNED_S2_S1_S);
      sm.addItemName(seedId);
      sm.addNumber(count);
      player.sendPacket(sm);
    }
    // Send update packets
    player.sendPacket(playerIU);

    StatusUpdate su = new StatusUpdate(player.getObjectId());
    su.addAttribute(StatusUpdate.CUR_LOAD, player.getCurrentLoad());
    player.sendPacket(su);
  }
View Full Code Here


  }

  @Override
  protected void runImpl()
  {
    L2PcInstance player = getClient().getActiveChar();

    if (player == null)
      return;

    if (player.isInBoat())
    {
      if (player.getBoat().getObjectId() == _boatId)
      {
        player.setInBoatPosition(new Point3D(_x, _y, _z));
        player.getPosition().setHeading(_heading);
        player.broadcastPacket(new StopMoveInVehicle(player, _boatId));
      }
    }
  }
View Full Code Here

  @Override
  protected void runImpl()
  {
    //System.out.println("C5: RequestPledgeMemberPowerInfo d:"+_unk1);
    //System.out.println("C5: RequestPledgeMemberPowerInfo S:"+_player);
    L2PcInstance activeChar = getClient().getActiveChar();
    if(activeChar == null)
      return;
    //do we need powers to do that??
    L2Clan clan = activeChar.getClan();
    if(clan == null)
      return;
    L2ClanMember member = clan.getClanMember(_player);
    if(member == null)
      return;
    activeChar.sendPacket(new PledgeReceivePowerInfo(member));
  }
View Full Code Here

    if(Config.DEBUG)
    {
      _log.fine("request unequip slot " + _slot);
    }

    L2PcInstance activeChar = getClient().getActiveChar();
    if(activeChar == null)
      return;

    if(activeChar._haveFlagCTF)
    {
      activeChar.sendMessage("You can't unequip a CTF flag.");
      return;
    }

    L2ItemInstance item = activeChar.getInventory().getPaperdollItemByL2ItemId(_slot);
    if(item != null && item.isWear())
      // Wear-items are not to be unequipped
      return;

    // Prevent of unequiping a cursed weapon
    if(_slot == L2Item.SLOT_LR_HAND && activeChar.isCursedWeaponEquiped())
      // Message ?
      return;

    // Prevent player from unequipping items in special conditions
    if(activeChar.isStunned() || activeChar.isConfused() || activeChar.isAway() || activeChar.isParalyzed() || activeChar.isSleeping() || activeChar.isAlikeDead())
    {
      activeChar.sendMessage("Your status does not allow you to do that.");
      return;
    }

    if(/*activeChar.isAttackingNow() || */activeChar.isCastingNow() || activeChar.isCastingPotionNow())
      return;

    if(activeChar.isMoving() && activeChar.isAttackingNow() && (_slot == L2Item.SLOT_LR_HAND || _slot == L2Item.SLOT_L_HAND || _slot == L2Item.SLOT_R_HAND))
    {
      L2Object target = activeChar.getTarget();
      activeChar.setTarget(null);
      activeChar.stopMove(null);
      activeChar.setTarget(target);
      activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK);
    }

    // Remove augmentation bonus
    if(item != null && item.isAugmented())
    {
      item.getAugmentation().removeBoni(activeChar);
    }

    L2ItemInstance[] unequiped = activeChar.getInventory().unEquipItemInBodySlotAndRecord(_slot);

    // show the update in the inventory
    InventoryUpdate iu = new InventoryUpdate();

    for(L2ItemInstance element : unequiped)
    {
      activeChar.checkSSMatch(null, element);

      iu.addModifiedItem(element);
    }

    activeChar.sendPacket(iu);

    activeChar.broadcastUserInfo();

    // this can be 0 if the user pressed the right mouse button twice very fast
    if(unequiped.length > 0)
    {

      SystemMessage sm = null;
      if(unequiped[0].getEnchantLevel() > 0)
      {
        sm = new SystemMessage(SystemMessageId.EQUIPMENT_S1_S2_REMOVED);
        sm.addNumber(unequiped[0].getEnchantLevel());
        sm.addItemName(unequiped[0].getItemId());
      }
      else
      {
        sm = new SystemMessage(SystemMessageId.S1_DISARMED);
        sm.addItemName(unequiped[0].getItemId());
      }
      activeChar.sendPacket(sm);
      sm = null;
    }
  }
View Full Code Here

 
  @Override
  protected void runImpl()
  {
    SystemMessage sm;
    L2PcInstance activeChar = getClient().getActiveChar();
   
    if (activeChar == null)
      return;
   
    L2PcInstance friend = L2World.getInstance().getPlayer(_name);
   
    // _name = Util.capitalizeFirst(_name); //FIXME: is it right to capitalize a nickname?
   
    if (friend == null)
    {
      // Target is not found in the game.
      sm = new SystemMessage(SystemMessageId.THE_USER_YOU_REQUESTED_IS_NOT_IN_GAME);
      activeChar.sendPacket(sm);
      sm = null;
      return;
    }
   
    if (friend == activeChar)
    {
      // You cannot add yourself to your own friend list.
      sm = new SystemMessage(SystemMessageId.YOU_CANNOT_ADD_YOURSELF_TO_OWN_FRIEND_LIST);
      activeChar.sendPacket(sm);
      sm = null;
      return;
    }
   
    if (activeChar.getBlockList().isInBlockList(_name))
    {
      sm = new SystemMessage(SystemMessageId.FAILED_TO_INVITE_A_FRIEND);
      activeChar.sendPacket(sm);
      return;
    }
   
    if (friend.getBlockList().isInBlockList(activeChar.getName()))
    {
      sm = new SystemMessage(SystemMessageId.S1_HAS_ADDED_YOU_TO_IGNORE_LIST);
      sm.addString(friend.getName());
      activeChar.sendPacket(sm);
      sm = new SystemMessage(SystemMessageId.FAILED_TO_INVITE_A_FRIEND);
      activeChar.sendPacket(sm);
      return;
    }
   
    if (activeChar.isInCombat() || friend.isInCombat())
    {
      sm = new SystemMessage(SystemMessageId.S1_IS_BUSY_TRY_LATER);
      activeChar.sendPacket(sm);
      sm = null;
      return;
    }
   
    if (activeChar.getFriendList().contains(friend.getName()))
    {
      // Player already is in your friendlist
      sm = new SystemMessage(SystemMessageId.S1_ALREADY_IN_FRIENDS_LIST);
      sm.addString(_name);
      activeChar.sendPacket(sm);
      return;
    }
   
    if (!friend.isProcessingRequest())
    {
      // requets to become friend
      activeChar.onTransactionRequest(friend);
      sm = new SystemMessage(SystemMessageId.S1_REQUESTED_TO_BECOME_FRIENDS);
      sm.addString(_name);
      AskJoinFriend ajf = new AskJoinFriend(activeChar.getName());
      friend.sendPacket(ajf);
    }
    else
    {
      sm = new SystemMessage(SystemMessageId.S1_IS_BUSY_TRY_LATER);
    }
   
    friend.sendPacket(sm);
   
  }
View Full Code Here

  }
 
  @Override
  protected void runImpl()
  {
    L2PcInstance activeChar = getClient().getActiveChar();
    if (activeChar == null)
      return;
    if (activeChar.inObserverMode()) Olympiad.sendMatchList(activeChar);
  }
View Full Code Here

  }

  @Override
  protected void runImpl()
  {
    L2PcInstance activeChar = getClient().getActiveChar();
    if(activeChar == null || _objectId == 0)
      return;

    if(activeChar.getActiveTradeList() != null)
    {
      activeChar.cancelActiveTrade();
      activeChar.sendMessage("Your trade canceled");
      return;
    }

    // Fix enchant transactions
    if(activeChar.isProcessingTransaction())
    {
      activeChar.sendPacket(new SystemMessage(SystemMessageId.INAPPROPRIATE_ENCHANT_CONDITION));
      activeChar.setActiveEnchantItem(null);
      return;
    }

    if(activeChar.isOnline() == 0)
    {
      activeChar.setActiveEnchantItem(null);
      return;
    }

    L2ItemInstance item = activeChar.getInventory().getItemByObjectId(_objectId);
    L2ItemInstance scroll = activeChar.getActiveEnchantItem();
    activeChar.setActiveEnchantItem(null);

    if(item == null || scroll == null)
    {
      activeChar.setActiveEnchantItem(null);
      return;
    }

    // can't enchant rods and shadow items
    if(item.getItem().getItemType() == L2WeaponType.ROD || item.isShadowItem())
    {
      activeChar.sendPacket(new SystemMessage(SystemMessageId.INAPPROPRIATE_ENCHANT_CONDITION));
      activeChar.setActiveEnchantItem(null);
      return;
    }

    if(!Config.ENCHANT_HERO_WEAPON && item.getItemId() >= 6611 && item.getItemId() <= 6621)
    {
      activeChar.sendPacket(new SystemMessage(SystemMessageId.INAPPROPRIATE_ENCHANT_CONDITION));
      activeChar.setActiveEnchantItem(null);
      return;
    }
   
    /*
    if(!FloodProtector.getInstance().tryPerformAction(activeChar.getObjectId(), FloodProtector.PROTECTED_ENCHANT))
    {
      activeChar.setActiveEnchantItem(null);
      activeChar.sendMessage("Enchant failed");
      return;
    }*/

    if(item.isWear())
    {
      activeChar.setActiveEnchantItem(null);
      Util.handleIllegalPlayerAction(activeChar, "Player " + activeChar.getName() + " tried to enchant a weared Item", IllegalPlayerAction.PUNISH_KICK);
      return;
    }

    int itemType2 = item.getItem().getType2();
    boolean enchantItem = false;
    boolean blessedScroll = false;
    boolean crystalScroll = false;
    int crystalId = 0;

    /** pretty code ;D */
    switch(item.getItem().getCrystalType())
    {
      case L2Item.CRYSTAL_A:
        crystalId = 1461;
        switch(scroll.getItemId())
        {
          case 729:
          case 731:
          case 6569:
            if(itemType2 == L2Item.TYPE2_WEAPON)
            {
              enchantItem = true;
            }
            break;
          case 730:
          case 732:
          case 6570:
            if(itemType2 == L2Item.TYPE2_SHIELD_ARMOR || itemType2 == L2Item.TYPE2_ACCESSORY)
            {
              enchantItem = true;
            }
            break;
        }
        break;
      case L2Item.CRYSTAL_B:
        crystalId = 1460;
        switch(scroll.getItemId())
        {
          case 947:
          case 949:
          case 6571:
            if(itemType2 == L2Item.TYPE2_WEAPON)
            {
              enchantItem = true;
            }
            break;
          case 948:
          case 950:
          case 6572:
            if(itemType2 == L2Item.TYPE2_SHIELD_ARMOR || itemType2 == L2Item.TYPE2_ACCESSORY)
            {
              enchantItem = true;
            }
            break;
        }
        break;
      case L2Item.CRYSTAL_C:
        crystalId = 1459;
        switch(scroll.getItemId())
        {
          case 951:
          case 953:
          case 6573:
            if(itemType2 == L2Item.TYPE2_WEAPON)
            {
              enchantItem = true;
            }
            break;
          case 952:
          case 954:
          case 6574:
            if(itemType2 == L2Item.TYPE2_SHIELD_ARMOR || itemType2 == L2Item.TYPE2_ACCESSORY)
            {
              enchantItem = true;
            }
            break;
        }
        break;
      case L2Item.CRYSTAL_D:
        crystalId = 1458;
        switch(scroll.getItemId())
        {
          case 955:
          case 957:
          case 6575:
            if(itemType2 == L2Item.TYPE2_WEAPON)
            {
              enchantItem = true;
            }
            break;
          case 956:
          case 958:
          case 6576:
            if(itemType2 == L2Item.TYPE2_SHIELD_ARMOR || itemType2 == L2Item.TYPE2_ACCESSORY)
            {
              enchantItem = true;
            }
            break;
        }
        break;
      case L2Item.CRYSTAL_S:
        crystalId = 1462;
        switch(scroll.getItemId())
        {
          case 959:
          case 961:
          case 6577:
            if(itemType2 == L2Item.TYPE2_WEAPON)
            {
              enchantItem = true;
            }
            break;
          case 960:
          case 962:
          case 6578:
            if(itemType2 == L2Item.TYPE2_SHIELD_ARMOR || itemType2 == L2Item.TYPE2_ACCESSORY)
            {
              enchantItem = true;
            }
            break;
        }
        break;
    }

    if(!enchantItem)
    {
      activeChar.sendPacket(new SystemMessage(SystemMessageId.INAPPROPRIATE_ENCHANT_CONDITION));
      return;
    }
   
    // Get the scroll type - Yesod
    if(scroll.getItemId() >= 6569 && scroll.getItemId() <= 6578)
    {
      blessedScroll = true;
    }
    else
    {
      for(int crystalscroll : CRYSTAL_SCROLLS)
        if(scroll.getItemId() == crystalscroll)
        {
          crystalScroll = true;
          break;
        }
    }

    // SystemMessage sm = new SystemMessage(SystemMessageId.ENCHANT_SCROLL_CANCELLED);
    // activeChar.sendPacket(sm);

    SystemMessage sm;

    int chance = 0;
    int maxEnchantLevel = 0;
    int minEnchantLevel = 0;

    if(item.getItem().getType2() == L2Item.TYPE2_WEAPON)
    {
      if(blessedScroll){
       
        for(int blessedweaponscroll : BLESSED_WEAPON_SCROLLS)
        {
          if(scroll.getItemId() == blessedweaponscroll)
          {
            if(item.getEnchantLevel() >= Config.BLESS_WEAPON_ENCHANT_LEVEL.size()) //the hash has size equals to
                                                 //max enchant, so if the actual
                                                 //enchant level is equal or more then max
                                                 //then the enchant rate is equal to last
                                                 //enchant rate
            {
              chance = Config.BLESS_WEAPON_ENCHANT_LEVEL.get(Config.BLESS_WEAPON_ENCHANT_LEVEL.size());
            }
            else
            {
              chance = Config.BLESS_WEAPON_ENCHANT_LEVEL.get(item.getEnchantLevel() + 1);
            }
            maxEnchantLevel = Config.ENCHANT_WEAPON_MAX;
           
            break;
          }
        }
       
      }else if(crystalScroll){
       
        for(int crystalweaponscroll : CRYSTAL_WEAPON_SCROLLS)
        {
          if(scroll.getItemId() == crystalweaponscroll)
          {
            if(item.getEnchantLevel() >= Config.CRYSTAL_WEAPON_ENCHANT_LEVEL.size())
            {
              chance = Config.CRYSTAL_WEAPON_ENCHANT_LEVEL.get(Config.CRYSTAL_WEAPON_ENCHANT_LEVEL.size());
            }
            else
            {
              chance = Config.CRYSTAL_WEAPON_ENCHANT_LEVEL.get(item.getEnchantLevel() + 1);
            }
            minEnchantLevel = Config.CRYSTAL_ENCHANT_MIN;
            maxEnchantLevel = Config.CRYSTAL_ENCHANT_MAX;
           
            break;
           
          }
        }
       
      }else{ //normal scrolls
       
        for(int normalweaponscroll : NORMAL_WEAPON_SCROLLS)
        {
          if(scroll.getItemId() == normalweaponscroll)
          {
            if(item.getEnchantLevel() >= Config.NORMAL_WEAPON_ENCHANT_LEVEL.size())
            {
              chance = Config.NORMAL_WEAPON_ENCHANT_LEVEL.get(Config.NORMAL_WEAPON_ENCHANT_LEVEL.size());
            }
            else
            {
              chance = Config.NORMAL_WEAPON_ENCHANT_LEVEL.get(item.getEnchantLevel() + 1);
            }
            maxEnchantLevel = Config.ENCHANT_WEAPON_MAX;
           
            break;
          }
        }
       
      }
     
    }
    else if(item.getItem().getType2() == L2Item.TYPE2_SHIELD_ARMOR)
    {
      if(blessedScroll){
       
        for(int blessedarmorscroll : BLESSED_ARMOR_SCROLLS)
        {
          if(scroll.getItemId() == blessedarmorscroll)
          {
            if(item.getEnchantLevel() >= Config.BLESS_ARMOR_ENCHANT_LEVEL.size())
            {
              chance = Config.BLESS_ARMOR_ENCHANT_LEVEL.get(Config.BLESS_ARMOR_ENCHANT_LEVEL.size());
            }
            else
            {
              chance = Config.BLESS_ARMOR_ENCHANT_LEVEL.get(item.getEnchantLevel() + 1);
            }
            maxEnchantLevel = Config.ENCHANT_ARMOR_MAX;
           
            break;
          }
        }
       
      }else if(crystalScroll){
       
        for(int crystalarmorscroll : CRYSTAL_ARMOR_SCROLLS)
        {
          if(scroll.getItemId() == crystalarmorscroll)
          {
            if(item.getEnchantLevel() >= Config.CRYSTAL_ARMOR_ENCHANT_LEVEL.size())
            {
              chance = Config.CRYSTAL_ARMOR_ENCHANT_LEVEL.get(Config.CRYSTAL_ARMOR_ENCHANT_LEVEL.size());
            }
            else
            {
              chance = Config.CRYSTAL_ARMOR_ENCHANT_LEVEL.get(item.getEnchantLevel() + 1);
            }
            minEnchantLevel = Config.CRYSTAL_ENCHANT_MIN;
            maxEnchantLevel = Config.CRYSTAL_ENCHANT_MAX;
           
            break;
          }
        }
       
      }else{ //normal scrolls
       
        for(int normalarmorscroll : NORMAL_ARMOR_SCROLLS)
        {
          if(scroll.getItemId() == normalarmorscroll)
          {
            if(item.getEnchantLevel()  >= Config.NORMAL_ARMOR_ENCHANT_LEVEL.size())
            {
              chance = Config.NORMAL_ARMOR_ENCHANT_LEVEL.get(Config.NORMAL_ARMOR_ENCHANT_LEVEL.size());
            }
            else
            {
              chance = Config.NORMAL_ARMOR_ENCHANT_LEVEL.get(item.getEnchantLevel() + 1);
            }
            maxEnchantLevel = Config.ENCHANT_ARMOR_MAX;
           
            break;
          }
        }
       
      }
     
    }
    else if(item.getItem().getType2() == L2Item.TYPE2_ACCESSORY)
    {
      if(blessedScroll){
       
        for(int blessedjewelscroll : BLESSED_ARMOR_SCROLLS)
        {
          if(scroll.getItemId() == blessedjewelscroll)
          {
            if(item.getEnchantLevel() >= Config.BLESS_JEWELRY_ENCHANT_LEVEL.size())
            {
              chance = Config.BLESS_JEWELRY_ENCHANT_LEVEL.get(Config.BLESS_JEWELRY_ENCHANT_LEVEL.size());
            }
            else
            {
              chance = Config.BLESS_JEWELRY_ENCHANT_LEVEL.get(item.getEnchantLevel() + 1);
            }
            maxEnchantLevel = Config.ENCHANT_JEWELRY_MAX;
           
            break;
          }
        }
       
      }else if(crystalScroll){
       
        for(int crystaljewelscroll : CRYSTAL_ARMOR_SCROLLS)
        {
          if(scroll.getItemId() == crystaljewelscroll)
          {
            if(item.getEnchantLevel() >= Config.CRYSTAL_JEWELRY_ENCHANT_LEVEL.size())
            {
              chance = Config.CRYSTAL_JEWELRY_ENCHANT_LEVEL.get(Config.CRYSTAL_JEWELRY_ENCHANT_LEVEL.size());
            }
            else
            {
              chance = Config.CRYSTAL_JEWELRY_ENCHANT_LEVEL.get(item.getEnchantLevel() + 1);
            }
            minEnchantLevel = Config.CRYSTAL_ENCHANT_MIN;
            maxEnchantLevel = Config.CRYSTAL_ENCHANT_MAX;
           
            break;
          }
        }
       
      }else{
       
        for(int normaljewelscroll : NORMAL_ARMOR_SCROLLS)
        {
          if(scroll.getItemId() == normaljewelscroll)
          {
            if(item.getEnchantLevel() >= Config.NORMAL_JEWELRY_ENCHANT_LEVEL.size())
            {
              chance = Config.NORMAL_JEWELRY_ENCHANT_LEVEL.get(Config.NORMAL_JEWELRY_ENCHANT_LEVEL.size());
            }
            else
            {
              chance = Config.NORMAL_JEWELRY_ENCHANT_LEVEL.get(item.getEnchantLevel() + 1);
            }
            maxEnchantLevel = Config.ENCHANT_JEWELRY_MAX;
           
            break;
          }
        }
       
      }
     
    }
   
    if((maxEnchantLevel != 0 && item.getEnchantLevel() >= maxEnchantLevel) || (item.getEnchantLevel()) < minEnchantLevel)
    {
      activeChar.sendPacket(new SystemMessage(SystemMessageId.INAPPROPRIATE_ENCHANT_CONDITION));
      return;
    }
   
    if (Config.SCROLL_STACKABLE) {
      scroll = activeChar.getInventory().destroyItem("Enchant", scroll.getObjectId(), 1, activeChar, item);
    }
    else {
      scroll = activeChar.getInventory().destroyItem("Enchant", scroll, activeChar, item);
    }
   
    if(scroll == null)
    {
      activeChar.sendPacket(new SystemMessage(SystemMessageId.NOT_ENOUGH_ITEMS));
      Util.handleIllegalPlayerAction(activeChar, "Player " + activeChar.getName() + " tried to enchant with a scroll he doesnt have", Config.DEFAULT_PUNISH);
      return;
    }

    if(item.getEnchantLevel() < Config.ENCHANT_SAFE_MAX || item.getItem().getBodyPart() == L2Item.SLOT_FULL_ARMOR && item.getEnchantLevel() < Config.ENCHANT_SAFE_MAX_FULL)
    {
      chance = 100;
    }

    int rndValue = Rnd.get(100);

    if(Config.ENABLE_DWARF_ENCHANT_BONUS && activeChar.getRace() == Race.dwarf)
      if(activeChar.getLevel() >= Config.DWARF_ENCHANT_MIN_LEVEL)
      {
        rndValue -= Config.DWARF_ENCHANT_BONUS;
      }

    Object aChance = item.fireEvent("calcEnchantChance", new Object[chance]);
    if(aChance != null)
    {
      chance = (Integer) aChance;
    }
    synchronized (item)
    {
      if(rndValue < chance)
      {
        if(item.getOwnerId() != activeChar.getObjectId())
        {
          activeChar.sendPacket(new SystemMessage(SystemMessageId.INAPPROPRIATE_ENCHANT_CONDITION));
          return;
        }

        if(item.getLocation() != L2ItemInstance.ItemLocation.INVENTORY && item.getLocation() != L2ItemInstance.ItemLocation.PAPERDOLL)
        {
          activeChar.sendPacket(new SystemMessage(SystemMessageId.INAPPROPRIATE_ENCHANT_CONDITION));
          return;
        }

        if(item.getEnchantLevel() == 0)
        {
          sm = new SystemMessage(SystemMessageId.S1_SUCCESSFULLY_ENCHANTED);
          sm.addItemName(item.getItemId());
          activeChar.sendPacket(sm);
        }
        else
        {
          sm = new SystemMessage(SystemMessageId.S1_S2_SUCCESSFULLY_ENCHANTED);
          sm.addNumber(item.getEnchantLevel());
          sm.addItemName(item.getItemId());
          activeChar.sendPacket(sm);
        }

        item.setEnchantLevel(item.getEnchantLevel() + Config.CUSTOM_ENCHANT_VALUE);
        item.updateDatabase();
      }
      else
      {
        if(crystalScroll)
        {
          sm = SystemMessage.sendString("Failed in Crystal Enchant.");
          activeChar.sendPacket(sm);
        }
        else if(blessedScroll){
          sm = new SystemMessage(SystemMessageId.BLESSED_ENCHANT_FAILED);
          activeChar.sendPacket(sm);
        }else{
          if(item.getEnchantLevel() > 0)
          {
            sm = new SystemMessage(SystemMessageId.ENCHANTMENT_FAILED_S1_S2_EVAPORATED);
            sm.addNumber(item.getEnchantLevel());
            sm.addItemName(item.getItemId());
            activeChar.sendPacket(sm);
          }
          else
          {
            sm = new SystemMessage(SystemMessageId.ENCHANTMENT_FAILED_S1_EVAPORATED);
            sm.addItemName(item.getItemId());
            activeChar.sendPacket(sm);
          }
        }
       
        if(!blessedScroll && !crystalScroll)
        {
          if(item.getEnchantLevel() > 0)
          {
            sm = new SystemMessage(SystemMessageId.EQUIPMENT_S1_S2_REMOVED);
            sm.addNumber(item.getEnchantLevel());
            sm.addItemName(item.getItemId());
            activeChar.sendPacket(sm);
          }
          else
          {
            sm = new SystemMessage(SystemMessageId.S1_DISARMED);
            sm.addItemName(item.getItemId());
            activeChar.sendPacket(sm);
          }

          if(item.isEquipped())
          {
            if(item.isAugmented())
            {
              item.getAugmentation().removeBoni(activeChar);
            }

            L2ItemInstance[] unequiped = activeChar.getInventory().unEquipItemInSlotAndRecord(item.getEquipSlot());

            InventoryUpdate iu = new InventoryUpdate();
            for(L2ItemInstance element : unequiped)
            {
              iu.addModifiedItem(element);
            }
            activeChar.sendPacket(iu);

            activeChar.broadcastUserInfo();
          }

          int count = item.getCrystalCount() - (item.getItem().getCrystalCount() + 1) / 2;
          if(count < 1)
          {
            count = 1;
          }
         
          if(item.fireEvent("enchantFail", new Object[]
          {}) != null)
            return;
          L2ItemInstance destroyItem = activeChar.getInventory().destroyItem("Enchant", item, activeChar, null);
          if(destroyItem == null)
            return;

          L2ItemInstance crystals = activeChar.getInventory().addItem("Enchant", crystalId, count, activeChar, destroyItem);

          sm = new SystemMessage(SystemMessageId.EARNED_S2_S1_S);
          sm.addItemName(crystals.getItemId());
          sm.addNumber(count);
          activeChar.sendPacket(sm);

          if(!Config.FORCE_INVENTORY_UPDATE)
          {
            InventoryUpdate iu = new InventoryUpdate();
            if(destroyItem.getCount() == 0)
            {
              iu.addRemovedItem(destroyItem);
            }
            else
            {
              iu.addModifiedItem(destroyItem);
            }
            iu.addItem(crystals);

            activeChar.sendPacket(iu);
          }
          else
          {
            activeChar.sendPacket(new ItemList(activeChar, true));
          }

          StatusUpdate su = new StatusUpdate(activeChar.getObjectId());
          su.addAttribute(StatusUpdate.CUR_LOAD, activeChar.getCurrentLoad());
          activeChar.sendPacket(su);

          activeChar.broadcastUserInfo();

          L2World world = L2World.getInstance();
          world.removeObject(destroyItem);
        }
        else
        {
          if(blessedScroll){
            item.setEnchantLevel(Config.BREAK_ENCHANT);
            item.updateDatabase();
          }
          else if(crystalScroll)
          {
            if(Config.ENABLE_CRYSTAL_ENCHANT_BREAK)
            {
              item.setEnchantLevel(Config.CRYSTAL_ENCHANT_MIN);
            }
            item.updateDatabase();
          }
         
         
        }
      }
    }
    sm = null;

    StatusUpdate su = new StatusUpdate(activeChar.getObjectId());
    su.addAttribute(StatusUpdate.CUR_LOAD, activeChar.getCurrentLoad());
    activeChar.sendPacket(su);
    su = null;

    activeChar.sendPacket(new EnchantResult(item.getEnchantLevel())); //FIXME i'm really not sure about this...
    activeChar.sendPacket(new ItemList(activeChar, false)); //TODO update only the enchanted item
    activeChar.broadcastUserInfo();
  }
View Full Code Here

 
  @Override
  protected void runImpl()
  {
    // Dont allow leaving if player is fighting
    L2PcInstance player = getClient().getActiveChar();
   
    if (player == null)
      return;
   
    if (player.isInFunEvent() && !player.isGM())
    {
      player.sendMessage("You cannot Logout while in registered in an Event.");
      player.sendPacket(ActionFailed.STATIC_PACKET);
      return;
    }
   
    if (LastManStanding.isActive())
    {
      if (LastManStanding.started && player.isInLMS())
      {
        player.sendMessage("You cannot Logout while in registered in LMS.");
        player.sendPacket(ActionFailed.STATIC_PACKET);
        return;
      }

      if(LastManStanding.players.contains(player))
      {
        LastManStanding.disconnect(player);
      }
    }
   
    if (player.isInArenaEvent())
    {
      player.sendMessage("You cannot logout while in Arena Event");
      player.sendPacket(ActionFailed.STATIC_PACKET);
      return;
    }
   
    if (player.isAway())
    {
      player.sendMessage("You can't restart in Away mode.");
      return;
    }
   
    player.getInventory().updateDatabase();
   
    if (AttackStanceTaskManager.getInstance().getAttackStanceTask(player) && !(player.isGM() && Config.GM_RESTART_FIGHTING))
    {
      if (Config.DEBUG)
        _log.fine("DEBUG " + getType() + ": Player " + player.getName() + " tried to logout while Fighting");
     
      player.sendPacket(new SystemMessage(SystemMessageId.CANT_LOGOUT_WHILE_FIGHTING));
      player.sendPacket(ActionFailed.STATIC_PACKET);
      return;
    }
   
    // Dont allow leaving if player is in combat
    if (player.isInCombat() && !player.isGM())
    {
      player.sendMessage("You cannot Logout while is in Combat mode.");
      player.sendPacket(ActionFailed.STATIC_PACKET);
      return;
    }
   
    // Dont allow leaving if player is teleporting
    if (player.isTeleporting() && !player.isGM())
    {
      player.sendMessage("You cannot Logout while is Teleporting.");
      player.sendPacket(ActionFailed.STATIC_PACKET);
      return;
    }
   
    if (player.isAio())
    {
      final long pXp = player.getStat().getExp();
          final long tXp = ExperienceData.getInstance().getExpForLevel(1);
          player.getStat().removeExpAndSp(pXp - tXp, 0);
    }
   
    if (player.atEvent)
    {
      player.sendPacket(SystemMessage.sendString("A superior power doesn't allow you to leave the event."));
      return;
    }
   
    if (player.isInOlympiadMode() || Olympiad.getInstance().isRegistered(player))
    {
      player.sendMessage("You can't Logout in Olympiad mode.");
      return;
    }
   
    // Prevent player from logging out if they are a festival participant nd it is in progress,
    // otherwise notify party members that the player is not longer a participant.
    if (player.isFestivalParticipant())
    {
      if (SevenSignsFestival.getInstance().isFestivalInitialized())
      {
        player.sendMessage("You cannot Logout while you are a participant in a Festival.");
        return;
      }
     
      L2Party playerParty = player.getParty();
      if (playerParty != null)
        player.getParty().broadcastToPartyMembers(SystemMessage.sendString(player.getName() + " has been removed from the upcoming Festival."));
    }
   
    if (player.isFlying())
      player.removeSkill(SkillTable.getInstance().getInfo(4289, 1));
   
    if (Config.OFFLINE_LOGOUT && player.isSitting())
    {
      if ((player.isInStoreMode() && Config.OFFLINE_TRADE_ENABLE) || (player.isInCraftMode() && Config.OFFLINE_CRAFT_ENABLE))
      {
        // Sleep effect, not official feature but however L2OFF features (like offline trade)
        if (Config.OFFLINE_SLEEP_EFFECT)
          player.startAbnormalEffect(L2Character.ABNORMAL_EFFECT_SLEEP);
       
        player.store();
        player.closeNetConnection();
       
        if (player.getOfflineStartTime() == 0)
          player.setOfflineStartTime(System.currentTimeMillis());
        return;
      }
    }
    else if (player.isStored())
    {
      player.store();
      player.closeNetConnection();
     
      if (player.getOfflineStartTime() == 0)
        player.setOfflineStartTime(System.currentTimeMillis());
      return;
    }
   
    if (player.isCastingNow())
    {
      player.abortCast();
      player.sendPacket(new ActionFailed());
    }
   
    RegionBBSManager.getInstance().changeCommunityBoard();
    player.deleteMe();
  }
View Full Code Here

  }
 
  @Override
  protected void runImpl()
  {
    L2PcInstance activeChar = getClient().getActiveChar();
   
    if (activeChar == null)
      return;
   
    L2PcInstance requestor = activeChar.getRequest().getPartner();
   
    if (requestor == null)
      return;
   
    if (_answer == 0)
    {
      SystemMessage sm = new SystemMessage(SystemMessageId.YOU_DID_NOT_RESPOND_TO_S1_CLAN_INVITATION);
      sm.addString(requestor.getName());
      activeChar.sendPacket(sm);
      sm = new SystemMessage(SystemMessageId.S1_DID_NOT_RESPOND_TO_CLAN_INVITATION);
      sm.addString(activeChar.getName());
      requestor.sendPacket(sm);
    }
    else
    {
      if (!(requestor.getRequest().getRequestPacket() instanceof RequestJoinPledge))
        return; // hax
       
      RequestJoinPledge requestPacket = (RequestJoinPledge) requestor.getRequest().getRequestPacket();
      L2Clan clan = requestor.getClan();
      // we must double check this cause during response time conditions can be changed, i.e. another player could join clan
      if (clan != null && clan.checkClanJoinCondition(requestor, activeChar, requestPacket.getPledgeType()))
      {
        JoinPledge jp = new JoinPledge(requestor.getClanId());
        activeChar.sendPacket(jp);
       
        activeChar.setPledgeType(requestPacket.getPledgeType());
       
        if (requestPacket.getPledgeType() == L2Clan.SUBUNIT_ACADEMY)
View Full Code Here

  }

  @Override
  protected void runImpl()
  {
    L2PcInstance activeChar = getClient().getActiveChar();

    if(activeChar == null)
      return;

    if(!(L2World.getInstance().findObject(_target) instanceof L2PcInstance))
    {
      activeChar.sendPacket(new SystemMessage(SystemMessageId.YOU_HAVE_INVITED_THE_WRONG_TARGET));
      return;
    }

    L2PcInstance target = (L2PcInstance) L2World.getInstance().findObject(_target);
    L2Clan clan = activeChar.getClan();

    if(!clan.checkClanJoinCondition(activeChar, target, _pledgeType))
      return;

    if(!activeChar.getRequest().setRequest(target, this))
      return;

    AskJoinPledge ap = new AskJoinPledge(activeChar.getObjectId(), activeChar.getClan().getName());
    target.sendPacket(ap);
  }
View Full Code Here

TOP

Related Classes of com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.