Last active
August 29, 2015 13:56
-
-
Save mackal/9045043 to your computer and use it in GitHub Desktop.
Used for testing NPC resist on EQEmu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# vim:fenc=utf-8 | |
# | |
# Copyright © 2014 Michael Cook <mcook@mackal.net> | |
# | |
# GPL whatever? | |
# used for testing NPC's resists | |
import random | |
def resist(level, caster_level, resist, damage_spell): | |
resistfalloff = 67 | |
# harmony spells default to 15 here | |
resist_chance = 0 | |
resist_modifier = 0 # some spells have a mod | |
target_resist = resist # this is the castee resist | |
temp_level_diff = level - caster_level | |
if level >= resistfalloff: | |
a = resistfalloff - 1 - caster_level | |
if a > 0: | |
temp_level_diff = a | |
else: | |
temp_level_diff = 0 | |
if temp_level_diff < -9: | |
temp_level_diff = -9 | |
level_mod = int(temp_level_diff * temp_level_diff / 2) | |
if temp_level_diff < 0: | |
level_mod = -level_mod | |
if caster_level - level < -20: | |
level_mod = 1000 | |
if damage_spell: | |
level_diff = 0 | |
if level >= resistfalloff: | |
level_diff = resistfalloff - 1 - caster_level | |
if level_diff < 0: | |
level_diff = 0 | |
else: | |
level_diff = level - caster_level | |
level_mod += (2 * level_diff) | |
resist_chance += level_mod | |
resist_chance += resist_modifier | |
resist_chance += target_resist | |
# min/max resist checks | |
# resist roll (0, 200) | |
return resist_chance | |
def main(): | |
# hardcoded stuff, change to test other settings | |
resist_chance = resist(71, 65, 200, False) | |
print('Resist chance: ' + str(resist_chance)) | |
tally = 0 | |
print('predicted percentage: ' + str(0.0 if resist_chance >= 200 else (200 - resist_chance) / 2.0) + '%') | |
for i in range(0, 1000000): | |
if random.randint(0, 200) > resist_chance: | |
tally += 1 | |
print('total landed: ' + str(tally)) | |
print('observed percentage: ' + str(tally / 1000000.0 * 100) + '%') | |
return 0 | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment