Updated LuckyGame packets and rewards.

Author: Sdw
Source: L2jUnity free files.
This commit is contained in:
MobiusDev
2017-11-16 14:22:02 +00:00
parent 421d61416d
commit 2084ed23e8
74 changed files with 4074 additions and 2378 deletions

View File

@@ -17,25 +17,26 @@
package com.l2jmobius.gameserver.data.xml.impl;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import com.l2jmobius.commons.util.IGameXmlReader;
import com.l2jmobius.commons.util.Rnd;
import com.l2jmobius.gameserver.model.holders.ItemHolder;
import com.l2jmobius.gameserver.model.StatsSet;
import com.l2jmobius.gameserver.model.holders.ItemChanceHolder;
import com.l2jmobius.gameserver.model.holders.ItemPointHolder;
import com.l2jmobius.gameserver.model.holders.LuckyGameDataHolder;
/**
* @author Mathael
* @author Sdw
*/
public class LuckyGameData implements IGameXmlReader
{
private static final List<ItemHolder> _fortuneReadingTicketRewards = new ArrayList<>();
private static final List<ItemHolder> _luxuryFortuneReadingTicketRewards = new ArrayList<>();
private static final List<ItemHolder> _rareLuxuryFortuneReadingTicketRewards = new ArrayList<>();
private final Map<Integer, LuckyGameDataHolder> _luckyGame = new HashMap<>();
final AtomicInteger _serverPlay = new AtomicInteger();
protected LuckyGameData()
{
@@ -45,112 +46,62 @@ public class LuckyGameData implements IGameXmlReader
@Override
public void load()
{
_fortuneReadingTicketRewards.clear();
_luxuryFortuneReadingTicketRewards.clear();
_rareLuxuryFortuneReadingTicketRewards.clear();
_luckyGame.clear();
parseDatapackFile("data/LuckyGameData.xml");
LOGGER.info(getClass().getSimpleName() + ": Loaded " + _fortuneReadingTicketRewards.size() + " Normal item rewards.");
LOGGER.info(getClass().getSimpleName() + ": Loaded " + _luxuryFortuneReadingTicketRewards.size() + " Luxury item rewards.");
LOGGER.info(getClass().getSimpleName() + ": Loaded " + _rareLuxuryFortuneReadingTicketRewards.size() + " Rare item rewards.");
LOGGER.info(getClass().getSimpleName() + ": Loaded " + _luckyGame.size() + " lucky game data.");
}
@Override
public void parseDocument(Document doc, File f)
{
for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
forEach(doc, "list", listNode -> forEach(listNode, "luckygame", rewardNode ->
{
if ("list".equalsIgnoreCase(n.getNodeName()))
final LuckyGameDataHolder holder = new LuckyGameDataHolder(new StatsSet(parseAttributes(rewardNode)));
forEach(rewardNode, "common_reward", commonRewardNode -> forEach(commonRewardNode, "item", itemNode ->
{
final NamedNodeMap at = n.getAttributes();
final Node attribute = at.getNamedItem("enabled");
if ((attribute != null) && Boolean.parseBoolean(attribute.getNodeValue())) // <list enabled="true"
final StatsSet stats = new StatsSet(parseAttributes(itemNode));
holder.addCommonReward(new ItemChanceHolder(stats.getInt("id"), stats.getDouble("chance"), stats.getLong("count")));
}));
forEach(rewardNode, "unique_reward", uniqueRewardNode -> forEach(uniqueRewardNode, "item", itemNode ->
{
holder.addUniqueReward(new ItemPointHolder(new StatsSet(parseAttributes(itemNode))));
}));
forEach(rewardNode, "modify_reward", uniqueRewardNode ->
{
holder.setMinModifyRewardGame(parseInteger(uniqueRewardNode.getAttributes(), "min_game"));
holder.setMaxModifyRewardGame(parseInteger(uniqueRewardNode.getAttributes(), "max_game"));
forEach(uniqueRewardNode, "item", itemNode ->
{
for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
{
if ("fortuneReadingTicketRewards".equalsIgnoreCase(d.getNodeName()))
{
for (Node b = d.getFirstChild(); b != null; b = b.getNextSibling())
{
if ("item".equalsIgnoreCase(b.getNodeName()))
{
final NamedNodeMap attrs = b.getAttributes();
final int itemId = parseInteger(attrs, "id");
final int count = parseInteger(attrs, "count");
if ((itemId == 0) || (count == 0))
{
LOGGER.severe(getClass().getSimpleName() + ": itemId: [" + itemId + "] count: [" + count + "] cannot be zero.");
return;
}
_fortuneReadingTicketRewards.add(new ItemHolder(itemId, count));
}
}
}
else if ("luxuryFortuneReadingTicketRewards".equalsIgnoreCase(d.getNodeName()))
{
for (Node b = d.getFirstChild(); b != null; b = b.getNextSibling())
{
if ("item".equalsIgnoreCase(b.getNodeName()))
{
final NamedNodeMap attrs = b.getAttributes();
final int itemId = parseInteger(attrs, "id");
final int count = parseInteger(attrs, "count");
if ((itemId == 0) || (count == 0))
{
LOGGER.severe(getClass().getSimpleName() + ": itemId: [" + itemId + "] count: [" + count + "] cannot be zero.");
return;
}
_luxuryFortuneReadingTicketRewards.add(new ItemHolder(itemId, count));
}
}
}
else if ("rareLuxuryFortuneReadingTicketRewards".equalsIgnoreCase(d.getNodeName()))
{
for (Node b = d.getFirstChild(); b != null; b = b.getNextSibling())
{
if ("item".equalsIgnoreCase(b.getNodeName()))
{
final NamedNodeMap attrs = b.getAttributes();
final int itemId = parseInteger(attrs, "id");
final int count = parseInteger(attrs, "count");
if ((itemId == 0) || (count == 0))
{
LOGGER.severe(getClass().getSimpleName() + ": itemId: [" + itemId + "] count: [" + count + "] cannot be zero.");
return;
}
_rareLuxuryFortuneReadingTicketRewards.add(new ItemHolder(itemId, count));
}
}
}
}
}
}
}
final StatsSet stats = new StatsSet(parseAttributes(itemNode));
holder.addModifyReward(new ItemChanceHolder(stats.getInt("id"), stats.getDouble("chance"), stats.getLong("count")));
});
});
_luckyGame.put(parseInteger(rewardNode.getAttributes(), "index"), holder);
}));
}
public static ItemHolder getRandomNormalReward()
public int getLuckyGameCount()
{
return _fortuneReadingTicketRewards.get(Rnd.get(_fortuneReadingTicketRewards.size()));
return _luckyGame.size();
}
public static ItemHolder getRandomLuxuryReward()
public LuckyGameDataHolder getLuckyGameDataByIndex(int index)
{
return _luxuryFortuneReadingTicketRewards.get(Rnd.get(_luxuryFortuneReadingTicketRewards.size()));
return _luckyGame.get(index);
}
public static ItemHolder getRandomRareReward()
public int increaseGame()
{
return _rareLuxuryFortuneReadingTicketRewards.get(Rnd.get(_rareLuxuryFortuneReadingTicketRewards.size()));
return _serverPlay.incrementAndGet();
}
public int getServerPlay()
{
return _serverPlay.get();
}
public static LuckyGameData getInstance()

View File

@@ -0,0 +1,39 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jmobius.gameserver.enums;
/**
* @author Sdw
*/
public enum LuckyGameItemType
{
COMMON(1),
UNIQUE(2),
RARE(3);
private final int _clientId;
LuckyGameItemType(int clientId)
{
_clientId = clientId;
}
public int getClientId()
{
return _clientId;
}
}

View File

@@ -0,0 +1,40 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jmobius.gameserver.enums;
/**
* @author Sdw
*/
public enum LuckyGameResultType
{
INVALID_CAPACITY(-2),
INVALID_ITEM_COUNT(-1),
DISABLED(0),
SUCCESS(1);
private final int _clientId;
private LuckyGameResultType(int clientId)
{
_clientId = clientId;
}
public int getClientId()
{
return _clientId;
}
}

View File

@@ -0,0 +1,27 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jmobius.gameserver.enums;
/**
* @author Sdw
*/
public enum LuckyGameType
{
NONE,
NORMAL,
LUXURY
}

View File

@@ -0,0 +1,53 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jmobius.gameserver.model.holders;
import com.l2jmobius.gameserver.model.StatsSet;
/**
* @author Sdw
*/
public class ItemPointHolder extends ItemHolder
{
private final int _points;
public ItemPointHolder(StatsSet params)
{
this(params.getInt("id"), params.getLong("count"), params.getInt("points"));
}
public ItemPointHolder(int id, long count, int points)
{
super(id, count);
_points = points;
}
/**
* Gets the point.
* @return the number of point to get the item
*/
public int getPoints()
{
return _points;
}
@Override
public String toString()
{
return "[" + getClass().getSimpleName() + "] ID: " + getId() + ", count: " + getCount() + ", points: " + _points;
}
}

View File

@@ -0,0 +1,102 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jmobius.gameserver.model.holders;
import java.util.ArrayList;
import java.util.List;
import com.l2jmobius.gameserver.model.StatsSet;
/**
* @author Sdw
*/
public class LuckyGameDataHolder
{
final private int _index;
final private int _turningPoints;
final private List<ItemChanceHolder> _commonRewards = new ArrayList<>();
final private List<ItemPointHolder> _uniqueRewards = new ArrayList<>();
final private List<ItemChanceHolder> _modifyRewards = new ArrayList<>();
private int _minModifyRewardGame;
private int _maxModifyRewardGame;
public LuckyGameDataHolder(StatsSet params)
{
_index = params.getInt("index");
_turningPoints = params.getInt("turning_point");
}
public void addCommonReward(ItemChanceHolder item)
{
_commonRewards.add(item);
}
public void addUniqueReward(ItemPointHolder item)
{
_uniqueRewards.add(item);
}
public void addModifyReward(ItemChanceHolder item)
{
_modifyRewards.add(item);
}
public List<ItemChanceHolder> getCommonReward()
{
return _commonRewards;
}
public List<ItemPointHolder> getUniqueReward()
{
return _uniqueRewards;
}
public List<ItemChanceHolder> getModifyReward()
{
return _modifyRewards;
}
public void setMinModifyRewardGame(int minModifyRewardGame)
{
_minModifyRewardGame = minModifyRewardGame;
}
public void setMaxModifyRewardGame(int maxModifyRewardGame)
{
_maxModifyRewardGame = maxModifyRewardGame;
}
public int getMinModifyRewardGame()
{
return _minModifyRewardGame;
}
public int getMaxModifyRewardGame()
{
return _maxModifyRewardGame;
}
public int getIndex()
{
return _index;
}
public int getTurningPoints()
{
return _turningPoints;
}
}

View File

@@ -57,6 +57,8 @@ public class PlayerVariables extends AbstractVariables
public static final String REVELATION_SKILL_1_DUAL_CLASS = "DualclassRevelationSkill1";
public static final String REVELATION_SKILL_2_DUAL_CLASS = "DualclassRevelationSkill2";
public static final String EXTEND_DROP = "EXTEND_DROP";
public static final String FORTUNE_TELLING_VARIABLE = "FortuneTelling";
public static final String FORTUNE_TELLING_BLACK_CAT_VARIABLE = "FortuneTellingBlackCat";
private final int _objectId;

View File

@@ -69,6 +69,8 @@ import com.l2jmobius.gameserver.network.clientpackets.dailymission.RequestTodoLi
import com.l2jmobius.gameserver.network.clientpackets.ensoul.RequestItemEnsoul;
import com.l2jmobius.gameserver.network.clientpackets.faction.RequestUserFactionInfo;
import com.l2jmobius.gameserver.network.clientpackets.friend.RequestFriendDetailInfo;
import com.l2jmobius.gameserver.network.clientpackets.luckygame.RequestLuckyGamePlay;
import com.l2jmobius.gameserver.network.clientpackets.luckygame.RequestLuckyGameStartInfo;
import com.l2jmobius.gameserver.network.clientpackets.mentoring.ConfirmMenteeAdd;
import com.l2jmobius.gameserver.network.clientpackets.mentoring.RequestMenteeAdd;
import com.l2jmobius.gameserver.network.clientpackets.mentoring.RequestMenteeWaitingList;
@@ -334,8 +336,8 @@ public enum ExIncomingPackets implements IIncomingPackets<L2GameClient>
REQUEST_ABILITY_WND_OPEN(0xEE, RequestAbilityWndOpen::new, ConnectionState.IN_GAME),
REQUEST_ABILITY_WND_CLOSE(0xEF, RequestAbilityWndClose::new, ConnectionState.IN_GAME),
EX_PC_CAFE_REQUEST_OPEN_WINDOW_WITHOUT_NPC(0xF0, ExPCCafeRequestOpenWindowWithoutNPC::new, ConnectionState.IN_GAME),
REQUEST_LUCKY_GAME_START_INFO(0xF1, null, ConnectionState.IN_GAME),
REQUEST_LUCKY_GAME_PLAY(0xF2, null, ConnectionState.IN_GAME),
REQUEST_LUCKY_GAME_START_INFO(0xF1, RequestLuckyGameStartInfo::new, ConnectionState.IN_GAME),
REQUEST_LUCKY_GAME_PLAY(0xF2, RequestLuckyGamePlay::new, ConnectionState.IN_GAME),
NOTIFY_TRAINING_ROOM_END(0xF3, null, ConnectionState.IN_GAME),
REQUEST_NEW_ENCHANT_PUSH_ONE(0xF4, RequestNewEnchantPushOne::new, ConnectionState.IN_GAME),
REQUEST_NEW_ENCHANT_REMOVE_ONE(0xF5, RequestNewEnchantRemoveOne::new, ConnectionState.IN_GAME),

View File

@@ -16,30 +16,169 @@
*/
package com.l2jmobius.gameserver.network.clientpackets.luckygame;
import java.util.ArrayList;
import java.util.EnumMap;
import java.util.List;
import java.util.Map.Entry;
import com.l2jmobius.commons.network.PacketReader;
import com.l2jmobius.commons.util.CommonUtil;
import com.l2jmobius.commons.util.Rnd;
import com.l2jmobius.gameserver.data.xml.impl.LuckyGameData;
import com.l2jmobius.gameserver.datatables.ItemTable;
import com.l2jmobius.gameserver.enums.LuckyGameItemType;
import com.l2jmobius.gameserver.enums.LuckyGameResultType;
import com.l2jmobius.gameserver.enums.LuckyGameType;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.model.holders.ItemChanceHolder;
import com.l2jmobius.gameserver.model.holders.ItemHolder;
import com.l2jmobius.gameserver.model.holders.LuckyGameDataHolder;
import com.l2jmobius.gameserver.model.items.instance.L2ItemInstance;
import com.l2jmobius.gameserver.model.variables.PlayerVariables;
import com.l2jmobius.gameserver.network.L2GameClient;
import com.l2jmobius.gameserver.network.SystemMessageId;
import com.l2jmobius.gameserver.network.clientpackets.IClientIncomingPacket;
import com.l2jmobius.gameserver.network.serverpackets.InventoryUpdate;
import com.l2jmobius.gameserver.network.serverpackets.SystemMessage;
import com.l2jmobius.gameserver.network.serverpackets.luckygame.ExBettingLuckyGameResult;
/**
* @author Mobius
* @author Sdw
*/
public class RequestLuckyGamePlay implements IClientIncomingPacket
{
private int _type;
private int _count;
private static final int FORTUNE_READING_TICKET = 23767;
private static final int LUXURY_FORTUNE_READING_TICKET = 23768;
private LuckyGameType _type;
private int _reading;
@Override
public boolean read(L2GameClient client, PacketReader packet)
{
_type = packet.readD(); // luxury = 2, normal = 1
_count = packet.readD(); // count
final int type = CommonUtil.constrain(packet.readD(), 0, LuckyGameType.values().length);
_type = LuckyGameType.values()[type];
_reading = CommonUtil.constrain(packet.readD(), 0, 50); // max play is 50
return true;
}
@Override
public void run(L2GameClient client)
{
client.getActiveChar().sendPacket(new ExBettingLuckyGameResult(client.getActiveChar(), _type, _count));
final L2PcInstance player = client.getActiveChar();
if (player == null)
{
return;
}
final int index = _type == LuckyGameType.LUXURY ? 102 : 2; // move to event config
final LuckyGameDataHolder holder = LuckyGameData.getInstance().getLuckyGameDataByIndex(index);
if (holder == null)
{
return;
}
final long tickets = _type == LuckyGameType.LUXURY ? player.getInventory().getInventoryItemCount(LUXURY_FORTUNE_READING_TICKET, -1) : player.getInventory().getInventoryItemCount(FORTUNE_READING_TICKET, -1);
if (tickets < _reading)
{
player.sendPacket(SystemMessageId.NOT_ENOUGH_TICKETS);
player.sendPacket(_type == LuckyGameType.LUXURY ? ExBettingLuckyGameResult.LUXURY_INVALID_ITEM_COUNT : ExBettingLuckyGameResult.NORMAL_INVALID_ITEM_COUNT);
return;
}
int playCount = player.getVariables().getInt(PlayerVariables.FORTUNE_TELLING_VARIABLE, 0);
boolean blackCat = player.getVariables().getBoolean(PlayerVariables.FORTUNE_TELLING_BLACK_CAT_VARIABLE, false);
final EnumMap<LuckyGameItemType, List<ItemHolder>> rewards = new EnumMap<>(LuckyGameItemType.class);
for (int i = 0; i < _reading; i++)
{
final double chance = 100 * Rnd.nextDouble();
double totalChance = 0;
for (ItemChanceHolder item : holder.getCommonReward())
{
totalChance += item.getChance();
if (totalChance >= chance)
{
rewards.computeIfAbsent(LuckyGameItemType.COMMON, k -> new ArrayList<>()).add(item);
break;
}
}
playCount++;
if ((playCount >= holder.getMinModifyRewardGame()) && (playCount <= holder.getMaxModifyRewardGame()) && !blackCat)
{
final List<ItemChanceHolder> modifyReward = holder.getModifyReward();
final double chanceModify = 100 * Rnd.nextDouble();
totalChance = 0;
for (ItemChanceHolder item : modifyReward)
{
totalChance += item.getChance();
if (totalChance >= chanceModify)
{
rewards.computeIfAbsent(LuckyGameItemType.RARE, k -> new ArrayList<>()).add(item);
blackCat = true;
break;
}
}
if (playCount == holder.getMaxModifyRewardGame())
{
rewards.computeIfAbsent(LuckyGameItemType.RARE, k -> new ArrayList<>()).add(modifyReward.get(Rnd.get(modifyReward.size())));
blackCat = true;
}
}
}
final int totalWeight = rewards.values().stream().mapToInt(list -> list.stream().mapToInt(item -> ItemTable.getInstance().getTemplate(item.getId()).getWeight()).sum()).sum();
// Check inventory capacity
if ((rewards.size() > 0) && (!player.getInventory().validateCapacity(rewards.size()) || !player.getInventory().validateWeight(totalWeight)))
{
player.sendPacket(_type == LuckyGameType.LUXURY ? ExBettingLuckyGameResult.LUXURY_INVALID_CAPACITY : ExBettingLuckyGameResult.NORMAL_INVALID_CAPACITY);
player.sendPacket(SystemMessageId.YOUR_INVENTORY_IS_EITHER_FULL_OR_OVERWEIGHT);
return;
}
if (!player.destroyItemByItemId("LuckyGame", _type == LuckyGameType.LUXURY ? LUXURY_FORTUNE_READING_TICKET : FORTUNE_READING_TICKET, _reading, player, true))
{
player.sendPacket(_type == LuckyGameType.LUXURY ? ExBettingLuckyGameResult.LUXURY_INVALID_ITEM_COUNT : ExBettingLuckyGameResult.NORMAL_INVALID_ITEM_COUNT);
return;
}
for (int i = 0; i < _reading; i++)
{
final int serverGameNumber = LuckyGameData.getInstance().increaseGame();
holder.getUniqueReward().stream().filter(reward -> reward.getPoints() == serverGameNumber).forEach(item -> rewards.computeIfAbsent(LuckyGameItemType.UNIQUE, k -> new ArrayList<>()).add(item));
}
player.sendPacket(new ExBettingLuckyGameResult(LuckyGameResultType.SUCCESS, _type, rewards, (int) (_type == LuckyGameType.LUXURY ? player.getInventory().getInventoryItemCount(LUXURY_FORTUNE_READING_TICKET, -1) : player.getInventory().getInventoryItemCount(FORTUNE_READING_TICKET, -1))));
final InventoryUpdate iu = new InventoryUpdate();
for (Entry<LuckyGameItemType, List<ItemHolder>> reward : rewards.entrySet())
{
for (ItemHolder r : reward.getValue())
{
final L2ItemInstance item = player.addItem("LuckyGame", r.getId(), r.getCount(), player, true);
iu.addItem(item);
if (reward.getKey() == LuckyGameItemType.UNIQUE)
{
final SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.CONGRATULATIONS_C1_HAS_OBTAINED_S2_OF_S3_THROUGH_FORTUNE_READING);
sm.addPcName(player);
sm.addLong(r.getCount());
sm.addItemName(item);
player.broadcastPacket(sm, 1000);
break;
}
}
}
player.sendInventoryUpdate(iu);
player.getVariables().set(PlayerVariables.FORTUNE_TELLING_VARIABLE, playCount >= 50 ? (playCount - 50) : playCount);
if (blackCat && (playCount < 50))
{
player.getVariables().set(PlayerVariables.FORTUNE_TELLING_BLACK_CAT_VARIABLE, true);
}
}
}

View File

@@ -0,0 +1,39 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jmobius.gameserver.network.clientpackets.luckygame;
import com.l2jmobius.commons.network.PacketReader;
import com.l2jmobius.gameserver.network.L2GameClient;
import com.l2jmobius.gameserver.network.clientpackets.IClientIncomingPacket;
/**
* @author Sdw
*/
public class RequestLuckyGameStartInfo implements IClientIncomingPacket
{
@Override
public boolean read(L2GameClient client, PacketReader packet)
{
return true;
}
@Override
public void run(L2GameClient client)
{
}
}

View File

@@ -16,121 +16,69 @@
*/
package com.l2jmobius.gameserver.network.serverpackets.luckygame;
import java.util.ArrayList;
import java.util.EnumMap;
import java.util.List;
import java.util.Map.Entry;
import com.l2jmobius.commons.network.PacketWriter;
import com.l2jmobius.commons.util.Rnd;
import com.l2jmobius.gameserver.data.xml.impl.LuckyGameData;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.enums.LuckyGameItemType;
import com.l2jmobius.gameserver.enums.LuckyGameResultType;
import com.l2jmobius.gameserver.enums.LuckyGameType;
import com.l2jmobius.gameserver.model.holders.ItemHolder;
import com.l2jmobius.gameserver.model.items.instance.L2ItemInstance;
import com.l2jmobius.gameserver.network.OutgoingPackets;
import com.l2jmobius.gameserver.network.SystemMessageId;
import com.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket;
import com.l2jmobius.gameserver.network.serverpackets.SystemMessage;
/**
* @author Mobius
* @author Sdw
*/
public class ExBettingLuckyGameResult implements IClientOutgoingPacket
{
private static final int FORTUNE_READING_TICKET = 23767;
private static final int LUXURY_FORTUNE_READING_TICKET = 23768;
private int _count = 0;
private int _type = 0;
private final L2PcInstance _activeChar;
public static final ExBettingLuckyGameResult NORMAL_INVALID_ITEM_COUNT = new ExBettingLuckyGameResult(LuckyGameResultType.INVALID_ITEM_COUNT, LuckyGameType.NORMAL);
public static final ExBettingLuckyGameResult LUXURY_INVALID_ITEM_COUNT = new ExBettingLuckyGameResult(LuckyGameResultType.INVALID_ITEM_COUNT, LuckyGameType.LUXURY);
public static final ExBettingLuckyGameResult NORMAL_INVALID_CAPACITY = new ExBettingLuckyGameResult(LuckyGameResultType.INVALID_CAPACITY, LuckyGameType.NORMAL);
public static final ExBettingLuckyGameResult LUXURY_INVALID_CAPACITY = new ExBettingLuckyGameResult(LuckyGameResultType.INVALID_CAPACITY, LuckyGameType.LUXURY);
public ExBettingLuckyGameResult(L2PcInstance activeChar, int type, int count)
private final LuckyGameResultType _result;
private final LuckyGameType _type;
private final EnumMap<LuckyGameItemType, List<ItemHolder>> _rewards;
private final int _ticketCount;
private final int _size;
public ExBettingLuckyGameResult(LuckyGameResultType result, LuckyGameType type)
{
_count = count;
_result = result;
_type = type;
_activeChar = activeChar;
_rewards = new EnumMap<>(LuckyGameItemType.class);
_ticketCount = 0;
_size = 0;
}
public ExBettingLuckyGameResult(LuckyGameResultType result, LuckyGameType type, EnumMap<LuckyGameItemType, List<ItemHolder>> rewards, int ticketCount)
{
_result = result;
_type = type;
_rewards = rewards;
_ticketCount = ticketCount;
_size = (int) rewards.values().stream().mapToLong(i -> i.stream().count()).sum();
}
@Override
public boolean write(PacketWriter packet)
{
// Calculate rewards
final List<ItemHolder> rewards = new ArrayList<>();
int totalWeight = 0;
for (int rewardCounter = 0; rewardCounter < _count; rewardCounter++)
{
if (Rnd.get(3) == 0) // 1 out of 3 chance
{
ItemHolder reward = null;
if (_type == 2)
{
if (_count >= 40)
{
reward = LuckyGameData.getRandomRareReward();
}
else
{
reward = LuckyGameData.getRandomLuxuryReward();
}
}
else
{
reward = LuckyGameData.getRandomNormalReward();
}
rewards.add(reward);
totalWeight += new L2ItemInstance(reward.getId()).getItem().getWeight() * reward.getCount();
}
}
// Check inventory capacity
if ((rewards.size() > 0) && (!_activeChar.getInventory().validateCapacity(rewards.size()) || !_activeChar.getInventory().validateWeight(totalWeight)))
{
_activeChar.sendPacket(new ExStartLuckyGame(_activeChar, _type));
_activeChar.sendPacket(SystemMessageId.YOUR_INVENTORY_IS_EITHER_FULL_OR_OVERWEIGHT);
return false;
}
if (_activeChar.getInventory().getInventoryItemCount(_type == 2 ? LUXURY_FORTUNE_READING_TICKET : FORTUNE_READING_TICKET, -1) < _count)
{
_activeChar.sendPacket(new ExStartLuckyGame(_activeChar, _type));
_activeChar.sendPacket(SystemMessageId.NOT_ENOUGH_TICKETS);
return false;
}
// Remove tickets
_activeChar.getInventory().destroyItemByItemId("FortuneTelling", _type == 2 ? LUXURY_FORTUNE_READING_TICKET : FORTUNE_READING_TICKET, _count, _activeChar, "FortuneTelling");
OutgoingPackets.EX_BETTING_LUCKY_GAME_RESULT.writeId(packet);
packet.writeD(0x01); // 0 disabled, 1 enabled
packet.writeD(0x01); // ?
packet.writeD((int) _activeChar.getInventory().getInventoryItemCount(_type == 2 ? LUXURY_FORTUNE_READING_TICKET : FORTUNE_READING_TICKET, -1)); // Count remaining tickets
if (rewards.size() > 0)
packet.writeD(_result.getClientId());
packet.writeD(_type.ordinal());
packet.writeD(_ticketCount);
packet.writeD(_size);
for (Entry<LuckyGameItemType, List<ItemHolder>> reward : _rewards.entrySet())
{
packet.writeD(rewards.size());
for (ItemHolder reward : rewards)
for (ItemHolder item : reward.getValue())
{
packet.writeD(0x02); // normal = 1, rare = 2 (forcing 2)
packet.writeD(reward.getId());
packet.writeD((int) reward.getCount());
final SystemMessage sm;
if (_type == 2)
{
_activeChar.addItem("LuxuryFortuneTelling", reward, _activeChar, false);
sm = SystemMessage.getSystemMessage(SystemMessageId.CONGRATULATIONS_C1_HAS_OBTAINED_S2_OF_S3_IN_THE_LUXURY_FORTUNE_READING);
}
else
{
_activeChar.addItem("FortuneTelling", reward, _activeChar, false);
sm = SystemMessage.getSystemMessage(SystemMessageId.CONGRATULATIONS_C1_HAS_OBTAINED_S2_OF_S3_THROUGH_FORTUNE_READING);
}
sm.addPcName(_activeChar);
sm.addLong(reward.getCount());
sm.addItemName(new L2ItemInstance(reward.getId()));
_activeChar.broadcastPacket(sm, 1000);
packet.writeD(reward.getKey().getClientId());
packet.writeD(item.getId());
packet.writeD((int) item.getCount());
}
}
else
{
packet.writeD(0x00);
}
return true;
}
}

View File

@@ -17,32 +17,30 @@
package com.l2jmobius.gameserver.network.serverpackets.luckygame;
import com.l2jmobius.commons.network.PacketWriter;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.enums.LuckyGameType;
import com.l2jmobius.gameserver.network.OutgoingPackets;
import com.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket;
/**
* @author Mobius
* @author Sdw
*/
public class ExStartLuckyGame implements IClientOutgoingPacket
{
private static final int FORTUNE_READING_TICKET = 23767;
private static final int LUXURY_FORTUNE_READING_TICKET = 23768;
private int _type = 0;
private int _count = 0;
private final LuckyGameType _type;
private final int _ticketCount;
public ExStartLuckyGame(L2PcInstance activeChar, int type)
public ExStartLuckyGame(LuckyGameType type, long ticketCount)
{
_type = type;
_count = (int) activeChar.getInventory().getInventoryItemCount(_type == 2 ? LUXURY_FORTUNE_READING_TICKET : FORTUNE_READING_TICKET, -1);
_ticketCount = (int) ticketCount;
}
@Override
public boolean write(PacketWriter packet)
{
OutgoingPackets.EX_START_LUCKY_GAME.writeId(packet);
packet.writeD(_type);
packet.writeD(_count);
packet.writeD(_type.ordinal());
packet.writeD(_ticketCount);
return true;
}
}