Advertisement
Nik

Item skills at Inventory

Nik
Sep 25th, 2011
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 4.11 KB | None | 0 0
  1. Index: java/com/l2jserver/gameserver/model/L2ItemInstance.java
  2. ===================================================================
  3. --- java/com/l2jserver/gameserver/model/L2ItemInstance.java (revision 4930)
  4. +++ java/com/l2jserver/gameserver/model/L2ItemInstance.java (working copy)
  5. @@ -45,6 +45,7 @@
  6.  import com.l2jserver.gameserver.network.serverpackets.SpawnItem;
  7.  import com.l2jserver.gameserver.network.serverpackets.StatusUpdate;
  8.  import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  9. +import com.l2jserver.gameserver.skills.SkillHolder;
  10.  import com.l2jserver.gameserver.skills.funcs.Func;
  11.  import com.l2jserver.gameserver.templates.item.L2Armor;
  12.  import com.l2jserver.gameserver.templates.item.L2EtcItem;
  13. @@ -322,10 +323,18 @@
  14.      */
  15.     public void setOwnerId(int owner_id)
  16.     {
  17. -       if (owner_id == _ownerId) return;
  18. +       if (owner_id == _ownerId)
  19. +           return;
  20.        
  21. +       removeSkillsFromOwner(); // Remove any inventory skills from the old owner.
  22. +      
  23.         _ownerId = owner_id;
  24.         _storedInDb = false;
  25. +      
  26. +       // Give any inventory skills to the new owner only if the item is in inventory
  27. +       // else the skills will be given when location is set to inventory.
  28. +       if (getLocation() == ItemLocation.INVENTORY)
  29. +           giveSkillsToOwner();
  30.     }
  31.    
  32.     /**
  33. @@ -347,7 +356,9 @@
  34.     }
  35.    
  36.     /**
  37. -    * Sets the location of the item.<BR><BR>
  38. +    * Sets the location of the item.<BR>
  39. +    * If the item has inventory skills, those skills will be either added to or removed from the owner,
  40. +    * depending on the new location (if its inventory, skills will be added, else removed).<BR>
  41.      * <U><I>Remark :</I></U> If loc and loc_data different from database, say datas not up-to-date
  42.      * @param loc : ItemLocation (enumeration)
  43.      * @param loc_data : int designating the slot where the item is stored or the village for freights
  44. @@ -356,6 +367,12 @@
  45.     {
  46.         if (loc == _loc && loc_data == _locData)
  47.             return;
  48. +      
  49. +       if (_loc == ItemLocation.INVENTORY) // Current loc
  50. +           removeSkillsFromOwner();
  51. +       else if (loc == ItemLocation.INVENTORY) // New loc
  52. +           giveSkillsToOwner();
  53. +      
  54.         _loc = loc;
  55.         _locData = loc_data;
  56.         _storedInDb = false;
  57. @@ -1951,4 +1968,32 @@
  58.        
  59.         return enchant;
  60.     }
  61. +  
  62. +   private void giveSkillsToOwner()
  63. +   {
  64. +       if (getItem().isInventorySkill() && getOwnerId() > 0)
  65. +       {
  66. +           L2PcInstance player = L2World.getInstance().getPlayer(getOwnerId());
  67. +          
  68. +           if (player != null)
  69. +           {
  70. +               for (SkillHolder sh : getItem().getSkills())
  71. +                   player.addSkill(sh.getSkill());
  72. +           }
  73. +       }
  74. +   }
  75. +  
  76. +   private void removeSkillsFromOwner()
  77. +   {
  78. +       if (getItem().isInventorySkill() && getOwnerId() > 0)
  79. +       {
  80. +           L2PcInstance player = L2World.getInstance().getPlayer(getOwnerId());
  81. +          
  82. +           if (player != null)
  83. +           {
  84. +               for (SkillHolder sh : getItem().getSkills())
  85. +                   player.removeSkill(sh.getSkill(), false, true);
  86. +           }
  87. +       }
  88. +   }
  89.  }
  90. Index: java/com/l2jserver/gameserver/templates/item/L2Item.java
  91. ===================================================================
  92. --- java/com/l2jserver/gameserver/templates/item/L2Item.java    (revision 4930)
  93. +++ java/com/l2jserver/gameserver/templates/item/L2Item.java    (working copy)
  94. @@ -184,6 +184,7 @@
  95.    
  96.     protected int _type1; // needed for item list (inventory)
  97.     protected int _type2; // different lists for armor, weapon, etc
  98. +   protected boolean _isInventorySkill;
  99.     protected Elementals[] _elementals = null;
  100.     protected FuncTemplate[] _funcTemplates;
  101.     protected EffectTemplate[] _effectTemplates;
  102. @@ -223,6 +224,7 @@
  103.         _depositable = set.getBool("is_depositable", true);
  104.         _questItem = set.getBool("is_questitem", false);
  105.         _freightable = set.getBool("is_freightable", false);
  106. +       _isInventorySkill = set.getBool("is_inventory_skill", false);
  107.        
  108.         //_immediate_effect - herb
  109.         _ex_immediate_effect = set.getInteger("ex_immediate_effect", 0) > 0;
  110. @@ -357,6 +359,15 @@
  111.     }
  112.    
  113.     /**
  114. +    * Returns if the item's skills are added while item is at the player's inventory.
  115. +    * @return boolean
  116. +    */
  117. +   public final boolean isInventorySkill()
  118. +   {
  119. +       return _isInventorySkill;
  120. +   }
  121. +  
  122. +   /**
  123.      * Returns the weight of the item
  124.      * @return int
  125.      */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement