SeedProduction.java 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright (C) 2004-2015 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 java.util.concurrent.atomic.AtomicLong;
  21. /**
  22. * @author xban1x
  23. */
  24. public class SeedProduction
  25. {
  26. private final int _seedId;
  27. private final long _price;
  28. private final long _startAmount;
  29. private final AtomicLong _amount;
  30. public SeedProduction(int id, long amount, long price, long startAmount)
  31. {
  32. _seedId = id;
  33. _amount = new AtomicLong(amount);
  34. _price = price;
  35. _startAmount = startAmount;
  36. }
  37. public final int getId()
  38. {
  39. return _seedId;
  40. }
  41. public final long getAmount()
  42. {
  43. return _amount.get();
  44. }
  45. public final long getPrice()
  46. {
  47. return _price;
  48. }
  49. public final long getStartAmount()
  50. {
  51. return _startAmount;
  52. }
  53. public final void setAmount(long amount)
  54. {
  55. _amount.set(amount);
  56. }
  57. public final boolean decreaseAmount(long val)
  58. {
  59. long current, next;
  60. do
  61. {
  62. current = _amount.get();
  63. next = current - val;
  64. if (next < 0)
  65. {
  66. return false;
  67. }
  68. }
  69. while (!_amount.compareAndSet(current, next));
  70. return true;
  71. }
  72. }