diff --git a/L2J_Mobius_08.2_Homunculus/dist/game/data/HomunculusCreationData.xml b/L2J_Mobius_08.2_Homunculus/dist/game/data/HomunculusCreationData.xml new file mode 100644 index 0000000000..ab55e77a40 --- /dev/null +++ b/L2J_Mobius_08.2_Homunculus/dist/game/data/HomunculusCreationData.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/L2J_Mobius_08.2_Homunculus/dist/game/data/xsd/HomunculusCreationData.xsd b/L2J_Mobius_08.2_Homunculus/dist/game/data/xsd/HomunculusCreationData.xsd new file mode 100644 index 0000000000..8331a269fb --- /dev/null +++ b/L2J_Mobius_08.2_Homunculus/dist/game/data/xsd/HomunculusCreationData.xsd @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/L2J_Mobius_08.2_Homunculus/java/org/l2jmobius/gameserver/GameServer.java b/L2J_Mobius_08.2_Homunculus/java/org/l2jmobius/gameserver/GameServer.java index c28ce0ca5d..abca4f26e2 100644 --- a/L2J_Mobius_08.2_Homunculus/java/org/l2jmobius/gameserver/GameServer.java +++ b/L2J_Mobius_08.2_Homunculus/java/org/l2jmobius/gameserver/GameServer.java @@ -75,6 +75,7 @@ import org.l2jmobius.gameserver.data.xml.FenceData; import org.l2jmobius.gameserver.data.xml.FishingData; import org.l2jmobius.gameserver.data.xml.HennaData; import org.l2jmobius.gameserver.data.xml.HitConditionBonusData; +import org.l2jmobius.gameserver.data.xml.HomunculusCreationData; import org.l2jmobius.gameserver.data.xml.HomunculusData; import org.l2jmobius.gameserver.data.xml.InitialEquipmentData; import org.l2jmobius.gameserver.data.xml.InitialShortcutData; @@ -337,6 +338,7 @@ public class GameServer GrandBossManager.getInstance(); EventDropManager.getInstance(); HomunculusData.getInstance(); + HomunculusCreationData.getInstance(); printSection("Instance"); InstanceManager.getInstance(); diff --git a/L2J_Mobius_08.2_Homunculus/java/org/l2jmobius/gameserver/data/xml/HomunculusCreationData.java b/L2J_Mobius_08.2_Homunculus/java/org/l2jmobius/gameserver/data/xml/HomunculusCreationData.java new file mode 100644 index 0000000000..088ebb8432 --- /dev/null +++ b/L2J_Mobius_08.2_Homunculus/java/org/l2jmobius/gameserver/data/xml/HomunculusCreationData.java @@ -0,0 +1,175 @@ +/* + * 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 . + */ +package org.l2jmobius.gameserver.data.xml; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.w3c.dom.Document; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; + +import org.l2jmobius.commons.util.IXmlReader; +import org.l2jmobius.gameserver.model.StatSet; +import org.l2jmobius.gameserver.model.holders.ItemHolder; +import org.l2jmobius.gameserver.model.homunculus.HomunculusCreationTemplate; + +/** + * @author Index + */ +public class HomunculusCreationData implements IXmlReader +{ + private final Map _templates = new HashMap<>(); + + protected HomunculusCreationData() + { + load(); + } + + @Override + public void load() + { + _templates.clear(); + parseDatapackFile("data/HomunculusCreationData.xml"); + LOGGER.info(getClass().getSimpleName() + ": Loaded " + _templates.size() + " templates."); + } + + @Override + public void parseDocument(Document doc, File f) + { + StatSet set; + Node att; + NamedNodeMap attrs; + for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling()) + { + if ("list".equalsIgnoreCase(n.getNodeName())) + { + for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling()) + { + if ("homunculusCreation".equalsIgnoreCase(d.getNodeName())) + { + attrs = d.getAttributes(); + set = new StatSet(); + for (int i = 0; i < attrs.getLength(); i++) + { + att = attrs.item(i); + set.set(att.getNodeName(), att.getNodeValue()); + } + + final int slotId = set.getInt("slotId", 0); + final Boolean isEnabled = set.getBoolean("isEnabled", false); + final int grade = set.getInt("grade", 0); + final Boolean isEvent = set.getBoolean("event", false); + List itemFees = Collections.emptyList(); + Integer[] hpFee = new Integer[2]; + Long[] spFee = new Long[2]; + Integer[] vpFee = new Integer[2]; + long time = 0; + List chances = Collections.emptyList(); + for (Node b = d.getFirstChild(); b != null; b = b.getNextSibling()) + { + if ("itemFees".equalsIgnoreCase(b.getNodeName())) + { + itemFees = getItemList(b); + } + else if ("hpFee".equalsIgnoreCase(b.getNodeName())) + { + hpFee[0] = Integer.parseInt(b.getAttributes().getNamedItem("count").getNodeValue()); + hpFee[1] = Integer.parseInt(b.getAttributes().getNamedItem("byUse").getNodeValue()); + } + else if ("spFee".equalsIgnoreCase(b.getNodeName())) + { + spFee[0] = Long.parseLong(b.getAttributes().getNamedItem("count").getNodeValue()); + spFee[1] = Long.parseLong(b.getAttributes().getNamedItem("byUse").getNodeValue()); + } + else if ("vpFee".equalsIgnoreCase(b.getNodeName())) + { + vpFee[0] = Integer.parseInt(b.getAttributes().getNamedItem("count").getNodeValue()); + vpFee[1] = Integer.parseInt(b.getAttributes().getNamedItem("byUse").getNodeValue()); + } + else if ("time".equalsIgnoreCase(b.getNodeName())) + { + time = Long.parseLong(b.getAttributes().getNamedItem("count").getNodeValue()); + } + else if ("chance".equalsIgnoreCase(b.getNodeName())) + { + chances = getChanceList(b); + } + } + + _templates.put(slotId, new HomunculusCreationTemplate(slotId, isEnabled, grade, isEvent, itemFees, hpFee, spFee, vpFee, time, chances)); + } + } + } + } + } + + private List getItemList(Node c) + { + final List items = new ArrayList<>(); + for (Node b = c.getFirstChild(); b != null; b = b.getNextSibling()) + { + if ("item".equalsIgnoreCase(b.getNodeName())) + { + final int itemId = Integer.parseInt(b.getAttributes().getNamedItem("id").getNodeValue()); + final long itemCount = Long.parseLong(b.getAttributes().getNamedItem("count").getNodeValue()); + items.add(new ItemHolder(itemId, itemCount)); + } + } + return items; + } + + private List getChanceList(Node c) + { + final List chanceList = new ArrayList<>(); + for (Node b = c.getFirstChild(); b != null; b = b.getNextSibling()) + { + if ("homunculus".equalsIgnoreCase(b.getNodeName())) + { + final Double[] feeArray = new Double[2]; + feeArray[0] = Double.parseDouble(b.getAttributes().getNamedItem("id").getNodeValue()); + feeArray[1] = Double.parseDouble(b.getAttributes().getNamedItem("creationChance").getNodeValue()); + chanceList.add(feeArray); + } + } + return chanceList; + } + + public HomunculusCreationTemplate getTemplate(int id) + { + return _templates.get(id); + } + + public int size() + { + return _templates.size(); + } + + public static HomunculusCreationData getInstance() + { + return SingletonHolder.INSTANCE; + } + + private static class SingletonHolder + { + protected static final HomunculusCreationData INSTANCE = new HomunculusCreationData(); + } +} diff --git a/L2J_Mobius_08.2_Homunculus/java/org/l2jmobius/gameserver/model/homunculus/HomunculusCreationTemplate.java b/L2J_Mobius_08.2_Homunculus/java/org/l2jmobius/gameserver/model/homunculus/HomunculusCreationTemplate.java new file mode 100644 index 0000000000..8a9d603ba6 --- /dev/null +++ b/L2J_Mobius_08.2_Homunculus/java/org/l2jmobius/gameserver/model/homunculus/HomunculusCreationTemplate.java @@ -0,0 +1,142 @@ +/* + * 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 . + */ +package org.l2jmobius.gameserver.model.homunculus; + +import java.util.List; + +import org.l2jmobius.gameserver.model.holders.ItemHolder; + +public class HomunculusCreationTemplate +{ + private final int _slotId; + private final boolean _isEnabled; + private final int _grade; + private final boolean _isEvent; + private final List _itemsFee; + private final Integer[] _hpFee; + private final Long[] _spFee; + private final Integer[] _vpFee; + private final long _time; + private final List _createChances; + + public HomunculusCreationTemplate(int slotId, boolean isEnabled, int grade, boolean isEvent, List itemsFee, Integer[] hpFee, Long[] spFee, Integer[] vpFee, long time, List createChances) + { + _slotId = slotId; + _isEnabled = isEnabled; + _grade = grade; + _isEvent = isEvent; + _itemsFee = itemsFee; + _hpFee = hpFee; + _spFee = spFee; + _vpFee = vpFee; + _time = time; + _createChances = createChances; + } + + public int getSlotId() + { + return _slotId; + } + + public boolean isEnabled() + { + return _isEnabled; + } + + public int getGrade() + { + return _grade; + } + + public boolean isEvent() + { + return _isEvent; + } + + public List getItemFee() + { + return _itemsFee; + } + + public boolean haveAnotherFee() + { + return !_itemsFee.isEmpty(); + } + + public int getHPFeeCountByUse() + { + return _hpFee[1]; + } + + public int getHPFeeCount() + { + return _hpFee[0]; + } + + public long getSPFeeCountByUse() + { + return _spFee[1]; + } + + public long getSPFeeCount() + { + return _spFee[0]; + } + + public int getVPFeeByUse() + { + return _vpFee[1]; + } + + public int getVPFeeCount() + { + return _vpFee[0]; + } + + public double getMaxChance() + { + double result = 0; + for (int i = 0; i < _createChances.size(); i++) + { + Double[] chance = _createChances.get(i); + result = result + chance[1]; + } + return result; + } + + public boolean isInstanceHaveCoupon(int itemId) + { + for (ItemHolder humu : _itemsFee) + { + if (humu.getId() == itemId) + { + return true; + } + } + return false; + } + + public long getCreationLime() + { + return _time; + } + + public List getCreationChance() + { + return _createChances; + } +} diff --git a/L2J_Mobius_08.2_Homunculus/java/org/l2jmobius/gameserver/model/homunculus/HomunculusSlotTemplate.java b/L2J_Mobius_08.2_Homunculus/java/org/l2jmobius/gameserver/model/homunculus/HomunculusSlotTemplate.java new file mode 100644 index 0000000000..6125633dd1 --- /dev/null +++ b/L2J_Mobius_08.2_Homunculus/java/org/l2jmobius/gameserver/model/homunculus/HomunculusSlotTemplate.java @@ -0,0 +1,50 @@ +/* + * 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 . + */ +package org.l2jmobius.gameserver.model.homunculus; + +import java.util.List; + +import org.l2jmobius.gameserver.model.holders.ItemHolder; + +public class HomunculusSlotTemplate +{ + private final int _slotId; + private final List _price; + private final boolean _isEnabled; + + public HomunculusSlotTemplate(int slotId, List price, boolean isEnabled) + { + _slotId = slotId; + _price = price; + _isEnabled = isEnabled; + } + + public int getSlotId() + { + return _slotId; + } + + public List getPrice() + { + return _price; + } + + public boolean getSlotEnabled() + { + return _isEnabled; + } +} diff --git a/L2J_Mobius_08.2_Homunculus/java/org/l2jmobius/gameserver/model/variables/PlayerVariables.java b/L2J_Mobius_08.2_Homunculus/java/org/l2jmobius/gameserver/model/variables/PlayerVariables.java index d547f70182..b91692eab0 100644 --- a/L2J_Mobius_08.2_Homunculus/java/org/l2jmobius/gameserver/model/variables/PlayerVariables.java +++ b/L2J_Mobius_08.2_Homunculus/java/org/l2jmobius/gameserver/model/variables/PlayerVariables.java @@ -80,6 +80,7 @@ public class PlayerVariables extends AbstractVariables public static final String HOMUNCULUS_USED_VP_POINTS = "HOMUNCULUS_USED_VP_POINTS"; public static final String HOMUNCULUS_USED_VP_CONVERT = "HOMUNCULUS_USED_VP_CONVERT"; public static final String HOMUNCULUS_USED_RESET_VP = "HOMUNCULUS_USED_RESET_VP"; + public static final String HOMUNCULUS_OPENED_SLOT_COUNT = "HOMUNCULUS_OPENED_SLOT_COUNT"; private final int _objectId; diff --git a/L2J_Mobius_08.2_Homunculus/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusCreateStart.java b/L2J_Mobius_08.2_Homunculus/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusCreateStart.java index dec3277cf4..b3b5c331de 100644 --- a/L2J_Mobius_08.2_Homunculus/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusCreateStart.java +++ b/L2J_Mobius_08.2_Homunculus/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusCreateStart.java @@ -17,7 +17,9 @@ package org.l2jmobius.gameserver.network.clientpackets.homunculus; import org.l2jmobius.commons.network.PacketReader; +import org.l2jmobius.gameserver.data.xml.HomunculusCreationData; import org.l2jmobius.gameserver.model.actor.Player; +import org.l2jmobius.gameserver.model.homunculus.HomunculusCreationTemplate; import org.l2jmobius.gameserver.model.variables.PlayerVariables; import org.l2jmobius.gameserver.network.GameClient; import org.l2jmobius.gameserver.network.SystemMessageId; @@ -30,8 +32,9 @@ import org.l2jmobius.gameserver.network.serverpackets.homunculus.ExShowHomunculu */ public class RequestExHomunculusCreateStart implements IClientIncomingPacket { - private static final int COST = 1000000; - private static final long CREATION_TIME = 86400000L; + private static final HomunculusCreationTemplate TEMPLATE = HomunculusCreationData.getInstance().getTemplate(0); + private static final int COST = Math.toIntExact(TEMPLATE.getItemFee().get(0).getCount()); + private static final long CREATION_TIME = TEMPLATE.getCreationLime(); @Override public boolean read(GameClient client, PacketReader packet) @@ -53,6 +56,7 @@ public class RequestExHomunculusCreateStart implements IClientIncomingPacket player.sendPacket(SystemMessageId.YOU_DO_NOT_HAVE_ENOUGH_ADENA_2); return; } + player.reduceAdena("Homunculus creation", COST, player, true); player.getVariables().set(PlayerVariables.HOMUNCULUS_CREATION_TIME, System.currentTimeMillis() + CREATION_TIME); diff --git a/L2J_Mobius_08.2_Homunculus/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusInsert.java b/L2J_Mobius_08.2_Homunculus/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusInsert.java index 6a2e480084..dde47a5571 100644 --- a/L2J_Mobius_08.2_Homunculus/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusInsert.java +++ b/L2J_Mobius_08.2_Homunculus/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusInsert.java @@ -17,8 +17,9 @@ package org.l2jmobius.gameserver.network.clientpackets.homunculus; import org.l2jmobius.commons.network.PacketReader; +import org.l2jmobius.gameserver.data.xml.HomunculusCreationData; import org.l2jmobius.gameserver.model.actor.Player; -import org.l2jmobius.gameserver.model.actor.stat.PlayerStat; +import org.l2jmobius.gameserver.model.homunculus.HomunculusCreationTemplate; import org.l2jmobius.gameserver.model.variables.PlayerVariables; import org.l2jmobius.gameserver.network.GameClient; import org.l2jmobius.gameserver.network.clientpackets.IClientIncomingPacket; @@ -31,9 +32,10 @@ import org.l2jmobius.gameserver.network.serverpackets.homunculus.ExShowHomunculu */ public class RequestExHomunculusInsert implements IClientIncomingPacket { - private static final short HP_COST = 10000; - private static final long SP_COST = 5000000000L; - private static final int VP_COST = PlayerStat.MAX_VITALITY_POINTS / 4; + private static final HomunculusCreationTemplate TEMPLATE = HomunculusCreationData.getInstance().getTemplate(0); + private static final short HP_COST = (short) TEMPLATE.getHPFeeCountByUse(); + private static final long SP_COST = TEMPLATE.getSPFeeCountByUse(); + private static final int VP_COST = TEMPLATE.getVPFeeByUse(); private int _type; @@ -59,7 +61,7 @@ public class RequestExHomunculusInsert implements IClientIncomingPacket { case 0: { - if ((player.getCurrentHp() > HP_COST) && (hpPoints < 100)) + if ((player.getCurrentHp() > HP_COST) && (hpPoints < TEMPLATE.getHPFeeCount())) { int newHp = (int) (player.getCurrentHp()) - HP_COST; player.setCurrentHp(newHp, true); @@ -74,7 +76,7 @@ public class RequestExHomunculusInsert implements IClientIncomingPacket } case 1: { - if ((player.getSp() >= SP_COST) && (spPoints < 10)) + if ((player.getSp() >= SP_COST) && (spPoints < TEMPLATE.getSPFeeCount())) { player.setSp(player.getSp() - SP_COST); spPoints += 1; @@ -88,7 +90,7 @@ public class RequestExHomunculusInsert implements IClientIncomingPacket } case 2: { - if ((player.getVitalityPoints() >= VP_COST) && (vpPoints < 5)) + if ((player.getVitalityPoints() >= VP_COST) && (vpPoints < TEMPLATE.getVPFeeCount())) { int newVitality = player.getVitalityPoints() - VP_COST; player.setVitalityPoints(newVitality, true); diff --git a/L2J_Mobius_08.2_Homunculus/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusSummon.java b/L2J_Mobius_08.2_Homunculus/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusSummon.java index 01d691a780..305ebab539 100644 --- a/L2J_Mobius_08.2_Homunculus/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusSummon.java +++ b/L2J_Mobius_08.2_Homunculus/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusSummon.java @@ -18,9 +18,11 @@ package org.l2jmobius.gameserver.network.clientpackets.homunculus; import org.l2jmobius.commons.network.PacketReader; import org.l2jmobius.commons.util.Rnd; +import org.l2jmobius.gameserver.data.xml.HomunculusCreationData; import org.l2jmobius.gameserver.data.xml.HomunculusData; import org.l2jmobius.gameserver.model.actor.Player; import org.l2jmobius.gameserver.model.homunculus.Homunculus; +import org.l2jmobius.gameserver.model.homunculus.HomunculusCreationTemplate; import org.l2jmobius.gameserver.model.homunculus.HomunculusTemplate; import org.l2jmobius.gameserver.model.variables.PlayerVariables; import org.l2jmobius.gameserver.network.GameClient; @@ -35,6 +37,8 @@ import org.l2jmobius.gameserver.network.serverpackets.homunculus.ExShowHomunculu */ public class RequestExHomunculusSummon implements IClientIncomingPacket { + private static final HomunculusCreationTemplate TEMPLATE = HomunculusCreationData.getInstance().getTemplate(0); + @Override public boolean read(GameClient client, PacketReader packet) { @@ -56,88 +60,26 @@ public class RequestExHomunculusSummon implements IClientIncomingPacket final int vpPoints = player.getVariables().getInt(PlayerVariables.HOMUNCULUS_VP_POINTS, 0); final int homunculusCreateTime = (int) (player.getVariables().getLong(PlayerVariables.HOMUNCULUS_CREATION_TIME, 0) / 1000); - if ((homunculusCreateTime > 0) && ((System.currentTimeMillis() / 1000) >= homunculusCreateTime) && (hpPoints == 100) && (spPoints == 10) && (vpPoints == 5)) + if ((homunculusCreateTime > 0) && ((System.currentTimeMillis() / 1000) >= homunculusCreateTime) && (hpPoints == TEMPLATE.getHPFeeCount()) && (spPoints == TEMPLATE.getSPFeeCount()) && (vpPoints == TEMPLATE.getVPFeeCount())) { - int chance; - int random; + double chance = Rnd.get(100.0); + double current = 0; int homunculusId = 0; while (homunculusId == 0) { - chance = Rnd.get(100); - random = Rnd.get(100); - - // Basic Homunculus - if (chance >= 60) + if (chance > TEMPLATE.getMaxChance()) { - if ((random >= 80) && !player.getHomunculusList().hasHomunculus(1)) - { - homunculusId = 1; - } - else if ((random >= 60) && !player.getHomunculusList().hasHomunculus(4)) - { - homunculusId = 4; - } - else if ((random >= 40) && !player.getHomunculusList().hasHomunculus(7)) - { - homunculusId = 7; - } - else if ((random >= 20) && !player.getHomunculusList().hasHomunculus(10)) - { - homunculusId = 10; - } - else if (!player.getHomunculusList().hasHomunculus(13)) - { - homunculusId = 13; - } + player.sendMessage("Homunculus is not created!"); + return; } - - // Water Homunculus - if ((homunculusId == 0) && (chance >= 10)) + for (int i = 0; i < TEMPLATE.getCreationChance().size(); i++) { - if ((random >= 80) && !player.getHomunculusList().hasHomunculus(2)) + final Double[] homuHolder = TEMPLATE.getCreationChance().get(i); + current += homuHolder[1]; + if (current >= chance) { - homunculusId = 2; - } - else if ((random >= 60) && !player.getHomunculusList().hasHomunculus(5)) - { - homunculusId = 5; - } - else if ((random >= 40) && !player.getHomunculusList().hasHomunculus(8)) - { - homunculusId = 8; - } - else if ((random >= 20) && !player.getHomunculusList().hasHomunculus(11)) - { - homunculusId = 11; - } - else if (!player.getHomunculusList().hasHomunculus(14)) - { - homunculusId = 14; - } - } - - // Luminous Homunculus - if (homunculusId == 0) - { - if ((random >= 80) && !player.getHomunculusList().hasHomunculus(3)) - { - homunculusId = 3; - } - else if ((random >= 60) && !player.getHomunculusList().hasHomunculus(6)) - { - homunculusId = 6; - } - else if ((random >= 40) && !player.getHomunculusList().hasHomunculus(9)) - { - homunculusId = 9; - } - else if ((random >= 20) && !player.getHomunculusList().hasHomunculus(12)) - { - homunculusId = 12; - } - else if (!player.getHomunculusList().hasHomunculus(15)) - { - homunculusId = 15; + homunculusId = homuHolder[0].intValue(); + break; } } } diff --git a/L2J_Mobius_08.2_Homunculus/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExShowHomunculusBirthInfo.java b/L2J_Mobius_08.2_Homunculus/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExShowHomunculusBirthInfo.java index cdc24a4c11..33d7857cba 100644 --- a/L2J_Mobius_08.2_Homunculus/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExShowHomunculusBirthInfo.java +++ b/L2J_Mobius_08.2_Homunculus/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExShowHomunculusBirthInfo.java @@ -17,7 +17,9 @@ package org.l2jmobius.gameserver.network.serverpackets.homunculus; import org.l2jmobius.commons.network.PacketWriter; +import org.l2jmobius.gameserver.data.xml.HomunculusCreationData; import org.l2jmobius.gameserver.model.actor.Player; +import org.l2jmobius.gameserver.model.homunculus.HomunculusCreationTemplate; import org.l2jmobius.gameserver.model.variables.PlayerVariables; import org.l2jmobius.gameserver.network.OutgoingPackets; import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket; @@ -27,10 +29,15 @@ import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket; */ public class ExShowHomunculusBirthInfo implements IClientOutgoingPacket { + private static final HomunculusCreationTemplate TEMPLATE = HomunculusCreationData.getInstance().getTemplate(0); + private final int _hpPoints; private final int _spPoints; private final int _vpPoints; private final int _homunculusCreateTime; + private final int _feeHpPoints; + private final int _feeSpPoints; + private final int _feeVpPoints; public ExShowHomunculusBirthInfo(Player player) { @@ -38,6 +45,9 @@ public class ExShowHomunculusBirthInfo implements IClientOutgoingPacket _spPoints = player.getVariables().getInt(PlayerVariables.HOMUNCULUS_SP_POINTS, 0); _vpPoints = player.getVariables().getInt(PlayerVariables.HOMUNCULUS_VP_POINTS, 0); _homunculusCreateTime = (int) (player.getVariables().getLong(PlayerVariables.HOMUNCULUS_CREATION_TIME, 0) / 1000); + _feeHpPoints = TEMPLATE.getHPFeeCount(); + _feeSpPoints = (int) TEMPLATE.getSPFeeCount(); + _feeVpPoints = TEMPLATE.getVPFeeCount(); } @Override @@ -47,7 +57,7 @@ public class ExShowHomunculusBirthInfo implements IClientOutgoingPacket int creationStage = 0; if (_homunculusCreateTime > 0) { - if (((System.currentTimeMillis() / 1000) >= _homunculusCreateTime) && (_hpPoints == 100) && (_spPoints == 10) && (_vpPoints == 5)) + if (((System.currentTimeMillis() / 1000) >= _homunculusCreateTime) && (_hpPoints == _feeHpPoints) && (_spPoints == _feeSpPoints) && (_vpPoints == _feeVpPoints)) { creationStage = 2; } @@ -60,8 +70,8 @@ public class ExShowHomunculusBirthInfo implements IClientOutgoingPacket packet.writeD(_hpPoints); // hp points packet.writeD(_spPoints); // sp points packet.writeD(_vpPoints); // vp points - packet.writeD(_homunculusCreateTime); // finish time - packet.writeD(0); // JP = 0. ? + packet.writeQ(_homunculusCreateTime); // finish time + // packet.writeD(0); // JP = 0. ? return true; } } diff --git a/L2J_Mobius_08.2_Homunculus/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExShowHomunculusList.java b/L2J_Mobius_08.2_Homunculus/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExShowHomunculusList.java index 74372f0878..28369f119f 100644 --- a/L2J_Mobius_08.2_Homunculus/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExShowHomunculusList.java +++ b/L2J_Mobius_08.2_Homunculus/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExShowHomunculusList.java @@ -16,10 +16,10 @@ */ package org.l2jmobius.gameserver.network.serverpackets.homunculus; -import org.l2jmobius.Config; import org.l2jmobius.commons.network.PacketWriter; import org.l2jmobius.gameserver.model.actor.Player; import org.l2jmobius.gameserver.model.homunculus.Homunculus; +import org.l2jmobius.gameserver.model.variables.PlayerVariables; import org.l2jmobius.gameserver.network.OutgoingPackets; import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket; @@ -38,18 +38,34 @@ public class ExShowHomunculusList implements IClientOutgoingPacket @Override public boolean write(PacketWriter packet) { - OutgoingPackets.EX_SHOW_HOMUNCULUS_LIST.writeId(packet); - if (_player.getHomunculusList().size() > 0) + if ((_player.getVariables().getInt(PlayerVariables.HOMUNCULUS_OPENED_SLOT_COUNT, 0) == 0) || (_player.getVariables().getInt(PlayerVariables.HOMUNCULUS_OPENED_SLOT_COUNT) == 1) || (_player.getVariables().getInt(PlayerVariables.HOMUNCULUS_OPENED_SLOT_COUNT) == 2)) { - packet.writeD(_player.getHomunculusList().size()); // homunculus count - int counter = 0; - for (int i = 0; i < Config.MAX_HOMUNCULUS_COUNT; i++) + if ((_player.getHomunculusList() != null) && (_player.getHomunculusList().size() != 0) && (_player.getHomunculusList().size() < 2)) + { + if (_player.getVariables().getInt(PlayerVariables.HOMUNCULUS_CREATION_TIME, 0) >= 0) + { + _player.getVariables().set(PlayerVariables.HOMUNCULUS_OPENED_SLOT_COUNT, _player.getHomunculusList().size() + 1); + } + else + { + _player.getVariables().set(PlayerVariables.HOMUNCULUS_OPENED_SLOT_COUNT, _player.getHomunculusList().size()); + } + } + else + { + _player.getVariables().set(PlayerVariables.HOMUNCULUS_OPENED_SLOT_COUNT, 3); + } + } + + final int slotCount = _player.getVariables().getInt(PlayerVariables.HOMUNCULUS_OPENED_SLOT_COUNT); + OutgoingPackets.EX_SHOW_HOMUNCULUS_LIST.writeId(packet); + packet.writeD(slotCount); + int counter = 0; + for (int i = 0; i <= slotCount; i++) + { + if (_player.getHomunculusList().get(i) != null) { final Homunculus homunculus = _player.getHomunculusList().get(i); - if (homunculus == null) - { - continue; - } packet.writeD(counter); // slot packet.writeD(homunculus.getId()); // homunculus id packet.writeD(homunculus.getType()); @@ -72,13 +88,33 @@ public class ExShowHomunculusList implements IClientOutgoingPacket packet.writeD(homunculus.getAtk()); packet.writeD(homunculus.getDef()); packet.writeD(homunculus.getCritRate()); - counter++; } + else + { + packet.writeD(counter); // slot + packet.writeD(0); // homunculus id + packet.writeD(0); + packet.writeC(0); + packet.writeD(0); + for (int j = 1; j <= 5; j++) + { + packet.writeD(0); + } + packet.writeD(0); + for (int j = 1; j <= 5; j++) + { + packet.writeD(0); + } + packet.writeD(0);// m_nLevel + packet.writeD(0);// m_nHP + packet.writeD(0);// m_nHP + packet.writeD(0);// m_nAttack + packet.writeD(0);// m_nDefence + packet.writeD(0);// m_nCritical + } + counter++; } - else - { - packet.writeD(0); - } + return true; } } diff --git a/L2J_Mobius_09.2_ReturnOfTheQueenAnt/dist/game/data/HomunculusCreationData.xml b/L2J_Mobius_09.2_ReturnOfTheQueenAnt/dist/game/data/HomunculusCreationData.xml new file mode 100644 index 0000000000..4b5ff8244e --- /dev/null +++ b/L2J_Mobius_09.2_ReturnOfTheQueenAnt/dist/game/data/HomunculusCreationData.xml @@ -0,0 +1,100 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/L2J_Mobius_09.2_ReturnOfTheQueenAnt/dist/game/data/HomunculusSlotData.xml b/L2J_Mobius_09.2_ReturnOfTheQueenAnt/dist/game/data/HomunculusSlotData.xml new file mode 100644 index 0000000000..0b336dd5d6 --- /dev/null +++ b/L2J_Mobius_09.2_ReturnOfTheQueenAnt/dist/game/data/HomunculusSlotData.xml @@ -0,0 +1,150 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/L2J_Mobius_09.2_ReturnOfTheQueenAnt/dist/game/data/xsd/HomunculusCreationData.xsd b/L2J_Mobius_09.2_ReturnOfTheQueenAnt/dist/game/data/xsd/HomunculusCreationData.xsd new file mode 100644 index 0000000000..8331a269fb --- /dev/null +++ b/L2J_Mobius_09.2_ReturnOfTheQueenAnt/dist/game/data/xsd/HomunculusCreationData.xsd @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/L2J_Mobius_09.2_ReturnOfTheQueenAnt/dist/game/data/xsd/HomunculusSlotData.xsd b/L2J_Mobius_09.2_ReturnOfTheQueenAnt/dist/game/data/xsd/HomunculusSlotData.xsd new file mode 100644 index 0000000000..73e250515d --- /dev/null +++ b/L2J_Mobius_09.2_ReturnOfTheQueenAnt/dist/game/data/xsd/HomunculusSlotData.xsd @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/GameServer.java b/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/GameServer.java index 1cf219560f..5357aec0e6 100644 --- a/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/GameServer.java +++ b/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/GameServer.java @@ -76,7 +76,9 @@ import org.l2jmobius.gameserver.data.xml.FenceData; import org.l2jmobius.gameserver.data.xml.FishingData; import org.l2jmobius.gameserver.data.xml.HennaData; import org.l2jmobius.gameserver.data.xml.HitConditionBonusData; +import org.l2jmobius.gameserver.data.xml.HomunculusCreationData; import org.l2jmobius.gameserver.data.xml.HomunculusData; +import org.l2jmobius.gameserver.data.xml.HomunculusSlotData; import org.l2jmobius.gameserver.data.xml.InitialEquipmentData; import org.l2jmobius.gameserver.data.xml.InitialShortcutData; import org.l2jmobius.gameserver.data.xml.ItemCrystallizationData; @@ -339,6 +341,8 @@ public class GameServer GrandBossManager.getInstance(); EventDropManager.getInstance(); HomunculusData.getInstance(); + HomunculusSlotData.getInstance(); + HomunculusCreationData.getInstance(); printSection("Instance"); InstanceManager.getInstance(); diff --git a/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/data/xml/HomunculusCreationData.java b/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/data/xml/HomunculusCreationData.java new file mode 100644 index 0000000000..088ebb8432 --- /dev/null +++ b/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/data/xml/HomunculusCreationData.java @@ -0,0 +1,175 @@ +/* + * 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 . + */ +package org.l2jmobius.gameserver.data.xml; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.w3c.dom.Document; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; + +import org.l2jmobius.commons.util.IXmlReader; +import org.l2jmobius.gameserver.model.StatSet; +import org.l2jmobius.gameserver.model.holders.ItemHolder; +import org.l2jmobius.gameserver.model.homunculus.HomunculusCreationTemplate; + +/** + * @author Index + */ +public class HomunculusCreationData implements IXmlReader +{ + private final Map _templates = new HashMap<>(); + + protected HomunculusCreationData() + { + load(); + } + + @Override + public void load() + { + _templates.clear(); + parseDatapackFile("data/HomunculusCreationData.xml"); + LOGGER.info(getClass().getSimpleName() + ": Loaded " + _templates.size() + " templates."); + } + + @Override + public void parseDocument(Document doc, File f) + { + StatSet set; + Node att; + NamedNodeMap attrs; + for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling()) + { + if ("list".equalsIgnoreCase(n.getNodeName())) + { + for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling()) + { + if ("homunculusCreation".equalsIgnoreCase(d.getNodeName())) + { + attrs = d.getAttributes(); + set = new StatSet(); + for (int i = 0; i < attrs.getLength(); i++) + { + att = attrs.item(i); + set.set(att.getNodeName(), att.getNodeValue()); + } + + final int slotId = set.getInt("slotId", 0); + final Boolean isEnabled = set.getBoolean("isEnabled", false); + final int grade = set.getInt("grade", 0); + final Boolean isEvent = set.getBoolean("event", false); + List itemFees = Collections.emptyList(); + Integer[] hpFee = new Integer[2]; + Long[] spFee = new Long[2]; + Integer[] vpFee = new Integer[2]; + long time = 0; + List chances = Collections.emptyList(); + for (Node b = d.getFirstChild(); b != null; b = b.getNextSibling()) + { + if ("itemFees".equalsIgnoreCase(b.getNodeName())) + { + itemFees = getItemList(b); + } + else if ("hpFee".equalsIgnoreCase(b.getNodeName())) + { + hpFee[0] = Integer.parseInt(b.getAttributes().getNamedItem("count").getNodeValue()); + hpFee[1] = Integer.parseInt(b.getAttributes().getNamedItem("byUse").getNodeValue()); + } + else if ("spFee".equalsIgnoreCase(b.getNodeName())) + { + spFee[0] = Long.parseLong(b.getAttributes().getNamedItem("count").getNodeValue()); + spFee[1] = Long.parseLong(b.getAttributes().getNamedItem("byUse").getNodeValue()); + } + else if ("vpFee".equalsIgnoreCase(b.getNodeName())) + { + vpFee[0] = Integer.parseInt(b.getAttributes().getNamedItem("count").getNodeValue()); + vpFee[1] = Integer.parseInt(b.getAttributes().getNamedItem("byUse").getNodeValue()); + } + else if ("time".equalsIgnoreCase(b.getNodeName())) + { + time = Long.parseLong(b.getAttributes().getNamedItem("count").getNodeValue()); + } + else if ("chance".equalsIgnoreCase(b.getNodeName())) + { + chances = getChanceList(b); + } + } + + _templates.put(slotId, new HomunculusCreationTemplate(slotId, isEnabled, grade, isEvent, itemFees, hpFee, spFee, vpFee, time, chances)); + } + } + } + } + } + + private List getItemList(Node c) + { + final List items = new ArrayList<>(); + for (Node b = c.getFirstChild(); b != null; b = b.getNextSibling()) + { + if ("item".equalsIgnoreCase(b.getNodeName())) + { + final int itemId = Integer.parseInt(b.getAttributes().getNamedItem("id").getNodeValue()); + final long itemCount = Long.parseLong(b.getAttributes().getNamedItem("count").getNodeValue()); + items.add(new ItemHolder(itemId, itemCount)); + } + } + return items; + } + + private List getChanceList(Node c) + { + final List chanceList = new ArrayList<>(); + for (Node b = c.getFirstChild(); b != null; b = b.getNextSibling()) + { + if ("homunculus".equalsIgnoreCase(b.getNodeName())) + { + final Double[] feeArray = new Double[2]; + feeArray[0] = Double.parseDouble(b.getAttributes().getNamedItem("id").getNodeValue()); + feeArray[1] = Double.parseDouble(b.getAttributes().getNamedItem("creationChance").getNodeValue()); + chanceList.add(feeArray); + } + } + return chanceList; + } + + public HomunculusCreationTemplate getTemplate(int id) + { + return _templates.get(id); + } + + public int size() + { + return _templates.size(); + } + + public static HomunculusCreationData getInstance() + { + return SingletonHolder.INSTANCE; + } + + private static class SingletonHolder + { + protected static final HomunculusCreationData INSTANCE = new HomunculusCreationData(); + } +} diff --git a/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/data/xml/HomunculusSlotData.java b/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/data/xml/HomunculusSlotData.java new file mode 100644 index 0000000000..5fd6b439cf --- /dev/null +++ b/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/data/xml/HomunculusSlotData.java @@ -0,0 +1,129 @@ +/* + * 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 . + */ +package org.l2jmobius.gameserver.data.xml; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.w3c.dom.Document; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; + +import org.l2jmobius.commons.util.IXmlReader; +import org.l2jmobius.gameserver.model.StatSet; +import org.l2jmobius.gameserver.model.holders.ItemHolder; +import org.l2jmobius.gameserver.model.homunculus.HomunculusSlotTemplate; + +/** + * @author Index + */ +public class HomunculusSlotData implements IXmlReader +{ + private final Map _templates = new HashMap<>(); + + protected HomunculusSlotData() + { + load(); + } + + @Override + public void load() + { + _templates.clear(); + parseDatapackFile("data/HomunculusSlotData.xml"); + LOGGER.info(getClass().getSimpleName() + ": Loaded " + _templates.size() + " templates."); + } + + @Override + public void parseDocument(Document doc, File f) + { + StatSet set; + Node att; + NamedNodeMap attrs; + for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling()) + { + if ("list".equalsIgnoreCase(n.getNodeName())) + { + for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling()) + { + if ("homunculusSlot".equalsIgnoreCase(d.getNodeName())) + { + attrs = d.getAttributes(); + set = new StatSet(); + for (int i = 0; i < attrs.getLength(); i++) + { + att = attrs.item(i); + set.set(att.getNodeName(), att.getNodeValue()); + } + + final int slotId = set.getInt("slotId"); + final Boolean isEnabled = set.getBoolean("isEnabled", false); + List fee = Collections.emptyList(); + + for (Node c = d.getFirstChild(); c != null; c = c.getNextSibling()) + { + if ("fee".equalsIgnoreCase(c.getNodeName())) + { + fee = getItemList(c); + } + } + _templates.put(slotId, new HomunculusSlotTemplate(slotId, fee, isEnabled)); + } + } + } + } + } + + private List getItemList(Node c) + { + final List items = new ArrayList<>(); + for (Node b = c.getFirstChild(); b != null; b = b.getNextSibling()) + { + if ("item".equalsIgnoreCase(b.getNodeName())) + { + final int itemId = Integer.parseInt(b.getAttributes().getNamedItem("id").getNodeValue()); + final long itemCount = Long.parseLong(b.getAttributes().getNamedItem("count").getNodeValue()); + items.add(new ItemHolder(itemId, itemCount)); + } + } + return items; + } + + public HomunculusSlotTemplate getTemplate(int id) + { + return _templates.get(id); + } + + public int size() + { + return _templates.size(); + } + + public static HomunculusSlotData getInstance() + { + return SingletonHolder.INSTANCE; + } + + private static class SingletonHolder + { + protected static final HomunculusSlotData INSTANCE = new HomunculusSlotData(); + } +} diff --git a/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/model/homunculus/HomunculusCreationTemplate.java b/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/model/homunculus/HomunculusCreationTemplate.java new file mode 100644 index 0000000000..8a9d603ba6 --- /dev/null +++ b/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/model/homunculus/HomunculusCreationTemplate.java @@ -0,0 +1,142 @@ +/* + * 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 . + */ +package org.l2jmobius.gameserver.model.homunculus; + +import java.util.List; + +import org.l2jmobius.gameserver.model.holders.ItemHolder; + +public class HomunculusCreationTemplate +{ + private final int _slotId; + private final boolean _isEnabled; + private final int _grade; + private final boolean _isEvent; + private final List _itemsFee; + private final Integer[] _hpFee; + private final Long[] _spFee; + private final Integer[] _vpFee; + private final long _time; + private final List _createChances; + + public HomunculusCreationTemplate(int slotId, boolean isEnabled, int grade, boolean isEvent, List itemsFee, Integer[] hpFee, Long[] spFee, Integer[] vpFee, long time, List createChances) + { + _slotId = slotId; + _isEnabled = isEnabled; + _grade = grade; + _isEvent = isEvent; + _itemsFee = itemsFee; + _hpFee = hpFee; + _spFee = spFee; + _vpFee = vpFee; + _time = time; + _createChances = createChances; + } + + public int getSlotId() + { + return _slotId; + } + + public boolean isEnabled() + { + return _isEnabled; + } + + public int getGrade() + { + return _grade; + } + + public boolean isEvent() + { + return _isEvent; + } + + public List getItemFee() + { + return _itemsFee; + } + + public boolean haveAnotherFee() + { + return !_itemsFee.isEmpty(); + } + + public int getHPFeeCountByUse() + { + return _hpFee[1]; + } + + public int getHPFeeCount() + { + return _hpFee[0]; + } + + public long getSPFeeCountByUse() + { + return _spFee[1]; + } + + public long getSPFeeCount() + { + return _spFee[0]; + } + + public int getVPFeeByUse() + { + return _vpFee[1]; + } + + public int getVPFeeCount() + { + return _vpFee[0]; + } + + public double getMaxChance() + { + double result = 0; + for (int i = 0; i < _createChances.size(); i++) + { + Double[] chance = _createChances.get(i); + result = result + chance[1]; + } + return result; + } + + public boolean isInstanceHaveCoupon(int itemId) + { + for (ItemHolder humu : _itemsFee) + { + if (humu.getId() == itemId) + { + return true; + } + } + return false; + } + + public long getCreationLime() + { + return _time; + } + + public List getCreationChance() + { + return _createChances; + } +} diff --git a/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/model/homunculus/HomunculusSlotTemplate.java b/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/model/homunculus/HomunculusSlotTemplate.java new file mode 100644 index 0000000000..6125633dd1 --- /dev/null +++ b/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/model/homunculus/HomunculusSlotTemplate.java @@ -0,0 +1,50 @@ +/* + * 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 . + */ +package org.l2jmobius.gameserver.model.homunculus; + +import java.util.List; + +import org.l2jmobius.gameserver.model.holders.ItemHolder; + +public class HomunculusSlotTemplate +{ + private final int _slotId; + private final List _price; + private final boolean _isEnabled; + + public HomunculusSlotTemplate(int slotId, List price, boolean isEnabled) + { + _slotId = slotId; + _price = price; + _isEnabled = isEnabled; + } + + public int getSlotId() + { + return _slotId; + } + + public List getPrice() + { + return _price; + } + + public boolean getSlotEnabled() + { + return _isEnabled; + } +} diff --git a/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/model/variables/PlayerVariables.java b/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/model/variables/PlayerVariables.java index 346db019d8..e40be28720 100644 --- a/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/model/variables/PlayerVariables.java +++ b/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/model/variables/PlayerVariables.java @@ -81,6 +81,7 @@ public class PlayerVariables extends AbstractVariables public static final String HOMUNCULUS_USED_VP_POINTS = "HOMUNCULUS_USED_VP_POINTS"; public static final String HOMUNCULUS_USED_VP_CONVERT = "HOMUNCULUS_USED_VP_CONVERT"; public static final String HOMUNCULUS_USED_RESET_VP = "HOMUNCULUS_USED_RESET_VP"; + public static final String HOMUNCULUS_OPENED_SLOT_COUNT = "HOMUNCULUS_OPENED_SLOT_COUNT"; private final int _objectId; diff --git a/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusActivateSlot.java b/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusActivateSlot.java index bb5463298d..6acd0c04a7 100644 --- a/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusActivateSlot.java +++ b/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusActivateSlot.java @@ -16,13 +16,20 @@ */ package org.l2jmobius.gameserver.network.clientpackets.homunculus; -import org.l2jmobius.Config; +import java.util.List; +import java.util.logging.Logger; + import org.l2jmobius.commons.network.PacketReader; +import org.l2jmobius.gameserver.data.xml.HomunculusSlotData; import org.l2jmobius.gameserver.model.actor.Player; -import org.l2jmobius.gameserver.model.homunculus.Homunculus; +import org.l2jmobius.gameserver.model.holders.ItemHolder; +import org.l2jmobius.gameserver.model.homunculus.HomunculusSlotTemplate; +import org.l2jmobius.gameserver.model.variables.PlayerVariables; import org.l2jmobius.gameserver.network.GameClient; +import org.l2jmobius.gameserver.network.PacketLogger; import org.l2jmobius.gameserver.network.clientpackets.IClientIncomingPacket; import org.l2jmobius.gameserver.network.serverpackets.homunculus.ExActivateHomunculusResult; +import org.l2jmobius.gameserver.network.serverpackets.homunculus.ExHomunculusPointInfo; import org.l2jmobius.gameserver.network.serverpackets.homunculus.ExShowHomunculusList; /** @@ -31,13 +38,12 @@ import org.l2jmobius.gameserver.network.serverpackets.homunculus.ExShowHomunculu public class RequestExHomunculusActivateSlot implements IClientIncomingPacket { private int _slot; - private boolean _activate; @Override public boolean read(GameClient client, PacketReader packet) { _slot = packet.readD(); - _activate = packet.readC() == 1; // enabled? + // _activate = packet.readC() == 1; // enabled? return true; } @@ -51,62 +57,46 @@ public class RequestExHomunculusActivateSlot implements IClientIncomingPacket } final int size = activeChar.getHomunculusList().size(); - if (size == 0) + final HomunculusSlotTemplate template = HomunculusSlotData.getInstance().getTemplate(_slot); + if ((size != 0) && ((activeChar.getHomunculusList().get(_slot) != null) || (_slot == activeChar.getVariables().getInt(PlayerVariables.HOMUNCULUS_OPENED_SLOT_COUNT)))) { + PacketLogger.info(getClass().getSimpleName() + " player " + activeChar.getName() + " " + activeChar.getObjectId() + " trying unlock already unlocked slot;"); + activeChar.sendPacket(new ExActivateHomunculusResult(false)); + return; + } + if (!template.getSlotEnabled()) + { + Logger.getLogger(getClass().getSimpleName() + " player " + activeChar.getName() + " " + activeChar.getObjectId() + " trying unlock disabled slot;"); + activeChar.sendPacket(new ExActivateHomunculusResult(false)); return; } - final Homunculus homunculus = activeChar.getHomunculusList().get(_slot); - if (homunculus == null) + final List fee = template.getPrice(); + for (int i = 0; i < fee.size(); i++) { - return; - } - - for (int i = 0; i < Config.MAX_HOMUNCULUS_COUNT; i++) - { - if (size <= i) + final ItemHolder feeHolder = fee.get(i); + if ((activeChar.getInventory().getItemByItemId(feeHolder.getId()) == null) || ((activeChar.getInventory().getItemByItemId(feeHolder.getId()) != null) && (activeChar.getInventory().getItemByItemId(feeHolder.getId()).getCount() < feeHolder.getCount()))) { - break; - } - - final Homunculus homu = activeChar.getHomunculusList().get(i); - if (homu == null) - { - continue; - } - - if (homu.isActive()) - { - homu.setActive(false); - activeChar.getHomunculusList().update(homu); - activeChar.getHomunculusList().refreshStats(true); - activeChar.sendPacket(new ExShowHomunculusList(activeChar)); activeChar.sendPacket(new ExActivateHomunculusResult(false)); + return; + } + } + for (int i = 0; i < fee.size(); i++) + { + final ItemHolder feeHolder = fee.get(i); + if (activeChar.getInventory().destroyItemByItemId("Homunclus slot unlock", feeHolder.getId(), feeHolder.getCount(), activeChar, null) == null) + { + Logger.getLogger(getClass().getSimpleName() + " player " + activeChar.getName() + " " + activeChar.getObjectId() + " trying unlock slot without items;"); + activeChar.sendPacket(new ExActivateHomunculusResult(false)); + return; } } - if (_activate) - { - if (!homunculus.isActive()) - { - - homunculus.setActive(true); - activeChar.getHomunculusList().update(homunculus); - activeChar.getHomunculusList().refreshStats(true); - activeChar.sendPacket(new ExShowHomunculusList(activeChar)); - activeChar.sendPacket(new ExActivateHomunculusResult(true)); - } - } - else - { - if (homunculus.isActive()) - { - homunculus.setActive(false); - activeChar.getHomunculusList().update(homunculus); - activeChar.getHomunculusList().refreshStats(true); - activeChar.sendPacket(new ExShowHomunculusList(activeChar)); - activeChar.sendPacket(new ExActivateHomunculusResult(false)); - } - } + activeChar.sendItemList(); + activeChar.broadcastUserInfo(); + activeChar.getVariables().set(PlayerVariables.HOMUNCULUS_OPENED_SLOT_COUNT, _slot); + activeChar.sendPacket(new ExHomunculusPointInfo(activeChar)); + activeChar.sendPacket(new ExShowHomunculusList(activeChar)); + activeChar.sendPacket(new ExActivateHomunculusResult(true)); } } diff --git a/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusCreateStart.java b/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusCreateStart.java index dec3277cf4..b3b5c331de 100644 --- a/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusCreateStart.java +++ b/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusCreateStart.java @@ -17,7 +17,9 @@ package org.l2jmobius.gameserver.network.clientpackets.homunculus; import org.l2jmobius.commons.network.PacketReader; +import org.l2jmobius.gameserver.data.xml.HomunculusCreationData; import org.l2jmobius.gameserver.model.actor.Player; +import org.l2jmobius.gameserver.model.homunculus.HomunculusCreationTemplate; import org.l2jmobius.gameserver.model.variables.PlayerVariables; import org.l2jmobius.gameserver.network.GameClient; import org.l2jmobius.gameserver.network.SystemMessageId; @@ -30,8 +32,9 @@ import org.l2jmobius.gameserver.network.serverpackets.homunculus.ExShowHomunculu */ public class RequestExHomunculusCreateStart implements IClientIncomingPacket { - private static final int COST = 1000000; - private static final long CREATION_TIME = 86400000L; + private static final HomunculusCreationTemplate TEMPLATE = HomunculusCreationData.getInstance().getTemplate(0); + private static final int COST = Math.toIntExact(TEMPLATE.getItemFee().get(0).getCount()); + private static final long CREATION_TIME = TEMPLATE.getCreationLime(); @Override public boolean read(GameClient client, PacketReader packet) @@ -53,6 +56,7 @@ public class RequestExHomunculusCreateStart implements IClientIncomingPacket player.sendPacket(SystemMessageId.YOU_DO_NOT_HAVE_ENOUGH_ADENA_2); return; } + player.reduceAdena("Homunculus creation", COST, player, true); player.getVariables().set(PlayerVariables.HOMUNCULUS_CREATION_TIME, System.currentTimeMillis() + CREATION_TIME); diff --git a/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusInsert.java b/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusInsert.java index 6a2e480084..dde47a5571 100644 --- a/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusInsert.java +++ b/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusInsert.java @@ -17,8 +17,9 @@ package org.l2jmobius.gameserver.network.clientpackets.homunculus; import org.l2jmobius.commons.network.PacketReader; +import org.l2jmobius.gameserver.data.xml.HomunculusCreationData; import org.l2jmobius.gameserver.model.actor.Player; -import org.l2jmobius.gameserver.model.actor.stat.PlayerStat; +import org.l2jmobius.gameserver.model.homunculus.HomunculusCreationTemplate; import org.l2jmobius.gameserver.model.variables.PlayerVariables; import org.l2jmobius.gameserver.network.GameClient; import org.l2jmobius.gameserver.network.clientpackets.IClientIncomingPacket; @@ -31,9 +32,10 @@ import org.l2jmobius.gameserver.network.serverpackets.homunculus.ExShowHomunculu */ public class RequestExHomunculusInsert implements IClientIncomingPacket { - private static final short HP_COST = 10000; - private static final long SP_COST = 5000000000L; - private static final int VP_COST = PlayerStat.MAX_VITALITY_POINTS / 4; + private static final HomunculusCreationTemplate TEMPLATE = HomunculusCreationData.getInstance().getTemplate(0); + private static final short HP_COST = (short) TEMPLATE.getHPFeeCountByUse(); + private static final long SP_COST = TEMPLATE.getSPFeeCountByUse(); + private static final int VP_COST = TEMPLATE.getVPFeeByUse(); private int _type; @@ -59,7 +61,7 @@ public class RequestExHomunculusInsert implements IClientIncomingPacket { case 0: { - if ((player.getCurrentHp() > HP_COST) && (hpPoints < 100)) + if ((player.getCurrentHp() > HP_COST) && (hpPoints < TEMPLATE.getHPFeeCount())) { int newHp = (int) (player.getCurrentHp()) - HP_COST; player.setCurrentHp(newHp, true); @@ -74,7 +76,7 @@ public class RequestExHomunculusInsert implements IClientIncomingPacket } case 1: { - if ((player.getSp() >= SP_COST) && (spPoints < 10)) + if ((player.getSp() >= SP_COST) && (spPoints < TEMPLATE.getSPFeeCount())) { player.setSp(player.getSp() - SP_COST); spPoints += 1; @@ -88,7 +90,7 @@ public class RequestExHomunculusInsert implements IClientIncomingPacket } case 2: { - if ((player.getVitalityPoints() >= VP_COST) && (vpPoints < 5)) + if ((player.getVitalityPoints() >= VP_COST) && (vpPoints < TEMPLATE.getVPFeeCount())) { int newVitality = player.getVitalityPoints() - VP_COST; player.setVitalityPoints(newVitality, true); diff --git a/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusSummon.java b/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusSummon.java index f1a28c90e8..c7acfe0cc6 100644 --- a/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusSummon.java +++ b/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusSummon.java @@ -18,9 +18,11 @@ package org.l2jmobius.gameserver.network.clientpackets.homunculus; import org.l2jmobius.commons.network.PacketReader; import org.l2jmobius.commons.util.Rnd; +import org.l2jmobius.gameserver.data.xml.HomunculusCreationData; import org.l2jmobius.gameserver.data.xml.HomunculusData; import org.l2jmobius.gameserver.model.actor.Player; import org.l2jmobius.gameserver.model.homunculus.Homunculus; +import org.l2jmobius.gameserver.model.homunculus.HomunculusCreationTemplate; import org.l2jmobius.gameserver.model.homunculus.HomunculusTemplate; import org.l2jmobius.gameserver.model.variables.PlayerVariables; import org.l2jmobius.gameserver.network.GameClient; @@ -29,12 +31,15 @@ import org.l2jmobius.gameserver.network.clientpackets.IClientIncomingPacket; import org.l2jmobius.gameserver.network.serverpackets.homunculus.ExHomunculusSummonResult; import org.l2jmobius.gameserver.network.serverpackets.homunculus.ExShowHomunculusBirthInfo; import org.l2jmobius.gameserver.network.serverpackets.homunculus.ExShowHomunculusList; +import org.l2jmobius.gameserver.network.serverpackets.homunculus.ExSummonHomunculusCouponResult; /** * @author Mobius */ public class RequestExHomunculusSummon implements IClientIncomingPacket { + private static final HomunculusCreationTemplate TEMPLATE = HomunculusCreationData.getInstance().getTemplate(0); + @Override public boolean read(GameClient client, PacketReader packet) { @@ -56,148 +61,27 @@ public class RequestExHomunculusSummon implements IClientIncomingPacket final int vpPoints = player.getVariables().getInt(PlayerVariables.HOMUNCULUS_VP_POINTS, 0); final int homunculusCreateTime = (int) (player.getVariables().getLong(PlayerVariables.HOMUNCULUS_CREATION_TIME, 0) / 1000); - if ((homunculusCreateTime > 0) && ((System.currentTimeMillis() / 1000) >= homunculusCreateTime) && (hpPoints == 100) && (spPoints == 10) && (vpPoints == 5)) + if ((homunculusCreateTime > 0) && ((System.currentTimeMillis() / 1000) >= homunculusCreateTime) && (hpPoints == TEMPLATE.getHPFeeCount()) && (spPoints == TEMPLATE.getSPFeeCount()) && (vpPoints == TEMPLATE.getVPFeeCount())) { - int chance; - int random; + double chance = Rnd.get(100.0); + double current = 0; int homunculusId = 0; while (homunculusId == 0) { - chance = Rnd.get(100); - random = Rnd.get(100); - - // Basic Homunculus - if (chance >= 60) + if (chance > TEMPLATE.getMaxChance()) { - if ((random >= 90) && !player.getHomunculusList().hasHomunculus(1)) - { - homunculusId = 1; - } - else if ((random >= 80) && !player.getHomunculusList().hasHomunculus(4)) - { - homunculusId = 4; - } - else if ((random >= 70) && !player.getHomunculusList().hasHomunculus(7)) - { - homunculusId = 7; - } - else if ((random >= 60) && !player.getHomunculusList().hasHomunculus(10)) - { - homunculusId = 10; - } - else if ((random >= 50) && !player.getHomunculusList().hasHomunculus(13)) - { - homunculusId = 13; - } - else if ((random >= 40) && !player.getHomunculusList().hasHomunculus(16)) - { - homunculusId = 16; - } - else if ((random >= 30) && !player.getHomunculusList().hasHomunculus(19)) - { - homunculusId = 19; - } - else if ((random >= 20) && !player.getHomunculusList().hasHomunculus(22)) - { - homunculusId = 22; - } - else if ((random >= 10) && !player.getHomunculusList().hasHomunculus(25)) - { - homunculusId = 25; - } - else if (!player.getHomunculusList().hasHomunculus(28)) - { - homunculusId = 28; - } + player.sendMessage("Homunculus is not created!"); + player.sendPacket(new ExSummonHomunculusCouponResult(0, 0)); + return; } - - // Water Homunculus - if ((homunculusId == 0) && (chance >= 10)) + for (int i = 0; i < TEMPLATE.getCreationChance().size(); i++) { - if ((random >= 90) && !player.getHomunculusList().hasHomunculus(2)) + final Double[] homuHolder = TEMPLATE.getCreationChance().get(i); + current += homuHolder[1]; + if (current >= chance) { - homunculusId = 2; - } - else if ((random >= 80) && !player.getHomunculusList().hasHomunculus(5)) - { - homunculusId = 5; - } - else if ((random >= 70) && !player.getHomunculusList().hasHomunculus(8)) - { - homunculusId = 8; - } - else if ((random >= 60) && !player.getHomunculusList().hasHomunculus(11)) - { - homunculusId = 11; - } - else if ((random >= 50) && !player.getHomunculusList().hasHomunculus(14)) - { - homunculusId = 14; - } - else if ((random >= 40) && !player.getHomunculusList().hasHomunculus(17)) - { - homunculusId = 17; - } - else if ((random >= 30) && !player.getHomunculusList().hasHomunculus(20)) - { - homunculusId = 20; - } - else if ((random >= 20) && !player.getHomunculusList().hasHomunculus(23)) - { - homunculusId = 23; - } - else if ((random >= 10) && !player.getHomunculusList().hasHomunculus(26)) - { - homunculusId = 26; - } - else if (!player.getHomunculusList().hasHomunculus(29)) - { - homunculusId = 29; - } - } - - // Luminous Homunculus - if (homunculusId == 0) - { - if ((random >= 90) && !player.getHomunculusList().hasHomunculus(3)) - { - homunculusId = 3; - } - else if ((random >= 80) && !player.getHomunculusList().hasHomunculus(6)) - { - homunculusId = 6; - } - else if ((random >= 70) && !player.getHomunculusList().hasHomunculus(9)) - { - homunculusId = 9; - } - else if ((random >= 60) && !player.getHomunculusList().hasHomunculus(12)) - { - homunculusId = 12; - } - else if ((random >= 50) && !player.getHomunculusList().hasHomunculus(15)) - { - homunculusId = 15; - } - else if ((random >= 40) && !player.getHomunculusList().hasHomunculus(18)) - { - homunculusId = 18; - } - else if ((random >= 30) && !player.getHomunculusList().hasHomunculus(21)) - { - homunculusId = 21; - } - else if ((random >= 20) && !player.getHomunculusList().hasHomunculus(24)) - { - homunculusId = 24; - } - else if ((random >= 10) && !player.getHomunculusList().hasHomunculus(27)) - { - homunculusId = 27; - } - else if (!player.getHomunculusList().hasHomunculus(30)) - { - homunculusId = 30; + homunculusId = homuHolder[0].intValue(); + break; } } } diff --git a/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExSummonHomunculusCouponResult.java b/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExSummonHomunculusCouponResult.java index 9c9096d387..4d369cf581 100644 --- a/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExSummonHomunculusCouponResult.java +++ b/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExSummonHomunculusCouponResult.java @@ -18,10 +18,14 @@ package org.l2jmobius.gameserver.network.clientpackets.homunculus; import org.l2jmobius.commons.network.PacketReader; import org.l2jmobius.commons.util.Rnd; +import org.l2jmobius.gameserver.data.xml.HomunculusCreationData; import org.l2jmobius.gameserver.data.xml.HomunculusData; import org.l2jmobius.gameserver.model.actor.Player; +import org.l2jmobius.gameserver.model.holders.ItemHolder; import org.l2jmobius.gameserver.model.homunculus.Homunculus; +import org.l2jmobius.gameserver.model.homunculus.HomunculusCreationTemplate; import org.l2jmobius.gameserver.model.homunculus.HomunculusTemplate; +import org.l2jmobius.gameserver.model.variables.PlayerVariables; import org.l2jmobius.gameserver.network.GameClient; import org.l2jmobius.gameserver.network.PacketLogger; import org.l2jmobius.gameserver.network.clientpackets.IClientIncomingPacket; @@ -34,15 +38,12 @@ import org.l2jmobius.gameserver.network.serverpackets.homunculus.ExSummonHomuncu */ public class RequestExSummonHomunculusCouponResult implements IClientIncomingPacket { - private static final int HOURGLASS = 81815; - private static final int HOURGLASS_SHINY = 81879; - private static final int ADENA = 57; - private static final int ADENA_COUNT = 2000000; + private int _item_id; @Override public boolean read(GameClient client, PacketReader packet) { - // packet.readD(); + _item_id = packet.readD(); return true; } @@ -55,161 +56,64 @@ public class RequestExSummonHomunculusCouponResult implements IClientIncomingPac return; } - // Take items. - if ((player.getInventory().getItemByItemId(HOURGLASS) != null) && (player.getInventory().getItemByItemId(ADENA).getCount() > ADENA_COUNT)) - { - player.destroyItemByItemId("Homunculus Hourglass", HOURGLASS, 1, player, true); - } - else if ((player.getInventory().getItemByItemId(HOURGLASS_SHINY) != null) && (player.getInventory().getItemByItemId(ADENA).getCount() >= ADENA_COUNT)) - { - player.destroyItemByItemId("Shiny Homunculus Hourglass", HOURGLASS_SHINY, 1, player, true); - } - else + if (player.getHomunculusList().size() == player.getVariables().getInt(PlayerVariables.HOMUNCULUS_OPENED_SLOT_COUNT)) { + player.sendPacket(new ExSummonHomunculusCouponResult(0, 0)); + PacketLogger.info("Player " + player.getObjectId() + " " + player.getName() + ", trying create homunculus withouts avaible slots;"); + return; + } + HomunculusCreationTemplate creationTemplate = null; + for (int i = 1; i < HomunculusCreationData.getInstance().size(); i++) + { + if (HomunculusCreationData.getInstance().getTemplate(i).isInstanceHaveCoupon(_item_id)) + { + creationTemplate = HomunculusCreationData.getInstance().getTemplate(i); + } + } + if ((creationTemplate == null) || (creationTemplate.getItemFee().size() == 0)) + { + PacketLogger.info("Player " + player.getObjectId() + " " + player.getName() + ", trying create homunculus with not existing coupon!"); return; } - player.destroyItemByItemId("Adena", ADENA, 2000000, player, true); - int chance; - int random; + // Take items. + for (int i = 0; i < creationTemplate.getItemFee().size(); i++) + { + ItemHolder humu = creationTemplate.getItemFee().get(i); + if (player.getInventory().getItemByItemId(humu.getId()).getCount() <= humu.getCount()) + { + return; + } + } + for (int i = 0; i < creationTemplate.getItemFee().size(); i++) + { + ItemHolder humu = creationTemplate.getItemFee().get(i); + if (!player.destroyItemByItemId("Homunculus Coupon Creation", humu.getId(), humu.getCount(), player, true)) + { + PacketLogger.info("Player " + player.getObjectId() + " " + player.getName() + ", trying create homunculus without " + humu + "!"); + return; + } + } + + double chance = Rnd.get(100.0); + double current = 0; int homunculusId = 0; while (homunculusId == 0) { - chance = Rnd.get(100); - random = Rnd.get(100); - - // Basic Homunculus - if (chance >= 60) + if (chance > creationTemplate.getMaxChance()) { - if ((random >= 90) && !player.getHomunculusList().hasHomunculus(1)) - { - homunculusId = 1; - } - else if ((random >= 80) && !player.getHomunculusList().hasHomunculus(4)) - { - homunculusId = 4; - } - else if ((random >= 70) && !player.getHomunculusList().hasHomunculus(7)) - { - homunculusId = 7; - } - else if ((random >= 60) && !player.getHomunculusList().hasHomunculus(10)) - { - homunculusId = 10; - } - else if ((random >= 50) && !player.getHomunculusList().hasHomunculus(13)) - { - homunculusId = 13; - } - else if ((random >= 40) && !player.getHomunculusList().hasHomunculus(16)) - { - homunculusId = 16; - } - else if ((random >= 30) && !player.getHomunculusList().hasHomunculus(19)) - { - homunculusId = 19; - } - else if ((random >= 20) && !player.getHomunculusList().hasHomunculus(22)) - { - homunculusId = 22; - } - else if ((random >= 10) && !player.getHomunculusList().hasHomunculus(25)) - { - homunculusId = 25; - } - else if (!player.getHomunculusList().hasHomunculus(28)) - { - homunculusId = 28; - } + player.sendMessage("Homunculus is not created!"); + player.sendPacket(new ExSummonHomunculusCouponResult(0, 0)); + return; } - - // Water Homunculus - if ((homunculusId == 0) && (chance >= 10)) + for (int i = 0; i < creationTemplate.getCreationChance().size(); i++) { - if ((random >= 90) && !player.getHomunculusList().hasHomunculus(2)) + final Double[] homuHolder = creationTemplate.getCreationChance().get(i); + current += homuHolder[1]; + if (current >= chance) { - homunculusId = 2; - } - else if ((random >= 80) && !player.getHomunculusList().hasHomunculus(5)) - { - homunculusId = 5; - } - else if ((random >= 70) && !player.getHomunculusList().hasHomunculus(8)) - { - homunculusId = 8; - } - else if ((random >= 60) && !player.getHomunculusList().hasHomunculus(11)) - { - homunculusId = 11; - } - else if ((random >= 50) && !player.getHomunculusList().hasHomunculus(14)) - { - homunculusId = 14; - } - else if ((random >= 40) && !player.getHomunculusList().hasHomunculus(17)) - { - homunculusId = 17; - } - else if ((random >= 30) && !player.getHomunculusList().hasHomunculus(20)) - { - homunculusId = 20; - } - else if ((random >= 20) && !player.getHomunculusList().hasHomunculus(23)) - { - homunculusId = 23; - } - else if ((random >= 10) && !player.getHomunculusList().hasHomunculus(26)) - { - homunculusId = 26; - } - else if (!player.getHomunculusList().hasHomunculus(29)) - { - homunculusId = 29; - } - } - - // Luminous Homunculus - if (homunculusId == 0) - { - if ((random >= 90) && !player.getHomunculusList().hasHomunculus(3)) - { - homunculusId = 3; - } - else if ((random >= 80) && !player.getHomunculusList().hasHomunculus(6)) - { - homunculusId = 6; - } - else if ((random >= 70) && !player.getHomunculusList().hasHomunculus(9)) - { - homunculusId = 9; - } - else if ((random >= 60) && !player.getHomunculusList().hasHomunculus(12)) - { - homunculusId = 12; - } - else if ((random >= 50) && !player.getHomunculusList().hasHomunculus(15)) - { - homunculusId = 15; - } - else if ((random >= 40) && !player.getHomunculusList().hasHomunculus(18)) - { - homunculusId = 18; - } - else if ((random >= 30) && !player.getHomunculusList().hasHomunculus(21)) - { - homunculusId = 21; - } - else if ((random >= 20) && !player.getHomunculusList().hasHomunculus(24)) - { - homunculusId = 24; - } - else if ((random >= 10) && !player.getHomunculusList().hasHomunculus(27)) - { - homunculusId = 27; - } - else if (!player.getHomunculusList().hasHomunculus(30)) - { - homunculusId = 30; + homunculusId = homuHolder[0].intValue(); + break; } } } diff --git a/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExHomunculusPointInfo.java b/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExHomunculusPointInfo.java index f26aefd800..550e908a64 100644 --- a/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExHomunculusPointInfo.java +++ b/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExHomunculusPointInfo.java @@ -16,7 +16,6 @@ */ package org.l2jmobius.gameserver.network.serverpackets.homunculus; -import org.l2jmobius.Config; import org.l2jmobius.commons.network.PacketWriter; import org.l2jmobius.gameserver.model.actor.Player; import org.l2jmobius.gameserver.model.variables.PlayerVariables; @@ -46,7 +45,7 @@ public class ExHomunculusPointInfo implements IClientOutgoingPacket packet.writeD(_player.getVariables().getInt(PlayerVariables.HOMUNCULUS_USED_VP_POINTS, 0)); // vp points packet.writeD(_player.getVariables().getInt(PlayerVariables.HOMUNCULUS_USED_VP_CONVERT, 0)); // consumed basic vp points packet.writeD(_player.getVariables().getInt(PlayerVariables.HOMUNCULUS_USED_RESET_VP, 0)); // consumed reset vp points - packet.writeD(Math.min(Config.MAX_HOMUNCULUS_COUNT, _player.getHomunculusList().size() + 1)); // 306 + packet.writeD(_player.getVariables().getInt(PlayerVariables.HOMUNCULUS_OPENED_SLOT_COUNT)); // 306 return true; } } diff --git a/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExShowHomunculusBirthInfo.java b/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExShowHomunculusBirthInfo.java index cdc24a4c11..33d7857cba 100644 --- a/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExShowHomunculusBirthInfo.java +++ b/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExShowHomunculusBirthInfo.java @@ -17,7 +17,9 @@ package org.l2jmobius.gameserver.network.serverpackets.homunculus; import org.l2jmobius.commons.network.PacketWriter; +import org.l2jmobius.gameserver.data.xml.HomunculusCreationData; import org.l2jmobius.gameserver.model.actor.Player; +import org.l2jmobius.gameserver.model.homunculus.HomunculusCreationTemplate; import org.l2jmobius.gameserver.model.variables.PlayerVariables; import org.l2jmobius.gameserver.network.OutgoingPackets; import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket; @@ -27,10 +29,15 @@ import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket; */ public class ExShowHomunculusBirthInfo implements IClientOutgoingPacket { + private static final HomunculusCreationTemplate TEMPLATE = HomunculusCreationData.getInstance().getTemplate(0); + private final int _hpPoints; private final int _spPoints; private final int _vpPoints; private final int _homunculusCreateTime; + private final int _feeHpPoints; + private final int _feeSpPoints; + private final int _feeVpPoints; public ExShowHomunculusBirthInfo(Player player) { @@ -38,6 +45,9 @@ public class ExShowHomunculusBirthInfo implements IClientOutgoingPacket _spPoints = player.getVariables().getInt(PlayerVariables.HOMUNCULUS_SP_POINTS, 0); _vpPoints = player.getVariables().getInt(PlayerVariables.HOMUNCULUS_VP_POINTS, 0); _homunculusCreateTime = (int) (player.getVariables().getLong(PlayerVariables.HOMUNCULUS_CREATION_TIME, 0) / 1000); + _feeHpPoints = TEMPLATE.getHPFeeCount(); + _feeSpPoints = (int) TEMPLATE.getSPFeeCount(); + _feeVpPoints = TEMPLATE.getVPFeeCount(); } @Override @@ -47,7 +57,7 @@ public class ExShowHomunculusBirthInfo implements IClientOutgoingPacket int creationStage = 0; if (_homunculusCreateTime > 0) { - if (((System.currentTimeMillis() / 1000) >= _homunculusCreateTime) && (_hpPoints == 100) && (_spPoints == 10) && (_vpPoints == 5)) + if (((System.currentTimeMillis() / 1000) >= _homunculusCreateTime) && (_hpPoints == _feeHpPoints) && (_spPoints == _feeSpPoints) && (_vpPoints == _feeVpPoints)) { creationStage = 2; } @@ -60,8 +70,8 @@ public class ExShowHomunculusBirthInfo implements IClientOutgoingPacket packet.writeD(_hpPoints); // hp points packet.writeD(_spPoints); // sp points packet.writeD(_vpPoints); // vp points - packet.writeD(_homunculusCreateTime); // finish time - packet.writeD(0); // JP = 0. ? + packet.writeQ(_homunculusCreateTime); // finish time + // packet.writeD(0); // JP = 0. ? return true; } } diff --git a/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExShowHomunculusList.java b/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExShowHomunculusList.java index 74372f0878..28369f119f 100644 --- a/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExShowHomunculusList.java +++ b/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExShowHomunculusList.java @@ -16,10 +16,10 @@ */ package org.l2jmobius.gameserver.network.serverpackets.homunculus; -import org.l2jmobius.Config; import org.l2jmobius.commons.network.PacketWriter; import org.l2jmobius.gameserver.model.actor.Player; import org.l2jmobius.gameserver.model.homunculus.Homunculus; +import org.l2jmobius.gameserver.model.variables.PlayerVariables; import org.l2jmobius.gameserver.network.OutgoingPackets; import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket; @@ -38,18 +38,34 @@ public class ExShowHomunculusList implements IClientOutgoingPacket @Override public boolean write(PacketWriter packet) { - OutgoingPackets.EX_SHOW_HOMUNCULUS_LIST.writeId(packet); - if (_player.getHomunculusList().size() > 0) + if ((_player.getVariables().getInt(PlayerVariables.HOMUNCULUS_OPENED_SLOT_COUNT, 0) == 0) || (_player.getVariables().getInt(PlayerVariables.HOMUNCULUS_OPENED_SLOT_COUNT) == 1) || (_player.getVariables().getInt(PlayerVariables.HOMUNCULUS_OPENED_SLOT_COUNT) == 2)) { - packet.writeD(_player.getHomunculusList().size()); // homunculus count - int counter = 0; - for (int i = 0; i < Config.MAX_HOMUNCULUS_COUNT; i++) + if ((_player.getHomunculusList() != null) && (_player.getHomunculusList().size() != 0) && (_player.getHomunculusList().size() < 2)) + { + if (_player.getVariables().getInt(PlayerVariables.HOMUNCULUS_CREATION_TIME, 0) >= 0) + { + _player.getVariables().set(PlayerVariables.HOMUNCULUS_OPENED_SLOT_COUNT, _player.getHomunculusList().size() + 1); + } + else + { + _player.getVariables().set(PlayerVariables.HOMUNCULUS_OPENED_SLOT_COUNT, _player.getHomunculusList().size()); + } + } + else + { + _player.getVariables().set(PlayerVariables.HOMUNCULUS_OPENED_SLOT_COUNT, 3); + } + } + + final int slotCount = _player.getVariables().getInt(PlayerVariables.HOMUNCULUS_OPENED_SLOT_COUNT); + OutgoingPackets.EX_SHOW_HOMUNCULUS_LIST.writeId(packet); + packet.writeD(slotCount); + int counter = 0; + for (int i = 0; i <= slotCount; i++) + { + if (_player.getHomunculusList().get(i) != null) { final Homunculus homunculus = _player.getHomunculusList().get(i); - if (homunculus == null) - { - continue; - } packet.writeD(counter); // slot packet.writeD(homunculus.getId()); // homunculus id packet.writeD(homunculus.getType()); @@ -72,13 +88,33 @@ public class ExShowHomunculusList implements IClientOutgoingPacket packet.writeD(homunculus.getAtk()); packet.writeD(homunculus.getDef()); packet.writeD(homunculus.getCritRate()); - counter++; } + else + { + packet.writeD(counter); // slot + packet.writeD(0); // homunculus id + packet.writeD(0); + packet.writeC(0); + packet.writeD(0); + for (int j = 1; j <= 5; j++) + { + packet.writeD(0); + } + packet.writeD(0); + for (int j = 1; j <= 5; j++) + { + packet.writeD(0); + } + packet.writeD(0);// m_nLevel + packet.writeD(0);// m_nHP + packet.writeD(0);// m_nHP + packet.writeD(0);// m_nAttack + packet.writeD(0);// m_nDefence + packet.writeD(0);// m_nCritical + } + counter++; } - else - { - packet.writeD(0); - } + return true; } } diff --git a/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExSummonHomunculusCouponResult.java b/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExSummonHomunculusCouponResult.java index 28c7d148e2..22597b6716 100644 --- a/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExSummonHomunculusCouponResult.java +++ b/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExSummonHomunculusCouponResult.java @@ -26,17 +26,31 @@ import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket; public class ExSummonHomunculusCouponResult implements IClientOutgoingPacket { private final int _slot; + private int _success = -1; public ExSummonHomunculusCouponResult(int slot) { _slot = slot; } + public ExSummonHomunculusCouponResult(int slot, int success) + { + _slot = slot; + _success = success; + } + @Override public boolean write(PacketWriter packet) { OutgoingPackets.EX_SUMMON_HOMUNCULUS_COUPON_RESULT.writeId(packet); - packet.writeD(1); // 1 - success + if (_success == -1) + { + packet.writeD(1); // 1 - success + } + else + { + packet.writeD(_success); + } packet.writeD(_slot); // homunculus slot packet.writeD(0); // keep or delete return true; diff --git a/L2J_Mobius_10.1_MasterClass/dist/game/data/HomunculusCreationData.xml b/L2J_Mobius_10.1_MasterClass/dist/game/data/HomunculusCreationData.xml new file mode 100644 index 0000000000..4b5ff8244e --- /dev/null +++ b/L2J_Mobius_10.1_MasterClass/dist/game/data/HomunculusCreationData.xml @@ -0,0 +1,100 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/L2J_Mobius_10.1_MasterClass/dist/game/data/HomunculusSlotData.xml b/L2J_Mobius_10.1_MasterClass/dist/game/data/HomunculusSlotData.xml new file mode 100644 index 0000000000..0b336dd5d6 --- /dev/null +++ b/L2J_Mobius_10.1_MasterClass/dist/game/data/HomunculusSlotData.xml @@ -0,0 +1,150 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/L2J_Mobius_10.1_MasterClass/dist/game/data/xsd/HomunculusCreationData.xsd b/L2J_Mobius_10.1_MasterClass/dist/game/data/xsd/HomunculusCreationData.xsd new file mode 100644 index 0000000000..8331a269fb --- /dev/null +++ b/L2J_Mobius_10.1_MasterClass/dist/game/data/xsd/HomunculusCreationData.xsd @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/L2J_Mobius_10.1_MasterClass/dist/game/data/xsd/HomunculusSlotData.xsd b/L2J_Mobius_10.1_MasterClass/dist/game/data/xsd/HomunculusSlotData.xsd new file mode 100644 index 0000000000..73e250515d --- /dev/null +++ b/L2J_Mobius_10.1_MasterClass/dist/game/data/xsd/HomunculusSlotData.xsd @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/GameServer.java b/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/GameServer.java index 1b17a02ea9..29dae8dc2e 100644 --- a/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/GameServer.java +++ b/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/GameServer.java @@ -76,7 +76,9 @@ import org.l2jmobius.gameserver.data.xml.FenceData; import org.l2jmobius.gameserver.data.xml.FishingData; import org.l2jmobius.gameserver.data.xml.HennaData; import org.l2jmobius.gameserver.data.xml.HitConditionBonusData; +import org.l2jmobius.gameserver.data.xml.HomunculusCreationData; import org.l2jmobius.gameserver.data.xml.HomunculusData; +import org.l2jmobius.gameserver.data.xml.HomunculusSlotData; import org.l2jmobius.gameserver.data.xml.InitialEquipmentData; import org.l2jmobius.gameserver.data.xml.InitialShortcutData; import org.l2jmobius.gameserver.data.xml.ItemCrystallizationData; @@ -343,6 +345,8 @@ public class GameServer GrandBossManager.getInstance(); EventDropManager.getInstance(); HomunculusData.getInstance(); + HomunculusSlotData.getInstance(); + HomunculusCreationData.getInstance(); printSection("Instance"); InstanceManager.getInstance(); diff --git a/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/data/xml/HomunculusCreationData.java b/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/data/xml/HomunculusCreationData.java new file mode 100644 index 0000000000..088ebb8432 --- /dev/null +++ b/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/data/xml/HomunculusCreationData.java @@ -0,0 +1,175 @@ +/* + * 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 . + */ +package org.l2jmobius.gameserver.data.xml; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.w3c.dom.Document; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; + +import org.l2jmobius.commons.util.IXmlReader; +import org.l2jmobius.gameserver.model.StatSet; +import org.l2jmobius.gameserver.model.holders.ItemHolder; +import org.l2jmobius.gameserver.model.homunculus.HomunculusCreationTemplate; + +/** + * @author Index + */ +public class HomunculusCreationData implements IXmlReader +{ + private final Map _templates = new HashMap<>(); + + protected HomunculusCreationData() + { + load(); + } + + @Override + public void load() + { + _templates.clear(); + parseDatapackFile("data/HomunculusCreationData.xml"); + LOGGER.info(getClass().getSimpleName() + ": Loaded " + _templates.size() + " templates."); + } + + @Override + public void parseDocument(Document doc, File f) + { + StatSet set; + Node att; + NamedNodeMap attrs; + for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling()) + { + if ("list".equalsIgnoreCase(n.getNodeName())) + { + for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling()) + { + if ("homunculusCreation".equalsIgnoreCase(d.getNodeName())) + { + attrs = d.getAttributes(); + set = new StatSet(); + for (int i = 0; i < attrs.getLength(); i++) + { + att = attrs.item(i); + set.set(att.getNodeName(), att.getNodeValue()); + } + + final int slotId = set.getInt("slotId", 0); + final Boolean isEnabled = set.getBoolean("isEnabled", false); + final int grade = set.getInt("grade", 0); + final Boolean isEvent = set.getBoolean("event", false); + List itemFees = Collections.emptyList(); + Integer[] hpFee = new Integer[2]; + Long[] spFee = new Long[2]; + Integer[] vpFee = new Integer[2]; + long time = 0; + List chances = Collections.emptyList(); + for (Node b = d.getFirstChild(); b != null; b = b.getNextSibling()) + { + if ("itemFees".equalsIgnoreCase(b.getNodeName())) + { + itemFees = getItemList(b); + } + else if ("hpFee".equalsIgnoreCase(b.getNodeName())) + { + hpFee[0] = Integer.parseInt(b.getAttributes().getNamedItem("count").getNodeValue()); + hpFee[1] = Integer.parseInt(b.getAttributes().getNamedItem("byUse").getNodeValue()); + } + else if ("spFee".equalsIgnoreCase(b.getNodeName())) + { + spFee[0] = Long.parseLong(b.getAttributes().getNamedItem("count").getNodeValue()); + spFee[1] = Long.parseLong(b.getAttributes().getNamedItem("byUse").getNodeValue()); + } + else if ("vpFee".equalsIgnoreCase(b.getNodeName())) + { + vpFee[0] = Integer.parseInt(b.getAttributes().getNamedItem("count").getNodeValue()); + vpFee[1] = Integer.parseInt(b.getAttributes().getNamedItem("byUse").getNodeValue()); + } + else if ("time".equalsIgnoreCase(b.getNodeName())) + { + time = Long.parseLong(b.getAttributes().getNamedItem("count").getNodeValue()); + } + else if ("chance".equalsIgnoreCase(b.getNodeName())) + { + chances = getChanceList(b); + } + } + + _templates.put(slotId, new HomunculusCreationTemplate(slotId, isEnabled, grade, isEvent, itemFees, hpFee, spFee, vpFee, time, chances)); + } + } + } + } + } + + private List getItemList(Node c) + { + final List items = new ArrayList<>(); + for (Node b = c.getFirstChild(); b != null; b = b.getNextSibling()) + { + if ("item".equalsIgnoreCase(b.getNodeName())) + { + final int itemId = Integer.parseInt(b.getAttributes().getNamedItem("id").getNodeValue()); + final long itemCount = Long.parseLong(b.getAttributes().getNamedItem("count").getNodeValue()); + items.add(new ItemHolder(itemId, itemCount)); + } + } + return items; + } + + private List getChanceList(Node c) + { + final List chanceList = new ArrayList<>(); + for (Node b = c.getFirstChild(); b != null; b = b.getNextSibling()) + { + if ("homunculus".equalsIgnoreCase(b.getNodeName())) + { + final Double[] feeArray = new Double[2]; + feeArray[0] = Double.parseDouble(b.getAttributes().getNamedItem("id").getNodeValue()); + feeArray[1] = Double.parseDouble(b.getAttributes().getNamedItem("creationChance").getNodeValue()); + chanceList.add(feeArray); + } + } + return chanceList; + } + + public HomunculusCreationTemplate getTemplate(int id) + { + return _templates.get(id); + } + + public int size() + { + return _templates.size(); + } + + public static HomunculusCreationData getInstance() + { + return SingletonHolder.INSTANCE; + } + + private static class SingletonHolder + { + protected static final HomunculusCreationData INSTANCE = new HomunculusCreationData(); + } +} diff --git a/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/data/xml/HomunculusSlotData.java b/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/data/xml/HomunculusSlotData.java new file mode 100644 index 0000000000..5fd6b439cf --- /dev/null +++ b/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/data/xml/HomunculusSlotData.java @@ -0,0 +1,129 @@ +/* + * 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 . + */ +package org.l2jmobius.gameserver.data.xml; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.w3c.dom.Document; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; + +import org.l2jmobius.commons.util.IXmlReader; +import org.l2jmobius.gameserver.model.StatSet; +import org.l2jmobius.gameserver.model.holders.ItemHolder; +import org.l2jmobius.gameserver.model.homunculus.HomunculusSlotTemplate; + +/** + * @author Index + */ +public class HomunculusSlotData implements IXmlReader +{ + private final Map _templates = new HashMap<>(); + + protected HomunculusSlotData() + { + load(); + } + + @Override + public void load() + { + _templates.clear(); + parseDatapackFile("data/HomunculusSlotData.xml"); + LOGGER.info(getClass().getSimpleName() + ": Loaded " + _templates.size() + " templates."); + } + + @Override + public void parseDocument(Document doc, File f) + { + StatSet set; + Node att; + NamedNodeMap attrs; + for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling()) + { + if ("list".equalsIgnoreCase(n.getNodeName())) + { + for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling()) + { + if ("homunculusSlot".equalsIgnoreCase(d.getNodeName())) + { + attrs = d.getAttributes(); + set = new StatSet(); + for (int i = 0; i < attrs.getLength(); i++) + { + att = attrs.item(i); + set.set(att.getNodeName(), att.getNodeValue()); + } + + final int slotId = set.getInt("slotId"); + final Boolean isEnabled = set.getBoolean("isEnabled", false); + List fee = Collections.emptyList(); + + for (Node c = d.getFirstChild(); c != null; c = c.getNextSibling()) + { + if ("fee".equalsIgnoreCase(c.getNodeName())) + { + fee = getItemList(c); + } + } + _templates.put(slotId, new HomunculusSlotTemplate(slotId, fee, isEnabled)); + } + } + } + } + } + + private List getItemList(Node c) + { + final List items = new ArrayList<>(); + for (Node b = c.getFirstChild(); b != null; b = b.getNextSibling()) + { + if ("item".equalsIgnoreCase(b.getNodeName())) + { + final int itemId = Integer.parseInt(b.getAttributes().getNamedItem("id").getNodeValue()); + final long itemCount = Long.parseLong(b.getAttributes().getNamedItem("count").getNodeValue()); + items.add(new ItemHolder(itemId, itemCount)); + } + } + return items; + } + + public HomunculusSlotTemplate getTemplate(int id) + { + return _templates.get(id); + } + + public int size() + { + return _templates.size(); + } + + public static HomunculusSlotData getInstance() + { + return SingletonHolder.INSTANCE; + } + + private static class SingletonHolder + { + protected static final HomunculusSlotData INSTANCE = new HomunculusSlotData(); + } +} diff --git a/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/model/homunculus/HomunculusCreationTemplate.java b/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/model/homunculus/HomunculusCreationTemplate.java new file mode 100644 index 0000000000..8a9d603ba6 --- /dev/null +++ b/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/model/homunculus/HomunculusCreationTemplate.java @@ -0,0 +1,142 @@ +/* + * 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 . + */ +package org.l2jmobius.gameserver.model.homunculus; + +import java.util.List; + +import org.l2jmobius.gameserver.model.holders.ItemHolder; + +public class HomunculusCreationTemplate +{ + private final int _slotId; + private final boolean _isEnabled; + private final int _grade; + private final boolean _isEvent; + private final List _itemsFee; + private final Integer[] _hpFee; + private final Long[] _spFee; + private final Integer[] _vpFee; + private final long _time; + private final List _createChances; + + public HomunculusCreationTemplate(int slotId, boolean isEnabled, int grade, boolean isEvent, List itemsFee, Integer[] hpFee, Long[] spFee, Integer[] vpFee, long time, List createChances) + { + _slotId = slotId; + _isEnabled = isEnabled; + _grade = grade; + _isEvent = isEvent; + _itemsFee = itemsFee; + _hpFee = hpFee; + _spFee = spFee; + _vpFee = vpFee; + _time = time; + _createChances = createChances; + } + + public int getSlotId() + { + return _slotId; + } + + public boolean isEnabled() + { + return _isEnabled; + } + + public int getGrade() + { + return _grade; + } + + public boolean isEvent() + { + return _isEvent; + } + + public List getItemFee() + { + return _itemsFee; + } + + public boolean haveAnotherFee() + { + return !_itemsFee.isEmpty(); + } + + public int getHPFeeCountByUse() + { + return _hpFee[1]; + } + + public int getHPFeeCount() + { + return _hpFee[0]; + } + + public long getSPFeeCountByUse() + { + return _spFee[1]; + } + + public long getSPFeeCount() + { + return _spFee[0]; + } + + public int getVPFeeByUse() + { + return _vpFee[1]; + } + + public int getVPFeeCount() + { + return _vpFee[0]; + } + + public double getMaxChance() + { + double result = 0; + for (int i = 0; i < _createChances.size(); i++) + { + Double[] chance = _createChances.get(i); + result = result + chance[1]; + } + return result; + } + + public boolean isInstanceHaveCoupon(int itemId) + { + for (ItemHolder humu : _itemsFee) + { + if (humu.getId() == itemId) + { + return true; + } + } + return false; + } + + public long getCreationLime() + { + return _time; + } + + public List getCreationChance() + { + return _createChances; + } +} diff --git a/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/model/homunculus/HomunculusSlotTemplate.java b/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/model/homunculus/HomunculusSlotTemplate.java new file mode 100644 index 0000000000..6125633dd1 --- /dev/null +++ b/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/model/homunculus/HomunculusSlotTemplate.java @@ -0,0 +1,50 @@ +/* + * 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 . + */ +package org.l2jmobius.gameserver.model.homunculus; + +import java.util.List; + +import org.l2jmobius.gameserver.model.holders.ItemHolder; + +public class HomunculusSlotTemplate +{ + private final int _slotId; + private final List _price; + private final boolean _isEnabled; + + public HomunculusSlotTemplate(int slotId, List price, boolean isEnabled) + { + _slotId = slotId; + _price = price; + _isEnabled = isEnabled; + } + + public int getSlotId() + { + return _slotId; + } + + public List getPrice() + { + return _price; + } + + public boolean getSlotEnabled() + { + return _isEnabled; + } +} diff --git a/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/model/variables/PlayerVariables.java b/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/model/variables/PlayerVariables.java index 346db019d8..e40be28720 100644 --- a/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/model/variables/PlayerVariables.java +++ b/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/model/variables/PlayerVariables.java @@ -81,6 +81,7 @@ public class PlayerVariables extends AbstractVariables public static final String HOMUNCULUS_USED_VP_POINTS = "HOMUNCULUS_USED_VP_POINTS"; public static final String HOMUNCULUS_USED_VP_CONVERT = "HOMUNCULUS_USED_VP_CONVERT"; public static final String HOMUNCULUS_USED_RESET_VP = "HOMUNCULUS_USED_RESET_VP"; + public static final String HOMUNCULUS_OPENED_SLOT_COUNT = "HOMUNCULUS_OPENED_SLOT_COUNT"; private final int _objectId; diff --git a/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusActivateSlot.java b/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusActivateSlot.java index bb5463298d..6acd0c04a7 100644 --- a/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusActivateSlot.java +++ b/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusActivateSlot.java @@ -16,13 +16,20 @@ */ package org.l2jmobius.gameserver.network.clientpackets.homunculus; -import org.l2jmobius.Config; +import java.util.List; +import java.util.logging.Logger; + import org.l2jmobius.commons.network.PacketReader; +import org.l2jmobius.gameserver.data.xml.HomunculusSlotData; import org.l2jmobius.gameserver.model.actor.Player; -import org.l2jmobius.gameserver.model.homunculus.Homunculus; +import org.l2jmobius.gameserver.model.holders.ItemHolder; +import org.l2jmobius.gameserver.model.homunculus.HomunculusSlotTemplate; +import org.l2jmobius.gameserver.model.variables.PlayerVariables; import org.l2jmobius.gameserver.network.GameClient; +import org.l2jmobius.gameserver.network.PacketLogger; import org.l2jmobius.gameserver.network.clientpackets.IClientIncomingPacket; import org.l2jmobius.gameserver.network.serverpackets.homunculus.ExActivateHomunculusResult; +import org.l2jmobius.gameserver.network.serverpackets.homunculus.ExHomunculusPointInfo; import org.l2jmobius.gameserver.network.serverpackets.homunculus.ExShowHomunculusList; /** @@ -31,13 +38,12 @@ import org.l2jmobius.gameserver.network.serverpackets.homunculus.ExShowHomunculu public class RequestExHomunculusActivateSlot implements IClientIncomingPacket { private int _slot; - private boolean _activate; @Override public boolean read(GameClient client, PacketReader packet) { _slot = packet.readD(); - _activate = packet.readC() == 1; // enabled? + // _activate = packet.readC() == 1; // enabled? return true; } @@ -51,62 +57,46 @@ public class RequestExHomunculusActivateSlot implements IClientIncomingPacket } final int size = activeChar.getHomunculusList().size(); - if (size == 0) + final HomunculusSlotTemplate template = HomunculusSlotData.getInstance().getTemplate(_slot); + if ((size != 0) && ((activeChar.getHomunculusList().get(_slot) != null) || (_slot == activeChar.getVariables().getInt(PlayerVariables.HOMUNCULUS_OPENED_SLOT_COUNT)))) { + PacketLogger.info(getClass().getSimpleName() + " player " + activeChar.getName() + " " + activeChar.getObjectId() + " trying unlock already unlocked slot;"); + activeChar.sendPacket(new ExActivateHomunculusResult(false)); + return; + } + if (!template.getSlotEnabled()) + { + Logger.getLogger(getClass().getSimpleName() + " player " + activeChar.getName() + " " + activeChar.getObjectId() + " trying unlock disabled slot;"); + activeChar.sendPacket(new ExActivateHomunculusResult(false)); return; } - final Homunculus homunculus = activeChar.getHomunculusList().get(_slot); - if (homunculus == null) + final List fee = template.getPrice(); + for (int i = 0; i < fee.size(); i++) { - return; - } - - for (int i = 0; i < Config.MAX_HOMUNCULUS_COUNT; i++) - { - if (size <= i) + final ItemHolder feeHolder = fee.get(i); + if ((activeChar.getInventory().getItemByItemId(feeHolder.getId()) == null) || ((activeChar.getInventory().getItemByItemId(feeHolder.getId()) != null) && (activeChar.getInventory().getItemByItemId(feeHolder.getId()).getCount() < feeHolder.getCount()))) { - break; - } - - final Homunculus homu = activeChar.getHomunculusList().get(i); - if (homu == null) - { - continue; - } - - if (homu.isActive()) - { - homu.setActive(false); - activeChar.getHomunculusList().update(homu); - activeChar.getHomunculusList().refreshStats(true); - activeChar.sendPacket(new ExShowHomunculusList(activeChar)); activeChar.sendPacket(new ExActivateHomunculusResult(false)); + return; + } + } + for (int i = 0; i < fee.size(); i++) + { + final ItemHolder feeHolder = fee.get(i); + if (activeChar.getInventory().destroyItemByItemId("Homunclus slot unlock", feeHolder.getId(), feeHolder.getCount(), activeChar, null) == null) + { + Logger.getLogger(getClass().getSimpleName() + " player " + activeChar.getName() + " " + activeChar.getObjectId() + " trying unlock slot without items;"); + activeChar.sendPacket(new ExActivateHomunculusResult(false)); + return; } } - if (_activate) - { - if (!homunculus.isActive()) - { - - homunculus.setActive(true); - activeChar.getHomunculusList().update(homunculus); - activeChar.getHomunculusList().refreshStats(true); - activeChar.sendPacket(new ExShowHomunculusList(activeChar)); - activeChar.sendPacket(new ExActivateHomunculusResult(true)); - } - } - else - { - if (homunculus.isActive()) - { - homunculus.setActive(false); - activeChar.getHomunculusList().update(homunculus); - activeChar.getHomunculusList().refreshStats(true); - activeChar.sendPacket(new ExShowHomunculusList(activeChar)); - activeChar.sendPacket(new ExActivateHomunculusResult(false)); - } - } + activeChar.sendItemList(); + activeChar.broadcastUserInfo(); + activeChar.getVariables().set(PlayerVariables.HOMUNCULUS_OPENED_SLOT_COUNT, _slot); + activeChar.sendPacket(new ExHomunculusPointInfo(activeChar)); + activeChar.sendPacket(new ExShowHomunculusList(activeChar)); + activeChar.sendPacket(new ExActivateHomunculusResult(true)); } } diff --git a/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusCreateStart.java b/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusCreateStart.java index 9764bb52ea..ff6c14c952 100644 --- a/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusCreateStart.java +++ b/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusCreateStart.java @@ -17,7 +17,9 @@ package org.l2jmobius.gameserver.network.clientpackets.homunculus; import org.l2jmobius.commons.network.PacketReader; +import org.l2jmobius.gameserver.data.xml.HomunculusCreationData; import org.l2jmobius.gameserver.model.actor.Player; +import org.l2jmobius.gameserver.model.homunculus.HomunculusCreationTemplate; import org.l2jmobius.gameserver.model.variables.PlayerVariables; import org.l2jmobius.gameserver.network.GameClient; import org.l2jmobius.gameserver.network.SystemMessageId; @@ -30,8 +32,9 @@ import org.l2jmobius.gameserver.network.serverpackets.homunculus.ExShowHomunculu */ public class RequestExHomunculusCreateStart implements IClientIncomingPacket { - private static final int COST = 1000000; - private static final long CREATION_TIME = 86400000L; + private static final HomunculusCreationTemplate TEMPLATE = HomunculusCreationData.getInstance().getTemplate(0); + private static final int COST = Math.toIntExact(TEMPLATE.getItemFee().get(0).getCount()); + private static final long CREATION_TIME = TEMPLATE.getCreationLime(); @Override public boolean read(GameClient client, PacketReader packet) @@ -53,6 +56,7 @@ public class RequestExHomunculusCreateStart implements IClientIncomingPacket player.sendPacket(SystemMessageId.NOT_ENOUGH_ADENA_2); return; } + player.reduceAdena("Homunculus creation", COST, player, true); player.getVariables().set(PlayerVariables.HOMUNCULUS_CREATION_TIME, System.currentTimeMillis() + CREATION_TIME); diff --git a/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusInsert.java b/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusInsert.java index 6a2e480084..dde47a5571 100644 --- a/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusInsert.java +++ b/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusInsert.java @@ -17,8 +17,9 @@ package org.l2jmobius.gameserver.network.clientpackets.homunculus; import org.l2jmobius.commons.network.PacketReader; +import org.l2jmobius.gameserver.data.xml.HomunculusCreationData; import org.l2jmobius.gameserver.model.actor.Player; -import org.l2jmobius.gameserver.model.actor.stat.PlayerStat; +import org.l2jmobius.gameserver.model.homunculus.HomunculusCreationTemplate; import org.l2jmobius.gameserver.model.variables.PlayerVariables; import org.l2jmobius.gameserver.network.GameClient; import org.l2jmobius.gameserver.network.clientpackets.IClientIncomingPacket; @@ -31,9 +32,10 @@ import org.l2jmobius.gameserver.network.serverpackets.homunculus.ExShowHomunculu */ public class RequestExHomunculusInsert implements IClientIncomingPacket { - private static final short HP_COST = 10000; - private static final long SP_COST = 5000000000L; - private static final int VP_COST = PlayerStat.MAX_VITALITY_POINTS / 4; + private static final HomunculusCreationTemplate TEMPLATE = HomunculusCreationData.getInstance().getTemplate(0); + private static final short HP_COST = (short) TEMPLATE.getHPFeeCountByUse(); + private static final long SP_COST = TEMPLATE.getSPFeeCountByUse(); + private static final int VP_COST = TEMPLATE.getVPFeeByUse(); private int _type; @@ -59,7 +61,7 @@ public class RequestExHomunculusInsert implements IClientIncomingPacket { case 0: { - if ((player.getCurrentHp() > HP_COST) && (hpPoints < 100)) + if ((player.getCurrentHp() > HP_COST) && (hpPoints < TEMPLATE.getHPFeeCount())) { int newHp = (int) (player.getCurrentHp()) - HP_COST; player.setCurrentHp(newHp, true); @@ -74,7 +76,7 @@ public class RequestExHomunculusInsert implements IClientIncomingPacket } case 1: { - if ((player.getSp() >= SP_COST) && (spPoints < 10)) + if ((player.getSp() >= SP_COST) && (spPoints < TEMPLATE.getSPFeeCount())) { player.setSp(player.getSp() - SP_COST); spPoints += 1; @@ -88,7 +90,7 @@ public class RequestExHomunculusInsert implements IClientIncomingPacket } case 2: { - if ((player.getVitalityPoints() >= VP_COST) && (vpPoints < 5)) + if ((player.getVitalityPoints() >= VP_COST) && (vpPoints < TEMPLATE.getVPFeeCount())) { int newVitality = player.getVitalityPoints() - VP_COST; player.setVitalityPoints(newVitality, true); diff --git a/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusSummon.java b/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusSummon.java index f1a28c90e8..c7acfe0cc6 100644 --- a/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusSummon.java +++ b/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusSummon.java @@ -18,9 +18,11 @@ package org.l2jmobius.gameserver.network.clientpackets.homunculus; import org.l2jmobius.commons.network.PacketReader; import org.l2jmobius.commons.util.Rnd; +import org.l2jmobius.gameserver.data.xml.HomunculusCreationData; import org.l2jmobius.gameserver.data.xml.HomunculusData; import org.l2jmobius.gameserver.model.actor.Player; import org.l2jmobius.gameserver.model.homunculus.Homunculus; +import org.l2jmobius.gameserver.model.homunculus.HomunculusCreationTemplate; import org.l2jmobius.gameserver.model.homunculus.HomunculusTemplate; import org.l2jmobius.gameserver.model.variables.PlayerVariables; import org.l2jmobius.gameserver.network.GameClient; @@ -29,12 +31,15 @@ import org.l2jmobius.gameserver.network.clientpackets.IClientIncomingPacket; import org.l2jmobius.gameserver.network.serverpackets.homunculus.ExHomunculusSummonResult; import org.l2jmobius.gameserver.network.serverpackets.homunculus.ExShowHomunculusBirthInfo; import org.l2jmobius.gameserver.network.serverpackets.homunculus.ExShowHomunculusList; +import org.l2jmobius.gameserver.network.serverpackets.homunculus.ExSummonHomunculusCouponResult; /** * @author Mobius */ public class RequestExHomunculusSummon implements IClientIncomingPacket { + private static final HomunculusCreationTemplate TEMPLATE = HomunculusCreationData.getInstance().getTemplate(0); + @Override public boolean read(GameClient client, PacketReader packet) { @@ -56,148 +61,27 @@ public class RequestExHomunculusSummon implements IClientIncomingPacket final int vpPoints = player.getVariables().getInt(PlayerVariables.HOMUNCULUS_VP_POINTS, 0); final int homunculusCreateTime = (int) (player.getVariables().getLong(PlayerVariables.HOMUNCULUS_CREATION_TIME, 0) / 1000); - if ((homunculusCreateTime > 0) && ((System.currentTimeMillis() / 1000) >= homunculusCreateTime) && (hpPoints == 100) && (spPoints == 10) && (vpPoints == 5)) + if ((homunculusCreateTime > 0) && ((System.currentTimeMillis() / 1000) >= homunculusCreateTime) && (hpPoints == TEMPLATE.getHPFeeCount()) && (spPoints == TEMPLATE.getSPFeeCount()) && (vpPoints == TEMPLATE.getVPFeeCount())) { - int chance; - int random; + double chance = Rnd.get(100.0); + double current = 0; int homunculusId = 0; while (homunculusId == 0) { - chance = Rnd.get(100); - random = Rnd.get(100); - - // Basic Homunculus - if (chance >= 60) + if (chance > TEMPLATE.getMaxChance()) { - if ((random >= 90) && !player.getHomunculusList().hasHomunculus(1)) - { - homunculusId = 1; - } - else if ((random >= 80) && !player.getHomunculusList().hasHomunculus(4)) - { - homunculusId = 4; - } - else if ((random >= 70) && !player.getHomunculusList().hasHomunculus(7)) - { - homunculusId = 7; - } - else if ((random >= 60) && !player.getHomunculusList().hasHomunculus(10)) - { - homunculusId = 10; - } - else if ((random >= 50) && !player.getHomunculusList().hasHomunculus(13)) - { - homunculusId = 13; - } - else if ((random >= 40) && !player.getHomunculusList().hasHomunculus(16)) - { - homunculusId = 16; - } - else if ((random >= 30) && !player.getHomunculusList().hasHomunculus(19)) - { - homunculusId = 19; - } - else if ((random >= 20) && !player.getHomunculusList().hasHomunculus(22)) - { - homunculusId = 22; - } - else if ((random >= 10) && !player.getHomunculusList().hasHomunculus(25)) - { - homunculusId = 25; - } - else if (!player.getHomunculusList().hasHomunculus(28)) - { - homunculusId = 28; - } + player.sendMessage("Homunculus is not created!"); + player.sendPacket(new ExSummonHomunculusCouponResult(0, 0)); + return; } - - // Water Homunculus - if ((homunculusId == 0) && (chance >= 10)) + for (int i = 0; i < TEMPLATE.getCreationChance().size(); i++) { - if ((random >= 90) && !player.getHomunculusList().hasHomunculus(2)) + final Double[] homuHolder = TEMPLATE.getCreationChance().get(i); + current += homuHolder[1]; + if (current >= chance) { - homunculusId = 2; - } - else if ((random >= 80) && !player.getHomunculusList().hasHomunculus(5)) - { - homunculusId = 5; - } - else if ((random >= 70) && !player.getHomunculusList().hasHomunculus(8)) - { - homunculusId = 8; - } - else if ((random >= 60) && !player.getHomunculusList().hasHomunculus(11)) - { - homunculusId = 11; - } - else if ((random >= 50) && !player.getHomunculusList().hasHomunculus(14)) - { - homunculusId = 14; - } - else if ((random >= 40) && !player.getHomunculusList().hasHomunculus(17)) - { - homunculusId = 17; - } - else if ((random >= 30) && !player.getHomunculusList().hasHomunculus(20)) - { - homunculusId = 20; - } - else if ((random >= 20) && !player.getHomunculusList().hasHomunculus(23)) - { - homunculusId = 23; - } - else if ((random >= 10) && !player.getHomunculusList().hasHomunculus(26)) - { - homunculusId = 26; - } - else if (!player.getHomunculusList().hasHomunculus(29)) - { - homunculusId = 29; - } - } - - // Luminous Homunculus - if (homunculusId == 0) - { - if ((random >= 90) && !player.getHomunculusList().hasHomunculus(3)) - { - homunculusId = 3; - } - else if ((random >= 80) && !player.getHomunculusList().hasHomunculus(6)) - { - homunculusId = 6; - } - else if ((random >= 70) && !player.getHomunculusList().hasHomunculus(9)) - { - homunculusId = 9; - } - else if ((random >= 60) && !player.getHomunculusList().hasHomunculus(12)) - { - homunculusId = 12; - } - else if ((random >= 50) && !player.getHomunculusList().hasHomunculus(15)) - { - homunculusId = 15; - } - else if ((random >= 40) && !player.getHomunculusList().hasHomunculus(18)) - { - homunculusId = 18; - } - else if ((random >= 30) && !player.getHomunculusList().hasHomunculus(21)) - { - homunculusId = 21; - } - else if ((random >= 20) && !player.getHomunculusList().hasHomunculus(24)) - { - homunculusId = 24; - } - else if ((random >= 10) && !player.getHomunculusList().hasHomunculus(27)) - { - homunculusId = 27; - } - else if (!player.getHomunculusList().hasHomunculus(30)) - { - homunculusId = 30; + homunculusId = homuHolder[0].intValue(); + break; } } } diff --git a/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExSummonHomunculusCouponResult.java b/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExSummonHomunculusCouponResult.java index 9c9096d387..4d369cf581 100644 --- a/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExSummonHomunculusCouponResult.java +++ b/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExSummonHomunculusCouponResult.java @@ -18,10 +18,14 @@ package org.l2jmobius.gameserver.network.clientpackets.homunculus; import org.l2jmobius.commons.network.PacketReader; import org.l2jmobius.commons.util.Rnd; +import org.l2jmobius.gameserver.data.xml.HomunculusCreationData; import org.l2jmobius.gameserver.data.xml.HomunculusData; import org.l2jmobius.gameserver.model.actor.Player; +import org.l2jmobius.gameserver.model.holders.ItemHolder; import org.l2jmobius.gameserver.model.homunculus.Homunculus; +import org.l2jmobius.gameserver.model.homunculus.HomunculusCreationTemplate; import org.l2jmobius.gameserver.model.homunculus.HomunculusTemplate; +import org.l2jmobius.gameserver.model.variables.PlayerVariables; import org.l2jmobius.gameserver.network.GameClient; import org.l2jmobius.gameserver.network.PacketLogger; import org.l2jmobius.gameserver.network.clientpackets.IClientIncomingPacket; @@ -34,15 +38,12 @@ import org.l2jmobius.gameserver.network.serverpackets.homunculus.ExSummonHomuncu */ public class RequestExSummonHomunculusCouponResult implements IClientIncomingPacket { - private static final int HOURGLASS = 81815; - private static final int HOURGLASS_SHINY = 81879; - private static final int ADENA = 57; - private static final int ADENA_COUNT = 2000000; + private int _item_id; @Override public boolean read(GameClient client, PacketReader packet) { - // packet.readD(); + _item_id = packet.readD(); return true; } @@ -55,161 +56,64 @@ public class RequestExSummonHomunculusCouponResult implements IClientIncomingPac return; } - // Take items. - if ((player.getInventory().getItemByItemId(HOURGLASS) != null) && (player.getInventory().getItemByItemId(ADENA).getCount() > ADENA_COUNT)) - { - player.destroyItemByItemId("Homunculus Hourglass", HOURGLASS, 1, player, true); - } - else if ((player.getInventory().getItemByItemId(HOURGLASS_SHINY) != null) && (player.getInventory().getItemByItemId(ADENA).getCount() >= ADENA_COUNT)) - { - player.destroyItemByItemId("Shiny Homunculus Hourglass", HOURGLASS_SHINY, 1, player, true); - } - else + if (player.getHomunculusList().size() == player.getVariables().getInt(PlayerVariables.HOMUNCULUS_OPENED_SLOT_COUNT)) { + player.sendPacket(new ExSummonHomunculusCouponResult(0, 0)); + PacketLogger.info("Player " + player.getObjectId() + " " + player.getName() + ", trying create homunculus withouts avaible slots;"); + return; + } + HomunculusCreationTemplate creationTemplate = null; + for (int i = 1; i < HomunculusCreationData.getInstance().size(); i++) + { + if (HomunculusCreationData.getInstance().getTemplate(i).isInstanceHaveCoupon(_item_id)) + { + creationTemplate = HomunculusCreationData.getInstance().getTemplate(i); + } + } + if ((creationTemplate == null) || (creationTemplate.getItemFee().size() == 0)) + { + PacketLogger.info("Player " + player.getObjectId() + " " + player.getName() + ", trying create homunculus with not existing coupon!"); return; } - player.destroyItemByItemId("Adena", ADENA, 2000000, player, true); - int chance; - int random; + // Take items. + for (int i = 0; i < creationTemplate.getItemFee().size(); i++) + { + ItemHolder humu = creationTemplate.getItemFee().get(i); + if (player.getInventory().getItemByItemId(humu.getId()).getCount() <= humu.getCount()) + { + return; + } + } + for (int i = 0; i < creationTemplate.getItemFee().size(); i++) + { + ItemHolder humu = creationTemplate.getItemFee().get(i); + if (!player.destroyItemByItemId("Homunculus Coupon Creation", humu.getId(), humu.getCount(), player, true)) + { + PacketLogger.info("Player " + player.getObjectId() + " " + player.getName() + ", trying create homunculus without " + humu + "!"); + return; + } + } + + double chance = Rnd.get(100.0); + double current = 0; int homunculusId = 0; while (homunculusId == 0) { - chance = Rnd.get(100); - random = Rnd.get(100); - - // Basic Homunculus - if (chance >= 60) + if (chance > creationTemplate.getMaxChance()) { - if ((random >= 90) && !player.getHomunculusList().hasHomunculus(1)) - { - homunculusId = 1; - } - else if ((random >= 80) && !player.getHomunculusList().hasHomunculus(4)) - { - homunculusId = 4; - } - else if ((random >= 70) && !player.getHomunculusList().hasHomunculus(7)) - { - homunculusId = 7; - } - else if ((random >= 60) && !player.getHomunculusList().hasHomunculus(10)) - { - homunculusId = 10; - } - else if ((random >= 50) && !player.getHomunculusList().hasHomunculus(13)) - { - homunculusId = 13; - } - else if ((random >= 40) && !player.getHomunculusList().hasHomunculus(16)) - { - homunculusId = 16; - } - else if ((random >= 30) && !player.getHomunculusList().hasHomunculus(19)) - { - homunculusId = 19; - } - else if ((random >= 20) && !player.getHomunculusList().hasHomunculus(22)) - { - homunculusId = 22; - } - else if ((random >= 10) && !player.getHomunculusList().hasHomunculus(25)) - { - homunculusId = 25; - } - else if (!player.getHomunculusList().hasHomunculus(28)) - { - homunculusId = 28; - } + player.sendMessage("Homunculus is not created!"); + player.sendPacket(new ExSummonHomunculusCouponResult(0, 0)); + return; } - - // Water Homunculus - if ((homunculusId == 0) && (chance >= 10)) + for (int i = 0; i < creationTemplate.getCreationChance().size(); i++) { - if ((random >= 90) && !player.getHomunculusList().hasHomunculus(2)) + final Double[] homuHolder = creationTemplate.getCreationChance().get(i); + current += homuHolder[1]; + if (current >= chance) { - homunculusId = 2; - } - else if ((random >= 80) && !player.getHomunculusList().hasHomunculus(5)) - { - homunculusId = 5; - } - else if ((random >= 70) && !player.getHomunculusList().hasHomunculus(8)) - { - homunculusId = 8; - } - else if ((random >= 60) && !player.getHomunculusList().hasHomunculus(11)) - { - homunculusId = 11; - } - else if ((random >= 50) && !player.getHomunculusList().hasHomunculus(14)) - { - homunculusId = 14; - } - else if ((random >= 40) && !player.getHomunculusList().hasHomunculus(17)) - { - homunculusId = 17; - } - else if ((random >= 30) && !player.getHomunculusList().hasHomunculus(20)) - { - homunculusId = 20; - } - else if ((random >= 20) && !player.getHomunculusList().hasHomunculus(23)) - { - homunculusId = 23; - } - else if ((random >= 10) && !player.getHomunculusList().hasHomunculus(26)) - { - homunculusId = 26; - } - else if (!player.getHomunculusList().hasHomunculus(29)) - { - homunculusId = 29; - } - } - - // Luminous Homunculus - if (homunculusId == 0) - { - if ((random >= 90) && !player.getHomunculusList().hasHomunculus(3)) - { - homunculusId = 3; - } - else if ((random >= 80) && !player.getHomunculusList().hasHomunculus(6)) - { - homunculusId = 6; - } - else if ((random >= 70) && !player.getHomunculusList().hasHomunculus(9)) - { - homunculusId = 9; - } - else if ((random >= 60) && !player.getHomunculusList().hasHomunculus(12)) - { - homunculusId = 12; - } - else if ((random >= 50) && !player.getHomunculusList().hasHomunculus(15)) - { - homunculusId = 15; - } - else if ((random >= 40) && !player.getHomunculusList().hasHomunculus(18)) - { - homunculusId = 18; - } - else if ((random >= 30) && !player.getHomunculusList().hasHomunculus(21)) - { - homunculusId = 21; - } - else if ((random >= 20) && !player.getHomunculusList().hasHomunculus(24)) - { - homunculusId = 24; - } - else if ((random >= 10) && !player.getHomunculusList().hasHomunculus(27)) - { - homunculusId = 27; - } - else if (!player.getHomunculusList().hasHomunculus(30)) - { - homunculusId = 30; + homunculusId = homuHolder[0].intValue(); + break; } } } diff --git a/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExHomunculusPointInfo.java b/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExHomunculusPointInfo.java index f26aefd800..550e908a64 100644 --- a/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExHomunculusPointInfo.java +++ b/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExHomunculusPointInfo.java @@ -16,7 +16,6 @@ */ package org.l2jmobius.gameserver.network.serverpackets.homunculus; -import org.l2jmobius.Config; import org.l2jmobius.commons.network.PacketWriter; import org.l2jmobius.gameserver.model.actor.Player; import org.l2jmobius.gameserver.model.variables.PlayerVariables; @@ -46,7 +45,7 @@ public class ExHomunculusPointInfo implements IClientOutgoingPacket packet.writeD(_player.getVariables().getInt(PlayerVariables.HOMUNCULUS_USED_VP_POINTS, 0)); // vp points packet.writeD(_player.getVariables().getInt(PlayerVariables.HOMUNCULUS_USED_VP_CONVERT, 0)); // consumed basic vp points packet.writeD(_player.getVariables().getInt(PlayerVariables.HOMUNCULUS_USED_RESET_VP, 0)); // consumed reset vp points - packet.writeD(Math.min(Config.MAX_HOMUNCULUS_COUNT, _player.getHomunculusList().size() + 1)); // 306 + packet.writeD(_player.getVariables().getInt(PlayerVariables.HOMUNCULUS_OPENED_SLOT_COUNT)); // 306 return true; } } diff --git a/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExShowHomunculusBirthInfo.java b/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExShowHomunculusBirthInfo.java index cdc24a4c11..33d7857cba 100644 --- a/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExShowHomunculusBirthInfo.java +++ b/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExShowHomunculusBirthInfo.java @@ -17,7 +17,9 @@ package org.l2jmobius.gameserver.network.serverpackets.homunculus; import org.l2jmobius.commons.network.PacketWriter; +import org.l2jmobius.gameserver.data.xml.HomunculusCreationData; import org.l2jmobius.gameserver.model.actor.Player; +import org.l2jmobius.gameserver.model.homunculus.HomunculusCreationTemplate; import org.l2jmobius.gameserver.model.variables.PlayerVariables; import org.l2jmobius.gameserver.network.OutgoingPackets; import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket; @@ -27,10 +29,15 @@ import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket; */ public class ExShowHomunculusBirthInfo implements IClientOutgoingPacket { + private static final HomunculusCreationTemplate TEMPLATE = HomunculusCreationData.getInstance().getTemplate(0); + private final int _hpPoints; private final int _spPoints; private final int _vpPoints; private final int _homunculusCreateTime; + private final int _feeHpPoints; + private final int _feeSpPoints; + private final int _feeVpPoints; public ExShowHomunculusBirthInfo(Player player) { @@ -38,6 +45,9 @@ public class ExShowHomunculusBirthInfo implements IClientOutgoingPacket _spPoints = player.getVariables().getInt(PlayerVariables.HOMUNCULUS_SP_POINTS, 0); _vpPoints = player.getVariables().getInt(PlayerVariables.HOMUNCULUS_VP_POINTS, 0); _homunculusCreateTime = (int) (player.getVariables().getLong(PlayerVariables.HOMUNCULUS_CREATION_TIME, 0) / 1000); + _feeHpPoints = TEMPLATE.getHPFeeCount(); + _feeSpPoints = (int) TEMPLATE.getSPFeeCount(); + _feeVpPoints = TEMPLATE.getVPFeeCount(); } @Override @@ -47,7 +57,7 @@ public class ExShowHomunculusBirthInfo implements IClientOutgoingPacket int creationStage = 0; if (_homunculusCreateTime > 0) { - if (((System.currentTimeMillis() / 1000) >= _homunculusCreateTime) && (_hpPoints == 100) && (_spPoints == 10) && (_vpPoints == 5)) + if (((System.currentTimeMillis() / 1000) >= _homunculusCreateTime) && (_hpPoints == _feeHpPoints) && (_spPoints == _feeSpPoints) && (_vpPoints == _feeVpPoints)) { creationStage = 2; } @@ -60,8 +70,8 @@ public class ExShowHomunculusBirthInfo implements IClientOutgoingPacket packet.writeD(_hpPoints); // hp points packet.writeD(_spPoints); // sp points packet.writeD(_vpPoints); // vp points - packet.writeD(_homunculusCreateTime); // finish time - packet.writeD(0); // JP = 0. ? + packet.writeQ(_homunculusCreateTime); // finish time + // packet.writeD(0); // JP = 0. ? return true; } } diff --git a/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExShowHomunculusList.java b/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExShowHomunculusList.java index 74372f0878..28369f119f 100644 --- a/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExShowHomunculusList.java +++ b/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExShowHomunculusList.java @@ -16,10 +16,10 @@ */ package org.l2jmobius.gameserver.network.serverpackets.homunculus; -import org.l2jmobius.Config; import org.l2jmobius.commons.network.PacketWriter; import org.l2jmobius.gameserver.model.actor.Player; import org.l2jmobius.gameserver.model.homunculus.Homunculus; +import org.l2jmobius.gameserver.model.variables.PlayerVariables; import org.l2jmobius.gameserver.network.OutgoingPackets; import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket; @@ -38,18 +38,34 @@ public class ExShowHomunculusList implements IClientOutgoingPacket @Override public boolean write(PacketWriter packet) { - OutgoingPackets.EX_SHOW_HOMUNCULUS_LIST.writeId(packet); - if (_player.getHomunculusList().size() > 0) + if ((_player.getVariables().getInt(PlayerVariables.HOMUNCULUS_OPENED_SLOT_COUNT, 0) == 0) || (_player.getVariables().getInt(PlayerVariables.HOMUNCULUS_OPENED_SLOT_COUNT) == 1) || (_player.getVariables().getInt(PlayerVariables.HOMUNCULUS_OPENED_SLOT_COUNT) == 2)) { - packet.writeD(_player.getHomunculusList().size()); // homunculus count - int counter = 0; - for (int i = 0; i < Config.MAX_HOMUNCULUS_COUNT; i++) + if ((_player.getHomunculusList() != null) && (_player.getHomunculusList().size() != 0) && (_player.getHomunculusList().size() < 2)) + { + if (_player.getVariables().getInt(PlayerVariables.HOMUNCULUS_CREATION_TIME, 0) >= 0) + { + _player.getVariables().set(PlayerVariables.HOMUNCULUS_OPENED_SLOT_COUNT, _player.getHomunculusList().size() + 1); + } + else + { + _player.getVariables().set(PlayerVariables.HOMUNCULUS_OPENED_SLOT_COUNT, _player.getHomunculusList().size()); + } + } + else + { + _player.getVariables().set(PlayerVariables.HOMUNCULUS_OPENED_SLOT_COUNT, 3); + } + } + + final int slotCount = _player.getVariables().getInt(PlayerVariables.HOMUNCULUS_OPENED_SLOT_COUNT); + OutgoingPackets.EX_SHOW_HOMUNCULUS_LIST.writeId(packet); + packet.writeD(slotCount); + int counter = 0; + for (int i = 0; i <= slotCount; i++) + { + if (_player.getHomunculusList().get(i) != null) { final Homunculus homunculus = _player.getHomunculusList().get(i); - if (homunculus == null) - { - continue; - } packet.writeD(counter); // slot packet.writeD(homunculus.getId()); // homunculus id packet.writeD(homunculus.getType()); @@ -72,13 +88,33 @@ public class ExShowHomunculusList implements IClientOutgoingPacket packet.writeD(homunculus.getAtk()); packet.writeD(homunculus.getDef()); packet.writeD(homunculus.getCritRate()); - counter++; } + else + { + packet.writeD(counter); // slot + packet.writeD(0); // homunculus id + packet.writeD(0); + packet.writeC(0); + packet.writeD(0); + for (int j = 1; j <= 5; j++) + { + packet.writeD(0); + } + packet.writeD(0); + for (int j = 1; j <= 5; j++) + { + packet.writeD(0); + } + packet.writeD(0);// m_nLevel + packet.writeD(0);// m_nHP + packet.writeD(0);// m_nHP + packet.writeD(0);// m_nAttack + packet.writeD(0);// m_nDefence + packet.writeD(0);// m_nCritical + } + counter++; } - else - { - packet.writeD(0); - } + return true; } } diff --git a/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExSummonHomunculusCouponResult.java b/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExSummonHomunculusCouponResult.java index 28c7d148e2..22597b6716 100644 --- a/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExSummonHomunculusCouponResult.java +++ b/L2J_Mobius_10.1_MasterClass/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExSummonHomunculusCouponResult.java @@ -26,17 +26,31 @@ import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket; public class ExSummonHomunculusCouponResult implements IClientOutgoingPacket { private final int _slot; + private int _success = -1; public ExSummonHomunculusCouponResult(int slot) { _slot = slot; } + public ExSummonHomunculusCouponResult(int slot, int success) + { + _slot = slot; + _success = success; + } + @Override public boolean write(PacketWriter packet) { OutgoingPackets.EX_SUMMON_HOMUNCULUS_COUPON_RESULT.writeId(packet); - packet.writeD(1); // 1 - success + if (_success == -1) + { + packet.writeD(1); // 1 - success + } + else + { + packet.writeD(_success); + } packet.writeD(_slot); // homunculus slot packet.writeD(0); // keep or delete return true; diff --git a/L2J_Mobius_10.2_MasterClass/dist/game/data/HomunculusCreationData.xml b/L2J_Mobius_10.2_MasterClass/dist/game/data/HomunculusCreationData.xml new file mode 100644 index 0000000000..4b5ff8244e --- /dev/null +++ b/L2J_Mobius_10.2_MasterClass/dist/game/data/HomunculusCreationData.xml @@ -0,0 +1,100 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/L2J_Mobius_10.2_MasterClass/dist/game/data/HomunculusSlotData.xml b/L2J_Mobius_10.2_MasterClass/dist/game/data/HomunculusSlotData.xml new file mode 100644 index 0000000000..0b336dd5d6 --- /dev/null +++ b/L2J_Mobius_10.2_MasterClass/dist/game/data/HomunculusSlotData.xml @@ -0,0 +1,150 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/L2J_Mobius_10.2_MasterClass/dist/game/data/xsd/HomunculusCreationData.xsd b/L2J_Mobius_10.2_MasterClass/dist/game/data/xsd/HomunculusCreationData.xsd new file mode 100644 index 0000000000..8331a269fb --- /dev/null +++ b/L2J_Mobius_10.2_MasterClass/dist/game/data/xsd/HomunculusCreationData.xsd @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/L2J_Mobius_10.2_MasterClass/dist/game/data/xsd/HomunculusSlotData.xsd b/L2J_Mobius_10.2_MasterClass/dist/game/data/xsd/HomunculusSlotData.xsd new file mode 100644 index 0000000000..73e250515d --- /dev/null +++ b/L2J_Mobius_10.2_MasterClass/dist/game/data/xsd/HomunculusSlotData.xsd @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/GameServer.java b/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/GameServer.java index 1b17a02ea9..29dae8dc2e 100644 --- a/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/GameServer.java +++ b/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/GameServer.java @@ -76,7 +76,9 @@ import org.l2jmobius.gameserver.data.xml.FenceData; import org.l2jmobius.gameserver.data.xml.FishingData; import org.l2jmobius.gameserver.data.xml.HennaData; import org.l2jmobius.gameserver.data.xml.HitConditionBonusData; +import org.l2jmobius.gameserver.data.xml.HomunculusCreationData; import org.l2jmobius.gameserver.data.xml.HomunculusData; +import org.l2jmobius.gameserver.data.xml.HomunculusSlotData; import org.l2jmobius.gameserver.data.xml.InitialEquipmentData; import org.l2jmobius.gameserver.data.xml.InitialShortcutData; import org.l2jmobius.gameserver.data.xml.ItemCrystallizationData; @@ -343,6 +345,8 @@ public class GameServer GrandBossManager.getInstance(); EventDropManager.getInstance(); HomunculusData.getInstance(); + HomunculusSlotData.getInstance(); + HomunculusCreationData.getInstance(); printSection("Instance"); InstanceManager.getInstance(); diff --git a/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/data/xml/HomunculusCreationData.java b/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/data/xml/HomunculusCreationData.java new file mode 100644 index 0000000000..088ebb8432 --- /dev/null +++ b/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/data/xml/HomunculusCreationData.java @@ -0,0 +1,175 @@ +/* + * 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 . + */ +package org.l2jmobius.gameserver.data.xml; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.w3c.dom.Document; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; + +import org.l2jmobius.commons.util.IXmlReader; +import org.l2jmobius.gameserver.model.StatSet; +import org.l2jmobius.gameserver.model.holders.ItemHolder; +import org.l2jmobius.gameserver.model.homunculus.HomunculusCreationTemplate; + +/** + * @author Index + */ +public class HomunculusCreationData implements IXmlReader +{ + private final Map _templates = new HashMap<>(); + + protected HomunculusCreationData() + { + load(); + } + + @Override + public void load() + { + _templates.clear(); + parseDatapackFile("data/HomunculusCreationData.xml"); + LOGGER.info(getClass().getSimpleName() + ": Loaded " + _templates.size() + " templates."); + } + + @Override + public void parseDocument(Document doc, File f) + { + StatSet set; + Node att; + NamedNodeMap attrs; + for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling()) + { + if ("list".equalsIgnoreCase(n.getNodeName())) + { + for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling()) + { + if ("homunculusCreation".equalsIgnoreCase(d.getNodeName())) + { + attrs = d.getAttributes(); + set = new StatSet(); + for (int i = 0; i < attrs.getLength(); i++) + { + att = attrs.item(i); + set.set(att.getNodeName(), att.getNodeValue()); + } + + final int slotId = set.getInt("slotId", 0); + final Boolean isEnabled = set.getBoolean("isEnabled", false); + final int grade = set.getInt("grade", 0); + final Boolean isEvent = set.getBoolean("event", false); + List itemFees = Collections.emptyList(); + Integer[] hpFee = new Integer[2]; + Long[] spFee = new Long[2]; + Integer[] vpFee = new Integer[2]; + long time = 0; + List chances = Collections.emptyList(); + for (Node b = d.getFirstChild(); b != null; b = b.getNextSibling()) + { + if ("itemFees".equalsIgnoreCase(b.getNodeName())) + { + itemFees = getItemList(b); + } + else if ("hpFee".equalsIgnoreCase(b.getNodeName())) + { + hpFee[0] = Integer.parseInt(b.getAttributes().getNamedItem("count").getNodeValue()); + hpFee[1] = Integer.parseInt(b.getAttributes().getNamedItem("byUse").getNodeValue()); + } + else if ("spFee".equalsIgnoreCase(b.getNodeName())) + { + spFee[0] = Long.parseLong(b.getAttributes().getNamedItem("count").getNodeValue()); + spFee[1] = Long.parseLong(b.getAttributes().getNamedItem("byUse").getNodeValue()); + } + else if ("vpFee".equalsIgnoreCase(b.getNodeName())) + { + vpFee[0] = Integer.parseInt(b.getAttributes().getNamedItem("count").getNodeValue()); + vpFee[1] = Integer.parseInt(b.getAttributes().getNamedItem("byUse").getNodeValue()); + } + else if ("time".equalsIgnoreCase(b.getNodeName())) + { + time = Long.parseLong(b.getAttributes().getNamedItem("count").getNodeValue()); + } + else if ("chance".equalsIgnoreCase(b.getNodeName())) + { + chances = getChanceList(b); + } + } + + _templates.put(slotId, new HomunculusCreationTemplate(slotId, isEnabled, grade, isEvent, itemFees, hpFee, spFee, vpFee, time, chances)); + } + } + } + } + } + + private List getItemList(Node c) + { + final List items = new ArrayList<>(); + for (Node b = c.getFirstChild(); b != null; b = b.getNextSibling()) + { + if ("item".equalsIgnoreCase(b.getNodeName())) + { + final int itemId = Integer.parseInt(b.getAttributes().getNamedItem("id").getNodeValue()); + final long itemCount = Long.parseLong(b.getAttributes().getNamedItem("count").getNodeValue()); + items.add(new ItemHolder(itemId, itemCount)); + } + } + return items; + } + + private List getChanceList(Node c) + { + final List chanceList = new ArrayList<>(); + for (Node b = c.getFirstChild(); b != null; b = b.getNextSibling()) + { + if ("homunculus".equalsIgnoreCase(b.getNodeName())) + { + final Double[] feeArray = new Double[2]; + feeArray[0] = Double.parseDouble(b.getAttributes().getNamedItem("id").getNodeValue()); + feeArray[1] = Double.parseDouble(b.getAttributes().getNamedItem("creationChance").getNodeValue()); + chanceList.add(feeArray); + } + } + return chanceList; + } + + public HomunculusCreationTemplate getTemplate(int id) + { + return _templates.get(id); + } + + public int size() + { + return _templates.size(); + } + + public static HomunculusCreationData getInstance() + { + return SingletonHolder.INSTANCE; + } + + private static class SingletonHolder + { + protected static final HomunculusCreationData INSTANCE = new HomunculusCreationData(); + } +} diff --git a/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/data/xml/HomunculusSlotData.java b/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/data/xml/HomunculusSlotData.java new file mode 100644 index 0000000000..5fd6b439cf --- /dev/null +++ b/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/data/xml/HomunculusSlotData.java @@ -0,0 +1,129 @@ +/* + * 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 . + */ +package org.l2jmobius.gameserver.data.xml; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.w3c.dom.Document; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; + +import org.l2jmobius.commons.util.IXmlReader; +import org.l2jmobius.gameserver.model.StatSet; +import org.l2jmobius.gameserver.model.holders.ItemHolder; +import org.l2jmobius.gameserver.model.homunculus.HomunculusSlotTemplate; + +/** + * @author Index + */ +public class HomunculusSlotData implements IXmlReader +{ + private final Map _templates = new HashMap<>(); + + protected HomunculusSlotData() + { + load(); + } + + @Override + public void load() + { + _templates.clear(); + parseDatapackFile("data/HomunculusSlotData.xml"); + LOGGER.info(getClass().getSimpleName() + ": Loaded " + _templates.size() + " templates."); + } + + @Override + public void parseDocument(Document doc, File f) + { + StatSet set; + Node att; + NamedNodeMap attrs; + for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling()) + { + if ("list".equalsIgnoreCase(n.getNodeName())) + { + for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling()) + { + if ("homunculusSlot".equalsIgnoreCase(d.getNodeName())) + { + attrs = d.getAttributes(); + set = new StatSet(); + for (int i = 0; i < attrs.getLength(); i++) + { + att = attrs.item(i); + set.set(att.getNodeName(), att.getNodeValue()); + } + + final int slotId = set.getInt("slotId"); + final Boolean isEnabled = set.getBoolean("isEnabled", false); + List fee = Collections.emptyList(); + + for (Node c = d.getFirstChild(); c != null; c = c.getNextSibling()) + { + if ("fee".equalsIgnoreCase(c.getNodeName())) + { + fee = getItemList(c); + } + } + _templates.put(slotId, new HomunculusSlotTemplate(slotId, fee, isEnabled)); + } + } + } + } + } + + private List getItemList(Node c) + { + final List items = new ArrayList<>(); + for (Node b = c.getFirstChild(); b != null; b = b.getNextSibling()) + { + if ("item".equalsIgnoreCase(b.getNodeName())) + { + final int itemId = Integer.parseInt(b.getAttributes().getNamedItem("id").getNodeValue()); + final long itemCount = Long.parseLong(b.getAttributes().getNamedItem("count").getNodeValue()); + items.add(new ItemHolder(itemId, itemCount)); + } + } + return items; + } + + public HomunculusSlotTemplate getTemplate(int id) + { + return _templates.get(id); + } + + public int size() + { + return _templates.size(); + } + + public static HomunculusSlotData getInstance() + { + return SingletonHolder.INSTANCE; + } + + private static class SingletonHolder + { + protected static final HomunculusSlotData INSTANCE = new HomunculusSlotData(); + } +} diff --git a/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/model/homunculus/HomunculusCreationTemplate.java b/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/model/homunculus/HomunculusCreationTemplate.java new file mode 100644 index 0000000000..8a9d603ba6 --- /dev/null +++ b/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/model/homunculus/HomunculusCreationTemplate.java @@ -0,0 +1,142 @@ +/* + * 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 . + */ +package org.l2jmobius.gameserver.model.homunculus; + +import java.util.List; + +import org.l2jmobius.gameserver.model.holders.ItemHolder; + +public class HomunculusCreationTemplate +{ + private final int _slotId; + private final boolean _isEnabled; + private final int _grade; + private final boolean _isEvent; + private final List _itemsFee; + private final Integer[] _hpFee; + private final Long[] _spFee; + private final Integer[] _vpFee; + private final long _time; + private final List _createChances; + + public HomunculusCreationTemplate(int slotId, boolean isEnabled, int grade, boolean isEvent, List itemsFee, Integer[] hpFee, Long[] spFee, Integer[] vpFee, long time, List createChances) + { + _slotId = slotId; + _isEnabled = isEnabled; + _grade = grade; + _isEvent = isEvent; + _itemsFee = itemsFee; + _hpFee = hpFee; + _spFee = spFee; + _vpFee = vpFee; + _time = time; + _createChances = createChances; + } + + public int getSlotId() + { + return _slotId; + } + + public boolean isEnabled() + { + return _isEnabled; + } + + public int getGrade() + { + return _grade; + } + + public boolean isEvent() + { + return _isEvent; + } + + public List getItemFee() + { + return _itemsFee; + } + + public boolean haveAnotherFee() + { + return !_itemsFee.isEmpty(); + } + + public int getHPFeeCountByUse() + { + return _hpFee[1]; + } + + public int getHPFeeCount() + { + return _hpFee[0]; + } + + public long getSPFeeCountByUse() + { + return _spFee[1]; + } + + public long getSPFeeCount() + { + return _spFee[0]; + } + + public int getVPFeeByUse() + { + return _vpFee[1]; + } + + public int getVPFeeCount() + { + return _vpFee[0]; + } + + public double getMaxChance() + { + double result = 0; + for (int i = 0; i < _createChances.size(); i++) + { + Double[] chance = _createChances.get(i); + result = result + chance[1]; + } + return result; + } + + public boolean isInstanceHaveCoupon(int itemId) + { + for (ItemHolder humu : _itemsFee) + { + if (humu.getId() == itemId) + { + return true; + } + } + return false; + } + + public long getCreationLime() + { + return _time; + } + + public List getCreationChance() + { + return _createChances; + } +} diff --git a/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/model/homunculus/HomunculusSlotTemplate.java b/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/model/homunculus/HomunculusSlotTemplate.java new file mode 100644 index 0000000000..6125633dd1 --- /dev/null +++ b/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/model/homunculus/HomunculusSlotTemplate.java @@ -0,0 +1,50 @@ +/* + * 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 . + */ +package org.l2jmobius.gameserver.model.homunculus; + +import java.util.List; + +import org.l2jmobius.gameserver.model.holders.ItemHolder; + +public class HomunculusSlotTemplate +{ + private final int _slotId; + private final List _price; + private final boolean _isEnabled; + + public HomunculusSlotTemplate(int slotId, List price, boolean isEnabled) + { + _slotId = slotId; + _price = price; + _isEnabled = isEnabled; + } + + public int getSlotId() + { + return _slotId; + } + + public List getPrice() + { + return _price; + } + + public boolean getSlotEnabled() + { + return _isEnabled; + } +} diff --git a/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/model/variables/PlayerVariables.java b/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/model/variables/PlayerVariables.java index 346db019d8..e40be28720 100644 --- a/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/model/variables/PlayerVariables.java +++ b/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/model/variables/PlayerVariables.java @@ -81,6 +81,7 @@ public class PlayerVariables extends AbstractVariables public static final String HOMUNCULUS_USED_VP_POINTS = "HOMUNCULUS_USED_VP_POINTS"; public static final String HOMUNCULUS_USED_VP_CONVERT = "HOMUNCULUS_USED_VP_CONVERT"; public static final String HOMUNCULUS_USED_RESET_VP = "HOMUNCULUS_USED_RESET_VP"; + public static final String HOMUNCULUS_OPENED_SLOT_COUNT = "HOMUNCULUS_OPENED_SLOT_COUNT"; private final int _objectId; diff --git a/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/ExHomunculusCouponProbabilityList.java b/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/ExHomunculusCouponProbabilityList.java index c2b830cdf7..8973e411de 100644 --- a/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/ExHomunculusCouponProbabilityList.java +++ b/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/ExHomunculusCouponProbabilityList.java @@ -17,8 +17,10 @@ package org.l2jmobius.gameserver.network.clientpackets.homunculus; import org.l2jmobius.commons.network.PacketWriter; +import org.l2jmobius.gameserver.data.xml.HomunculusCreationData; import org.l2jmobius.gameserver.data.xml.HomunculusData; import org.l2jmobius.gameserver.model.actor.Player; +import org.l2jmobius.gameserver.model.homunculus.HomunculusCreationTemplate; import org.l2jmobius.gameserver.network.OutgoingPackets; import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket; @@ -44,32 +46,33 @@ public class ExHomunculusCouponProbabilityList implements IClientOutgoingPacket return false; } + HomunculusCreationTemplate creationTemplate = null; + for (int i = 1; i < HomunculusCreationData.getInstance().size(); i++) + { + if (HomunculusCreationData.getInstance().getTemplate(i).isInstanceHaveCoupon(_couponId)) + { + creationTemplate = HomunculusCreationData.getInstance().getTemplate(i); + } + } + if (creationTemplate == null) + { + return false; + } + OutgoingPackets.EX_HOMUNCULUS_COUPON_PROB_LIST.writeId(packet); - final int size = HomunculusData.getInstance().size(); + final int size = creationTemplate.getCreationChance().size(); packet.writeD(_couponId); packet.writeD(size); - for (int i = 1; i < size; i++) + for (int type = 0; type < 3; type++) { - if (HomunculusData.getInstance().getTemplate(i).getType() == 0) + for (int i = 0; i < size; i++) { - packet.writeD(i); - packet.writeD(7000000); - } - } - for (int i = 1; i < size; i++) - { - if (HomunculusData.getInstance().getTemplate(i).getType() == 1) - { - packet.writeD(i); - packet.writeD(2990000); - } - } - for (int i = 1; i <= size; i++) - { - if (HomunculusData.getInstance().getTemplate(i).getType() == 2) - { - packet.writeD(i); - packet.writeD(10000); + final Double[] homunculusChance = creationTemplate.getCreationChance().get(i); + if (HomunculusData.getInstance().getTemplate(homunculusChance[0].intValue()).getType() == type) + { + packet.writeD(homunculusChance[0].intValue()); + packet.writeD((int) (homunculusChance[1] * 1000000)); + } } } return true; diff --git a/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusActivateSlot.java b/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusActivateSlot.java index bb5463298d..6acd0c04a7 100644 --- a/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusActivateSlot.java +++ b/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusActivateSlot.java @@ -16,13 +16,20 @@ */ package org.l2jmobius.gameserver.network.clientpackets.homunculus; -import org.l2jmobius.Config; +import java.util.List; +import java.util.logging.Logger; + import org.l2jmobius.commons.network.PacketReader; +import org.l2jmobius.gameserver.data.xml.HomunculusSlotData; import org.l2jmobius.gameserver.model.actor.Player; -import org.l2jmobius.gameserver.model.homunculus.Homunculus; +import org.l2jmobius.gameserver.model.holders.ItemHolder; +import org.l2jmobius.gameserver.model.homunculus.HomunculusSlotTemplate; +import org.l2jmobius.gameserver.model.variables.PlayerVariables; import org.l2jmobius.gameserver.network.GameClient; +import org.l2jmobius.gameserver.network.PacketLogger; import org.l2jmobius.gameserver.network.clientpackets.IClientIncomingPacket; import org.l2jmobius.gameserver.network.serverpackets.homunculus.ExActivateHomunculusResult; +import org.l2jmobius.gameserver.network.serverpackets.homunculus.ExHomunculusPointInfo; import org.l2jmobius.gameserver.network.serverpackets.homunculus.ExShowHomunculusList; /** @@ -31,13 +38,12 @@ import org.l2jmobius.gameserver.network.serverpackets.homunculus.ExShowHomunculu public class RequestExHomunculusActivateSlot implements IClientIncomingPacket { private int _slot; - private boolean _activate; @Override public boolean read(GameClient client, PacketReader packet) { _slot = packet.readD(); - _activate = packet.readC() == 1; // enabled? + // _activate = packet.readC() == 1; // enabled? return true; } @@ -51,62 +57,46 @@ public class RequestExHomunculusActivateSlot implements IClientIncomingPacket } final int size = activeChar.getHomunculusList().size(); - if (size == 0) + final HomunculusSlotTemplate template = HomunculusSlotData.getInstance().getTemplate(_slot); + if ((size != 0) && ((activeChar.getHomunculusList().get(_slot) != null) || (_slot == activeChar.getVariables().getInt(PlayerVariables.HOMUNCULUS_OPENED_SLOT_COUNT)))) { + PacketLogger.info(getClass().getSimpleName() + " player " + activeChar.getName() + " " + activeChar.getObjectId() + " trying unlock already unlocked slot;"); + activeChar.sendPacket(new ExActivateHomunculusResult(false)); + return; + } + if (!template.getSlotEnabled()) + { + Logger.getLogger(getClass().getSimpleName() + " player " + activeChar.getName() + " " + activeChar.getObjectId() + " trying unlock disabled slot;"); + activeChar.sendPacket(new ExActivateHomunculusResult(false)); return; } - final Homunculus homunculus = activeChar.getHomunculusList().get(_slot); - if (homunculus == null) + final List fee = template.getPrice(); + for (int i = 0; i < fee.size(); i++) { - return; - } - - for (int i = 0; i < Config.MAX_HOMUNCULUS_COUNT; i++) - { - if (size <= i) + final ItemHolder feeHolder = fee.get(i); + if ((activeChar.getInventory().getItemByItemId(feeHolder.getId()) == null) || ((activeChar.getInventory().getItemByItemId(feeHolder.getId()) != null) && (activeChar.getInventory().getItemByItemId(feeHolder.getId()).getCount() < feeHolder.getCount()))) { - break; - } - - final Homunculus homu = activeChar.getHomunculusList().get(i); - if (homu == null) - { - continue; - } - - if (homu.isActive()) - { - homu.setActive(false); - activeChar.getHomunculusList().update(homu); - activeChar.getHomunculusList().refreshStats(true); - activeChar.sendPacket(new ExShowHomunculusList(activeChar)); activeChar.sendPacket(new ExActivateHomunculusResult(false)); + return; + } + } + for (int i = 0; i < fee.size(); i++) + { + final ItemHolder feeHolder = fee.get(i); + if (activeChar.getInventory().destroyItemByItemId("Homunclus slot unlock", feeHolder.getId(), feeHolder.getCount(), activeChar, null) == null) + { + Logger.getLogger(getClass().getSimpleName() + " player " + activeChar.getName() + " " + activeChar.getObjectId() + " trying unlock slot without items;"); + activeChar.sendPacket(new ExActivateHomunculusResult(false)); + return; } } - if (_activate) - { - if (!homunculus.isActive()) - { - - homunculus.setActive(true); - activeChar.getHomunculusList().update(homunculus); - activeChar.getHomunculusList().refreshStats(true); - activeChar.sendPacket(new ExShowHomunculusList(activeChar)); - activeChar.sendPacket(new ExActivateHomunculusResult(true)); - } - } - else - { - if (homunculus.isActive()) - { - homunculus.setActive(false); - activeChar.getHomunculusList().update(homunculus); - activeChar.getHomunculusList().refreshStats(true); - activeChar.sendPacket(new ExShowHomunculusList(activeChar)); - activeChar.sendPacket(new ExActivateHomunculusResult(false)); - } - } + activeChar.sendItemList(); + activeChar.broadcastUserInfo(); + activeChar.getVariables().set(PlayerVariables.HOMUNCULUS_OPENED_SLOT_COUNT, _slot); + activeChar.sendPacket(new ExHomunculusPointInfo(activeChar)); + activeChar.sendPacket(new ExShowHomunculusList(activeChar)); + activeChar.sendPacket(new ExActivateHomunculusResult(true)); } } diff --git a/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusCreateStart.java b/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusCreateStart.java index 9764bb52ea..ff6c14c952 100644 --- a/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusCreateStart.java +++ b/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusCreateStart.java @@ -17,7 +17,9 @@ package org.l2jmobius.gameserver.network.clientpackets.homunculus; import org.l2jmobius.commons.network.PacketReader; +import org.l2jmobius.gameserver.data.xml.HomunculusCreationData; import org.l2jmobius.gameserver.model.actor.Player; +import org.l2jmobius.gameserver.model.homunculus.HomunculusCreationTemplate; import org.l2jmobius.gameserver.model.variables.PlayerVariables; import org.l2jmobius.gameserver.network.GameClient; import org.l2jmobius.gameserver.network.SystemMessageId; @@ -30,8 +32,9 @@ import org.l2jmobius.gameserver.network.serverpackets.homunculus.ExShowHomunculu */ public class RequestExHomunculusCreateStart implements IClientIncomingPacket { - private static final int COST = 1000000; - private static final long CREATION_TIME = 86400000L; + private static final HomunculusCreationTemplate TEMPLATE = HomunculusCreationData.getInstance().getTemplate(0); + private static final int COST = Math.toIntExact(TEMPLATE.getItemFee().get(0).getCount()); + private static final long CREATION_TIME = TEMPLATE.getCreationLime(); @Override public boolean read(GameClient client, PacketReader packet) @@ -53,6 +56,7 @@ public class RequestExHomunculusCreateStart implements IClientIncomingPacket player.sendPacket(SystemMessageId.NOT_ENOUGH_ADENA_2); return; } + player.reduceAdena("Homunculus creation", COST, player, true); player.getVariables().set(PlayerVariables.HOMUNCULUS_CREATION_TIME, System.currentTimeMillis() + CREATION_TIME); diff --git a/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusInsert.java b/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusInsert.java index 6a2e480084..dde47a5571 100644 --- a/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusInsert.java +++ b/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusInsert.java @@ -17,8 +17,9 @@ package org.l2jmobius.gameserver.network.clientpackets.homunculus; import org.l2jmobius.commons.network.PacketReader; +import org.l2jmobius.gameserver.data.xml.HomunculusCreationData; import org.l2jmobius.gameserver.model.actor.Player; -import org.l2jmobius.gameserver.model.actor.stat.PlayerStat; +import org.l2jmobius.gameserver.model.homunculus.HomunculusCreationTemplate; import org.l2jmobius.gameserver.model.variables.PlayerVariables; import org.l2jmobius.gameserver.network.GameClient; import org.l2jmobius.gameserver.network.clientpackets.IClientIncomingPacket; @@ -31,9 +32,10 @@ import org.l2jmobius.gameserver.network.serverpackets.homunculus.ExShowHomunculu */ public class RequestExHomunculusInsert implements IClientIncomingPacket { - private static final short HP_COST = 10000; - private static final long SP_COST = 5000000000L; - private static final int VP_COST = PlayerStat.MAX_VITALITY_POINTS / 4; + private static final HomunculusCreationTemplate TEMPLATE = HomunculusCreationData.getInstance().getTemplate(0); + private static final short HP_COST = (short) TEMPLATE.getHPFeeCountByUse(); + private static final long SP_COST = TEMPLATE.getSPFeeCountByUse(); + private static final int VP_COST = TEMPLATE.getVPFeeByUse(); private int _type; @@ -59,7 +61,7 @@ public class RequestExHomunculusInsert implements IClientIncomingPacket { case 0: { - if ((player.getCurrentHp() > HP_COST) && (hpPoints < 100)) + if ((player.getCurrentHp() > HP_COST) && (hpPoints < TEMPLATE.getHPFeeCount())) { int newHp = (int) (player.getCurrentHp()) - HP_COST; player.setCurrentHp(newHp, true); @@ -74,7 +76,7 @@ public class RequestExHomunculusInsert implements IClientIncomingPacket } case 1: { - if ((player.getSp() >= SP_COST) && (spPoints < 10)) + if ((player.getSp() >= SP_COST) && (spPoints < TEMPLATE.getSPFeeCount())) { player.setSp(player.getSp() - SP_COST); spPoints += 1; @@ -88,7 +90,7 @@ public class RequestExHomunculusInsert implements IClientIncomingPacket } case 2: { - if ((player.getVitalityPoints() >= VP_COST) && (vpPoints < 5)) + if ((player.getVitalityPoints() >= VP_COST) && (vpPoints < TEMPLATE.getVPFeeCount())) { int newVitality = player.getVitalityPoints() - VP_COST; player.setVitalityPoints(newVitality, true); diff --git a/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusSummon.java b/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusSummon.java index ec603ce4ef..c7acfe0cc6 100644 --- a/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusSummon.java +++ b/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExHomunculusSummon.java @@ -18,9 +18,11 @@ package org.l2jmobius.gameserver.network.clientpackets.homunculus; import org.l2jmobius.commons.network.PacketReader; import org.l2jmobius.commons.util.Rnd; +import org.l2jmobius.gameserver.data.xml.HomunculusCreationData; import org.l2jmobius.gameserver.data.xml.HomunculusData; import org.l2jmobius.gameserver.model.actor.Player; import org.l2jmobius.gameserver.model.homunculus.Homunculus; +import org.l2jmobius.gameserver.model.homunculus.HomunculusCreationTemplate; import org.l2jmobius.gameserver.model.homunculus.HomunculusTemplate; import org.l2jmobius.gameserver.model.variables.PlayerVariables; import org.l2jmobius.gameserver.network.GameClient; @@ -29,12 +31,15 @@ import org.l2jmobius.gameserver.network.clientpackets.IClientIncomingPacket; import org.l2jmobius.gameserver.network.serverpackets.homunculus.ExHomunculusSummonResult; import org.l2jmobius.gameserver.network.serverpackets.homunculus.ExShowHomunculusBirthInfo; import org.l2jmobius.gameserver.network.serverpackets.homunculus.ExShowHomunculusList; +import org.l2jmobius.gameserver.network.serverpackets.homunculus.ExSummonHomunculusCouponResult; /** * @author Mobius */ public class RequestExHomunculusSummon implements IClientIncomingPacket { + private static final HomunculusCreationTemplate TEMPLATE = HomunculusCreationData.getInstance().getTemplate(0); + @Override public boolean read(GameClient client, PacketReader packet) { @@ -56,148 +61,27 @@ public class RequestExHomunculusSummon implements IClientIncomingPacket final int vpPoints = player.getVariables().getInt(PlayerVariables.HOMUNCULUS_VP_POINTS, 0); final int homunculusCreateTime = (int) (player.getVariables().getLong(PlayerVariables.HOMUNCULUS_CREATION_TIME, 0) / 1000); - if ((homunculusCreateTime > 0) && ((System.currentTimeMillis() / 1000) >= homunculusCreateTime) && (hpPoints == 100) && (spPoints == 10) && (vpPoints == 5)) + if ((homunculusCreateTime > 0) && ((System.currentTimeMillis() / 1000) >= homunculusCreateTime) && (hpPoints == TEMPLATE.getHPFeeCount()) && (spPoints == TEMPLATE.getSPFeeCount()) && (vpPoints == TEMPLATE.getVPFeeCount())) { - int chance; - int random; + double chance = Rnd.get(100.0); + double current = 0; int homunculusId = 0; while (homunculusId == 0) { - chance = Rnd.get(100); - random = Rnd.get(100); - - // Basic Homunculus - if (chance >= 70) + if (chance > TEMPLATE.getMaxChance()) { - if ((random >= 90) && !player.getHomunculusList().hasHomunculus(1)) - { - homunculusId = 1; - } - else if ((random >= 80) && !player.getHomunculusList().hasHomunculus(4)) - { - homunculusId = 4; - } - else if ((random >= 70) && !player.getHomunculusList().hasHomunculus(7)) - { - homunculusId = 7; - } - else if ((random >= 60) && !player.getHomunculusList().hasHomunculus(10)) - { - homunculusId = 10; - } - else if ((random >= 50) && !player.getHomunculusList().hasHomunculus(13)) - { - homunculusId = 13; - } - else if ((random >= 40) && !player.getHomunculusList().hasHomunculus(16)) - { - homunculusId = 16; - } - else if ((random >= 30) && !player.getHomunculusList().hasHomunculus(19)) - { - homunculusId = 19; - } - else if ((random >= 20) && !player.getHomunculusList().hasHomunculus(22)) - { - homunculusId = 22; - } - else if ((random >= 10) && !player.getHomunculusList().hasHomunculus(25)) - { - homunculusId = 25; - } - else if (!player.getHomunculusList().hasHomunculus(28)) - { - homunculusId = 28; - } + player.sendMessage("Homunculus is not created!"); + player.sendPacket(new ExSummonHomunculusCouponResult(0, 0)); + return; } - - // Water Homunculus - if ((homunculusId == 0) && (chance >= 1)) + for (int i = 0; i < TEMPLATE.getCreationChance().size(); i++) { - if ((random >= 90) && !player.getHomunculusList().hasHomunculus(2)) + final Double[] homuHolder = TEMPLATE.getCreationChance().get(i); + current += homuHolder[1]; + if (current >= chance) { - homunculusId = 2; - } - else if ((random >= 80) && !player.getHomunculusList().hasHomunculus(5)) - { - homunculusId = 5; - } - else if ((random >= 70) && !player.getHomunculusList().hasHomunculus(8)) - { - homunculusId = 8; - } - else if ((random >= 60) && !player.getHomunculusList().hasHomunculus(11)) - { - homunculusId = 11; - } - else if ((random >= 50) && !player.getHomunculusList().hasHomunculus(14)) - { - homunculusId = 14; - } - else if ((random >= 40) && !player.getHomunculusList().hasHomunculus(17)) - { - homunculusId = 17; - } - else if ((random >= 30) && !player.getHomunculusList().hasHomunculus(20)) - { - homunculusId = 20; - } - else if ((random >= 20) && !player.getHomunculusList().hasHomunculus(23)) - { - homunculusId = 23; - } - else if ((random >= 10) && !player.getHomunculusList().hasHomunculus(26)) - { - homunculusId = 26; - } - else if (!player.getHomunculusList().hasHomunculus(29)) - { - homunculusId = 29; - } - } - - // Luminous Homunculus - if (homunculusId == 0) - { - if ((random >= 90) && !player.getHomunculusList().hasHomunculus(3)) - { - homunculusId = 3; - } - else if ((random >= 80) && !player.getHomunculusList().hasHomunculus(6)) - { - homunculusId = 6; - } - else if ((random >= 70) && !player.getHomunculusList().hasHomunculus(9)) - { - homunculusId = 9; - } - else if ((random >= 60) && !player.getHomunculusList().hasHomunculus(12)) - { - homunculusId = 12; - } - else if ((random >= 50) && !player.getHomunculusList().hasHomunculus(15)) - { - homunculusId = 15; - } - else if ((random >= 40) && !player.getHomunculusList().hasHomunculus(18)) - { - homunculusId = 18; - } - else if ((random >= 30) && !player.getHomunculusList().hasHomunculus(21)) - { - homunculusId = 21; - } - else if ((random >= 20) && !player.getHomunculusList().hasHomunculus(24)) - { - homunculusId = 24; - } - else if ((random >= 10) && !player.getHomunculusList().hasHomunculus(27)) - { - homunculusId = 27; - } - else if (!player.getHomunculusList().hasHomunculus(30)) - { - homunculusId = 30; + homunculusId = homuHolder[0].intValue(); + break; } } } diff --git a/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExSummonHomunculusCouponResult.java b/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExSummonHomunculusCouponResult.java index 9c9096d387..4d369cf581 100644 --- a/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExSummonHomunculusCouponResult.java +++ b/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/network/clientpackets/homunculus/RequestExSummonHomunculusCouponResult.java @@ -18,10 +18,14 @@ package org.l2jmobius.gameserver.network.clientpackets.homunculus; import org.l2jmobius.commons.network.PacketReader; import org.l2jmobius.commons.util.Rnd; +import org.l2jmobius.gameserver.data.xml.HomunculusCreationData; import org.l2jmobius.gameserver.data.xml.HomunculusData; import org.l2jmobius.gameserver.model.actor.Player; +import org.l2jmobius.gameserver.model.holders.ItemHolder; import org.l2jmobius.gameserver.model.homunculus.Homunculus; +import org.l2jmobius.gameserver.model.homunculus.HomunculusCreationTemplate; import org.l2jmobius.gameserver.model.homunculus.HomunculusTemplate; +import org.l2jmobius.gameserver.model.variables.PlayerVariables; import org.l2jmobius.gameserver.network.GameClient; import org.l2jmobius.gameserver.network.PacketLogger; import org.l2jmobius.gameserver.network.clientpackets.IClientIncomingPacket; @@ -34,15 +38,12 @@ import org.l2jmobius.gameserver.network.serverpackets.homunculus.ExSummonHomuncu */ public class RequestExSummonHomunculusCouponResult implements IClientIncomingPacket { - private static final int HOURGLASS = 81815; - private static final int HOURGLASS_SHINY = 81879; - private static final int ADENA = 57; - private static final int ADENA_COUNT = 2000000; + private int _item_id; @Override public boolean read(GameClient client, PacketReader packet) { - // packet.readD(); + _item_id = packet.readD(); return true; } @@ -55,161 +56,64 @@ public class RequestExSummonHomunculusCouponResult implements IClientIncomingPac return; } - // Take items. - if ((player.getInventory().getItemByItemId(HOURGLASS) != null) && (player.getInventory().getItemByItemId(ADENA).getCount() > ADENA_COUNT)) - { - player.destroyItemByItemId("Homunculus Hourglass", HOURGLASS, 1, player, true); - } - else if ((player.getInventory().getItemByItemId(HOURGLASS_SHINY) != null) && (player.getInventory().getItemByItemId(ADENA).getCount() >= ADENA_COUNT)) - { - player.destroyItemByItemId("Shiny Homunculus Hourglass", HOURGLASS_SHINY, 1, player, true); - } - else + if (player.getHomunculusList().size() == player.getVariables().getInt(PlayerVariables.HOMUNCULUS_OPENED_SLOT_COUNT)) { + player.sendPacket(new ExSummonHomunculusCouponResult(0, 0)); + PacketLogger.info("Player " + player.getObjectId() + " " + player.getName() + ", trying create homunculus withouts avaible slots;"); + return; + } + HomunculusCreationTemplate creationTemplate = null; + for (int i = 1; i < HomunculusCreationData.getInstance().size(); i++) + { + if (HomunculusCreationData.getInstance().getTemplate(i).isInstanceHaveCoupon(_item_id)) + { + creationTemplate = HomunculusCreationData.getInstance().getTemplate(i); + } + } + if ((creationTemplate == null) || (creationTemplate.getItemFee().size() == 0)) + { + PacketLogger.info("Player " + player.getObjectId() + " " + player.getName() + ", trying create homunculus with not existing coupon!"); return; } - player.destroyItemByItemId("Adena", ADENA, 2000000, player, true); - int chance; - int random; + // Take items. + for (int i = 0; i < creationTemplate.getItemFee().size(); i++) + { + ItemHolder humu = creationTemplate.getItemFee().get(i); + if (player.getInventory().getItemByItemId(humu.getId()).getCount() <= humu.getCount()) + { + return; + } + } + for (int i = 0; i < creationTemplate.getItemFee().size(); i++) + { + ItemHolder humu = creationTemplate.getItemFee().get(i); + if (!player.destroyItemByItemId("Homunculus Coupon Creation", humu.getId(), humu.getCount(), player, true)) + { + PacketLogger.info("Player " + player.getObjectId() + " " + player.getName() + ", trying create homunculus without " + humu + "!"); + return; + } + } + + double chance = Rnd.get(100.0); + double current = 0; int homunculusId = 0; while (homunculusId == 0) { - chance = Rnd.get(100); - random = Rnd.get(100); - - // Basic Homunculus - if (chance >= 60) + if (chance > creationTemplate.getMaxChance()) { - if ((random >= 90) && !player.getHomunculusList().hasHomunculus(1)) - { - homunculusId = 1; - } - else if ((random >= 80) && !player.getHomunculusList().hasHomunculus(4)) - { - homunculusId = 4; - } - else if ((random >= 70) && !player.getHomunculusList().hasHomunculus(7)) - { - homunculusId = 7; - } - else if ((random >= 60) && !player.getHomunculusList().hasHomunculus(10)) - { - homunculusId = 10; - } - else if ((random >= 50) && !player.getHomunculusList().hasHomunculus(13)) - { - homunculusId = 13; - } - else if ((random >= 40) && !player.getHomunculusList().hasHomunculus(16)) - { - homunculusId = 16; - } - else if ((random >= 30) && !player.getHomunculusList().hasHomunculus(19)) - { - homunculusId = 19; - } - else if ((random >= 20) && !player.getHomunculusList().hasHomunculus(22)) - { - homunculusId = 22; - } - else if ((random >= 10) && !player.getHomunculusList().hasHomunculus(25)) - { - homunculusId = 25; - } - else if (!player.getHomunculusList().hasHomunculus(28)) - { - homunculusId = 28; - } + player.sendMessage("Homunculus is not created!"); + player.sendPacket(new ExSummonHomunculusCouponResult(0, 0)); + return; } - - // Water Homunculus - if ((homunculusId == 0) && (chance >= 10)) + for (int i = 0; i < creationTemplate.getCreationChance().size(); i++) { - if ((random >= 90) && !player.getHomunculusList().hasHomunculus(2)) + final Double[] homuHolder = creationTemplate.getCreationChance().get(i); + current += homuHolder[1]; + if (current >= chance) { - homunculusId = 2; - } - else if ((random >= 80) && !player.getHomunculusList().hasHomunculus(5)) - { - homunculusId = 5; - } - else if ((random >= 70) && !player.getHomunculusList().hasHomunculus(8)) - { - homunculusId = 8; - } - else if ((random >= 60) && !player.getHomunculusList().hasHomunculus(11)) - { - homunculusId = 11; - } - else if ((random >= 50) && !player.getHomunculusList().hasHomunculus(14)) - { - homunculusId = 14; - } - else if ((random >= 40) && !player.getHomunculusList().hasHomunculus(17)) - { - homunculusId = 17; - } - else if ((random >= 30) && !player.getHomunculusList().hasHomunculus(20)) - { - homunculusId = 20; - } - else if ((random >= 20) && !player.getHomunculusList().hasHomunculus(23)) - { - homunculusId = 23; - } - else if ((random >= 10) && !player.getHomunculusList().hasHomunculus(26)) - { - homunculusId = 26; - } - else if (!player.getHomunculusList().hasHomunculus(29)) - { - homunculusId = 29; - } - } - - // Luminous Homunculus - if (homunculusId == 0) - { - if ((random >= 90) && !player.getHomunculusList().hasHomunculus(3)) - { - homunculusId = 3; - } - else if ((random >= 80) && !player.getHomunculusList().hasHomunculus(6)) - { - homunculusId = 6; - } - else if ((random >= 70) && !player.getHomunculusList().hasHomunculus(9)) - { - homunculusId = 9; - } - else if ((random >= 60) && !player.getHomunculusList().hasHomunculus(12)) - { - homunculusId = 12; - } - else if ((random >= 50) && !player.getHomunculusList().hasHomunculus(15)) - { - homunculusId = 15; - } - else if ((random >= 40) && !player.getHomunculusList().hasHomunculus(18)) - { - homunculusId = 18; - } - else if ((random >= 30) && !player.getHomunculusList().hasHomunculus(21)) - { - homunculusId = 21; - } - else if ((random >= 20) && !player.getHomunculusList().hasHomunculus(24)) - { - homunculusId = 24; - } - else if ((random >= 10) && !player.getHomunculusList().hasHomunculus(27)) - { - homunculusId = 27; - } - else if (!player.getHomunculusList().hasHomunculus(30)) - { - homunculusId = 30; + homunculusId = homuHolder[0].intValue(); + break; } } } diff --git a/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExHomunculusCreateProbabilityList.java b/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExHomunculusCreateProbabilityList.java index c7010c6cc8..cf78f6f5b4 100644 --- a/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExHomunculusCreateProbabilityList.java +++ b/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExHomunculusCreateProbabilityList.java @@ -17,8 +17,10 @@ package org.l2jmobius.gameserver.network.serverpackets.homunculus; import org.l2jmobius.commons.network.PacketWriter; +import org.l2jmobius.gameserver.data.xml.HomunculusCreationData; import org.l2jmobius.gameserver.data.xml.HomunculusData; import org.l2jmobius.gameserver.model.actor.Player; +import org.l2jmobius.gameserver.model.homunculus.HomunculusCreationTemplate; import org.l2jmobius.gameserver.network.OutgoingPackets; import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket; @@ -43,30 +45,19 @@ public class ExHomunculusCreateProbabilityList implements IClientOutgoingPacket } OutgoingPackets.EX_HOMUNCULUS_CREATE_PROB_LIST.writeId(packet); - final int size = HomunculusData.getInstance().size(); + HomunculusCreationTemplate creationTemplate = HomunculusCreationData.getInstance().getTemplate(0); + final int size = creationTemplate.getCreationChance().size(); packet.writeD(size); - for (int i = 1; i < size; i++) + for (int type = 0; type < 3; type++) { - if (HomunculusData.getInstance().getTemplate(i).getType() == 0) + for (int i = 0; i < size; i++) { - packet.writeD(i); - packet.writeD(7000000); - } - } - for (int i = 1; i < size; i++) - { - if (HomunculusData.getInstance().getTemplate(i).getType() == 1) - { - packet.writeD(i); - packet.writeD(2990000); - } - } - for (int i = 1; i <= size; i++) - { - if (HomunculusData.getInstance().getTemplate(i).getType() == 2) - { - packet.writeD(i); - packet.writeD(10000); + final Double[] chance = creationTemplate.getCreationChance().get(i); + if (HomunculusData.getInstance().getTemplate(chance[0].intValue()).getType() == type) + { + packet.writeD(chance[0].intValue()); + packet.writeD((int) (chance[1] * 1000000)); + } } } return true; diff --git a/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExHomunculusPointInfo.java b/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExHomunculusPointInfo.java index f26aefd800..550e908a64 100644 --- a/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExHomunculusPointInfo.java +++ b/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExHomunculusPointInfo.java @@ -16,7 +16,6 @@ */ package org.l2jmobius.gameserver.network.serverpackets.homunculus; -import org.l2jmobius.Config; import org.l2jmobius.commons.network.PacketWriter; import org.l2jmobius.gameserver.model.actor.Player; import org.l2jmobius.gameserver.model.variables.PlayerVariables; @@ -46,7 +45,7 @@ public class ExHomunculusPointInfo implements IClientOutgoingPacket packet.writeD(_player.getVariables().getInt(PlayerVariables.HOMUNCULUS_USED_VP_POINTS, 0)); // vp points packet.writeD(_player.getVariables().getInt(PlayerVariables.HOMUNCULUS_USED_VP_CONVERT, 0)); // consumed basic vp points packet.writeD(_player.getVariables().getInt(PlayerVariables.HOMUNCULUS_USED_RESET_VP, 0)); // consumed reset vp points - packet.writeD(Math.min(Config.MAX_HOMUNCULUS_COUNT, _player.getHomunculusList().size() + 1)); // 306 + packet.writeD(_player.getVariables().getInt(PlayerVariables.HOMUNCULUS_OPENED_SLOT_COUNT)); // 306 return true; } } diff --git a/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExShowHomunculusBirthInfo.java b/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExShowHomunculusBirthInfo.java index cdc24a4c11..33d7857cba 100644 --- a/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExShowHomunculusBirthInfo.java +++ b/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExShowHomunculusBirthInfo.java @@ -17,7 +17,9 @@ package org.l2jmobius.gameserver.network.serverpackets.homunculus; import org.l2jmobius.commons.network.PacketWriter; +import org.l2jmobius.gameserver.data.xml.HomunculusCreationData; import org.l2jmobius.gameserver.model.actor.Player; +import org.l2jmobius.gameserver.model.homunculus.HomunculusCreationTemplate; import org.l2jmobius.gameserver.model.variables.PlayerVariables; import org.l2jmobius.gameserver.network.OutgoingPackets; import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket; @@ -27,10 +29,15 @@ import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket; */ public class ExShowHomunculusBirthInfo implements IClientOutgoingPacket { + private static final HomunculusCreationTemplate TEMPLATE = HomunculusCreationData.getInstance().getTemplate(0); + private final int _hpPoints; private final int _spPoints; private final int _vpPoints; private final int _homunculusCreateTime; + private final int _feeHpPoints; + private final int _feeSpPoints; + private final int _feeVpPoints; public ExShowHomunculusBirthInfo(Player player) { @@ -38,6 +45,9 @@ public class ExShowHomunculusBirthInfo implements IClientOutgoingPacket _spPoints = player.getVariables().getInt(PlayerVariables.HOMUNCULUS_SP_POINTS, 0); _vpPoints = player.getVariables().getInt(PlayerVariables.HOMUNCULUS_VP_POINTS, 0); _homunculusCreateTime = (int) (player.getVariables().getLong(PlayerVariables.HOMUNCULUS_CREATION_TIME, 0) / 1000); + _feeHpPoints = TEMPLATE.getHPFeeCount(); + _feeSpPoints = (int) TEMPLATE.getSPFeeCount(); + _feeVpPoints = TEMPLATE.getVPFeeCount(); } @Override @@ -47,7 +57,7 @@ public class ExShowHomunculusBirthInfo implements IClientOutgoingPacket int creationStage = 0; if (_homunculusCreateTime > 0) { - if (((System.currentTimeMillis() / 1000) >= _homunculusCreateTime) && (_hpPoints == 100) && (_spPoints == 10) && (_vpPoints == 5)) + if (((System.currentTimeMillis() / 1000) >= _homunculusCreateTime) && (_hpPoints == _feeHpPoints) && (_spPoints == _feeSpPoints) && (_vpPoints == _feeVpPoints)) { creationStage = 2; } @@ -60,8 +70,8 @@ public class ExShowHomunculusBirthInfo implements IClientOutgoingPacket packet.writeD(_hpPoints); // hp points packet.writeD(_spPoints); // sp points packet.writeD(_vpPoints); // vp points - packet.writeD(_homunculusCreateTime); // finish time - packet.writeD(0); // JP = 0. ? + packet.writeQ(_homunculusCreateTime); // finish time + // packet.writeD(0); // JP = 0. ? return true; } } diff --git a/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExShowHomunculusList.java b/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExShowHomunculusList.java index 74372f0878..28369f119f 100644 --- a/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExShowHomunculusList.java +++ b/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExShowHomunculusList.java @@ -16,10 +16,10 @@ */ package org.l2jmobius.gameserver.network.serverpackets.homunculus; -import org.l2jmobius.Config; import org.l2jmobius.commons.network.PacketWriter; import org.l2jmobius.gameserver.model.actor.Player; import org.l2jmobius.gameserver.model.homunculus.Homunculus; +import org.l2jmobius.gameserver.model.variables.PlayerVariables; import org.l2jmobius.gameserver.network.OutgoingPackets; import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket; @@ -38,18 +38,34 @@ public class ExShowHomunculusList implements IClientOutgoingPacket @Override public boolean write(PacketWriter packet) { - OutgoingPackets.EX_SHOW_HOMUNCULUS_LIST.writeId(packet); - if (_player.getHomunculusList().size() > 0) + if ((_player.getVariables().getInt(PlayerVariables.HOMUNCULUS_OPENED_SLOT_COUNT, 0) == 0) || (_player.getVariables().getInt(PlayerVariables.HOMUNCULUS_OPENED_SLOT_COUNT) == 1) || (_player.getVariables().getInt(PlayerVariables.HOMUNCULUS_OPENED_SLOT_COUNT) == 2)) { - packet.writeD(_player.getHomunculusList().size()); // homunculus count - int counter = 0; - for (int i = 0; i < Config.MAX_HOMUNCULUS_COUNT; i++) + if ((_player.getHomunculusList() != null) && (_player.getHomunculusList().size() != 0) && (_player.getHomunculusList().size() < 2)) + { + if (_player.getVariables().getInt(PlayerVariables.HOMUNCULUS_CREATION_TIME, 0) >= 0) + { + _player.getVariables().set(PlayerVariables.HOMUNCULUS_OPENED_SLOT_COUNT, _player.getHomunculusList().size() + 1); + } + else + { + _player.getVariables().set(PlayerVariables.HOMUNCULUS_OPENED_SLOT_COUNT, _player.getHomunculusList().size()); + } + } + else + { + _player.getVariables().set(PlayerVariables.HOMUNCULUS_OPENED_SLOT_COUNT, 3); + } + } + + final int slotCount = _player.getVariables().getInt(PlayerVariables.HOMUNCULUS_OPENED_SLOT_COUNT); + OutgoingPackets.EX_SHOW_HOMUNCULUS_LIST.writeId(packet); + packet.writeD(slotCount); + int counter = 0; + for (int i = 0; i <= slotCount; i++) + { + if (_player.getHomunculusList().get(i) != null) { final Homunculus homunculus = _player.getHomunculusList().get(i); - if (homunculus == null) - { - continue; - } packet.writeD(counter); // slot packet.writeD(homunculus.getId()); // homunculus id packet.writeD(homunculus.getType()); @@ -72,13 +88,33 @@ public class ExShowHomunculusList implements IClientOutgoingPacket packet.writeD(homunculus.getAtk()); packet.writeD(homunculus.getDef()); packet.writeD(homunculus.getCritRate()); - counter++; } + else + { + packet.writeD(counter); // slot + packet.writeD(0); // homunculus id + packet.writeD(0); + packet.writeC(0); + packet.writeD(0); + for (int j = 1; j <= 5; j++) + { + packet.writeD(0); + } + packet.writeD(0); + for (int j = 1; j <= 5; j++) + { + packet.writeD(0); + } + packet.writeD(0);// m_nLevel + packet.writeD(0);// m_nHP + packet.writeD(0);// m_nHP + packet.writeD(0);// m_nAttack + packet.writeD(0);// m_nDefence + packet.writeD(0);// m_nCritical + } + counter++; } - else - { - packet.writeD(0); - } + return true; } } diff --git a/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExSummonHomunculusCouponResult.java b/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExSummonHomunculusCouponResult.java index 28c7d148e2..22597b6716 100644 --- a/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExSummonHomunculusCouponResult.java +++ b/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/gameserver/network/serverpackets/homunculus/ExSummonHomunculusCouponResult.java @@ -26,17 +26,31 @@ import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket; public class ExSummonHomunculusCouponResult implements IClientOutgoingPacket { private final int _slot; + private int _success = -1; public ExSummonHomunculusCouponResult(int slot) { _slot = slot; } + public ExSummonHomunculusCouponResult(int slot, int success) + { + _slot = slot; + _success = success; + } + @Override public boolean write(PacketWriter packet) { OutgoingPackets.EX_SUMMON_HOMUNCULUS_COUPON_RESULT.writeId(packet); - packet.writeD(1); // 1 - success + if (_success == -1) + { + packet.writeD(1); // 1 - success + } + else + { + packet.writeD(_success); + } packet.writeD(_slot); // homunculus slot packet.writeD(0); // keep or delete return true;