Loot.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. #include "Loot.h"
  17. #include "../client.h"
  18. #include "../../common/ConfigReader.h"
  19. #include "../classes.h"
  20. #include "../../common/debug.h"
  21. #include "../zoneserver.h"
  22. #include "../Skills.h"
  23. #include "../classes.h"
  24. #include "../World.h"
  25. #include "../LuaInterface.h"
  26. #include "../../common/Log.h"
  27. #include "../Entity.h"
  28. #include "../Rules/Rules.h"
  29. extern Classes classes;
  30. extern ConfigReader configReader;
  31. extern MasterSkillList master_skill_list;
  32. extern RuleManager rule_manager;
  33. // If we want to transfer functions to this file then we should just do it, but for now we don't need all this commented code here
  34. NPC* Entity::DropChest() {
  35. // Check to see if treasure chests are disabled in the rules
  36. if (rule_manager.GetGlobalRule(R_World, TreasureChestDisabled)->GetBool())
  37. return 0;
  38. if(GetChestDropTime()) {
  39. return 0; // this is a chest! It doesn't drop itself!
  40. }
  41. NPC* chest = 0;
  42. chest = new NPC();
  43. chest->SetAttackable(0);
  44. chest->SetShowLevel(0);
  45. chest->SetShowName(1);
  46. chest->SetTargetable(1);
  47. chest->SetLevel(GetLevel());
  48. chest->SetChestDropTime();
  49. chest->SetTotalHP(100);
  50. chest->SetHP(100);
  51. chest->SetAlive(false);
  52. // Set the brain to a blank brain so it does nothing
  53. chest->SetBrain(new BlankBrain(chest));
  54. // Set the x, y, z, heading, location (grid id) to that of the dead spawn
  55. chest->SetZone(GetZone());
  56. // heading needs to be GetHeading() - 180 so the chest faces the proper way
  57. chest->SetHeading(GetHeading() - 180);
  58. // Set the primary command to loot and the secondary to disarm
  59. chest->AddPrimaryEntityCommand("loot", rule_manager.GetGlobalRule(R_Loot, LootRadius)->GetFloat(), "loot", "", 0, 0);
  60. chest->AddSecondaryEntityCommand("Disarm", rule_manager.GetGlobalRule(R_Loot, LootRadius)->GetFloat(), "Disarm", "", 0, 0);
  61. // 32 = loot icon for the mouse
  62. chest->SetIcon(32);
  63. // 1 = show the right click menu
  64. chest->SetShowCommandIcon(1);
  65. int8 highest_tier = 0;
  66. vector<Item*>::iterator itr;
  67. for (itr = ((Spawn*)this)->GetLootItems()->begin(); itr != ((Spawn*)this)->GetLootItems()->end(); ) {
  68. if ((*itr)->details.tier >= ITEM_TAG_COMMON && !(*itr)->IsBodyDrop()) {
  69. if ((*itr)->details.tier > highest_tier)
  70. highest_tier = (*itr)->details.tier;
  71. // Add the item to the chest
  72. chest->AddLootItem((*itr)->details.item_id, (*itr)->details.count);
  73. // Remove the item from the corpse
  74. itr = ((Spawn*)this)->GetLootItems()->erase(itr);
  75. }
  76. else
  77. itr++;
  78. }
  79. /*4034 = small chest | 5864 = treasure chest | 5865 = ornate treasure chest | 4015 = exquisite chest*/
  80. if (highest_tier >= ITEM_TAG_FABLED) {
  81. chest->SetModelType(4015);
  82. chest->SetName("Exquisite Chest");
  83. }
  84. else if (highest_tier >= ITEM_TAG_LEGENDARY) {
  85. chest->SetModelType(5865);
  86. chest->SetName("Ornate Chest");
  87. }
  88. else if (highest_tier >= ITEM_TAG_TREASURED) {
  89. chest->SetModelType(5864);
  90. chest->SetName("Treasure Chest");
  91. }
  92. else if (highest_tier >= ITEM_TAG_COMMON) {
  93. chest->SetModelType(4034);
  94. chest->SetName("Small Chest");
  95. }
  96. else {
  97. safe_delete(chest);
  98. chest = nullptr;
  99. }
  100. if (chest) {
  101. chest->SetID(Spawn::NextID());
  102. chest->SetShowHandIcon(1);
  103. chest->SetLocation(GetLocation());
  104. chest->SetX(GetX());
  105. chest->SetZ(GetZ());
  106. ((Entity*)chest)->GetInfoStruct()->set_flying_type(false);
  107. chest->is_flying_creature = false;
  108. if(GetMap()) {
  109. auto loc = glm::vec3(GetX(), GetZ(), GetY());
  110. float new_z = FindBestZ(loc, nullptr);
  111. chest->appearance.pos.Y = new_z; // don't use SetY here can cause a loop
  112. }
  113. else {
  114. chest->appearance.pos.Y = GetY();
  115. }
  116. }
  117. return chest;
  118. }