Kaynağa Gözat

BETA: Core-part for [DP9850].
* Patch by Nos, xban1x
* Reviewed by UnAfraid, Zoey76

xban1x 12 yıl önce
ebeveyn
işleme
a414835ce8

+ 4 - 0
L2J_Server_BETA/java/com/l2jserver/gameserver/GameServer.java

@@ -41,6 +41,7 @@ import com.l2jserver.gameserver.datatables.AdminTable;
 import com.l2jserver.gameserver.datatables.ArmorSetsData;
 import com.l2jserver.gameserver.datatables.AugmentationData;
 import com.l2jserver.gameserver.datatables.BuyListData;
+import com.l2jserver.gameserver.datatables.CategoryData;
 import com.l2jserver.gameserver.datatables.CharNameTable;
 import com.l2jserver.gameserver.datatables.CharSummonTable;
 import com.l2jserver.gameserver.datatables.CharTemplateTable;
@@ -211,6 +212,9 @@ public class GameServer
 		Announcements.getInstance();
 		GlobalVariablesManager.getInstance();
 		
+		printSection("Data");
+		CategoryData.getInstance();
+		
 		printSection("Skills");
 		EffectHandler.getInstance().executeScript();
 		EnchantGroupsData.getInstance();

+ 124 - 0
L2J_Server_BETA/java/com/l2jserver/gameserver/datatables/CategoryData.java

@@ -0,0 +1,124 @@
+/*
+ * Copyright (C) 2004-2013 L2J Server
+ * 
+ * This file is part of L2J Server.
+ * 
+ * L2J Server is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * L2J Server is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package com.l2jserver.gameserver.datatables;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+
+import com.l2jserver.gameserver.engines.DocumentParser;
+import com.l2jserver.gameserver.model.CategoryType;
+
+/**
+ * @author Nos, xban1x
+ */
+public final class CategoryData extends DocumentParser
+{
+	private static final Logger _log = Logger.getLogger(CategoryData.class.getName());
+	
+	private final Map<CategoryType, Set<Integer>> _categories = new HashMap<>();
+	
+	protected CategoryData()
+	{
+		load();
+	}
+	
+	@Override
+	public void load()
+	{
+		parseDatapackFile("data/categoryData.xml");
+		_log.info(getClass().getSimpleName() + ": Loaded " + _categories.size() + " Categories.");
+	}
+	
+	@Override
+	protected void parseDocument()
+	{
+		for (Node node = getCurrentDocument().getFirstChild(); node != null; node = node.getNextSibling())
+		{
+			if ("list".equalsIgnoreCase(node.getNodeName()))
+			{
+				for (Node list_node = node.getFirstChild(); list_node != null; list_node = list_node.getNextSibling())
+				{
+					if ("category".equalsIgnoreCase(list_node.getNodeName()))
+					{
+						final NamedNodeMap attrs = list_node.getAttributes();
+						final CategoryType categoryType = CategoryType.findByName(attrs.getNamedItem("name").getNodeValue());
+						if (categoryType == null)
+						{
+							_log.log(Level.WARNING, getClass().getSimpleName() + ": Can't find category by name :" + attrs.getNamedItem("name").getNodeValue());
+							continue;
+						}
+						
+						final Set<Integer> ids = new HashSet<>();
+						for (Node category_node = list_node.getFirstChild(); category_node != null; category_node = category_node.getNextSibling())
+						{
+							if ("id".equalsIgnoreCase(category_node.getNodeName()))
+							{
+								ids.add(Integer.parseInt(category_node.getTextContent()));
+							}
+						}
+						_categories.put(categoryType, ids);
+					}
+				}
+			}
+		}
+	}
+	
+	/**
+	 * Checks if id is in category.
+	 * @param type The category type.
+	 * @param id The id to be checked.
+	 * @return {@code true} if id is in category, {@code false} if id is not in category or category was not found.
+	 */
+	public boolean isInCategory(CategoryType type, int id)
+	{
+		final Set<Integer> category = getCategoryByType(type);
+		if (category == null)
+		{
+			_log.log(Level.WARNING, getClass().getSimpleName() + ": Can't find category type :" + type);
+			return false;
+		}
+		return category.contains(id);
+	}
+	
+	/**
+	 * @param type The category type
+	 * @return A {@code Set} containing all the ids in category if category is found, {@code null} if category was not found.
+	 */
+	public Set<Integer> getCategoryByType(CategoryType type)
+	{
+		return _categories.get(type);
+	}
+	
+	public static CategoryData getInstance()
+	{
+		return SingletonHolder._instance;
+	}
+	
+	private static class SingletonHolder
+	{
+		protected final static CategoryData _instance = new CategoryData();
+	}
+}

+ 167 - 0
L2J_Server_BETA/java/com/l2jserver/gameserver/model/CategoryType.java

@@ -0,0 +1,167 @@
+/*
+ * Copyright (C) 2004-2013 L2J Server
+ * 
+ * This file is part of L2J Server.
+ * 
+ * L2J Server is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * L2J Server is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package com.l2jserver.gameserver.model;
+
+/**
+ * @author xban1x
+ */
+public enum CategoryType
+{
+	FIGHTER_GROUP,
+	MAGE_GROUP,
+	WIZARD_GROUP,
+	CLERIC_GROUP,
+	ATTACKER_GROUP,
+	TANKER_GROUP,
+	FIRST_CLASS_GROUP,
+	SECOND_CLASS_GROUP,
+	THIRD_CLASS_GROUP,
+	FOURTH_CLASS_GROUP,
+	BOUNTY_HUNTER_GROUP,
+	WARSMITH_GROUP,
+	SUMMON_NPC_GROUP,
+	KNIGHT_GROUP,
+	WHITE_MAGIC_GROUP,
+	HEAL_GROUP,
+	ASSIST_MAGIC_GROUP,
+	WARRIOR_GROUP,
+	HUMAN_2ND_GROUP,
+	ELF_2ND_GROUP,
+	DELF_2ND_GROUP,
+	ORC_2ND_GROUP,
+	DWARF_2ND_GROUP,
+	STRIDER,
+	STRIDER_GROUP,
+	RED_STRIDER_GROUP,
+	WOLF_GROUP,
+	GROWN_UP_WOLF_GROUP,
+	HATCHLING_GROUP,
+	BABY_PET_GROUP,
+	UPGRADE_BABY_PET_GROUP,
+	WYVERN_GROUP,
+	ALL_WOLF_GROUP,
+	WOLF,
+	SIN_EATER_GROUP,
+	PET_GROUP,
+	ITEM_EQUIP_PET_GROUP,
+	SUBJOB_GROUP_DAGGER,
+	SUBJOB_GROUP_BOW,
+	SUBJOB_GROUP_KNIGHT,
+	SUBJOB_GROUP_SUMMONER,
+	SUBJOB_GROUP_HALF_HEALER,
+	SUBJOB_GROUP_DANCE,
+	SUBJOB_GROUP_WIZARD,
+	HUMAN_FALL_CLASS,
+	HUMAN_WALL_CLASS,
+	HUMAN_MALL_CLASS,
+	HUMAN_CALL_CLASS,
+	ELF_FALL_CLASS,
+	ELF_MALL_CLASS,
+	ELF_WALL_CLASS,
+	ELF_CALL_CLASS,
+	DELF_FALL_CLASS,
+	DELF_MALL_CLASS,
+	DELF_WALL_CLASS,
+	DELF_CALL_CLASS,
+	ORC_FALL_CLASS,
+	ORC_MALL_CLASS,
+	DWARF_ALL_CLASS,
+	DWARF_BOUNTY_CLASS,
+	DWARF_SMITH_CLASS,
+	KAMAEL_ALL_CLASS,
+	KAMAEL_FIRST_CLASS_GROUP,
+	KAMAEL_SECOND_CLASS_GROUP,
+	KAMAEL_THIRD_CLASS_GROUP,
+	KAMAEL_FOURTH_CLASS_GROUP,
+	BEGINNER_FIGHTER,
+	BEGINNER_MAGE,
+	KAMAEL_MALE_MAIN_OCCUPATION,
+	KAMAEL_FEMALE_MAIN_OCCUPATION,
+	ARCHER_GROUP,
+	SHIELD_MASTER,
+	BARD,
+	FORCE_MASTER,
+	WEAPON_MASTER,
+	BOW_MASTER,
+	DAGGER_MASTER,
+	HEAL_MASTER,
+	WIZARD_MASTER,
+	BUFF_MASTER,
+	SUMMON_MASTER,
+	WARRIOR_CLOACK,
+	ROGUE_CLOACK,
+	MAGE_CLOACK,
+	SHIELD_MASTER2_3,
+	BARD2_3,
+	FORCE_MASTER2_3,
+	WEAPON_MASTER2_3,
+	BOW_MASTER2_3,
+	DAGGER_MASTER2_3,
+	HEAL_MASTER2_3,
+	WIZARD_MASTER2_3,
+	BUFF_MASTER2_3,
+	SUMMON_MASTER2_3,
+	ATTRIBUTE_GROUP_SUMMONER,
+	SUB_GROUP_WARRIOR,
+	SUB_GROUP_ROGUE,
+	SUB_GROUP_KNIGHT,
+	SUB_GROUP_SUMMONER,
+	SUB_GROUP_WIZARD,
+	SUB_GROUP_HEALER,
+	SUB_GROUP_ENCHANTER,
+	SUB_GROUP_HEC,
+	SUB_GROUP_HEW,
+	SUB_GROUP_HEF,
+	SUB_GROUP_ORC,
+	SUB_GROUP_WARE,
+	SUB_GROUP_BLACK,
+	SUB_GROUP_DE,
+	SUB_GROUP_KAMAEL,
+	LIGHT_TANKER_GROUP,
+	DARK_TANKER_GROUP,
+	MELEE_ATTACKER,
+	RECOM_KNIGHT_GROUP,
+	RECOM_MAGIC_GROUP,
+	RECOM_WARRIOR_GROUP,
+	RECOM_ROGUE_GROUP,
+	RECOM_KAMAEL_GROUP,
+	RECOM_ORCF_GROUP,
+	RECOM_ORCM_GROUP,
+	DEINONYCHUS_PET_GROUP,
+	BEASTFARM_BEAST,
+	BEASTFARM_INVADER,
+	ICEQUEEN_NPC;
+	
+	/**
+	 * Finds category by it's name
+	 * @param categoryName
+	 * @return A {@code CategoryType} if category was found, {@code null} if category was not found
+	 */
+	public static final CategoryType findByName(String categoryName)
+	{
+		for (CategoryType type : values())
+		{
+			if (type.name().equalsIgnoreCase(categoryName))
+			{
+				return type;
+			}
+		}
+		return null;
+	}
+}