TransformationManager.java 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 net.sf.l2j.gameserver.instancemanager;
  16. import java.util.Collection;
  17. import java.util.Map;
  18. import java.util.logging.Logger;
  19. import javolution.util.FastMap;
  20. import net.sf.l2j.gameserver.model.L2Transformation;
  21. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  22. /**
  23. *
  24. * @author KenM
  25. */
  26. public class TransformationManager
  27. {
  28. private static final Logger _log = Logger.getLogger(TransformationManager.class.getName());
  29. private static final TransformationManager INSTANCE = new TransformationManager();
  30. public static TransformationManager getInstance()
  31. {
  32. return INSTANCE;
  33. }
  34. private Map<Integer, L2Transformation> _transformations;
  35. private TransformationManager()
  36. {
  37. _transformations = new FastMap<Integer, L2Transformation>();
  38. }
  39. public void report()
  40. {
  41. _log.info("Loaded: "+this.getAllTransformations().size()+" transformations.");
  42. }
  43. public boolean transformPlayer(int id, L2PcInstance player)
  44. {
  45. L2Transformation template = this.getTransformationById(id);
  46. if (template != null)
  47. {
  48. L2Transformation trans = template.createTransformationForPlayer(player);
  49. trans.start();
  50. return true;
  51. }
  52. else
  53. {
  54. return false;
  55. }
  56. }
  57. public boolean transformPlayer(int id, L2PcInstance player, long forceDuration)
  58. {
  59. L2Transformation template = this.getTransformationById(id);
  60. if (template != null)
  61. {
  62. L2Transformation trans = template.createTransformationForPlayer(player);
  63. trans.setDuration(forceDuration);
  64. trans.start();
  65. return true;
  66. }
  67. else
  68. {
  69. return false;
  70. }
  71. }
  72. public L2Transformation getTransformationById(int id)
  73. {
  74. return _transformations.get(id);
  75. }
  76. public L2Transformation registerTransformation(L2Transformation transformation)
  77. {
  78. return _transformations.put(transformation.getId() , transformation);
  79. }
  80. public Collection<L2Transformation> getAllTransformations()
  81. {
  82. return _transformations.values();
  83. }
  84. }