ExpiresComponent.cs 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #region File description
  2. // --------------------------------------------------------------------------------------------------------------------
  3. // <copyright file="ExpiresComponent.cs" company="GAMADU.COM">
  4. // Copyright © 2013 GAMADU.COM. All rights reserved.
  5. //
  6. // Redistribution and use in source and binary forms, with or without modification, are
  7. // permitted provided that the following conditions are met:
  8. //
  9. // 1. Redistributions of source code must retain the above copyright notice, this list of
  10. // conditions and the following disclaimer.
  11. //
  12. // 2. Redistributions in binary form must reproduce the above copyright notice, this list
  13. // of conditions and the following disclaimer in the documentation and/or other materials
  14. // provided with the distribution.
  15. //
  16. // THIS SOFTWARE IS PROVIDED BY GAMADU.COM 'AS IS' AND ANY EXPRESS OR IMPLIED
  17. // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  18. // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GAMADU.COM OR
  19. // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  20. // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  22. // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  23. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  24. // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. //
  26. // The views and conclusions contained in the software and documentation are those of the
  27. // authors and should not be interpreted as representing official policies, either expressed
  28. // or implied, of GAMADU.COM.
  29. // </copyright>
  30. // <summary>
  31. // The expires.
  32. // </summary>
  33. // --------------------------------------------------------------------------------------------------------------------
  34. #endregion File description
  35. namespace StarWarrior.Components
  36. {
  37. #region Using statements
  38. using Artemis.Interface;
  39. #endregion
  40. /// <summary>The expires.</summary>
  41. internal class ExpiresComponent : IComponent
  42. {
  43. /// <summary>Initializes a new instance of the <see cref="ExpiresComponent" /> class.</summary>
  44. public ExpiresComponent()
  45. : this(0.0f)
  46. {
  47. }
  48. /// <summary>Initializes a new instance of the <see cref="ExpiresComponent" /> class.</summary>
  49. /// <param name="lifeTime">The life time.</param>
  50. public ExpiresComponent(float lifeTime)
  51. {
  52. this.LifeTime = lifeTime;
  53. }
  54. /// <summary>Gets a value indicating whether is expired.</summary>
  55. /// <value><see langword="true" /> if this instance is expired; otherwise, <see langword="false" />.</value>
  56. public bool IsExpired
  57. {
  58. get
  59. {
  60. return this.LifeTime <= 0;
  61. }
  62. }
  63. /// <summary>Gets or sets the life time.</summary>
  64. /// <value>The life time.</value>
  65. public float LifeTime { get; set; }
  66. /// <summary>The reduce life time.</summary>
  67. /// <param name="lifeTimeDelta">The life time.</param>
  68. public void ReduceLifeTime(float lifeTimeDelta)
  69. {
  70. this.LifeTime -= lifeTimeDelta;
  71. if (this.LifeTime < 0)
  72. {
  73. this.LifeTime = 0;
  74. }
  75. }
  76. }
  77. }