L2Crest.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * Copyright (C) 2004-2014 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server 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 GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.model;
  20. import com.l2jserver.Config;
  21. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  22. import com.l2jserver.gameserver.model.interfaces.IIdentifiable;
  23. import com.l2jserver.gameserver.network.serverpackets.AllyCrest;
  24. import com.l2jserver.gameserver.network.serverpackets.ExPledgeCrestLarge;
  25. import com.l2jserver.gameserver.network.serverpackets.PledgeCrest;
  26. /**
  27. * @author Nos
  28. */
  29. public final class L2Crest implements IIdentifiable
  30. {
  31. public enum CrestType
  32. {
  33. PLEDGE(1),
  34. PLEDGE_LARGE(2),
  35. ALLY(3);
  36. private final int _id;
  37. private CrestType(int id)
  38. {
  39. _id = id;
  40. }
  41. public int getId()
  42. {
  43. return _id;
  44. }
  45. public static CrestType getById(int id)
  46. {
  47. for (CrestType crestType : values())
  48. {
  49. if (crestType.getId() == id)
  50. {
  51. return crestType;
  52. }
  53. }
  54. return null;
  55. }
  56. }
  57. private final int _id;
  58. private final byte[] _data;
  59. private final CrestType _type;
  60. public L2Crest(int id, byte[] data, CrestType type)
  61. {
  62. _id = id;
  63. _data = data;
  64. _type = type;
  65. }
  66. @Override
  67. public int getId()
  68. {
  69. return _id;
  70. }
  71. public byte[] getData()
  72. {
  73. return _data;
  74. }
  75. public CrestType getType()
  76. {
  77. return _type;
  78. }
  79. /**
  80. * Gets the client path to crest for use in html and sends the crest to {@code L2PcInstance}
  81. * @param activeChar the @{code L2PcInstance} where html is send to.
  82. * @return the client path to crest
  83. */
  84. public String getClientPath(L2PcInstance activeChar)
  85. {
  86. String path = null;
  87. switch (getType())
  88. {
  89. case PLEDGE:
  90. {
  91. activeChar.sendPacket(new PledgeCrest(getId(), getData()));
  92. path = "Crest.crest_" + Config.SERVER_ID + "_" + getId();
  93. break;
  94. }
  95. case PLEDGE_LARGE:
  96. {
  97. activeChar.sendPacket(new ExPledgeCrestLarge(getId(), getData()));
  98. path = "Crest.crest_" + Config.SERVER_ID + "_" + getId() + "_l";
  99. break;
  100. }
  101. case ALLY:
  102. {
  103. activeChar.sendPacket(new AllyCrest(getId(), getData()));
  104. path = "Crest.crest_" + Config.SERVER_ID + "_" + getId();
  105. break;
  106. }
  107. }
  108. return path;
  109. }
  110. }