@@ -80,9 +80,9 @@ void AHBot_AuctionHouseScript::OnBeforeAuctionHouseMgrSendAuctionOutbiddedMail(
8080
8181void AHBot_AuctionHouseScript::OnAuctionAdd (AuctionHouseObject* /* ah*/ , AuctionEntry* auction)
8282{
83- //
83+ //
8484 // The the configuration for the auction house
85- //
85+ //
8686
8787 AuctionHouseEntry const * ahEntry = sAuctionMgr ->GetAuctionHouseEntryFromHouse (auction->GetHouseId ());
8888 AHBConfig* config = gNeutralConfig ;
@@ -99,9 +99,9 @@ void AHBot_AuctionHouseScript::OnAuctionAdd(AuctionHouseObject* /*ah*/, AuctionE
9999 }
100100 }
101101
102- //
102+ //
103103 // Consider only those auctions handled by the bots
104- //
104+ //
105105
106106 if (config->ConsiderOnlyBotAuctions )
107107 {
@@ -143,12 +143,9 @@ void AHBot_AuctionHouseScript::OnAuctionAdd(AuctionHouseObject* /*ah*/, AuctionE
143143
144144void AHBot_AuctionHouseScript::OnAuctionRemove (AuctionHouseObject* /* ah*/ , AuctionEntry* auction)
145145{
146- //
147146 // Get the configuration for the auction house
148- //
149-
150147 AuctionHouseEntry const * ahEntry = sAuctionMgr ->GetAuctionHouseEntryFromHouse (auction->GetHouseId ());
151- AHBConfig* config = gNeutralConfig ;
148+ AHBConfig* config = gNeutralConfig ;
152149
153150 if (ahEntry)
154151 {
@@ -162,10 +159,7 @@ void AHBot_AuctionHouseScript::OnAuctionRemove(AuctionHouseObject* /*ah*/, Aucti
162159 }
163160 }
164161
165- //
166162 // Consider only those auctions handled by the bots
167- //
168-
169163 if (config->ConsiderOnlyBotAuctions )
170164 {
171165 if (gBotsId .find (auction->owner .GetCounter ()) != gBotsId .end ())
@@ -174,41 +168,41 @@ void AHBot_AuctionHouseScript::OnAuctionRemove(AuctionHouseObject* /*ah*/, Aucti
174168 }
175169 }
176170
177- //
178171 // Verify if we can operate on the item
179- //
180-
181172 Item* pItem = sAuctionMgr ->GetAItem (auction->item_guid );
182173
174+ ItemTemplate const * prototype = sObjectMgr ->GetItemTemplate (auction->item_template );
175+
183176 if (!pItem)
184177 {
185178 if (config->DebugOut )
186179 {
187180 LOG_ERROR (" module" , " AHBot: Item {} doesn't exist, perhaps bought already?" , auction->item_guid .ToString ());
188181 }
189182
183+ // Decrement item counts even if the item does not exist
184+ if (prototype)
185+ {
186+ config->DecItemCounts (prototype->Class , prototype->Quality );
187+ }
188+
190189 return ;
191190 }
192191
193- //
194- // Decrements
195- //
196-
197- ItemTemplate const * prototype = sObjectMgr ->GetItemTemplate (auction->item_template );
198-
199192 if (config->DebugOut )
200193 {
201194 LOG_INFO (" module" , " AHBot: ah={}, item={}, count={}" , auction->GetHouseId (), auction->item_template , config->GetItemCounts (prototype->Quality ));
202195 }
203196
197+ // Decrement item counts
204198 config->DecItemCounts (prototype->Class , prototype->Quality );
205199}
206200
207201void AHBot_AuctionHouseScript::OnAuctionSuccessful (AuctionHouseObject* /* ah*/ , AuctionEntry* auction)
208202{
209- //
203+ //
210204 // Get the configuration for the auction house
211- //
205+ //
212206
213207 AuctionHouseEntry const * ahEntry = sAuctionMgr ->GetAuctionHouseEntryFromHouse (auction->GetHouseId ());
214208 AHBConfig* config = gNeutralConfig ;
@@ -225,19 +219,19 @@ void AHBot_AuctionHouseScript::OnAuctionSuccessful(AuctionHouseObject* /*ah*/, A
225219 }
226220 }
227221
228- //
222+ //
229223 // If the auction has been won, it means that it has been accepted by the market.
230224 // Use the buyout as a reference since the price for the bid is downgraded during selling.
231- //
225+ //
232226
233227 config->UpdateItemStats (auction->item_template , auction->itemCount , auction->buyout );
234228}
235229
236230void AHBot_AuctionHouseScript::OnAuctionExpire (AuctionHouseObject* /* ah*/ , AuctionEntry* auction)
237231{
238- //
232+ //
239233 // Get the configuration for the auction house
240- //
234+ //
241235
242236 AuctionHouseEntry const * ahEntry = sAuctionMgr ->GetAuctionHouseEntryFromHouse (auction->GetHouseId ());
243237 AHBConfig* config = gNeutralConfig ;
@@ -254,12 +248,22 @@ void AHBot_AuctionHouseScript::OnAuctionExpire(AuctionHouseObject* /*ah*/, Aucti
254248 }
255249 }
256250
257- //
251+ //
258252 // If the auction expired, then it means that the bid was unwanted by the market.
259253 // Bid price is usually less or equal to the buyout, so this likely will bring the price down.
260- //
254+ //
261255
262256 config->UpdateItemStats (auction->item_template , auction->itemCount , auction->bid );
257+
258+ // Decrement item counts
259+ ItemTemplate const * prototype = sObjectMgr ->GetItemTemplate (auction->item_template );
260+
261+ if (config->DebugOut )
262+ {
263+ LOG_INFO (" module" , " AHBot: ah={}, item={}, count={}" , auction->GetHouseId (), auction->item_template , config->GetItemCounts (prototype->Quality ));
264+ }
265+
266+ config->DecItemCounts (prototype->Class , prototype->Quality );
263267}
264268
265269void AHBot_AuctionHouseScript::OnBeforeAuctionHouseMgrUpdate ()
0 commit comments