Combination item rework.

Adapted from: L2jUnity free files.
This commit is contained in:
MobiusDev
2018-02-17 14:58:09 +00:00
parent fab58a3d3d
commit c459395968
126 changed files with 14210 additions and 2012 deletions

View File

@@ -21,12 +21,15 @@ import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.nio.ByteBuffer;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.time.DayOfWeek;
import java.time.LocalDateTime;
import java.time.temporal.TemporalAdjusters;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.StringJoiner;
import java.util.StringTokenizer;
@@ -573,4 +576,15 @@ public final class CommonUtil
}
return sj.toString();
}
/**
* @param val
* @param format
* @return
*/
public static String formatDouble(double val, String format)
{
final DecimalFormat formatter = new DecimalFormat(format, new DecimalFormatSymbols(Locale.ENGLISH));
return formatter.format(val);
}
}

View File

@@ -50,6 +50,7 @@ import com.l2jmobius.gameserver.data.xml.impl.CategoryData;
import com.l2jmobius.gameserver.data.xml.impl.ClanHallData;
import com.l2jmobius.gameserver.data.xml.impl.ClanRewardData;
import com.l2jmobius.gameserver.data.xml.impl.ClassListData;
import com.l2jmobius.gameserver.data.xml.impl.CombinationItemsData;
import com.l2jmobius.gameserver.data.xml.impl.CubicData;
import com.l2jmobius.gameserver.data.xml.impl.DoorData;
import com.l2jmobius.gameserver.data.xml.impl.EnchantItemData;
@@ -203,6 +204,7 @@ public class GameServer
CategoryData.getInstance();
SecondaryAuthData.getInstance();
AbilityPointsData.getInstance();
CombinationItemsData.getInstance();
SayuneData.getInstance();
ClanRewardData.getInstance();

View File

@@ -0,0 +1,111 @@
/*
* This file is part of the L2J Mobius project.
*
* This program 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.
*
* This program 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.l2jmobius.gameserver.data.xml.impl;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import org.w3c.dom.Document;
import com.l2jmobius.commons.util.IGameXmlReader;
import com.l2jmobius.gameserver.datatables.ItemTable;
import com.l2jmobius.gameserver.model.StatsSet;
import com.l2jmobius.gameserver.model.items.combination.CombinationItem;
import com.l2jmobius.gameserver.model.items.combination.CombinationItemReward;
import com.l2jmobius.gameserver.model.items.combination.CombinationItemType;
/**
* @author UnAfraid
*/
public class CombinationItemsData implements IGameXmlReader
{
private static final Logger LOGGER = Logger.getLogger(CombinationItemsData.class.getName());
private final List<CombinationItem> _items = new ArrayList<>();
protected CombinationItemsData()
{
load();
}
@Override
public synchronized void load()
{
_items.clear();
parseDatapackFile("data/CombinationItems.xml");
LOGGER.info(getClass().getSimpleName() + ": Loaded " + _items.size() + " combinations.");
}
@Override
public void parseDocument(Document doc, File f)
{
forEach(doc, "list", listNode -> forEach(listNode, "item", itemNode ->
{
final CombinationItem item = new CombinationItem(new StatsSet(parseAttributes(itemNode)));
forEach(itemNode, "reward", rewardNode ->
{
final int id = parseInteger(rewardNode.getAttributes(), "id");
final int count = parseInteger(rewardNode.getAttributes(), "count", 1);
final CombinationItemType type = parseEnum(rewardNode.getAttributes(), CombinationItemType.class, "type");
item.addReward(new CombinationItemReward(id, count, type));
if (ItemTable.getInstance().getTemplate(id) == null)
{
LOGGER.info(getClass().getSimpleName() + ": Could not find item with id " + id);
}
});
_items.add(item);
}));
}
public int getLoadedElementsCount()
{
return _items.size();
}
public List<CombinationItem> getItems()
{
return _items;
}
public CombinationItem getItemsBySlots(int firstSlot, int secondSlot)
{
return _items.stream().filter(item -> (item.getItemOne() == firstSlot) && (item.getItemTwo() == secondSlot)).findFirst().orElse(null);
}
public List<CombinationItem> getItemsByFirstSlot(int id)
{
return _items.stream().filter(item -> item.getItemOne() == id).collect(Collectors.toList());
}
public List<CombinationItem> getItemsBySecondSlot(int id)
{
return _items.stream().filter(item -> item.getItemTwo() == id).collect(Collectors.toList());
}
public static final CombinationItemsData getInstance()
{
return SingletonHolder.INSTANCE;
}
private static class SingletonHolder
{
protected static final CombinationItemsData INSTANCE = new CombinationItemsData();
}
}

View File

@@ -170,8 +170,6 @@ public abstract class L2Item extends ListenersContainer implements IIdentifiable
private int _sharedReuseGroup;
private CommissionItemType _commissionItemType;
private int _compoundItem;
private float _compoundChance;
private boolean _isAppearanceable;
private boolean _isBlessed;
@@ -230,8 +228,6 @@ public abstract class L2Item extends ListenersContainer implements IIdentifiable
_reuseDelay = set.getInt("reuse_delay", 0);
_sharedReuseGroup = set.getInt("shared_reuse_group", 0);
_commissionItemType = set.getEnum("commissionItemType", CommissionItemType.class, CommissionItemType.OTHER_ITEM);
_compoundItem = set.getInt("compoundItem", 0);
_compoundChance = set.getFloat("compoundChance", 0);
_common = ((_itemId >= 11605) && (_itemId <= 12361));
_heroItem = ((_itemId >= 6611) && (_itemId <= 6621)) || ((_itemId >= 9388) && (_itemId <= 9390)) || (_itemId == 6842);
_pvpItem = ((_itemId >= 10667) && (_itemId <= 10835)) || ((_itemId >= 12852) && (_itemId <= 12977)) || ((_itemId >= 14363) && (_itemId <= 14525)) || (_itemId == 14528) || (_itemId == 14529) || (_itemId == 14558) || ((_itemId >= 15913) && (_itemId <= 16024)) || ((_itemId >= 16134) && (_itemId <= 16147)) || (_itemId == 16149) || (_itemId == 16151) || (_itemId == 16153) || (_itemId == 16155) || (_itemId == 16157) || (_itemId == 16159) || ((_itemId >= 16168) && (_itemId <= 16176)) || ((_itemId >= 16179) && (_itemId <= 16220));
@@ -961,16 +957,6 @@ public abstract class L2Item extends ListenersContainer implements IIdentifiable
return _commissionItemType;
}
public int getCompoundItem()
{
return _compoundItem;
}
public float getCompoundChance()
{
return _compoundChance;
}
/**
* Usable in HTML windows.
* @return the icon link in client files

View File

@@ -0,0 +1,65 @@
/*
* This file is part of the L2J Mobius project.
*
* This program 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.
*
* This program 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.l2jmobius.gameserver.model.items.combination;
import java.util.EnumMap;
import java.util.Map;
import com.l2jmobius.gameserver.model.StatsSet;
/**
* @author UnAfraid
*/
public class CombinationItem
{
private final int _itemOne;
private final int _itemTwo;
private final int _chance;
private final Map<CombinationItemType, CombinationItemReward> _rewards = new EnumMap<>(CombinationItemType.class);
public CombinationItem(StatsSet set)
{
_itemOne = set.getInt("one");
_itemTwo = set.getInt("two");
_chance = set.getInt("chance");
}
public int getItemOne()
{
return _itemOne;
}
public int getItemTwo()
{
return _itemTwo;
}
public int getChance()
{
return _chance;
}
public void addReward(CombinationItemReward item)
{
_rewards.put(item.getType(), item);
}
public CombinationItemReward getReward(CombinationItemType type)
{
return _rewards.get(type);
}
}

View File

@@ -0,0 +1,38 @@
/*
* This file is part of the L2J Mobius project.
*
* This program 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.
*
* This program 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.l2jmobius.gameserver.model.items.combination;
import com.l2jmobius.gameserver.model.holders.ItemHolder;
/**
* @author UnAfraid
*/
public class CombinationItemReward extends ItemHolder
{
private final CombinationItemType _type;
public CombinationItemReward(int id, int count, CombinationItemType type)
{
super(id, count);
_type = type;
}
public CombinationItemType getType()
{
return _type;
}
}

View File

@@ -0,0 +1,26 @@
/*
* This file is part of the L2J Mobius project.
*
* This program 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.
*
* This program 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.l2jmobius.gameserver.model.items.combination;
/**
* @author UnAfraid
*/
public enum CombinationItemType
{
ON_SUCCESS,
ON_FAILURE;
}

View File

@@ -16,9 +16,13 @@
*/
package com.l2jmobius.gameserver.network.clientpackets.compound;
import java.util.List;
import com.l2jmobius.commons.network.PacketReader;
import com.l2jmobius.gameserver.data.xml.impl.CombinationItemsData;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.model.actor.request.CompoundRequest;
import com.l2jmobius.gameserver.model.items.combination.CombinationItem;
import com.l2jmobius.gameserver.model.items.instance.L2ItemInstance;
import com.l2jmobius.gameserver.network.L2GameClient;
import com.l2jmobius.gameserver.network.SystemMessageId;
@@ -78,8 +82,10 @@ public class RequestNewEnchantPushOne implements IClientIncomingPacket
return;
}
final List<CombinationItem> combinationItems = CombinationItemsData.getInstance().getItemsByFirstSlot(itemOne.getId());
// Not implemented or not able to merge!
if ((itemOne.getItem().getCompoundItem() == 0) || (itemOne.getItem().getCompoundChance() == 0))
if (combinationItems.isEmpty())
{
client.sendPacket(ExEnchantOneFail.STATIC_PACKET);
activeChar.removeRequest(request.getClass());

View File

@@ -17,8 +17,10 @@
package com.l2jmobius.gameserver.network.clientpackets.compound;
import com.l2jmobius.commons.network.PacketReader;
import com.l2jmobius.gameserver.data.xml.impl.CombinationItemsData;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.model.actor.request.CompoundRequest;
import com.l2jmobius.gameserver.model.items.combination.CombinationItem;
import com.l2jmobius.gameserver.model.items.instance.L2ItemInstance;
import com.l2jmobius.gameserver.network.L2GameClient;
import com.l2jmobius.gameserver.network.SystemMessageId;
@@ -86,15 +88,10 @@ public class RequestNewEnchantPushTwo implements IClientIncomingPacket
return;
}
// Combining only same items!
if (itemOne.getItem().getId() != itemTwo.getItem().getId())
{
client.sendPacket(ExEnchantTwoFail.STATIC_PACKET);
return;
}
final CombinationItem combinationItem = CombinationItemsData.getInstance().getItemsBySlots(itemOne.getId(), itemTwo.getId());
// Not implemented or not able to merge!
if ((itemOne.getItem().getCompoundItem() == 0) || (itemOne.getItem().getCompoundChance() == 0))
if (combinationItem == null)
{
client.sendPacket(ExEnchantTwoFail.STATIC_PACKET);
return;

View File

@@ -18,8 +18,12 @@ package com.l2jmobius.gameserver.network.clientpackets.compound;
import com.l2jmobius.commons.network.PacketReader;
import com.l2jmobius.commons.util.Rnd;
import com.l2jmobius.gameserver.data.xml.impl.CombinationItemsData;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.model.actor.request.CompoundRequest;
import com.l2jmobius.gameserver.model.items.combination.CombinationItem;
import com.l2jmobius.gameserver.model.items.combination.CombinationItemReward;
import com.l2jmobius.gameserver.model.items.combination.CombinationItemType;
import com.l2jmobius.gameserver.model.items.instance.L2ItemInstance;
import com.l2jmobius.gameserver.network.L2GameClient;
import com.l2jmobius.gameserver.network.SystemMessageId;
@@ -82,50 +86,39 @@ public class RequestNewEnchantTry implements IClientIncomingPacket
// Lets prevent using same item twice
if (itemOne.getObjectId() == itemTwo.getObjectId())
{
client.sendPacket(new ExEnchantFail(itemOne.getItem().getId(), itemTwo.getItem().getId()));
client.sendPacket(new ExEnchantFail(itemOne.getId(), itemTwo.getId()));
activeChar.removeRequest(request.getClass());
return;
}
// Combining only same items!
if (itemOne.getItem().getId() != itemTwo.getItem().getId())
{
client.sendPacket(new ExEnchantFail(itemOne.getItem().getId(), itemTwo.getItem().getId()));
activeChar.removeRequest(request.getClass());
return;
}
final CombinationItem combinationItem = CombinationItemsData.getInstance().getItemsBySlots(itemOne.getId(), itemTwo.getId());
// Not implemented or not able to merge!
if ((itemOne.getItem().getCompoundItem() == 0) || (itemOne.getItem().getCompoundChance() == 0))
if (combinationItem == null)
{
client.sendPacket(new ExEnchantFail(itemOne.getItem().getId(), itemTwo.getItem().getId()));
client.sendPacket(new ExEnchantFail(itemOne.getId(), itemTwo.getId()));
activeChar.removeRequest(request.getClass());
return;
}
final InventoryUpdate iu = new InventoryUpdate();
final double random = Rnd.nextDouble() * 100;
iu.addRemovedItem(itemOne);
iu.addRemovedItem(itemTwo);
// Success
if (random < itemOne.getItem().getCompoundChance())
if (activeChar.destroyItem("Compound-Item-One", itemOne, 1, null, true) && activeChar.destroyItem("Compound-Item-Two", itemTwo, 1, null, true))
{
iu.addRemovedItem(itemOne);
iu.addRemovedItem(itemTwo);
final double random = (Rnd.nextDouble() * 100);
final boolean success = random <= combinationItem.getChance();
final CombinationItemReward rewardItem = combinationItem.getReward(success ? CombinationItemType.ON_SUCCESS : CombinationItemType.ON_FAILURE);
final L2ItemInstance item = activeChar.addItem("Compound-Result", rewardItem.getId(), rewardItem.getCount(), null, true);
if (activeChar.destroyItem("Compound-Item-One", itemOne, null, true) && activeChar.destroyItem("Compound-Item-Two", itemTwo, null, true))
if (success)
{
final L2ItemInstance item = activeChar.addItem("Compound-Result", itemOne.getItem().getCompoundItem(), 1, null, true);
client.sendPacket(new ExEnchantSucess(item.getItem().getId()));
client.sendPacket(new ExEnchantSucess(item.getId()));
}
}
else
{
iu.addRemovedItem(itemTwo);
// Upon fail we destroy the second item.
if (activeChar.destroyItem("Compound-Item-Two-Fail", itemTwo, null, true))
else
{
client.sendPacket(new ExEnchantFail(itemOne.getItem().getId(), itemTwo.getItem().getId()));
client.sendPacket(new ExEnchantFail(itemOne.getId(), itemTwo.getId()));
}
}