Critical Hits
Hey everyone, we're going to be adding critical hits to our Project Insanity source today!
It will make you hit a whole lot harder then what you would have done, we aren't going to add the orange hit splatters because we are trying to add this for new coders. If you are advanced with the Java language and don't know how to add this, then you must not have worked with combat very much.
Enough talk, lets get started!
First:
Go into your CombatAssistant.java (server > src > models > player > CombatAssistant.java) and add this code somewhere:
This is the boolean that you will use with a true-false statement into other calculations on here. This code is what your other ranged and melee attack will be depending on to receive a critical strike. So you will absolutely need this code if you want to add this.Code:public boolean CalculateCriticalDamage(Client c) { int CriticalDamage = Misc.random(100); if (CriticalDamage > 99) return true; else return false; }
That gives it a 1-100% chance of actually hitting the critical.Code:int CriticalDamage = Misc.random(100);
This makes it a 1% chance of actually getting that critical hit to go through.Code:if (CriticalDamage > 99)
Second:
Still in CombatAssistant.java add this:
This is what will add the damage applied. It's not a very big code, so I cannot explain it thoroughly like I have with the other codes I put and am putting. But; this applies the damage necessary for your critical strikes. If you cease to leave this code snippet out, you will not see any differences in your hits.Code:public int CalculateCriticalDamage(Client c, int Damage, String type) { return Damage += Damage; }
Third:
Still in your CombatAssistant.java you will need to add this:
Now, this code is actually redundant; it makes you gloat about your critical hit. It will make you say either "Melee Critical!" or "Ranged Critical!" Either way, I still added this more as proof that the person hit a critical, instead of using a sendMessage code saying he did then your player could simply say, "I just hit a critical." But with this code, they really cannot lie about hitting a critical.Code:public void sendCriticalDamageGloating(Client c, String CombatStyle) { if (CombatStyle == "Ranged") { c.forcedText = "Ranged Critical!"; c.forcedChatUpdateRequired = true; c.updateRequired = true; } if (CombatStyle == "Melee") { c.forcedText = "Melee Critical!"; c.forcedChatUpdateRequired = true; c.updateRequired = true; } }
So that's why this code is in here, and it's not that complicated to add, just something extra I though you guys might like.
Fourth:
Still in CombatAssistant class, search for this:
Under it, add this:Code:int MeleeDamage = (int) Math.floor(maxHit);
This is actually applying the critical damage when it happens.Code:int MeleeDamage = (int) Math.floor(maxHit); CalculateCriticalDamage(c); if (CalculateCriticalDamage(c)) { sendCriticalDamageGloating(c, "Melee"); return CalculateCriticalDamage(c, MeleeDamage, "Melee"); } else return (int) Math.floor(maxHit); }
Is sending your gloating, so the person will say "Melee Critical!" once a critical hit happens.Code:sendCriticalDamageGloating(c, "Melee");
This is applying the critical damage that happens. Now when you hit a critical, this is the code that will actually apply the damage.Code:return CalculateCriticalDamage(c, MeleeDamage, "Melee");
Fifth:
Yet again, in CombatAssistant class search for:
Under that, add this:Code:int RangedDamage = (int) max;
This is actually applying the critical damage when it happens.Code:CalculateCriticalDamage(c); if (CalculateCriticalDamage(c)) { sendCriticalDamageGloating(c, "Ranged"); return CalculateCriticalDamage(c, RangedDamage, "Ranged"); } else return (int) max; }
Is sending your gloating, so the person will say "Ranged Critical!" once a critical hit happens.Code:sendCriticalDamageGloating(c, "Ranged");
This is applying the critical damage that happens. Now when you hit a critical, this is the code that will actually apply the damage.Code:return CalculateCriticalDamage(c, MeleeDamage, "Ranged");
You've successfully added critical hits to your Project Insanity! If you have any errors at all, please post it below. I am a pretty friendly guy and I'm only here to help, so again; any errors, post them. I will try to help you out through all your problems. I could usually figure out all of them, but if I can't, then I'm very sorry. But I will give it my best, so please post all your errors!



Reply With Quote![[Project Insanity]Critical Hits](http://ragezone.com/hyper728.png)

