9
3

Loot.cpp 3.9 KB

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