Jump to content

Fixing Immune Bug


Think

Recommended Posts

Well, I've been meaning to share an actual fix after seeing different attempts at it (one or two which were totally off and decided to remove some code, and the other which recalculated the flag on each check), so here it goes:

 

The bug: If you equip an item without immune after equipping another one with immune, you lose your immune. Internally, the problem is that your immune flag gets recalculated every time you equip an item, but it bases off the proto immunes, forgetting completely about the actual bonuses on the item.

 

The solution itself is rather short!

 

In the functions CItem::EquipTo and CItem::Unequip (in item.cpp)

Find:

SET_BIT(dwImmuneFlag, m_pOwner->GetWear(i)->m_pProto->dwImmuneFlag);

Replace with:

SET_BIT(dwImmuneFlag, m_pOwner->GetWear(i)->GetRealImmuneFlag());

Then add the function referred up there to item.cpp:

DWORD CItem::GetRealImmuneFlag() 
{
	DWORD dwImmuneFlag = m_pProto->dwImmuneFlag;
	for (int i = 0; i < ITEM_ATTRIBUTE_MAX_NUM; ++i)
	{
		if (GetAttributeType(i))
		{
			const TPlayerItemAttribute& ia = GetAttribute(i);

			if (ia.bType == APPLY_IMMUNE_STUN && !IS_SET(dwImmuneFlag, IMMUNE_STUN))
				SET_BIT(dwImmuneFlag, IMMUNE_STUN);
			else if (ia.bType == APPLY_IMMUNE_FALL && !IS_SET(dwImmuneFlag, IMMUNE_FALL))
				SET_BIT(dwImmuneFlag, IMMUNE_FALL);
			else if (ia.bType == APPLY_IMMUNE_SLOW && !IS_SET(dwImmuneFlag, IMMUNE_SLOW))
				SET_BIT(dwImmuneFlag, IMMUNE_SLOW);
		}
	}

	return dwImmuneFlag;
}

As a new function, it also needs to have an entry on item.h, so find:

long		GetLimitValue(DWORD idx) const { return m_pProto ? m_pProto->aLimits[idx].lValue : 0;	}

And add afterwards:

DWORD        GetRealImmuneFlag();

That's about it.

 

I hope I am not missing anything, as we no longer have the original commit history anymore. If this is not enough, please tell me in the comments, I'll recheck again.

 

Now, as a final note, since I criticized the other solutions (Though only one actually works) I will also go a bit against mine: Is this the best solution possible? It's probable that the answer is no, and that the really best solution involves changes in the point system as a whole. That is however more messy and error prone, so I stayed out of it for the time being.

 

Anyway, hope it helps. Regards!

  • Love 10
Link to comment
Share on other sites

  • Premium

No. Is not good at all.

Why?

First of all you did not checked the protos!!!! You must check them aswell.

Second: if i have two items with immune ( like armor and shield with stun immune) and i remove one my imunne will be gone... i guess.

Third thing: if i have two immunes ( slow and stun) your code will apply only the first one.

Tell me if i am wrong. I am on the phone.

Yeah. My code may involve performance issues because will check everytime player will get hitted by a stun-hit if they don't have imunne at all. But i did some work on my computer: a variable which is true when the flags are updated for the current equipment and changes to false when the player changes his equipment.

Link to comment
Share on other sites

No. Is not good at all.

Why?

First of all you did not checked the protos!!!! You must check them aswell.

Second: if i have two items with immune ( like armor and shield with stun immune) and i remove one my imunne will be gone... i guess.

Third thing: if i have two immunes ( slow and stun) your code will apply only the first one.

Tell me if i am wrong. I am on the phone.

Yeah. My code may involve performance issues because will check everytime player will get hitted by a stun-hit if they don't have imunne at all. But i did some work on my computer: a variable which is true when the flags are updated for the current equipment and changes to false when the player changes his equipment.

First of all, I clearly did. I would ask you to please check the code.

Second, you guessed wrong? Recheck how bits are set and how the bit logic works!

To reassure you, this fix has been running on WoM since March and all immunes worked fine.

And I don't really understand what you mean about the work you did on your computer.

@metin2team: no, else if does not need to be if. Each attribute can only be one type of immune at the same time!

Link to comment
Share on other sites

  • Premium

In proto exists two types of immune flags: first flag is on "immuneFlag" row and the second is on the applytype/value. You checked only the "immuneFlag" row.

If I equip armor and shield, both with stun immune flag and I unequip only one will be the immune flag still there?

PS: I've told you that I am on my phone... so I can't check entire game source. Sorry. And about my work: i fixed performance issues from my code on my game.

Link to comment
Share on other sites

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.