Page 1 of 1
BUG:FIXED spells(buffs) and TS spells not stacking correctly
Posted: Thu Mar 07, 2019 3:40 pm
by Ememjr
so far none of the tradeskill buffs are stacking i created some test spells and when testing spell one stats go correctly bu when casting spell 2 spell 1 buffs disappear
also if i then cancel spell 2, spell 2 buffs reappear
please test and confirm
Re: BUG: spells(buffs) and TS spells not stacking correctly
Posted: Sat Mar 09, 2019 7:03 am
by Ememjr
i found the issue to apparently be in this code
Code: Select all
void Entity::CalculateSpellBonuses(ItemStatsValues* stats){
if(stats){
MutexList<BonusValues*>::iterator itr = bonus_list.begin();
vector<BonusValues*> bv;
//First check if we meet the requirement for each bonus
while(itr.Next()) {
int64 class1 = pow(2.0, (GetAdventureClass() - 1));
int64 class2 = pow(2.0, (classes.GetSecondaryBaseClass(GetAdventureClass()) - 1));
int64 class3 = pow(2.0, (classes.GetBaseClass(GetAdventureClass()) - 1));
if (itr.value->class_req == 0 || (itr.value->class_req & class1) == class1 || (itr.value->class_req & class2) == class2 || (itr.value->class_req & class3) == class3)
bv.push_back(itr.value);
}
//Sort the bonuses by spell id and luaspell
BonusValues* bonus;
map <int32, map<LuaSpell*, vector<BonusValues*> > > sort;
for (int8 i = 0; i < bv.size(); i++){
bonus = bv.at(i);
sort[bonus->spell_id][bonus->luaspell].push_back(bonus);
}
//Now check for the highest tier of each spell id and apply those bonuses
map<LuaSpell*, vector<BonusValues*> >::iterator tier_itr;
map <int32, map<LuaSpell*, vector<BonusValues*> > >::iterator sort_itr;
for (sort_itr = sort.begin(); sort_itr != sort.end(); sort_itr++){
LuaSpell* key;
sint8 highest_tier = -1;
//Find the highest tier for this spell id
for (tier_itr = sort_itr->second.begin(); tier_itr != sort_itr->second.end(); tier_itr++){
LuaSpell* current_spell = tier_itr->first;
sint8 current_tier ;
if (current_spell && ((current_tier = current_spell->spell->GetSpellTier()) > highest_tier)) {
highest_tier = current_tier;
key = current_spell;
}
}
//We've found the highest tier for this spell id, so add the bonuses
vector<BonusValues*>* final_bonuses = &sort_itr->second[key];
for (int8 i = 0; i < final_bonuses->size(); i++)
world.AddBonuses(stats, final_bonuses->at(i)->type, final_bonuses->at(i)->value, this);
}
}
}
in the for statement right after this line
//Find the highest tier for this spell id
both spells i want to stack pass through here the first spell will see that it is the highest tier
but the second spell which is different except for the bonus will think it is not the highest tier because highest tier was already set by the first spell
please help me what is wrong with it
Re: BUG: spells(buffs) and TS spells not stacking correctly
Posted: Sun Mar 10, 2019 12:37 am
by tyrbo
I thought you said they weren't the same spell though?
The sort map that is being iterated there is a map of spell IDs to LuaSpells/bonuses, so you should only see that behavior if you're trying to use the same spell but with a different version (like Adept vs Expert).
Re: BUG: spells(buffs) and TS spells not stacking correctly
Posted: Sun Mar 10, 2019 9:33 am
by Ememjr
tyrbo wrote: Sun Mar 10, 2019 12:37 am
I thought you said they weren't the same spell though?
The sort map that is being iterated there is a map of spell IDs to LuaSpells/bonuses, so you should only see that behavior if you're trying to use the same spell but with a different version (like Adept vs Expert).
exactly "should" but there is something wrong with it
Re: BUG: spells(buffs) and TS spells not stacking correctly
Posted: Sun Mar 10, 2019 4:41 pm
by Jabantiz
I see a mutex container in there, those cause all sorts of odd behavior so the first thing I would suggest doing is to replace it with a standard container and a mutex to wrap it, no clue how often this list is used so that itself could end up being a large change.
Re: BUG: spells(buffs) and TS spells not stacking correctly
Posted: Mon Mar 11, 2019 3:15 am
by Ememjr
Jabantiz wrote: Sun Mar 10, 2019 4:41 pm
I see a mutex container in there, those cause all sorts of odd behavior so the first thing I would suggest doing is to replace it with a standard container and a mutex to wrap it, no clue how often this list is used so that itself could end up being a large change.
perfect now i have to figure out what a mutex container is, and how to make it into a standard container, and then, how to wrap it in a mutex
do we have an expample of that in code elsewhere i could look at
Re: BUG: spells(buffs) and TS spells not stacking correctly
Posted: Mon Mar 11, 2019 4:07 am
by Ememjr
Yeah , I found the fix for this and will test and commit later
you will see from the earlier posted code that this line
Code: Select all
sort[bonus->spell_id][bonus->luaspell].push_back(bonus);
is referencing bonus->spell_id
but what i found when tracing the debug that spell_id was the same for everyspell passing through that line
so looking at the following code
Code: Select all
void Entity::AddSpellBonus(LuaSpell* spell, int16 type, sint32 value, int64 class_req){
CheckSpellBonusRemoval(spell, type);
BonusValues* bonus = new BonusValues;
bonus->spell_id = spell->spell->GetSpellID();
bonus->luaspell = spell;
bonus->type = type;
bonus->value = value;
bonus->class_req = class_req;
bonus->tier = spell ? spell->spell->GetSpellTier() : 0;
bonus_list.Add(bonus);
}
i found that this line was missing
Code: Select all
bonus->spell_id = spell->spell->GetSpellID();
once i added it in, all my tests of spell stacking started working
Re: BUG:FIXED spells(buffs) and TS spells not stacking correctly
Posted: Mon Mar 11, 2019 7:34 am
by Ememjr
I have committed a fix for this SVN it is included in SVN revision # 2798