Addition of upgrade equipment system.

This commit is contained in:
MobiusDevelopment
2019-06-20 00:49:47 +00:00
parent 712e10dc92
commit fc2c52f965
27 changed files with 4823 additions and 15654 deletions

View File

@@ -98,6 +98,7 @@ import org.l2jmobius.gameserver.data.xml.impl.SpawnsData;
import org.l2jmobius.gameserver.data.xml.impl.StaticObjectData;
import org.l2jmobius.gameserver.data.xml.impl.TeleportersData;
import org.l2jmobius.gameserver.data.xml.impl.TransformData;
import org.l2jmobius.gameserver.data.xml.impl.UpgradeEquipmentData;
import org.l2jmobius.gameserver.data.xml.impl.VariationData;
import org.l2jmobius.gameserver.datatables.BotReportTable;
import org.l2jmobius.gameserver.datatables.EventDroplist;
@@ -262,6 +263,7 @@ public class GameServer
EnchantItemHPBonusData.getInstance();
BuyListData.getInstance();
MultisellData.getInstance();
UpgradeEquipmentData.getInstance();
RecipeData.getInstance();
ArmorSetsData.getInstance();
FishingData.getInstance();

View File

@@ -0,0 +1,112 @@
/*
* 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 org.l2jmobius.gameserver.data.xml.impl;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import org.w3c.dom.Document;
import org.l2jmobius.commons.util.IXmlReader;
import org.l2jmobius.gameserver.datatables.ItemTable;
import org.l2jmobius.gameserver.model.StatsSet;
import org.l2jmobius.gameserver.model.holders.ItemHolder;
import org.l2jmobius.gameserver.model.holders.UpgradeEquipmentHolder;
/**
* @author Mobius
*/
public class UpgradeEquipmentData implements IXmlReader
{
private static Logger LOGGER = Logger.getLogger(UpgradeEquipmentData.class.getName());
private static final Map<Integer, UpgradeEquipmentHolder> _upgrades = new HashMap<>();
protected UpgradeEquipmentData()
{
load();
}
@Override
public void load()
{
_upgrades.clear();
parseDatapackFile("data/UpgradeEquipmentData.xml");
LOGGER.info(getClass().getSimpleName() + ": Loaded " + _upgrades.size() + " upgrade equipment data.");
}
@Override
public void parseDocument(Document doc, File f)
{
forEach(doc, "list", listNode -> forEach(listNode, "upgrade", upgradeNode ->
{
final StatsSet set = new StatsSet(parseAttributes(upgradeNode));
final int id = set.getInt("id");
final String[] item = set.getString("item").split(",");
final int requiredItemId = Integer.parseInt(item[0]);
final int requiredItemEnchant = Integer.parseInt(item[1]);
final String materials = set.getString("materials");
final List<ItemHolder> materialList = new ArrayList<>();
if (!materials.isEmpty())
{
for (String mat : materials.split(";"))
{
final String[] matValues = mat.split(",");
final int matItemId = Integer.parseInt(matValues[0]);
if (ItemTable.getInstance().getTemplate(matItemId) == null)
{
LOGGER.info(getClass().getSimpleName() + ": Material item with id " + matItemId + " does not exist.");
}
else
{
materialList.add(new ItemHolder(matItemId, Long.parseLong(matValues[1])));
}
}
}
final long adena = set.getLong("adena", 0);
final String[] resultItem = set.getString("result").split(",");
final int resultItemId = Integer.parseInt(resultItem[0]);
final int resultItemEnchant = Integer.parseInt(resultItem[1]);
if (ItemTable.getInstance().getTemplate(requiredItemId) == null)
{
LOGGER.info(getClass().getSimpleName() + ": Required item with id " + requiredItemId + " does not exist.");
}
else
{
_upgrades.put(id, new UpgradeEquipmentHolder(id, requiredItemId, requiredItemEnchant, materialList, adena, resultItemId, resultItemEnchant));
}
}));
}
public UpgradeEquipmentHolder getUpgrade(int id)
{
return _upgrades.get(id);
}
public static UpgradeEquipmentData getInstance()
{
return SingletonHolder.INSTANCE;
}
private static class SingletonHolder
{
protected static final UpgradeEquipmentData INSTANCE = new UpgradeEquipmentData();
}
}

View File

@@ -0,0 +1,79 @@
/*
* 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 org.l2jmobius.gameserver.model.holders;
import java.util.List;
/**
* @author Mobius
*/
public class UpgradeEquipmentHolder
{
private final int _id;
private final int _requiredItemId;
private final int _requiredItemEnchant;
private final List<ItemHolder> _materials;
private final long _adena;
private final int _resultItemId;
private final int _resultItemEnchant;
public UpgradeEquipmentHolder(int id, int requiredItemId, int requiredItemEnchant, List<ItemHolder> materials, long adena, int resultItemId, int resultItemEnchant)
{
_id = id;
_requiredItemId = requiredItemId;
_requiredItemEnchant = requiredItemEnchant;
_materials = materials;
_adena = adena;
_resultItemId = resultItemId;
_resultItemEnchant = resultItemEnchant;
}
public int getId()
{
return _id;
}
public int getRequiredItemId()
{
return _requiredItemId;
}
public int getRequiredItemEnchant()
{
return _requiredItemEnchant;
}
public List<ItemHolder> getMaterials()
{
return _materials;
}
public long getAdena()
{
return _adena;
}
public int getResultItemId()
{
return _resultItemId;
}
public int getResultItemEnchant()
{
return _resultItemEnchant;
}
}

View File

@@ -69,6 +69,7 @@ import org.l2jmobius.gameserver.network.clientpackets.crystalization.RequestCrys
import org.l2jmobius.gameserver.network.clientpackets.crystalization.RequestCrystallizeItemCancel;
import org.l2jmobius.gameserver.network.clientpackets.ensoul.RequestItemEnsoul;
import org.l2jmobius.gameserver.network.clientpackets.ensoul.RequestTryEnSoulExtraction;
import org.l2jmobius.gameserver.network.clientpackets.equipmentupgrade.RequestUpgradeSystemResult;
import org.l2jmobius.gameserver.network.clientpackets.faction.RequestUserFactionInfo;
import org.l2jmobius.gameserver.network.clientpackets.friend.RequestFriendDetailInfo;
import org.l2jmobius.gameserver.network.clientpackets.luckygame.RequestLuckyGamePlay;
@@ -415,7 +416,7 @@ public enum ExIncomingPackets implements IIncomingPackets<GameClient>
EXREQUEST_MATCH_GROUP_WITHDRAW(0x133, null, ConnectionState.IN_GAME),
EXREQUEST_MATCH_GROUP_OUST(0x134, null, ConnectionState.IN_GAME),
EXREQUEST_MATCH_GROUP_CHANGE_MASTER(0x135, null, ConnectionState.IN_GAME),
REQUEST_UPGRADE_SYSTEM_RESULT(0x136, null, ConnectionState.IN_GAME),
REQUEST_UPGRADE_SYSTEM_RESULT(0x136, RequestUpgradeSystemResult::new, ConnectionState.IN_GAME),
EX_CARD_UPDOWN_PICK_NUMB(0x137, null, ConnectionState.IN_GAME),
EX_CARD_UPDOWN_GAME_REWARD_REQUEST(0x138, null, ConnectionState.IN_GAME),
EX_CARD_UPDOWN_GAME_RETRY(0x139, null, ConnectionState.IN_GAME),

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 org.l2jmobius.gameserver.network.clientpackets.equipmentupgrade;
import org.l2jmobius.commons.network.PacketReader;
import org.l2jmobius.gameserver.data.xml.impl.UpgradeEquipmentData;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.model.holders.ItemHolder;
import org.l2jmobius.gameserver.model.holders.UpgradeEquipmentHolder;
import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
import org.l2jmobius.gameserver.network.GameClient;
import org.l2jmobius.gameserver.network.clientpackets.IClientIncomingPacket;
import org.l2jmobius.gameserver.network.serverpackets.equipmentupgrade.ExUpgradeSystemResult;
/**
* @author Mobius
*/
public class RequestUpgradeSystemResult implements IClientIncomingPacket
{
private int _objectId;
private int _upgradeId;
@Override
public boolean read(GameClient client, PacketReader packet)
{
_objectId = packet.readD();
_upgradeId = packet.readD();
return true;
}
@Override
public void run(GameClient client)
{
final PlayerInstance player = client.getPlayer();
if (player == null)
{
return;
}
final ItemInstance existingItem = player.getInventory().getItemByObjectId(_objectId);
if (existingItem == null)
{
player.sendPacket(new ExUpgradeSystemResult(0, 0));
return;
}
final UpgradeEquipmentHolder upgradeHolder = UpgradeEquipmentData.getInstance().getUpgrade(_upgradeId);
if (upgradeHolder == null)
{
player.sendPacket(new ExUpgradeSystemResult(0, 0));
return;
}
for (ItemHolder material : upgradeHolder.getMaterials())
{
if (player.getInventory().getInventoryItemCount(material.getId(), -1) < material.getCount())
{
player.sendPacket(new ExUpgradeSystemResult(0, 0));
return;
}
}
final long adena = upgradeHolder.getAdena();
if ((adena > 0) && (player.getAdena() < adena))
{
player.sendPacket(new ExUpgradeSystemResult(0, 0));
return;
}
if ((existingItem.getItem().getId() != upgradeHolder.getRequiredItemId()) || (existingItem.getEnchantLevel() != upgradeHolder.getRequiredItemEnchant()))
{
player.sendPacket(new ExUpgradeSystemResult(0, 0));
return;
}
// Get materials.
player.destroyItem("UpgradeEquipment", _objectId, 1, player, true);
for (ItemHolder material : upgradeHolder.getMaterials())
{
player.destroyItemByItemId("UpgradeEquipment", material.getId(), material.getCount(), player, true);
}
if (adena > 0)
{
player.reduceAdena("UpgradeEquipment", adena, player, true);
}
// Give item.
final ItemInstance newItem = player.addItem("UpgradeEquipment", upgradeHolder.getResultItemId(), 1, player, true);
final int enchantLevel = upgradeHolder.getResultItemEnchant();
if (enchantLevel > 0)
{
newItem.setEnchantLevel(enchantLevel);
}
player.sendPacket(new ExUpgradeSystemResult(newItem.getObjectId(), 1));
}
}

View File

@@ -0,0 +1,39 @@
/*
* 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 org.l2jmobius.gameserver.network.serverpackets.equipmentupgrade;
import org.l2jmobius.commons.network.PacketWriter;
import org.l2jmobius.gameserver.network.OutgoingPackets;
import org.l2jmobius.gameserver.network.serverpackets.AbstractItemPacket;
/**
* @author Mobius
*/
public class ExShowUpgradeSystem extends AbstractItemPacket
{
public ExShowUpgradeSystem()
{
}
@Override
public boolean write(PacketWriter packet)
{
OutgoingPackets.EX_SHOW_UPGRADE_SYSTEM.writeId(packet);
packet.writeH(0x01);
return true;
}
}

View File

@@ -0,0 +1,45 @@
/*
* 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 org.l2jmobius.gameserver.network.serverpackets.equipmentupgrade;
import org.l2jmobius.commons.network.PacketWriter;
import org.l2jmobius.gameserver.network.OutgoingPackets;
import org.l2jmobius.gameserver.network.serverpackets.AbstractItemPacket;
/**
* @author Mobius
*/
public class ExUpgradeSystemResult extends AbstractItemPacket
{
private final int _objectId;
private final int _success;
public ExUpgradeSystemResult(int objectId, int success)
{
_objectId = objectId;
_success = success;
}
@Override
public boolean write(PacketWriter packet)
{
OutgoingPackets.EX_UPGRADE_SYSTEM_RESULT.writeId(packet);
packet.writeH(_success);
packet.writeD(_objectId);
return true;
}
}