Emudevs - MMORPG Development

Immerse yourself in a world of limitless possibilities and open the gateway to mmo emulation.

Source Code NewBie System Data

Unencrypted Source Code Resource

BAN - L2JDEV

Developer
Developer

0

0%

Status

Online

Posts

7

Likes

12

Rep

6

Bits

27

2

Months of Service

LEVEL 7
36 XP
This is a primitive system focused on giving some rewards to players according to their level,

Assuming he is level one and kills a monster and reaches level four after setting three he will still receive the item

There is no html for choosing items, it will only deliver items to players equipped with Armor and Weapon, other items will be delivered to the bag normally

If one of the items is a soulshot or spiritshot, it will be received and registered in the player's skill bar, to be exact, it will be sent to the third bar in the dose potion.



1707171622334
Python:
=============================================================
Index: net/sf/l2j/gameserver/model/holder/IntIntHolder.java
=============================================================
# Use Ctrl + Shift + R in eclipse and check if the class does not exist, if it does not exist add it

+package net.sf.l2j.gameserver.model.holder;

+    import net.sf.l2j.gameserver.data.SkillTable;
+    import net.sf.l2j.gameserver.model.L2Skill;
+   
+    /**
+     * A generic int/int container.
+     */
+    public class IntIntHolder
+    {
+        private int _id;
+        private int _value;
+       
+        public IntIntHolder(int id, int value)
+        {
+            _id = id;
+            _value = value;
+        }
+       
+        public int getId()
+        {
+            return _id;
+        }
+       
+        public int getValue()
+        {
+            return _value;
+        }
+       
+        public void setId(int id)
+        {
+            _id = id;
+        }
+       
+        public void setValue(int value)
+        {
+            _value = value;
+        }
+       
+        /**
+         * @return the L2Skill associated to the id/value.
+         */
+        public final L2Skill getSkill()
+        {
+            return SkillTable.getInstance().getInfo(_id, _value);
+        }
+       
+        @Override
+        public String toString()
+        {
+            return getClass().getSimpleName() + ": Id: " + _id + ", Value: " + _value;
+        }
+    }

=============================================================
Index: net/sf/l2j/gameserver/dev/newbie/NewbieHolder.java
=============================================================
# Add this class to represent the functions

+package net.sf.l2j.gameserver.dev.newbie;

+import java.util.List;
+
+import net.sf.l2j.commons.util.StatsSet;
+import net.sf.l2j.gameserver.model.holder.IntIntHolder;
+
+/**
+ * @author BAN - L2JDEV
+ */
+public class NewbieHolder
+{
+   
+    private final List<IntIntHolder> _MageItems;
+    private final List<IntIntHolder> _FighteItems;
+    private final int _Id;
+    private final int _ShortcutId;
+    private final int _level;
+   
+    public NewbieHolder(StatsSet set)
+    {
+        _MageItems = set.getIntIntHolderList("isMage");
+        _FighteItems = set.getIntIntHolderList("isFight");
+        _Id = set.getInteger("id");
+        _ShortcutId = set.getInteger("registerShortcutId", 12);
+        _level = set.getInteger("level", 0);
+    }
+   
+    public List<IntIntHolder> getWizzarditems()
+    {
+        return _MageItems;
+    }
+   
+    public List<IntIntHolder> getFightsitems()
+    {
+        return _FighteItems;
+    }
+   
+    public int getId()
+    {
+        return _Id;
+    }
+   
+    public int getLevel()
+    {
+        return _level;
+    }
+   
+    public int getShortcutId()
+    {
+        return _ShortcutId;
+    }
+}

=============================================================
Index: net/sf/l2j/gameserver/dev/newbie/newbieData.java
=============================================================
# Add this class to represent the functions

+package net.sf.l2j.gameserver.dev.newbie;
+
+import java.nio.file.Path;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import net.sf.l2j.commons.data.xml.IXmlReader;
+import net.sf.l2j.commons.util.StatsSet;
+
+import org.w3c.dom.Document;
+
+/**
+ * @author BAN - L2JDEV
+ */
+public class newbieData implements IXmlReader
+{
+    private final Map<Integer, NewbieHolder> _newbie = new HashMap<>();
+   
+    protected newbieData()
+    {
+        load();
+    }
+   
+    public void reload()
+    {
+        _newbie.clear();
+        load();
+    }
+   
+    @Override
+    public void load()
+    {
+        parseFile("./data/xml/custom/NewbieSystem.xml");
+    }
+   
+    @Override
+    public void parseDocument(Document doc, Path path)
+    {
+        forEach(doc, "list", listNode -> forEach(listNode, "newbie", recipeNode -> {
+            final StatsSet set = parseAttributes(recipeNode);
+            _newbie.put(set.getInteger("id"), new NewbieHolder(set));
+        }));
+    }
+   
+    public NewbieHolder getlevelList(int level)
+    {
+        return _newbie.get(level);
+    }
+   
+    public NewbieHolder getlevel(int level)
+    {
+        return _newbie.values().stream().filter(r -> r.getLevel() == level).findFirst().orElse(null);
+    }
+   
+    public List<NewbieHolder> getlevelId(int level)
+    {
+        return _newbie.values().stream().filter(recipe -> recipe.getLevel() == level).collect(Collectors.toList());
+    }
+   
+    public int getSize()
+    {
+        return _newbie.size();
+    }
+   
+    public static newbieData getInstance()
+    {
+        return SingletonHolder.INSTANCE;
+    }
+   
+    private static class SingletonHolder
+    {
+        protected static final newbieData INSTANCE = new newbieData();
+    }
+}

=============================================================
Index: net/sf/l2j/gameserver/gameserver.java
=============================================================

+import net.sf.l2j.gameserver.dev.newbie.newbieData;


+        StringUtil.printSection("Newbie System Manager");
+        newbieData.getInstance();
+        LOGGER.info("Newbie Loaded {}", newbieData.getInstance().getSize());
        
        StringUtil.printSection("Handlers");

=============================================================
Index: net/sf/l2j/gameserver/model/actor/stat/PlayableStat.java
=============================================================
# Add this class to represent the functions
# put it below this method, don't remove it, just use it as a reference

import net.sf.l2j.gameserver.model.actor.Player;
+import net.sf.l2j.gameserver.data.xml.ItemData;
+import net.sf.l2j.gameserver.dev.newbie.NewbieHolder;
+import net.sf.l2j.gameserver.dev.newbie.newbieData;
+import net.sf.l2j.gameserver.model.Shortcut;
+import net.sf.l2j.gameserver.model.holder.IntIntHolder;
+import net.sf.l2j.gameserver.model.item.instance.ItemInstance;
+import net.sf.l2j.gameserver.network.serverpackets.ExAutoSoulShot;
+import net.sf.l2j.gameserver.network.serverpackets.ShortCutRegister;
+import net.sf.l2j.gameserver.model.item.kind.Armor;
+import net.sf.l2j.gameserver.model.item.kind.EtcItem;
+import net.sf.l2j.gameserver.model.item.kind.Item;
+import net.sf.l2j.gameserver.model.item.kind.Weapon;
+import net.sf.l2j.gameserver.network.serverpackets.ItemList;
    
public boolean removeExpAndSp(long removeExp, int removeSp)
{
    boolean expRemoved = false;
    boolean spRemoved = false;
    
    if (removeExp > 0)
        expRemoved = removeExp(removeExp);
    
    if (removeSp > 0)
        spRemoved = removeSp(removeSp);
    
    return expRemoved || spRemoved;
}


+        public boolean isSoulshot(IntIntHolder product)
+        {
+            Item itemTemplate = ItemData.getInstance().getTemplate(product.getId());
+            if (itemTemplate instanceof EtcItem)
+            {
+                EtcItem etcItem = (EtcItem) itemTemplate;
+                return etcItem.getItemType() == EtcItemType.SHOT;
+            }
+            return false;
+        }
+       
+        public void applySoulshotLogic(ItemInstance soulshotItem)
+        {
+            int previousLevel = getActiveChar().getLevel() - 1;
+            int levelDifference = getActiveChar().getLevel() - previousLevel;
+           
+            if (levelDifference <= 3)
+            {
+                NewbieHolder newbie = newbieData.getInstance().getlevel(previousLevel);
+                if (newbie != null)
+                {
+                    if (((Player)getActiveChar()).isMageClass())
+                    {
+                        for (IntIntHolder product : newbie.getWizzarditems())
+                        {
+                           
+                            ItemInstance item = getActiveChar().getInventory().getItemByItemId(product.getId());
+                            if (item != null)
+                            {
+                                if (item.getItem().getDefaultAction() == ActionType.spiritshot)
+                                {
+                                    if (((Player)getActiveChar()).getAutoSoulShot().isEmpty())
+                                    {
+                                        ((Player)getActiveChar()).addAutoSoulShot(item.getItemId());
+                                        ((Player)getActiveChar()).rechargeShots(false, true);
+                                    }
+                                   
+                                    Shortcut shortcut = new Shortcut(newbie.getShortcutId(), 2, ShortcutType.ITEM, item.getObjectId(), -1, 1);
+                                    ((Player)getActiveChar()).sendPacket(new ShortCutRegister(((Player)getActiveChar()), shortcut));
+                                    ((Player)getActiveChar()).getShortcutList().addShortcut(shortcut);
+                                    ((Player)getActiveChar()).sendPacket(new ExAutoSoulShot(item.getItemId(), 1));
+                                   
+                                }
+                               
+                            }
+                        }
+                    }
+                    else
+                    {
+                        for (IntIntHolder product : newbie.getFightsitems())
+                        {
+                           
+                            ItemInstance item = getActiveChar().getInventory().getItemByItemId(product.getId());
+                            if (item != null)
+                            {
+                                if (item.getItem().getDefaultAction() == ActionType.soulshot)
+                                {
+                                    if (((Player)getActiveChar()).getAutoSoulShot().isEmpty())
+                                    {
+                                        ((Player)getActiveChar()).addAutoSoulShot(item.getItemId());
+                                        ((Player)getActiveChar()).rechargeShots(true, false);
+                                    }
+                                   
+                                    Shortcut shortcut = new Shortcut(newbie.getShortcutId(), 2, ShortcutType.ITEM, item.getObjectId(), -1, 1);
+                                    ((Player)getActiveChar()).sendPacket(new ShortCutRegister(((Player)getActiveChar()), shortcut));
+                                    ((Player)getActiveChar()).getShortcutList().addShortcut(shortcut);
+                                    ((Player)getActiveChar()).sendPacket(new ExAutoSoulShot(item.getItemId(), 1));
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+           
+        }

    public boolean addLevel(byte value)
    {
        if (getLevel() + value > PlayerLevelData.getInstance().getRealMaxLevel())
        {
            if (getLevel() < PlayerLevelData.getInstance().getRealMaxLevel())
                value = (byte) (PlayerLevelData.getInstance().getRealMaxLevel() - getLevel());
            else
                return false;
        }
        
        boolean levelIncreased = (getLevel() + value > getLevel());
        value += getLevel();
        setLevel(value);
        
        // Sync up exp with current level
        if (getExp() >= getExpForLevel(getLevel() + 1) || getExpForLevel(getLevel()) > getExp())
            setExp(getExpForLevel(getLevel()));
        
        if (!levelIncreased)
            return false;
        
        getActiveChar().getStatus().setCurrentHpMp(getMaxHp(), getMaxMp());
        
            
+        int previousLevel = getActiveChar().getLevel() - 1;
+        int levelDifference = getActiveChar().getLevel() - previousLevel;
+       
+        if (levelDifference <= 3)
+        {
+            final NewbieHolder newbie = newbieData.getInstance().getlevel(previousLevel);
+            if (newbie != null)
+            {
+                if (((Player)getActiveChar()).isMageClass())
+                {
+                    for (IntIntHolder product : newbie.getWizzarditems())
+                    {
+                        int itemId = product.getId();
+                        int itemCount = product.getValue();
+                       
+                        if (!getActiveChar().getInventory().validateCapacity(1))
+                        {
+                            getActiveChar().sendPacket(SystemMessageId.SLOTS_FULL);
+                            getActiveChar().sendMessage("Full Slots inventory.");
+                            return false;
+                        }
+                       
+                        ItemInstance itemInstance = ((Player)getActiveChar()).addItem("NewbieSystem", itemId, itemCount, getActiveChar(), true);
+                       
+                        if (isSoulshot(product))
+                        {
+                            applySoulshotLogic(itemInstance);
+                        }
+                        else if (itemInstance.getItem() instanceof Armor || itemInstance.getItem() instanceof Weapon)
+                        {
+                           
+                            ((Player)getActiveChar()).useEquippableItem(itemInstance, true);
+                        }
+                    }
+                   
+                    ((Player)getActiveChar()).sendPacket(new ItemList(((Player)getActiveChar()), false));
+                    ((Player)getActiveChar()).rewardSkills();
+                }
+                else
+                {
+                    for (IntIntHolder product : newbie.getFightsitems())
+                    {
+                        int itemId = product.getId();
+                        int itemCount = product.getValue();
+                       
+                        if (!getActiveChar().getInventory().validateCapacity(1))
+                        {
+                            getActiveChar().sendPacket(SystemMessageId.SLOTS_FULL);
+                            getActiveChar().sendMessage("Full Slots inventory.");
+                            return false;
+                        }
+                       
+                        ItemInstance itemInstance = ((Player)getActiveChar()).addItem("NewbieSystem", itemId, itemCount, getActiveChar(), true);
+                       
+                        if (isSoulshot(product))
+                        {
+                            applySoulshotLogic(itemInstance);
+                        }
+                        else if (itemInstance.getItem() instanceof Armor || itemInstance.getItem() instanceof Weapon)
+                        {
+                           
+                            ((Player)getActiveChar()).useEquippableItem(itemInstance, true);
+                        }
+                    }
+                   
+                    ((Player)getActiveChar()).sendPacket(new ItemList(((Player)getActiveChar()), false));
+                    ((Player)getActiveChar()).rewardSkills();
+                }
+            }
+           
+        }
        return true;
}

=============================================================
Index: data/xml/custom/NewbieSystem.xml
=============================================================

+    <?xml version='1.0' encoding='utf-8'?>
+    <!--
+        This XML defines newbie rewards for reaching level.
+        Players can receive different items based on their class type.
+    -->
+    <list>
+   
+    <newbie id="1" isMage="1101-1;1104-1;44-1;1300-1;3947-400" isFight="23-1;2386-1;43-1;7821-1;1835-400" registerShortcutId="11" level="3" />
+   
+    </list>
 
Reactions:
Liked by 1 member:

2,407

1,079

8,786

Top