Skip to content

Instantly share code, notes, and snippets.

@Battlecruiser
Created March 22, 2015 10:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Battlecruiser/7df27199397e96d9688f to your computer and use it in GitHub Desktop.
Save Battlecruiser/7df27199397e96d9688f to your computer and use it in GitHub Desktop.
Droplist converter
/*
* Copyright (C) 2004-2014 L2J DataPack
*
* This file is part of L2J DataPack.
*
* L2J DataPack 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 DataPack 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 convertor;
import java.io.File;
import java.util.ArrayList;
import com.l2jserver.Config;
import com.l2jserver.gameserver.data.xml.impl.NpcData;
import com.l2jserver.gameserver.model.actor.templates.L2NpcTemplate;
import com.l2jserver.gameserver.model.drops.DropListScope;
import com.l2jserver.gameserver.model.drops.GeneralDropItem;
import com.l2jserver.gameserver.model.drops.GroupedGeneralDropItem;
import com.l2jserver.gameserver.model.drops.IDropItem;
/**
* @author venca
*/
public class DropList
{
private void printInsert(int mobId, int itemId, long min, long max, int category, int chance)
{
System.out.println("INSERT INTO droplist VALUES(" + mobId + ", " + itemId + ", " + min + ", " + max + ", " + category + ", " + chance + ");");
}
/**
*
*/
public DropList()
{
Config.LEGACY_DROP_TABLES = new ArrayList<>();
Config.XML_DROP_TABLE = true;
Config.XML_DROP_HERBS = false;
Config.DATAPACK_ROOT = new File("dist/game/");
Config.ALT_DEV_NO_HANDLERS = true;
Config.ALT_DEV_NO_SPAWNS = true;
Config.ALT_DEV_NO_QUESTS = true;
System.out.println("DROP TABLE IF EXISTS `droplist`; \n" + "CREATE TABLE `droplist` (\n" + " `mobId` int(11) unsigned NOT NULL,\n" + " `itemId` int(11) unsigned NOT NULL,\n" + " `min` int(8) unsigned NOT NULL DEFAULT '0',\n" + " `max` int(8) unsigned NOT NULL DEFAULT '0',\n" + " `category` smallint(3) NOT NULL DEFAULT '0',\n" + " `chance` decimal(30,15) unsigned NOT NULL,\n" + " PRIMARY KEY (`mobId`,`itemId`,`category`),\n" + " KEY `key_mobId` (`mobId`)\n" + ") ENGINE=MyISAM DEFAULT CHARSET=UTF8;");
for (L2NpcTemplate template : NpcData.getInstance().getTemplates(t -> true))
{
try
{
for (IDropItem item : template.getDropList(DropListScope.CORPSE))
{
if (item instanceof GeneralDropItem)
{
printInsert(template.getId(), ((GeneralDropItem) item).getItemId(), ((GeneralDropItem) item).getMin(), ((GeneralDropItem) item).getMax(), -1, (int) ((((GeneralDropItem) item).getChance() * IDropItem.MAX_CHANCE) / 100));
}
else if (item instanceof GroupedGeneralDropItem)
{
for (GeneralDropItem dropItem : ((GroupedGeneralDropItem) item).getItems())
{
printInsert(template.getId(), dropItem.getItemId(), dropItem.getMin(), dropItem.getMax(), -1, (int) ((((GroupedGeneralDropItem) item).getChance() * dropItem.getChance() * IDropItem.MAX_CHANCE) / (100 * 100)));
}
}
else
{
throw new ClassCastException("Unknown IDropItem implementation at NPC id: " + template.getId());
}
}
int category = 0;
for (IDropItem item : template.getDropList(DropListScope.DEATH))
{
if (item instanceof GeneralDropItem)
{
printInsert(template.getId(), ((GeneralDropItem) item).getItemId(), ((GeneralDropItem) item).getMin(), ((GeneralDropItem) item).getMax(), category, (((int) ((GeneralDropItem) item).getChance() * IDropItem.MAX_CHANCE) / 100));
}
else if (item instanceof GroupedGeneralDropItem)
{
for (GeneralDropItem dropItem : ((GroupedGeneralDropItem) item).getItems())
{
printInsert(template.getId(), dropItem.getItemId(), dropItem.getMin(), dropItem.getMax(), category, (int) ((((GroupedGeneralDropItem) item).getChance() * dropItem.getChance() * IDropItem.MAX_CHANCE) / (100 * 100)));
}
}
else
{
throw new ClassCastException("Unknown IDropItem implementation at NPC id: " + template.getId());
}
category++;
}
}
catch (NullPointerException e)
{
// empty droplist
}
}
}
public static void main(String[] args)
{
new DropList();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment