Fixes petautobonus issues (#7272)
* Fixes #7271. * Fixes a missing check that looks to see if the bonus already exists before adding it again to the vector. * Fixes the removal of pet autobonuses. Thanks to @mazvi, @vstumpf, and @Lemongrass3110!
This commit is contained in:
parent
c9f075b8c6
commit
4c42bcbb34
@ -2345,6 +2345,14 @@ void pet_evolution(struct map_session_data *sd, int16 pet_id) {
|
|||||||
* @return True on success or false otherwise
|
* @return True on success or false otherwise
|
||||||
*/
|
*/
|
||||||
bool pet_addautobonus(std::vector<std::shared_ptr<s_petautobonus>> &bonus, const std::string &script, int16 rate, uint32 dur, uint16 flag, const std::string &other_script, bool onskill) {
|
bool pet_addautobonus(std::vector<std::shared_ptr<s_petautobonus>> &bonus, const std::string &script, int16 rate, uint32 dur, uint16 flag, const std::string &other_script, bool onskill) {
|
||||||
|
// Check if the same bonus already exists
|
||||||
|
for (auto &autobonus : bonus) {
|
||||||
|
// Compare based on bonus script
|
||||||
|
if (script == autobonus->bonus_script) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (bonus.size() == MAX_PC_BONUS) {
|
if (bonus.size() == MAX_PC_BONUS) {
|
||||||
ShowWarning("pet_addautobonus: Reached max (%d) number of petautobonus per pet!\n", MAX_PC_BONUS);
|
ShowWarning("pet_addautobonus: Reached max (%d) number of petautobonus per pet!\n", MAX_PC_BONUS);
|
||||||
return false;
|
return false;
|
||||||
@ -2395,11 +2403,16 @@ void pet_delautobonus(map_session_data &sd, std::vector<std::shared_ptr<s_petaut
|
|||||||
|
|
||||||
if (b->timer != INVALID_TIMER && !b->bonus_script.empty() && restore) {
|
if (b->timer != INVALID_TIMER && !b->bonus_script.empty() && restore) {
|
||||||
script_run_petautobonus(b->bonus_script, sd);
|
script_run_petautobonus(b->bonus_script, sd);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (restore) {
|
||||||
|
it++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
it = bonus.erase(it);
|
it = bonus.erase(it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute petautobonus on player.
|
* Execute petautobonus on player.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user