9
3

Tradeskills.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef __EQ2_TRADESKILLS__
  17. #define __EQ2_TRADESKILLS__
  18. #include "../../common/types.h"
  19. #include "../../common/Mutex.h"
  20. #include "../Items/Items.h"
  21. #include <map>
  22. class Player;
  23. class Spawn;
  24. class Recipe;
  25. class Client;
  26. struct TradeskillEvent
  27. {
  28. char Name[250];
  29. int16 Icon;
  30. int32 Technique;
  31. int16 SuccessProgress;
  32. int16 SuccessDurability;
  33. int16 SuccessHP;
  34. int16 SuccessPower;
  35. int32 SuccessSpellID;
  36. int32 SuccessItemID;
  37. sint16 FailProgress;
  38. sint16 FailDurability;
  39. sint16 FailHP;
  40. sint16 FailPower;
  41. };
  42. struct Tradeskill
  43. {
  44. Player* player;
  45. Spawn* table;
  46. Recipe* recipe;
  47. int32 currentProgress;
  48. int32 currentDurability;
  49. int32 nextUpdateTime;
  50. vector<pair<int32, int16>> usedComponents;
  51. TradeskillEvent* CurrentEvent;
  52. bool eventChecked;
  53. bool eventCountered;
  54. };
  55. class TradeskillMgr
  56. {
  57. public:
  58. TradeskillMgr();
  59. ~TradeskillMgr();
  60. /// <summary>Determines if an update is needed if so send one and stop crafting if finished</summary>
  61. void Process();
  62. /// <summary>Starts the actual crafting process</summary>
  63. /// <param name='client'>Client that is crafting</param>
  64. /// <param name='components'>List of items the player is using to craft</param>
  65. void BeginCrafting(Client* client, vector<pair<int32, int16>> components);
  66. /// <summary>Stops the crafting process</summary>
  67. /// <param name='client'>Client that stopped crafting</param>
  68. /// <param name='lock'>Does the list need a mutex lock? default = true</param>
  69. void StopCrafting(Client* client, bool lock = true);
  70. /// <summary>Checks to see if the given client is crafting</summary>
  71. /// <param name='client'>The client to check</param>
  72. /// <returns>True if the client is crafting</returns>
  73. bool IsClientCrafting(Client* client);
  74. /// <summary>Get the tradeskill struct for the given client</summary>
  75. /// <param name='client'>The client to get the tradeskill struct for</param>
  76. /// <returns>Pointer to the clients tradeskill struct, or 0 if they don't have one</returns>
  77. Tradeskill* GetTradeskill(Client* client);
  78. /// <summary>Check to see if we countered the tradeskill event</summary>
  79. /// <param name='client'>The client to check for</param>
  80. /// <param name='icon'>The icon of the spell we casted</param>
  81. void CheckTradeskillEvent(Client* client, int16 icon);
  82. /// <summary>Lock the tradeskill list for reading, should never need to write to the tradeskill list outside of the TradeskillMgr class</summary>
  83. /// <param name='function'>Function name that called this lock</param>
  84. /// <param name='line'>Line number this lock was called from</param>
  85. void ReadLock(const char* function = (const char*)0, int32 line = 0) { m_tradeskills.readlock(function, line); }
  86. /// <summary>Releases the red lock on the tradeskill list</summary>
  87. /// <param name='function'>Function name that is releasing the lock</param>
  88. /// <param name='line'>Line number that is releasing the lock</param>
  89. void ReleaseReadLock(const char* function = (const char*)0, int32 line = 0) { m_tradeskills.releasereadlock(function, line); }
  90. int32 GetTechniqueSuccessAnim(int16 version, int32 technique);
  91. int32 GetTechniqueFailureAnim(int16 version, int32 technique);
  92. int32 GetTechniqueIdleAnim(int16 version, int32 technique);
  93. int32 GetMissTargetAnim(int16 version);
  94. int32 GetKillMissTargetAnim(int16 version);
  95. void SetClientIdleVisualState(Client* client, Tradeskill* ts);
  96. private:
  97. /// <summary>Sends the creation window</summary>
  98. /// <param name='client'>Client to send the window to</param>
  99. /// <param name='recipe'>The recipe being crafted</param>
  100. void SendItemCreationUI(Client* client, Recipe* recipe);
  101. map<Client*, Tradeskill*> tradeskillList;
  102. Mutex m_tradeskills;
  103. float m_critFail;
  104. float m_critSuccess;
  105. float m_fail;
  106. float m_success;
  107. float m_eventChance;
  108. };
  109. class MasterTradeskillEventsList
  110. {
  111. public:
  112. MasterTradeskillEventsList();
  113. ~MasterTradeskillEventsList();
  114. /// <summary>Adds a tradeskill event to the master list</summery>
  115. /// <param name='tradeskillEvent'>The event to add</param>
  116. void AddEvent(TradeskillEvent* tradeskillEvent);
  117. /// <summary>Gets a list of tradeskill events for the given technique</summery>
  118. /// <param name='technique'>The skill id of the technique</param>
  119. /// <returns>Vector of TradeskillEvent* for the given technique</returns>
  120. vector<TradeskillEvent*>* GetEventByTechnique(int32 technique);
  121. /// <summary>Get the size of the event list</summary>
  122. /// <returns>int32 containing the size of the list</returns>
  123. int32 Size();
  124. private:
  125. Mutex m_eventList;
  126. map<int32, vector<TradeskillEvent*> > eventList;
  127. };
  128. #endif