Guest User

Untitled

a guest
May 12th, 2018
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.83 KB | None | 0 0
  1. /*
  2.  * Copyright (C) 2004-2016 L2J DataPack
  3.  *
  4.  * This file is part of L2J DataPack.
  5.  *
  6.  * L2J DataPack is free software: you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation, either version 3 of the License, or
  9.  * (at your option) any later version.
  10.  *
  11.  * L2J DataPack is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14.  * General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18.  */
  19. package ai.npc.NpcBuffers;
  20.  
  21. import java.util.Collection;
  22. import java.util.HashMap;
  23. import java.util.Map;
  24. import java.util.Set;
  25.  
  26. import org.w3c.dom.Document;
  27. import org.w3c.dom.NamedNodeMap;
  28. import org.w3c.dom.Node;
  29.  
  30. import com.l2jserver.gameserver.model.StatsSet;
  31. import com.l2jserver.util.data.xml.IXmlReader;
  32.  
  33. /**
  34.  * NPC Buffers data.
  35.  * @author UnAfraid
  36.  */
  37. public class NpcBuffersData implements IXmlReader
  38. {
  39.     private final Map<Integer, NpcBufferData> _npcBuffers = new HashMap<>();
  40.    
  41.     protected NpcBuffersData()
  42.     {
  43.         load();
  44.     }
  45.    
  46.     @Override
  47.     public void load()
  48.     {
  49.         parseDatapackFile("data/scripts/ai/npc/NpcBuffers/NpcBuffersData.xml");
  50.         LOG.info("{}: Loaded: {} buffers data.", getClass().getSimpleName(), _npcBuffers.size());
  51.     }
  52.    
  53.     @Override
  54.     public void parseDocument(Document doc)
  55.     {
  56.         StatsSet set;
  57.         Node attr;
  58.         NamedNodeMap attrs;
  59.         for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
  60.         {
  61.             if ("list".equalsIgnoreCase(n.getNodeName()))
  62.             {
  63.                 for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
  64.                 {
  65.                     if ("npc".equalsIgnoreCase(d.getNodeName()))
  66.                     {
  67.                         attrs = d.getAttributes();
  68.                         final int npcId = parseInteger(attrs, "id");
  69.                         final NpcBufferData npc = new NpcBufferData(npcId);
  70.                         for (Node c = d.getFirstChild(); c != null; c = c.getNextSibling())
  71.                         {
  72.                             switch (c.getNodeName())
  73.                             {
  74.                                 case "skill":
  75.                                 {
  76.                                     attrs = c.getAttributes();
  77.                                     set = new StatsSet();
  78.                                     for (int i = 0; i < attrs.getLength(); i++)
  79.                                     {
  80.                                         attr = attrs.item(i);
  81.                                         set.set(attr.getNodeName(), attr.getNodeValue());
  82.                                     }
  83.                                     npc.addSkill(new NpcBufferSkillData(set));
  84.                                     break;
  85.                                 }
  86.                             }
  87.                         }
  88.                         _npcBuffers.put(npcId, npc);
  89.                     }
  90.                 }
  91.             }
  92.         }
  93.     }
  94.    
  95.     public NpcBufferData getNpcBuffer(int npcId)
  96.     {
  97.         return _npcBuffers.get(npcId);
  98.     }
  99.    
  100.     public Collection<NpcBufferData> getNpcBuffers()
  101.     {
  102.         return _npcBuffers.values();
  103.     }
  104.    
  105.     public Set<Integer> getNpcBufferIds()
  106.     {
  107.         return _npcBuffers.keySet();
  108.     }
  109. }
Add Comment
Please, Sign In to add comment