Skip to content

Commit 3113542

Browse files
authored
Merge 0d0bc64 into a7ff752
2 parents a7ff752 + 0d0bc64 commit 3113542

6 files changed

Lines changed: 132 additions & 25 deletions

File tree

src/game/WorldHandlers/SpellEffects.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2633,6 +2633,11 @@ void Spell::EffectOpenLock(SpellEffectIndex eff_idx)
26332633
itemTarget->SetFlag(ITEM_FIELD_FLAGS, ITEM_DYNFLAG_UNLOCKED);
26342634
}
26352635

2636+
if (gameObjTarget)
2637+
{
2638+
gameObjTarget->RemoveFlag(GAMEOBJECT_FLAGS, GO_FLAG_LOCKED);
2639+
}
2640+
26362641
SendLoot(guid, LOOT_SKINNING, LockType(m_spellInfo->EffectMiscValue[eff_idx]));
26372642

26382643
// not allow use skill grow at item base open

src/modules/Bots/playerbot/PlayerbotAI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ PlayerbotAI::PlayerbotAI(Player* bot) :
119119
//masterIncomingPacketHandlers.AddHandler(CMSG_GAMEOBJ_REPORT_USE, "use game object");
120120
masterIncomingPacketHandlers.AddHandler(CMSG_AREATRIGGER, "area trigger");
121121
masterIncomingPacketHandlers.AddHandler(CMSG_GAMEOBJ_USE, "use game object");
122-
masterIncomingPacketHandlers.AddHandler(CMSG_LOOT_ROLL, "loot roll");
122+
botOutgoingPacketHandlers.AddHandler(SMSG_LOOT_START_ROLL, "loot roll");
123123
masterIncomingPacketHandlers.AddHandler(CMSG_GOSSIP_HELLO, "gossip hello");
124124
masterIncomingPacketHandlers.AddHandler(CMSG_QUESTGIVER_HELLO, "gossip hello");
125125
masterIncomingPacketHandlers.AddHandler(CMSG_QUESTGIVER_COMPLETE_QUEST, "complete quest");

src/modules/Bots/playerbot/strategy/actions/AddLootAction.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ bool AddGatheringLootAction::AddLoot(ObjectGuid guid)
6666
return false;
6767
}
6868

69+
if (bot->GetMap()->IsDungeon() && loot.skillId != SKILL_LOCKPICKING)
70+
{
71+
return false;
72+
}
73+
6974
if (!loot.IsLootPossible(bot))
7075
{
7176
return false;
@@ -76,12 +81,6 @@ bool AddGatheringLootAction::AddLoot(ObjectGuid guid)
7681

7782
bool AddGatheringLootAction::isUseful()
7883
{
79-
// Don't gather in dungeons or raids
80-
if (bot->GetMap()->IsDungeon())
81-
{
82-
return false;
83-
}
84-
8584
// NC gathering is a problem if you are supposed to be following
8685
Player* master = ai->GetMaster();
8786
if (master && bot->GetGroup())

src/modules/Bots/playerbot/strategy/actions/LootAction.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,23 @@ bool OpenLootAction::DoLoot(LootObject& lootObject)
103103
}
104104

105105
bot->GetMotionMaster()->Clear();
106+
107+
if (go && go->GetGoState() == GO_STATE_ACTIVE)
108+
{
109+
if (bot->GetLootGuid() == lootObject.guid)
110+
return false;
111+
112+
WorldPacket* const packet = new WorldPacket(CMSG_LOOT, 8);
113+
*packet << lootObject.guid;
114+
bot->GetSession()->QueuePacket(packet);
115+
return true;
116+
}
117+
118+
if (bot->IsNonMeleeSpellCasted(false))
119+
{
120+
return false;
121+
}
122+
106123
if (lootObject.skillId == SKILL_MINING)
107124
{
108125
return bot->HasSkill(SKILL_MINING) ? ai->CastSpell(MINING, bot) : false;
@@ -286,7 +303,7 @@ bool StoreLootAction::Execute(Event event)
286303
continue;
287304
}
288305

289-
if (loot_type != LOOT_SKINNING && !IsLootAllowed(itemid))
306+
if (!IsLootAllowed(itemid))
290307
{
291308
continue;
292309
}

src/modules/Bots/playerbot/strategy/actions/LootRollAction.cpp

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
#include "botpch.h"
22
#include "../../playerbot.h"
33
#include "LootRollAction.h"
4-
4+
#include "../values/ItemUsageValue.h"
55

66
using namespace ai;
77

88
bool LootRollAction::Execute(Event event)
99
{
1010
Player *bot = QueryItemUsageAction::ai->GetBot();
1111

12-
WorldPacket p(event.getPacket()); //WorldPacket packet for CMSG_LOOT_ROLL, (8+4+1)
13-
ObjectGuid guid;
12+
WorldPacket p(event.getPacket());
13+
ObjectGuid lootTargetGuid;
1414
uint32 slot;
15-
uint8 rollType;
16-
p.rpos(0); //reset packet pointer
17-
p >> guid; //guid of the item rolled
18-
p >> slot; //number of players invited to roll
19-
p >> rollType; //need,greed or pass on roll
15+
uint32 itemid;
16+
uint32 randomSuffix;
17+
uint32 itemRandomPropId;
18+
p.rpos(0);
19+
p >> lootTargetGuid;
20+
p >> slot;
21+
p >> itemid;
22+
p >> randomSuffix;
23+
p >> itemRandomPropId;
2024

2125
Group* group = bot->GetGroup();
2226
if (!group)
@@ -26,23 +30,30 @@ bool LootRollAction::Execute(Event event)
2630

2731
RollVote vote = ROLL_PASS;
2832

29-
ItemPrototype const *proto = sItemStorage.LookupEntry<ItemPrototype>(guid.GetEntry());
33+
ItemPrototype const *proto = sItemStorage.LookupEntry<ItemPrototype>(itemid);
3034
if (proto)
3135
{
36+
AiObjectContext* context = QueryItemUsageAction::context;
37+
ostringstream out; out << itemid;
38+
ItemUsage usage = AI_VALUE2(ItemUsage, "item usage", out.str());
39+
3240
switch (proto->Class)
3341
{
3442
case ITEM_CLASS_WEAPON:
3543
case ITEM_CLASS_ARMOR:
36-
if (QueryItemUsage(proto))
37-
{
44+
if (usage == ITEM_USAGE_EQUIP || usage == ITEM_USAGE_REPLACE)
3845
vote = ROLL_NEED;
39-
}
46+
else if (bot->CanUseItem(proto) == EQUIP_ERR_OK && proto->Bonding != BIND_WHEN_PICKED_UP)
47+
vote = ROLL_GREED;
4048
break;
4149
default:
42-
if (IsLootAllowed(guid.GetEntry()))
43-
{
50+
if (usage == ITEM_USAGE_SKILL || usage == ITEM_USAGE_USE)
51+
vote = ROLL_NEED;
52+
else if (proto->StartQuest || proto->Bonding == BIND_QUEST_ITEM ||
53+
proto->Bonding == BIND_QUEST_ITEM1 || proto->Class == ITEM_CLASS_QUEST)
4454
vote = ROLL_NEED;
45-
}
55+
else if (proto->SellPrice > 0 && proto->Bonding != BIND_WHEN_PICKED_UP)
56+
vote = ROLL_GREED;
4657
break;
4758
}
4859
}
@@ -51,10 +62,10 @@ bool LootRollAction::Execute(Event event)
5162
{
5263
case MASTER_LOOT:
5364
case FREE_FOR_ALL:
54-
group->CountRollVote(bot, guid, slot, ROLL_PASS);
65+
group->CountRollVote(bot, lootTargetGuid, slot, ROLL_PASS);
5566
break;
5667
default:
57-
group->CountRollVote(bot, guid, slot, vote);
68+
group->CountRollVote(bot, lootTargetGuid, slot, vote);
5869
break;
5970
}
6071

src/modules/Bots/playerbot/strategy/values/ItemUsageValue.cpp

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,63 @@ ItemUsage ItemUsageValue::QueryItemUsageForEquip(ItemPrototype const * item)
8787
return ITEM_USAGE_NONE;
8888
}
8989

90+
static bool IsClothMaterial(uint32 itemId, uint32 botSkill)
91+
{
92+
static std::map<uint32, uint32> firstAidMaterials;
93+
static bool initialized = false;
94+
if (!initialized)
95+
{
96+
initialized = true;
97+
for (uint32 i = 0; i < sSkillLineAbilityStore.GetNumRows(); ++i)
98+
{
99+
SkillLineAbilityEntry const* entry = sSkillLineAbilityStore.LookupEntry(i);
100+
if (!entry || entry->skillId != SKILL_FIRST_AID)
101+
continue;
102+
SpellEntry const* spell = sSpellStore.LookupEntry(entry->spellId);
103+
if (!spell)
104+
continue;
105+
for (int r = 0; r < MAX_SPELL_REAGENTS; ++r)
106+
{
107+
if (spell->Reagent[r] <= 0)
108+
continue;
109+
uint32 reagentId = (uint32)spell->Reagent[r];
110+
uint32 greyAt = entry->max_value;
111+
auto it = firstAidMaterials.find(reagentId);
112+
if (it == firstAidMaterials.end() || greyAt > it->second)
113+
firstAidMaterials[reagentId] = greyAt;
114+
}
115+
}
116+
}
117+
auto it = firstAidMaterials.find(itemId);
118+
if (it == firstAidMaterials.end())
119+
return false;
120+
return it->second == 0 || botSkill < it->second;
121+
}
122+
123+
static bool IsSkillMaterial(uint32 skillId, uint32 itemId)
124+
{
125+
static std::map<uint32,std::set<uint32>> skillMaterials;
126+
if (skillMaterials[skillId].size()==0)
127+
{
128+
for (uint32 i = 0; i < sSkillLineAbilityStore.GetNumRows(); ++i)
129+
{
130+
SkillLineAbilityEntry const* entry = sSkillLineAbilityStore.LookupEntry(i);
131+
if (!entry || entry->skillId != skillId)
132+
continue;
133+
SpellEntry const* spell = sSpellStore.LookupEntry(entry->spellId);
134+
if (!spell)
135+
continue;
136+
for (int r = 0; r < MAX_SPELL_REAGENTS; ++r)
137+
{
138+
if (spell->Reagent[r] <= 0)
139+
continue;
140+
skillMaterials[skillId].insert((uint32)spell->Reagent[r]);
141+
}
142+
}
143+
}
144+
return skillMaterials[skillId].count(itemId) > 0;
145+
}
146+
90147
bool ItemUsageValue::IsItemUsefulForSkill(ItemPrototype const * proto)
91148
{
92149
switch (proto->Class)
@@ -99,6 +156,24 @@ bool ItemUsageValue::IsItemUsefulForSkill(ItemPrototype const * proto)
99156
case ITEM_SUBCLASS_DEVICES:
100157
return bot->HasSkill(SKILL_ENGINEERING);
101158
}
159+
if (bot->HasSkill(SKILL_FIRST_AID) && IsClothMaterial(proto->ItemId, bot->GetSkillValue(SKILL_FIRST_AID)))
160+
return true;
161+
if (bot->HasSkill(SKILL_HERBALISM) && IsSkillMaterial(SKILL_ALCHEMY, proto->ItemId))
162+
return true;
163+
if (bot->HasSkill(SKILL_ALCHEMY) && IsSkillMaterial(SKILL_ALCHEMY, proto->ItemId))
164+
return true;
165+
if (bot->HasSkill(SKILL_TAILORING) && IsSkillMaterial(SKILL_TAILORING, proto->ItemId))
166+
return true;
167+
if (bot->HasSkill(SKILL_SKINNING) && IsSkillMaterial(SKILL_LEATHERWORKING, proto->ItemId))
168+
return true;
169+
if (bot->HasSkill(SKILL_LEATHERWORKING) && IsSkillMaterial(SKILL_LEATHERWORKING, proto->ItemId))
170+
return true;
171+
if (bot->HasSkill(SKILL_MINING) && IsSkillMaterial(SKILL_MINING, proto->ItemId))
172+
return true;
173+
if (bot->HasSkill(SKILL_BLACKSMITHING) && IsSkillMaterial(SKILL_BLACKSMITHING, proto->ItemId))
174+
return true;
175+
if (bot->HasSkill(SKILL_ENGINEERING) && IsSkillMaterial(SKILL_ENGINEERING, proto->ItemId))
176+
return true;
102177
break;
103178
case ITEM_CLASS_RECIPE:
104179
{

0 commit comments

Comments
 (0)