Unhardcoded Letter Collector rewards.
Thanks to Index.
This commit is contained in:
		| @@ -16,22 +16,122 @@ | ||||
|  */ | ||||
| package events.LetterCollector; | ||||
|  | ||||
| import java.io.File; | ||||
| import java.util.ArrayList; | ||||
| import java.util.HashMap; | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
| import java.util.concurrent.atomic.AtomicBoolean; | ||||
| import java.util.concurrent.atomic.AtomicInteger; | ||||
| import java.util.concurrent.atomic.AtomicReference; | ||||
|  | ||||
| import org.w3c.dom.Document; | ||||
|  | ||||
| import org.l2jmobius.commons.util.IXmlReader; | ||||
| import org.l2jmobius.gameserver.instancemanager.events.LetterCollectorManager; | ||||
| import org.l2jmobius.gameserver.model.StatSet; | ||||
| import org.l2jmobius.gameserver.model.actor.Player; | ||||
| import org.l2jmobius.gameserver.model.events.EventType; | ||||
| import org.l2jmobius.gameserver.model.events.ListenerRegisterType; | ||||
| import org.l2jmobius.gameserver.model.events.annotations.RegisterEvent; | ||||
| import org.l2jmobius.gameserver.model.events.annotations.RegisterType; | ||||
| import org.l2jmobius.gameserver.model.events.impl.creature.player.OnPlayerLogin; | ||||
| import org.l2jmobius.gameserver.model.holders.ItemChanceHolder; | ||||
| import org.l2jmobius.gameserver.model.holders.ItemHolder; | ||||
| import org.l2jmobius.gameserver.model.quest.LongTimeEvent; | ||||
| import org.l2jmobius.gameserver.network.serverpackets.ExLetterCollectorUI; | ||||
|  | ||||
| /** | ||||
|  * @author Mobius | ||||
|  */ | ||||
| public class LetterCollector extends LongTimeEvent | ||||
| public class LetterCollector extends LongTimeEvent implements IXmlReader | ||||
| { | ||||
| 	private LetterCollector() | ||||
| 	{ | ||||
| 		if (isEventPeriod()) | ||||
| 		{ | ||||
| 			load(); | ||||
| 			LetterCollectorManager.getInstance().init(); | ||||
| 		} | ||||
| 	} | ||||
| 	 | ||||
| 	public void reloadRewards() | ||||
| 	{ | ||||
| 		LetterCollectorManager.getInstance().resetField(); | ||||
| 		load(); | ||||
| 	} | ||||
| 	 | ||||
| 	@Override | ||||
| 	public synchronized void load() | ||||
| 	{ | ||||
| 		parseDatapackFile("data/scripts/events/LetterCollector/rewards.xml"); | ||||
| 	} | ||||
| 	 | ||||
| 	@Override | ||||
| 	public void parseDocument(Document doc, File f) | ||||
| 	{ | ||||
| 		final AtomicInteger minimumLevel = new AtomicInteger(); | ||||
| 		final AtomicInteger maximumLevel = new AtomicInteger(); | ||||
| 		final Map<String, Integer> letters = new HashMap<>(); | ||||
| 		forEach(doc, "list", listNode -> | ||||
| 		{ | ||||
| 			forEach(listNode, "params", paramNode -> | ||||
| 			{ | ||||
| 				forEach(paramNode, "minimum", minimumLevelNode -> minimumLevel.set(new StatSet(parseAttributes(minimumLevelNode)).getInt("level"))); | ||||
| 				forEach(paramNode, "maximum", maximumLevelNode -> maximumLevel.set(new StatSet(parseAttributes(maximumLevelNode)).getInt("level"))); | ||||
| 			}); | ||||
| 			forEach(listNode, "letters", letterNode -> forEach(letterNode, "item", itemNode -> | ||||
| 			{ | ||||
| 				StatSet letterSet = new StatSet(parseAttributes(itemNode)); | ||||
| 				letters.put(letterSet.getString("name"), letterSet.getInt("id")); | ||||
| 			})); | ||||
| 			forEach(listNode, "reward", rewardNode -> | ||||
| 			{ | ||||
| 				final int id = new StatSet(parseAttributes(rewardNode)).getInt("id"); | ||||
| 				final AtomicReference<List<ItemHolder>> word = new AtomicReference<>(new ArrayList<>()); | ||||
| 				final AtomicReference<List<ItemChanceHolder>> rewards = new AtomicReference<>(new ArrayList<>()); | ||||
| 				AtomicBoolean needToSumAllChance = new AtomicBoolean(false); | ||||
| 				AtomicReference<Double> chanceSum = new AtomicReference<>(0.0); | ||||
| 				forEach(rewardNode, "word", wordNode -> | ||||
| 				{ | ||||
| 					String[] letter = wordNode.getTextContent().trim().split(";"); | ||||
| 					for (String token : letter) | ||||
| 					{ | ||||
| 						int count = 1; | ||||
| 						for (ItemHolder check : word.get()) | ||||
| 						{ | ||||
| 							if (check.getId() == letters.get(token)) | ||||
| 							{ | ||||
| 								count = Math.toIntExact(check.getCount() + 1); | ||||
| 								word.get().remove(check); | ||||
| 								break; | ||||
| 							} | ||||
| 						} | ||||
| 						word.get().add(new ItemHolder(letters.get(token), count)); | ||||
| 					} | ||||
| 				}); | ||||
| 				forEach(rewardNode, "rewards", rewardsNode -> | ||||
| 				{ | ||||
| 					needToSumAllChance.set(new StatSet(parseAttributes(rewardsNode)).getBoolean("sumChances")); | ||||
| 					forEach(rewardsNode, "item", itemNode -> | ||||
| 					{ | ||||
| 						StatSet itemSet = new StatSet(parseAttributes(itemNode)); | ||||
| 						final double chance = itemSet.getDouble("chance"); | ||||
| 						if (needToSumAllChance.get()) | ||||
| 						{ | ||||
| 							chanceSum.set(chanceSum.get() + chance); | ||||
| 						} | ||||
| 						rewards.get().add(new ItemChanceHolder(itemSet.getInt("id"), chance, itemSet.getLong("count"), (byte) itemSet.getInt("enchantLevel", 0))); | ||||
| 					}); | ||||
| 				}); | ||||
| 				LetterCollectorManager lcm = LetterCollectorManager.getInstance(); | ||||
| 				lcm.addWords(id, word.get()); | ||||
| 				lcm.addRewards(id, new LetterCollectorManager.LetterCollectorRewardHolder(rewards.get(), chanceSum.get() == 0d ? 100d : chanceSum.get())); | ||||
| 				lcm.setLetters(letters); | ||||
| 				lcm.setMinLevel(minimumLevel.get()); | ||||
| 				lcm.setMaxLevel(maximumLevel.get()); | ||||
| 			}); | ||||
| 		}); | ||||
| 	} | ||||
| 	 | ||||
| 	@RegisterEvent(EventType.ON_PLAYER_LOGIN) | ||||
| @@ -46,7 +146,7 @@ public class LetterCollector extends LongTimeEvent | ||||
| 		final Player player = event.getPlayer(); | ||||
| 		if (player != null) | ||||
| 		{ | ||||
| 			player.sendPacket(ExLetterCollectorUI.STATIC_PACKET); | ||||
| 			player.sendPacket(new ExLetterCollectorUI(player)); | ||||
| 		} | ||||
| 	} | ||||
| 	 | ||||
|   | ||||
| @@ -1,7 +1,5 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <event name="Letter Collector" active="30 06 2021-29 07 2021" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../xsd/eventConfig.xsd"> | ||||
| 	<!-- Minimum level (95) also set at ExLetterCollectorUI.java --> | ||||
| 	<!-- Rewards and items set at ExLetterCollectorTakeReward.java --> | ||||
| 	<droplist> | ||||
| 		<add item="3875" min="1" max="1" chance="1%" minLevel="95" /> <!-- Letter Collector's A --> | ||||
| 		<add item="3877" min="1" max="1" chance="1%" minLevel="95" /> <!-- Letter Collector's E --> | ||||
|   | ||||
							
								
								
									
										117
									
								
								L2J_Mobius_10.1_MasterClass/dist/game/data/scripts/events/LetterCollector/rewards.xml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										117
									
								
								L2J_Mobius_10.1_MasterClass/dist/game/data/scripts/events/LetterCollector/rewards.xml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,117 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <list xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="rewards.xsd"> | ||||
| 	<params> | ||||
| 		<minimum level="95" /> | ||||
| 		<maximum level="-1" /> <!-- -1 = no limit --> | ||||
| 	</params> | ||||
| 	<letters> | ||||
| 		<!-- name of letter, for using down / id of this letter --> | ||||
| 		<item name="A" id="3875" /> | ||||
| 		<item name="E" id="3877" /> | ||||
| 		<item name="G" id="3879" /> | ||||
| 		<item name="I" id="3881" /> | ||||
| 		<item name="L" id="3882" /> | ||||
| 		<item name="N" id="3883" /> | ||||
| 		<item name="O" id="3884" /> | ||||
| 		<item name="T" id="3886" /> | ||||
| 		<item name="H" id="3880" /> | ||||
| 		<item name="II" id="3888" /> | ||||
| 		<item name="W" id="22894" /> | ||||
| 		<item name="D" id="29545" /> | ||||
| 		<item name="P" id="29825" /> | ||||
| 	</letters> | ||||
| 	<!-- client id --> | ||||
| 	<reward id="0"> | ||||
| 		<!-- split letter with ";" / LINEAGE II -> L;I;N;E;A;G;E;II --> | ||||
| 		<word>L;I;N;E;A;G;E;II</word> <!-- LINEAGE II --> | ||||
| 		<!-- sumChances - sum item chances cumulatively --> | ||||
| 		<rewards sumChances="true"> | ||||
| 			<!-- item id; count; chance; / id="-1" = no reward --> | ||||
| 			<item id="80333" count="1" chance="5" /> <!-- Dragon Necklace --> | ||||
| 			<item id="80334" count="1" chance="5" /> <!-- Dragon Earring --> | ||||
| 			<item id="80335" count="1" chance="5" /> <!-- Dragon Ring --> | ||||
| 			<item id="48296" count="1" chance="5" /> <!-- +10 Eternal Light Armor Capsule --> | ||||
| 			<item id="48297" count="1" chance="5" /> <!-- +10 Eternal Robe Capsule --> | ||||
| 			<item id="48295" count="1" chance="5" /> <!-- +10 Eternal Heavy Armor Capsule --> | ||||
| 			<item id="39573" count="1" chance="5" /> <!-- Sealed Talisman - Insanity --> | ||||
| 			<item id="37716" count="1" chance="5" /> <!-- Seven Signs' Energy --> | ||||
| 			<item id="80416" count="1" chance="5" /> <!-- Fortune Box of 10 Billion Adena --> | ||||
| 			<item id="36414" count="1" chance="5" /> <!-- Dragon Claw --> | ||||
| 			<item id="47705" count="1" chance="15" /> <!-- Blue Cat's Eye Lv. 3 Jewelry Box --> | ||||
| 			<item id="47627" count="1" chance="15" /> <!-- Sapphire Lv. 3 Jewelry Box --> | ||||
| 			<item id="47626" count="1" chance="15" /> <!-- Ruby Lv. 3 Jewelry Box --> | ||||
| 			<item id="47703" count="1" chance="15" /> <!-- Red Cat's Eye Lv. 3 Jewelry Box --> | ||||
| 			<item id="47629" count="1" chance="15" /> <!-- Opal Lv. 3 Jewelry Box --> | ||||
| 			<item id="28360" count="1" chance="15" /> <!-- Cat's Eye Lv. 3 Jewelry Box --> | ||||
| 			<item id="28362" count="1" chance="15" /> <!-- Amethyst Lv. 3 Jewelry Box --> | ||||
| 			<item id="47631" count="1" chance="15" /> <!-- Diamond Lv. 3 Jewelry Box --> | ||||
| 			<item id="47634" count="1" chance="15" /> <!-- Pearl Lv. 3 Jewelry Box --> | ||||
| 			<item id="47635" count="1" chance="15" /> <!-- Vital Stone Lv. 3 Jewelry Box --> | ||||
| 			<item id="47630" count="1" chance="15" /> <!-- Obsidian Lv. 3 Jewelry Box --> | ||||
| 			<item id="47633" count="1" chance="15" /> <!-- Aquamarine Lv. 3 Jewelry Box --> | ||||
| 			<item id="80423" count="1" chance="30" /> <!-- Balance Artifact Box --> | ||||
| 			<item id="80420" count="1" chance="30" /> <!-- Attack Artifact Box --> | ||||
| 			<item id="80421" count="1" chance="30" /> <!-- Protection Artifact Box --> | ||||
| 			<item id="80422" count="1" chance="30" /> <!-- Support Artifact Box --> | ||||
| 			<item id="39374" count="1" chance="30" /> <!-- Scroll: 5.000.000 SP --> | ||||
| 			<item id="46274" count="1" chance="30" /> <!-- Wind Vitality Tonic --> | ||||
| 			<item id="35563" count="1" chance="30" /> <!-- Giant's Energy --> | ||||
| 			<item id="38761" count="1" chance="30" /> <!-- Energy of Destruction 3-unit Pack --> | ||||
| 			<item id="36513" count="1" chance="30" /> <!-- Elcyum Powder --> | ||||
| 			<item id="27673" count="1" chance="30" /> <!-- Freya's Scroll of Storm --> | ||||
| 		</rewards> | ||||
| 	</reward> | ||||
| 	<reward id="1"> | ||||
| 		<word>D;E;A;T;H</word> <!-- DEATH --> | ||||
| 		<rewards sumChances="true"> | ||||
| 			<item id="47821" count="1" chance="5" /> <!-- Sayha's Talisman Lv. 10 --> | ||||
| 			<item id="47820" count="1" chance="5" /> <!-- Sayha's Talisman Lv. 9 --> | ||||
| 			<item id="37717" count="1" chance="5" /> <!-- Talisman - Seven Signs --> | ||||
| 			<item id="39572" count="1" chance="5" /> <!-- Talisman - Insanity --> | ||||
| 			<item id="48032" count="1" chance="5" /> <!-- Sayha's Talisman Lv. 8 --> | ||||
| 			<item id="80416" count="1" chance="5" /> <!-- Fortune Box of 10 Billion Adena --> | ||||
| 			<item id="28448" count="1" chance="5" /> <!-- Sayha's Talisman Lv. 7 --> | ||||
| 			<item id="37715" count="1" chance="5" /> <!-- Talisman - Anakim --> | ||||
| 			<item id="35649" count="1" chance="15" /> <!-- Sealed Talisman - Longing --> | ||||
| 			<item id="29152" count="1" chance="15" /> <!-- High-grade Zodiac Agathion Pack --> | ||||
| 			<item id="29151" count="1" chance="15" /> <!-- Mid-grade Zodiac Agathion Pack --> | ||||
| 			<item id="28373" count="1" chance="15" /> <!-- Tanzenite Lv. 3 Jewelry Box --> | ||||
| 			<item id="47632" count="1" chance="15" /> <!-- Emerald Lv. 3 Jewelry Box --> | ||||
| 			<item id="47636" count="1" chance="15" /> <!-- Garnet Lv. 3 Jewelry Box --> | ||||
| 			<item id="80423" count="1" chance="30" /> <!-- Balance Artifact Box --> | ||||
| 			<item id="80420" count="1" chance="30" /> <!-- Attack Artifact Box --> | ||||
| 			<item id="80421" count="1" chance="30" /> <!-- Protection Artifact Box --> | ||||
| 			<item id="80422" count="1" chance="30" /> <!-- Support Artifact Box --> | ||||
| 			<item id="39374" count="1" chance="30" /> <!-- Scroll: 5.000.000 SP --> | ||||
| 			<item id="46274" count="1" chance="30" /> <!-- Wind Vitality Tonic --> | ||||
| 			<item id="35563" count="1" chance="30" /> <!-- Giant's Energy --> | ||||
| 			<item id="38761" count="1" chance="30" /> <!-- Energy of Destruction 3-unit Pack --> | ||||
| 			<item id="36513" count="1" chance="30" /> <!-- Elcyum Powder --> | ||||
| 			<item id="27673" count="1" chance="30" /> <!-- Freya's Scroll of Storm --> | ||||
| 		</rewards> | ||||
| 	</reward> | ||||
| 	<reward id="2"> | ||||
| 		<word>K;N;I;G;H;T</word> <!-- KNIGHT --> | ||||
| 		<rewards sumChances="true"> | ||||
| 			<item id="80416" count="1" chance="5" /> <!-- Fortune Box of 10 Billion Adena --> | ||||
| 			<item id="28448" count="1" chance="5" /> <!-- Sayha's Talisman Lv. 7 --> | ||||
| 			<item id="26291" count="1" chance="5" /> <!-- Kaliel's Energy - Longing --> | ||||
| 			<item id="36731" count="1" chance="5" /> <!-- Life Stone: Giant's Power --> | ||||
| 			<item id="37714" count="1" chance="5" /> <!-- Talisman - Lilith --> | ||||
| 			<item id="29150" count="1" chance="15" /> <!-- Low-grade Zodiac Agathion Pack --> | ||||
| 			<item id="80423" count="1" chance="30" /> <!-- Balance Artifact Box --> | ||||
| 			<item id="80420" count="1" chance="30" /> <!-- Attack Artifact Box --> | ||||
| 			<item id="80421" count="1" chance="30" /> <!-- Protection Artifact Box --> | ||||
| 			<item id="80422" count="1" chance="30" /> <!-- Support Artifact Box --> | ||||
| 			<item id="36515" count="1" chance="15" /> <!-- Elcyum --> | ||||
| 			<item id="48215" count="1" chance="30" /> <!-- Circlet Spirit Stone --> | ||||
| 			<item id="28540" count="1" chance="30" /> <!-- Magnificent Brooch Spirit Stone --> | ||||
| 			<item id="36514" count="1" chance="30" /> <!-- Elcyum Crystal --> | ||||
| 			<item id="39374" count="1" chance="30" /> <!-- Scroll: 5.000.000 SP --> | ||||
| 			<item id="46274" count="1" chance="30" /> <!-- Wind Vitality Tonic --> | ||||
| 			<item id="35563" count="1" chance="30" /> <!-- Giant's Energy --> | ||||
| 			<item id="38761" count="1" chance="30" /> <!-- Energy of Destruction 3-unit Pack --> | ||||
| 			<item id="27673" count="1" chance="30" /> <!-- Freya's Scroll of Storm --> | ||||
| 		</rewards> | ||||
| 	</reward> | ||||
| </list> | ||||
							
								
								
									
										59
									
								
								L2J_Mobius_10.1_MasterClass/dist/game/data/scripts/events/LetterCollector/rewards.xsd
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										59
									
								
								L2J_Mobius_10.1_MasterClass/dist/game/data/scripts/events/LetterCollector/rewards.xsd
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,59 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> | ||||
| 	<xs:element name="list" type="listType"/> | ||||
| 	<xs:complexType name="minimumType"> | ||||
| 		<xs:simpleContent> | ||||
| 			<xs:extension base="xs:string"> | ||||
| 				<xs:attribute type="xs:string" name="level"/> | ||||
| 			</xs:extension> | ||||
| 		</xs:simpleContent> | ||||
| 	</xs:complexType> | ||||
| 	<xs:complexType name="maximumType"> | ||||
| 		<xs:simpleContent> | ||||
| 			<xs:extension base="xs:string"> | ||||
| 				<xs:attribute type="xs:string" name="level"/> | ||||
| 			</xs:extension> | ||||
| 		</xs:simpleContent> | ||||
| 	</xs:complexType> | ||||
| 	<xs:complexType name="paramsType"> | ||||
| 		<xs:sequence> | ||||
| 			<xs:element type="minimumType" name="minimum"/> | ||||
| 			<xs:element type="maximumType" name="maximum"/> | ||||
| 		</xs:sequence> | ||||
| 	</xs:complexType> | ||||
| 	<xs:complexType name="itemType"> | ||||
| 		<xs:simpleContent> | ||||
| 			<xs:extension base="xs:string"> | ||||
| 				<xs:attribute type="xs:string" name="name" use="optional"/> | ||||
| 				<xs:attribute type="xs:string" name="id" use="optional"/> | ||||
| 				<xs:attribute type="xs:string" name="count" use="optional"/> | ||||
| 				<xs:attribute type="xs:string" name="chance" use="optional"/> | ||||
| 			</xs:extension> | ||||
| 		</xs:simpleContent> | ||||
| 	</xs:complexType> | ||||
| 	<xs:complexType name="lettersType"> | ||||
| 		<xs:sequence> | ||||
| 			<xs:element type="itemType" name="item" maxOccurs="unbounded" minOccurs="0"/> | ||||
| 		</xs:sequence> | ||||
| 	</xs:complexType> | ||||
| 	<xs:complexType name="rewardsType"> | ||||
| 		<xs:sequence> | ||||
| 			<xs:element type="itemType" name="item" maxOccurs="unbounded" minOccurs="0"/> | ||||
| 		</xs:sequence> | ||||
| 		<xs:attribute type="xs:string" name="sumChances"/> | ||||
| 	</xs:complexType> | ||||
| 	<xs:complexType name="rewardType"> | ||||
| 		<xs:sequence> | ||||
| 			<xs:element type="xs:string" name="word"/> | ||||
| 			<xs:element type="rewardsType" name="rewards"/> | ||||
| 		</xs:sequence> | ||||
| 		<xs:attribute type="xs:string" name="id"/> | ||||
| 	</xs:complexType> | ||||
| 	<xs:complexType name="listType"> | ||||
| 		<xs:sequence> | ||||
| 			<xs:element type="paramsType" name="params"/> | ||||
| 			<xs:element type="lettersType" name="letters"/> | ||||
| 			<xs:element type="rewardType" name="reward" maxOccurs="unbounded"/> | ||||
| 		</xs:sequence> | ||||
| 	</xs:complexType> | ||||
| </xs:schema> | ||||
| @@ -0,0 +1,169 @@ | ||||
| /* | ||||
|  * This file is part of the L2J Mobius project. | ||||
|  *  | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU General Public License as published by | ||||
|  * the Free Software Foundation, either version 3 of the License, or | ||||
|  * (at your option) any later version. | ||||
|  *  | ||||
|  * This program is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
|  * General Public License for more details. | ||||
|  *  | ||||
|  * You should have received a copy of the GNU General Public License | ||||
|  * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
| package org.l2jmobius.gameserver.instancemanager.events; | ||||
|  | ||||
| import java.util.HashMap; | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
| import java.util.logging.Logger; | ||||
|  | ||||
| import org.l2jmobius.Config; | ||||
| import org.l2jmobius.gameserver.model.holders.ItemChanceHolder; | ||||
| import org.l2jmobius.gameserver.model.holders.ItemHolder; | ||||
|  | ||||
| /** | ||||
|  * @author Index | ||||
|  */ | ||||
| public class LetterCollectorManager | ||||
| { | ||||
| 	protected static final Logger LOGGER = Logger.getLogger(LetterCollectorManager.class.getName()); | ||||
| 	 | ||||
| 	private final Map<Integer, LetterCollectorRewardHolder> _rewards = new HashMap<>(); | ||||
| 	private final Map<Integer, List<ItemHolder>> _words = new HashMap<>(); | ||||
| 	private final Map<String, Integer> _letter = new HashMap<>(); | ||||
| 	private final Map<Integer, Boolean> _needToSumAllChance = new HashMap<>(); | ||||
| 	 | ||||
| 	private int _minLevel = 1; | ||||
| 	private int _maxLevel = Config.PLAYER_MAXIMUM_LEVEL; | ||||
| 	 | ||||
| 	protected LetterCollectorManager() | ||||
| 	{ | ||||
| 	} | ||||
| 	 | ||||
| 	public void init() | ||||
| 	{ | ||||
| 		LOGGER.info(getClass().getSimpleName() + ": Loaded " + _rewards.size() + " words."); | ||||
| 		LOGGER.info(getClass().getSimpleName() + ": Loaded " + _letter.size() + " letters."); | ||||
| 	} | ||||
| 	 | ||||
| 	public int getMinLevel() | ||||
| 	{ | ||||
| 		return _minLevel; | ||||
| 	} | ||||
| 	 | ||||
| 	public void setMinLevel(int minLevel) | ||||
| 	{ | ||||
| 		_minLevel = minLevel; | ||||
| 	} | ||||
| 	 | ||||
| 	public int getMaxLevel() | ||||
| 	{ | ||||
| 		return _maxLevel; | ||||
| 	} | ||||
| 	 | ||||
| 	public void setMaxLevel(int maxLevel) | ||||
| 	{ | ||||
| 		if (maxLevel < 1) | ||||
| 		{ | ||||
| 			_maxLevel = Config.PLAYER_MAXIMUM_LEVEL; | ||||
| 		} | ||||
| 		else | ||||
| 		{ | ||||
| 			_maxLevel = maxLevel; | ||||
| 		} | ||||
| 	} | ||||
| 	 | ||||
| 	public LetterCollectorRewardHolder getRewards(int id) | ||||
| 	{ | ||||
| 		return _rewards.get(id); | ||||
| 	} | ||||
| 	 | ||||
| 	public List<ItemHolder> getWord(int id) | ||||
| 	{ | ||||
| 		return _words.get(id); | ||||
| 	} | ||||
| 	 | ||||
| 	public void setRewards(Map<Integer, LetterCollectorRewardHolder> rewards) | ||||
| 	{ | ||||
| 		_rewards.putAll(rewards); | ||||
| 	} | ||||
| 	 | ||||
| 	public void setWords(Map<Integer, List<ItemHolder>> words) | ||||
| 	{ | ||||
| 		_words.putAll(words); | ||||
| 	} | ||||
| 	 | ||||
| 	public void addRewards(int id, LetterCollectorRewardHolder rewards) | ||||
| 	{ | ||||
| 		_rewards.put(id, rewards); | ||||
| 	} | ||||
| 	 | ||||
| 	public void addWords(int id, List<ItemHolder> words) | ||||
| 	{ | ||||
| 		_words.put(id, words); | ||||
| 	} | ||||
| 	 | ||||
| 	public void resetField() | ||||
| 	{ | ||||
| 		_minLevel = 1; | ||||
| 		_rewards.clear(); | ||||
| 		_words.clear(); | ||||
| 		_needToSumAllChance.clear(); | ||||
| 	} | ||||
| 	 | ||||
| 	public void setLetters(Map<String, Integer> letters) | ||||
| 	{ | ||||
| 		_letter.putAll(letters); | ||||
| 	} | ||||
| 	 | ||||
| 	public Map<String, Integer> getLetters() | ||||
| 	{ | ||||
| 		return _letter; | ||||
| 	} | ||||
| 	 | ||||
| 	public void setNeedToSumAllChance(int id, boolean needToSumAllChance) | ||||
| 	{ | ||||
| 		_needToSumAllChance.put(id, needToSumAllChance); | ||||
| 	} | ||||
| 	 | ||||
| 	public boolean getNeedToSumAllChance(int id) | ||||
| 	{ | ||||
| 		return _needToSumAllChance.get(id); | ||||
| 	} | ||||
| 	 | ||||
| 	public static class LetterCollectorRewardHolder | ||||
| 	{ | ||||
| 		final List<ItemChanceHolder> _rewards; | ||||
| 		final double _chance; | ||||
| 		 | ||||
| 		public LetterCollectorRewardHolder(List<ItemChanceHolder> rewards, double chance) | ||||
| 		{ | ||||
| 			_rewards = rewards; | ||||
| 			_chance = chance; | ||||
| 		} | ||||
| 		 | ||||
| 		public List<ItemChanceHolder> getRewards() | ||||
| 		{ | ||||
| 			return _rewards; | ||||
| 		} | ||||
| 		 | ||||
| 		public double getChance() | ||||
| 		{ | ||||
| 			return _chance; | ||||
| 		} | ||||
| 	} | ||||
| 	 | ||||
| 	public static LetterCollectorManager getInstance() | ||||
| 	{ | ||||
| 		return SingletonHolder.INSTANCE; | ||||
| 	} | ||||
| 	 | ||||
| 	private static class SingletonHolder | ||||
| 	{ | ||||
| 		protected static final LetterCollectorManager INSTANCE = new LetterCollectorManager(); | ||||
| 	} | ||||
| } | ||||
| @@ -16,120 +16,24 @@ | ||||
|  */ | ||||
| package org.l2jmobius.gameserver.network.clientpackets; | ||||
|  | ||||
| import java.util.List; | ||||
|  | ||||
| import org.l2jmobius.commons.network.PacketReader; | ||||
| import org.l2jmobius.commons.util.Rnd; | ||||
| import org.l2jmobius.gameserver.data.ItemTable; | ||||
| import org.l2jmobius.gameserver.instancemanager.events.LetterCollectorManager; | ||||
| import org.l2jmobius.gameserver.model.actor.Player; | ||||
| import org.l2jmobius.gameserver.model.holders.ItemChanceHolder; | ||||
| import org.l2jmobius.gameserver.model.holders.ItemHolder; | ||||
| import org.l2jmobius.gameserver.model.itemcontainer.PlayerInventory; | ||||
| import org.l2jmobius.gameserver.network.GameClient; | ||||
| import org.l2jmobius.gameserver.network.SystemMessageId; | ||||
| import org.l2jmobius.gameserver.network.serverpackets.SystemMessage; | ||||
|  | ||||
| /** | ||||
|  * @author Index, Mobius | ||||
|  */ | ||||
| public class ExLetterCollectorTakeReward implements IClientIncomingPacket | ||||
| { | ||||
| 	// Items | ||||
| 	private static final int A = 3875; | ||||
| 	private static final int E = 3877; | ||||
| 	private static final int G = 3879; | ||||
| 	private static final int I = 3881; | ||||
| 	private static final int L = 3882; | ||||
| 	private static final int N = 3883; | ||||
| 	private static final int O = 3884; | ||||
| 	private static final int T = 3886; | ||||
| 	private static final int H = 3880; | ||||
| 	private static final int II = 3888; | ||||
| 	private static final int W = 22894; | ||||
| 	private static final int D = 29545; | ||||
| 	private static final int P = 29825; | ||||
| 	 | ||||
| 	// Rewards | ||||
| 	private static final ItemChanceHolder[] LINEAGE_II_REWARDS = | ||||
| 	{ | ||||
| 		new ItemChanceHolder(80333, 5, 1), // Dragon Necklace | ||||
| 		new ItemChanceHolder(80334, 5, 1), // Dragon Earring | ||||
| 		new ItemChanceHolder(80335, 5, 1), // Dragon Ring | ||||
| 		new ItemChanceHolder(48296, 5, 1), // +10 Eternal Light Armor Capsule | ||||
| 		new ItemChanceHolder(48297, 5, 1), // +10 Eternal Robe Capsule | ||||
| 		new ItemChanceHolder(48295, 5, 1), // +10 Eternal Heavy Armor Capsule | ||||
| 		new ItemChanceHolder(39573, 5, 1), // Sealed Talisman - Insanity | ||||
| 		new ItemChanceHolder(37716, 5, 1), // Seven Signs' Energy | ||||
| 		new ItemChanceHolder(80416, 5, 1), // Fortune Box of 10 Billion Adena | ||||
| 		new ItemChanceHolder(36414, 5, 1), // Dragon Claw | ||||
| 		new ItemChanceHolder(47705, 15, 1), // Blue Cat's Eye Lv. 3 Jewelry Box | ||||
| 		new ItemChanceHolder(47627, 15, 1), // Sapphire Lv. 3 Jewelry Box | ||||
| 		new ItemChanceHolder(47626, 15, 1), // Ruby Lv. 3 Jewelry Box | ||||
| 		new ItemChanceHolder(47703, 15, 1), // Red Cat's Eye Lv. 3 Jewelry Box | ||||
| 		new ItemChanceHolder(47629, 15, 1), // Opal Lv. 3 Jewelry Box | ||||
| 		new ItemChanceHolder(28360, 15, 1), // Cat's Eye Lv. 3 Jewelry Box | ||||
| 		new ItemChanceHolder(28362, 15, 1), // Amethyst Lv. 3 Jewelry Box | ||||
| 		new ItemChanceHolder(47631, 15, 1), // Diamond Lv. 3 Jewelry Box | ||||
| 		new ItemChanceHolder(47634, 15, 1), // Pearl Lv. 3 Jewelry Box | ||||
| 		new ItemChanceHolder(47635, 15, 1), // Vital Stone Lv. 3 Jewelry Box | ||||
| 		new ItemChanceHolder(47630, 15, 1), // Obsidian Lv. 3 Jewelry Box | ||||
| 		new ItemChanceHolder(47633, 15, 1), // Aquamarine Lv. 3 Jewelry Box | ||||
| 		new ItemChanceHolder(80423, 30, 1), // Balance Artifact Box | ||||
| 		new ItemChanceHolder(80420, 30, 1), // Attack Artifact Box | ||||
| 		new ItemChanceHolder(80421, 30, 1), // Protection Artifact Box | ||||
| 		new ItemChanceHolder(80422, 30, 1), // Support Artifact Box | ||||
| 		new ItemChanceHolder(39374, 30, 1), // Scroll: 5.000.000 SP | ||||
| 		new ItemChanceHolder(46274, 30, 1), // Wind Vitality Tonic | ||||
| 		new ItemChanceHolder(35563, 30, 1), // Giant's Energy | ||||
| 		new ItemChanceHolder(38761, 30, 1), // Energy of Destruction 3-unit Pack | ||||
| 		new ItemChanceHolder(36513, 30, 1), // Elcyum Powder | ||||
| 		new ItemChanceHolder(27673, 30, 1), // Freya's Scroll of Storm | ||||
| 	}; | ||||
| 	private static final ItemChanceHolder[] DEATH_REWARDS = | ||||
| 	{ | ||||
| 		new ItemChanceHolder(47821, 5, 1), // Sayha's Talisman Lv. 10 | ||||
| 		new ItemChanceHolder(47820, 5, 1), // Sayha's Talisman Lv. 9 | ||||
| 		new ItemChanceHolder(37717, 5, 1), // Talisman - Seven Signs | ||||
| 		new ItemChanceHolder(39572, 5, 1), // Talisman - Insanity | ||||
| 		new ItemChanceHolder(48032, 5, 1), // Sayha's Talisman Lv. 8 | ||||
| 		new ItemChanceHolder(80416, 5, 1), // Fortune Box of 10 Billion Adena | ||||
| 		new ItemChanceHolder(28448, 5, 1), // Sayha's Talisman Lv. 7 | ||||
| 		new ItemChanceHolder(37715, 5, 1), // Talisman - Anakim | ||||
| 		new ItemChanceHolder(35649, 15, 1), // Sealed Talisman - Longing | ||||
| 		new ItemChanceHolder(29152, 15, 1), // High-grade Zodiac Agathion Pack | ||||
| 		new ItemChanceHolder(29151, 15, 1), // Mid-grade Zodiac Agathion Pack | ||||
| 		new ItemChanceHolder(28373, 15, 1), // Tanzenite Lv. 3 Jewelry Box | ||||
| 		new ItemChanceHolder(47632, 15, 1), // Emerald Lv. 3 Jewelry Box | ||||
| 		new ItemChanceHolder(47636, 15, 1), // Garnet Lv. 3 Jewelry Box | ||||
| 		new ItemChanceHolder(80423, 30, 1), // Balance Artifact Box | ||||
| 		new ItemChanceHolder(80420, 30, 1), // Attack Artifact Box | ||||
| 		new ItemChanceHolder(80421, 30, 1), // Protection Artifact Box | ||||
| 		new ItemChanceHolder(80422, 30, 1), // Support Artifact Box | ||||
| 		new ItemChanceHolder(39374, 30, 1), // Scroll: 5.000.000 SP | ||||
| 		new ItemChanceHolder(46274, 30, 1), // Wind Vitality Tonic | ||||
| 		new ItemChanceHolder(35563, 30, 1), // Giant's Energy | ||||
| 		new ItemChanceHolder(38761, 30, 1), // Energy of Destruction 3-unit Pack | ||||
| 		new ItemChanceHolder(36513, 30, 1), // Elcyum Powder | ||||
| 		new ItemChanceHolder(27673, 30, 1), // Freya's Scroll of Storm | ||||
| 	}; | ||||
| 	private static final ItemChanceHolder[] KNIGHT_REWARDS = | ||||
| 	{ | ||||
| 		new ItemChanceHolder(80416, 5, 1), // Fortune Box of 10 Billion Adena | ||||
| 		new ItemChanceHolder(28448, 5, 1), // Sayha's Talisman Lv. 7 | ||||
| 		new ItemChanceHolder(26291, 5, 1), // Kaliel's Energy - Longing | ||||
| 		new ItemChanceHolder(36731, 5, 1), // Life Stone: Giant's Power | ||||
| 		new ItemChanceHolder(37714, 5, 1), // Talisman - Lilith | ||||
| 		new ItemChanceHolder(29150, 15, 1), // Low-grade Zodiac Agathion Pack | ||||
| 		new ItemChanceHolder(80423, 30, 1), // Balance Artifact Box | ||||
| 		new ItemChanceHolder(80420, 30, 1), // Attack Artifact Box | ||||
| 		new ItemChanceHolder(80421, 30, 1), // Protection Artifact Box | ||||
| 		new ItemChanceHolder(80422, 30, 1), // Support Artifact Box | ||||
| 		new ItemChanceHolder(36515, 15, 1), // Elcyum | ||||
| 		new ItemChanceHolder(48215, 30, 1), // Circlet Spirit Stone | ||||
| 		new ItemChanceHolder(28540, 30, 1), // Magnificent Brooch Spirit Stone | ||||
| 		new ItemChanceHolder(36514, 30, 1), // Elcyum Crystal | ||||
| 		new ItemChanceHolder(39374, 30, 1), // Scroll: 5.000.000 SP | ||||
| 		new ItemChanceHolder(46274, 30, 1), // Wind Vitality Tonic | ||||
| 		new ItemChanceHolder(35563, 30, 1), // Giant's Energy | ||||
| 		new ItemChanceHolder(38761, 30, 1), // Energy of Destruction 3-unit Pack | ||||
| 		new ItemChanceHolder(27673, 30, 1), // Freya's Scroll of Storm | ||||
| 	}; | ||||
| 	 | ||||
| 	private int _wordId; | ||||
| 	 | ||||
| 	@Override | ||||
| @@ -154,95 +58,53 @@ public class ExLetterCollectorTakeReward implements IClientIncomingPacket | ||||
| 			return; | ||||
| 		} | ||||
| 		 | ||||
| 		switch (_wordId) | ||||
| 		final LetterCollectorManager.LetterCollectorRewardHolder lcrh = LetterCollectorManager.getInstance().getRewards(_wordId); | ||||
| 		if (lcrh == null) | ||||
| 		{ | ||||
| 			case 0: | ||||
| 			return; | ||||
| 		} | ||||
| 		 | ||||
| 		for (ItemHolder needLetter : LetterCollectorManager.getInstance().getWord(_wordId)) | ||||
| 		{ | ||||
| 			if (inventory.getInventoryItemCount(needLetter.getId(), -1) < needLetter.getCount()) | ||||
| 			{ | ||||
| 				if ((inventory.getInventoryItemCount(L, -1) < 1) || // | ||||
| 					(inventory.getInventoryItemCount(I, -1) < 1) || // | ||||
| 					(inventory.getInventoryItemCount(N, -1) < 1) || // | ||||
| 					(inventory.getInventoryItemCount(E, -1) < 2) || // | ||||
| 					(inventory.getInventoryItemCount(A, -1) < 1) || // | ||||
| 					(inventory.getInventoryItemCount(G, -1) < 1) || // | ||||
| 					(inventory.getInventoryItemCount(II, -1) < 1)) | ||||
| 				{ | ||||
| 					return; | ||||
| 				} | ||||
| 				 | ||||
| 				player.destroyItemByItemId("LetterCollector", L, 1, player, true); | ||||
| 				player.destroyItemByItemId("LetterCollector", I, 1, player, true); | ||||
| 				player.destroyItemByItemId("LetterCollector", N, 1, player, true); | ||||
| 				player.destroyItemByItemId("LetterCollector", E, 1, player, true); | ||||
| 				player.destroyItemByItemId("LetterCollector", A, 1, player, true); | ||||
| 				player.destroyItemByItemId("LetterCollector", G, 1, player, true); | ||||
| 				player.destroyItemByItemId("LetterCollector", E, 1, player, true); | ||||
| 				player.destroyItemByItemId("LetterCollector", II, 1, player, true); | ||||
| 				 | ||||
| 				player.addItem("LetterCollector", getRandomReward(LINEAGE_II_REWARDS), player, true); | ||||
| 				break; | ||||
| 			} | ||||
| 			case 1: | ||||
| 			{ | ||||
| 				if ((inventory.getInventoryItemCount(N, -1) < 2) || // | ||||
| 					(inventory.getInventoryItemCount(E, -1) < 3) || // | ||||
| 					(inventory.getInventoryItemCount(W, -1) < 1) || // | ||||
| 					(inventory.getInventoryItemCount(L, -1) < 1) || // | ||||
| 					(inventory.getInventoryItemCount(G, -1) < 1) || // | ||||
| 					(inventory.getInventoryItemCount(D, -1) < 1)) | ||||
| 				{ | ||||
| 					return; | ||||
| 				} | ||||
| 				 | ||||
| 				player.destroyItemByItemId("LetterCollector", N, 1, player, true); | ||||
| 				player.destroyItemByItemId("LetterCollector", E, 1, player, true); | ||||
| 				player.destroyItemByItemId("LetterCollector", W, 1, player, true); | ||||
| 				player.destroyItemByItemId("LetterCollector", L, 1, player, true); | ||||
| 				player.destroyItemByItemId("LetterCollector", E, 1, player, true); | ||||
| 				player.destroyItemByItemId("LetterCollector", G, 1, player, true); | ||||
| 				player.destroyItemByItemId("LetterCollector", E, 1, player, true); | ||||
| 				player.destroyItemByItemId("LetterCollector", N, 1, player, true); | ||||
| 				player.destroyItemByItemId("LetterCollector", D, 1, player, true); | ||||
| 				 | ||||
| 				player.addItem("LetterCollector", getRandomReward(DEATH_REWARDS), player, true); | ||||
| 				break; | ||||
| 			} | ||||
| 			case 2: | ||||
| 			{ | ||||
| 				if ((inventory.getInventoryItemCount(T, -1) < 3) || // | ||||
| 					(inventory.getInventoryItemCount(O, -1) < 2) || // | ||||
| 					(inventory.getInventoryItemCount(H, -1) < 1) || // | ||||
| 					(inventory.getInventoryItemCount(E, -1) < 1) || // | ||||
| 					(inventory.getInventoryItemCount(P, -1) < 1)) | ||||
| 				{ | ||||
| 					return; | ||||
| 				} | ||||
| 				 | ||||
| 				player.destroyItemByItemId("LetterCollector", T, 1, player, true); | ||||
| 				player.destroyItemByItemId("LetterCollector", O, 1, player, true); | ||||
| 				player.destroyItemByItemId("LetterCollector", T, 1, player, true); | ||||
| 				player.destroyItemByItemId("LetterCollector", H, 1, player, true); | ||||
| 				player.destroyItemByItemId("LetterCollector", E, 1, player, true); | ||||
| 				player.destroyItemByItemId("LetterCollector", T, 1, player, true); | ||||
| 				player.destroyItemByItemId("LetterCollector", O, 1, player, true); | ||||
| 				player.destroyItemByItemId("LetterCollector", P, 1, player, true); | ||||
| 				 | ||||
| 				player.addItem("LetterCollector", getRandomReward(KNIGHT_REWARDS), player, true); | ||||
| 				break; | ||||
| 				return; | ||||
| 			} | ||||
| 		} | ||||
| 		for (ItemHolder destroyLetter : LetterCollectorManager.getInstance().getWord(_wordId)) | ||||
| 		{ | ||||
| 			if (!player.destroyItemByItemId("LetterCollector", destroyLetter.getId(), destroyLetter.getCount(), player, true)) | ||||
| 			{ | ||||
| 				return; | ||||
| 			} | ||||
| 		} | ||||
| 		 | ||||
| 		final ItemHolder rewardItem = getRandomReward(lcrh.getRewards(), lcrh.getChance()); | ||||
| 		if (rewardItem == null) | ||||
| 		{ | ||||
| 			player.sendPacket(new SystemMessage(SystemMessageId.NOTHING_HAPPENED)); | ||||
| 			return; | ||||
| 		} | ||||
| 		 | ||||
| 		player.addItem("LetterCollector", rewardItem.getId(), rewardItem.getCount(), player, true); | ||||
| 	} | ||||
| 	 | ||||
| 	private ItemChanceHolder getRandomReward(ItemChanceHolder[] rewards) | ||||
| 	private ItemHolder getRandomReward(List<ItemChanceHolder> rewards, double holderChance) | ||||
| 	{ | ||||
| 		ItemChanceHolder reward = null; | ||||
| 		while (reward == null) | ||||
| 		final double chance = Rnd.get(holderChance); | ||||
| 		double itemChance = 0; | ||||
| 		for (ItemChanceHolder rewardItem : rewards) | ||||
| 		{ | ||||
| 			final ItemChanceHolder random = rewards[Rnd.get(rewards.length)]; | ||||
| 			if ((Rnd.get(100) < random.getChance()) && (ItemTable.getInstance().getTemplate(random.getId()) != null)) | ||||
| 			itemChance += rewardItem.getChance(); | ||||
| 			if (chance <= itemChance) | ||||
| 			{ | ||||
| 				reward = random; | ||||
| 				if (rewardItem.getId() == -1) | ||||
| 				{ | ||||
| 					return null; | ||||
| 				} | ||||
| 				return rewardItem; | ||||
| 			} | ||||
| 		} | ||||
| 		return reward; | ||||
| 		return null; | ||||
| 	} | ||||
| } | ||||
| @@ -16,7 +16,10 @@ | ||||
|  */ | ||||
| package org.l2jmobius.gameserver.network.serverpackets; | ||||
|  | ||||
| import org.l2jmobius.Config; | ||||
| import org.l2jmobius.commons.network.PacketWriter; | ||||
| import org.l2jmobius.gameserver.instancemanager.events.LetterCollectorManager; | ||||
| import org.l2jmobius.gameserver.model.actor.Player; | ||||
| import org.l2jmobius.gameserver.network.OutgoingPackets; | ||||
|  | ||||
| /** | ||||
| @@ -24,12 +27,11 @@ import org.l2jmobius.gameserver.network.OutgoingPackets; | ||||
|  */ | ||||
| public class ExLetterCollectorUI implements IClientOutgoingPacket | ||||
| { | ||||
| 	public static final ExLetterCollectorUI STATIC_PACKET = new ExLetterCollectorUI(); | ||||
| 	final int _minimumLevel; | ||||
| 	 | ||||
| 	private static final int LETTER_COLLECTOR_MIN_LEVEL = 95; | ||||
| 	 | ||||
| 	private ExLetterCollectorUI() | ||||
| 	public ExLetterCollectorUI(Player player) | ||||
| 	{ | ||||
| 		_minimumLevel = player.getLevel() <= LetterCollectorManager.getInstance().getMaxLevel() ? LetterCollectorManager.getInstance().getMinLevel() : Config.PLAYER_MAXIMUM_LEVEL; | ||||
| 	} | ||||
| 	 | ||||
| 	@Override | ||||
| @@ -37,7 +39,7 @@ public class ExLetterCollectorUI implements IClientOutgoingPacket | ||||
| 	{ | ||||
| 		OutgoingPackets.EX_LETTER_COLLECTOR_UI_LAUNCHER.writeId(packet); | ||||
| 		packet.writeC(1); // enabled (0x00 - no, 0x01 -yes) | ||||
| 		packet.writeD(LETTER_COLLECTOR_MIN_LEVEL); // Minimum Level | ||||
| 		packet.writeD(_minimumLevel); // Minimum Level | ||||
| 		return true; | ||||
| 	} | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 MobiusDevelopment
					MobiusDevelopment