Loot.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. chest->SetLootMethod(this->GetLootMethod(), this->GetLootRarity(), this->GetLootGroupID());
  66. chest->SetLootName(this->GetName());
  67. int8 highest_tier = 0;
  68. vector<Item*>::iterator itr;
  69. for (itr = ((Spawn*)this)->GetLootItems()->begin(); itr != ((Spawn*)this)->GetLootItems()->end(); ) {
  70. if ((*itr)->details.tier >= ITEM_TAG_COMMON && !(*itr)->IsBodyDrop()) {
  71. if ((*itr)->details.tier > highest_tier)
  72. highest_tier = (*itr)->details.tier;
  73. // Add the item to the chest
  74. chest->AddLootItem((*itr)->details.item_id, (*itr)->details.count);
  75. // Remove the item from the corpse
  76. itr = ((Spawn*)this)->GetLootItems()->erase(itr);
  77. }
  78. else
  79. itr++;
  80. }
  81. /*4034 = small chest | 5864 = treasure chest | 5865 = ornate treasure chest | 4015 = exquisite chest*/
  82. if (highest_tier >= ITEM_TAG_FABLED) {
  83. chest->SetModelType(4015);
  84. chest->SetName("Exquisite Chest");
  85. }
  86. else if (highest_tier >= ITEM_TAG_LEGENDARY) {
  87. chest->SetModelType(5865);
  88. chest->SetName("Ornate Chest");
  89. }
  90. else if (highest_tier >= ITEM_TAG_TREASURED) {
  91. chest->SetModelType(5864);
  92. chest->SetName("Treasure Chest");
  93. }
  94. else if (highest_tier >= ITEM_TAG_COMMON) {
  95. chest->SetModelType(4034);
  96. chest->SetName("Small Chest");
  97. }
  98. else {
  99. safe_delete(chest);
  100. chest = nullptr;
  101. }
  102. if (chest) {
  103. chest->SetID(Spawn::NextID());
  104. chest->SetShowHandIcon(1);
  105. chest->SetLocation(GetLocation());
  106. chest->SetX(GetX());
  107. chest->SetZ(GetZ());
  108. ((Entity*)chest)->GetInfoStruct()->set_flying_type(false);
  109. chest->is_flying_creature = false;
  110. if(GetMap()) {
  111. auto loc = glm::vec3(GetX(), GetZ(), GetY());
  112. float new_z = FindBestZ(loc, nullptr);
  113. chest->appearance.pos.Y = new_z; // don't use SetY here can cause a loop
  114. }
  115. else {
  116. chest->appearance.pos.Y = GetY();
  117. }
  118. }
  119. return chest;
  120. }