Loot.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. chest->SetX(GetX());
  51. chest->SetZ(GetZ()); // need to set X/Z BEFORE setting Y
  52. chest->SetY(GetY());
  53. // heading needs to be GetHeading() - 180 so the chest faces the proper way
  54. chest->SetHeading(GetHeading() - 180);
  55. chest->SetLocation(GetLocation());
  56. // Set the primary command to loot and the secondary to disarm
  57. chest->AddPrimaryEntityCommand("loot", rule_manager.GetGlobalRule(R_Loot, LootRadius)->GetFloat(), "loot", "", 0, 0);
  58. chest->AddSecondaryEntityCommand("Disarm", rule_manager.GetGlobalRule(R_Loot, LootRadius)->GetFloat(), "Disarm", "", 0, 0);
  59. // 32 = loot icon for the mouse
  60. chest->SetIcon(32);
  61. // 1 = show the right click menu
  62. chest->SetShowCommandIcon(1);
  63. int8 highest_tier = 0;
  64. vector<Item*>::iterator itr;
  65. for (itr = ((Spawn*)this)->GetLootItems()->begin(); itr != ((Spawn*)this)->GetLootItems()->end(); ) {
  66. if ((*itr)->details.tier >= ITEM_TAG_UNCOMMON && !(*itr)->IsBodyDrop()) {
  67. if ((*itr)->details.tier > highest_tier)
  68. highest_tier = (*itr)->details.tier;
  69. // Add the item to the chest
  70. chest->AddLootItem((*itr)->details.item_id, (*itr)->details.count);
  71. // Remove the item from the corpse
  72. itr = ((Spawn*)this)->GetLootItems()->erase(itr);
  73. }
  74. else
  75. itr++;
  76. }
  77. /*4034 = small chest | 5864 = treasure chest | 5865 = ornate treasure chest | 4015 = exquisite chest*/
  78. if (highest_tier >= ITEM_TAG_FABLED) {
  79. chest->SetModelType(4015);
  80. chest->SetName("Exquisite Chest");
  81. }
  82. else if (highest_tier >= ITEM_TAG_LEGENDARY) {
  83. chest->SetModelType(5865);
  84. chest->SetName("Ornate Chest");
  85. }
  86. else if (highest_tier >= ITEM_TAG_TREASURED) {
  87. chest->SetModelType(5864);
  88. chest->SetName("Treasure Chest");
  89. }
  90. else if (highest_tier >= ITEM_TAG_UNCOMMON) {
  91. chest->SetModelType(4034);
  92. chest->SetName("Small Chest");
  93. }
  94. else
  95. safe_delete(chest);
  96. if (chest)
  97. chest->SetShowHandIcon(1);
  98. return chest;
  99. }