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 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.Map;
  22. import java.util.StringTokenizer;
  23. import java.util.logging.Logger;
  24. import com.l2jserver.Config;
  25. import com.l2jserver.gameserver.idfactory.IdFactory;
  26. import com.l2jserver.gameserver.model.actor.instance.L2BoatInstance;
  27. import com.l2jserver.gameserver.templates.StatsSet;
  28. import com.l2jserver.gameserver.templates.chars.L2CharTemplate;
  29. import javolution.util.FastMap;
  30. public class BoatManager
  31. {
  32. private static final Logger _log = Logger.getLogger(BoatManager.class.getName());
  33. public static final BoatManager getInstance()
  34. {
  35. return SingletonHolder._instance;
  36. }
  37. // =========================================================
  38. // =========================================================
  39. // Data Field
  40. private Map<Integer, L2BoatInstance> _staticItems = new FastMap<Integer, L2BoatInstance>();
  41. @SuppressWarnings("unused")
  42. private boolean _initialized;
  43. // =========================================================
  44. // Constructor
  45. private BoatManager()
  46. {
  47. _log.info("Initializing BoatManager");
  48. load();
  49. }
  50. // =========================================================
  51. // Method - Private
  52. private final void load()
  53. {
  54. _initialized = true;
  55. if (!Config.ALLOW_BOAT)
  56. {
  57. _initialized = false;
  58. return;
  59. }
  60. LineNumberReader lnr = null;
  61. try
  62. {
  63. File doorData = new File(Config.DATAPACK_ROOT, "data/boat.csv");
  64. lnr = new LineNumberReader(new BufferedReader(new FileReader(doorData)));
  65. String line = null;
  66. while ((line = lnr.readLine()) != null)
  67. {
  68. if (line.trim().length() == 0 || line.startsWith("#"))
  69. continue;
  70. L2BoatInstance boat = parseLine(line);
  71. boat.spawn();
  72. _staticItems.put(boat.getObjectId(), boat);
  73. if (Config.DEBUG)
  74. {
  75. _log.info("Boat ID : " + boat.getObjectId());
  76. }
  77. }
  78. }
  79. catch (FileNotFoundException e)
  80. {
  81. _initialized = false;
  82. _log.warning("boat.csv is missing in data folder");
  83. }
  84. catch (Exception e)
  85. {
  86. _initialized = false;
  87. _log.warning("error while creating boat table " + e);
  88. e.printStackTrace();
  89. }
  90. finally
  91. {
  92. try
  93. {
  94. lnr.close();
  95. }
  96. catch (Exception e1)
  97. { /* ignore problems */
  98. }
  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.setId(id);
  161. // boat.spawnMe();
  162. int IdWaypoint1 = Integer.parseInt(st.nextToken());
  163. int IdWTicket1 = Integer.parseInt(st.nextToken());
  164. int ntx1 = Integer.parseInt(st.nextToken());
  165. int nty1 = Integer.parseInt(st.nextToken());
  166. int ntz1 = Integer.parseInt(st.nextToken());
  167. String npc1 = st.nextToken();
  168. String mess10_1 = st.nextToken();
  169. String mess5_1 = st.nextToken();
  170. String mess1_1 = st.nextToken();
  171. String mess0_1 = st.nextToken();
  172. String messb_1 = st.nextToken();
  173. boat.setTrajet1(IdWaypoint1, IdWTicket1, ntx1, nty1, ntz1, npc1, mess10_1, mess5_1, mess1_1, mess0_1, messb_1);
  174. IdWaypoint1 = Integer.parseInt(st.nextToken());
  175. IdWTicket1 = Integer.parseInt(st.nextToken());
  176. ntx1 = Integer.parseInt(st.nextToken());
  177. nty1 = Integer.parseInt(st.nextToken());
  178. ntz1 = Integer.parseInt(st.nextToken());
  179. npc1 = st.nextToken();
  180. mess10_1 = st.nextToken();
  181. mess5_1 = st.nextToken();
  182. mess1_1 = st.nextToken();
  183. mess0_1 = st.nextToken();
  184. messb_1 = st.nextToken();
  185. boat.setTrajet2(IdWaypoint1, IdWTicket1, ntx1, nty1, ntz1, npc1, mess10_1, mess5_1, mess1_1, mess0_1, messb_1);
  186. return boat;
  187. }
  188. // =========================================================
  189. // Property - Public
  190. /**
  191. * @param boatId
  192. * @return
  193. */
  194. public L2BoatInstance getBoat(int boatId)
  195. {
  196. if (_staticItems == null)
  197. _staticItems = new FastMap<Integer, L2BoatInstance>();
  198. return _staticItems.get(boatId);
  199. }
  200. @SuppressWarnings("synthetic-access")
  201. private static class SingletonHolder
  202. {
  203. protected static final BoatManager _instance = new BoatManager();
  204. }
  205. }