home *** CD-ROM | disk | FTP | other *** search
-
-
- import Bladex
- import GameState
- import MemPersistence
- import BBLib
- import string
-
-
- class MainCharState(GameState.EntityPersonState):
- "Clase para grabar el estado del jugador"
-
- def __init__(self,ent_name="Player1"):
- entity=Bladex.GetEntity(ent_name)
-
- if not entity:
- return
-
- import Actions
-
-
- self.Props={}
- self.Props["Life"]=entity.Life
- self.Props["Level"]=entity.Level
- self.Props["PartialLevel"]=entity.PartialLevel
- self.Props["Energy"]=entity.Energy
-
- GameState.EntityPersonState.__init__(self,entity)
- inv=entity.GetInventory()
- self.Inventory={}
- self.Inventory["Objects"]=[]
- for i in range(inv.nKindObjects):
- for name in Actions.GetListOfObjectsAt(inv,i):
- self.Inventory["Objects"].append(self.__GetObjAux(name))
-
- self.Inventory["Weapons"]=[]
- for i in range(inv.nWeapons):
- self.Inventory["Weapons"].append(self.__GetObjAux(inv.GetWeapon(i)))
-
- self.Inventory["Shields"]=[]
- for i in range(inv.nShields):
- self.Inventory["Shields"].append(self.__GetObjAux(inv.GetShield(i)))
-
- self.Inventory["Quivers"]=[]
- for i in range(inv.nQuivers):
- self.Inventory["Quivers"].append(self.__GetObjAux(inv.GetQuiver(i)))
-
- self.Inventory["Keys"]=[]
- for i in range(inv.nKeys):
- self.Inventory["Keys"].append(self.__GetObjAux(inv.GetKey(i)))
-
- self.Inventory["SpecialKeys"]=[]
- for i in range(inv.nSpecialKeys):
- self.Inventory["SpecialKeys"].append(self.__GetObjAux(inv.GetSpecialKey(i)))
-
- self.Inventory["Tablets"]=[]
- for i in range(inv.nTablets):
- self.Inventory["Tablets"].append(self.__GetObjAux(inv.GetTablet(i)))
-
- self.Inventory["InvLeft"]=self.__GetObjAux(entity.InvLeft)
- self.Inventory["InvLeft2"]=self.__GetObjAux(entity.InvLeft2)
- #Avoid to carry standard objects to another map( chairs and similars)
- if Actions.IsRightHandWeaponObject(entity.Name)==0:
- print "Not taking right hand object to next map cause it┤s not a weapon!"
- self.Inventory["InvRight"]=None
- else:
- self.Inventory["InvRight"]=self.__GetObjAux(entity.InvRight)
- self.Inventory["InvLeftBack"]=self.__GetObjAux(entity.InvLeftBack)
- self.Inventory["InvRightBack"]=self.__GetObjAux(entity.InvRightBack)
-
-
- def __GetBOD(self,ent_kind):
- RM=BBLib.GetResourceManager()
- for i in range(RM.NResources(BBLib.B_CID_OBJDSCR)):
- if RM.IsResourceLoaded(BBLib.B_CID_OBJDSCR,i):
- if RM.GetResourceName(BBLib.B_CID_OBJDSCR,i)==ent_kind:
- return RM.GetResourceFile(BBLib.B_CID_OBJDSCR,i)
- return None
-
- def __GetObjAux(self,obj):
- if not obj:
- return None
- objKind=Bladex.GetEntity(obj).Kind
- return (obj,objKind,self.__GetBOD(objKind))
-
-
- ## def SaveInventory(self,file_name):
- ## f=open('../../Save/'+file_name,'wt')
- ## p=cPickle.Pickler(f)
- ## temp={}
- ## temp["Life"]=self.Props["Life"]
- ## temp["Level"]=self.Props["Level"]
- ## temp["PartialLevel"]=self.Props["PartialLevel"]
- ##
- ## p.dump((self.CreationProps,temp,self.Inventory))
- ## f.close()
-
-
- def GetProps(self):
- temp={}
- temp["Life"]=self.Props["Life"]
- temp["Level"]=self.Props["Level"]
- temp["PartialLevel"]=self.Props["PartialLevel"]
- temp["Energy"]=self.Props["Energy"]
-
- return (self.CreationProps,temp,self.Inventory)
-
-
- def CreateMainCharWithProps(props):
- CreationProps=props[0]
- Props=props[1]
- Inventory=props[2]
-
- import Basic_Funcs
- import AniSound
- import Reference
- import Sparks
- import Breakings
- import ItemTypes
- import Actions
-
-
- char=Bladex.CreateEntity("Player1",CreationProps["Kind"],0,0,0,"Person")
- char.Data=Basic_Funcs.PlayerPerson(char)
- inv=char.GetInventory()
- AniSound.AsignarSonidosCaballero('Player1')
-
- char.Level=Props["Level"]
- char.PartialLevel=Props["PartialLevel"]
- char.Life=Props["Life"]
- char.Energy=Props["Energy"]
-
- for i in Inventory["Objects"]:
- GameState.CreateEntAux(i,"Physic")
- Actions.ExtendedTakeObject(inv,i[0])
-
- for i in Inventory["Weapons"]:
- obj=GameState.CreateEntAux(i,"Weapon")
- object_flag=Reference.GiveObjectFlag(i[0])
- if object_flag == Reference.OBJ_BOW:
- inv.AddBow(i[0])
- else:
- flag=Reference.GiveWeaponFlag(i[0])
- inv.AddWeapon(i[0],flag)
-
- Breakings.SetBreakableWS(i[0])
-
- for i in Inventory["Shields"]:
- GameState.CreateEntAux(i,"Weapon")
- inv.AddShield(i[0])
- #Para que saque chispas!!!
- Sparks.MakeShield(i[0])
- Breakings.SetBreakableWS(i[0])
-
- for i in Inventory["Quivers"]:
- obj=GameState.CreateEntAux(i,"Weapon")
- ItemTypes.ItemDefaultFuncs(obj)
- inv.AddQuiver(i[0])
-
- for i in Inventory["Keys"]:
- GameState.CreateEntAux(i,"Physic")
- inv.AddKey(i[0])
-
- for i in Inventory["SpecialKeys"]:
- GameState.CreateEntAux(i,"Physic")
- inv.AddSpecialKey(i[0])
-
- for i in Inventory["Tablets"]:
- GameState.CreateEntAux(i,"Physic")
- inv.AddTablet(i[0])
-
- if Inventory["InvLeft"]:
- GameState.CreateEntAux(Inventory["InvLeft"],"Physic")
- inv.LinkLeftHand(Inventory["InvLeft"][0])
-
- if Inventory["InvLeft2"]:
- GameState.CreateEntAux(Inventory["InvLeft2"],"Physic")
- inv.LinkLeftHand2(Inventory["InvLeft2"][0])
-
- if Inventory["InvRight"]:
- GameState.CreateEntAux(Inventory["InvRight"],"Physic")
- inv.LinkRightHand(Inventory["InvRight"][0])
-
- if Inventory["InvRightBack"]:
- GameState.CreateEntAux(Inventory["InvRightBack"],"Physic")
- inv.LinkRightBack(Inventory["InvRightBack"][0])
-
- if Inventory["InvLeftBack"]:
- GameState.CreateEntAux(Inventory["InvLeftBack"],"Physic")
- inv.LinkLeftBack(Inventory["InvLeftBack"][0])
-
-
-
- def RestoreMainCharState(key):
- props=MemPersistence.Get(key)
- if props:
- CreateMainCharWithProps(props)
- return 1
- return 0
-
-
-
- def SaveMainCharState(key):
- ent_state=MainCharState('Player1')
- props=ent_state.GetProps()
- MemPersistence.Store(key,props)
-
-
-
-
-
- #place in scripts
- VisitedMaps = [ 0,0,0,0,
- 0,0,
- 0,
- 0,
- 0,0,0,0,0,0,0,0,0] # Maintained outside, 2DMAP
-
- # Once a Tablet is placed on Ianna's update this array
- PlacedTablets = [0,0,0,0,0,0] # Maintained Outside, 2DMAP
-
-
- # TEXT TO BE SAVED PER MAP
- MText = []
- BaList = []
- for a in range(17):
- MText.append([])
-
- # Formerly picked weapons
- PWeapons= []
-
- # Formerly picked Items
- PItems = []
-
- # NOTES:
- # Llamar a esta funcion desde cualquier script de mapa donde se quiera aniadir texto, el formato es:
- # 1) primero se incluye "import GotoMapVars" en el comiezo del archivo (junto con los otros imports)
- # 2) Donde se haya de escribir el texto se pone:
- # GotoMapVars.MapText(Numero del mapa, "el texto que se quiera.htm")
- def MapText(MapNum,MapTex):
- if MapNum == -1:
- BaList.append(MapTex)
- else:
- MText[MapNum - 1].append(MapTex) # Must include the -1 offset to make mappers work easier.
-
- # Weapon is a string with the internal name of the weapon
- def PickedWeapon(Weapon):
- PWeapons.append(Weapon)
-
- # Item is a string with the internal name of the item
- def PickedItems(Item):
- PItems.append(Item)
-
-
- def Set2DMapValuesAux():
- return [VisitedMaps,PlacedTablets,MText,PWeapons,PItems,BaList]
-
-
- def Get2DMapValuesAux(vals):
-
- if vals:
- global VisitedMaps
- global PlacedTablets
- global MText
- global PWeapons
- global PItems
- global BaList
- VisitedMaps=vals[0]
- PlacedTablets=vals[1]
- MText=vals[2]
- PWeapons=vals[3]
- PItems=vals[4]
- BaList=vals[5]
- return 1
-
- return 0
-
-
-
-
- def Get2DMapValues():
-
- print "Get2DMapValues()"
- vals=MemPersistence.Get('2DMapValues')
- if vals:
- return Get2DMapValuesAux(vals)
- else:
- print "Get2DMapValues() -> can't find vals."
- return 0
-
-
- def GetCarriedTablets():
- a = [0,0,0,0,0,0]
- for i in MemPersistence.Get('MainChar')[2]["Tablets"]:
- a[string.atoi(i[0][len("tablilla")])-1] = 1
-
- return a
-
-
- def BeginLevel():
- pj=RestoreMainCharState('MainChar')
- if pj:
- return Get2DMapValues()
- return 0
-
-
-
-
- # LEVEL ENDING
- LevelNames = [ "barb_m1", "ragnar_m2", "dwarf_m3", "ruins_m4", "mine_m5", "labyrinth_m6",
- "tomb_m7", "island_m8", "orc_m9", "orlok_m10", "ice_m11", "btomb_m12",
- "desert_m13", "volcano_m14", "palace_m15", "tower_m16", "chaos_m17"]
-
- BackLevelNames = [ "mine_back", "labyrinth_back", "tomb_back", "ice_back", "btomb_back", "desert_back",
- "palace_back"]
-
- def EndOfLevel():
- import string
-
- global VisitedMaps
- global BackLevelNames
-
- print "EndOfLevel()"
-
- print "Preparing main char for the travel."
- import Actions
- Actions.PutAllInBack("Player1")
- Actions.RemoveAllKeys("Player1")
- Actions.RemoveNoTravelObjects( "Player1" )
-
-
-
-
- # Save lists in this file in c memory
- pname = Bladex.GetCurrentMap()
- name = string.lower(pname)
-
- if (name == "palace_m15"):
- name = "palace_back"
- if not(name in BackLevelNames):
- iIndex = LevelNames.index(name)
- else:
- iIndex = BackLevelNames.index(name)
- VisitedMaps[14] = 1
- Bladex.SetStringValue("LastVisitedMap","M_" + str(iIndex+1))
- VisitedMaps[iIndex] = 1
- print iIndex
- MemPersistence.Store('2DMapValues',Set2DMapValuesAux())
- SaveMainCharState('MainChar')
- Bladex.LoadLevel("2dMap")
-