Unhardcoded Letter Collector rewards.

Thanks to Index.
This commit is contained in:
MobiusDevelopment
2022-06-09 15:59:40 +00:00
parent f41d29758e
commit 3000820cdb
42 changed files with 2956 additions and 1156 deletions

View File

@@ -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));
}
}

View File

@@ -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 -->

View 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>

View 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>