here's the code that I use.
You might find it useful
It still needs to be tweaked a little i think. It's pretty good but not perfect.
-
- Enemy->OnBeAttacked( this );
- Position->destiny = Position->current;
- Log(MSG_DEBUG,"(NormalAttack) Destiny set to current position X: %f Y: %f.",Position->current.x,Position->current.y);
-
- // new formula
- float levelmult = (float) Stats->Level / Enemy->Stats->Level;
- if(levelmult > 2)levelmult = 2;
- float atkdefmult = 0;
- float attack = 0;
- float constant = 4;
- if(Stats->magicattack == 1)
- {
- atkdefmult = (float) Stats->Attack_Power / Enemy->Stats->Magic_Defense;
- }
- else
- {
- atkdefmult = (float) Stats->Attack_Power / Enemy->Stats->Defense;
- }
- attack = Stats->Attack_Power * levelmult * atkdefmult / constant;
-
- if(attack < 5) attack = 5;
- float d_attack = attack / 100;
- float mod = GServer->RandNumber( 0, 10 ) * d_attack;
- attack += mod;
- long int hitpower = (long int)floor(attack);
- if(IsPlayer( )) //temp fix to find balance btw monster and player
- {
- hitpower = (long int)floor(attack * (GServer->Config.PlayerDmg/100.00));
- hitpower+=((hitpower*(Stats->ExtraDamage))/100);
- }
- if(IsSummon( )) //temp fix to find balance btw monster and player
- {
- hitpower = (long int)floor(attack * (GServer->Config.PlayerDmg/100.00));
- //Log(MSG_DEBUG,"Summon hitpower = %i",hitpower);
- }
- if(IsMonster( )) //temp fix to find balance btw monster and player
- hitpower = (long int)floor(attack * (GServer->Config.MonsterDmg/100.00));
- bool critical = false;
- if(hitpower <= 5)
- {
- hitpower = 5;
- }
- else
- {
- if(GServer->RandNumber(0,300)<Stats->Critical)
- {
- hitpower = (long int)floor(hitpower * 1.5);
- critical = true;
- }
- }
- // dodge
- unsigned int hitvalue = (unsigned int)floor((double)(Stats->Accury * 40 / Enemy->Stats->Dodge));
- if(hitvalue > 100) hitvalue = 100;
- if(GServer->RandNumber( 0, 100 ) > hitvalue)
- hitpower = 0; // dodged
- if (hitpower > 0x7ff)//2047 packet size limit.
- {
- hitpower = 0x7ff;
- }
- Battle->atktarget = Battle->target;
-
- //if(IsMonster())
- //{
- //Log(MSG_INFO,"Monster hits player for %i damage. Attack target = %i",hitpower,Battle->atktarget);
- //}
- //Log( MSG_INFO, "hitpower %i. Attack %f ", hitpower,attack );
- if(!Enemy->IsSummon( ) && Enemy->IsMonster( ))
- {
- Enemy->AddDamage( this, hitpower );
- Enemy->damagecounter += hitpower;// is for AI
- }
- Enemy->Stats->HP -= hitpower;
- //if(IsPlayer())
- // Log(MSG_DEBUG,"Player attack did damage %i",hitpower);
- //if(IsMonster())
- // Log(MSG_DEBUG,"Monster attack did damage %i",hitpower);
-
I still have a load of debug outputs in this, some commented out but others active.
i don't think the dev rev actually loads in a value to define magic attack or normal attack so you will probably be missing
Stats->magicattack
The use of "constant" is what lets me adjust the formula easily. It is presently defined as 4 but you can play around with this and use any number you like.
Need to lookup information on NARose items, skills, quests?
Now featuring a newly completed skill tree for all classesFormatting fixed for different resolutions"A Gazelle is nothing but a giraffe plotted logarithmicaly"