BoatManager.java 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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
  99. {
  100. lnr.close();
  101. }
  102. catch (Exception e1)
  103. { /* ignore problems */
  104. }
  105. }
  106. }
  107. /**
  108. * @param line
  109. * @return
  110. */
  111. private L2BoatInstance parseLine(String line)
  112. {
  113. L2BoatInstance boat;
  114. StringTokenizer st = new StringTokenizer(line, ";");
  115. String name = st.nextToken();
  116. int id = Integer.parseInt(st.nextToken());
  117. int xspawn = Integer.parseInt(st.nextToken());
  118. int yspawn = Integer.parseInt(st.nextToken());
  119. int zspawn = Integer.parseInt(st.nextToken());
  120. int heading = Integer.parseInt(st.nextToken());
  121. StatsSet npcDat = new StatsSet();
  122. npcDat.set("npcId", id);
  123. npcDat.set("level", 0);
  124. npcDat.set("jClass", "boat");
  125. npcDat.set("baseSTR", 0);
  126. npcDat.set("baseCON", 0);
  127. npcDat.set("baseDEX", 0);
  128. npcDat.set("baseINT", 0);
  129. npcDat.set("baseWIT", 0);
  130. npcDat.set("baseMEN", 0);
  131. npcDat.set("baseShldDef", 0);
  132. npcDat.set("baseShldRate", 0);
  133. npcDat.set("baseAccCombat", 38);
  134. npcDat.set("baseEvasRate", 38);
  135. npcDat.set("baseCritRate", 38);
  136. // npcDat.set("name", "");
  137. npcDat.set("collision_radius", 0);
  138. npcDat.set("collision_height", 0);
  139. npcDat.set("sex", "male");
  140. npcDat.set("type", "");
  141. npcDat.set("baseAtkRange", 0);
  142. npcDat.set("baseMpMax", 0);
  143. npcDat.set("baseCpMax", 0);
  144. npcDat.set("rewardExp", 0);
  145. npcDat.set("rewardSp", 0);
  146. npcDat.set("basePAtk", 0);
  147. npcDat.set("baseMAtk", 0);
  148. npcDat.set("basePAtkSpd", 0);
  149. npcDat.set("aggroRange", 0);
  150. npcDat.set("baseMAtkSpd", 0);
  151. npcDat.set("rhand", 0);
  152. npcDat.set("lhand", 0);
  153. npcDat.set("armor", 0);
  154. npcDat.set("baseWalkSpd", 0);
  155. npcDat.set("baseRunSpd", 0);
  156. npcDat.set("name", name);
  157. npcDat.set("baseHpMax", 50000);
  158. npcDat.set("baseHpReg", 3.e-3f);
  159. npcDat.set("baseMpReg", 3.e-3f);
  160. npcDat.set("basePDef", 100);
  161. npcDat.set("baseMDef", 100);
  162. L2CharTemplate template = new L2CharTemplate(npcDat);
  163. boat = new L2BoatInstance(IdFactory.getInstance().getNextId(), template, name);
  164. boat.getPosition().setHeading(heading);
  165. boat.setXYZ(xspawn, yspawn, zspawn);
  166. boat.setId(id);
  167. // boat.spawnMe();
  168. int IdWaypoint1 = Integer.parseInt(st.nextToken());
  169. int IdWTicket1 = Integer.parseInt(st.nextToken());
  170. int ntx1 = Integer.parseInt(st.nextToken());
  171. int nty1 = Integer.parseInt(st.nextToken());
  172. int ntz1 = Integer.parseInt(st.nextToken());
  173. String npc1 = st.nextToken();
  174. String mess10_1 = st.nextToken();
  175. String mess5_1 = st.nextToken();
  176. String mess1_1 = st.nextToken();
  177. String mess0_1 = st.nextToken();
  178. String messb_1 = st.nextToken();
  179. boat.setTrajet1(IdWaypoint1, IdWTicket1, ntx1, nty1, ntz1, npc1, mess10_1, mess5_1, mess1_1, mess0_1, messb_1);
  180. IdWaypoint1 = Integer.parseInt(st.nextToken());
  181. IdWTicket1 = Integer.parseInt(st.nextToken());
  182. ntx1 = Integer.parseInt(st.nextToken());
  183. nty1 = Integer.parseInt(st.nextToken());
  184. ntz1 = Integer.parseInt(st.nextToken());
  185. npc1 = st.nextToken();
  186. mess10_1 = st.nextToken();
  187. mess5_1 = st.nextToken();
  188. mess1_1 = st.nextToken();
  189. mess0_1 = st.nextToken();
  190. messb_1 = st.nextToken();
  191. boat.setTrajet2(IdWaypoint1, IdWTicket1, ntx1, nty1, ntz1, npc1, mess10_1, mess5_1, mess1_1, mess0_1, messb_1);
  192. return boat;
  193. }
  194. // =========================================================
  195. // Property - Public
  196. /**
  197. * @param boatId
  198. * @return
  199. */
  200. public L2BoatInstance getBoat(int boatId)
  201. {
  202. if (_staticItems == null)
  203. _staticItems = new FastMap<Integer, L2BoatInstance>();
  204. return _staticItems.get(boatId);
  205. }
  206. }