AirShipManager.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.gameserver.instancemanager;
  16. import java.util.ArrayList;
  17. import javolution.util.FastMap;
  18. import com.l2jserver.gameserver.idfactory.IdFactory;
  19. import com.l2jserver.gameserver.model.actor.instance.L2AirShipControllerInstance;
  20. import com.l2jserver.gameserver.model.actor.instance.L2AirShipInstance;
  21. import com.l2jserver.gameserver.templates.StatsSet;
  22. import com.l2jserver.gameserver.templates.chars.L2CharTemplate;
  23. public class AirShipManager
  24. {
  25. private L2CharTemplate _airShipTemplate = null;
  26. private FastMap<Integer, L2AirShipInstance> _airShips = new FastMap<Integer, L2AirShipInstance>();
  27. private ArrayList<L2AirShipControllerInstance> _atcs = new ArrayList<L2AirShipControllerInstance>(2);
  28. public static final AirShipManager getInstance()
  29. {
  30. return SingletonHolder._instance;
  31. }
  32. private AirShipManager()
  33. {
  34. StatsSet npcDat = new StatsSet();
  35. npcDat.set("npcId", 9);
  36. npcDat.set("level", 0);
  37. npcDat.set("jClass", "boat");
  38. npcDat.set("baseSTR", 0);
  39. npcDat.set("baseCON", 0);
  40. npcDat.set("baseDEX", 0);
  41. npcDat.set("baseINT", 0);
  42. npcDat.set("baseWIT", 0);
  43. npcDat.set("baseMEN", 0);
  44. npcDat.set("baseShldDef", 0);
  45. npcDat.set("baseShldRate", 0);
  46. npcDat.set("baseAccCombat", 38);
  47. npcDat.set("baseEvasRate", 38);
  48. npcDat.set("baseCritRate", 38);
  49. npcDat.set("collision_radius", 0);
  50. npcDat.set("collision_height", 0);
  51. npcDat.set("sex", "male");
  52. npcDat.set("type", "");
  53. npcDat.set("baseAtkRange", 0);
  54. npcDat.set("baseMpMax", 0);
  55. npcDat.set("baseCpMax", 0);
  56. npcDat.set("rewardExp", 0);
  57. npcDat.set("rewardSp", 0);
  58. npcDat.set("basePAtk", 0);
  59. npcDat.set("baseMAtk", 0);
  60. npcDat.set("basePAtkSpd", 0);
  61. npcDat.set("aggroRange", 0);
  62. npcDat.set("baseMAtkSpd", 0);
  63. npcDat.set("rhand", 0);
  64. npcDat.set("lhand", 0);
  65. npcDat.set("armor", 0);
  66. npcDat.set("baseWalkSpd", 0);
  67. npcDat.set("baseRunSpd", 0);
  68. npcDat.set("name", "AirShip");
  69. npcDat.set("baseHpMax", 50000);
  70. npcDat.set("baseHpReg", 3.e-3f);
  71. npcDat.set("baseMpReg", 3.e-3f);
  72. npcDat.set("basePDef", 100);
  73. npcDat.set("baseMDef", 100);
  74. _airShipTemplate = new L2CharTemplate(npcDat);
  75. }
  76. public L2AirShipInstance getAirShip(int objectId)
  77. {
  78. return _airShips.get(objectId);
  79. }
  80. public L2AirShipInstance getNewAirShip(int x, int y, int z, int heading)
  81. {
  82. L2AirShipInstance airShip = new L2AirShipInstance(IdFactory.getInstance().getNextId(), _airShipTemplate);
  83. _airShips.put(airShip.getObjectId(), airShip);
  84. airShip.setHeading(heading);
  85. airShip.setXYZInvisible(x, y, z);
  86. airShip.spawnMe();
  87. return airShip;
  88. }
  89. public void registerATC(L2AirShipControllerInstance atc)
  90. {
  91. _atcs.add(atc);
  92. }
  93. public ArrayList<L2AirShipControllerInstance> getATCs()
  94. {
  95. return _atcs;
  96. }
  97. public L2AirShipControllerInstance getNearestATC(L2AirShipInstance ship, int radius)
  98. {
  99. if (_atcs == null || _atcs.isEmpty())
  100. return null;
  101. for (L2AirShipControllerInstance atc : _atcs)
  102. {
  103. if (atc != null && atc.isInsideRadius(ship, radius, true, false))
  104. return atc;
  105. }
  106. return null;
  107. }
  108. @SuppressWarnings("synthetic-access")
  109. private static class SingletonHolder
  110. {
  111. protected static final AirShipManager _instance = new AirShipManager();
  112. }
  113. }