StaticObjects.java 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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.datatables;
  16. import gnu.trove.TIntObjectHashMap;
  17. import java.io.BufferedReader;
  18. import java.io.File;
  19. import java.io.FileNotFoundException;
  20. import java.io.FileReader;
  21. import java.io.LineNumberReader;
  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.L2StaticObjectInstance;
  27. import com.l2jserver.gameserver.templates.StatsSet;
  28. import com.l2jserver.gameserver.templates.chars.L2CharTemplate;
  29. public class StaticObjects
  30. {
  31. private static Logger _log = Logger.getLogger(StaticObjects.class.getName());
  32. private TIntObjectHashMap<L2StaticObjectInstance> _staticObjects;
  33. public static StaticObjects getInstance()
  34. {
  35. return SingletonHolder._instance;
  36. }
  37. private StaticObjects()
  38. {
  39. _staticObjects = new TIntObjectHashMap<L2StaticObjectInstance>();
  40. parseData();
  41. _log.config("StaticObject: Loaded " + _staticObjects.size() + " StaticObject Templates.");
  42. }
  43. private void parseData()
  44. {
  45. LineNumberReader lnr = null;
  46. try
  47. {
  48. File doorData = new File(Config.DATAPACK_ROOT, "data/staticobjects.csv");
  49. lnr = new LineNumberReader(new BufferedReader(new FileReader(doorData)));
  50. String line = null;
  51. while ((line = lnr.readLine()) != null)
  52. {
  53. if (line.trim().length() == 0 || line.startsWith("#"))
  54. continue;
  55. L2StaticObjectInstance obj = parse(line);
  56. _staticObjects.put(obj.getStaticObjectId(), obj);
  57. }
  58. }
  59. catch (FileNotFoundException e)
  60. {
  61. _log.warning("staticobjects.csv is missing in data folder");
  62. }
  63. catch (Exception e)
  64. {
  65. _log.warning("error while creating StaticObjects table " + e);
  66. }
  67. finally
  68. {
  69. try
  70. {
  71. lnr.close();
  72. }
  73. catch (Exception e)
  74. {
  75. }
  76. }
  77. }
  78. public static L2StaticObjectInstance parse(String line)
  79. {
  80. StringTokenizer st = new StringTokenizer(line, ";");
  81. st.nextToken(); //Pass over static object name (not used in server)
  82. int id = Integer.parseInt(st.nextToken());
  83. int x = Integer.parseInt(st.nextToken());
  84. int y = Integer.parseInt(st.nextToken());
  85. int z = Integer.parseInt(st.nextToken());
  86. int type = Integer.parseInt(st.nextToken());
  87. String texture = st.nextToken();
  88. int map_x = Integer.parseInt(st.nextToken());
  89. int map_y = Integer.parseInt(st.nextToken());
  90. StatsSet npcDat = new StatsSet();
  91. npcDat.set("npcId", id);
  92. npcDat.set("level", 0);
  93. npcDat.set("jClass", "staticobject");
  94. npcDat.set("baseSTR", 0);
  95. npcDat.set("baseCON", 0);
  96. npcDat.set("baseDEX", 0);
  97. npcDat.set("baseINT", 0);
  98. npcDat.set("baseWIT", 0);
  99. npcDat.set("baseMEN", 0);
  100. npcDat.set("baseShldDef", 0);
  101. npcDat.set("baseShldRate", 0);
  102. npcDat.set("baseAccCombat", 38);
  103. npcDat.set("baseEvasRate", 38);
  104. npcDat.set("baseCritRate", 38);
  105. //npcDat.set("name", "");
  106. npcDat.set("collision_radius", 10);
  107. npcDat.set("collision_height", 10);
  108. npcDat.set("sex", "male");
  109. npcDat.set("type", "");
  110. npcDat.set("baseAtkRange", 0);
  111. npcDat.set("baseMpMax", 0);
  112. npcDat.set("baseCpMax", 0);
  113. npcDat.set("rewardExp", 0);
  114. npcDat.set("rewardSp", 0);
  115. npcDat.set("basePAtk", 0);
  116. npcDat.set("baseMAtk", 0);
  117. npcDat.set("basePAtkSpd", 0);
  118. npcDat.set("aggroRange", 0);
  119. npcDat.set("baseMAtkSpd", 0);
  120. npcDat.set("rhand", 0);
  121. npcDat.set("lhand", 0);
  122. npcDat.set("armor", 0);
  123. npcDat.set("baseWalkSpd", 0);
  124. npcDat.set("baseRunSpd", 0);
  125. npcDat.set("name", "");
  126. npcDat.set("baseHpMax", 1);
  127. npcDat.set("baseHpReg", 3.e-3f);
  128. npcDat.set("baseMpReg", 3.e-3f);
  129. npcDat.set("basePDef", 1);
  130. npcDat.set("baseMDef", 1);
  131. L2CharTemplate template = new L2CharTemplate(npcDat);
  132. L2StaticObjectInstance obj = new L2StaticObjectInstance(IdFactory.getInstance().getNextId(), template, id);
  133. obj.setType(type);
  134. obj.setXYZ(x, y, z);
  135. obj.setMap(texture, map_x, map_y);
  136. obj.spawnMe();
  137. return obj;
  138. }
  139. public void putObject(L2StaticObjectInstance obj)
  140. {
  141. _staticObjects.put(obj.getStaticObjectId(), obj);
  142. }
  143. @SuppressWarnings("synthetic-access")
  144. private static class SingletonHolder
  145. {
  146. protected static final StaticObjects _instance = new StaticObjects();
  147. }
  148. }