PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/Trunk/src/net/sf/odinms/client/MapleQuestStatus.java

https://github.com/system32/NinjaMS
Java | 189 lines | 126 code | 30 blank | 33 comment | 20 complexity | 24586e57d697879ecd28a330dd3aa5f3 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. /*
  19. * MapleQuestStatus.java
  20. *
  21. * Created on 11. Dezember 2007, 23:24
  22. *
  23. * To change this template, choose Tools | Template Manager
  24. * and open the template in the editor.
  25. */
  26. package net.sf.odinms.client;
  27. import java.util.Collections;
  28. import java.util.LinkedHashMap;
  29. import java.util.List;
  30. import java.util.Map;
  31. import net.sf.odinms.server.quest.MapleQuest;
  32. import net.sf.odinms.tools.StringUtil;
  33. /**
  34. *
  35. * @author Matze
  36. */
  37. public class MapleQuestStatus {
  38. public enum Status {
  39. UNDEFINED(-1),
  40. NOT_STARTED(0),
  41. STARTED(1),
  42. COMPLETED(2);
  43. final int status;
  44. private Status(int id) {
  45. status = id;
  46. }
  47. public int getId() {
  48. return status;
  49. }
  50. public static Status getById(int id) {
  51. for (Status l : Status.values()) {
  52. if (l.getId() == id) {
  53. return l;
  54. }
  55. }
  56. return null;
  57. }
  58. }
  59. private MapleQuest quest;
  60. private Status status;
  61. private Map<Integer,Integer> killedMobs = new LinkedHashMap<Integer,Integer>();
  62. private int npc;
  63. private long completionTime;
  64. private int forfeited = 0;
  65. /** Creates a new instance of MapleQuestStatus */
  66. public MapleQuestStatus(MapleQuest quest, Status status) {
  67. this.quest = quest;
  68. this.setStatus(status);
  69. this.completionTime = System.currentTimeMillis();
  70. if (status == Status.STARTED)
  71. registerMobs();
  72. }
  73. public MapleQuestStatus(MapleQuest quest, Status status, int npc) {
  74. this.quest = quest;
  75. this.setStatus(status);
  76. this.setNpc(npc);
  77. this.completionTime = System.currentTimeMillis();
  78. if (status == Status.STARTED)
  79. registerMobs();
  80. }
  81. public MapleQuest getQuest() {
  82. return quest;
  83. }
  84. public Status getStatus() {
  85. return status;
  86. }
  87. public void setStatus(Status status) {
  88. this.status = status;
  89. }
  90. public int getNpc() {
  91. return npc;
  92. }
  93. public void setNpc(int npc) {
  94. this.npc = npc;
  95. }
  96. private void registerMobs() {
  97. List<Integer> relevants = quest.getRelevantMobs();
  98. for (int i : relevants) {
  99. killedMobs.put(i, 0);
  100. }
  101. }
  102. public boolean mobKilled(int id) {
  103. if (killedMobs.get(id) != null) {
  104. killedMobs.put(id, killedMobs.get(id) + 1);
  105. return true;
  106. }
  107. return false;
  108. }
  109. public void setMobKills(int id, int count) {
  110. killedMobs.put(id, count);
  111. }
  112. public boolean hasMobKills() {
  113. return killedMobs.size() > 0;
  114. }
  115. public int getMobKills(int id) {
  116. if (killedMobs.get(id) == null) return 0;
  117. return killedMobs.get(id);
  118. }
  119. public Map<Integer,Integer> getMobKills() {
  120. return Collections.unmodifiableMap(killedMobs);
  121. }
  122. public int getMobNum(int id) {
  123. int i = 0;
  124. for (int kMob : killedMobs.values()) {
  125. i++;
  126. if (kMob == id) return i;
  127. }
  128. return i;
  129. }
  130. public long getCompletionTime() {
  131. return completionTime;
  132. }
  133. public void setCompletionTime(long completionTime) {
  134. this.completionTime = completionTime;
  135. }
  136. public int getForfeited() {
  137. return forfeited;
  138. }
  139. public void setForfeited(int forfeited) {
  140. if (forfeited >= this.forfeited) {
  141. this.forfeited = forfeited;
  142. } else {
  143. throw new IllegalArgumentException("Can't set forfeits to something lower than before.");
  144. }
  145. }
  146. public String getQuestData() {
  147. if (killedMobs.size() == 0) {
  148. return "";
  149. }
  150. StringBuilder str = new StringBuilder();
  151. for (Integer mob : killedMobs.values()) {
  152. str.append(StringUtil.getLeftPaddedStr(mob.toString(), '\30', 3));
  153. }
  154. return str.toString();
  155. }
  156. }