BoatManager.java 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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.Map;
  22. import java.util.StringTokenizer;
  23. import java.util.logging.Logger;
  24. import javolution.util.FastMap;
  25. import net.sf.l2j.Config;
  26. import net.sf.l2j.gameserver.idfactory.IdFactory;
  27. import net.sf.l2j.gameserver.model.actor.instance.L2BoatInstance;
  28. import net.sf.l2j.gameserver.templates.L2CharTemplate;
  29. import net.sf.l2j.gameserver.templates.StatsSet;
  30. public class BoatManager
  31. {
  32. private static final Logger _log = Logger.getLogger(BoatManager.class.getName());
  33. // =========================================================
  34. private static BoatManager _instance;
  35. public static final BoatManager getInstance()
  36. {
  37. if (_instance == null)
  38. {
  39. _log.info("Initializing BoatManager");
  40. _instance = new BoatManager();
  41. _instance.load();
  42. }
  43. return _instance;
  44. }
  45. // =========================================================
  46. // =========================================================
  47. // Data Field
  48. private Map<Integer,L2BoatInstance> _staticItems = new FastMap<Integer,L2BoatInstance>();
  49. @SuppressWarnings("unused")
  50. private boolean _initialized;
  51. // =========================================================
  52. // Constructor
  53. public BoatManager()
  54. {
  55. }
  56. // =========================================================
  57. // Method - Private
  58. private final void load()
  59. {
  60. _initialized = true;
  61. if(!Config.ALLOW_BOAT)
  62. {
  63. _initialized = false;
  64. return;
  65. }
  66. LineNumberReader lnr = null;
  67. try
  68. {
  69. File doorData = new File(Config.DATAPACK_ROOT, "data/boat.csv");
  70. lnr = new LineNumberReader(new BufferedReader(new FileReader(doorData)));
  71. String line = null;
  72. while ((line = lnr.readLine()) != null)
  73. {
  74. if (line.trim().length() == 0 || line.startsWith("#"))
  75. continue;
  76. L2BoatInstance boat = parseLine(line);
  77. boat.spawn();
  78. _staticItems.put(boat.getObjectId(), boat);
  79. if(Config.DEBUG)
  80. {
  81. _log.info("Boat ID : " + boat.getObjectId());
  82. }
  83. }
  84. }
  85. catch (FileNotFoundException e)
  86. {
  87. _initialized = false;
  88. _log.warning("boat.csv is missing in data folder");
  89. }
  90. catch (Exception e)
  91. {
  92. _initialized = false;
  93. _log.warning("error while creating boat table " + e);
  94. e.printStackTrace();
  95. }
  96. finally
  97. {
  98. try { lnr.close(); } catch (Exception e1) { /* ignore problems */ }
  99. }
  100. }
  101. /**
  102. * @param line
  103. * @return
  104. */
  105. private L2BoatInstance parseLine(String line)
  106. {
  107. L2BoatInstance boat;
  108. StringTokenizer st = new StringTokenizer(line, ";");
  109. String name = st.nextToken();
  110. int id = Integer.parseInt(st.nextToken());
  111. int xspawn = Integer.parseInt(st.nextToken());
  112. int yspawn = Integer.parseInt(st.nextToken());
  113. int zspawn = Integer.parseInt(st.nextToken());
  114. int heading = Integer.parseInt(st.nextToken());
  115. StatsSet npcDat = new StatsSet();
  116. npcDat.set("npcId", id);
  117. npcDat.set("level", 0);
  118. npcDat.set("jClass", "boat");
  119. npcDat.set("baseSTR", 0);
  120. npcDat.set("baseCON", 0);
  121. npcDat.set("baseDEX", 0);
  122. npcDat.set("baseINT", 0);
  123. npcDat.set("baseWIT", 0);
  124. npcDat.set("baseMEN", 0);
  125. npcDat.set("baseShldDef", 0);
  126. npcDat.set("baseShldRate", 0);
  127. npcDat.set("baseAccCombat", 38);
  128. npcDat.set("baseEvasRate", 38);
  129. npcDat.set("baseCritRate", 38);
  130. //npcDat.set("name", "");
  131. npcDat.set("collision_radius", 0);
  132. npcDat.set("collision_height", 0);
  133. npcDat.set("sex", "male");
  134. npcDat.set("type", "");
  135. npcDat.set("baseAtkRange", 0);
  136. npcDat.set("baseMpMax", 0);
  137. npcDat.set("baseCpMax", 0);
  138. npcDat.set("rewardExp", 0);
  139. npcDat.set("rewardSp", 0);
  140. npcDat.set("basePAtk", 0);
  141. npcDat.set("baseMAtk", 0);
  142. npcDat.set("basePAtkSpd", 0);
  143. npcDat.set("aggroRange", 0);
  144. npcDat.set("baseMAtkSpd", 0);
  145. npcDat.set("rhand", 0);
  146. npcDat.set("lhand", 0);
  147. npcDat.set("armor", 0);
  148. npcDat.set("baseWalkSpd", 0);
  149. npcDat.set("baseRunSpd", 0);
  150. npcDat.set("name", name);
  151. npcDat.set("baseHpMax", 50000);
  152. npcDat.set("baseHpReg", 3.e-3f);
  153. npcDat.set("baseMpReg", 3.e-3f);
  154. npcDat.set("basePDef", 100);
  155. npcDat.set("baseMDef", 100);
  156. L2CharTemplate template = new L2CharTemplate(npcDat);
  157. boat = new L2BoatInstance(IdFactory.getInstance().getNextId(),template,name);
  158. boat.getPosition().setHeading(heading);
  159. boat.setXYZ(xspawn,yspawn,zspawn);
  160. //boat.spawnMe();
  161. int IdWaypoint1 = Integer.parseInt(st.nextToken());
  162. int IdWTicket1 = Integer.parseInt(st.nextToken());
  163. int ntx1 = Integer.parseInt(st.nextToken());
  164. int nty1 = Integer.parseInt(st.nextToken());
  165. int ntz1 = Integer.parseInt(st.nextToken());
  166. String npc1 = st.nextToken();
  167. String mess10_1 = st.nextToken();
  168. String mess5_1 = st.nextToken();
  169. String mess1_1 = st.nextToken();
  170. String mess0_1 = st.nextToken();
  171. String messb_1 = st.nextToken();
  172. boat.setTrajet1(IdWaypoint1,IdWTicket1,ntx1,nty1,ntz1,npc1,mess10_1,mess5_1,mess1_1,mess0_1,messb_1);
  173. IdWaypoint1 = Integer.parseInt(st.nextToken());
  174. IdWTicket1 = Integer.parseInt(st.nextToken());
  175. ntx1 = Integer.parseInt(st.nextToken());
  176. nty1 = Integer.parseInt(st.nextToken());
  177. ntz1 = Integer.parseInt(st.nextToken());
  178. npc1 = st.nextToken();
  179. mess10_1 = st.nextToken();
  180. mess5_1 = st.nextToken();
  181. mess1_1 = st.nextToken();
  182. mess0_1 = st.nextToken();
  183. messb_1 = st.nextToken();
  184. boat.setTrajet2(IdWaypoint1,IdWTicket1,ntx1,nty1,ntz1,npc1,mess10_1,mess5_1,mess1_1,mess0_1,messb_1);
  185. return boat;
  186. }
  187. // =========================================================
  188. // Property - Public
  189. /**
  190. * @param boatId
  191. * @return
  192. */
  193. public L2BoatInstance getBoat(int boatId)
  194. {
  195. if (_staticItems == null) _staticItems = new FastMap<Integer,L2BoatInstance>();
  196. return _staticItems.get(boatId);
  197. }
  198. }