AirShipManager.java 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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.io.BufferedReader;
  17. import java.io.File;
  18. import java.io.FileNotFoundException;
  19. import java.io.FileReader;
  20. import java.io.LineNumberReader;
  21. import java.util.ArrayList;
  22. import java.util.StringTokenizer;
  23. import java.util.logging.Level;
  24. import java.util.logging.Logger;
  25. import com.l2jserver.Config;
  26. import com.l2jserver.gameserver.idfactory.IdFactory;
  27. import com.l2jserver.gameserver.model.actor.instance.L2AirShipControllerInstance;
  28. import com.l2jserver.gameserver.model.actor.instance.L2AirShipInstance;
  29. import com.l2jserver.gameserver.templates.StatsSet;
  30. import com.l2jserver.gameserver.templates.chars.L2CharTemplate;
  31. public class AirShipManager
  32. {
  33. private static final Logger _log = Logger.getLogger(AirShipManager.class.getName());
  34. private L2AirShipInstance _airShip = null;
  35. private ArrayList<L2AirShipControllerInstance> _atcs = new ArrayList<L2AirShipControllerInstance>(2);
  36. public static final AirShipManager getInstance()
  37. {
  38. return SingletonHolder._instance;
  39. }
  40. private AirShipManager()
  41. {
  42. load();
  43. }
  44. private final void load()
  45. {
  46. LineNumberReader lnr = null;
  47. try
  48. {
  49. File doorData = new File(Config.DATAPACK_ROOT, "data/airship.csv");
  50. lnr = new LineNumberReader(new BufferedReader(new FileReader(doorData)));
  51. String line = null;
  52. while ((line = lnr.readLine()) != null)
  53. {
  54. if (line.trim().length() == 0 || line.startsWith("#"))
  55. continue;
  56. L2AirShipInstance airShip = parseLine(line);
  57. airShip.spawn();
  58. _airShip = airShip;
  59. if (Config.DEBUG)
  60. {
  61. _log.info("AirShip ID : " + airShip.getObjectId());
  62. }
  63. }
  64. }
  65. catch (FileNotFoundException e)
  66. {
  67. _log.warning("airship.csv is missing in data folder");
  68. }
  69. catch (Exception e)
  70. {
  71. _log.log(Level.WARNING, "Error while creating AirShip table " + e.getMessage(), e);
  72. }
  73. finally
  74. {
  75. try
  76. {
  77. lnr.close();
  78. }
  79. catch (Exception e1)
  80. { /* ignore problems */
  81. }
  82. }
  83. }
  84. /**
  85. * @param line
  86. * @return
  87. */
  88. private L2AirShipInstance parseLine(String line)
  89. {
  90. L2AirShipInstance airShip;
  91. StringTokenizer st = new StringTokenizer(line, ";");
  92. int xspawn = Integer.parseInt(st.nextToken());
  93. int yspawn = Integer.parseInt(st.nextToken());
  94. int zspawn = Integer.parseInt(st.nextToken());
  95. int heading = Integer.parseInt(st.nextToken());
  96. StatsSet npcDat = new StatsSet();
  97. npcDat.set("npcId", 9);
  98. npcDat.set("level", 0);
  99. npcDat.set("jClass", "boat");
  100. npcDat.set("baseSTR", 0);
  101. npcDat.set("baseCON", 0);
  102. npcDat.set("baseDEX", 0);
  103. npcDat.set("baseINT", 0);
  104. npcDat.set("baseWIT", 0);
  105. npcDat.set("baseMEN", 0);
  106. npcDat.set("baseShldDef", 0);
  107. npcDat.set("baseShldRate", 0);
  108. npcDat.set("baseAccCombat", 38);
  109. npcDat.set("baseEvasRate", 38);
  110. npcDat.set("baseCritRate", 38);
  111. // npcDat.set("name", "");
  112. npcDat.set("collision_radius", 0);
  113. npcDat.set("collision_height", 0);
  114. npcDat.set("sex", "male");
  115. npcDat.set("type", "");
  116. npcDat.set("baseAtkRange", 0);
  117. npcDat.set("baseMpMax", 0);
  118. npcDat.set("baseCpMax", 0);
  119. npcDat.set("rewardExp", 0);
  120. npcDat.set("rewardSp", 0);
  121. npcDat.set("basePAtk", 0);
  122. npcDat.set("baseMAtk", 0);
  123. npcDat.set("basePAtkSpd", 0);
  124. npcDat.set("aggroRange", 0);
  125. npcDat.set("baseMAtkSpd", 0);
  126. npcDat.set("rhand", 0);
  127. npcDat.set("lhand", 0);
  128. npcDat.set("armor", 0);
  129. npcDat.set("baseWalkSpd", 0);
  130. npcDat.set("baseRunSpd", 0);
  131. npcDat.set("name", "AirShip");
  132. npcDat.set("baseHpMax", 50000);
  133. npcDat.set("baseHpReg", 3.e-3f);
  134. npcDat.set("baseMpReg", 3.e-3f);
  135. npcDat.set("basePDef", 100);
  136. npcDat.set("baseMDef", 100);
  137. L2CharTemplate template = new L2CharTemplate(npcDat);
  138. airShip = new L2AirShipInstance(IdFactory.getInstance().getNextId(), template);
  139. airShip.setIsFlying(true);
  140. airShip.getPosition().setHeading(heading);
  141. airShip.setXYZ(xspawn, yspawn, zspawn);
  142. airShip.setTrajet1(1);
  143. airShip.setTrajet2(2);
  144. airShip.setTrajet3(3);
  145. airShip.setTrajet4(4);
  146. return airShip;
  147. }
  148. public L2AirShipInstance getAirShip()
  149. {
  150. return _airShip;
  151. }
  152. public void registerATC(L2AirShipControllerInstance atc)
  153. {
  154. _atcs.add(atc);
  155. }
  156. public ArrayList<L2AirShipControllerInstance> getATCs()
  157. {
  158. return _atcs;
  159. }
  160. @SuppressWarnings("synthetic-access")
  161. private static class SingletonHolder
  162. {
  163. protected static final AirShipManager _instance = new AirShipManager();
  164. }
  165. }