PDA

View Full Version : Very simple attack.cpp question (adding crit)


laxative
08-25-2015, 11:09 AM
Hi

Been away for a LONG time. I just want to remember if I get the jist of things here...

Let's say I want to add a base crit chance to paladins(ok shd too). (I know it's humorous)

From all that I understand (which is very little) .. modify the attack.cpp and add some new rules.

modify this:
if (((GetClass() == WARRIOR || GetClass() == BERSERKER) && GetLevel() >= 12) || IsBerskerSPA) {
if (IsBerserk() || IsBerskerSPA)
critChance += RuleI(Combat, BerserkBaseCritChance);
else
critChance += RuleI(Combat, WarBerBaseCritChance);

to this

if (((GetClass() == WARRIOR || GetClass() == BERSERKER || GetClass() == Paladin || GetClass() == ShadowKnight) && GetLevel() >= 12) || IsBerskerSPA) {
if (IsBerserk() || IsBerskerSPA)
critChance += RuleI(Combat, BerserkBaseCritChance);
elseif
critChance += RuleI(Combat, PalShdBaseCritChance);
else
critChance += RuleI(Combat, WarBerBaseCritChance);

Add the appropriate rule to the rules table; PalShdBaseCritChance

Would this fly?

-lax

laxative
08-25-2015, 12:11 PM
well the else statement is wrong, and I had to add the int to the rules and recompile.. let's see if that worked,,. aha

laxative
08-25-2015, 12:22 PM
holy crap, that actually worked (I simply replaced the warrior section with the edited paladin section)

-- edited attack.cpp
-- edited rulestype.h
-- added the three entries in the database for rule sets 1,2,10

voila level 12 paladin critical hitting. Made me happy.

I suppose i should probably make ruleset 5 and just modify one set :)

-lax

Shendare
08-25-2015, 12:23 PM
Yeah, you left out the condition for the 'elseif', and in C++ it needs a space. The class constants are also all uppercase, per C standards.

You'd want that line to read:


else if (GetClass() == PALADIN || GetClass() == SHADOWKNIGHT)


And you'd want to fully capitalize them in the first 'if' statement as well.

Shendare
08-25-2015, 12:26 PM
... Did it work without the changes I suggested?

laxative
08-25-2015, 01:44 PM
Shendare,

Wow, I thought this forum was all but dead., thanks for such a quick response. !

I quickly get lost with all the elseing and elseif'ing so I tidied it up a bit. I missed a parantheses my first time and noticed my new level limitation wasn't working (going to give paladins and sk's crit at 15 and not 12)

so edited attack.cpp to read this:

if (IsClient()) {
critChance += RuleI(Combat, ClientBaseCritChance);

if (spellbonuses.BerserkSPA || itembonuses.BerserkSPA || aabonuses.BerserkSPA)
IsBerskerSPA = true;

if (((GetClass() == WARRIOR || GetClass() == BERSERKER) && GetLevel() >= 12) || IsBerskerSPA) {
if (IsBerserk() || IsBerskerSPA)
critChance += RuleI(Combat, BerserkBaseCritChance);
else
critChance += RuleI(Combat, WarBerBaseCritChance);
}
if (((GetClass() == PALADIN || GetClass() == SHADOWKNIGHT) && GetLevel() >= 15))
critChance += RuleI(Combat, PalShdBaseCritChance);

I'm thinking I don't understand this segment properly:: the note in this section states that there is the innate chance to score a crit.

How would that be possible since:
clientbasecritchance and meleebasecritchance in my rules are zero.

Shendare
08-25-2015, 01:54 PM
Looks like it's saying that IF you define crit chance percentages for MeleeBaseCritChance or ClientBaseCritChance, melees (or everyone) will have an innate chance to crit at level 1, with melees getting the sum of the two rule values as their innate crit chance.

A little farther down, Rangers get a chance to crit archery at level 65, and Rogues get a chance to crit throwing at level 65.

Then any aa's, item bonuses, or crit chance buffs come into play to result in the final chance to critical hit.

The way you've coded it up there now looks like it should work fine!

laxative
08-25-2015, 02:05 PM
Thank you,

So.. do entries of Zero "0" (not a null entry) an actual zero count as being defined? I would say yes..?

That's what's striking me, my crit chance should be less than a 1.0% according to the documentation, based on loose parsing I'm around 20% 1 in 5 roughly..

Shendare
08-25-2015, 02:12 PM
No. If you don't define a rule at all, it falls back to the default hard-coded in the server code, which is likely zeroes as well.

So, you're seeing a 20% crit rate on a Paladin with these settings?

* MeleeBaseCritChance = 0
* ClientBaseCritChance = 0
* BerserkBaseCritChance = 6 (the default, active when you're berzerk)
* WarBerBaseCritChance = 3 (the default)
* PalShdBaseCritChance = 1 (your new rule)

* No equipped items granting +crit chance
* No active buffs granting +crit chance
* No AA's granting crit chance

laxative
08-25-2015, 02:21 PM
Oh my, you are quick on the draw.

MeleeBaseCritChance=0
ClientBaseCritChance=0
BeserkBaseCritChance=7 (i added one)
WarBerBaseCritChance=5 (added one)
PalShdBaseCritChance=4 (want them only a step behind warriors)

Too Generous? :) but I deleveled the paladin all the way to level 1 up through 16 crit rate is similar.. no exact parses.

I'd probably prefer no crits at all till a certain level, then you get class base chance + dex

Shendare
08-25-2015, 02:33 PM
That certainly doesn't seem to mesh with what you're going for, or what you've coded. It looks like a Paladin shouldn't crit at all until level 15, and then they'd have:

* A 4% base chance from the new rule
* +1% for each 125 points of DEX up to 255 (Max 2%)
* +1% for each 500 points of DEX after 255

20% doesn't make sense with those numbers. 10% doesn't even make sense.

You mind copy/pasting your full TryCriticalHit() function into a Code block?

laxative
08-25-2015, 02:51 PM
Definitely and Thank you as I'm with you, my percent should be around .6% at best (assuming innate crits based on dex)



But I want nothing till 15.. here is the block from attack.cpp

//2: Try Melee Critical

//Base critical rate for all classes is dervived from DEX stat, this rate is then augmented
//by item,spell and AA bonuses allowing you a chance to critical hit. If the following rules
//are defined you will have an innate chance to hit at Level 1 regardless of bonuses.
//Warning: Do not define these rules if you want live like critical hits.
critChance += RuleI(Combat, MeleeBaseCritChance);

if (IsClient()) {
critChance += RuleI(Combat, ClientBaseCritChance);

if (spellbonuses.BerserkSPA || itembonuses.BerserkSPA || aabonuses.BerserkSPA)
IsBerskerSPA = true;

if (((GetClass() == WARRIOR || GetClass() == BERSERKER) && GetLevel() >= 12) || IsBerskerSPA) {
if (IsBerserk() || IsBerskerSPA)
critChance += RuleI(Combat, BerserkBaseCritChance);
else
critChance += RuleI(Combat, WarBerBaseCritChance);
}
if (((GetClass() == PALADIN || GetClass() == SHADOWKNIGHT) && GetLevel() >= 15))
critChance += RuleI(Combat, PalShdBaseCritChance);
}

int deadlyChance = 0;
int deadlyMod = 0;
if(skill == SkillArchery && GetClass() == RANGER && GetSkill(SkillArchery) >= 65)
critChance += 6;

if (skill == SkillThrowing && GetClass() == ROGUE && GetSkill(SkillThrowing) >= 65) {
critChance += RuleI(Combat, RogueCritThrowingChance);
deadlyChance = RuleI(Combat, RogueDeadlyStrikeChance);
deadlyMod = RuleI(Combat, RogueDeadlyStrikeMod);
}

int CritChanceBonus = GetCriticalChanceBonus(skill);

if (CritChanceBonus || critChance) {

//Get Base CritChance from Dex. (200 = ~1.6%, 255 = ~2.0%, 355 = ~2.20%) Fall off rate > 255
//http://giline.versus.jp/shiden/su.htm , http://giline.versus.jp/shiden/damage_e.htm
if (GetDEX() <= 255)
critChance += (float(GetDEX()) / 125.0f);
else if (GetDEX() > 255)
critChance += (float(GetDEX()-255)/ 500.0f) + 2.0f;
critChance += critChance*(float)CritChanceBonus /100.0f;
}

if(opts) {
critChance *= opts->crit_percent;
critChance += opts->crit_flat;
}

I stopped where it starts calculating crippling blows

Shendare
08-25-2015, 02:57 PM
Really don't see anything wrong there.

This is you playing a Paladin, right? Not a bot or npc or merc?

laxative
08-25-2015, 03:40 PM
Correct, I just did a completely (I mean complete) setup, wiped the datebase, downloaded and compiled all new code.

I did not however delete my client profile files on my local client (the windows and views were all set) but I was not getting any crits until I modified this file.

Shendare
08-25-2015, 03:44 PM
Take a look and Verify the rule values in your database and the ruleset you're using, and make sure you've shut the server software down and started it back up, with shared_memory being the first executable loading. Verify that the ruleset you're seeing there is the same as what you're expecting from the rule_values table. Also verify the ruleset field in the zone you're fighting in.

laxative
08-25-2015, 04:42 PM
odd..

gotta go for now.. but I closed sql workbench, opened PEQ back up.

my variables are not there.. (in the database)

so that's definately off, the code compiles as the variables are defined properly in the rules, but if I'm believing this.. the database entries never made it properly....

icky.. I'll see about cleaning that up.

the zones I was testing in are using rule set 1 or 2 I **thought** i entered the PalShdBaseCritChance for rule sets 1,2, and 10.

More testing to come.

Thankyou!

laxative
08-26-2015, 08:45 AM
Rules were there, I wasnt returning enough rows in SQL workbench. Going to remove the Paladin lines completely see what happens.

laxative
08-26-2015, 08:58 AM
OK removed the code referencing the paladin, recompiled and tested. No Crits *level 8*
Leveled myself to 16, just to be sure there was no linkage to level 12.. no difference.

So a few possibilites: Innate dex crit calc not working.

Perhaps I need to modify the meleebasecritchance and/or clientbasecritchance to something like .001 instead of a zero. ?

My code didnt seem to take level into effect as I was critting at level 1.

Based on all that, it looks like the innate dex calc is off?

Is there a way to see the variable value in flight?

laxative
08-26-2015, 10:34 AM
Made a change and does appear to be working now.

I put the pal/sk check in the first if statement as follows:

if ((GetClass() == PALADIN || GetClass() == SHADOWKNIGHT) && GetLevel() >= 15)
critChance += RuleI(Combat, PalShdBaseCritChance);

That seemed to do the trick. The testing was much more in line with expectations. I started at level 14 and go no crits in 3 mobs over 50 swings.

Leveled up to 15, got a crit after 5 strikes, but then it went to 1 in under 20.

Not sure why the order of the statement made that much impact but it's working as I intended.

Now to improve paladin's hit chances closer to warriors.. time to sniff through more code..

-lax