Reanimation06

anti pk absdoluto l2

Dec 1st, 2025
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.27 KB | Gaming | 0 0
  1. Index: L2Kryos_GameServer/config/system_config/fun/npc_Protector.ini
  2. =====================================================================
  3.  
  4. +#============================================================#
  5. +# L2NpcProtectorInstance Config
  6. +#============================================================#
  7. +# Tables; 1,2,3,4,5,6,7,8,9,10,15,16,17,18.
  8. +# Default = 15
  9. +NpcProtectorTextCreatureSay = 15
  10. +# Prefix to be displayed before the message
  11. +NpcMessagePrefix = [Anti-PK]
  12. +# Message after eliminating a player with karma.
  13. +ScreenNpcProtectorMessageText = PK is prohibited.
  14. +# Damage that the NPC will inflict.
  15. +NpcProtectorPAtk = 30000
  16. +NpcProtectorMAtk = 30000
  17.  
  18. Index: head-src/kryos/Config.java
  19. ==================================
  20.  
  21. +
  22. +   // ===============================FUN===============================
  23. +   public static int NPC_PROTECTOR_P_ATK;
  24. +   public static int NPC_PROTECTOR_M_ATK;
  25. +
  26. +   public static int NPC_PROTECTOR_TEXT_CREATURE_SAY;
  27. +   public static String NPC_MESSAGE_PREFIX;
  28. +   public static String NPC_PROTECTOR_MESSAGE_TEXT;
  29. +
  30. +   //==================================================================
  31. +   public static void loadNpcProtectorConfig()
  32. +   {
  33. +       final String NPCSYSTEM = FService.NPCSYSTEM_FILE;
  34. +
  35. +       try
  36. +       {
  37. +           final Properties NpcConfig = new Properties();
  38. +           final InputStream is = new FileInputStream(new File(NPCSYSTEM));
  39. +           NpcConfig.load(is);
  40. +           is.close();
  41. +           // =============================================FUN=============================================
  42. +
  43. +           NPC_PROTECTOR_P_ATK = Integer.parseInt(NpcConfig.getProperty("NpcProtectorPAtk", "30000"));
  44. +           NPC_PROTECTOR_M_ATK = Integer.parseInt(NpcConfig.getProperty("NpcProtectorMAtk", "30000"));
  45. +
  46. +           NPC_PROTECTOR_TEXT_CREATURE_SAY = Integer.parseInt(NpcConfig.getProperty("NpcProtectorTextCreatureSay", "15"));
  47. +           NPC_MESSAGE_PREFIX = NpcConfig.getProperty("NpcMessagePrefix", "[Anti-PK]");
  48. +           NPC_PROTECTOR_MESSAGE_TEXT = NpcConfig.getProperty("ScreenNpcProtectorMessageText", "PK is prohibited.");
  49. +
  50. +           // =============================================================================================
  51. +       }
  52. +       catch (Exception e)
  53. +       {
  54. +           e.printStackTrace();
  55. +           throw new Error("Failed to Load " + NPCSYSTEM + " File.");
  56. +       }
  57. +   }
  58. +
  59.  
  60. @@
  61.  
  62.             loadRewardSystemConfig();
  63. +           loadNpcProtectorConfig();
  64.  
  65. Index: head-src/kryos/FService.java
  66. ====================================
  67.  
  68. +public static final String NPCSYSTEM_FILE = "./config/system_config/fun/npc_Protector.ini";
  69.  
  70. Index: head-src/kryos/gameserver/model/actor/knownlist/ProtectorKnownList.java
  71. ===============================================================================
  72.  
  73. +package kryos.gameserver.model.actor.knownlist;
  74. +
  75. +import kryos.gameserver.model.L2Object;
  76. +import kryos.gameserver.model.actor.instance.L2NpcProtectorInstance;
  77. +
  78. +public class ProtectorKnownList extends AttackableKnownList
  79. +{
  80. +   private static final int DISTANCE_TO_WATCH = 10000;
  81. +
  82. +   public ProtectorKnownList(L2NpcProtectorInstance activeChar)
  83. +   {
  84. +       super(activeChar);
  85. +   }
  86. +
  87. +   @Override
  88. +   public boolean addKnownObject(L2Object object)
  89. +   {
  90. +
  91. +       double distance = getDistance(object);
  92. +       if (distance > DISTANCE_TO_WATCH)
  93. +       {
  94. +           return false;
  95. +       }
  96. +       return super.addKnownObject(object);
  97. +   }
  98. +
  99. +   private double getDistance(L2Object object)
  100. +   {
  101. +       int dx = getActiveChar().getX() - object.getX();
  102. +       int dy = getActiveChar().getY() - object.getY();
  103. +       int dz = getActiveChar().getZ() - object.getZ();
  104. +       return Math.sqrt(dx*dx + dy*dy + dz*dz);
  105. +   }
  106. +
  107. +   @Override
  108. +   public L2NpcProtectorInstance getActiveChar()
  109. +   {
  110. +       return (L2NpcProtectorInstance) super.getActiveChar();
  111. +   }
  112. +}
  113.  
  114. Index: head-src/kryos/gameserver/model/actor/instance/L2NpcProtectorInstance.java
  115. ==================================================================================
  116.  
  117. +package kryos.gameserver.model.actor.instance;
  118. +
  119. +import kryos.gameserver.model.L2Character;
  120. +import kryos.gameserver.model.L2Attackable;
  121. +import kryos.gameserver.model.actor.knownlist.ProtectorKnownList;
  122. +import kryos.gameserver.network.serverpackets.ActionFailed;
  123. +import kryos.gameserver.templates.L2NpcTemplate;
  124. +import kryos.gameserver.thread.ThreadPoolManager;
  125. +import kryos.gameserver.model.L2Object;
  126. +import kryos.gameserver.model.L2World;
  127. +import kryos.Config;
  128. +import kryos.gameserver.ai.CtrlIntention;
  129. +
  130. +public class L2NpcProtectorInstance extends L2Attackable
  131. +{
  132. +   private int spawnX, spawnY, spawnZ;
  133. +   private double pAtk;
  134. +   private double mAtk;
  135. +
  136. +   public L2NpcProtectorInstance(int objectId, L2NpcTemplate template)
  137. +   {
  138. +       super(objectId, template);
  139. +       setKnownList(new ProtectorKnownList(this));
  140. +   }
  141. +
  142. +   @Override
  143. +   public void onSpawn()
  144. +   {
  145. +       super.onSpawn();
  146. +
  147. +       spawnX = getX();
  148. +       spawnY = getY();
  149. +       spawnZ = getZ();
  150. +
  151. +       pAtk = Config.NPC_PROTECTOR_P_ATK;
  152. +       mAtk = Config.NPC_PROTECTOR_M_ATK;
  153. +
  154. +       ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(() ->
  155. +       {
  156. +           try
  157. +           {
  158. +               scanForPKs();
  159. +           }
  160. +           catch (Exception e)
  161. +           {
  162. +               e.printStackTrace();
  163. +           }
  164. +       }, 100, 100);
  165. +   }
  166. +
  167. +   private void scanForPKs()
  168. +   {
  169. +       L2PcInstance targetPK = null;
  170. +       double minDistance = Double.MAX_VALUE;
  171. +
  172. +       for (L2Character cha : getAggroList().keySet())
  173. +       {
  174. +           if (cha instanceof L2PcInstance)
  175. +           {
  176. +               L2PcInstance pc = (L2PcInstance) cha;
  177. +               if (pc.isDead() || pc.getKarma() <= 0)
  178. +               {
  179. +                   stopHating(pc);
  180. +               }
  181. +           }
  182. +       }
  183. +
  184. +       for (L2PcInstance pc : L2World.getInstance().getAllPlayers())
  185. +       {
  186. +           if (pc.getKarma() <= 0 || pc.isDead())
  187. +               continue;
  188. +
  189. +           double distance = getDistance(pc);
  190. +           if (distance > 10000)
  191. +               continue;
  192. +
  193. +           if (!getKnownList().knowsObject(pc))
  194. +           {
  195. +               getKnownList().addKnownObject(pc);
  196. +           }
  197. +
  198. +           if (distance < minDistance)
  199. +           {
  200. +               targetPK = pc;
  201. +               minDistance = distance;
  202. +           }
  203. +       }
  204. +
  205. +       if (targetPK != null)
  206. +       {
  207. +           if (getAI().getIntention() != CtrlIntention.AI_INTENTION_ATTACK || getTarget() != targetPK)
  208. +           {
  209. +               getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, targetPK);
  210. +           }
  211. +           double physDamage = pAtk - targetPK.getPDef(this);
  212. +           if (physDamage < 0) physDamage = 1000;
  213. +
  214. +           double magicDamage = mAtk - targetPK.getMDef(this, null);
  215. +           if (magicDamage < 0) magicDamage = 500;
  216. +
  217. +           double totalDamage = physDamage + magicDamage;
  218. +           targetPK.reduceCurrentHp(totalDamage, this, true);
  219. +       }
  220. +       else
  221. +       {
  222. +           if (getX() != spawnX || getY() != spawnY)
  223. +           {
  224. +               teleToLocation(spawnX, spawnY, spawnZ);
  225. +           }
  226. +           if (getAI().getIntention() != CtrlIntention.AI_INTENTION_IDLE)
  227. +           {
  228. +               getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE, null);
  229. +           }
  230. +       }
  231. +   }
  232. +
  233. +   private double getDistance(L2Object obj)
  234. +   {
  235. +       int dx = getX() - obj.getX();
  236. +       int dy = getY() - obj.getY();
  237. +       int dz = getZ() - obj.getZ();
  238. +       return Math.sqrt(dx*dx + dy*dy + dz*dz);
  239. +   }
  240. +
  241. +   @Override
  242. +   public void onAction(L2PcInstance player)
  243. +   {
  244. +       player.sendPacket(new ActionFailed());
  245. +   }
  246. +
  247. +   @Override
  248. +   public boolean isAutoAttackable(L2Character attacker)
  249. +   {
  250. +       return false;
  251. +   }
  252. +}
  253.  
  254. Index: head-src/kryos/gameserver/model/actor/instance/L2PcInstance.java
  255. ========================================================================
  256.  
  257. @@
  258.  
  259.     @Override
  260.     public boolean doDie(final L2Character killer)
  261.     {
  262.             castle = CastleManager.getInstance().getCastleByOwner(getClan());
  263.             if (castle != null)
  264.             {
  265.                 castle.destroyClanGate();
  266.                 castle = null;
  267.             }
  268.         }
  269.  
  270.         if (killer != null)
  271.         {
  272.             final L2PcInstance pk = killer.getActingPlayer();
  273. +
  274. +           // Message sent by the L2NpcProtectorInstance
  275. +           if (killer instanceof L2NpcProtectorInstance)
  276. +           {
  277. +               L2NpcProtectorInstance npc = (L2NpcProtectorInstance) killer;
  278. +               if (getKarma() > 0)
  279. +               {
  280. +                   String regionName = MapRegionTable.getInstance().getClosestTownName(this);
  281. +
  282. +                   CreatureSay cs = new CreatureSay(npc.getObjectId(),Config.NPC_PROTECTOR_TEXT_CREATURE_SAY, "", Config.NPC_MESSAGE_PREFIX +" " + getName() + " (" + regionName + ") " + Config.NPC_PROTECTOR_MESSAGE_TEXT );
  283.  
  284. +                   Broadcast.toAllOnlinePlayers(cs);
  285. +               }
  286. +           }
  287. +           // /////////////////////////////
  288. +
  289.             if (pk != null)
  290.             {
  291.                 if (Config.ENABLE_PK_INFO)
  292.                 {
  293.                     doPkInfo(pk);
  294.                 }
  295.  
  296.                 if (atEvent)
  297.                 {
  298.                     pk.kills.add(getName());
  299.                 }
  300.  
  301.                 if (_inEventTvT && pk._inEventTvT)
Add Comment
Please, Sign In to add comment