Loot.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. NPC* chest = 0;
  39. chest = new NPC();
  40. chest->SetAttackable(0);
  41. chest->SetShowLevel(0);
  42. chest->SetShowName(1);
  43. chest->SetTargetable(1);
  44. chest->SetLevel(GetLevel());
  45. chest->SetChestDropTime();
  46. // Set the brain to a blank brain so it does nothing
  47. chest->SetBrain(new BlankBrain(chest));
  48. // Set the x, y, z, heading, location (grid id) to that of the dead spawn
  49. chest->SetZone(GetZone());
  50. // heading needs to be GetHeading() - 180 so the chest faces the proper way
  51. chest->SetHeading(GetHeading() - 180);
  52. // Set the primary command to loot and the secondary to disarm
  53. chest->AddPrimaryEntityCommand("loot", rule_manager.GetGlobalRule(R_Loot, LootRadius)->GetFloat(), "loot", "", 0, 0);
  54. chest->AddSecondaryEntityCommand("Disarm", rule_manager.GetGlobalRule(R_Loot, LootRadius)->GetFloat(), "Disarm", "", 0, 0);
  55. // 32 = loot icon for the mouse
  56. chest->SetIcon(32);
  57. // 1 = show the right click menu
  58. chest->SetShowCommandIcon(1);
  59. int8 highest_tier = 0;
  60. vector<Item*>::iterator itr;
  61. for (itr = ((Spawn*)this)->GetLootItems()->begin(); itr != ((Spawn*)this)->GetLootItems()->end(); ) {
  62. if ((*itr)->details.tier >= ITEM_TAG_UNCOMMON && !(*itr)->IsBodyDrop()) {
  63. if ((*itr)->details.tier > highest_tier)
  64. highest_tier = (*itr)->details.tier;
  65. // Add the item to the chest
  66. chest->AddLootItem((*itr)->details.item_id, (*itr)->details.count);
  67. // Remove the item from the corpse
  68. itr = ((Spawn*)this)->GetLootItems()->erase(itr);
  69. }
  70. else
  71. itr++;
  72. }
  73. /*4034 = small chest | 5864 = treasure chest | 5865 = ornate treasure chest | 4015 = exquisite chest*/
  74. if (highest_tier >= ITEM_TAG_FABLED) {
  75. chest->SetModelType(4015);
  76. chest->SetName("Exquisite Chest");
  77. }
  78. else if (highest_tier >= ITEM_TAG_LEGENDARY) {
  79. chest->SetModelType(5865);
  80. chest->SetName("Ornate Chest");
  81. }
  82. else if (highest_tier >= ITEM_TAG_TREASURED) {
  83. chest->SetModelType(5864);
  84. chest->SetName("Treasure Chest");
  85. }
  86. else if (highest_tier >= ITEM_TAG_UNCOMMON) {
  87. chest->SetModelType(4034);
  88. chest->SetName("Small Chest");
  89. }
  90. else {
  91. safe_delete(chest);
  92. chest = nullptr;
  93. }
  94. if (chest) {
  95. chest->SetID(Spawn::NextID());
  96. chest->SetShowHandIcon(1);
  97. chest->SetLocation(GetLocation());
  98. chest->SetX(GetX());
  99. chest->SetZ(GetZ());
  100. chest->appearance.pos.Y = GetY(); // don't use SetY, do this last after loc/x/z set
  101. }
  102. return chest;
  103. }