Skip to content

Commit

Permalink
Correction to creatures wielding loot.
Browse files Browse the repository at this point in the history
  • Loading branch information
ratkosrb committed Dec 31, 2024
1 parent 7459887 commit 4338efe
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 14 deletions.
79 changes: 79 additions & 0 deletions sql/migrations/20241231005055_world.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
DROP PROCEDURE IF EXISTS add_migration;
DELIMITER ??
CREATE PROCEDURE `add_migration`()
BEGIN
DECLARE v INT DEFAULT 1;
SET v = (SELECT COUNT(*) FROM `migrations` WHERE `id`='20241231005055');
IF v = 0 THEN
INSERT INTO `migrations` VALUES ('20241231005055');
-- Add your query below.


-- Remove loot from equipment of creatures. (handled by static flag)
DELETE FROM `creature_equip_template` WHERE `entry`=2344;
INSERT INTO `creature_equip_template` (`entry`, `probability`, `item1`, `item2`, `item3`, `patch_min`, `patch_max`) VALUES (2344, 1, 12934, 1985, 0, 0, 10);
DELETE FROM `creature_equip_template` WHERE `entry`=2345;
INSERT INTO `creature_equip_template` (`entry`, `probability`, `item1`, `item2`, `item3`, `patch_min`, `patch_max`) VALUES (2345, 1, 1901, 0, 2552, 0, 10);
DELETE FROM `creature_equip_template` WHERE `entry`=2346;
INSERT INTO `creature_equip_template` (`entry`, `probability`, `item1`, `item2`, `item3`, `patch_min`, `patch_max`) VALUES (2346, 1, 2809, 0, 0, 0, 10);
DELETE FROM `creature_equip_template` WHERE `entry`=3727;
INSERT INTO `creature_equip_template` (`entry`, `probability`, `item1`, `item2`, `item3`, `patch_min`, `patch_max`) VALUES (3727, 1, 5289, 0, 0, 0, 10);
DELETE FROM `creature_equip_template` WHERE `entry`=4809;
INSERT INTO `creature_equip_template` (`entry`, `probability`, `item1`, `item2`, `item3`, `patch_min`, `patch_max`) VALUES (4809, 1, 2176, 0, 0, 0, 10);
DELETE FROM `creature_equip_template` WHERE `entry`=4810;
INSERT INTO `creature_equip_template` (`entry`, `probability`, `item1`, `item2`, `item3`, `patch_min`, `patch_max`) VALUES (4810, 1, 4991, 0, 0, 0, 10);
DELETE FROM `creature_equip_template` WHERE `entry`=4811;
UPDATE `creature_template` SET `equipment_id`=0 WHERE `entry`=4811;
DELETE FROM `creature_equip_template` WHERE `entry`=4812;
INSERT INTO `creature_equip_template` (`entry`, `probability`, `item1`, `item2`, `item3`, `patch_min`, `patch_max`) VALUES (4812, 1, 1907, 0, 0, 0, 10);
DELETE FROM `creature_equip_template` WHERE `entry`=4813;
INSERT INTO `creature_equip_template` (`entry`, `probability`, `item1`, `item2`, `item3`, `patch_min`, `patch_max`) VALUES (4813, 1, 2559, 0, 0, 0, 10);
DELETE FROM `creature_equip_template` WHERE `entry`=4814;
INSERT INTO `creature_equip_template` (`entry`, `probability`, `item1`, `item2`, `item3`, `patch_min`, `patch_max`) VALUES (4814, 1, 2177, 0, 0, 0, 10);
DELETE FROM `creature_equip_template` WHERE `entry`=4832;
INSERT INTO `creature_equip_template` (`entry`, `probability`, `item1`, `item2`, `item3`, `patch_min`, `patch_max`) VALUES (4832, 1, 5303, 0, 0, 0, 10);
DELETE FROM `creature_equip_template` WHERE `entry`=5860;
INSERT INTO `creature_equip_template` (`entry`, `probability`, `item1`, `item2`, `item3`, `patch_min`, `patch_max`) VALUES (5860, 1, 5277, 0, 0, 0, 10);
DELETE FROM `creature_equip_template` WHERE `entry`=5861;
INSERT INTO `creature_equip_template` (`entry`, `probability`, `item1`, `item2`, `item3`, `patch_min`, `patch_max`) VALUES (5861, 1, 3361, 1984, 0, 0, 10);
DELETE FROM `creature_equip_template` WHERE `entry`=5862;
INSERT INTO `creature_equip_template` (`entry`, `probability`, `item1`, `item2`, `item3`, `patch_min`, `patch_max`) VALUES (5862, 1, 5303, 0, 0, 0, 10);
DELETE FROM `creature_equip_template` WHERE `entry`=5998;
INSERT INTO `creature_equip_template` (`entry`, `probability`, `item1`, `item2`, `item3`, `patch_min`, `patch_max`) VALUES (5998, 1, 2182, 0, 0, 0, 10);
DELETE FROM `creature_equip_template` WHERE `entry`=5999;
INSERT INTO `creature_equip_template` (`entry`, `probability`, `item1`, `item2`, `item3`, `patch_min`, `patch_max`) VALUES (5999, 1, 2178, 1984, 0, 0, 10);
DELETE FROM `creature_equip_template` WHERE `entry`=6000;
INSERT INTO `creature_equip_template` (`entry`, `probability`, `item1`, `item2`, `item3`, `patch_min`, `patch_max`) VALUES (6000, 1, 2176, 0, 0, 0, 10);
DELETE FROM `creature_equip_template` WHERE `entry`=6002;
INSERT INTO `creature_equip_template` (`entry`, `probability`, `item1`, `item2`, `item3`, `patch_min`, `patch_max`) VALUES (6002, 1, 2177, 0, 0, 0, 10);
DELETE FROM `creature_equip_template` WHERE `entry`=6003;
INSERT INTO `creature_equip_template` (`entry`, `probability`, `item1`, `item2`, `item3`, `patch_min`, `patch_max`) VALUES (6003, 1, 5305, 0, 0, 0, 10);
DELETE FROM `creature_equip_template` WHERE `entry`=6004;
INSERT INTO `creature_equip_template` (`entry`, `probability`, `item1`, `item2`, `item3`, `patch_min`, `patch_max`) VALUES (6004, 1, 5280, 0, 6886, 0, 10);
DELETE FROM `creature_equip_template` WHERE `entry`=6005;
UPDATE `creature_template` SET `equipment_id`=0 WHERE `entry`=6005;
DELETE FROM `creature_equip_template` WHERE `entry`=6006;
INSERT INTO `creature_equip_template` (`entry`, `probability`, `item1`, `item2`, `item3`, `patch_min`, `patch_max`) VALUES (6006, 1, 1907, 0, 0, 0, 10);
DELETE FROM `creature_equip_template` WHERE `entry`=6007;
INSERT INTO `creature_equip_template` (`entry`, `probability`, `item1`, `item2`, `item3`, `patch_min`, `patch_max`) VALUES (6007, 1, 6224, 0, 0, 0, 10);
DELETE FROM `creature_equip_template` WHERE `entry`=6008;
INSERT INTO `creature_equip_template` (`entry`, `probability`, `item1`, `item2`, `item3`, `patch_min`, `patch_max`) VALUES (6008, 1, 2559, 0, 0, 0, 10);
DELETE FROM `creature_equip_template` WHERE `entry`=6009;
UPDATE `creature_template` SET `equipment_id`=0 WHERE `entry`=6009;
DELETE FROM `creature_equip_template` WHERE `entry`=7360;
INSERT INTO `creature_equip_template` (`entry`, `probability`, `item1`, `item2`, `item3`, `patch_min`, `patch_max`) VALUES (7360, 1, 2695, 1985, 0, 0, 10);
DELETE FROM `creature_equip_template` WHERE `entry`=7851;
INSERT INTO `creature_equip_template` (`entry`, `probability`, `item1`, `item2`, `item3`, `patch_min`, `patch_max`) VALUES (7851, 1, 4991, 0, 0, 0, 10);
DELETE FROM `creature_equip_template` WHERE `entry`=8282;
INSERT INTO `creature_equip_template` (`entry`, `probability`, `item1`, `item2`, `item3`, `patch_min`, `patch_max`) VALUES (8282, 1, 2177, 0, 0, 0, 10);

-- Remove empty item row.
DELETE FROM `item_template` WHERE `entry`=0;


-- End of migration.
END IF;
END??
DELIMITER ;
CALL add_migration();
DROP PROCEDURE IF EXISTS add_migration;
27 changes: 13 additions & 14 deletions src/game/Objects/Creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1995,56 +1995,55 @@ void Creature::LoadDefaultEquipment(GameEventCreatureData const* eventData)
}
else
{
// use default from the template
LoadEquipment(m_creatureInfo->equipment_id, true);

// loot can override the default equipment
if (HasStaticFlag(CREATURE_STATIC_FLAG_CAN_WIELD_LOOT))
{
LoadEquipment(0, true);
GenerateLootForBody(nullptr, nullptr);

bool usingLoot = false;
bool hasMainHand = false;
bool hasOffHand = false;
bool hasRanged = false;
for (auto const& itr : loot.items)
{
if (ItemPrototype const* pItem = sObjectMgr.GetItemPrototype(itr.itemid))
{
if (!GetVirtualItemDisplayId(BASE_ATTACK))
if (!hasMainHand)
{
if (pItem->InventoryType == INVTYPE_WEAPON ||
pItem->InventoryType == INVTYPE_WEAPONMAINHAND ||
pItem->InventoryType == INVTYPE_2HWEAPON && !GetVirtualItemDisplayId(OFF_ATTACK))
{
SetVirtualItem(BASE_ATTACK, itr.itemid);
usingLoot = true;
hasMainHand = true;
continue;
}
}

if (!GetVirtualItemDisplayId(OFF_ATTACK) && GetVirtualItemInventoryType(BASE_ATTACK) != INVTYPE_2HWEAPON)
if (!hasOffHand && GetVirtualItemInventoryType(BASE_ATTACK) != INVTYPE_2HWEAPON)
{
if (pItem->InventoryType == INVTYPE_WEAPON ||
pItem->InventoryType == INVTYPE_WEAPONOFFHAND ||
pItem->InventoryType == INVTYPE_SHIELD ||
pItem->InventoryType == INVTYPE_HOLDABLE)
{
SetVirtualItem(OFF_ATTACK, itr.itemid);
usingLoot = true;
hasOffHand = true;
continue;
}
}

if (!GetVirtualItemDisplayId(RANGED_ATTACK) && pItem->IsRangedWeapon())
if (!hasRanged && pItem->IsRangedWeapon())
{
SetVirtualItem(RANGED_ATTACK, itr.itemid);
usingLoot = true;
hasRanged = true;
continue;
}
}
}

if (usingLoot)
return;
}

// use default from the template
LoadEquipment(m_creatureInfo->equipment_id, true);
}
}

Expand Down

0 comments on commit 4338efe

Please sign in to comment.