The code below has been tested and works. But, there is one huge bug that still needs to be corrected before this can be added to the SVN. Currently, it works perfectly, accept if you have an empty primary slot. If the primary slot is empty and you run this command, it crashes the zone.
I will work on resolving the zone crash issue. If anyone has a suggestion, I would be willing to try it. Once I have a good solution, I will edit the code in this post to be the good code.
Also, note that I currently have 3 versions of attack showing on the command output. We can probably leave Worn Attack and Total Attack in there, but in the final version, we probably don't need the server seen attack rating. That is mostly just there for my testing purposes.
I still need to figure out the formula for attack rating caps, but I don't think that will be too hard. Once that is all done, I think this new formula should be pretty complete and fairly accurate.
EDIT: This code is now complete, tested and very accurate. All issues, including the crash and worn caps have been resolved. This has been added to the SVN in Revision. The only minor tweak left to correct is for +attack from spells that can exceed cap, such as Avatar/Champion.
mob.cpp
Code:
void Mob::ShowStats(Client* client) {
int16 attackRating = 0;
int16 WornCap = GetATK();
if(IsClient())
attackRating = GetATK() + ((GetSTR() + GetSkill(OFFENSE)) * 9 / 10);
else
attackRating = GetATK() + (GetSTR() * 9 / 10);
if(WornCap > 250)
WornCap = 250;
client->Message(0, "Name: %s %s", GetName(), lastname);
client->Message(0, " Level: %i MaxHP: %i CurHP: %i AC: %i Class: %i", GetLevel(), GetMaxHP(), GetHP(), GetAC(), GetClass());
client->Message(0, " MaxMana: %i CurMana: %i Size: %1.1f", GetMaxMana(), GetMana(), GetSize());
client->Message(0, " Total ATK: %i Worn ATK: %i Worn ATK Capped: %i Server Used ATK: %i", this->CastToClient()->GetTotalATK(), GetATK(), WornCap, attackRating);
client->Message(0, " STR: %i STA: %i DEX: %i AGI: %i INT: %i WIS: %i CHA: %i", GetSTR(), GetSTA(), GetDEX(), GetAGI(), GetINT(), GetWIS(), GetCHA());
client->Message(0, " MR: %i PR: %i FR: %i CR: %i DR: %i", GetMR(), GetPR(), GetFR(), GetCR(), GetDR());
client->Message(0, " Race: %i BaseRace: %i Texture: %i HelmTexture: %i Gender: %i BaseGender: %i", GetRace(), GetBaseRace(), GetTexture(), GetHelmTexture(), GetGender(), GetBaseGender());
client->Message(0, " Last Warp Distance: %f Threshold Remaining: %f", GetLWDistance(), GetWarpThreshold());
if (client->Admin() >= 100) {
client->Message(0, " EntityID: %i PetID: %i OwnerID: %i AIControlled: %i", this->GetID(), this->GetPetID(), this->GetOwnerID(), this->IsAIControlled());
if (this->IsClient()) {
client->Message(0, " CharID: %i PetID: %i", this->CastToClient()->CharacterID(), this->GetPetID());
client->Message(0, " Endurance: %i, Max Endurance %i",client->GetEndurance(), client->GetMaxEndurance());
}
else if (this->IsCorpse()) {
if (this->IsPlayerCorpse()) {
client->Message(0, " CharID: %i PlayerCorpse: %i", this->CastToCorpse()->GetCharID(), this->CastToCorpse()->GetDBID());
}
else {
client->Message(0, " NPCCorpse", this->GetID());
}
}
else if (this->IsNPC()) {
int32 spawngroupid = 0;
if(this->CastToNPC()->respawn2 != 0)
spawngroupid = this->CastToNPC()->respawn2->SpawnGroupID();
client->Message(0, " NPCID: %u SpawnGroupID: %u LootTable: %u FactionID: %i SpellsID: %u MerchantID: %i", this->GetNPCTypeID(),spawngroupid, this->CastToNPC()->GetLoottableID(), this->CastToNPC()->GetNPCFactionID(), this->CastToNPC()->GetNPCSpellsID(),this->CastToNPC()->MerchantType);
client->Message(0, " Accuracy: %i", CastToNPC()->GetAccuracyRating());
}
if (this->IsAIControlled()) {
client->Message(0, " AIControlled: AggroRange: %1.0f AssistRange: %1.0f", this->GetAggroRange(), this->GetAssistRange());
}
}
}
client.cpp
Code:
uint16 Client::GetPrimarySkillValue()
{
SkillType skill = HIGHEST_SKILL; //because NULL == 0, which is 1H Slashing, & we want it to return 0 from GetSkill
bool equiped = m_inv.GetItem(13);
if (!equiped)
skill = HAND_TO_HAND;
else {
uint8 type = m_inv.GetItem(13)->GetItem()->ItemType; //is this the best way to do this?
switch (type)
{
case ItemType1HS: // 1H Slashing
{
skill = _1H_SLASHING;
break;
}
case ItemType2HS: // 2H Slashing
{
skill = _2H_SLASHING;
break;
}
case ItemTypePierce: // Piercing
{
skill = PIERCING;
break;
}
case ItemType1HB: // 1H Blunt
{
skill = _1H_BLUNT;
break;
}
case ItemType2HB: // 2H Blunt
{
skill = _2H_BLUNT;
break;
}
case ItemType2HPierce: // 2H Piercing
{
skill = PIERCING;
break;
}
case ItemTypeHand2Hand: // Hand to Hand
{
skill = HAND_TO_HAND;
break;
}
default: // All other types default to Hand to Hand
{
skill = HAND_TO_HAND;
break;
}
}
}
return GetSkill(skill);
}
uint16 Client::GetTotalATK()
{
int16 AttackRating = 0;
int16 WornCap = GetATK();
if(WornCap > 250)
WornCap = 250;
if(IsClient()) {
AttackRating = ((WornCap * 1.342) + (GetSkill(OFFENSE) * 1.345) + ((GetSTR() - 66) * 0.9) + (GetPrimarySkillValue() * 2.69));
if (AttackRating < 10)
AttackRating = 10;
}
else
AttackRating = GetATK() + (GetSTR() * 9 / 10);
return AttackRating;
}
client.h - Anywhere in the file
Code:
//This calculates total Attack Rating to match very close to what the client should show
uint16 GetTotalATK();
//This gets the skill value of the item type equiped in the Primary Slot
uint16 GetPrimarySkillValue();