Topic: [Code] Potions and how best to implement them
I have a question, I want to make all sorts of potions, both ordinary without functions and with them
Plans:
- Without Enums
- Without Enums name
- Any effect writing it, in GiveEffect
- Counting the number of effects is easy
Example GiveEffect("Dance", 10); and player got effect dance
Now i use, but I don't know if it's safe
Need advice on how to optimize this, and how to protect it
I am use std::map
There are no problems with the operation of this code.
player.cpp in tick
if(Server()->Tick() % Server()->TickSpeed() == 0)
{
for(auto const& x : m_Effect)
{
if(m_Effect.find(x.first) != m_Effect.end())
{
if(!strcmp(x.first, "poison"))
{
// effect poison
}
// idk
m_Effect[x.first]--;
if(m_Effect[x.first] <= 0)
m_Effect.erase(m_Effect.find(x.first));
}
}
}
player.h
Private:
std::map < const char * , int > m_Effect;
Public:
void GiveEffect(const char* Effect, int Sec);
function:
void CPlayer::GiveEffect(const char* Effect, int Sec)
{
m_Effect[Effect] = Sec;
}