Page 1 of 1
Saving Player buffs to give them later
Posted: Fri Nov 14, 2014 3:07 pm
by HappyLDE
Hello i want to store the character buffs and when needed give them back:
Code: Select all
Map<Integer, BuffInfo> buffs = activeChar.getEffectList().getBuffs(); activeChar.sendMessage("buffs count "+buffs.size()); activeChar.stopAllEffects(); activeChar.sendMessage("buffs count "+buffs.size()); for (Entry<Integer, BuffInfo> entry : buffs.entrySet()) { try { SkillData.getInstance().getSkill(entry.getValue().getSkill().getId(), entry.getValue().getSkill().getLevel()).applyEffects(activeChar, activeChar); } catch (RuntimeException e) { } }
But after stopAllEffects(), buffs.size() gets to zero, therefore no buffs in my list to give back, what should i do?
Re: Saving Player buffs to give them later
Posted: Fri Nov 14, 2014 3:58 pm
by UnAfraid
Map<Integer, BuffInfo> buffs = activeChar.getEffectList().getBuffs();
its not a copy its reference
Re: Saving Player buffs to give them later
Posted: Fri Nov 14, 2014 4:03 pm
by HappyLDE
How to make a copy instead of references? Thank you very much for answer

Re: Saving Player buffs to give them later
Posted: Fri Nov 14, 2014 4:50 pm
by Starter
Add player buffs to a list like this:
Code: Select all
for (L2Effect effect : playerInstance.getAllEffects()) { if (effect == null) continue; playerInstance._buffs.addIfAbsent(effect); }
?
Re: Saving Player buffs to give them later
Posted: Fri Nov 14, 2014 4:52 pm
by UnAfraid
Starter wrote:Add player buffs to a list like this:
Code: Select all
for (L2Effect effect : playerInstance.getAllEffects()) { if (effect == null) continue; playerInstance._buffs.addIfAbsent(effect); }
?
Hell no!
If you need it a list: List<BuffInfo> buffs = new ArrayList<>(activeChar.getEffectList().getBuffs().values());
if you need it as map: Map<Integer, BuffInfo> buffs = new HashMap<>(activeChar.getEffectList().getBuffs());
Re: Saving Player buffs to give them later
Posted: Fri Nov 14, 2014 4:54 pm
by Starter
UnAfraid wrote:Starter wrote:Add player buffs to a list like this:
Code: Select all
for (L2Effect effect : playerInstance.getAllEffects()) { if (effect == null) continue; playerInstance._buffs.addIfAbsent(effect); }
?
Hell no!
List<BuffInfo> buffs = new ArrayList<>(activeChar.getEffectList().getBuffs().values());
What about:
public final CopyOnWriteArrayList<L2Effect> _buffs = new CopyOnWriteArrayList<L2Effect>();
Added in l2pcinstance. Dont remember atm why I did it that way in the past but I think it was the best solution avoiding several bad situations.
Re: Saving Player buffs to give them later
Posted: Fri Nov 14, 2014 4:55 pm
by UnAfraid
Not needed to be thread safe since hes going to use it right away.
BTW xban1x made an effect that restores canceled effects after some time u may want to check it
Re: Saving Player buffs to give them later
Posted: Fri Nov 14, 2014 6:35 pm
by Starter
Cant, I have a ban allergy.
Re: Saving Player buffs to give them later
Posted: Fri Nov 14, 2014 8:49 pm
by HappyLDE
Thank you guys that did it and now works!!

Re: Saving Player buffs to give them later
Posted: Fri Nov 14, 2014 9:01 pm
by Starter
HappyLDE wrote:Thank you guys that did it and now works!!

like
Re: Saving Player buffs to give them later
Posted: Fri Nov 14, 2014 9:37 pm
by HappyLDE
UnAfraid wrote:Not needed to be thread safe since hes going to use it right away.
BTW xban1x made an effect that restores canceled effects after some time u may want to check it
What if i don't give them back right away but in 10 hours, is that bad?
Re: Saving Player buffs to give them later
Posted: Sat Nov 15, 2014 1:16 am
by Zoey76
Check StealAbnormal, that's a perfect example.
