Homunculus related cleanups.
This commit is contained in:
@@ -18,10 +18,9 @@ package org.l2jmobius.gameserver.data.xml;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
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;
|
||||
@@ -37,7 +36,9 @@ import org.l2jmobius.gameserver.model.homunculus.HomunculusCreationTemplate;
|
||||
*/
|
||||
public class HomunculusCreationData implements IXmlReader
|
||||
{
|
||||
private final Map<Integer, HomunculusCreationTemplate> _templates = new HashMap<>();
|
||||
private static final List<HomunculusCreationTemplate> TEMPLATES = new ArrayList<>();
|
||||
|
||||
private HomunculusCreationTemplate _defaultTemplate;
|
||||
|
||||
protected HomunculusCreationData()
|
||||
{
|
||||
@@ -47,9 +48,10 @@ public class HomunculusCreationData implements IXmlReader
|
||||
@Override
|
||||
public void load()
|
||||
{
|
||||
_templates.clear();
|
||||
TEMPLATES.clear();
|
||||
_defaultTemplate = null;
|
||||
parseDatapackFile("data/HomunculusCreationData.xml");
|
||||
LOGGER.info(getClass().getSimpleName() + ": Loaded " + _templates.size() + " templates.");
|
||||
LOGGER.info(getClass().getSimpleName() + ": Loaded " + TEMPLATES.size() + " templates.");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -115,7 +117,12 @@ public class HomunculusCreationData implements IXmlReader
|
||||
}
|
||||
}
|
||||
|
||||
_templates.put(slotId, new HomunculusCreationTemplate(slotId, isEnabled, grade, isEvent, itemFees, hpFee, spFee, vpFee, time, chances));
|
||||
final HomunculusCreationTemplate template = new HomunculusCreationTemplate(slotId, isEnabled, grade, isEvent, itemFees, hpFee, spFee, vpFee, time, chances);
|
||||
TEMPLATES.add(template);
|
||||
if (_defaultTemplate == null)
|
||||
{
|
||||
_defaultTemplate = template;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -153,14 +160,26 @@ public class HomunculusCreationData implements IXmlReader
|
||||
return chanceList;
|
||||
}
|
||||
|
||||
public HomunculusCreationTemplate getTemplate(int id)
|
||||
public HomunculusCreationTemplate getTemplateByItemId(int itemId)
|
||||
{
|
||||
return _templates.get(id);
|
||||
for (HomunculusCreationTemplate template : TEMPLATES)
|
||||
{
|
||||
if (template.isInstanceHaveCoupon(itemId))
|
||||
{
|
||||
return template;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int size()
|
||||
public HomunculusCreationTemplate getDefaultTemplate()
|
||||
{
|
||||
return _templates.size();
|
||||
return _defaultTemplate;
|
||||
}
|
||||
|
||||
public Collection<HomunculusCreationTemplate> getTemplates()
|
||||
{
|
||||
return TEMPLATES;
|
||||
}
|
||||
|
||||
public static HomunculusCreationData getInstance()
|
||||
@@ -172,4 +191,5 @@ public class HomunculusCreationData implements IXmlReader
|
||||
{
|
||||
protected static final HomunculusCreationData INSTANCE = new HomunculusCreationData();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -31,7 +31,7 @@ import org.l2jmobius.gameserver.model.homunculus.HomunculusTemplate;
|
||||
*/
|
||||
public class HomunculusData implements IXmlReader
|
||||
{
|
||||
private final Map<Integer, HomunculusTemplate> _templates = new HashMap<>();
|
||||
private static final Map<Integer, HomunculusTemplate> TEMPLATES = new HashMap<>();
|
||||
|
||||
protected HomunculusData()
|
||||
{
|
||||
@@ -41,9 +41,9 @@ public class HomunculusData implements IXmlReader
|
||||
@Override
|
||||
public void load()
|
||||
{
|
||||
_templates.clear();
|
||||
TEMPLATES.clear();
|
||||
parseDatapackFile("data/HomunculusData.xml");
|
||||
LOGGER.info(getClass().getSimpleName() + ": Loaded " + _templates.size() + " templates.");
|
||||
LOGGER.info(getClass().getSimpleName() + ": Loaded " + TEMPLATES.size() + " templates.");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -53,18 +53,13 @@ public class HomunculusData implements IXmlReader
|
||||
{
|
||||
final StatSet set = new StatSet(parseAttributes(homunculusNode));
|
||||
final int id = set.getInt("id");
|
||||
_templates.put(id, new HomunculusTemplate(id, set.getInt("type"), set.getInt("basicSkillId"), set.getInt("basicSkillLevel"), set.getInt("skillId1"), set.getInt("skillId2"), set.getInt("skillId3"), set.getInt("skillId4"), set.getInt("skillId5"), set.getInt("hpLevel1"), set.getInt("atkLevel1"), set.getInt("defLevel1"), set.getInt("expToLevel2"), set.getInt("hpLevel2"), set.getInt("atkLevel2"), set.getInt("defLevel2"), set.getInt("expToLevel3"), set.getInt("hpLevel3"), set.getInt("atkLevel3"), set.getInt("defLevel3"), set.getInt("expToLevel4"), set.getInt("hpLevel4"), set.getInt("atkLevel4"), set.getInt("defLevel4"), set.getInt("expToLevel5"), set.getInt("hpLevel5"), set.getInt("atkLevel5"), set.getInt("defLevel5"), set.getInt("expToLevel6"), set.getInt("critRate")));
|
||||
TEMPLATES.put(id, new HomunculusTemplate(id, set.getInt("type"), set.getInt("basicSkillId"), set.getInt("basicSkillLevel"), set.getInt("skillId1"), set.getInt("skillId2"), set.getInt("skillId3"), set.getInt("skillId4"), set.getInt("skillId5"), set.getInt("hpLevel1"), set.getInt("atkLevel1"), set.getInt("defLevel1"), set.getInt("expToLevel2"), set.getInt("hpLevel2"), set.getInt("atkLevel2"), set.getInt("defLevel2"), set.getInt("expToLevel3"), set.getInt("hpLevel3"), set.getInt("atkLevel3"), set.getInt("defLevel3"), set.getInt("expToLevel4"), set.getInt("hpLevel4"), set.getInt("atkLevel4"), set.getInt("defLevel4"), set.getInt("expToLevel5"), set.getInt("hpLevel5"), set.getInt("atkLevel5"), set.getInt("defLevel5"), set.getInt("expToLevel6"), set.getInt("critRate")));
|
||||
}));
|
||||
}
|
||||
|
||||
public HomunculusTemplate getTemplate(int id)
|
||||
{
|
||||
return _templates.get(id);
|
||||
}
|
||||
|
||||
public int size()
|
||||
{
|
||||
return _templates.size();
|
||||
return TEMPLATES.get(id);
|
||||
}
|
||||
|
||||
public static HomunculusData getInstance()
|
||||
|
@@ -130,7 +130,7 @@ public class HomunculusCreationTemplate
|
||||
return false;
|
||||
}
|
||||
|
||||
public long getCreationLime()
|
||||
public long getCreationTime()
|
||||
{
|
||||
return _time;
|
||||
}
|
||||
|
@@ -19,7 +19,6 @@ 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;
|
||||
@@ -32,10 +31,6 @@ import org.l2jmobius.gameserver.network.serverpackets.homunculus.ExShowHomunculu
|
||||
*/
|
||||
public class RequestExHomunculusCreateStart implements IClientIncomingPacket
|
||||
{
|
||||
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)
|
||||
{
|
||||
@@ -51,14 +46,15 @@ public class RequestExHomunculusCreateStart implements IClientIncomingPacket
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.getAdena() < COST)
|
||||
final int fee = Math.toIntExact(HomunculusCreationData.getInstance().getDefaultTemplate().getItemFee().get(0).getCount());
|
||||
if (player.getAdena() < fee)
|
||||
{
|
||||
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);
|
||||
player.reduceAdena("Homunculus creation", fee, player, true);
|
||||
player.getVariables().set(PlayerVariables.HOMUNCULUS_CREATION_TIME, System.currentTimeMillis() + HomunculusCreationData.getInstance().getDefaultTemplate().getCreationTime());
|
||||
|
||||
client.sendPacket(new ExShowHomunculusBirthInfo(player));
|
||||
client.sendPacket(new ExHomunculusCreateStartResult(player));
|
||||
|
@@ -19,7 +19,6 @@ 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.clientpackets.IClientIncomingPacket;
|
||||
@@ -32,11 +31,6 @@ import org.l2jmobius.gameserver.network.serverpackets.homunculus.ExShowHomunculu
|
||||
*/
|
||||
public class RequestExHomunculusInsert implements IClientIncomingPacket
|
||||
{
|
||||
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;
|
||||
|
||||
@Override
|
||||
@@ -61,9 +55,9 @@ public class RequestExHomunculusInsert implements IClientIncomingPacket
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
if ((player.getCurrentHp() > HP_COST) && (hpPoints < TEMPLATE.getHPFeeCount()))
|
||||
if ((player.getCurrentHp() > HomunculusCreationData.getInstance().getDefaultTemplate().getHPFeeCountByUse()) && (hpPoints < HomunculusCreationData.getInstance().getDefaultTemplate().getHPFeeCount()))
|
||||
{
|
||||
int newHp = (int) (player.getCurrentHp()) - HP_COST;
|
||||
int newHp = (int) (player.getCurrentHp()) - HomunculusCreationData.getInstance().getDefaultTemplate().getHPFeeCountByUse();
|
||||
player.setCurrentHp(newHp, true);
|
||||
hpPoints += 1;
|
||||
player.getVariables().set(PlayerVariables.HOMUNCULUS_HP_POINTS, hpPoints);
|
||||
@@ -76,9 +70,9 @@ public class RequestExHomunculusInsert implements IClientIncomingPacket
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
if ((player.getSp() >= SP_COST) && (spPoints < TEMPLATE.getSPFeeCount()))
|
||||
if ((player.getSp() >= HomunculusCreationData.getInstance().getDefaultTemplate().getSPFeeCountByUse()) && (spPoints < HomunculusCreationData.getInstance().getDefaultTemplate().getSPFeeCount()))
|
||||
{
|
||||
player.setSp(player.getSp() - SP_COST);
|
||||
player.setSp(player.getSp() - HomunculusCreationData.getInstance().getDefaultTemplate().getSPFeeCountByUse());
|
||||
spPoints += 1;
|
||||
player.getVariables().set(PlayerVariables.HOMUNCULUS_SP_POINTS, spPoints);
|
||||
}
|
||||
@@ -90,9 +84,9 @@ public class RequestExHomunculusInsert implements IClientIncomingPacket
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
if ((player.getVitalityPoints() >= VP_COST) && (vpPoints < TEMPLATE.getVPFeeCount()))
|
||||
if ((player.getVitalityPoints() >= HomunculusCreationData.getInstance().getDefaultTemplate().getVPFeeByUse()) && (vpPoints < HomunculusCreationData.getInstance().getDefaultTemplate().getVPFeeCount()))
|
||||
{
|
||||
int newVitality = player.getVitalityPoints() - VP_COST;
|
||||
int newVitality = player.getVitalityPoints() - HomunculusCreationData.getInstance().getDefaultTemplate().getVPFeeByUse();
|
||||
player.setVitalityPoints(newVitality, true);
|
||||
vpPoints += 1;
|
||||
player.getVariables().set(PlayerVariables.HOMUNCULUS_VP_POINTS, vpPoints);
|
||||
|
@@ -22,7 +22,6 @@ 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;
|
||||
@@ -37,8 +36,6 @@ 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)
|
||||
{
|
||||
@@ -60,22 +57,21 @@ 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 == TEMPLATE.getHPFeeCount()) && (spPoints == TEMPLATE.getSPFeeCount()) && (vpPoints == TEMPLATE.getVPFeeCount()))
|
||||
if ((homunculusCreateTime > 0) && ((System.currentTimeMillis() / 1000) >= homunculusCreateTime) && (hpPoints == HomunculusCreationData.getInstance().getDefaultTemplate().getHPFeeCount()) && (spPoints == HomunculusCreationData.getInstance().getDefaultTemplate().getSPFeeCount()) && (vpPoints == HomunculusCreationData.getInstance().getDefaultTemplate().getVPFeeCount()))
|
||||
{
|
||||
double chance = Rnd.get(100.0);
|
||||
double current = 0;
|
||||
int homunculusId = 0;
|
||||
while (homunculusId == 0)
|
||||
{
|
||||
if (chance > TEMPLATE.getMaxChance())
|
||||
if (chance > HomunculusCreationData.getInstance().getDefaultTemplate().getMaxChance())
|
||||
{
|
||||
player.sendMessage("Homunculus is not created!");
|
||||
player.sendPacket(new ExHomunculusSummonResult(0));
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < TEMPLATE.getCreationChance().size(); i++)
|
||||
for (Double[] homuHolder : HomunculusCreationData.getInstance().getDefaultTemplate().getCreationChance())
|
||||
{
|
||||
final Double[] homuHolder = TEMPLATE.getCreationChance().get(i);
|
||||
current += homuHolder[1];
|
||||
if (current >= chance)
|
||||
{
|
||||
|
@@ -19,7 +19,6 @@ 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;
|
||||
@@ -29,8 +28,6 @@ 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;
|
||||
@@ -45,9 +42,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();
|
||||
_feeHpPoints = HomunculusCreationData.getInstance().getDefaultTemplate().getHPFeeCount();
|
||||
_feeSpPoints = (int) HomunculusCreationData.getInstance().getDefaultTemplate().getSPFeeCount();
|
||||
_feeVpPoints = HomunculusCreationData.getInstance().getDefaultTemplate().getVPFeeCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user