Jump to content

Recommended Posts

Posted (edited)

Hello, i want to share this code of an npc buffer that i adapted from fissban.

 

 

Here I leave a video of how the npc works

 

https://www.youtube.com/watch?v=H6fvw7ZFHAU&list=LL&index=1&ab_channel=L2-Terius

 

 

Code L2JOrion

with configuration by levels 1 to 40 from 40 to 75 and 76 to 80

https://pastebin.com/ZCYN7m5G

 

 

 

Code L2JFROZEN

/* l2jfrozen Project - www.l2jfrozen.com 
 * 
 * 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 2, 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, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 *
 * http://www.gnu.org/copyleft/gpl.html
 */
package com.l2jfrozen.gameserver.model.actor.instance;

import java.util.concurrent.ScheduledFuture;

import com.l2jfrozen.Config;
import com.l2jfrozen.gameserver.ai.CtrlIntention;
import com.l2jfrozen.gameserver.datatables.SkillTable;
import com.l2jfrozen.gameserver.model.L2Skill;
import com.l2jfrozen.gameserver.model.base.ClassId;
import com.l2jfrozen.gameserver.network.serverpackets.ActionFailed;
import com.l2jfrozen.gameserver.network.serverpackets.MagicSkillUser;
import com.l2jfrozen.gameserver.network.serverpackets.MoveToPawn;
import com.l2jfrozen.gameserver.network.serverpackets.MyTargetSelected;
import com.l2jfrozen.gameserver.network.serverpackets.NpcHtmlMessage;
import com.l2jfrozen.gameserver.network.serverpackets.ValidateLocation;
import com.l2jfrozen.gameserver.skills.SkillHolder;
import com.l2jfrozen.gameserver.templates.L2NpcTemplate;
import com.l2jfrozen.gameserver.thread.ThreadPoolManager;

/**
 * @author fissban
 * @adaptado tensador
 */
public class L2TeriusBuffInstance extends L2NpcInstance
{
	private ScheduledFuture<?> _aiTask;
	
   	@Override
	public void onAction(L2PcInstance player)
	{
		if (this != player.getTarget())
		{
			player.setTarget(this);
			player.sendPacket(new MyTargetSelected(getObjectId(), 0));
			player.sendPacket(new ValidateLocation(this));
		}
		else
		{
			if (!canInteract(player))
				player.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, this);
			else
			{
				// Rotate the player to face the instance
				player.sendPacket(new MoveToPawn(player, this, L2NpcInstance.INTERACTION_DISTANCE));
				
				if (hasRandomAnimation())
					onRandomAnimation();
				
				showMainWindow(player);
				
				// Send ActionFailed to the player in order to avoid he stucks
				player.sendPacket(ActionFailed.STATIC_PACKET);
			}
		}
	}
   
	private void showMainWindow(L2PcInstance player)
	{
		
		NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
		html.setFile("data/html/mods/TeriusBuff.htm");
		html.replace("%objectId%", String.valueOf(getObjectId()));
		html.replace("%npcname%", getName());
		player.sendPacket(html);
	} 	
	
	private class TeriusAI implements Runnable
	{
		private final L2TeriusBuffInstance _caster;
		
		protected TeriusAI(final L2TeriusBuffInstance caster)
		{
			_caster = caster;
		}
		
        private final SkillHolder[] FIGHTER_BUFFS =
        {
        	new SkillHolder(1352, 1),
        	new SkillHolder(1353, 1),
        	new SkillHolder(1415, 1),
        	new SkillHolder(1393, 3),
        	new SkillHolder(1392, 3),
        	new SkillHolder(1191, 3),
        	new SkillHolder(1189, 3),
        	new SkillHolder(1182, 3),
        	new SkillHolder(1392, 3),
        	new SkillHolder(1040, 3),
        	new SkillHolder(1036, 2),
        	new SkillHolder(1062, 2),
        	new SkillHolder(1045, 6),
        	new SkillHolder(1068, 3),
        	new SkillHolder(1035, 4),
        	new SkillHolder(1240, 3),
        	new SkillHolder(1242, 3),
        	new SkillHolder(1077, 3),
        	new SkillHolder(1086, 2),
        	new SkillHolder(1204, 2),
        	new SkillHolder(1268, 4),
        	new SkillHolder(264, 1),
        	new SkillHolder(266, 1),
        	new SkillHolder(267, 1),
        	new SkillHolder(268, 1),
        	new SkillHolder(269, 1),
        	new SkillHolder(304, 1),
        	new SkillHolder(306, 1),
        	new SkillHolder(308, 1),
        	new SkillHolder(270, 1),
        	new SkillHolder(364, 1),
        	new SkillHolder(274, 1),
        	new SkillHolder(275, 1),
        	new SkillHolder(271, 1),
        	new SkillHolder(309, 1),
        	new SkillHolder(307, 1),
        	new SkillHolder(272, 1),
        	new SkillHolder(310, 1),
        	new SkillHolder(1363, 1),
        	new SkillHolder(1388, 3),
        	new SkillHolder(4700, 13),
        	new SkillHolder(1323, 1),
        };
        private final SkillHolder[] MAGE_BUFFS =
        {
        	new SkillHolder(1352, 1),
        	new SkillHolder(1353, 1),
        	new SkillHolder(1415, 1),
        	new SkillHolder(1393, 3),
        	new SkillHolder(1392, 3),
        	new SkillHolder(1191, 3),
        	new SkillHolder(1189, 3),
        	new SkillHolder(1182, 3),
        	new SkillHolder(1392, 3),
        	new SkillHolder(1040, 3),
        	new SkillHolder(1036, 2),
        	new SkillHolder(1045, 6),
        	new SkillHolder(1048, 6),
        	new SkillHolder(1062, 2),
        	new SkillHolder(1035, 4),
        	new SkillHolder(1085, 3),
        	new SkillHolder(1078, 6),
        	new SkillHolder(1304, 3),
        	new SkillHolder(1243, 6),
        	new SkillHolder(1204, 2),
        	new SkillHolder(1303, 2),
        	new SkillHolder(1259, 4),
        	new SkillHolder(1059, 3),
        	new SkillHolder(266, 1),
        	new SkillHolder(264, 1),
        	new SkillHolder(267, 1),
        	new SkillHolder(306, 1),
        	new SkillHolder(308, 1),
        	new SkillHolder(270, 1),
        	new SkillHolder(268, 1),
        	new SkillHolder(304, 1),
        	new SkillHolder(273, 1),
        	new SkillHolder(307, 1),
        	new SkillHolder(276, 1),
        	new SkillHolder(349, 1),
        	new SkillHolder(277, 1),
        	new SkillHolder(365, 1),
        	new SkillHolder(304, 1),
        	new SkillHolder(1413, 1),
        	new SkillHolder(1389, 3),
        	new SkillHolder(4702, 13),
        	new SkillHolder(1323, 1),
        };
		
		@Override
		public void run()
		{
			for (final L2PcInstance player : getKnownList().getKnownPlayers().values())
			{			
				
                if (player.isMageClass() && (player.getClassId() != ClassId.overlord) && (player.getClassId() != ClassId.warcryer))
				{
                    for (SkillHolder skills : MAGE_BUFFS) 
                    {
    					TeriusCast(player, skills.getSkill());
                    }

				}else
                    for (SkillHolder skills : FIGHTER_BUFFS)
                    {
                    	TeriusCast(player, skills.getSkill());
                    }

			}
		}	
		
	private boolean TeriusCast(final L2PcInstance player,L2Skill skill)
		{
			if (player.isDead() || !player.isVisible() || !isInsideRadius(player, 200, false, false))
				return false;
			
			if (player.getFirstEffect(skill) == null)
			{
				heal(player);
                SkillTable.getInstance().getInfo(skill.getId(), skill.getLevel()).getEffects(player, player);
				skill.getEffects(_caster, player, false, false, false);
				broadcastPacket(new MagicSkillUser(_caster, player, skill.getId(), skill.getLevel(), Config.PROTECTOR_SKILLTIME, 0));

				return true;
			}
			
			return false;
		}
	}
	
	static void heal(L2PcInstance activeChar)
	{
		activeChar.setCurrentHp(activeChar.getMaxHp());
		activeChar.setCurrentCp(activeChar.getMaxCp());
		activeChar.setCurrentMp(activeChar.getMaxMp());
	}	
	
	public L2TeriusBuffInstance(final int objectId, final L2NpcTemplate template)
	{
		super(objectId, template);
		
		if (_aiTask != null)
		{
			_aiTask.cancel(true);
		}
		
		_aiTask = ThreadPoolManager.getInstance().scheduleAiAtFixedRate(new TeriusAI(this), 3000, 3000);
	}

}

 

 

Code original fissban h5 l2jserver

/*
     * Copyright (C) 2004-2013 L2J DataPack
     *
     * This file is part of L2J DataPack.
     *
     * L2J DataPack 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.
     *
     * L2J DataPack 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 custom.NpcBufferGod;
     
    /**
     * @autor: fissban
     */
     
    import java.util.Collection;
     
    import ai.npc.AbstractNpcAI;
     
    import com.l2jserver.gameserver.ThreadPoolManager;
    import com.l2jserver.gameserver.datatables.SkillTable;
    import com.l2jserver.gameserver.model.Location;
    import com.l2jserver.gameserver.model.actor.L2Npc;
    import com.l2jserver.gameserver.model.actor.L2Summon;
    import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
    import com.l2jserver.gameserver.model.base.ClassId;
    import com.l2jserver.gameserver.model.holders.SkillHolder;
    import com.l2jserver.gameserver.model.skills.L2Skill;
     
    public class NpcBufferGOD extends AbstractNpcAI
    {
        // NPC
        private static final int Newbie_Helper = 32327;
        // Spawn state
        private static boolean SPAWNED = false;
       
        static final Location[] SPAWNS =
        {
            // Sacado de la DB
            new Location(17136, 144896, -3008, 26624),
            new Location(43556, -47608, -792, 36864),
            new Location(82385, 53283, -1488, 16384),
            new Location(82879, 149380, -3469, 34120),
            new Location(87152, -141328, -1336, 49296),
            new Location(111168, 221008, -3544, 0),
            new Location(116935, 77258, -2688, 40960),
            new Location(147099, 25939, -2008, 49151),
            new Location(148077, -55367, -2728, 32768),
            new Location(-84081, 243227, -3728, 9000),
            new Location(115632, -177996, -896, 32768),
            new Location(-45032, -113598, -192, 32768),
            new Location(12111, 16686, -4584, 63240),
            new Location(45475, 48359, -3056, 49152),
            new Location(-119692, 44504, 360, 33324),
            new Location(-13920, 121977, -2984, 33000),
            new Location(-83123, 150868, -3120, 0),
        };
       
        protected NpcBufferGOD(String name, String descr)
        {
            super(name, descr);
           
            addStartNpc(Newbie_Helper);
            addSpawnId(Newbie_Helper);
            addTalkId(Newbie_Helper);
           
            if (!SPAWNED)
            {
                for (Location spawn : SPAWNS)
                {
                    addSpawn(Newbie_Helper, spawn, false, 0);
                }
                SPAWNED = true;
            }
        }
       
        @Override
        public String onSpawn(L2Npc npc)
        {
            ThreadPoolManager.getInstance().scheduleGeneral(new BufferAI(npc), 5000);
            return super.onSpawn(npc);
        }
       
        @Override
        public String onTalk(L2Npc npc, L2PcInstance player)
        {
            return "32327.htm";
        }
       
        protected class BufferAI implements Runnable
        {
            private final L2Npc _npc;
           
            // Skills
            private final SkillHolder HASTE_1 = new SkillHolder(4327, 1);
            private final SkillHolder HASTE_2 = new SkillHolder(5632, 1);
            private final SkillHolder CUBIC = new SkillHolder(4338, 1);
            private final SkillHolder[] FIGHTER_BUFFS =
            {
                new SkillHolder(4322, 1), // Wind Walk
                new SkillHolder(4323, 1), // Shield
                new SkillHolder(5637, 1), // Magic Barrier
                new SkillHolder(4324, 1), // Bless the Body
                new SkillHolder(4325, 1), // Vampiric Rage
                new SkillHolder(4326, 1), // Regeneration
            };
            private final SkillHolder[] MAGE_BUFFS =
            {
                new SkillHolder(4322, 1), // Wind Walk
                new SkillHolder(4323, 1), // Shield
                new SkillHolder(5637, 1), // Magic Barrier
                new SkillHolder(4328, 1), // Bless the Soul
                new SkillHolder(4329, 1), // Acumen
                new SkillHolder(4330, 1), // Concentration
                new SkillHolder(4331, 1), // Empower
            };
            private final SkillHolder[] SUMMON_BUFFS =
            {
                new SkillHolder(4322, 1), // Wind Walk
                new SkillHolder(4323, 1), // Shield
                new SkillHolder(5637, 1), // Magic Barrier
                new SkillHolder(4324, 1), // Bless the Body
                new SkillHolder(4325, 1), // Vampiric Rage
                new SkillHolder(4326, 1), // Regeneration
                new SkillHolder(4328, 1), // Bless the Soul
                new SkillHolder(4329, 1), // Acumen
                new SkillHolder(4330, 1), // Concentration
                new SkillHolder(4331, 1), // Empower
            };
           
            protected BufferAI(L2Npc caster)
            {
                _npc = caster;
            }
           
            @Override
            public void run()
            {
                if ((_npc == null) || !_npc.isVisible())
                {
                    return;
                }
               
                Collection<L2PcInstance> plrs = _npc.getKnownList().getKnownPlayers().values();
                for (L2PcInstance player : plrs)
                {
                    if ((player == null) || player.isInvul() || player.isDead() || (player.getLevel() > 75) || (player.getLevel() < 6) || player.isCursedWeaponEquipped() || (player.getKarma() != 0) || !_npc.isInsideRadius(player, 500, false, false))
                    {
                        continue;
                    }
                    // summons
                    if ((player.getSummon() != null) && player.getSummon().isServitor())
                    {
                        for (SkillHolder skills : SUMMON_BUFFS)
                        {
                            CastSummon(player.getSummon(), skills.getSkill());
                        }
                        if (player.getLevel() > 40)
                        {
                            CastSummon(player.getSummon(), HASTE_2.getSkill());
                        }
                        else
                        {
                            CastSummon(player.getSummon(), HASTE_1.getSkill());
                        }
                    }
                    // magos
                    if (player.isMageClass() && (player.getClassId() != ClassId.overlord) && (player.getClassId() != ClassId.warcryer))
                    {
                        for (SkillHolder skills : MAGE_BUFFS)
                        {
                            CastPlayer(player, skills.getSkill());
                        }
                    }
                    // warrios
                    else
                    {
                        for (SkillHolder skills : FIGHTER_BUFFS)
                        {
                            CastPlayer(player, skills.getSkill());
                        }
                        if (player.getLevel() > 40)
                        {
                            CastPlayer(player, HASTE_2.getSkill());
                        }
                        else
                        {
                            CastPlayer(player, HASTE_1.getSkill());
                        }
                    }
                    if ((player.getLevel() >= 16) && (player.getLevel() <= 34))
                    {
                        player.doSimultaneousCast(CUBIC.getSkill());
                    }
                }
                ThreadPoolManager.getInstance().scheduleGeneral(this, 3000);
            }
           
            // metodo para los players
            private boolean CastPlayer(L2PcInstance player, L2Skill skill)
            {
                if (player.getFirstEffect(skill) == null)
                {
                    skill.getEffects(_npc, player);
                    SkillTable.getInstance().getInfo(skill.getId(), skill.getLevel()).getEffects(player, player);
                    return true;
                }
                return false;
            }
           
            // metodo para los summons
            private boolean CastSummon(L2Summon summon, L2Skill skill)
            {
                if (summon.getFirstEffect(skill) == null)
                {
                    skill.getEffects(_npc, summon);
                    SkillTable.getInstance().getInfo(skill.getId(), skill.getLevel()).getEffects(summon, summon);
                    return true;
                }
                return false;
            }
        }
       
        public static void main(String[] args)
        {
            new NpcBufferGOD(NpcBufferGOD.class.getSimpleName(), "ai/npc");
        }
       
    }

 

 

htm: https://www.mediafire.com/file/vd5hy2cjfwf2lzj/TeriusBuff.htm/file

 

 

Edited by tensador27
new code l2jorion

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...