RollingDice.java 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 handlers.itemhandlers;
  16. import com.l2jserver.gameserver.handler.IItemHandler;
  17. import com.l2jserver.gameserver.model.actor.L2Character;
  18. import com.l2jserver.gameserver.model.actor.L2Playable;
  19. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  20. import com.l2jserver.gameserver.model.item.instance.L2ItemInstance;
  21. import com.l2jserver.gameserver.network.SystemMessageId;
  22. import com.l2jserver.gameserver.network.serverpackets.Dice;
  23. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  24. import com.l2jserver.gameserver.util.Broadcast;
  25. import com.l2jserver.util.Rnd;
  26. /**
  27. * This class ...
  28. *
  29. * @version $Revision: 1.1.4.2 $ $Date: 2005/03/27 15:30:07 $
  30. */
  31. public class RollingDice implements IItemHandler
  32. {
  33. /**
  34. *
  35. * @see com.l2jserver.gameserver.handler.IItemHandler#useItem(com.l2jserver.gameserver.model.actor.L2Playable, com.l2jserver.gameserver.model.L2ItemInstance, boolean)
  36. */
  37. public void useItem(L2Playable playable, L2ItemInstance item, boolean forceUse)
  38. {
  39. if (!(playable instanceof L2PcInstance))
  40. return;
  41. L2PcInstance activeChar = (L2PcInstance) playable;
  42. int itemId = item.getItemId();
  43. if (activeChar.isInOlympiadMode())
  44. {
  45. activeChar.sendPacket(SystemMessageId.THIS_ITEM_IS_NOT_AVAILABLE_FOR_THE_OLYMPIAD_EVENT);
  46. return;
  47. }
  48. if (itemId == 4625 || itemId == 4626 || itemId == 4627 || itemId == 4628)
  49. {
  50. int number = rollDice(activeChar);
  51. if (number == 0)
  52. {
  53. activeChar.sendPacket(SystemMessageId.YOU_MAY_NOT_THROW_THE_DICE_AT_THIS_TIME_TRY_AGAIN_LATER);
  54. return;
  55. }
  56. Broadcast.toSelfAndKnownPlayers(activeChar, new Dice(activeChar.getObjectId(), item.getItemId(), number, activeChar.getX() - 30, activeChar.getY() - 30, activeChar.getZ()));
  57. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_ROLLED_S2);
  58. sm.addString(activeChar.getName());
  59. sm.addNumber(number);
  60. activeChar.sendPacket(sm);
  61. if (activeChar.isInsideZone(L2Character.ZONE_PEACE))
  62. Broadcast.toKnownPlayers(activeChar, sm);
  63. else if (activeChar.isInParty())
  64. activeChar.getParty().broadcastToPartyMembers(activeChar, sm);
  65. }
  66. }
  67. /**
  68. *
  69. * @param player
  70. * @return
  71. */
  72. private int rollDice(L2PcInstance player)
  73. {
  74. // Check if the dice is ready
  75. if (!player.getFloodProtectors().getRollDice().
  76. tryPerformAction("roll dice"))
  77. {
  78. return 0;
  79. }
  80. return Rnd.get(1, 6);
  81. }
  82. }