PlayerBuffStorage.java
Upload User: gwt600
Upload Date: 2021-06-03
Package Size: 704k
Code Size: 4k
Category:

Games

Development Platform:

Java

  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.  * To change this template, choose Tools | Templates
  20.  * and open the template in the editor.
  21.  */
  22. package net.sf.odinms.net.world;
  23. import java.io.Serializable;
  24. import java.util.ArrayList;
  25. import java.util.List;
  26. import net.sf.odinms.tools.Pair;
  27. import org.slf4j.Logger;
  28. import org.slf4j.LoggerFactory;
  29. /**
  30.  *
  31.  * @author Danny
  32.  */
  33. @SuppressWarnings("serial")
  34. public class PlayerBuffStorage implements Serializable {
  35. private List<Pair<Integer, List<PlayerBuffValueHolder>>> buffs = new ArrayList<Pair<Integer, List<PlayerBuffValueHolder>>>();
  36. private List<Pair<Integer, List<PlayerCoolDownValueHolder>>> coolDowns = new ArrayList<Pair<Integer, List<PlayerCoolDownValueHolder>>>();
  37. private int id = (int) (Math.random()*100);
  38. @SuppressWarnings("unused")
  39. public PlayerBuffStorage() {
  40. // Empty constructor
  41. }
  42. public void addBuffsToStorage(int chrid, List<PlayerBuffValueHolder> toStore) {
  43. for (Pair<Integer, List<PlayerBuffValueHolder>> stored : buffs) {
  44. if (stored.getLeft() == Integer.valueOf(chrid)) {
  45. buffs.remove(stored);
  46. }
  47. }
  48. buffs.add(new Pair<Integer, List<PlayerBuffValueHolder>>(Integer.valueOf(chrid), toStore));
  49. }
  50. public void addCooldownsToStorage(int chrid, List<PlayerCoolDownValueHolder> toStore) {
  51. for (Pair<Integer, List<PlayerCoolDownValueHolder>> stored : coolDowns) {
  52. if (stored.getLeft() == Integer.valueOf(chrid)) {
  53. coolDowns.remove(stored);
  54. }
  55. }
  56. coolDowns.add(new Pair<Integer, List<PlayerCoolDownValueHolder>>(Integer.valueOf(chrid), toStore));
  57. }
  58. public List<PlayerBuffValueHolder> getBuffsFromStorage(int chrid) {
  59. List<PlayerBuffValueHolder> ret = null;
  60. Pair<Integer, List<PlayerBuffValueHolder>> stored;
  61. for (int i = 0; i < buffs.size(); i++) {
  62. stored = buffs.get(i);
  63. if (stored.getLeft().equals(Integer.valueOf(chrid))) {
  64. ret = stored.getRight();
  65. buffs.remove(stored);
  66. }
  67. }
  68. return ret;
  69. }
  70. public List<PlayerCoolDownValueHolder> getCooldownsFromStorage(int chrid) {
  71. List<PlayerCoolDownValueHolder> ret = null;
  72. Pair<Integer, List<PlayerCoolDownValueHolder>> stored;
  73. for (int i = 0; i < coolDowns.size(); i++) {
  74. stored = coolDowns.get(i);
  75. if (stored.getLeft().equals(Integer.valueOf(chrid))) {
  76. ret = stored.getRight();
  77. coolDowns.remove(stored);
  78. }
  79. }
  80. return ret;
  81. }
  82. @Override
  83. public int hashCode() {
  84. final int prime = 31;
  85. int result = 1;
  86. result = prime * result + id;
  87. return result;
  88. }
  89. @Override
  90. public boolean equals(Object obj) {
  91. if (this == obj)
  92. return true;
  93. if (obj == null)
  94. return false;
  95. if (getClass() != obj.getClass())
  96. return false;
  97. final PlayerBuffStorage other = (PlayerBuffStorage) obj;
  98. if (id != other.id)
  99. return false;
  100. return true;
  101. }
  102. }