@@ -462,45 +462,57 @@ void Player::updateInventoryWeight()
462
462
}
463
463
}
464
464
465
- void Player::updateInventoryImbuement (bool init /* = false */ )
465
+ void Player::updateInventoryImbuement ()
466
466
{
467
+ // Get the tile the player is currently on
467
468
const Tile* playerTile = getTile ();
469
+ // Check if the player is in a protection zone
468
470
bool isInProtectionZone = playerTile && playerTile->hasFlag (TILESTATE_PROTECTIONZONE);
471
+ // Check if the player is in fight mode
469
472
bool isInFightMode = hasCondition (CONDITION_INFIGHT);
470
-
471
- uint8_t imbuementsToCheck = g_game ().getPlayerActiveImbuements (getID ());
472
- for (auto item : getAllInventoryItems ()) {
473
+ // Iterate through all items in the player's inventory
474
+ for (auto item : getAllInventoryItems ())
475
+ {
476
+ // Iterate through all imbuement slots on the item
473
477
for (uint8_t slotid = 0 ; slotid < item->getImbuementSlot (); slotid++)
474
478
{
475
479
ImbuementInfo imbuementInfo;
480
+ // Get the imbuement information for the current slot
476
481
if (!item->getImbuementInfo (slotid, &imbuementInfo))
477
482
{
478
- continue ;
483
+ // If no imbuement is found, continue to the next slot
484
+ break ;
479
485
}
480
486
481
- const CategoryImbuement* categoryImbuement = g_imbuements ().getCategoryByID (imbuementInfo.imbuement ->getCategory ());
482
- if (categoryImbuement && categoryImbuement->agressive )
483
- {
484
- if (isInProtectionZone || !isInFightMode)
485
- {
486
- break ;
487
+ // Imbuement from imbuementInfo, this variable reduces code complexity
488
+ auto imbuement = imbuementInfo.imbuement ;
489
+ // Get the category of the imbuement
490
+ const CategoryImbuement* categoryImbuement = g_imbuements ().getCategoryByID (imbuement->getCategory ());
491
+ // Parent of the imbued item
492
+ auto parent = item->getParent ();
493
+ // If the imbuement is aggressive and the player is not in fight mode or is in a protection zone, or the item is in a container, ignore it.
494
+ if (categoryImbuement && categoryImbuement->agressive ) {
495
+ if (!isInFightMode || isInProtectionZone || parent && parent->getContainer ()) {
496
+ continue ;
487
497
}
488
498
}
489
-
490
- if (init)
491
- {
492
- g_game ().increasePlayerActiveImbuements (getID ());
499
+ // If the item is not in the backpack slot and it's not a agressive imbuement, ignore it.
500
+ if (categoryImbuement && !categoryImbuement->agressive && parent && parent != this ) {
501
+ continue ;
493
502
}
494
503
495
- int32_t duration = std::max<int32_t >(0 , imbuementInfo.duration - EVENT_IMBUEMENT_INTERVAL / 1000 );
496
- item->decayImbuementTime (slotid, imbuementInfo.imbuement ->getID (), duration);
497
- if (duration == 0 )
504
+ // If the imbuement's duration is 0, remove its stats and continue to the next slot
505
+ if (imbuementInfo.duration == 0 )
498
506
{
499
- removeItemImbuementStats (imbuementInfo. imbuement );
500
- g_game (). decreasePlayerActiveImbuements ( getID ()) ;
507
+ removeItemImbuementStats (imbuement);
508
+ continue ;
501
509
}
502
510
503
- imbuementsToCheck--;
511
+ SPDLOG_DEBUG (" Decaying imbuement {} from item {} of player {}" , imbuement->getName (), item->getName (), getName ());
512
+ // Calculate the new duration of the imbuement, making sure it doesn't go below 0
513
+ uint64_t duration = std::max<uint64_t >(0 , imbuementInfo.duration - EVENT_IMBUEMENT_INTERVAL / 1000 );
514
+ // Update the imbuement's duration in the item
515
+ item->decayImbuementTime (slotid, imbuement->getID (), duration);
504
516
}
505
517
}
506
518
}
@@ -1287,7 +1299,6 @@ void Player::onApplyImbuement(Imbuement *imbuement, Item *item, uint8_t slot, bo
1287
1299
1288
1300
item->addImbuement (slot, imbuement->getID (), baseImbuement->duration );
1289
1301
openImbuementWindow (item);
1290
- updateInventoryImbuement ();
1291
1302
}
1292
1303
1293
1304
void Player::onClearImbuement (Item* item, uint8_t slot)
0 commit comments