Advertisement
tensador125

L2FavorecedoraBuffer

Feb 13th, 2022 (edited)
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.19 KB | None | 0 0
  1. /* l2jterius Project - www.l2jterius.com
  2.  *
  3.  * This program is free software; you can redistribute it and/or modify
  4.  * it under the terms of the GNU General Public License as published by
  5.  * the Free Software Foundation; either version 2, or (at your option)
  6.  * any later version.
  7.  *
  8.  * This program is distributed in the hope that it will be useful,
  9.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.  * GNU General Public License for more details.
  12.  *
  13.  * You should have received a copy of the GNU General Public License
  14.  * along with this program; if not, write to the Free Software
  15.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  16.  * 02111-1307, USA.
  17.  *
  18.  * http://www.gnu.org/copyleft/gpl.html
  19.  */
  20. package com.l2jterius.gameserver.model.actor.instance;
  21.  
  22. import java.util.concurrent.ScheduledFuture;
  23.  
  24. import com.l2jterius.Config;
  25. import com.l2jterius.gameserver.ai.CtrlIntention;
  26. import com.l2jterius.gameserver.datatables.SkillTable;
  27. import com.l2jterius.gameserver.model.L2Skill;
  28. import com.l2jterius.gameserver.model.base.ClassId;
  29. import com.l2jterius.gameserver.network.serverpackets.ActionFailed;
  30. import com.l2jterius.gameserver.network.serverpackets.MagicSkillUser;
  31. import com.l2jterius.gameserver.network.serverpackets.MoveToPawn;
  32. import com.l2jterius.gameserver.network.serverpackets.MyTargetSelected;
  33. import com.l2jterius.gameserver.network.serverpackets.NpcHtmlMessage;
  34. import com.l2jterius.gameserver.network.serverpackets.ValidateLocation;
  35. import com.l2jterius.gameserver.skills.SkillHolder;
  36. import com.l2jterius.gameserver.templates.L2NpcTemplate;
  37. import com.l2jterius.gameserver.thread.ThreadPoolManager;
  38.  
  39. /**
  40.  * @author ADM-Terius
  41.  */
  42. public class L2FavorecedoraInstance extends L2NpcInstance
  43. {
  44.     private ScheduledFuture<?> _aiTask;
  45.    
  46.     @Override
  47.     public void onAction(L2PcInstance player)
  48.     {
  49.         if (this != player.getTarget())
  50.         {
  51.             player.setTarget(this);
  52.             player.sendPacket(new MyTargetSelected(getObjectId(), 0));
  53.             player.sendPacket(new ValidateLocation(this));
  54.         }
  55.         else
  56.         {
  57.             if (!canInteract(player))
  58.                 player.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, this);
  59.             else
  60.             {
  61.                 // Rotate the player to face the instance
  62.                 player.sendPacket(new MoveToPawn(player, this, L2NpcInstance.INTERACTION_DISTANCE));
  63.                
  64.                 if (hasRandomAnimation())
  65.                     onRandomAnimation();
  66.                
  67.                 showMainWindow(player);
  68.                
  69.                 // Send ActionFailed to the player in order to avoid he stucks
  70.                 player.sendPacket(ActionFailed.STATIC_PACKET);
  71.             }
  72.         }
  73.     }
  74.    
  75.     /**
  76.      * @param player
  77.      */
  78.     private void showMainWindow(L2PcInstance player)
  79.     {
  80.        
  81.         NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
  82.         html.setFile("data/html/mods/FavorecedoraBuff.htm");
  83.         html.replace("%objectId%", String.valueOf(getObjectId()));
  84.         html.replace("%npcname%", getName());
  85.         player.sendPacket(html);
  86.     }  
  87.    
  88.     private class TeriusAI implements Runnable
  89.     {
  90.         private final L2FavorecedoraInstance _caster;
  91.        
  92.         protected TeriusAI(final L2FavorecedoraInstance caster)
  93.         {
  94.             _caster = caster;
  95.         }
  96.         private final SkillHolder[] HERO_BUFFS =
  97.         {
  98.             new SkillHolder(2622, 1),
  99.         };
  100.        
  101.         private final SkillHolder[] CLANLORD_BUFFS =
  102.         {
  103.             new SkillHolder(2621, 1),
  104.         };
  105.                
  106.         private final SkillHolder[] DonatorM_BUFFS =
  107.         {
  108.             new SkillHolder(2619, 1),
  109.         };
  110.         private final SkillHolder[] DonatorW_BUFFS =
  111.         {
  112.             new SkillHolder(2620, 1),
  113.         };
  114.        
  115.        
  116.         @Override
  117.         public void run()
  118.         {
  119.             for (final L2PcInstance player : getKnownList().getKnownPlayers().values())
  120.             {          
  121.                
  122.                 if (player.isMageClass() && (player.isDonator() && (player.getClassId() != ClassId.overlord) && (player.getClassId() != ClassId.warcryer)))
  123.                 {
  124.                     for (SkillHolder skills : DonatorM_BUFFS)
  125.                     {
  126.                         TeriusCast(player, skills.getSkill());
  127.                     }
  128.  
  129.                 }else
  130.                 if(player.isDonator())
  131.                     for (SkillHolder skills : DonatorW_BUFFS)
  132.                     {
  133.                         TeriusCast(player, skills.getSkill());
  134.                     }
  135.                 if(player.isHero() && (player.isDonator()))
  136.                 {
  137.                     for (SkillHolder skills : HERO_BUFFS)
  138.                     {
  139.                         TeriusCast(player, skills.getSkill());
  140.                     }
  141.                 }
  142.                 if((player.isCastleLord(1) || (player.isCastleLord(2) || (player.isCastleLord(3) || (player.isCastleLord(4) || (player.isCastleLord(5) || (player.isCastleLord(6) || (player.isCastleLord(7) || (player.isCastleLord(8) || (player.isCastleLord(9) && (player.isDonator())))))))))))
  143.                 {
  144.                     for (SkillHolder skills : CLANLORD_BUFFS)
  145.                     {
  146.                         TeriusCast(player, skills.getSkill());
  147.                     }
  148.  
  149.  
  150.                 }
  151.             }
  152.         }
  153.    
  154.         // Funcion de casteo al jugador
  155.    private boolean TeriusCast(final L2PcInstance player,L2Skill skill)
  156.         {
  157.             if (player.isDead() || !player.isVisible() || !isInsideRadius(player, 200, false, false))
  158.                 return false;
  159.            
  160.             if (player.getFirstEffect(skill) == null)
  161.             {
  162.                 heal(player);
  163.                 SkillTable.getInstance().getInfo(skill.getId(), skill.getLevel()).getEffects(player, player);
  164.                 skill.getEffects(_caster, player, false, false, false);
  165.                 broadcastPacket(new MagicSkillUser(_caster, player, skill.getId(), skill.getLevel(), Config.PROTECTOR_SKILLTIME, 0));
  166.                 skill = null;
  167.                 return true;
  168.             }
  169.            
  170.             return false;
  171.         }
  172.     }
  173.    
  174.     static void heal(L2PcInstance activeChar)
  175.     {
  176.         activeChar.setCurrentHp(activeChar.getMaxHp());
  177.         activeChar.setCurrentCp(activeChar.getMaxCp());
  178.         activeChar.setCurrentMp(activeChar.getMaxMp());
  179.     }  
  180.    
  181.     public L2FavorecedoraInstance(final int objectId, final L2NpcTemplate template)
  182.     {
  183.         super(objectId, template);
  184.        
  185.         if (_aiTask != null)
  186.         {
  187.             _aiTask.cancel(true);
  188.         }
  189.        
  190.         _aiTask = ThreadPoolManager.getInstance().scheduleAiAtFixedRate(new TeriusAI(this), 3000, 3000);
  191.     }
  192.  
  193. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement