pankration.py 50.6 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
import random
import time
import pickle
import math
import collections
import logging

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

FIND_PERCENTAGE = 100
SKILL_PERCENT = 80

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

    def get_job_name(self, 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']
}

FeralSkills = {
    '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},
}

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} },
    }

    def get_spell_list(self, level, job = None, sub_job = None):
        available_spells = []
        for spell_name, spell in self.SpellList.iteritems():
            if job and job in spell['jobs'] and spell['jobs'][job] <= level:
                if spell_name not in available_spells:
                    available_spells.append(spell_name)
            if sub_job and sub_job in spell['jobs'] and spell['jobs'][sub_job] <= level / 2:
                if spell_name not in available_spells:
                    available_spells.append(spell_name)
        return sorted(available_spells)

    def get_spell_data(self, spell):
        spell = self.SpellList[spell]
        type_data = self.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']
        }
        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,
        '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',
        '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': 15,
        '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': 15,
        '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': 15,
    },
    'Morbid Eye': {
        'family': 'ahriman',
        'zone': ['castle zvahl baileys', 'castle zvahl keep'],
        'hp': 15,
        'mp': 24,
        'weapon_base_damage': 15
    },
    'Deadly Iris': {
        'family': 'ahriman',
        'zone': ['castle zvahl keep'],
        'hp': 15,
        'mp': 24,
        'weapon_base_damage': 15
    },
    'Ahriman': {
        'family': 'ahriman',
        'zone': ['castle zvahl baileys'],
        'hp': 15,
        'mp': 24,
        'weapon_base_damage': 15
    },
    'Fachan': {
        'family': 'ahriman',
        'zone': ['uleguerand range'],
        'hp': 15,
        'mp': 24,
        'weapon_base_damage': 15
    },
    'Gawper': {
        'family': 'ahriman',
        'zone': ['beaucedine glacier (s)'],
        'hp': 15,
        'mp': 24,
        'weapon_base_damage': 15
    },
    'Menacing Eye': {
        'family': 'ahriman',
        'zone': ['xarcabard (s)'],
        'hp': 15,
        'mp': 24,
        'weapon_base_damage': 15
    },
    'Ogler': {
        'family': 'ahriman',
        'zone': ['castle zvahl keep (s)', 'castle zvahl baileys (s)'],
        'hp': 15,
        'mp': 24,
        'weapon_base_damage': 15
    },
    'Smolenkos': {
        'family': 'ahriman',
        'zone': ['uleguerand range'],
        'hp': 15,
        'mp': 24,
        'weapon_base_damage': 15
    },
    'Doom Lens': {
        'family': 'ahriman',
        'zone': ['castle zvahl keep (s)', 'castle zvahl baileys (s)'],
        'hp': 15,
        'mp': 24,
        'weapon_base_damage': 15
    },
    'Scowlenkos': {
        'family': 'ahriman',
        'zone': ['uleguerand range'],
        'hp': 15,
        'mp': 24,
        'weapon_base_damage': 15
    }

}

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 = []
            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):
        self.spell = spell
        self.is_a_crit = is_a_crit
        self.is_a_hit = is_a_hit
        self.resisted = resisted
        self.damage = damage

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

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.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

    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 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 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 main_mp + sub_mp


    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
        for i in range(self.level, 51):
            if self.exp >= 200 * i:
                if i > self.level:
                    # We leveled up!
                    self.level = i
                    return (True, "Congratulations your monster leveled up!\n\nStart level: {} New Level: {}".format(self.level, i))
            else:
                break
        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 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 int(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 base_eva + int(self.get_agility() / 2)

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

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

    def get_agility(self):
        return int(round(max(self.base_agi, self.level * self.agi_per_level)))

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

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

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

    def get_base_defense(self):
        return (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):
        return 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)
        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':
            dSTAT = self.get_intelligence() - enemy.get_intelligence()
        elif magic_acc_stat == 'mnd':
            dSTAT = self.get_mind() - enemy.get_mind()
        elif magic_acc_stat == 'chr':
            dSTAT = self.get_charisma() - enemy.get_charisma()
        elif magic_acc_stat == 'agi':
            dSTAT = self.get_agility() - enemy.get_agility()

        magic_hit_rate = 50 - 0.5 * (enemy.get_magic_evasion() - dSTAT)

        if magic_hit_rate < 5:
            magic_hit_rate = 5
        elif magic_hit_rate > 95:
            magic_hit_rate = 95
        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

    # 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

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


        ######
        # TODO: Build some type of AI / testing to find the most powerful attack and use that (magic, melee, or ranged)
        ######

        spell = 'Fire'
        if self.is_a_magic_hit(spell, monster):
            damage = self.get_magic_base_damage(spell, monster)
            if damage == 0:
                resisted = True
            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
        return AttackResponse(is_a_hit, damage, is_a_crit, spell, resisted)

        if self.is_a_hit(monster):
            # TODO: Make this follow the behavior in temprament and select the right behavior.
            if self.tp >= 1000:
                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 += 64
            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)

    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

    # 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 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):
        self.attacker = attacker
        self.target = target
        self.message = random.choice(DefeatAction.MESSAGES)
        self.xp = xp


class Arena:

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

    def heal_monsters(self):
        self.monster1.hp = self.monster1.get_hp()
        self.monster2.hp = self.monster2.get_hp()
        self.monster1.mp = self.monster1.get_mp()
        self.monster2.mp = self.monster2.get_mp()

    def start(self):
        self.heal_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.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))
            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
                actions.append(DefeatAction(primary, secondary, xp))
                return actions
        else:
            actions.append(MissAction(primary, secondary, result1.spell))

        result2 = secondary.attack(primary)
        if 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))
            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
                actions.append(DefeatAction(secondary, primary, 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(20, job=Jobs.BLM, sub_job=Jobs.WHM)))
    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')
        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()))
        monster2.add_xp(16900)
        phy_damage = monster2.attack(monster)
        print("Phys Attack: {}".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(2)
        for action in actions:
            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))
                action.attacker.hp = 500
                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()))