AirShipManager.java 5.0 KB

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