<s> import sqlite3 <EOL> import os . path <EOL> import pickle <EOL> from objects import * <EOL> from utils import * <EOL> import globalvars as g <EOL> database = None <EOL> def setupDatabase ( ) : <EOL> global database <EOL> database = Database ( g . dataFolder + "<STR_LIT>" ) <EOL> class Database ( ) : <EOL> def __init__ ( self , database ) : <EOL> if os . path . isfile ( database ) : <EOL> g . serverLogger . info ( '<STR_LIT>' ) <EOL> else : <EOL> g . serverLogger . info ( '<STR_LIT>' ) <EOL> self . createDatabase ( database ) <EOL> return <EOL> self . conn = sqlite3 . connect ( database ) <EOL> self . conn . row_factory = sqlite3 . Row <EOL> self . cursor = self . conn . cursor ( ) <EOL> def createDatabase ( self , database_name ) : <EOL> '''<STR_LIT>''' <EOL> self . conn = sqlite3 . connect ( database_name ) <EOL> self . conn . row_factory = sqlite3 . Row <EOL> self . cursor = self . conn . cursor ( ) <EOL> self . sendQuery ( "<STR_LIT>" ) <EOL> self . sendQuery ( "<STR_LIT>" ) <EOL> self . sendQuery ( "<STR_LIT>" ) <EOL> self . sendQuery ( "<STR_LIT>" ) <EOL> self . sendQuery ( "<STR_LIT>" ) <EOL> self . sendQuery ( "<STR_LIT>" ) <EOL> self . sendQuery ( "<STR_LIT>" ) <EOL> self . sendQuery ( "<STR_LIT>" ) <EOL> self . sendQuery ( "<STR_LIT>" ) <EOL> self . sendQuery ( "<STR_LIT>" ) <EOL> self . sendQuery ( "<STR_LIT>" ) <EOL> self . sendQuery ( "<STR_LIT>" ) <EOL> self . sendQuery ( "<STR_LIT>" ) <EOL> self . sendQuery ( "<STR_LIT>" ) <EOL> self . sendQuery ( "<STR_LIT>" ) <EOL> self . sendQuery ( "<STR_LIT>" ) <EOL> self . sendQuery ( "<STR_LIT>" ) <EOL> self . saveChanges ( ) <EOL> g . serverLogger . info ( '<STR_LIT>' ) <EOL> def sendQuery ( self , query , * args ) : <EOL> try : <EOL> return self . cursor . execute ( query , * args ) <EOL> except sqlite3 . Error , msg : <EOL> print msg <EOL> def saveChanges ( self ) : <EOL> self . conn . commit ( ) <EOL> def closeDatabase ( self ) : <EOL> self . conn . close ( ) <EOL> def getNumberOfRows ( self , tableName ) : <EOL> '''<STR_LIT>''' <EOL> result = self . sendQuery ( "<STR_LIT>" + tableName + "<STR_LIT:;>" ) <EOL> return result . fetchone ( ) [ <NUM_LIT:0> ] <EOL> def accountExists ( name ) : <EOL> query = database . sendQuery ( "<STR_LIT>" % name ) <EOL> rows = query . fetchone ( ) <EOL> if not rows : <EOL> return False <EOL> else : <EOL> return True <EOL> def passwordOK ( name , password ) : <EOL> if accountExists ( name ) : <EOL> query = database . sendQuery ( "<STR_LIT>" % name ) <EOL> rows = query . fetchone ( ) <EOL> if password == rows [ <NUM_LIT:2> ] : <EOL> return True <EOL> def addAccount ( index , name , password ) : <EOL> Player [ index ] . Login = name <EOL> Player [ index ] . Password = password <EOL> for i in range ( MAX_CHARS ) : <EOL> clearChar ( index , i ) <EOL> saveAccount ( name , password ) <EOL> savePlayer ( index ) <EOL> def deleteName ( name ) : <EOL> print "<STR_LIT>" <EOL> def charExist ( index , charNum ) : <EOL> if len ( Player [ index ] . char [ charNum ] . name ) > <NUM_LIT:0> : <EOL> return True <EOL> def addChar ( index , name , sex , classNum , charNum ) : <EOL> if len ( Player [ index ] . char [ charNum ] . name ) == <NUM_LIT:0> : <EOL> print "<STR_LIT>" <EOL> TempPlayer [ index ] . charNum = charNum <EOL> Player [ index ] . char [ charNum ] . name = name <EOL> Player [ index ] . char [ charNum ] . sex = sex <EOL> Player [ index ] . char [ charNum ] . Class = classNum <EOL> Player [ index ] . char [ charNum ] . sprite = Class [ classNum ] . sprite <EOL> Player [ index ] . char [ charNum ] . level = <NUM_LIT:1> <EOL> Player [ index ] . char [ charNum ] . exp = <NUM_LIT:0> <EOL> for n in range ( Stats . stat_count ) : <EOL> Player [ index ] . char [ charNum ] . stats [ n ] = Class [ classNum ] . stat [ n ] <EOL> Player [ index ] . char [ charNum ] . vitals [ Vitals . hp ] = getPlayerMaxVital ( index , Vitals . hp ) <EOL> Player [ index ] . char [ charNum ] . vitals [ Vitals . mp ] = getPlayerMaxVital ( index , Vitals . mp ) <EOL> Player [ index ] . char [ charNum ] . vitals [ Vitals . sp ] = getPlayerMaxVital ( index , Vitals . sp ) <EOL> Player [ index ] . char [ charNum ] . map = START_MAP <EOL> Player [ index ] . char [ charNum ] . x = START_X <EOL> Player [ index ] . char [ charNum ] . y = START_Y <EOL> savePlayer ( index ) <EOL> def saveChar ( index ) : <EOL> print "<STR_LIT>" <EOL> def delChar ( index , charNum ) : <EOL> clearChar ( index , charNum ) <EOL> savePlayer ( index ) <EOL> def findChar ( name ) : <EOL> query = database . sendQuery ( "<STR_LIT>" % name ) <EOL> rows = query . fetchone ( ) <EOL> if rows == None : <EOL> return False <EOL> else : <EOL> return True <EOL> def saveAccount ( name , password ) : <EOL> query = database . sendQuery ( "<STR_LIT>" % ( name , password ) ) <EOL> database . saveChanges ( ) <EOL> def savePlayer ( index ) : <EOL> query = database . sendQuery ( "<STR_LIT>" % getPlayerName ( index ) ) <EOL> rows = query . fetchone ( ) <EOL> if rows == None : <EOL> query = database . sendQuery ( "<STR_LIT>" % getPlayerLogin ( index ) ) <EOL> result = query . fetchone ( ) <EOL> accountID = result [ '<STR_LIT:id>' ] <EOL> query = database . sendQuery ( "<STR_LIT>" , ( accountID , getPlayerName ( index ) , getPlayerClass ( index ) , getPlayerSprite ( index ) , getPlayerLevel ( index ) , getPlayerExp ( index ) , getPlayerAccess ( index ) , getPlayerMap ( index ) , getPlayerX ( index ) , getPlayerY ( index ) , getPlayerDir ( index ) , getPlayerEquipmentSlot ( index , Equipment . helmet ) , getPlayerEquipmentSlot ( index , Equipment . armor ) , getPlayerEquipmentSlot ( index , Equipment . weapon ) , getPlayerEquipmentSlot ( index , Equipment . shield ) , getPlayerStat ( index , Stats . strength ) , getPlayerStat ( index , Stats . defense ) , getPlayerStat ( index , Stats . speed ) , getPlayerStat ( index , Stats . magic ) , getPlayerVital ( index , Vitals . hp ) , getPlayerVital ( index , Vitals . mp ) , getPlayerVital ( index , Vitals . sp ) ) ) <EOL> elif len ( rows ) > <NUM_LIT:0> : <EOL> charId = rows [ '<STR_LIT:id>' ] <EOL> query = database . sendQuery ( """<STR_LIT>""" , ( getPlayerSprite ( index ) , getPlayerLevel ( index ) , getPlayerExp ( index ) , getPlayerMap ( index ) , getPlayerX ( index ) , getPlayerY ( index ) , getPlayerAccess ( index ) , getPlayerDir ( index ) , getPlayerEquipmentSlot ( index , Equipment . helmet ) , getPlayerEquipmentSlot ( index , Equipment . armor ) , getPlayerEquipmentSlot ( index , Equipment . weapon ) , getPlayerEquipmentSlot ( index , Equipment . shield ) , getPlayerStat ( index , Stats . strength ) , getPlayerStat ( index , Stats . defense ) , getPlayerStat ( index , Stats . speed ) , getPlayerStat ( index , Stats . magic ) , getPlayerVital ( index , Vitals . hp ) , getPlayerVital ( index , Vitals . mp ) , getPlayerVital ( index , Vitals . sp ) , getPlayerName ( index ) ) ) <EOL> for i in range ( MAX_INV ) : <EOL> if getPlayerInvItemNum ( index , i ) != None : <EOL> itemNum = getPlayerInvItemNum ( index , i ) <EOL> invQuery = database . sendQuery ( "<STR_LIT>" % ( charId , ( itemNum + <NUM_LIT:1> ) ) ) <EOL> invRows = query . fetchone ( ) <EOL> if invRows == None : <EOL> invQuery = database . sendQuery ( '<STR_LIT>' % ( charId , ( getPlayerInvItemNum ( index , i ) + <NUM_LIT:1> ) , <EOL> getPlayerInvItemValue ( index , i ) , <EOL> getPlayerInvItemDur ( index , i ) ) ) <EOL> elif len ( invRows ) > <NUM_LIT:0> : <EOL> rowId = invRows [ '<STR_LIT:id>' ] <EOL> invQuery = database . sendQuery ( '<STR_LIT>' % ( getPlayerInvItemValue ( index , i ) , getPlayerInvItemDur ( index , i ) , rowId ) ) <EOL> for i in range ( MAX_PLAYER_SPELLS ) : <EOL> if getPlayerSpell ( index , i ) is not None : <EOL> spellNum = getPlayerSpell ( index , i ) <EOL> spbQuery = database . sendQuery ( "<STR_LIT>" % ( charId , ( spellNum + <NUM_LIT:1> ) ) ) <EOL> spbRows = query . fetchone ( ) <EOL> if spbRows is None : <EOL> spbQuery = database . sendQuery ( '<STR_LIT>' , ( charId , spellNum + <NUM_LIT:1> ) ) <EOL> elif len ( spbRows ) > <NUM_LIT:0> : <EOL> continue <EOL> database . saveChanges ( ) <EOL> '''<STR_LIT>''' <EOL> def loadPlayer ( index , name ) : <EOL> clearPlayer ( index ) <EOL> query = database . sendQuery ( "<STR_LIT>" % name ) <EOL> rows = query . fetchone ( ) <EOL> accountID = rows [ '<STR_LIT:id>' ] <EOL> Player [ index ] . Login = rows [ '<STR_LIT:username>' ] <EOL> Player [ index ] . Password = rows [ '<STR_LIT:password>' ] <EOL> query = database . sendQuery ( "<STR_LIT>" % accountID ) <EOL> rows = query . fetchall ( ) <EOL> for i in range ( <NUM_LIT:0> , MAX_CHARS ) : <EOL> try : <EOL> Player [ index ] . char [ i ] . name = rows [ i ] [ '<STR_LIT:name>' ] <EOL> Player [ index ] . char [ i ] . Class = rows [ i ] [ '<STR_LIT:class>' ] <EOL> Player [ index ] . char [ i ] . access = rows [ i ] [ '<STR_LIT>' ] <EOL> Player [ index ] . char [ i ] . sprite = rows [ i ] [ '<STR_LIT>' ] <EOL> Player [ index ] . char [ i ] . level = rows [ i ] [ '<STR_LIT>' ] <EOL> Player [ index ] . char [ i ] . exp = rows [ i ] [ '<STR_LIT>' ] <EOL> Player [ index ] . char [ i ] . Map = rows [ i ] [ '<STR_LIT>' ] <EOL> Player [ index ] . char [ i ] . x = rows [ i ] [ '<STR_LIT:x>' ] <EOL> Player [ index ] . char [ i ] . y = rows [ i ] [ '<STR_LIT:y>' ] <EOL> Player [ index ] . char [ i ] . direction = rows [ i ] [ '<STR_LIT>' ] <EOL> Player [ index ] . char [ i ] . stats [ Stats . strength ] = rows [ i ] [ '<STR_LIT>' ] <EOL> Player [ index ] . char [ i ] . stats [ Stats . defense ] = rows [ i ] [ '<STR_LIT>' ] <EOL> Player [ index ] . char [ i ] . stats [ Stats . speed ] = rows [ i ] [ '<STR_LIT>' ] <EOL> Player [ index ] . char [ i ] . stats [ Stats . magic ] = rows [ i ] [ '<STR_LIT>' ] <EOL> Player [ index ] . char [ i ] . vitals [ Vitals . hp ] = rows [ i ] [ '<STR_LIT>' ] <EOL> Player [ index ] . char [ i ] . vitals [ Vitals . mp ] = rows [ i ] [ '<STR_LIT>' ] <EOL> Player [ index ] . char [ i ] . vitals [ Vitals . sp ] = rows [ i ] [ '<STR_LIT>' ] <EOL> Player [ index ] . char [ i ] . equipment [ Equipment . helmet ] = rows [ i ] [ '<STR_LIT>' ] <EOL> Player [ index ] . char [ i ] . equipment [ Equipment . armor ] = rows [ i ] [ '<STR_LIT>' ] <EOL> Player [ index ] . char [ i ] . equipment [ Equipment . weapon ] = rows [ i ] [ '<STR_LIT>' ] <EOL> Player [ index ] . char [ i ] . equipment [ Equipment . shield ] = rows [ i ] [ '<STR_LIT>' ] <EOL> charId = rows [ i ] [ <NUM_LIT:0> ] <EOL> invQuery = database . sendQuery ( "<STR_LIT>" % charId ) <EOL> invRow = invQuery . fetchall ( ) <EOL> for j in range ( len ( invRow ) ) : <EOL> try : <EOL> Player [ index ] . char [ i ] . inv [ j ] . num = invRow [ j ] [ '<STR_LIT>' ] - <NUM_LIT:1> <EOL> Player [ index ] . char [ i ] . inv [ j ] . value = invRow [ j ] [ '<STR_LIT:value>' ] <EOL> Player [ index ] . char [ i ] . inv [ j ] . dur = invRow [ j ] [ '<STR_LIT>' ] <EOL> except : <EOL> break <EOL> spbQuery = database . sendQuery ( "<STR_LIT>" % charId ) <EOL> spbRow = spbQuery . fetchall ( ) <EOL> for k in range ( len ( spbRow ) ) : <EOL> try : <EOL> setPlayerSpell ( index , k , spbRow [ k ] [ '<STR_LIT>' ] - <NUM_LIT:1> ) <EOL> except : <EOL> break <EOL> except : <EOL> break <EOL> def clearPlayer ( index ) : <EOL> '''<STR_LIT>''' <EOL> Player [ index ] = AccountClass ( ) <EOL> def clearChar ( index , charNum ) : <EOL> '''<STR_LIT>''' <EOL> Player [ index ] . char [ charNum ] = PlayerClass ( ) <EOL> def createClasses ( ) : <EOL> maxClasses = <NUM_LIT:2> <EOL> def loadClasses ( ) : <EOL> g . maxClasses = database . getNumberOfRows ( "<STR_LIT>" ) <EOL> for i in range ( <NUM_LIT:0> , g . maxClasses ) : <EOL> query = database . sendQuery ( "<STR_LIT>" % ( i + <NUM_LIT:1> ) ) <EOL> rows = query . fetchone ( ) <EOL> Class [ i ] . name = rows [ '<STR_LIT:name>' ] <EOL> Class [ i ] . sprite = rows [ '<STR_LIT>' ] <EOL> Class [ i ] . stat [ Stats . strength ] = int ( rows [ '<STR_LIT>' ] ) <EOL> Class [ i ] . stat [ Stats . defense ] = int ( rows [ '<STR_LIT>' ] ) <EOL> Class [ i ] . stat [ Stats . speed ] = int ( rows [ '<STR_LIT>' ] ) <EOL> Class [ i ] . stat [ Stats . magic ] = int ( rows [ '<STR_LIT>' ] ) <EOL> def saveClasses ( ) : <EOL> print "<STR_LIT>" <EOL> def clearClasses ( ) : <EOL> for i in range ( g . maxClasses ) : <EOL> Class [ i ] = ClassClass ( ) <EOL> def getClassName ( classNum ) : <EOL> return Class [ classNum ] . name <EOL> def getClassMaxVital ( classNum , vital ) : <EOL> if vital == Vitals . hp : <EOL> return ( <NUM_LIT:1> + ( Class [ classNum ] . stat [ Stats . strength ] // <NUM_LIT:2> ) + Class [ classNum ] . stat [ Stats . strength ] ) * <NUM_LIT:2> <EOL> elif vital == Vitals . mp : <EOL> return ( <NUM_LIT:1> + ( Class [ classNum ] . stat [ Stats . magic ] // <NUM_LIT:2> ) + Class [ classNum ] . stat [ Stats . magic ] ) * <NUM_LIT:2> <EOL> elif vital == Vitals . sp : <EOL> return ( <NUM_LIT:1> + ( Class [ classNum ] . stat [ Stats . speed ] // <NUM_LIT:2> ) + Class [ classNum ] . stat [ Stats . speed ] ) * <NUM_LIT:2> <EOL> def getClassStat ( classNum , stat ) : <EOL> return Class [ i ] . Stat [ stat ] <EOL> def saveItems ( ) : <EOL> for i in range ( MAX_ITEMS ) : <EOL> if Item [ i ] . name != '<STR_LIT>' : <EOL> saveItem ( i ) <EOL> def saveItem ( itemNum ) : <EOL> query = database . sendQuery ( "<STR_LIT>" % ( itemNum + <NUM_LIT:1> ) ) <EOL> rows = query . fetchone ( ) <EOL> if rows == None : <EOL> query = database . sendQuery ( "<STR_LIT>" % ( int ( itemNum + <NUM_LIT:1> ) , Item [ itemNum ] . name , Item [ itemNum ] . pic , Item [ itemNum ] . type , Item [ itemNum ] . data1 , Item [ itemNum ] . data2 , Item [ itemNum ] . data3 ) ) <EOL> elif len ( rows ) > <NUM_LIT:0> : <EOL> query = database . sendQuery ( "<STR_LIT>" % ( Item [ itemNum ] . name , Item [ itemNum ] . pic , Item [ itemNum ] . type , Item [ itemNum ] . data1 , Item [ itemNum ] . data2 , Item [ itemNum ] . data3 , int ( itemNum + <NUM_LIT:1> ) ) ) <EOL> database . saveChanges ( ) <EOL> def loadItems ( ) : <EOL> itemAmount = database . getNumberOfRows ( '<STR_LIT>' ) <EOL> for i in range ( <NUM_LIT:0> , itemAmount ) : <EOL> query = database . sendQuery ( "<STR_LIT>" % ( i + <NUM_LIT:1> ) ) <EOL> rows = query . fetchone ( ) <EOL> Item [ i ] . name = rows [ '<STR_LIT:name>' ] <EOL> Item [ i ] . pic = int ( rows [ '<STR_LIT>' ] ) <EOL> Item [ i ] . type = int ( rows [ '<STR_LIT:type>' ] ) <EOL> Item [ i ] . data1 = rows [ '<STR_LIT>' ] <EOL> Item [ i ] . data2 = rows [ '<STR_LIT>' ] <EOL> Item [ i ] . data3 = rows [ '<STR_LIT>' ] <EOL> def checkItems ( ) : <EOL> for i in range ( MAX_ITEMS ) : <EOL> print "<STR_LIT>" <EOL> def saveSpell ( spellNum ) : <EOL> query = database . sendQuery ( "<STR_LIT>" % ( spellNum + <NUM_LIT:1> ) ) <EOL> rows = query . fetchone ( ) <EOL> if rows == None : <EOL> query = database . sendQuery ( "<STR_LIT>" , ( int ( spellNum + <NUM_LIT:1> ) , Spell [ spellNum ] . name , Spell [ spellNum ] . pic , Spell [ spellNum ] . type , Spell [ spellNum ] . reqMp , Spell [ spellNum ] . reqClass , Spell [ spellNum ] . reqLevel , Spell [ spellNum ] . data1 , Spell [ spellNum ] . data2 , Spell [ spellNum ] . data3 ) ) <EOL> elif len ( rows ) > <NUM_LIT:0> : <EOL> query = database . sendQuery ( "<STR_LIT>" , ( Spell [ spellNum ] . name , Spell [ spellNum ] . pic , Spell [ spellNum ] . type , Spell [ spellNum ] . reqMp , Spell [ spellNum ] . reqClass , Spell [ spellNum ] . reqLevel , Spell [ spellNum ] . data1 , Spell [ spellNum ] . data2 , Spell [ spellNum ] . data3 , int ( spellNum + <NUM_LIT:1> ) ) ) <EOL> database . saveChanges ( ) <EOL> def saveSpells ( ) : <EOL> print '<STR_LIT>' <EOL> for i in range ( MAX_SPELLS ) : <EOL> saveSpell ( i ) <EOL> def loadSpells ( ) : <EOL> spellAmount = database . getNumberOfRows ( '<STR_LIT>' ) <EOL> for i in range ( <NUM_LIT:0> , spellAmount ) : <EOL> query = database . sendQuery ( "<STR_LIT>" % ( i + <NUM_LIT:1> ) ) <EOL> rows = query . fetchone ( ) <EOL> Spell [ i ] . name = rows [ '<STR_LIT:name>' ] <EOL> Spell [ i ] . pic = rows [ '<STR_LIT>' ] <EOL> Spell [ i ] . type = rows [ '<STR_LIT:type>' ] <EOL> Spell [ i ] . reqMp = rows [ '<STR_LIT>' ] <EOL> Spell [ i ] . reqClass = rows [ '<STR_LIT>' ] <EOL> Spell [ i ] . reqLevel = rows [ '<STR_LIT>' ] <EOL> Spell [ i ] . data1 = rows [ '<STR_LIT>' ] <EOL> Spell [ i ] . data2 = rows [ '<STR_LIT>' ] <EOL> Spell [ i ] . data3 = rows [ '<STR_LIT>' ] <EOL> def clearSpell ( index ) : <EOL> Spell [ index ] = SpellClass ( ) <EOL> def clearSpells ( ) : <EOL> for i in range ( MAX_SPELLS ) : <EOL> Spell [ i ] = SpellClass ( ) <EOL> def saveNpc ( npcNum ) : <EOL> query = database . sendQuery ( "<STR_LIT>" % ( npcNum + <NUM_LIT:1> ) ) <EOL> rows = query . fetchone ( ) <EOL> if rows == None : <EOL> query = database . sendQuery ( "<STR_LIT>" , ( int ( npcNum + <NUM_LIT:1> ) , NPC [ npcNum ] . name , NPC [ npcNum ] . sprite , NPC [ npcNum ] . attackSay , NPC [ npcNum ] . spawnSecs , NPC [ npcNum ] . behaviour , NPC [ npcNum ] . range , NPC [ npcNum ] . dropChance , NPC [ npcNum ] . dropItem , NPC [ npcNum ] . dropItemValue , NPC [ npcNum ] . stat [ Stats . strength ] , NPC [ npcNum ] . stat [ Stats . defense ] , NPC [ npcNum ] . stat [ Stats . magic ] , NPC [ npcNum ] . stat [ Stats . speed ] ) ) <EOL> elif len ( rows ) > <NUM_LIT:0> : <EOL> query = database . sendQuery ( "<STR_LIT>" , ( NPC [ npcNum ] . name , NPC [ npcNum ] . sprite , NPC [ npcNum ] . attackSay , NPC [ npcNum ] . spawnSecs , NPC [ npcNum ] . behaviour , NPC [ npcNum ] . range , NPC [ npcNum ] . dropChance , NPC [ npcNum ] . dropItem , NPC [ npcNum ] . dropItemValue , NPC [ npcNum ] . stat [ Stats . strength ] , NPC [ npcNum ] . stat [ Stats . defense ] , NPC [ npcNum ] . stat [ Stats . magic ] , NPC [ npcNum ] . stat [ Stats . speed ] , int ( npcNum + <NUM_LIT:1> ) ) ) <EOL> database . saveChanges ( ) <EOL> def saveNpcs ( ) : <EOL> for i in range ( MAX_NPCS ) : <EOL> saveNpcs ( i ) <EOL> def loadNpcs ( ) : <EOL> npcAmount = database . getNumberOfRows ( '<STR_LIT>' ) <EOL> for i in range ( <NUM_LIT:0> , npcAmount ) : <EOL> query = database . sendQuery ( "<STR_LIT>" % ( i + <NUM_LIT:1> ) ) <EOL> rows = query . fetchone ( ) <EOL> NPC [ i ] . name = rows [ '<STR_LIT:name>' ] <EOL> NPC [ i ] . attackSay = rows [ '<STR_LIT>' ] <EOL> NPC [ i ] . sprite = int ( rows [ '<STR_LIT>' ] ) <EOL> NPC [ i ] . spawnSecs = int ( rows [ '<STR_LIT>' ] ) <EOL> NPC [ i ] . behaviour = int ( rows [ '<STR_LIT>' ] ) <EOL> NPC [ i ] . range = int ( rows [ '<STR_LIT>' ] ) <EOL> NPC [ i ] . dropChance = int ( rows [ '<STR_LIT>' ] ) <EOL> NPC [ i ] . dropItem = rows [ '<STR_LIT>' ] <EOL> NPC [ i ] . dropItemValue = int ( rows [ '<STR_LIT>' ] ) <EOL> NPC [ i ] . stat [ Stats . strength ] = int ( rows [ '<STR_LIT>' ] ) <EOL> NPC [ i ] . stat [ Stats . defense ] = int ( rows [ '<STR_LIT>' ] ) <EOL> NPC [ i ] . stat [ Stats . magic ] = int ( rows [ '<STR_LIT>' ] ) <EOL> NPC [ i ] . stat [ Stats . speed ] = int ( rows [ '<STR_LIT>' ] ) <EOL> def saveMap ( mapNum ) : <EOL> pickle . dump ( Map [ mapNum ] , open ( g . dataFolder + "<STR_LIT>" + str ( mapNum ) + "<STR_LIT>" , '<STR_LIT:wb>' ) ) <EOL> def saveMaps ( ) : <EOL> for i in range ( MAX_MAPS ) : <EOL> saveMap ( i ) <EOL> def loadMaps ( ) : <EOL> checkMaps ( ) <EOL> for i in range ( MAX_MAPS ) : <EOL> Map [ i ] = pickle . load ( open ( g . dataFolder + "<STR_LIT>" + str ( i ) + "<STR_LIT>" , '<STR_LIT:rb>' ) ) <EOL> def checkMaps ( ) : <EOL> for i in range ( MAX_MAPS ) : <EOL> if not os . path . isfile ( g . dataFolder + "<STR_LIT>" + str ( i ) + "<STR_LIT>" ) : <EOL> saveMap ( i ) <EOL> def clearMapItem ( index , mapNum ) : <EOL> mapItem [ mapNum ] [ index ] = MapItemClass ( ) <EOL> def clearMapItems ( ) : <EOL> for i in range ( MAX_MAPS ) : <EOL> for j in range ( MAX_MAP_ITEMS ) : <EOL> clearMapItem ( j , i ) <EOL> def clearMapNpc ( index , mapNum ) : <EOL> mapNPC [ mapNum ] [ index ] = MapNPCClass ( ) <EOL> def clearMapNpcs ( ) : <EOL> for i in range ( MAX_MAPS ) : <EOL> for j in range ( MAX_MAP_NPCS ) : <EOL> clearMapNpc ( j , i ) <EOL> def clearMap ( mapNum ) : <EOL> Map [ mapNum ] . tileSet = <NUM_LIT:1> <EOL> Map [ mapNum ] . name = "<STR_LIT>" <EOL> playersOnMap [ mapNum ] = <NUM_LIT:0> <EOL> MapCache [ mapNum ] = "<STR_LIT>" <EOL> def clearMaps ( ) : <EOL> for i in range ( MAX_MAPS ) : <EOL> clearMap ( i ) <EOL> '''<STR_LIT>''' <EOL> def getPlayerLogin ( index ) : <EOL> return Player [ index ] . Login <EOL> '''<STR_LIT>''' <EOL> def getPlayerName ( index ) : <EOL> return Player [ index ] . char [ TempPlayer [ index ] . charNum ] . name <EOL> def setPlayerName ( index , name ) : <EOL> Player [ index ] . char [ TempPlayer [ index ] . charNum ] . name = name <EOL> '''<STR_LIT>''' <EOL> def getPlayerClass ( index ) : <EOL> return Player [ index ] . char [ TempPlayer [ index ] . charNum ] . Class <EOL> def setPlayerClass ( index , classNum ) : <EOL> Player [ index ] . char [ TempPlayer [ index ] . charNum ] . Class = classNum <EOL> '''<STR_LIT>''' <EOL> def getPlayerSprite ( index ) : <EOL> return Player [ index ] . char [ TempPlayer [ index ] . charNum ] . sprite <EOL> def setPlayerSprite ( index , sprite ) : <EOL> Player [ index ] . char [ TempPlayer [ index ] . charNum ] . sprite = sprite <EOL> '''<STR_LIT>''' <EOL> def getPlayerLevel ( index ) : <EOL> return Player [ index ] . char [ TempPlayer [ index ] . charNum ] . level <EOL> def setPlayerLevel ( index , level ) : <EOL> Player [ index ] . char [ TempPlayer [ index ] . charNum ] . level = level <EOL> '''<STR_LIT>''' <EOL> def getPlayerNextLevel ( index ) : <EOL> return ( getPlayerLevel ( index ) + <NUM_LIT:1> ) * ( getPlayerStat ( index , Stats . strength ) + getPlayerStat ( index , Stats . defense ) + getPlayerStat ( index , Stats . magic ) + getPlayerStat ( index , Stats . speed ) + getPlayerPoints ( index ) ) * <NUM_LIT> <EOL> '''<STR_LIT>''' <EOL> def getPlayerExp ( index ) : <EOL> return Player [ index ] . char [ TempPlayer [ index ] . charNum ] . exp <EOL> def setPlayerExp ( index , exp ) : <EOL> Player [ index ] . char [ TempPlayer [ index ] . charNum ] . exp = exp <EOL> '''<STR_LIT>''' <EOL> def getPlayerAccess ( index ) : <EOL> return Player [ index ] . char [ TempPlayer [ index ] . charNum ] . access <EOL> def setPlayerAccess ( index , access ) : <EOL> Player [ index ] . char [ TempPlayer [ index ] . charNum ] . access = access <EOL> '''<STR_LIT>''' <EOL> def getPlayerVital ( index , vital ) : <EOL> return Player [ index ] . char [ TempPlayer [ index ] . charNum ] . vitals [ vital ] <EOL> def setPlayerVital ( index , vital , value ) : <EOL> Player [ index ] . char [ TempPlayer [ index ] . charNum ] . vitals [ vital ] = value <EOL> if getPlayerVital ( index , vital ) > getPlayerMaxVital ( index , vital ) : <EOL> Player [ index ] . char [ TempPlayer [ index ] . charNum ] . vitals [ vital ] = getPlayerMaxVital ( index , vital ) <EOL> if getPlayerVital ( index , vital ) < <NUM_LIT:0> : <EOL> Player [ index ] . char [ TempPlayer [ index ] . charNum ] . vitals [ vital ] = <NUM_LIT:0> <EOL> '''<STR_LIT>''' <EOL> def getPlayerMaxVital ( index , vital ) : <EOL> charNum = TempPlayer [ index ] . charNum <EOL> if vital == Vitals . hp : <EOL> return ( Player [ index ] . char [ charNum ] . level + ( getPlayerStat ( index , Stats . strength ) // <NUM_LIT:2> ) + Class [ Player [ index ] . char [ charNum ] . Class ] . stat [ Stats . strength ] * <NUM_LIT:2> ) <EOL> elif vital == Vitals . mp : <EOL> return ( Player [ index ] . char [ charNum ] . level + ( getPlayerStat ( index , Stats . magic ) // <NUM_LIT:2> ) + Class [ Player [ index ] . char [ charNum ] . Class ] . stat [ Stats . magic ] * <NUM_LIT:2> ) <EOL> elif vital == Vitals . sp : <EOL> return ( Player [ index ] . char [ charNum ] . level + ( getPlayerStat ( index , Stats . speed ) // <NUM_LIT:2> ) + Class [ Player [ index ] . char [ charNum ] . Class ] . stat [ Stats . speed ] * <NUM_LIT:2> ) <EOL> '''<STR_LIT>''' <EOL> def getPlayerStat ( index , stat ) : <EOL> return Player [ index ] . char [ TempPlayer [ index ] . charNum ] . stats [ stat ] <EOL> def setPlayerStat ( index , stat , value ) : <EOL> Player [ index ] . char [ TempPlayer [ index ] . charNum ] . stats [ stat ] = value <EOL> '''<STR_LIT>''' <EOL> def getPlayerPoints ( index ) : <EOL> return Player [ index ] . char [ TempPlayer [ index ] . charNum ] . statsPoints <EOL> def setPlayerPoints ( index , points ) : <EOL> Player [ index ] . char [ TempPlayer [ index ] . charNum ] . statsPoints = points <EOL> '''<STR_LIT>''' <EOL> def getPlayerMap ( index ) : <EOL> return Player [ index ] . char [ TempPlayer [ index ] . charNum ] . Map <EOL> def setPlayerMap ( index , mapNum ) : <EOL> Player [ index ] . char [ TempPlayer [ index ] . charNum ] . Map = mapNum <EOL> '''<STR_LIT>''' <EOL> def getPlayerX ( index ) : <EOL> return Player [ index ] . char [ TempPlayer [ index ] . charNum ] . x <EOL> def setPlayerX ( index , x ) : <EOL> Player [ index ] . char [ TempPlayer [ index ] . charNum ] . x = x <EOL> '''<STR_LIT>''' <EOL> def getPlayerY ( index ) : <EOL> return Player [ index ] . char [ TempPlayer [ index ] . charNum ] . y <EOL> def setPlayerY ( index , y ) : <EOL> Player [ index ] . char [ TempPlayer [ index ] . charNum ] . y = y <EOL> '''<STR_LIT>''' <EOL> def getPlayerDir ( index ) : <EOL> return Player [ index ] . char [ TempPlayer [ index ] . charNum ] . Dir <EOL> def setPlayerDir ( index , direction ) : <EOL> Player [ index ] . char [ TempPlayer [ index ] . charNum ] . Dir = direction <EOL> '''<STR_LIT>''' <EOL> def getPlayerInvItemNum ( index , invSlot ) : <EOL> return Player [ index ] . char [ TempPlayer [ index ] . charNum ] . inv [ invSlot ] . num <EOL> def setPlayerInvItemNum ( index , invSlot , itemNum ) : <EOL> Player [ index ] . char [ TempPlayer [ index ] . charNum ] . inv [ invSlot ] . num = itemNum <EOL> def getPlayerInvItemValue ( index , invSlot ) : <EOL> return Player [ index ] . char [ TempPlayer [ index ] . charNum ] . inv [ invSlot ] . value <EOL> def setPlayerInvItemValue ( index , invSlot , itemValue ) : <EOL> Player [ index ] . char [ TempPlayer [ index ] . charNum ] . inv [ invSlot ] . value = itemValue <EOL> def getPlayerInvItemDur ( index , invSlot ) : <EOL> return Player [ index ] . char [ TempPlayer [ index ] . charNum ] . inv [ invSlot ] . dur <EOL> def setPlayerInvItemDur ( index , invSlot , itemDur ) : <EOL> Player [ index ] . char [ TempPlayer [ index ] . charNum ] . inv [ invSlot ] . dur = itemDur <EOL> '''<STR_LIT>''' <EOL> def getPlayerSpell ( index , spellSlot ) : <EOL> return Player [ index ] . char [ TempPlayer [ index ] . charNum ] . spell [ spellSlot ] <EOL> def setPlayerSpell ( index , spellSlot , spellNum ) : <EOL> Player [ index ] . char [ TempPlayer [ index ] . charNum ] . spell [ spellSlot ] = spellNum <EOL> '''<STR_LIT>''' <EOL> def getPlayerEquipmentSlot ( index , equipmentSlot ) : <EOL> return Player [ index ] . char [ TempPlayer [ index ] . charNum ] . equipment [ equipmentSlot ] <EOL> def setPlayerEquipmentSlot ( index , invNum , equipmentSlot ) : <EOL> Player [ index ] . char [ TempPlayer [ index ] . charNum ] . equipment [ equipmentSlot ] = invNum </s>
