Thread: Racial Spells
View Single Post
  #3  
Old 12-01-2015, 07:49 PM
Charles082986
Sarnak
 
Join Date: Dec 2010
Posts: 46
Default

So I could put the race check in either the class/level check section on line 1135 or in the scribing section of the switch statement. I have no clue what coding standards or practices you guys like to follow here. I work as a full stack web developer (though primarily using C# and .NET technologies instead of open source alternatives), so our approaches may be a little different.

Code:
case memSpellScribing:	{	// scribing spell to book
	const ItemInst* inst = m_inv[MainCursor];

	if(inst && inst->IsType(ItemClassCommon))
	{
		const Item_Struct* item = inst->GetItem();
                
		if(item && item->Scroll.Effect == (int32)(memspell->spell_id))
		{
                        // new code
                        bool raceAllowed = false;
                        uint32 Race_ = GetArrayRace(GetRace());
                        uint32 Races_ = item->Races;
                        Race_ = (Race_ == 18 ? 16 : Race_);
                        for(unsigned int CurrentRace = 1; CurrentRace <= PLAYER_RACE_COUNT; ++CurrentRace){
                                if(Races_ & 1){
                                        if(Race_ == CurrentRace){
                                                raceAllowed = true;
                                                break;
                                        }
                                }
                                Races_ >>= 1;
                        }
                        if(!raceAllowed){
                                Message(0,"Your class/race/deity cannot use this spell.");
                                break;
                        }
                        // end new code
			ScribeSpell(memspell->spell_id, memspell->slot);
			DeleteItemInInventory(MainCursor, 1, true);
		}
		else
			Message(0,"Scribing spell: inst exists but item does not or spell ids do not match.");
	}
	else
		Message(0,"Scribing a spell without an inst on your cursor?");
	break;
}
I opted to put it in the scribing section because there's already a reference to the item on the cursor and it involves a loop, which for performance reasons I'd only like to hit in the event someone is actually scribing a spell instead of every time someone tries to memorize OR scribe a spell.

I pulled the race check from here: https://github.com/EQEmu/Server/blob...item.cpp#L2356

If there's a simpler or more efficient way of checking the race against the spell scroll race slot, I'm not sure where it would be. Also, this is my first time working with C++, so I made most of my assumptions based on my knowledge of C#. If someone could review it I would be very appreciative.
Reply With Quote