Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. /**
  2. * Input:
  3. * cth : chance to hit, 0-100.
  4. * karma : the player's karma rating before attacking
  5. * Output:
  6. * karma : the player's karma rating after attacking
  7. * return : whether or not this attack hit
  8. */
  9. bool attack(int cth, int& karma)
  10. {
  11. int rng = rand() % 100;
  12. int revise_cth = max(5,min(95,cth+karma*min(cth,100-cth)/100));
  13. bool hit = (rng < revised_cth);
  14.  
  15. //update karma
  16. if(hit)
  17. karma -= (100-cth); //chance to miss
  18. else
  19. karma += cth;
  20.  
  21. return hit;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement