PageRenderTime 37ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/Trunk/src/net/sf/odinms/server/maps/MapleReactorFactory.java

https://github.com/system32/NinjaMS
Java | 92 lines | 60 code | 7 blank | 25 comment | 17 complexity | 694b2b856f2de1197fc69f8f26c8756b MD5 | raw file
Possible License(s): AGPL-3.0
  1. /*
  2. This file is part of the OdinMS Maple Story Server
  3. Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
  4. Matthias Butz <matze@odinms.de>
  5. Jan Christian Meyer <vimes@odinms.de>
  6. This program is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU Affero General Public License version 3
  8. as published by the Free Software Foundation. You may not use, modify
  9. or distribute this program under any other version of the
  10. GNU Affero General Public License.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU Affero General Public License for more details.
  15. You should have received a copy of the GNU Affero General Public License
  16. along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. package net.sf.odinms.server.maps;
  19. /**
  20. *
  21. * @author Lerk
  22. */
  23. import java.io.File;
  24. import java.util.HashMap;
  25. import java.util.Map;
  26. import net.sf.odinms.provider.MapleData;
  27. import net.sf.odinms.provider.MapleDataProvider;
  28. import net.sf.odinms.provider.MapleDataProviderFactory;
  29. import net.sf.odinms.provider.MapleDataTool;
  30. import net.sf.odinms.tools.Pair;
  31. import net.sf.odinms.tools.StringUtil;
  32. public class MapleReactorFactory {
  33. //private static Logger log = LoggerFactory.getLogger(MapleReactorFactory.class);
  34. private static MapleDataProvider data = MapleDataProviderFactory.getDataProvider(new File(System.getProperty("net.sf.odinms.wzpath") + "/Reactor.wz"));
  35. private static Map<Integer, MapleReactorStats> reactorStats = new HashMap<Integer, MapleReactorStats>();
  36. public static MapleReactorStats getReactor(int rid) {
  37. MapleReactorStats stats = reactorStats.get(Integer.valueOf(rid));
  38. if (stats == null) {
  39. int infoId = rid;
  40. MapleData reactorData = data.getData(StringUtil.getLeftPaddedStr(Integer.toString(infoId) + ".img", '0', 11));
  41. MapleData link = reactorData.getChildByPath("info/link");
  42. if (link != null) {
  43. infoId = MapleDataTool.getIntConvert("info/link",reactorData);
  44. stats = reactorStats.get(Integer.valueOf(infoId));
  45. }
  46. if (stats == null) {
  47. reactorData = data.getData(StringUtil.getLeftPaddedStr(Integer.toString(infoId) + ".img", '0', 11));
  48. MapleData reactorInfoData = reactorData.getChildByPath("0/event/0");
  49. stats = new MapleReactorStats();
  50. if (reactorInfoData != null) {
  51. boolean areaSet = false;
  52. int i = 0;
  53. while (reactorInfoData != null) {
  54. Pair<Integer,Integer> reactItem = null;
  55. int type = MapleDataTool.getIntConvert("type",reactorInfoData);
  56. if (type == 100) { //reactor waits for item
  57. reactItem = new Pair<Integer,Integer>(MapleDataTool.getIntConvert("0",reactorInfoData),MapleDataTool.getIntConvert("1",reactorInfoData));
  58. if (!areaSet) { //only set area of effect for item-triggered reactors once
  59. stats.setTL(MapleDataTool.getPoint("lt",reactorInfoData));
  60. stats.setBR(MapleDataTool.getPoint("rb",reactorInfoData));
  61. areaSet = true;
  62. }
  63. }
  64. byte nextState = (byte)MapleDataTool.getIntConvert("state",reactorInfoData);
  65. stats.addState((byte) i, type, reactItem, nextState);
  66. i++;
  67. reactorInfoData = reactorData.getChildByPath(i + "/event/0");
  68. }
  69. } else { //sit there and look pretty; likely a reactor such as Zakum/Papulatus doors that shows if player can enter
  70. stats.addState((byte) 0, 999, null, (byte) 0);
  71. }
  72. reactorStats.put(Integer.valueOf(infoId), stats);
  73. if (rid != infoId) {
  74. reactorStats.put(Integer.valueOf(rid), stats);
  75. }
  76. } else { // stats exist at infoId but not rid; add to map
  77. reactorStats.put(Integer.valueOf(rid), stats);
  78. }
  79. }
  80. return stats;
  81. }
  82. }