#!/usr/bin/python3
# -*- coding: utf-8 -*-
#
# module CLFECOMMON
#
#    Copyright (C) 2019  AleaJactaEst
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.


from enum import IntEnum

def GetNameIntEnum(typeEnum,  value):
        for key in typeEnum.__dict__:
            try:
                #print("-"*80)
                #print(key, dir(typeEnum.__dict__[key]))
                #print(key, typeEnum.__dict__[key].value)
                if typeEnum.__dict__[key].value == value:
                    return key
            except:
                pass
        return None

class TConnectionState(IntEnum):
    NotInitialised = 0      # nothing happened yet
    NotConnected = 1        # init() called
    Authenticate = 2        # connect() called, identified by the login server
    Login = 3               # connecting to the frontend, sending identification
    Synchronize = 4         # connection accepted by the frontend, synchronizing
    Connected = 5           # synchronized, connected, ready to work
    Probe = 6               # connection lost by frontend, probing for response
    Stalled = 7             # server is stalled
    Disconnect = 8          # disconnect() called, or timeout, or connection closed by frontend
    Quit = 9                # quit() called

class TState(IntEnum):
    # initial state
    st_start = 0
    # display login screen and options
    st_login = 1
    # auto login using cmd lien parameters (used with patch reboot)
    st_auto_login = 2
    # display the shard list
    st_shard_list = 3
    # lauch the configurator and close ryzom
    st_start_config = 4
    # run the scan data thread
    st_scan_data = 5
    # display the eula and wait for validation
    st_display_eula = 6
    # check the data to determine need for patch
    st_check_patch = 7
    # display the list of optional patch category for patching
    st_display_cat = 8
    # run the patch process and display progress
    st_patch = 9
    # terminate the client and quit
    st_close_client = 10
    # display the reboot screen and wait validation
    st_reboot_screen = 11
    # restart the client with login bypass params
    st_restart_client = 12
    # connect to the FS (start the 'in game' mode)
    st_connect = 13
    # show the outgame browser
    st_browser_screen = 14
    # ingame state
    st_ingame = 15
    # leave the current shard (the exit action progress, Far TP part 1.1; Server Hop part 1-2)
    st_leave_shard = 16
    # let the main loop finish the current frame and leave it (Far TP part 1.2)
    st_enter_far_tp_main_loop = 17
    # disconnect from the FS (Far TP part 2)
    st_disconnect = 18
    # connect to a new FS (Far TP & Server Hop part 3.1)
    st_reconnect_fs = 19
    # after reconnecting, bypass character selection ui & select the same character (Far TP & Server Hop part 3.2)
    st_reconnect_select_char = 20
    # after reconnecting and receiving ready, send ready (Far TP part 3.3)
    st_reconnect_ready = 21
    # between global menu exit and sending ready (Server Hop part 3.3)
    st_exit_global_menu = 22
    # error while reconnecting
    st_reconnect_error = 23
    # Rate a ring session. should pop a web windows pointing the rate session page
    st_rate_session = 24
    # create account
    st_create_account = 25
    # try to login with alternate login system
    st_alt_login = 26
    # pseudo state to leave the state machine
    st_end = 27
    st_unknown = 28


class EGender(IntEnum):
    male = 0
    female = 1
    neutral = 2
    unknown = 4


class TPeople(IntEnum):
    Undefined = -1
    Humanoid = 0
    Playable = 0
    Fyros = 0
    Matis = 1
    Tryker = 2
    Zorai = 3
    EndPlayable = 4
    Karavan = 4
    Tribe = 5
    Common = 6
    EndHumanoid = 7
    Creature = 7
    Fauna = 7
    Arma = 7
    Balduse = 8
    Bul = 9
    Capryni = 10
    Chonari = 11
    Clapclap = 12
    Cococlaw = 13
    Cute = 14
    Dag = 15
    Diranak = 16
    Estrasson = 17
    Filin = 18
    Frahar = 19
    Gibbai = 20
    Hachtaha = 21
    Jungler = 22
    Kakty = 23
    Kalab = 24
    Kami = 25
    Kazoar = 26
    Kitin = 27
    Kitins = 28
    Kitifly = 28
    Kitihank = 29
    Kitiharak = 30
    Kitikil = 31
    Kitimandib = 32
    Kitinagan = 33
    Kitinega = 34
    Kitinokto = 35
    EndKitins = 36
    Lightbird = 36
    Mektoub = 37
    MektoubPacker = 38
    MektoubMount = 39
    Pucetron = 40
    Regus = 41
    Ryzerb = 42
    Ryzoholo = 43
    Ryzoholok = 44
    Vampignon = 45
    Varinx = 46
    Yber = 47
    Zerx = 48
    race_c1 = 49
    race_c2 = 50
    race_c3 = 51
    race_c4 = 52
    race_c5 = 53
    race_c6 = 54
    race_c7 = 55
    race_h1 = 56
    race_h2 = 57
    race_h3 = 58
    race_h4 = 59
    race_h5 = 60
    race_h6 = 61
    race_h7 = 62
    race_h8 = 63
    race_h9 = 64
    race_h10 = 65
    race_h11 = 66
    race_h12 = 67
    EndFauna = 68
    Flora = 68
    Cephaloplant = 68
    Electroalgs = 69
    Phytopsy = 70
    SapEnslaver = 71
    SpittingWeeds = 72
    Swarmplants = 73
    EndFlora = 74
    Goo = 74
    GooFauna = 74
    GooArma = 74
    GooBalduse = 75
    GooBul = 76
    GooCapryni = 77
    GooChonari = 78
    GooClapclap = 79
    GooCococlaw = 80
    GooCute = 81
    GooDag = 82
    GooDiranak = 83
    GooEstrasson = 84
    GooFilin = 85
    GooFrahar = 86
    GooGibbai = 87
    GooHachtaha = 88
    GooJungler = 89
    GooKakty = 90
    GooKalab = 91
    GooKami = 92
    GooKazoar = 93
    GooKitifly = 94
    GooKitihank = 95
    GooKitiharak = 96
    GooKitikil = 97
    GooKitimandib = 98
    GooKitin = 99
    GooKitinagan = 100
    GooKitinega = 101
    GooKitinokto = 102
    GooLightbird = 103
    GooMektoub = 104
    GooMektoubPacker = 105
    GooMektoubMount = 106
    GooPucetron = 107
    GooRegus = 108
    GooRyzerb = 109
    GooRyzoholo = 110
    GooRyzoholok = 111
    GooVampignon = 112
    GooVarinx = 113
    GooYber = 114
    GooZerx = 115
    Goorace_c1 = 116
    Goorace_c2 = 117
    Goorace_c3 = 118
    Goorace_c4 = 119
    Goorace_c5 = 120
    Goorace_c6 = 121
    Goorace_c7 = 122
    Goorace_h1 = 123
    Goorace_h2 = 124
    Goorace_h3 = 125
    Goorace_h4 = 126
    Goorace_h5 = 127
    Goorace_h6 = 128
    Goorace_h7 = 129
    Goorace_h8 = 130
    Goorace_h9 = 131
    Goorace_h10 = 132
    Goorace_h11 = 133
    Goorace_h12 = 134
    EndGooFauna = 135
    GooPlant = 135
    GooCephaloplant = 135
    GooElectroalgs = 136
    GooPhytopsy = 137
    GooSapEnslaver = 138
    GooSpittingWeeds = 139
    GooSwarmplants = 140
    EndGooPlant = 141
    EndGoo = 141
    EndCreature = 141
    ___TPeople_useSize = 142
    Unknown = 142
    EndPeople = 142


class ECharacterTitle(IntEnum):
    '''
        khanat-opennel-code/code/ryzom/common/src/game_share/character_title.h # enum ECharacterTitle
    '''
    Refugee = 0
    Homin = 1 #
    Novice_Artisan = 2 #
    Novice_Warrior = 3 #
    Novice_Harvester = 4 #
    Novice_Magician = 5 #
    Artisan_Apprentice = 6 #
    Magician_Apprentice = 7 #
    Defensive_Magician = 8 #
    Offensive_Magician = 9 #
    Mentalist = 10 #
    Summoner = 11 #
    Master_Of_Illusion = 12 #
    Mind_Lord = 13 #
    Healer = 14 #
    Priest = 15 #
    Master_Of_Life = 16 #
    Celestial_Guardian = 17 #
    Disturber = 18 #
    Affliction_Bringer = 19 #
    Master_Of_Torment = 20 #
    Avatar_Of_Sorrow = 21 #
    Destroyer = 22 #
    Archmage = 23 #
    Master_Of_Pain = 24 #
    Avatar_Of_Destruction = 25 #
    Elementalist = 26 #
    Alchemist = 27 #
    Biomancer = 28 #
    Master_Of_Energies = 29 #
    Chosen_Of_Atys = 30 #
    Warrior_Apprentice = 31 #
    Melee_Warrior = 32 #
    Range_Fighter = 33 #
    Light_Armsman = 34 #
    Heavy_Armsman = 35 #
    Close_Fighter = 36 #
    Gunman = 37 #
    Heavy_Gunman = 38 #
    Advanced_Gunman = 39 #
    Advanced_Heavy_Gunman = 40 #
    Bludgeoner = 41 #
    Skewerer = 42 #
    Slasher = 43 #
    Smasher = 44 #
    Impaler = 45 #
    Cleaver = 46 #
    Advanced_Close_Fighter = 47 #
    Maceman = 48 #
    Brute = 49 #
    Spearman = 50 #
    Axeman = 51 #
    Swordsman = 52 #
    Heavy_Maceman = 53 #
    Pikeman = 54 #
    Heavy_Axeman = 55 #
    Heavy_Swordsman = 56 #
    Knifeman = 57 #
    Hand_To_Hand_Fighter = 58 #
    Bowman = 59 #
    Pistoleer = 60 #
    Heavy_Bowman = 61 #
    Artilleryman = 62 #
    Rifleman = 63 #
    Master_Maceman = 64 #
    Master_Brute = 65 #
    Master_Spearman = 66 #
    Master_Axeman = 67 #
    Master_Swordsman = 68 #
    Master_Heavy_Maceman = 69 #
    Master_Pikeman = 70 #
    Master_Heavy_Axeman = 71 #
    Master_Heavy_Swordsman = 72 #
    Master_Knifeman = 73 #
    Master_Hand_To_Hand_Fighter = 74 #
    Master_Bowman = 75 #
    Master_Pistoleer = 76 #
    Master_Heavy_Bowman = 77 #
    Master_Artilleryman = 78 #
    Master_Rifleman = 79 #
    Armorer_Apprentice = 80 #
    Jeweler_Apprentice = 81 #
    Melee_Weapon_Smith_Apprentice = 82 #
    Range_Weapon_Smith_Apprentice = 83 #
    Heavy_Armorer = 84 #
    Light_Armorer = 85 #
    Medium_Armorer = 86 #
    Shield_Smith = 87 #
    Jeweler = 88 #
    Melee_Weapon_Smith = 89 #
    Melee_Heavy_Weapon_Smith = 90 #
    Melee_Light_Weapon_Smith = 91 #
    Range_Weapon_Smith = 92 #
    Range_Heavy_Weapon_Smith = 93 #
    Advanced_Heavy_Armorer = 94 #
    Advanced_Light_Armorer = 95 #
    Advanced_Medium_Armorer = 96 #
    Advanced_Shield_Smith = 97 #
    Advanced_Jeweler = 98 #
    Advanced_Melee_Weapon_Smith = 99 #
    Advanced_Melee_Heavy_Weapon_Smith = 100 #
    Advanced_Melee_Light_Weapon_Smith = 101 #
    Advanced_Range_Weapon_Smith = 102 #
    Advanced_Range_Heavy_Weapon_Smith = 103 #
    Expert_Heavy_Armorer = 104 #
    Expert_Light_Armorer = 105 #
    Expert_Medium_Armorer = 106 #
    Expert_Shield_Smith = 107 #
    Expert_Jeweler = 108 #
    Expert_Melee_Weapon_Smith = 109 #
    Expert_Melee_Heavy_Weapon_Smith = 110 #
    Expert_Melee_Light_Weapon_Smith = 111 #
    Expert_Range_Weapon_Smith = 112 #
    Expert_Range_Heavy_Weapon_Smith = 113 #
    Heavy_Armorer_Master = 114 #
    Light_Armorer_Master = 115 #
    Medium_Armorer_Master = 116 #
    Shield_Smith_Master = 117 #
    Jeweler_Master = 118 #
    Melee_Weapon_Smith_Master = 119 #
    Melee_Heavy_Weapon_Smith_Master = 120 #
    Melee_Light_Weapon_Smith_Master = 121 #
    Range_Weapon_Smith_Master = 122 #
    Range_Heavy_Weapon_Smith_Master = 123 #
    Forager_Apprentice = 124 #
    Forager = 125 #
    Desert_Forager = 126 #
    Forest_Forager = 127 #
    Jungle_Forager = 128 #
    Lacustre_Forager = 129 #
    Prime_Roots_Forager = 130 #
    Advanced_Desert_Forager = 131 #
    Advanced_Forest_Forager = 132 #
    Advanced_Jungle_Forager = 133 #
    Advanced_Lacustre_Forager = 134 #
    Advanced_Prime_Roots_Forager = 135 #
    Expert_Desert_Forager = 136 #
    Expert_Forest_Forager = 137 #
    Expert_Jungle_Forager = 138 #
    Expert_Lacustre_Forager = 139 #
    Expert_Prime_Roots_Forager = 140 #
    Master_Desert_Forager = 141 #
    Master_Forest_Forager = 142 #
    Master_Jungle_Forager = 143 #
    Master_Lacustre_Forager = 144 #
    Master_Prime_Roots_Forager = 145 #
    Kami_Ally = 146 #
    Karavan_Ally = 147 #
    Title00000 = 148 #
    Title00001 = 149 #  // Journeyer
    Title00002 = 150 #  // Novice Kitin Hunter
    Title00003 = 151 #  // Kitin Hunter
    Title00004 = 152 #  // Master Kitin Hunter
    Title00005 = 153 #  // Kitin Eradicator
    Title00006 = 154 #  // Kitin Mass Murderer
    Title00007 = 155 #  // Matis Guardian
    Title00008 = 156 #  // Fyros Guardian
    Title00009 = 157 #  // Tryker Guardian
    Title00010 = 158 #  // Zorai Guardian
    Title00011 = 159 #  // Atys Guardian
    Title00012 = 160 #
    Title00013 = 161 #
    Title00014 = 162 #  // The fortunate
    Title00015 = 163 #  // Jinxed
    Title00016 = 164 #
    Title00017 = 165 #
    Title00018 = 166 #
    Title00019 = 167 #
    Title00020 = 168 #  // Fyros Patriot
    Title00021 = 169 #  // Matis Vassal
    Title00022 = 170 #  // Tryker Citizen
    Title00023 = 171 #  // Zorai Initiate
    Title00024 = 172 #  // Kami Disciple
    Title00025 = 173 #  // Karavan Follower
    Title00026 = 174 #  // Fyros Akenak
    Title00027 = 175 #  // Matis Noble
    Title00028 = 176 #  // Tryker Taliar
    Title00029 = 177 #  // Zorai Awakened
    Title00030 = 178 #  // Marauder
    Title00031 = 179 #  // Fyros Ambassador
    Title00032 = 180 #  // Matis Ambassador
    Title00033 = 181 #  // Tryker Ambassador
    Title00034 = 182 #  // Zorai Ambassador
    Title00035 = 183 #
    Title00036 = 184 #
    Title00037 = 185 #
    Title00038 = 186 #
    Title00039 = 187 #
    Title00040 = 188 #
    Title00041 = 189 #
    Title00042 = 190 #
    Title00043 = 191 #
    Title00044 = 192 #
    Title00045 = 193 #
    Title00046 = 194 #
    Title00047 = 195 #  // Machinegunner
    Title00048 = 196 #  // Assault Machinegunner
    Title00049 = 197 #
    Title00050 = 198 #  // Apprentice Butcher
    Title00051 = 199 #  // Butcher
    Title00052 = 200 #  // Apprentice Florist
    Title00053 = 201 #  // Florist
    Title00054 = 202 #  // Apprentice Water-Carrier
    Title00055 = 203 #  // Water-Carrier
    Title00056 = 204 #  // Apprentice Magnetic
    Title00057 = 205 #  // Magnetic Cartographe
    Title00058 = 206 #  // Apprentice Toolmaker
    Title00059 = 207 #  // Toolmaker
    Title00060 = 208 #  // Apprentice Rescuer
    Title00061 = 209 #  // Rescuer
    Title00062 = 210 #  // Apprentice Larvester
    Title00063 = 211 #  // Larvester
    Title00064 = 212 #  // Apprentice Scrollmaker
    Title00065 = 213 #  // Scrollmaker
    Title00066 = 214 #
    Title00067 = 215 #
    Title00068 = 216 #
    Title00069 = 217 #
    Title00070 = 218 #
    Title00071 = 219 #
    Title00072 = 220 #
    Title00073 = 221 #
    Title00074 = 222 #
    Title00075 = 223 #
    Title00076 = 224 #
    Title00077 = 225 #
    Title00078 = 226 #
    Title00079 = 227 #  // Wayfarer
    WIND = Title00079 #     // Title for player come from old Windermmer community
    FBT = 228 #
    BeginGmTitle = 229 #
    # SGM = BeginGmTitle #
    GM = 230 #
    VG = 231 #
    SG = 232 #
    G = 233 #
    CM = 234 #
    EM = 235 #
    EG = 236 #
    OBSERVER = 237 #
    # EndGmTitle = OBSERVER,
    NB_CHARACTER_TITLE = 238


class CLFECOMMON(IntEnum):
    SYSTEM_LOGIN_CODE = 0
    SYSTEM_SYNC_CODE = 1
    SYSTEM_ACK_SYNC_CODE = 2
    SYSTEM_PROBE_CODE = 3
    SYSTEM_ACK_PROBE_CODE = 4
    SYSTEM_DISCONNECTION_CODE = 5
    SYSTEM_STALLED_CODE = 6
    SYSTEM_SERVER_DOWN_CODE = 7
    SYSTEM_QUIT_CODE = 8
    SYSTEM_ACK_QUIT_CODE = 9
    NumBitsInLongAck = 512

class TActionCode(IntEnum):
    ACTION_POSITION_CODE = 0
    ACTION_GENERIC_CODE = 1
    ACTION_GENERIC_MULTI_PART_CODE = 2
    ACTION_SINT64 = 3
    ACTION_SYNC_CODE = 10
    ACTION_DISCONNECTION_CODE = 11
    ACTION_ASSOCIATION_CODE = 12
    ACTION_LOGIN_CODE = 13
    ACTION_TARGET_SLOT_CODE = 40
    ACTION_DUMMY_CODE = 99
    ACTION_NONE = 999


class Card(IntEnum):
    BEGIN_TOKEN = 0
    END_TOKEN = 1
    SINT_TOKEN = 2
    UINT_TOKEN = 3
    FLOAT_TOKEN = 4
    STRING_TOKEN = 5
    FLAG_TOKEN = 6
    EXTEND_TOKEN = 7


class TType(IntEnum):
    STRUCT_BEGIN = 0
    STRUCT_END = 1
    FLAG = 2
    SINT32 = 3
    UINT32 = 4
    FLOAT32 = 5
    STRING = 6
    SINT64 = 7
    UINT64 = 8
    FLOAT64 = 9
    EXTEND_TYPE = 10
    NB_TYPE = 11


class NPC_ICON(IntEnum): # TNPCMissionGiverState
    AwaitingFirstData = 0
    NotAMissionGiver = 1
    ListHasOutOfReachMissions = 2
    ListHasAlreadyTakenMissions = 3
    ListHasAvailableMission = 4
    AutoHasUnavailableMissions = 5
    AutoHasAvailableMission = 6
    NbMissionGiverStates = 7

class TInventoryId(IntEnum):
        Bag = 0,
        Packers = 1,
        Room= 5,  # Packers+MaxNbPackers,
        InvalidInvId = 6,
        NbInventoryIds = 6, #  =InvalidInvId

class TItemPropId(IntEnum):
    Sheet = 0,
    Quality = 1,
    Quantity = 2,
    UserColor = 3,
    CreateTime = 4,
    Serial = 5,
    Locked = 6,
    Weight = 7,
    NameId = 8,
    Enchant = 9,
    ItemClass = 10,
    ItemBestStat = 11,
    Price = 12,
    ResaleFlag = 13,
    PrerequisitValid = 14,
    Worned = 15,
    NbItemPropId = 16

class TCDBBank(IntEnum):
    CDBPlayer = 0,
    CDBGuild = 1,
    # CDBContinent,
    CDBOutpost = 2,
    # CDBGlobal,
    NB_CDB_BANKS = 3,
    INVALID_CDB_BANK = 4,  
    NB_BITS_FOR_CDBBANK = 2 # normally calculate with NB_CDB_BANKS // ------ for ( nbits=1; (1<<nbits) < NB_CDB_BANKS; ++nbits ) {}

class TPropIndex(IntEnum):
    PROPERTY_POSITION = 0,
    PROPERTY_POSX = 0,
    PROPERTY_POSY = 1, 
    PROPERTY_POSZ = 2,
    PROPERTY_ORIENTATION = 3, 
    PROPERTY_SHEET = 4
    PROPERTY_BEHAVIOUR = 5, 
    PROPERTY_NAME_STRING_ID = 6, 
    PROPERTY_TARGET_ID = 7, 
    PROPERTY_MODE = 8, 
    PROPERTY_VPA = 9, 
    PROPERTY_VPB = 10, 
    PROPERTY_VPC = 11, 
    PROPERTY_ENTITY_MOUNTED_ID = 12, 
    PROPERTY_RIDER_ENTITY_ID = 13, 
    PROPERTY_CONTEXTUAL = 14, 
    PROPERTY_BARS = 15
    PROPERTY_TARGET_LIST = 16, 
    PROPERTY_TARGET_LIST_0 = 16, 
    PROPERTY_TARGET_LIST_1 = 17,  
    PROPERTY_TARGET_LIST_2 = 18, 
    PROPERTY_TARGET_LIST_3 = 19, 
    PROPERTY_GUILD_SYMBOL = 20, 
    PROPERTY_GUILD_NAME_ID = 21, 
    PROPERTY_VISUAL_FX = 22, 
    PROPERTY_EVENT_FACTION_ID = 23, 
    PROPERTY_PVP_MODE = 24, 
    PROPERTY_PVP_CLAN = 25, 
    PROPERTY_OWNER_PEOPLE = 26, 
    PROPERTY_OUTPOST_INFOS = 27, 
    NB_VISUAL_PROPERTIES = 28
    
class TPVPMode(IntEnum):
    NONE				= 0,
    PvpDuel				= 1,
    PvpChallenge		= 2,
    PvpZoneFree			= 4,
    PvpZoneFaction		= 8,
    PvpZoneGuild		= 16,
    PvpZoneOutpost		= 32,
    PvpFaction			= 64,
    PvpFactionFlagged	= 128,
    PvpZoneSafe			= 256,
    PvpSafe				= 512,
    #Unknown = 513,
    #NbModes = 513,
    NbBits = 10 #// number of bits needed to store all valid values