pankration.py 75.3 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522
import random
import time
import pickle
import math
import collections
import logging
import operator

def log(message):
    try:
        print(message)
        logging.warning("{} - {}".format(datetime.datetime.now().strftime('%Y/%m/%d %H:%M:%S'), message))
    except:
        pass

ATTACK_EFFECT_PERCENTAGE = 25
FIND_PERCENTAGE = 80
SKILL_PERCENT = 60

class WeightedChoice(object):
    def __init__(self, weights):
        """Pick items with weighted probabilities.

            weights
                a sequence of tuples of item and it's weight.
        """
        self._total_weight = 0.
        self._item_levels = []
        for item, weight in weights.iteritems():
            self._total_weight += weight
            self._item_levels.append((self._total_weight, item))

    def pick(self):
        pick = self._total_weight * (random.randint(1, 10)/10)
        for level, item in self._item_levels:
            if level >= pick:
                return item

class HuntResponse:
    ERROR = -1
    FAILURE = 0
    SUCCESS = 1

    def __init__(self, result, message, monster):
        self.result = result
        self.message = message
        self.monster = monster

exp_to_level = [0, 500, 1250, 2250, 3500, 5000, 6750, 8750, 10950, 13350, 15950, 18750, 21750, 24950, 28350, 31950, 35750, 39750, 43950, 48350, 52950, 57750, 62750, 67850, 73050, 78350, 83750, 89250, 94850, 100550, 106350, 112250, 118250, 124350, 130550, 136850, 143250, 149750, 156350, 163050, 169850, 176750, 183750, 190850, 198050, 205350, 212750, 220250, 227850, 235550, 243350]

exp_table = {
    15: 600, 
    14: 600,
    13: 600,
    12: 600,
    11: 600,
    10: 600,
    9: 600,
    8: 600,
    7: 550,
    6: 450,
    5: 350,
    4: 300,
    3: 240,
    2: 220,
    1: 210,
    0: 200,
    -1: 180,
    -2: 160,
    -3: 150,
    -4: 140,
    -5: 130,
    -6: 120,
    -7: 110,
    -8: 100,
    -9: 80,
    -10: 60,
    -11: 40,
    -12: 40,
    -13: 40,
    -14: 40,
    -15: 20,
}
class Jobs:
    BLM = 1
    BLU = 2
    BRD = 3
    BST = 4
    COR = 5
    DNC = 6
    DRG = 7
    DRK = 8
    GEO = 9
    MNK = 10
    NIN = 11
    PLD = 12
    PUP = 13
    RDM = 14
    RNG = 15
    RUN = 16
    SAM = 17
    SCH = 18
    SMN = 19
    THF = 20
    WAR = 21
    WHM = 22

    @staticmethod
    def get_job_name(job):
        members = [attr for attr in dir(Jobs()) if not callable(attr) and not attr.startswith("__") and not attr.startswith("get_job_name")]
        return members[job-1]

# MP Per level is actually the amount added to the multiplier per level for the mp base for that monster.
adjustments_by_job = {
    Jobs.BLM: {'base_eva': 4, 'eva_per_level': 2.48, 'mp_per_level': 0.3},
    Jobs.BLU: {'base_eva': 5, 'eva_per_level': 2.78, 'mp_per_level': 0.15},
    Jobs.BRD: {'base_eva': 4, 'eva_per_level': 2.66, 'mp_per_level': 0},
    Jobs.BST: {'base_eva': 5, 'eva_per_level': 2.78, 'mp_per_level': 0},
    Jobs.COR: {'base_eva': 4, 'eva_per_level': 2.66, 'mp_per_level': 0},
    Jobs.DNC: {'base_eva': 5, 'eva_per_level': 2.88, 'mp_per_level': 0},
    Jobs.DRG: {'base_eva': 5, 'eva_per_level': 2.88, 'mp_per_level': 0},
    Jobs.DRK: {'base_eva': 5, 'eva_per_level': 2.78, 'mp_per_level': 0.1},
    Jobs.GEO: {'base_eva': 4, 'eva_per_level': 2.66, 'mp_per_level': 0},
    Jobs.MNK: {'base_eva': 5, 'eva_per_level': 2.88, 'mp_per_level': 0},
    Jobs.NIN: {'base_eva': 6, 'eva_per_level': 3, 'mp_per_level': 0},
    Jobs.PLD: {'base_eva': 5, 'eva_per_level': 2.78, 'mp_per_level': 0.1},
    Jobs.PUP: {'base_eva': 5, 'eva_per_level': 2.88, 'mp_per_level': 0},
    Jobs.RDM: {'base_eva': 4, 'eva_per_level': 2.66, 'mp_per_level': 0.15},
    Jobs.RNG: {'base_eva': 4, 'eva_per_level': 2.48, 'mp_per_level': 0},
    Jobs.RUN: {'base_eva': 5, 'eva_per_level': 2.88, 'mp_per_level': 0.1},
    Jobs.SAM: {'base_eva': 5, 'eva_per_level': 2.88, 'mp_per_level': 0},
    Jobs.SCH: {'base_eva': 4, 'eva_per_level': 2.48, 'mp_per_level': 0.15},
    Jobs.SMN: {'base_eva': 4, 'eva_per_level': 2.48, 'mp_per_level': 0.4},
    Jobs.THF: {'base_eva': 6, 'eva_per_level': 3, 'mp_per_level': 0},
    Jobs.WAR: {'base_eva': 5, 'eva_per_level': 2.78, 'mp_per_level': 0},
    Jobs.WHM: {'base_eva': 4, 'eva_per_level': 2.48, 'mp_per_level': 0.2},
}

TemperamentPosture = {
    4: {"name": "Very Agressive", "message": "Show no mercy!", "value": 4},
    3: {"name": "Somewhat Agressive", "message": "Give em' a little more bite!", "value": 3},
    2: {"name": "Somewhat Defensive", "message": "Back off a bit!", "value": 2},
    1: {"name": "Very Defensive", "message": "Guard! Block! Parry! Hold!", "value": 1}
}

TemperamentAttitude = {
    4: {"name": "Very Wild", "message": "Don't think, kill!", "value": 4},
    3: {"name": "Somewhat Wild", "message": "Less thinking, more striking!", "value": 3},
    2: {"name": "Somewhat Tame", "message": "Watch your opponent, then attack!", "value": 2},
    1: {"name": "Very Tame", "message": "Think, and think again!", "value": 1}
}

PhysicalDamageTypes = {
    'blunt': ['Hand-to-Hand', 'Club', 'Staff', 'Harlequin Frame', 'Stormwaker Frame', 'Sharpshot Frame'],
    'slashing': ['Axe', 'Great Axe', 'Great Sword', 'Sword', 'Scythe', 'Katana', 'Great Katana', 'Valoredge Frame'],
    'piercing': ['Dagger', 'Polearm', 'Archery', 'Marksmanship', 'Shuriken', 'Boomerang']
}

class FeralSkills:
    SkillsList = {
        # 'Airy Shield': {'fp_cost': 0, 'type': 'Enhancing', 'sub_type': 'arrow shield', 'shadows': 'ignore', 'range': None, 'aoe': False, 'spell': 'arrow shield'},
        # 'Binding Wave': {'type': 'Enfeebling', 'shadows': 'ignore', 'range': 15, 'aoe': True, 'spell': 'bind'},
        # 'Dire Straight': {'type': 'Physical', 'shadows': 'wipe', 'range': None, 'aoe': False},
        # 'Dismemberment': {'type': 'Piercing', 'shadows': 'absorb', 'range': None, 'aoe': False}, # causes the monster to lose a body part
        # 'Earthshatter': {'type': 'Piercing', 'shadows': 'wipe', 'range': None, 'aoe': True},
        # 'Eyes On Me': {'type': 'Magical', 'sub_type': 'Dark', 'mp_cost': 112, 'shadows': 'absorb', 'range': 13, 'aoe': False},
        # 'Hypnosis': {'type': 'Enfeebling', 'sub_type': 'sleep', 'shadows': 'ignore', 'range': 'gaze', 'aoe': True},
        # 'Magic Barrier': {'type': 'Magical', 'sub_type': 'Dark', 'mp_cost': 29, 'shadows': 'absorb', 'range': None, 'aoe': True},
        # 'Sinker Drill': {'type': 'Physical', 'sub_type': 'Piercing', 'shadows': 'absorb', 'range': None, 'aoe': False},
        'Accuracy +15%': {'fp_cost': 23, 'effect': 'acc', 'amount': 15, 'is_percent': True, 'expires_seconds': 0, 'levels': False},
        'Accuracy +30%': {'fp_cost': 30, 'effect': 'acc', 'amount': 30, 'is_percent': True, 'expires_seconds': 0, 'levels': False},
        'Accuracy Bonus': {'fp_cost': 30, 'effect': 'acc', 'amount': 15, 'is_percent': True, 'expires_seconds': 0, 'levels': True},
        'AGI +25': {'fp_cost': 17, 'effect': 'agi', 'amount': 25, 'is_percent': False, 'expires_seconds': 0, 'levels': False},
        'AGI +50': {'fp_cost': 23, 'effect': 'agi', 'amount': 50, 'is_percent': False, 'expires_seconds': 0, 'levels': False},
        'AGI Bonus': {'fp_cost': 23, 'effect': 'agi', 'amount': 15, 'is_percent': True, 'expires_seconds': 0, 'levels': False},
        'Amnesia Attack': {'fp_cost': 47, 'effect': 'amnesia', 'amount': 1, 'is_percent': False, 'expires_seconds': 0, 'levels': False},
        'Amorph Killer': {'fp_cost': 8, 'effect': 'amorph_killer', 'amount': 5, 'is_percent': True, 'expires_seconds': 0, 'levels': True},
        'Attack +15%': {'fp_cost': 23, 'effect': 'attack', 'amount': 15, 'is_percent': True, 'expires_seconds': 0, 'levels': False},
        'Attack Bonus': {'fp_cost': 30, 'effect': 'attack', 'amount': 10, 'is_percent': False, 'expires_seconds': 0, 'levels': True},
        'Auto Refresh': {'fp_cost': 38, 'effect': 'auto_refresh', 'amount': 1, 'is_percent': False, 'expires_seconds': 0, 'levels': True},
        'Auto Refresh +5': {'fp_cost': 30, 'effect': 'auto_refresh', 'amount': 5, 'is_percent': False, 'expires_seconds': 0, 'levels': False},
        'Auto Regain': {'fp_cost': 70, 'effect': 'auto_regain', 'amount': 1, 'is_percent': False, 'expires_seconds': 0, 'levels': True},
        'Auto Regain +3': {'fp_cost': 58, 'effect': 'auto_regain', 'amount': 3, 'is_percent': False, 'expires_seconds': 0, 'levels': False},
        'Auto Regen': {'fp_cost': 47, 'effect': 'auto_regen', 'amount': 1, 'is_percent': False, 'expires_seconds': 0, 'levels': True},
        'Auto Regen +5': {'fp_cost': 38, 'effect': 'auto_regen', 'amount': 5, 'is_percent': False, 'expires_seconds': 0, 'levels': False},
        'Aquan Killer': {'fp_cost': 8, 'effect': 'aquan_killer', 'amount': 5, 'is_percent': True, 'expires_seconds': 0, 'levels': True},
        'Bird Killer': {'fp_cost': 8, 'effect': 'bird_killer', 'amount': 5, 'is_percent': True, 'expires_seconds': 0, 'levels': True},
        'Blinding Attack': {'fp_cost': 23, 'effect': 'blind', 'amount': -20, 'is_percent': True, 'expires_seconds': 0, 'levels': False},
        'CHR +25': {'fp_cost': 17, 'effect': 'cha', 'amount': 25, 'is_percent': False, 'expires_seconds': 0, 'levels': False},
        'CHR Bonus': {'fp_cost': 23, 'effect': 'cha', 'amount': 15, 'is_percent': True, 'expires_seconds': 0, 'levels': False},
        'Curse Attack': {'fp_cost': 23, 'effect': 'curse', 'amount': -20, 'is_percent': True, 'expires_seconds': 0, 'levels': False},
        'Damage Resistance +15%': {'fp_cost': 30, 'effect': 'damage_resist', 'amount': 15, 'is_percent': True, 'expires_seconds': 0, 'levels': False},
        'Damage Resistance Bonus': {'fp_cost': 38, 'effect': 'damage_resist', 'amount': 10, 'is_percent': False, 'expires_seconds': 0, 'levels': True},
        'Dark Resistance +2': {'fp_cost': 8, 'effect': 'dark_resist', 'amount': 2, 'is_percent': False, 'expires_seconds': 0, 'levels': False},
        'Dark Resistance Bonus': {'fp_cost': 12, 'effect': 'dark_resist', 'amount': 1, 'is_percent': False, 'expires_seconds': 0, 'levels': True},
        'Defense +15%': {'fp_cost': 23, 'effect': 'def', 'amount': 15, 'is_percent': True, 'expires_seconds': 0, 'levels': False},
        'Defense Bonus': {'fp_cost': 30, 'effect': 'def', 'amount': 10, 'is_percent': False, 'expires_seconds': 0, 'levels': True},
        'Defense +30%': {'fp_cost': 30, 'effect': 'def', 'amount': 30, 'is_percent': True, 'expires_seconds': 0, 'levels': False},
        'DEX +25': {'fp_cost': 17, 'effect': 'dex', 'amount': 25, 'is_percent': False, 'expires_seconds': 0, 'levels': False},
        'DEX +50': {'fp_cost': 23, 'effect': 'dex', 'amount': 50, 'is_percent': False, 'expires_seconds': 0, 'levels': False},
        'DEX Bonus': {'fp_cost': 23, 'effect': 'dex', 'amount': 15, 'is_percent': False, 'expires_seconds': 0, 'levels': True},
        'Demon Killer': {'fp_cost': 8, 'effect': 'demon_killer', 'amount': 5, 'is_percent': True, 'expires_seconds': 0, 'levels': True},
        'Dragon Killer': {'fp_cost': 8, 'effect': 'dragon_killer', 'amount': 5, 'is_percent': True, 'expires_seconds': 0, 'levels': True},
        'Earth Resistance +2': {'fp_cost': 8, 'effect': 'earth_resist', 'amount': 2, 'is_percent': False, 'expires_seconds': 0, 'levels': False},
        'Earth Resistance Bonus': {'fp_cost': 12, 'effect': 'earth_resist', 'amount': 1, 'is_percent': False, 'expires_seconds': 0, 'levels': True},
        'Evasion +15%': {'fp_cost': 23, 'effect': 'eva', 'amount': 15, 'is_percent': True, 'expires_seconds': 0, 'levels': False},
        'Evasion Bonus': {'fp_cost': 30, 'effect': 'eva', 'amount': 5, 'is_percent': False, 'expires_seconds': 0, 'levels': True},
        'Fire Resistance +2': {'fp_cost': 8, 'effect': 'fire_resist', 'amount': 2, 'is_percent': False, 'expires_seconds': 0, 'levels': False},
        'Fire Resistance Bonus': {'fp_cost': 12, 'effect': 'fire_resist', 'amount': 1, 'is_percent': False, 'expires_seconds': 0, 'levels': True},
        'HP Max Bonus': {'fp_cost': 12, 'effect': 'hp', 'amount': 1, 'is_percent': False, 'expires_seconds': 0, 'levels': True},
        'HP Max +15%': {'fp_cost': 23, 'effect': 'hp', 'amount': 15, 'is_percent': True, 'expires_seconds': 0, 'levels': False},
        'HP Max +30%': {'fp_cost': 30, 'effect': 'hp', 'amount': 30, 'is_percent': True, 'expires_seconds': 0, 'levels': False},
        'HP Max +50': {'fp_cost': 8, 'effect': 'hp', 'amount': 50, 'is_percent': False, 'expires_seconds': 0, 'levels': False},
        'Ice Resistance +2': {'fp_cost': 8, 'effect': 'ice_resist', 'amount': 2, 'is_percent': False, 'expires_seconds': 0, 'levels': False},
        'Ice Resistance Bonus': {'fp_cost': 12, 'effect': 'ice_resist', 'amount': 1, 'is_percent': False, 'expires_seconds': 0, 'levels': True},
        'INT Bonus': {'fp_cost': 23, 'effect': 'int', 'amount': 1, 'is_percent': False, 'expires_seconds': 0, 'levels': True},
        'INT +25': {'fp_cost': 17, 'effect': 'int', 'amount': 25, 'is_percent': False, 'expires_seconds': 0, 'levels': False},
        'INT +50': {'fp_cost': 23, 'effect': 'int', 'amount': 50, 'is_percent': False, 'expires_seconds': 0, 'levels': False},
        'Light Resistance +2': {'fp_cost': 8, 'effect': 'light_resist', 'amount': 2, 'is_percent': False, 'expires_seconds': 0, 'levels': False},
        'Lightning Resistance +2': {'fp_cost': 8, 'effect': 'lightning_resist', 'amount': 2, 'is_percent': False, 'expires_seconds': 0, 'levels': False},
        'Lizard Killer': {'fp_cost': 8, 'effect': 'lizard_killer', 'amount': 5, 'is_percent': True, 'expires_seconds': 0, 'levels': True},
        'MP Max Bonus': {'fp_cost': 17, 'effect': 'mp', 'amount': 1, 'is_percent': False, 'expires_seconds': 0, 'levels': True},
        'MP Max +15%': {'fp_cost': 12, 'effect': 'mp', 'amount': 15, 'is_percent': True, 'expires_seconds': 0, 'levels': False},
        'MP Max +50': {'fp_cost': 5, 'effect': 'mp', 'amount': 50, 'is_percent': False, 'expires_seconds': 0, 'levels': False},
        'Magic Accuracy Bonus': {'fp_cost': 30, 'effect': 'magic_acc', 'amount': 1, 'is_percent': False, 'expires_seconds': 0, 'levels': True},
        'Magic Accuracy 15%': {'fp_cost': 23, 'effect': 'magic_acc', 'amount': 15, 'is_percent': True, 'expires_seconds': 0, 'levels': False},
        'Magic Attack Bonus': {'fp_cost': 30, 'effect': 'magic_attack', 'amount': 1, 'is_percent': False, 'expires_seconds': 0, 'levels': True},
        'Magic Attack +15%': {'fp_cost': 23, 'effect': 'magic_attack', 'amount': 15, 'is_percent': True, 'expires_seconds': 0, 'levels': False},
        'MND Bonus': {'fp_cost': 23, 'effect': 'mnd', 'amount': 1, 'is_percent': False, 'expires_seconds': 0, 'levels': True},
        'MND +25': {'fp_cost': 17, 'effect': 'mnd', 'amount': 25, 'is_percent': False, 'expires_seconds': 0, 'levels': False},
        'MND +50': {'fp_cost': 23, 'effect': 'mnd', 'amount': 50, 'is_percent': False, 'expires_seconds': 0, 'levels': False},
        'Poisoning Attack': {'fp_cost': 17, 'effect': 'poison', 'amount': -4, 'is_percent': False, 'expires_seconds': 0, 'levels': False},
        'Plantoid Killer': {'fp_cost': 8, 'effect': 'plantoid_killer', 'amount': 5, 'is_percent': True, 'expires_seconds': 0, 'levels': True},
        'Silencing Attack': {'fp_cost': 30, 'effect': 'silence', 'amount': 1, 'is_percent': False, 'expires_seconds': 0, 'levels': False},
        'Store TP +10%': {'fp_cost': 38, 'effect': 'store_tp', 'amount': 10, 'is_percent': True, 'expires_seconds': 0, 'levels': False},
        'STR Bonus': {'fp_cost': 23, 'effect': 'str', 'amount': 1, 'is_percent': False, 'expires_seconds': 0, 'levels': True},
        'STR +25': {'fp_cost': 17, 'effect': 'str', 'amount': 25, 'is_percent': False, 'expires_seconds': 0, 'levels': False},
        'STR +50': {'fp_cost': 23, 'effect': 'str', 'amount': 50, 'is_percent': False, 'expires_seconds': 0, 'levels': False},
        'Undead Killer': {'fp_cost': 8, 'effect': 'undead_killer', 'amount': 5, 'is_percent': True, 'expires_seconds': 0, 'levels': True},
        'Vermin Killer': {'fp_cost': 8, 'effect': 'vermin_killer', 'amount': 5, 'is_percent': True, 'expires_seconds': 0, 'levels': True},
        'VIT Bonus': {'fp_cost': 23, 'effect': 'vit', 'amount': 1, 'is_percent': False, 'expires_seconds': 0, 'levels': True},
        'VIT +25': {'fp_cost': 17, 'effect': 'vit', 'amount': 25, 'is_percent': False, 'expires_seconds': 0, 'levels': False},
        'VIT +50': {'fp_cost': 23, 'effect': 'vit', 'amount': 50, 'is_percent': False, 'expires_seconds': 0, 'levels': False},
        'Water Resistance +2': {'fp_cost': 8, 'effect': 'water_resist', 'amount': 2, 'is_percent': False, 'expires_seconds': 0, 'levels': False},
        'Water Resistance Bonus': {'fp_cost': 12, 'effect': 'water_resist', 'amount': 1, 'is_percent': False, 'expires_seconds': 0, 'levels': True},
        'Wind Resistance +2': {'fp_cost': 8, 'effect': 'wind_resist', 'amount': 2, 'is_percent': False, 'expires_seconds': 0, 'levels': False},
        'Wind Resistance Bonus': {'fp_cost': 12, 'effect': 'wind_resist', 'amount': 1, 'is_percent': False, 'expires_seconds': 0, 'levels': True},
    }

    @staticmethod
    def get_skill(skill_name):
        return FeralSkills.SkillsList.get(skill_name)

class Spells:
    SpellTypes = {
        't1': {'multiplier': 1.0, 'earth': 10, 'water': 16, 'wind': 25, 'fire': 35, 'ice': 46, 'thunder': 60, 'dark': 0, 'light': 14},
        't2': {'multiplier': 1.0, 'earth': 78, 'water': 95, 'wind': 113, 'fire': 133, 'ice': 155, 'thunder': 178, 'dark': 0, 'light': 85},
        't3': {'multiplier': 1.5, 'earth': 210, 'water': 236, 'wind': 265, 'fire': 295, 'ice': 320, 'thunder': 345, 'dark': 0, 'light': 198},
        't4': {'multiplier': 2.0, 'earth': 381, 'water': 410, 'wind': 440, 'fire': 472, 'ice': 506, 'thunder': 541, 'dark': 0, 'light': 0},
        't5': {'multiplier': 2.299, 'earth': 626, 'water': 680, 'wind': 738, 'fire': 785, 'ice': 828, 'thunder': 874, 'dark': 963, 'light': 0},
        't1-ga': {'multiplier': 1.0, 'earth': 56, 'water': 74, 'wind': 93, 'fire': 120, 'ice': 145, 'thunder': 172, 'dark': 0, 'light': 50},
        't2-ga-a': {'multiplier': 1.0, 'earth': 201, 'water': 232, 'wind': 266, 'fire': 312, 'ice': 350, 'thunder': 392, 'dark': 0, 'light': 180},
        't2-ga-b': {'multiplier': 1.5, 'earth': 201, 'water': 232, 'wind': 266, 'fire': 312, 'ice': 350, 'thunder': 392, 'dark': 0, 'light': 180},
        't3-ga': {'multiplier': 1.5, 'earth': 434, 'water': 480, 'wind': 527, 'fire': 589, 'ice': 642, 'thunder': 697, 'dark': 0, 'light': 0},
        'ja': {'multiplier': 1.0, 'earth': 719, 'water': 782, 'wind': 844, 'fire': 902, 'ice': 953, 'thunder': 1004, 'dark': 0, 'light': 0},
        't1-ra': {'multiplier': 1.0, 'earth': 128, 'water': 153, 'wind': 179, 'fire': 216, 'ice': 247, 'thunder': 282, 'dark': 0, 'light': 0},
        't2-ra-a': {'multiplier': 1.0, 'earth': 317, 'water': 356, 'wind': 396, 'fire': 450, 'ice': 496, 'thunder': 544, 'dark': 0, 'light': 0},
        't2-ra-b': {'multiplier': 1.5, 'earth': 317, 'water': 356, 'wind': 396, 'fire': 450, 'ice': 496, 'thunder': 544, 'dark': 0, 'light': 0},
        't1-am': {'multiplier': 2.0, 'earth': 577, 'water': 630, 'wind': 552, 'fire': 657, 'ice': 526, 'thunder': 603, 'dark': 939, 'light': 125},
        't2-am': {'multiplier': 2.0, 'earth': 710, 'water': 710, 'wind': 710, 'fire': 710, 'ice': 710, 'thunder': 710, 'dark': 0, 'light': 0},
        'helix': {'multiplier': 1.0, 'earth': 25, 'water': 25, 'wind': 25, 'fire': 25, 'ice': 25, 'thunder': 25, 'dark': 25, 'light': 25},
        'ichi': {'multiplier': 1.0, 'earth': 10, 'water': 10, 'wind': 10, 'fire': 10, 'ice': 10, 'thunder': 10, 'dark': 0, 'light': 0},
        'ni': {'multiplier': 1.0, 'earth': 78, 'water': 78, 'wind': 78, 'fire': 78, 'ice': 78, 'thunder': 78, 'dark': 0, 'light': 0},
        'san': {'multiplier': 1.5, 'earth': 78, 'water': 78, 'wind': 78, 'fire': 78, 'ice': 78, 'thunder': 78, 'dark': 0, 'light': 0},
    }

    # TODO: Finish jobs listing for each spell.
    SpellList = {
        'Stone': {'mp_cost': 4, 'casting_time': 0.5, 'recast_time': 2, 'magic_acc_stat': 'int', 'spell_type': 't1', 'damage_type': 'earth', 'jobs': {Jobs.BLM: 1, Jobs.RDM: 4, Jobs.SCH: 4, Jobs.GEO: 4, Jobs.DRK: 5, Jobs.PUP: 5} },
        'Water': {'mp_cost': 5, 'casting_time': 0.5, 'recast_time': 2, 'magic_acc_stat': 'int', 'spell_type': 't1', 'damage_type': 'water', 'jobs': {Jobs.BLM: 5, Jobs.SCH: 8, Jobs.RDM: 9, Jobs.GEO: 9, Jobs.PUP: 10, Jobs.DRK: 11} },
        'Aero': {'mp_cost': 6, 'casting_time': 0.5, 'recast_time': 2, 'magic_acc_stat': 'int', 'spell_type': 't1', 'damage_type': 'wind', 'jobs': {Jobs.BLM: 9, Jobs.SCH: 12, Jobs.RDM: 14, Jobs.PUP: 15, Jobs.DRK: 17} },
        'Fire': {'mp_cost': 7, 'casting_time': 0.5, 'recast_time': 2, 'magic_acc_stat': 'int', 'spell_type': 't1', 'damage_type': 'fire', 'jobs': {Jobs.BLM: 13, Jobs.SCH: 16, Jobs.RDM: 19, Jobs.GEO: 19, Jobs.PUP: 20, Jobs.DRK: 23} },
        'Blizzard': {'mp_cost': 8, 'casting_time': 0.5, 'recast_time': 2, 'magic_acc_stat': 'int', 'spell_type': 't1', 'damage_type': 'ice', 'jobs': {Jobs.BLM: 17, Jobs.SCH: 20, Jobs.RDM: 24, Jobs.PUP: 24, Jobs.DRK: 29} },
        'Thunder': {'mp_cost': 9, 'casting_time': 0.5, 'recast_time': 2, 'magic_acc_stat': 'int', 'spell_type': 't1', 'damage_type': 'thunder', 'jobs': {Jobs.BLM: 21, Jobs.SCH: 24, Jobs.RDM: 29, Jobs.PUP: 29, Jobs.DRK: 35} },
        'Banish': {'mp_cost': 15, 'casting_time': 3, 'recast_time': 14, 'magic_acc_stat': 'mnd', 'spell_type': 't1', 'damage_type': 'light', 'jobs': {Jobs.WHM: 5, Jobs.PLD: 7} },
        'Stone II': {'mp_cost': 16, 'casting_time': 1.5, 'recast_time': 6, 'magic_acc_stat': 'int', 'spell_type': 't2', 'damage_type': 'earth', 'jobs': {Jobs.BLM: 26, Jobs.SCH: 30, Jobs.RDM: 35, Jobs.DRK: 42, Jobs.PUP: 35} },
        'Water II': {'mp_cost': 19, 'casting_time': 1.5, 'recast_time': 6, 'magic_acc_stat': 'int', 'spell_type': 't2', 'damage_type': 'water', 'jobs': {Jobs.BLM: 30, Jobs.SCH: 34, Jobs.RDM: 40, Jobs.PUP: 40, Jobs.DRK: 48} },
        'Aero II': {'mp_cost': 22, 'casting_time': 1.5, 'recast_time': 6, 'magic_acc_stat': 'int', 'spell_type': 't2', 'damage_type': 'wind', 'jobs': {Jobs.BLM: 34, Jobs.SCH: 38, Jobs.RDM: 45, Jobs.PUP: 45, Jobs.DRK: 54} },
        'Fire II': {'mp_cost': 26, 'casting_time': 1.5, 'recast_time': 6, 'magic_acc_stat': 'int', 'spell_type': 't2', 'damage_type': 'fire', 'jobs': {Jobs.BLM: 38, Jobs.SCH: 42, Jobs.RDM: 50, Jobs.PUP: 50, Jobs.DRK: 60} },
        'Blizzard II': {'mp_cost': 31, 'casting_time': 1.5, 'recast_time': 6, 'magic_acc_stat': 'int', 'spell_type': 't2', 'damage_type': 'ice', 'jobs': {Jobs.BLM: 42, Jobs.SCH: 46, Jobs.RDM: 55, Jobs.PUP: 55, Jobs.DRK: 66} },
        'Thunder II': {'mp_cost': 37, 'casting_time': 1.5, 'recast_time': 6, 'magic_acc_stat': 'int', 'spell_type': 't2', 'damage_type': 'thunder', 'jobs': {Jobs.BLM: 46, Jobs.SCH: 51, Jobs.RDM: 60, Jobs.PUP: 60, Jobs.DRK: 72} },
        'Banish II': {'mp_cost': 57, 'casting_time': 2.5, 'recast_time': 21, 'magic_acc_stat': 'mnd', 'spell_type': 't2', 'damage_type': 'light', 'jobs': {Jobs.WHM: 30, Jobs.PLD: 34} },
        'Stone III': {'mp_cost': 40, 'casting_time': 3, 'recast_time': 15, 'magic_acc_stat': 'int', 'spell_type': 't3', 'damage_type': 'earth', 'jobs': {Jobs.BLM: 51, Jobs.SCH: 54, Jobs.RDM: 65, Jobs.DRK: 76, Jobs.PUP: 65} },
        'Water III': {'mp_cost': 46, 'casting_time': 3, 'recast_time': 15, 'magic_acc_stat': 'int', 'spell_type': 't3', 'damage_type': 'water', 'jobs': {Jobs.BLM: 55, Jobs.SCH: 57, Jobs.RDM: 67, Jobs.PUP: 67, Jobs.DRK: 80} },
        'Aero III': {'mp_cost': 54, 'casting_time': 3, 'recast_time': 15, 'magic_acc_stat': 'int', 'spell_type': 't3', 'damage_type': 'wind', 'jobs': {Jobs.BLM: 59, Jobs.SCH: 60, Jobs.RDM: 69, Jobs.PUP: 69, Jobs.DRK: 84} },
        'Fire III': {'mp_cost': 63, 'casting_time': 3, 'recast_time': 15, 'magic_acc_stat': 'int', 'spell_type': 't3', 'damage_type': 'fire', 'jobs': {Jobs.BLM: 62, Jobs.SCH: 63, Jobs.RDM: 71, Jobs.PUP: 70, Jobs.DRK: 88} },
        'Blizzard III': {'mp_cost': 75, 'casting_time': 3, 'recast_time': 15, 'magic_acc_stat': 'int', 'spell_type': 't3', 'damage_type': 'ice', 'jobs': {Jobs.BLM: 64, Jobs.SCH: 66, Jobs.RDM: 73, Jobs.PUP: 71, Jobs.DRK: 92} },
        'Thunder III': {'mp_cost': 91, 'casting_time': 3, 'recast_time': 15, 'magic_acc_stat': 'int', 'spell_type': 't3', 'damage_type': 'thunder', 'jobs': {Jobs.BLM: 66, Jobs.SCH: 69, Jobs.RDM: 75, Jobs.PUP: 72, Jobs.DRK: 96} },
        'Banish III': {'mp_cost': 96, 'casting_time': 3, 'recast_time': 45, 'magic_acc_stat': 'mnd', 'spell_type': 't3', 'damage_type': 'light', 'jobs': {Jobs.WHM: 65} },
    }

    @staticmethod
    def get_spell_list(mp, level, job = None, support_job = None):
        available_spells = []
        for spell_name, spell in Spells.SpellList.iteritems():
            if job and job in spell['jobs'] and spell['jobs'][job] <= level:
                if spell_name not in available_spells:
                    if spell['mp_cost'] < mp:
                        available_spells.append(spell_name)
            if support_job and support_job in spell['jobs'] and spell['jobs'][support_job] <= level / 2:
                if spell_name not in available_spells:
                    if spell['mp_cost'] < mp:
                        available_spells.append(spell_name)
        return sorted(available_spells)

    @staticmethod
    def get_spell_data(spell):
        spell = Spells.SpellList[spell]
        type_data = Spells.SpellTypes[spell['spell_type']]
        spell_data = {
            'type': type_data,
            'magic_acc_stat': spell['magic_acc_stat'],
            'base_damage': type_data[spell['damage_type']],
            'multiplier': type_data['multiplier'],
            'mp_cost': spell['mp_cost'],
            'damage_type': spell['damage_type']
        }
        return spell_data

Families = {
    'acrolith': {
        'base_fp': 50,
        'fp_per_level': 0.1,
        'max_fp': 55,
        'available_main_job': [Jobs.WAR, Jobs.DRG, Jobs.DRK, Jobs.PLD],
        'available_support_job': [Jobs.WAR, Jobs.DRG, Jobs.DRK, Jobs.PLD],
        'innate_feral_skills': [],#'Sinker Drill', 'Dire Straight', 'Dismemberment', 'Earthshatter'],
        'target_magic_damage_adjustment': 1.00,
        'feral_skills_conversion': {'Accuracy +15%': 50, 'Attack Bonus': 20},
        'type': 'Arcana',
        'strong_vs': ['Dark'],
        'charmable': False,
        'aspir': False,
        'drain': False,
        'base_vit': 10,
        'vit_per_level': 0.9334,
        'base_str': 9,
        'str_per_level': 0.8934,
        'base_agi': 7,
        'agi_per_level': 0.76,
        'base_dex': 10,
        'dex_per_level': 0.76,
        'base_mnd': 8,
        'mnd_per_level': 0.76,
        'base_int': 8,
        'int_per_level': 0.76,
        'base_chr': 7,
        'chr_per_level': 0.76,
        'temperament_attitude': {
            'initial_value': 4,
            'actions': {
                4: {'use_tp_chance': 100, 'ws': ['Sinker Drill'], 'side_attack_chance': 0, 'range_chance': 0},
                3: {'use_tp_chance': 75, 'ws': ['Eyes On Me'], 'side_attack_chance': 70, 'range_chance': 10},
                2: {'use_tp_chance': 50, 'ws': ['Binding Wave', 'Hypnosis'], 'side_attack_chance': 25, 'range_chance': 70},
                1: {'use_tp_chance': 70, 'ws': ['Binding Wave', 'Hypnosis', 'Magic Barrier', 'Airy Shield'], 'side_attack_chance': 25, 'range_chance': 70}
            }
        },
        'temperament_posture': {
            'initial_value': 4,
            'actions': {
                4: {'use_tp_chance': 100, 'ws': ['Eyes On Me'], 'side_attack_chance': 0, 'range_chance': 0},
                3: {'use_tp_chance': 75, 'ws': ['Eyes On Me'], 'side_attack_chance': 70, 'range_chance': 10},
                2: {'use_tp_chance': 50, 'ws': ['Binding Wave', 'Hypnosis'], 'side_attack_chance': 25, 'range_chance': 70},
                1: {'use_tp_chance': 70, 'ws': ['Magic Barrier', 'Airy Shield'], 'side_attack_chance': 25, 'range_chance': 100}
            }
        }
    },
    'ahriman': {
        'base_fp': 65,
        'fp_per_level': 0.3,
        'max_fp': 80,
        'available_main_job': [Jobs.BLM, Jobs.RDM, Jobs.WAR],
        'available_support_job': [Jobs.BLM, Jobs.RDM, Jobs.WAR],
        'innate_feral_skills': ['Binding Wave', 'Magic Barrier', 'Hypnosis', 'Eyes On Me', 'Airy Shield'],
        'type': 'Demon',
        'feral_skills_conversion': {'Accuracy +15%': 50},
        'traits': ['magic defence bonus +25%'],
        'target_magic_damage_adjustment': 0.75,
        'charmable': False,
        'aspir': True,
        'drain': True,
        'base_vit': 8,
        'vit_per_level': 0.8,
        'base_str': 8,
        'str_per_level': 0.8534,
        'base_agi': 9,
        'agi_per_level': 0.88,
        'base_dex': 10,
        'dex_per_level': 0.714,
        'base_mnd': 9,
        'mnd_per_level': 0.9066,
        'base_int': 9,
        'int_per_level': 0.9066,
        'base_chr': 8,
        'chr_per_level': 0.84,
        'temperament_attitude': {
            'initial_value': 4,
            'actions': {
                4: {'use_tp_chance': 100, 'ws': ['Eyes On Me'], 'side_attack_chance': 0, 'range_chance': 0},
                3: {'use_tp_chance': 75, 'ws': ['Eyes On Me'], 'side_attack_chance': 70, 'range_chance': 10},
                2: {'use_tp_chance': 50, 'ws': ['Binding Wave', 'Hypnosis'], 'side_attack_chance': 25, 'range_chance': 70},
                1: {'use_tp_chance': 70, 'ws': ['Binding Wave', 'Hypnosis', 'Magic Barrier', 'Airy Shield'], 'side_attack_chance': 25, 'range_chance': 70}
            }
        },
        'temperament_posture': {
            'initial_value': 4,
            'actions': {
                4: {'use_tp_chance': 100, 'ws': ['Eyes On Me'], 'side_attack_chance': 0, 'range_chance': 0},
                3: {'use_tp_chance': 75, 'ws': ['Eyes On Me'], 'side_attack_chance': 70, 'range_chance': 10},
                2: {'use_tp_chance': 50, 'ws': ['Binding Wave', 'Hypnosis'], 'side_attack_chance': 25, 'range_chance': 70},
                1: {'use_tp_chance': 70, 'ws': ['Magic Barrier', 'Airy Shield'], 'side_attack_chance': 25, 'range_chance': 100}
            }
        }
    }
}

Monsters = {
    'Mechanical Menace': {
        'family': 'acrolith',
        'zone': ['abyssea - uleguerand'],
        'hp': 20,
        'mp': 20,
        'weapon_base_damage': 18
    },
    'Floating Eye': {
        'family': 'ahriman',
        'zone': ['ranguemont pass'],
        'hp': 15,
        'mp': 24,
        'weapon_base_damage': 5,
        'image_url': 'http://vignette1.wikia.nocookie.net/ffxi/images/9/94/Floating_Eye.JPG/revision/latest?cb=20070704142439'
    },
    'Bat Eye': {
        'family': 'ahriman',
        'zone': ['ranguemont pass', 'beaucedine glacier'],
        'hp': 15,
        'mp': 24,
        'weapon_base_damage': 5,
        'image_url': 'http://vignette3.wikia.nocookie.net/ffxi/images/4/40/Bat_Eye.jpg/revision/latest?cb=20060909124134',
    },
    'Evil Eye': {
        'family': 'ahriman',
        'zone': ['castle zvahl baileys', 'castle zvahl keep', 'xarcabard'],
        'hp': 15,
        'mp': 24,
        'weapon_base_damage': 5,
    },
    'Morbid Eye': {
        'family': 'ahriman',
        'zone': ['castle zvahl baileys', 'castle zvahl keep'],
        'hp': 15,
        'mp': 24,
        'weapon_base_damage': 5
    },
    'Deadly Iris': {
        'family': 'ahriman',
        'zone': ['castle zvahl keep'],
        'hp': 15,
        'mp': 24,
        'weapon_base_damage': 5
    },
    'Ahriman': {
        'family': 'ahriman',
        'zone': ['castle zvahl baileys'],
        'hp': 15,
        'mp': 24,
        'weapon_base_damage': 5
    },
    'Fachan': {
        'family': 'ahriman',
        'zone': ['uleguerand range'],
        'hp': 15,
        'mp': 24,
        'weapon_base_damage': 5
    },
    'Gawper': {
        'family': 'ahriman',
        'zone': ['beaucedine glacier (s)'],
        'hp': 15,
        'mp': 24,
        'weapon_base_damage': 5
    },
    'Menacing Eye': {
        'family': 'ahriman',
        'zone': ['xarcabard (s)'],
        'hp': 15,
        'mp': 24,
        'weapon_base_damage': 5
    },
    'Ogler': {
        'family': 'ahriman',
        'zone': ['castle zvahl keep (s)', 'castle zvahl baileys (s)'],
        'hp': 15,
        'mp': 24,
        'weapon_base_damage': 5
    },
    'Smolenkos': {
        'family': 'ahriman',
        'zone': ['uleguerand range'],
        'hp': 15,
        'mp': 24,
        'weapon_base_damage': 5
    },
    'Doom Lens': {
        'family': 'ahriman',
        'zone': ['castle zvahl keep (s)', 'castle zvahl baileys (s)'],
        'hp': 15,
        'mp': 24,
        'weapon_base_damage': 5
    },
    'Scowlenkos': {
        'family': 'ahriman',
        'zone': ['uleguerand range'],
        'hp': 15,
        'mp': 24,
        'weapon_base_damage': 5
    }

}

UnsortedZones = {
    'abyssea - uleguerand': {'cost': 10, 'find_percent': 50},
    'beaucedine glacier': {'cost': 10, 'find_percent': 50},
    'beaucedine glacier (s)': {'cost': 10, 'find_percent': 50},
    'castle zvahl baileys': {'cost': 10, 'find_percent': 50},
    'castle zvahl baileys (s)': {'cost': 10, 'find_percent': 50},
    'castle zvahl keep': {'cost': 10, 'find_percent': 50},
    'castle zvahl keep (s)': {'cost': 10, 'find_percent': 50},
    'ranguemont pass': {'cost': 10, 'find_percent': 50},
    'uleguerand range': {'cost': 10, 'find_percent': 50},
    'xarcabard': {'cost': 10, 'find_percent': 50},
    'xarcabard (s)': {'cost': 10, 'find_percent': 50},
}

Zones = collections.OrderedDict(sorted(UnsortedZones.items()))

class Pankration:
    def __init__(self):
        pass

    def start_battle(self, monster1, monster2, battle_type):
        battle = Arena(monster1, monster2, battle_type)
        battle.start()
        return battle

    def list_zones(self):
        return Zones

    def get_monsters(self, zone):
        monster_list = []
        for monster_name, monster in Monsters.iteritems():
            if zone.lower() in monster['zone']:
                monster_list.append(monster_name)
        return monster_list

    def get_zone_cost(self, zone):
        zone = zone.lower()
        if zone in Zones:
            return Zones[zone]['cost']
        else:
            return False

    def hunt_monster(self, zone):
        zone = zone.lower()
        if not zone in Zones:
            return HuntResponse(HuntResponse.FAILURE, "The zone was not found. {} - {}".format(zone, Zones), None)            
        if random.randint(1, 100) < Zones[zone]['find_percent']:
            monster_name = random.choice(self.get_monsters(zone))
            monster_data = Monsters[monster_name]
            hp = monster_data['hp']
            mp = monster_data['mp']
            weapon_base_damage = monster_data['weapon_base_damage']
            log("Monster: {} Data: {}".format(monster_name, monster_data))
            family_name = monster_data['family']
            family = Families[family_name]
            level = 1
            main_job = random.choice(family['available_main_job'])
            support_job = random.choice(family['available_support_job'])
            while support_job == main_job:
                support_job = random.choice(family['available_support_job'])
            feral_skills = []
            # TODO: Add support back in for innate feral skills
            # skills = random.sample(family['innate_feral_skills'], 3)
            # if random.randint(1, 100) < SKILL_PERCENT:
            #     feral_skills.append(skills[0])
            #     if random.randint(1, 100) < SKILL_PERCENT:
            #         feral_skills.append(skills[1])
            #         if random.randint(1, 100) < SKILL_PERCENT:
            #             feral_skills.append(skills[2])
            dicipline_level = 1

            monster = Monster(monster_name, family_name, family, hp, mp, level,
                              weapon_base_damage, main_job, support_job, feral_skills,
                              [], dicipline_level)
            url = ''
            if 'image_url' in monster_data:
                url = monster_data['image_url']
            return HuntResponse(HuntResponse.SUCCESS, "You captured a *{}*!\n\n{}".format(monster_name, url),
                                monster)
        else:
            return HuntResponse(HuntResponse.FAILURE, "You were unable to capture a monster's soul.",
                                None)

    def get_action():
        return ""

class AttackResponse:
    def __init__(self, is_a_hit, damage, is_a_crit, spell, resisted, intimidated):
        self.spell = spell
        self.is_a_crit = is_a_crit
        self.is_a_hit = is_a_hit
        self.resisted = resisted
        self.intimidated = intimidated
        self.damage = damage

    def __str__(self):
        return "Spell: {} Resisted: {} Is a Hit: {} Is a Crit: {} Damage: {} intimidated: {}".format(self.spell, self.resisted, self.is_a_hit, self.is_a_crit, self.damage, self.intimidated)

class Monster:
    def __init__(self, monster_type, family_name, family, base_hp, base_mp, level, weapon_base_damage, main_job,
                 support_job, innate_feral_skills, equipped_feral_skills, dicipline_level):
        self.custom_name = None
        self.status_effects = {}

        self.monster_type = monster_type
        self.family_name = family_name
        self.family = family
        self.base_hp = base_hp
        self.base_mp = base_mp
        self.level = level
        self.main_job = main_job
        self.support_job = support_job
        self.innate_feral_skills = innate_feral_skills
        self.equipped_feral_skills = equipped_feral_skills
        
        self.discipline_level = dicipline_level
        self.temperament_posture = family['temperament_posture']['initial_value']
        self.temperament_attitude = family['temperament_attitude']['initial_value']
        self.pre_fight_command = {"temperament_posture": None, "temperament_attitude": None}
        self.target_magic_damage_adjustment = family['target_magic_damage_adjustment']
        self.exp = 200 * (level - 1)
        # TODO: Setup something more interesting for each monster. 
        self.weapon_base_damage = weapon_base_damage
        self.ammo_damage = 0
        self.base_vit = family['base_vit']
        self.vit_per_level = family['vit_per_level']
        self.base_str = family['base_str']
        self.str_per_level = family['str_per_level']
        self.base_agi = family['base_agi']
        self.agi_per_level = family['agi_per_level']
        self.base_dex = family['base_dex']
        self.dex_per_level = family['dex_per_level']
        self.base_mnd = family['base_mnd']
        self.mnd_per_level = family['mnd_per_level']
        self.base_int = family['base_int']
        self.int_per_level = family['int_per_level']
        self.base_chr = family['base_chr']
        self.chr_per_level = family['chr_per_level']
        self.tp = 0
        self.hp = self.get_hp()
        self.mp = self.get_mp()
        self.wins = 0
        self.losses = 0
        self.battle_memory = {}

    def __str__(self):
        try:
            return "**{}**\n*Stats:*\nFamily: {}\nLevel: {}\nMain Job: {}\nSupport Job: {}\nInnate Feral Skills: {}\nEquipped Feral Skills: {}\nFeral Points: {}\n\nWins: {}\nLosses: {}".format(self.get_monster_name(), self.family_name, self.level, Jobs.get_job_name(self.main_job), Jobs.get_job_name(self.support_job), ', '.join(self.innate_feral_skills), ', '.join(self.equipped_feral_skills), self.get_fp(), self.wins, self.losses)
        except AttributeError:
            return "Old Format monster, unable to display."
        #return "Family: {}\nLevel: {}\nMain Job: {}\nSupport Job: {}\nInnate Feral Skills: {}\nEquipped Feral Skills: {}\nDicipline Level: {}\nTemperament...".format(self.family, self.level, self.main_job, self.support_job, self.innate_feral_skills, self.equipped_feral_skills, self.discipline_level)


    def pre_fight_init(self):
        self.status_effects = {}
        self.hp = self.get_hp()
        self.mp = self.get_mp()
        effects = self.get_status_effect_list()
        for feral_skill in self.innate_feral_skills + self.equipped_feral_skills:
            effect = effects[FeralSkills.get_skill(feral_skill)['effect']]
            # Should init = true
            if effect:
                self.apply_feral_skill(feral_skill)


    def get_monster_name(self):
        if self.custom_name:
            return self.custom_name
        else:
            return self.monster_type

    def set_monster_name(self, name):
        self.custom_name = name

    def get_soul_plate_description(self):
        try:
            return "*Family:*\n**{}**\nJob Trait: {}\nFeral Points: {}".format(self.family_name, Jobs.get_job_name(self.main_job), self.get_fp())
        except AttributeError:
            return "Old Format monster, unable to display."
        #return "Family: {}\nLevel: {}\nMain Job: {}\nSupport Job: {}\nInnate Feral Skills: {}\nEquipped Feral Skills: {}\nDicipline Level: {}\nTemperament...".format(self.family, self.level, self.main_job, self.support_job, self.innate_feral_skills, self.equipped_feral_skills, self.discipline_level)

    def get_reflector_description(self):
        try:
            return "**{}**\n*Stats:*\nFamily: {}\nLevel: {}\nMain Job: {}\nSupport Job: {}\nInnate Feral Skills: {}\nEquipped Feral Skills: {}\nFeral Points: {}\n\nWins: {}\nLosses: {}".format(self.get_monster_name(), self.family_name, self.level, Jobs.get_job_name(self.main_job), Jobs.get_job_name(self.support_job), ', '.join(self.innate_feral_skills), ', '.join(self.equipped_feral_skills), self.get_fp(), self.wins, self.losses)
        except AttributeError:
            return "Old Format monster, unable to display."
        #return "Family: {}\nLevel: {}\nMain Job: {}\nSupport Job: {}\nInnate Feral Skills: {}\nEquipped Feral Skills: {}\nDicipline Level: {}\nTemperament...".format(self.family, self.level, self.main_job, self.support_job, self.innate_feral_skills, self.equipped_feral_skills, self.discipline_level)

    def get_hp(self):
        #this is a bit dumb but it's close enough.
        return self.get_status_effect('curse', 
                    self.get_status_effect('hp', 
                        int((self.level * 20) + self.base_hp)))

    def get_mp(self):
        #this is a bit dumb but it's close enough.

        main_add_amount = self.base_mp * adjustments_by_job[self.main_job]['mp_per_level']
        sub_add_amount = self.base_mp * adjustments_by_job[self.support_job]['mp_per_level']

        main_mp = int((self.level * (self.base_mp + main_add_amount)) + self.base_mp)
        sub_mp = int((self.level/2) * sub_add_amount)
        return self.get_status_effect('curse',
                self.get_status_effect('mp', main_mp + sub_mp))


    def get_available_fp(self):
        ttl_used = 0
        for fs in self.equipped_feral_skills:
            skill = FeralSkills.SkillsList.get(fs)
            if not skill:
                return False
            ttl_used += skill['fp_cost']
        return self.get_fp() - ttl_used

    def get_fp(self):
        return int(self.level / self.family['fp_per_level'] + self.family['base_fp'])

    def add_xp(self, exp_to_add):
        self.exp += exp_to_add
        original_level = self.level
        for i in range(self.level, 51):
            if self.exp >= 200 * i:
                if i > self.level:
                    # We leveled up!
                    self.level = i
            else:
                break
        if original_level > self.level:
            return (True, "Congratulations your monster leveled up!\n\nStart level: {} New Level: {}".format(original_level, self.level))
        else:
            return (False,None)

    def get_current_posture(self):
        return TemperamentPosture[self.temperament_posture]

    def get_current_attitude(self):
        return TemperamentAttitude[self.temperament_attitude]

    def get_dicipline_level(self):
        if self.dicipline_level < 2:
            return "Defiant"
        elif self.dicipline_level < 5:
            return "Disrespectful"
        elif self.dicipline_level < 7:
            return "Disobedient"
        else:
            return "Obedient"

    def get_combat_skill(self):
        # This is a very very complicated relationship betwen job and weapon type and how often it is used.
        # We are going to generalize it since it's a pain in the ass and just take the average A+ rating and get the cap for the current level
        return int(round(max(5, self.level * 2.88)))


    def get_dexterity(self):
        return self.get_status_effect('dex', int(round(max(self.base_dex, self.level * self.dex_per_level))))

    def get_accuracy(self):
        # We ignore magic / ranged / melee here and give everyone a good acc. This could be improved by doing a lookup for each type and based on the
        # type of monster (magic, range, or melee) then adjust the combat skill according to what type of attack is being performed.
        return self.get_status_effect('acc', math.floor(3*self.get_dexterity()/4) + self.get_combat_skill())

    def get_evasion(self):
        job_eva = adjustments_by_job[self.main_job]
        base_eva = int(round(max(job_eva['base_eva'], self.level * job_eva['eva_per_level'])))
        return self.get_status_effect('eva', base_eva + int(self.get_agility() / 2))

    def get_vitality(self):
        return self.get_status_effect('vit', int(round(max(self.base_vit, self.level * self.vit_per_level))))

    def get_strength(self):
        return self.get_status_effect('str', int(round(max(self.base_str, self.level * self.str_per_level))))

    def get_agility(self):
        return self.get_status_effect('agi', round(max(self.base_agi, self.level * self.agi_per_level)))

    def get_mind(self):
        return self.get_status_effect('mnd', int(round(max(self.base_mnd, self.level * self.mnd_per_level))))

    def get_intelligence(self):
        return self.get_status_effect('int', int(round(max(self.base_int, self.level * self.int_per_level))))

    def get_charisma(self):
        return self.get_status_effect('cha', int(round(max(self.base_chr, self.level * self.chr_per_level))))

    def get_base_defense(self):
        return self.get_status_effect('def', (math.floor(self.get_vitality()/2) + 8 + self.level))

    def get_hp_percent(self):
        return max(1, int(round((self.hp/self.get_hp())*100)))

    def get_magic_evasion(self, damage_type):
        # This handles spell types and elemental additions due to damage type
        return self.get_status_effect(damage_type + '_resist', max(1, int(1+round(self.level/4))))

    def get_hit_rate(self, enemy_eva, level_difference):
        rate = 75 + math.floor(((self.get_accuracy() - enemy_eva)/2)) - (2*level_difference)
        rate = self.get_status_effect('blind', rate)
        if rate < 20:
            rate = 20
        elif rate > 95:
            rate = 95
        return rate

    def get_magic_hit_rate(self, spell, enemy):
        # Calculate the magic accuracy
        spell_data = Spells.get_spell_data(spell)
        # Get the stat for the spell and base magic accuracy for that spells MA
        magic_acc_stat = spell_data['magic_acc_stat']
        if magic_acc_stat == 'int':
            print("DSTAT - INT")
            dSTAT = self.get_intelligence() - enemy.get_intelligence()
        elif magic_acc_stat == 'mnd':
            print("DSTAT - INT")
            dSTAT = self.get_mind() - enemy.get_mind()
        elif magic_acc_stat == 'chr':
            print("DSTAT - INT")
            dSTAT = self.get_charisma() - enemy.get_charisma()
        elif magic_acc_stat == 'agi':
            print("DSTAT - INT")
            dSTAT = self.get_agility() - enemy.get_agility()

        magic_hit_rate = 50 - 0.5 * (enemy.get_magic_evasion(spell_data['damage_type']) - dSTAT)
        magic_hit_rate = self.get_status_effect('magic_acc', magic_hit_rate)

        if magic_hit_rate < 5:
            magic_hit_rate = 5
        elif magic_hit_rate > 95:
            magic_hit_rate = 95
        print("DSTAT {}\nMagic Evasion: {}\nMagic hit rate: {}".format(dSTAT, enemy.get_magic_evasion(spell_data['damage_type']), magic_hit_rate))

        return magic_hit_rate

    def get_pdif(self, base_damage, defense, attack_type, level_difference):
        
        if defense == 0:
            ratio = 99
        else:
            ratio = base_damage / float(defense)
        if attack_type == 'ranged':
            cap = 3.0
        else:
            cap = 2.25
        if ratio > cap:
            ratio = cap
        # Get the level correction ratio
        if attack_type == 'ranged':
            cRatio = ratio - 0.025 * level_difference
        else:
            cRatio = ratio - 0.050 * level_difference
        if cRatio < 0:
            cRatio = 0
        if attack_type == 'ranged':
            if cRatio > 3.0:
                cRatio = 3.0
        else:
            if cRatio > 2.25:
                cRatio = 2.25
        # Calculate the pDif max as the max of our RNG
        if cRatio <= 0.5:
            pDif_max = 1+(10/9)*(cRatio-0.5)
        elif 0.5 <= cRatio <= float(3/4):
            pDif_max = 1
        elif float(3/4) <= cRatio <= cap:
            pDif_max = 1+(10/9)*(cRatio-float(3/4))

        # Calculate the pDif max as the max of our RNG
        if cRatio <= 0.5:
            pDif_min = 1/6
        elif 0.5 <= cRatio <= 1.25:
            pDif_min = 1+(10/9)*(cRatio-1.25)
        elif 1.25 <= cRatio <= 1.5:
            pDif_min = 1
        elif 1.5 <= cRatio <= cap:
            pDif_min = 1+(10/9)*(cRatio-1.5)

        # Some fuckery since python doesn't let you do a rand between decimals
        pDif_rand = float(random.randint(int(pDif_min*100000), int(pDif_max*100000))) / 100000.0
        return pDif_rand * cRatio

    def get_physical_ws_damage(self, defense, attack_type, fTP, modifiers, level_difference, enemy_vit):
        level_range_alpha = 1.01 - (math.floor(float(self.level) / 5.0) / 100.0)
        wsc = 0
        for modifier in modifiers:
            if modifier['stat'] == 'str':
                wsc += (modifer['percent'] / 100) * self.get_strength()
            elif modifiers['stat'] == 'vit':
                wsc += (modifer['percent'] / 100) * self.get_vitality()
            elif modifiers['stat'] == 'dex':
                wsc += (modifer['percent'] / 100) * self.get_dexterity()
            elif modifiers['stat'] == 'agi':
                wsc += (modifer['percent'] / 100) * self.get_agility()
            elif modifiers['stat'] == 'eva':
                wsc += (modifer['percent'] / 100) * self.get_evasion()
            elif modifiers['stat'] == 'int':
                wsc += (modifer['percent'] / 100) * self.get_intelligence()
            elif modifiers['stat'] == 'mnd':
                wsc += (modifer['percent'] / 100) * self.get_mind()
        wsc = (wsc * level_range_alpha)

        bd = float(self.weapon_base_damage)
        if attack_type == 'ranged':
            bd += self.ammo_damage

        fstr = ((self.get_strength() - enemy_vit)+4) / 4

        # These are specific to each WS
        fTP_1000 = fTP[0]
        fTP_2000 = fTP[1]
        fTP_3000 = fTP[2]

        if self.tp < 1000:
            return
        if 1000 <= self.tp <= 2000:
            prev_anchor = fTP_1000
            next_anchor = fTP_2000
            dTP = float(self.tp - 1000) / 1000.0
        elif 2000 <= self.tp <= 3000:
            prev_anchor = fTP_2000
            next_anchor = fTP_3000
            dTP = float(self.tp - 2000) / 1000.0

        fTP = prev_anchor + (dTP * (next_anchor - prev_anchor))
        pDif = self.get_pdif(bd, defense, attack_type, level_difference)

        final_damage = int((bd + fstr + wsc) * fTP * pDif)

        return final_damage

    def get_magic_base_damage(self, spell, enemy):

        if spell in ['Banish', 'Holy']:
            dINT = self.get_mind() - enemy.get_mind()
        else:
            dINT = self.get_intelligence() - enemy.get_intelligence()

        spell_data = Spells.get_spell_data(spell)

        base_damage = 0
        if dINT < 0:
            # multiplier ignored since dINT is too low.
            base_damage = spell_data['base_damage'] + dINT
        elif 0 <= dINT <= 150:
            base_damage = spell_data['base_damage'] + (dINT * spell_data['multiplier'])
        if base_damage < 0:
            base_damage = 0
        # We can skip multi-target damage reduction. There is no such thing since we only have a single enemy.

        # Calculate the hit rate so we can determine if the resistance applied to the base damage.
        resist_level = 0
        for i in range(0, 3):
            if not self.is_a_magic_hit(spell, enemy):
                resist_level += 1
                base_damage = base_damage / 2
        if resist_level == 3:
            base_damage = 0

        # TODO: Add weather later maybe

        # Not adding in magic burst since it is primarily a player thing
        base_damage *= enemy.target_magic_damage_adjustment

        return base_damage

    def equip_feral_skill(self, feral_skill):
        fs = FeralSkills.get_skill(feral_skill)
        log("{} {}".format(feral_skill, self.equipped_feral_skills))
        if feral_skill in self.equipped_feral_skills:
            return False, "Unable to equip the feral skill. The monster already has this skill equipped."
        if self.get_available_fp() >= fs['fp_cost']:
            self.equipped_feral_skills.append(feral_skill)
            return True, ""
        else:
            return False, "Your monster does not have enough feral points. {} of {} feral points available.", format(self.get_available_fp(), self.get_fp())

    def unequip_feral_skill(self, feral_skill):
        self.equipped_feral_skills.remove(feral_skill)

    def apply_feral_skill(self, feral_skill):
        #    'Amnesia Attack': {'fp_cost': 47, 'effect': 'amnesia', 'amount': 1, 'is_percent': False, 'expires_seconds': 0, 'levels': False},
        fs = FeralSkills.get_skill(feral_skill)
        self.set_status_effect(fs['effect'], fs['amount'], fs['is_percent'], fs['expires_seconds'])
        if feral_skill == 'Curse Attack':
            self.hp = min(self.hp, self.get_hp())
            self.mp = min(self.mp, self.get_mp())

    def convert_to_feral_skill(self):
        if random.randint(1, 100) < SKILL_PERCENT:
            log("family: {}".format(self.family))
            log("Skills: {}".format(self.family['feral_skills_conversion']))
            return WeightedChoice(self.family['feral_skills_conversion']).pick()


    # it is up to the rest of the system to understand how to read this data and act on it.
    # Example Call: ('acc', '10', False, 30)
    def set_status_effect(self, effect, amount, is_percent, expires_seconds):
        self.status_effects[effect] = {'amount': amount, 'is_percent': is_percent, 'expires_seconds': expires_seconds}

    def get_status_effect(self, effect, base_amount):

        if effect in self.status_effects:
            amount = self.status_effects[effect]['amount']
            if self.status_effects[effect]['is_percent']:
                return int(base_amount + base_amount * (amount/100))
            else:
                return int(base_amount + amount)
        else:
            return base_amount

    # This is a list of all status effects that are available and if they should be auto intialized.
    def get_status_effect_list(self):
        return {
            'acc': True,
            'agi': True,
            'cha': True,
            'def': True,
            'dex': True,
            'eva': True,
            'hp': True,
            'int': True,
            'mnd': True,
            'mp': True,
            'str': True,
            'vit': True,
            'store_tp': True,
            'fire_resist': True,
            'water_resist': True,
            'ice_resist': True,
            'wind_resist': True,
            'earth_resist': True,
            'thunder_resist': True,
            'light_resist': True,
            'dark_resist': True,
            'damage_resist': True,
            'auto_refresh': True,
            'auto_regain': True,
            'auto_regen': True,
            'amnesia': False,
            'amorph_killer': False,
            'aquan_killer': False,
            'bird_killer': False,
            'demon_killer': False,
            'dragon_killer': False,
            'lizard_killer': False,
            'plantoid_killer': False,
            'undead_killer': False,
            'vermin_killer': False,
            'attack': False,
            'blind': False,
            'curse': False,
            'poison': False,
            'silence': False,
            'magic_acc': True,
            'magic_attack': True,
        }

    # Calculate the base damage against the provided defense
    # attack_type can be 'ranged' or 'melee'
    # TODO: Replace enemyvit with the actual enemy variable
    def get_physical_base_damage(self, defense, attack_type, level_difference, enemy_vit):
        #print("Defense: {} Type: {} Level diff: {}".format(defense, attack_type, level_difference))
        # Calculate the attack/defense ratio
        bd = float(self.weapon_base_damage)
        if attack_type == 'ranged':
            bd += self.ammo_damage
        pDif = self.get_pdif(bd, defense, attack_type, level_difference)

        fstr = ((self.get_strength() - enemy_vit)+4) / 4
        log("Str: {} Vit: {} fstr: {}".format(self.get_strength(), enemy_vit, fstr))
        bd = bd + fstr
        final_damage = int(bd * pDif)
        return final_damage

    # Choose the best action for the monster
    def get_best_action(self, monster):
        # Step 0: Am I already casting a spell? Is it time to calc damage from that?

        # Step 1: Is magic possible?

        # Step 2: Do i have a memory of this monster from past battles?  Does it have any elemental weakness?

        spell_list = Spells.get_spell_list(self.mp, self.level, job=self.main_job, support_job=self.support_job)
        best_spell_name = None
        if spell_list and 'silence' not in self.status_effects:
            if monster.family_name in self.battle_memory:
                battles = self.battle_memory[monster.family_name]
                # this assumes spells are: 'spells':{'Fire': 100, 'Stone II': 500}
                if 'spells' in battles:
                    # if i have tried all spells then i know the right spell, otherwise try 
                    # one of the ones that i don't know
                    if len(battles['spells']) == len(spell_list):
                        # get the sorted spell list by best average damage against this monster. 
                        for i in max(battles['spells'].iteritems(), key=operator.itemgetter(1)):
                            best_spell_name = i
                            break
                    else:
                        untried_spells = []
                        for i in spell_list:
                            if i not in battles['spells']:
                                untried_spells.append(i)
                        best_spell_name = random.choice(untried_spells)
                else:
                    best_spell_name = random.choice(spell_list)
            else:
                best_spell_name = random.choice(spell_list)
        # Step 3: What status effects is the monster currently under? What are the effects(DOTS) we can apply?
        spell_damage = 0
        if best_spell_name:
            print("BEST SPELL NAME: {}".format(best_spell_name))
            spell_damage = self.get_magic_base_damage(best_spell_name, monster)

        # TODO: Make this follow the behavior in temprament and select the right behavior.
        if self.tp >= 1000:
            physical_damage = self.get_physical_ws_damage(monster.get_base_defense(), 'melee', [1.0, 1.5, 4.0], [], monster.level - self.level, monster.get_vitality())
        else:
            physical_damage = self.get_physical_base_damage(monster.get_base_defense(), 'melee', monster.level - self.level, monster.get_vitality())

        return (best_spell_name, spell_damage, physical_damage)

        # Step 4: find out the avg damage from each type of attack and sort them
        
        # find out if we need to do defensive actions given the amount of life left in the enemy vs how much damage it does.
        # We should also store how hard the AI has hit previously and adjust accordingly (Store previous average damage per hit). IE project how much damage we will 
        # do vs how much they will do and choose an action

        # Decide if we need to do healing as part of the defensive strategy.
        #   - This should be partially decided based on the class and the efficacy of healing
        #   - This should be comparied against shielding. Shielding is often based on a specific type of hit so remember the hits they have
        #       Taken on us in the past.

        # Modify apply damage to pass what type of damage it was (magic, melee, or ranged)

        # If we don't need defense (we thi)
        pass

    def attack(self, monster):
        is_a_crit = False
        is_a_hit = False
        spell = None
        resisted = False
        intimidated = False
        damage = 0

        if self.unable_to_move(monster):
            return AttackResponse(is_a_hit, damage, is_a_crit, spell, resisted, True)

        # intialize the monster memory for this family name if it isn't already set.
        if monster.family_name not in self.battle_memory:
            self.battle_memory[monster.family_name] = {'spells': {}}
        action_result = self.get_best_action(monster)
        print("AI RESULTS: {}".format(action_result))
        # TODO: Add a nice response object from the action choice to make this code pretty. (no tuple)
        if action_result[1] > action_result[2]:
            spell = action_result[0]
            if self.is_a_magic_hit(spell, monster):
                damage = self.get_magic_base_damage(spell, monster)
                if damage == 0:
                    resisted = True
                damage = self.get_status_effect('magic_attack', damage)
                log("MAGIC DAMAGE: {}".format(damage))
                is_a_hit = True
                spell_data = Spells.get_spell_data(spell)
                self.mp -= spell_data['mp_cost']
                if self.mp < 0:
                    self.mp = 0
            # if the spell already exists then average the two damage amounts.
            if spell in self.battle_memory[monster.family_name]['spells']:
                self.battle_memory[monster.family_name]['spells'][spell] = damage + (self.battle_memory[monster.family_name]['spells'][spell]) / 2
            else:
                self.battle_memory[monster.family_name]['spells'][spell] = damage
            return AttackResponse(is_a_hit, damage, is_a_crit, spell, resisted, intimidated)
        else:
            if self.is_a_hit(monster):
                if random.randint(1, 100) < ATTACK_EFFECT_PERCENTAGE: # 50% chance of applying the effects "XXX Attack"
                    if 'Amnesia Attack' in self.equipped_feral_skills:
                        monster.apply_feral_skill('Amnesia Attack')
                    if 'Blinding Attack' in self.equipped_feral_skills:
                        monster.apply_feral_skill('Blinding Attack')
                    if 'Curse Attack' in self.equipped_feral_skills:
                        monster.apply_feral_skill('Curse Attack')
                    if 'Poisoning Attack' in self.equipped_feral_skills:
                        monster.apply_feral_skill('Poisoning Attack')
                    if 'Silencing Attack' in self.equipped_feral_skills:
                        monster.apply_feral_skill('Silencing Attack')

                # TODO: Make this follow the behavior in temperament and select the right behavior.
                if self.tp >= 1000 and not self.get_status_effect('amnesia', 0):
                    damage = self.get_physical_ws_damage(monster.get_base_defense(), 'melee', [1.0, 1.5, 4.0], [], monster.level - self.level, monster.get_vitality())
                    log("WS DAMAGE: {}".format(damage))
                    self.tp = 0
                else:
                    damage = self.get_physical_base_damage(monster.get_base_defense(), 'melee', monster.level - self.level, monster.get_vitality())
                    print("STD DAMAGE: {}".format(damage))
                    self.tp += self.get_status_effect('store_tp', 64)
                damage = self.get_status_effect('damage_resist', damage)
                is_a_hit = True
            # Returns the amount of damage and if it is a crit
            return AttackResponse(is_a_hit, damage, is_a_crit, spell, resisted, intimidated)            

    # This determines if a monster is paralized or intimidated and unable to act.
    def unable_to_move(self, monster):
        killer_type = "{}_{}".format(monster.family['type'], "killer").lower()
        if killer_type in self.status_effects:
            if random.randint(1, 100) < self.status_effects[killer_type]['amount']:
                return True
        return False
        #if 

        #monster.family['type'] == killer

    def is_a_magic_hit(self, spell, monster):
        hit_rate = self.get_magic_hit_rate(spell,  monster)
        return random.randint(1, 100) < hit_rate

    def is_a_hit(self, monster):
        hit_rate = self.get_hit_rate(monster.get_evasion(),  monster.level - self.level)
        return random.randint(1, 100) < hit_rate

    def apply_damage(self, damage, is_spell=False):
        self.hp -= damage
        if is_spell:
            self.tp += 100
        else:
            self.tp += 30

    def apply_per_tick_adjustment(self):
        # apply all healing first
        self.mp = self.get_status_effect('auto_refresh', self.mp)
        self.tp = self.get_status_effect('auto_regain', self.tp)
        self.hp = self.get_status_effect('auto_regen', self.hp)

        # apply DOTs
        self.hp = self.get_status_effect('poison', self.hp)

    # This should ONLY be executed at the start of battle.
    def set_strategy(self, temperament_posture, temperament_attitude):        
        distance_from_nature = abs(self.temperament_posture - temperament_posture)
        distance_from_nature += abs(self.temperament_attitude - temperament_attitude)

        if distance_from_nature == 0:
            chance_of_listening = self.discipline_level
        else:
            chance_of_listening = float(float(self.discipline_level) / (float(distance_from_nature)/10))

        chance_of_listening = abs(float((float(chance_of_listening)-1)/(20-1)))

        if random.randint(1, 100) > chance_of_listening * 100:
            print("DO ACTION:")
            # adjust dicipline_level
            # move temperament
        else:
            #continue action
            #if severe request then reduce dicipline_level
            pass

class Action:
    def __init__(self, monster):
        self.monster = monster

class AttackAction(Action):
    STANDARD_MESSAGES = ['hit', 'smashed', 'walloped', 'struck', 'beat',
                         'knocked', 'punched', 'belted', 'decked', 'banged',
                         'battered', 'clipped', 'slapped', 'bashed', 'socked',
                         'smacked', 'thumped', 'cuffed', 'flogged', 'whacked',
                         'clobbered', 'swatted']
    MAGIC_MESSAGES = ['cast']
    CRIT_MESSAGES = ['CRITICALLY hit']

    def __init__(self, attacker, target, damage, is_a_crit=False, spell=None):
        self.attacker = attacker
        self.target = target
        self.damage = damage
        self.spell = spell
        if spell:
            self.message = random.choice(AttackAction.MAGIC_MESSAGES)
        elif is_a_crit:
            self.message = random.choice(AttackAction.CRIT_MESSAGES)
        else:
            self.message = random.choice(AttackAction.STANDARD_MESSAGES)

#TODO: Modify and add resist as part of attacks
class MagicResistAction(Action):
    MESSAGES = ['resisted']

    def __init__(self, attacker, target, spell):
        self.attacker = attacker
        self.target = target
        self.spell = spell
        self.message = random.choice(MagicResistAction.MESSAGES)


class IntimidatedAction(Action):
    MESSAGES = ['was unable to act']

    def __init__(self, attacker):
        self.attacker = attacker
        self.message = random.choice(IntimidatedAction.MESSAGES)

class MissAction(Action):
    MAGIC_MESSAGES = ['fizzled the spell against']
    MESSAGES = ['missed', 'was unable to hit', 'attack went wide of', 'fumbled the hit on']

    def __init__(self, attacker, target, spell):
        self.attacker = attacker
        self.target = target
        self.spell = spell
        if spell:
            self.message = random.choice(MissAction.MESSAGES)
        else:
            self.message = random.choice(MissAction.MAGIC_MESSAGES)

class DefeatAction(Action):
    MESSAGES = ['was defeated', 'was smited', 'was conquered', 'was routed', 'was thwarted',
                'was vanquished', 'was bested']
    def __init__(self, attacker, target, xp, losing_xp):
        self.attacker = attacker
        self.target = target
        self.message = random.choice(DefeatAction.MESSAGES)
        self.xp = xp
        self.losing_xp = xp


class Arena:

    def __init__(self, monster1, monster2, battle_type):
        self.monster1 = monster1
        self.monster2 = monster2
        self.battle_type = battle_type

    def init_monsters(self):
        self.monster1.pre_fight_init()
        self.monster2.pre_fight_init()

    def start(self):
        self.init_monsters()
        self.m1_init = self.monster1.get_agility() + random.randint(1, 20)
        self.m2_init = self.monster2.get_agility() + random.randint(1, 20)

    def step(self):
        actions = []
        if self.m1_init > self.m2_init:
            primary = self.monster1
            secondary = self.monster2
        else:
            primary = self.monster2
            secondary = self.monster1
        # TODO: Add a way to decide if the monster will use magic or melee or range

        #if primary.is_a_magic_hit(spell, secondary)
        result1 = primary.attack(secondary)
        if result1.intimidated:
            actions.append(IntimidatedAction(primary))
        elif result1.resisted:
            actions.append(MagicResistAction(primary, secondary, result1.spell))
        elif result1.is_a_hit:
            secondary.apply_damage(result1.damage)
            actions.append(AttackAction(primary, secondary, result1.damage, result1.is_a_crit,
                           result1.spell))
            # apply healing then dots to make sure secondary survived.
            secondary.apply_per_tick_adjustment()
            if secondary.hp <= 0:
                level_difference = secondary.level - primary.level
                if level_difference in exp_table:
                    xp = exp_table[level_difference]
                elif level_difference > 15:
                    xp = exp_table[15]
                else:
                    xp = 0
                losing_xp = max(5, 11*level_difference)
                if losing_xp > 75:
                    losing_xp = 75

                actions.append(DefeatAction(primary, secondary, xp, losing_xp))
                return actions
        else:
            actions.append(MissAction(primary, secondary, result1.spell))

        result2 = secondary.attack(primary)
        if result2.intimidated:
            actions.append(IntimidatedAction(secondary))
        elif result2.resisted:
            actions.append(MagicResistAction(secondary, primary, result2.spell))
        elif result2.is_a_hit:
            primary.apply_damage(result2.damage)
            actions.append(AttackAction(secondary, primary, result2.damage, result2.is_a_crit,
                           result2.spell))
            tick_result = primary.apply_per_tick_adjustment()

            if primary.hp <= 0:
                level_difference = primary.level - secondary.level
                if level_difference in exp_table:
                    xp = exp_table[level_difference]
                elif level_difference > 15:
                    xp = exp_table[15]
                else:
                    xp = 0
                losing_xp = max(5, 11*level_difference)
                if losing_xp > 75:
                    losing_xp = 75
                actions.append(DefeatAction(secondary, primary, xp, losing_xp))
                return actions
        else:
            actions.append(MissAction(secondary, primary, result2.spell))
        return actions


if __name__ == "__main__":
    #print Families

    print("Spell List: \n{}\n".format(Spells.get_spell_list(100, 10, job=Jobs.RDM, support_job=Jobs.WAR)))
    hunt_response = None
    p = Pankration()
    print("Zones: \n\n{}".format('\n'.join(p.list_zones())))
    hunt_zone = p.list_zones().keys()[0]
    print("Hunting for monster in zone: {}\n".format(hunt_zone))
    while not hunt_response or (hasattr(hunt_response, 'result') and hunt_response.result != HuntResponse.SUCCESS):
        hunt_response = p.hunt_monster(hunt_zone)
    print("hunt_response")
    print(str(hunt_response.result))
    time.sleep(0.5)
    if hunt_response.result == HuntResponse.SUCCESS:
        print(hunt_response.message)
        monster = hunt_response.monster
        monster.set_monster_name('Kickass 1')
        monster.set_status_effect('demon_killer', 50, False, None)

        print("The Soul Plate Shows: \n\n{}".format(monster))
        # print(monster.set_strategy(4, 3))
        # print(monster.set_strategy(1, 1))
        # print(monster.set_strategy(1, 2))
        #monster.add_xp(22900)
        # phy_damage = monster.get_physical_base_damage(100, 'melee', -15)
        # print("Phys Attack: {}".format(phy_damage))
        # print(monster.get_base_defense())
        # monster.add_xp(22900)
        # print(monster.get_base_defense())
        # monster.add_xp(222900)
        # print(monster.get_base_defense())
    else:
        print(hunt_response.message)

    hunt_response2 = None
    hunt_zone = p.list_zones().keys()[1]
    while not hunt_response2 or (hasattr(hunt_response2, 'result') and hunt_response2.result != HuntResponse.SUCCESS):
        hunt_response2 = p.hunt_monster(hunt_zone)
    if hunt_response2.result == HuntResponse.SUCCESS:
        monster2 = hunt_response2.monster
        monster2.set_monster_name('wreckbutt 2')
        print("1 The Soul Plate Shows: \n\n{}".format(monster))
        print("2 The Soul Plate Shows: \n\n{}".format(monster2))
        print("MP m1: {}\nMP m2: {}".format(monster.get_mp(), monster2.get_mp()))
        #print(monster2.add_xp(16900))
        monster2.set_status_effect('demon_killer', 50, False, None)
        phy_damage = monster2.attack(monster)
        print("Phys Attack: {}".format(phy_damage))
        phy_damage = monster.attack(monster2)
        print("Phys Attack2: {}".format(phy_damage))


    print("Acc: {}".format(monster.get_accuracy()))
    print("Eva: {}".format(monster.get_evasion()))

    print("Acc: {}".format(monster2.get_accuracy()))
    print("Eva: {}".format(monster2.get_evasion()))

    battle_arena = p.start_battle(monster, monster2, "derp")
    fighting = True
    while fighting:
        actions = battle_arena.step()
        time.sleep(3)
        for action in actions:
            if isinstance(action, IntimidatedAction):
                print("{} {}.".format(action.attacker.get_monster_name(), action.message))
            if isinstance(action, MagicResistAction):
                print("{} {} {} while casting {}.".format(action.attacker.get_monster_name(), action.message, action.target.get_monster_name(), action.spell))
            if isinstance(action, MissAction):
                print("{} {} {} while casting {}.".format(action.attacker.get_monster_name(), action.message, action.target.get_monster_name(), action.spell))
            if isinstance(action, AttackAction):
                print("{} {} {} against {} for {}.".format(action.attacker.get_monster_name(), action.message, action.spell, action.target.get_monster_name(), action.damage))
            if isinstance(action, DefeatAction):
                print("{} {} {} gains {} xp.".format(action.target.get_monster_name(), action.message, action.attacker.get_monster_name(), action.xp))
                #print(action.attacker.add_xp(action.xp))
                print("{} {}".format(action.target.hp, action.attacker.hp))
                fighting = False
                break
        print("\n\nhp: {} {}\nmp: {} {}\n\n".format(monster.hp, monster2.hp, monster.mp, monster2.mp))
        print("\n{} {}%    -    {}  {}%\n".format(monster.get_monster_name(), monster.get_hp_percent(), monster2.get_monster_name(), monster2.get_hp_percent()))
        print("\n{} Memory: {}\n\n{} Memory: {}\n\n".format(monster.get_monster_name(), monster.battle_memory, monster2.get_monster_name(), monster2.battle_memory))