Advertisement
Nik

WeaponType support for all characters.

Nik
Jul 27th, 2012
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 7.85 KB | None | 0 0
  1. Index: java/com/l2jserver/gameserver/datatables/NpcTable.java
  2. ===================================================================
  3. --- java/com/l2jserver/gameserver/datatables/NpcTable.java  (revision 5522)
  4. +++ java/com/l2jserver/gameserver/datatables/NpcTable.java  (working copy)
  5. @@ -146,6 +146,7 @@
  6.         npcDat.set("baseMAtkSpd", NpcData.getInt("matkspd"));
  7.         npcDat.set("rhand", NpcData.getInt("rhand"));
  8.         npcDat.set("lhand", NpcData.getInt("lhand"));
  9. +       npcDat.set("baseAttackType", NpcData.getString("baseAttackType"));
  10.         npcDat.set("enchant", NpcData.getInt("enchant"));
  11.         npcDat.set("baseWalkSpd", NpcData.getInt("walkspd"));
  12.         npcDat.set("baseRunSpd", NpcData.getInt("runspd"));
  13. Index: java/com/l2jserver/gameserver/model/conditions/ConditionUsingItemType.java
  14. ===================================================================
  15. --- java/com/l2jserver/gameserver/model/conditions/ConditionUsingItemType.java  (revision 5528)
  16. +++ java/com/l2jserver/gameserver/model/conditions/ConditionUsingItemType.java  (working copy)
  17. @@ -41,16 +41,14 @@
  18.    
  19.     @Override
  20.     public boolean testImpl(Env env)
  21. -   {
  22. -       if (env.getCharacter() == null || !env.getCharacter().isPlayer())
  23. -       {
  24. +   {  
  25. +       if (env.getCharacter() == null)
  26.             return false;
  27. -       }
  28.        
  29. -       final Inventory inv = env.getPlayer().getInventory();
  30.         // If ConditionUsingItemType is one between Light, Heavy or Magic
  31. -       if (_armor)
  32. +       if (_armor && env.getCharacter().isPlayer())
  33.         {
  34. +           final Inventory inv = env.getPlayer().getInventory();
  35.             // Get the itemMask of the weared chest (if exists)
  36.             L2ItemInstance chest = inv.getPaperdollItem(Inventory.PAPERDOLL_CHEST);
  37.             if (chest == null)
  38. @@ -83,6 +81,7 @@
  39.             // return true if legs armor matches too
  40.             return (_mask & legMask) != 0;
  41.         }
  42. -       return (_mask & inv.getWearedMask()) != 0;
  43. +      
  44. +       return (_mask & env.getCharacter().getWeaponType().mask()) != 0;
  45.     }
  46.  }
  47. Index: java/com/l2jserver/gameserver/model/actor/templates/L2NpcTemplate.java
  48. ===================================================================
  49. --- java/com/l2jserver/gameserver/model/actor/templates/L2NpcTemplate.java  (revision 5522)
  50. +++ java/com/l2jserver/gameserver/model/actor/templates/L2NpcTemplate.java  (working copy)
  51. @@ -19,6 +19,7 @@
  52.  import java.util.List;
  53.  import java.util.Map;
  54.  import java.util.Map.Entry;
  55. +import java.util.logging.Level;
  56.  import java.util.logging.Logger;
  57.  
  58.  import javolution.util.FastMap;
  59. @@ -31,6 +32,7 @@
  60.  import com.l2jserver.gameserver.model.StatsSet;
  61.  import com.l2jserver.gameserver.model.actor.instance.L2XmassTreeInstance;
  62.  import com.l2jserver.gameserver.model.base.ClassId;
  63. +import com.l2jserver.gameserver.model.items.type.L2WeaponType;
  64.  import com.l2jserver.gameserver.model.quest.Quest;
  65.  import com.l2jserver.gameserver.model.quest.Quest.QuestEventType;
  66.  import com.l2jserver.gameserver.model.skills.L2Skill;
  67. @@ -55,6 +57,7 @@
  68.     private final int _rewardSp;
  69.     private final int _rHand;
  70.     private final int _lHand;
  71. +   private L2WeaponType _baseAttackType;
  72.     private final int _enchantEffect;
  73.    
  74.     private Race _race;
  75. @@ -216,6 +219,15 @@
  76.         _rewardSp = set.getInteger("rewardSp");
  77.         _rHand = set.getInteger("rhand");
  78.         _lHand = set.getInteger("lhand");
  79. +       try
  80. +       {
  81. +           _baseAttackType = L2WeaponType.valueOf(set.getString("baseAttackType"));
  82. +       }
  83. +       catch (IllegalArgumentException iae)
  84. +       {
  85. +           _baseAttackType = L2WeaponType.NONE;
  86. +           _log.log(Level.WARNING, "Invalid baseAttackType for npcId: " + _npcId, iae);
  87. +       }
  88.         _enchantEffect = set.getInteger("enchant");
  89.         _race = null;
  90.         final int herbGroup = set.getInteger("dropHerbGroup");
  91. @@ -632,6 +644,14 @@
  92.     }
  93.    
  94.     /**
  95. +    * @return the weapon type this NPC is using.
  96. +    */
  97. +   public L2WeaponType getBaseAttackType()
  98. +   {
  99. +       return _baseAttackType;
  100. +   }
  101. +  
  102. +   /**
  103.      * @return the enchant effect.
  104.      */
  105.     public int getEnchantEffect()
  106. Index: java/com/l2jserver/gameserver/model/actor/L2Character.java
  107. ===================================================================
  108. --- java/com/l2jserver/gameserver/model/actor/L2Character.java  (revision 5522)
  109. +++ java/com/l2jserver/gameserver/model/actor/L2Character.java  (working copy)
  110. @@ -41,6 +41,7 @@
  111.  import com.l2jserver.gameserver.ai.L2CharacterAI;
  112.  import com.l2jserver.gameserver.datatables.DoorTable;
  113.  import com.l2jserver.gameserver.datatables.ItemTable;
  114. +import com.l2jserver.gameserver.datatables.NpcTable;
  115.  import com.l2jserver.gameserver.datatables.SkillTable;
  116.  import com.l2jserver.gameserver.handler.ISkillHandler;
  117.  import com.l2jserver.gameserver.handler.SkillHandler;
  118. @@ -186,6 +187,7 @@
  119.     private double _hpUpdateIncCheck = .0;
  120.     private double _hpUpdateDecCheck = .0;
  121.     private double _hpUpdateInterval = .0;
  122. +   private L2WeaponType _weaponType = null; // If this is null, it will be initialized when getWeaponType() is called.
  123.    
  124.     /** Table of Calculators containing all used calculator */
  125.     private Calculator[] _calculators;
  126. @@ -5388,6 +5390,58 @@
  127.         // Dummy method (overridden by players and pets)
  128.     }
  129.    
  130. +   public L2WeaponType getWeaponType()
  131. +   {
  132. +       if (_weaponType == null)
  133. +       {
  134. +           synchronized (this)
  135. +           {
  136. +               if (_weaponType == null)
  137. +                   setWeaponType();
  138. +           }
  139. +       }
  140. +      
  141. +       return _weaponType;
  142. +   }
  143. +  
  144. +   /**
  145. +    * Sets the weapon type to the default weapon type of this character.
  146. +    */
  147. +   public void setWeaponType()
  148. +   {
  149. +       if (isPlayer())
  150. +           _weaponType = getActingPlayer().getActiveWeaponItem().getItemType();
  151. +       else if (isNpc())
  152. +       {
  153. +           L2NpcTemplate tmpl = NpcTable.getInstance().getTemplate(((L2Npc)this).getNpcId());
  154. +           if (tmpl != null)
  155. +               _weaponType = tmpl.getBaseAttackType();
  156. +       }
  157. +       else if (isSummon())
  158. +       {
  159. +           L2NpcTemplate tmpl = NpcTable.getInstance().getTemplate(((L2Summon)this).getNpcId());
  160. +           if (tmpl != null)
  161. +               _weaponType = tmpl.getBaseAttackType();
  162. +       }
  163. +      
  164. +       // If the weapon type is still somehow null.
  165. +       if (_weaponType == null)
  166. +           _weaponType = L2WeaponType.NONE;
  167. +   }
  168. +  
  169. +   public void setWeaponType(L2WeaponType weaponType)
  170. +   {
  171. +       _weaponType = weaponType;
  172. +   }
  173. +  
  174. +   public void setWeaponType(L2ItemInstance item)
  175. +   {
  176. +       if (item != null && item.isWeapon())
  177. +           _weaponType = (L2WeaponType)item.getItemType();
  178. +       else
  179. +           _weaponType = null;
  180. +   }
  181. +  
  182.     /**
  183.      * <B><U> Overridden in </U> :</B><BR><BR>
  184.      * <li> L2PcInstance</li><BR><BR>
  185. Index: java/com/l2jserver/gameserver/model/itemcontainer/Inventory.java
  186. ===================================================================
  187. --- java/com/l2jserver/gameserver/model/itemcontainer/Inventory.java    (revision 5522)
  188. +++ java/com/l2jserver/gameserver/model/itemcontainer/Inventory.java    (working copy)
  189. @@ -152,11 +152,11 @@
  190.         }
  191.     }
  192.    
  193. -   private static final class BowCrossRodListener implements PaperdollListener
  194. +   private static final class WeaponListener implements PaperdollListener
  195.     {
  196. -       private static BowCrossRodListener instance = new BowCrossRodListener();
  197. +       private static WeaponListener instance = new WeaponListener();
  198.        
  199. -       public static BowCrossRodListener getInstance()
  200. +       public static WeaponListener getInstance()
  201.         {
  202.             return instance;
  203.         }
  204. @@ -188,6 +188,9 @@
  205.                 if (lure != null)
  206.                     inventory.setPaperdollItem(PAPERDOLL_LHAND, null);
  207.             }
  208. +          
  209. +           // Reset the weapon type to the default weapon type.
  210. +           inventory.getOwner().setWeaponType();
  211.         }
  212.        
  213.         @Override
  214. @@ -210,6 +213,9 @@
  215.                 if (bolts != null)
  216.                     inventory.setPaperdollItem(PAPERDOLL_LHAND, bolts);
  217.             }
  218. +          
  219. +           // Update the weapon type the owner is wearing.
  220. +           inventory.getOwner().setWeaponType(item);
  221.         }
  222.     }
  223.    
  224. @@ -729,7 +735,7 @@
  225.         if (this instanceof PcInventory)
  226.         {
  227.             addPaperdollListener(ArmorSetListener.getInstance());
  228. -           addPaperdollListener(BowCrossRodListener.getInstance());
  229. +           addPaperdollListener(WeaponListener.getInstance());
  230.             addPaperdollListener(ItemSkillsListener.getInstance());
  231.             addPaperdollListener(BraceletListener.getInstance());
  232.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement