Tradeskills.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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<int32> 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<int32> 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. private:
  91. /// <summary>Sends the creation window</summary>
  92. /// <param name='client'>Client to send the window to</param>
  93. /// <param name='recipe'>The recipe being crafted</param>
  94. void SendItemCreationUI(Client* client, Recipe* recipe);
  95. map<Client*, Tradeskill*> tradeskillList;
  96. Mutex m_tradeskills;
  97. float m_critFail;
  98. float m_critSuccess;
  99. float m_fail;
  100. float m_success;
  101. float m_eventChance;
  102. };
  103. class MasterTradeskillEventsList
  104. {
  105. public:
  106. MasterTradeskillEventsList();
  107. ~MasterTradeskillEventsList();
  108. /// <summary>Adds a tradeskill event to the master list</summery>
  109. /// <param name='tradeskillEvent'>The event to add</param>
  110. void AddEvent(TradeskillEvent* tradeskillEvent);
  111. /// <summary>Gets a list of tradeskill events for the given technique</summery>
  112. /// <param name='technique'>The skill id of the technique</param>
  113. /// <returns>Vector of TradeskillEvent* for the given technique</returns>
  114. vector<TradeskillEvent*>* GetEventByTechnique(int32 technique);
  115. /// <summary>Get the size of the event list</summary>
  116. /// <returns>int32 containing the size of the list</returns>
  117. int32 Size();
  118. private:
  119. Mutex m_eventList;
  120. map<int32, vector<TradeskillEvent*> > eventList;
  121. };
  122. #endif