def setFriendsList(self, friendsList): self.oldFriendsList = self.friendsList self.friendsList = friendsList self.timeFriendsListChanged = globalClock.getFrameTime() self.notify.debug('setting friends list to %s' % self.friendsList) messenger.send('friendsListChanged') Avatar.reconsiderAllUnderstandable()
def onClientBulletExplosion(gd, contacts, isPlayer, victim, bulletDir): materialId = isTeamObject(victim) and 254 or 255 materialName = db.DBLogic.g_instance.getMaterialName(materialId) if hasattr(gd.explosionParticles, materialName): explosionEffectName = gd.explosionParticles.__dict__[materialName] else: explosionEffectName = gd.explosionParticles.default if explosionEffectName: import Avatar for position, partID, bbox, armor in contacts: Avatar.onBulletExplosion( Effects.getEffectId(explosionEffectName), isPlayer, position, bulletDir if materialName == 'aircraft' else None, victim) if isPlayer: Weapons.debug_addBulletCollisionEffects( explosionEffectName) Weapons.debug_drawBulletCollisionLines(position) return
def change_game_state(self, **state): import BigWorld, Avatar, Account assert self.mod_tessumod, "Mod must be loaded first before changing game state" if state["mode"] == "battle": BigWorld.player(Avatar.Avatar()) if "players" in state: for player in state["players"]: vehicle_id = random.randint(0, 1000000) dbid = random.randint(0, 1000000) BigWorld.player().arena.vehicles[vehicle_id] = { "accountDBID": dbid, "name": player["name"], "isAlive": True } if vehicle_id not in BigWorld.entities: BigWorld.entities[vehicle_id] = BigWorld.Entity() if "position" in player: BigWorld.player( ).arena.positions[vehicle_id] = player["position"] BigWorld.entities[ vehicle_id].position = BigWorld.Vector( *player["position"]) if "camera" in state: if "position" in state["camera"]: BigWorld.camera().position = BigWorld.Vector( *state["camera"]["position"]) if "direction" in state["camera"]: BigWorld.camera().direction = BigWorld.Vector( *state["camera"]["direction"]) elif state["mode"] == "lobby": BigWorld.player(Account.PlayerAccount()) if "players" in state: for id, player in enumerate(state["players"]): BigWorld.player().prebattle.rosters[0][id] = { "name": player["name"], "dbID": random.randint(0, 1000000) }
#Cajas caja1 = Textura(caja1Im, 45, 45) bolaExtra = Textura(bolaExtraIm, 25, 25) randomThrow = Textura(randomThIm, 25, 25) blFila = Textura(blowFilaIm, 25, 25) blCol = Textura(blowColIm, 25, 25) #Bolas pokebola = Textura(pokeIm, 10, 10) pong = Textura(pongIm, 15, 15) paty = Textura(patyIm, 30, 30) todasLasBolas = [pong, pokebola] #Flecha flecha = Textura(flechaIm, 120, 120) #Botones playTex = [Textura(playIm, 57 * 4, 80), Textura(playIm2, 57 * 4, 80)] restartTex = [Textura(restartIm, 57 * 4, 80), Textura(restartIm2, 57 * 4, 80)] pausaTex = [Textura(pausaIm, 50, 50), Textura(pausaIm2, 50, 50)] quitTex = [Textura(quitIm, 57 * 4, 80), Textura(quitIm2, 57 * 4, 80)] cambioDerTex = [Textura(cambioDerIm, 60, 60), Textura(cambioDerIm2, 60, 60)] cambioIzqTex = [Textura(cambioIzqIm, 60, 60), Textura(cambioIzqIm2, 60, 60)] backTex = [Textura(backIm, 57 * 4, 80), Textura(backIm2, 57 * 4, 80)] customTex = [Textura(customIm, 57 * 4, 80), Textura(customIm2, 57 * 4, 80)] #Avatares cisnerosIm = pygame.image.load('images/avatarCisneros275.png') avatarCisneros = Avatar(cisnerosIm, 60.5, 57.75)
def my_constructor(self, USER, DISPLAY_GROUP, VIEW_TRANSFORM_NODE, HEAD_NODE_NAME = 'head', COMPLEX_SETUP = True): ## @var USER # Reference to the user to be represented. self.USER = USER ## @var DISPLAY_GROUP # Reference to the display group this user representation is responsible for. self.DISPLAY_GROUP = DISPLAY_GROUP ## @var view_transform_node # Transform node to be filled by one navigation of the display group. self.view_transform_node = VIEW_TRANSFORM_NODE ## @var screens # List of screen nodes for each display of the display group. self.screens = [] ## @var dependent_nodes # Placeholder for scenegraph nodes which are relevant for the transformation policy. self.dependent_nodes = [] ## @var execute_transformation_policy # Boolean indicating if the transformation policy is evaluated every frame. self.execute_transformation_policy = True ## create user representation nodes ## ## @var stereo_display_group # Boolean saying if this DisplayGroup contains of only stereo displays. self.stereo_display_group = True for _display in DISPLAY_GROUP.displays: if _display.stereo == False: self.stereo_display_group = False break ## @var head # Head node of the user. self.head = avango.gua.nodes.TransformNode(Name = HEAD_NODE_NAME) self.view_transform_node.Children.value.append(self.head) ## @var left_eye # Left eye node of the user. self.left_eye = avango.gua.nodes.TransformNode(Name = "eyeL") self.head.Children.value.append(self.left_eye) ## @var right_eye # Right eye node of the user. self.right_eye = avango.gua.nodes.TransformNode(Name = "eyeR") self.head.Children.value.append(self.right_eye) # assign correct transformations to nodes if COMPLEX_SETUP: self.make_complex_viewing_setup() else: self.make_default_viewing_setup() ## @var connected_navigation_id # Navigation ID within the display group that is currently used. self.connected_navigation_id = -1 ## @var avatar # Avatar instance belonging to this UserRepresentation. self.avatar = Avatar() self.avatar.my_constructor(self) ## @var frame_trigger # Triggers framewise evaluation of frame_callback method. self.frame_trigger = avango.script.nodes.Update(Callback = self.frame_callback, Active = True) ## @var thumbnail_mode # Boolean indicating if the portal if a default viewing setup is activated although the portal might suggest it differently. self.thumbnail_mode = False
class UserRepresentation: ## Default constructor. def __init__(self): pass ## Custom constructor. # @param USER Reference to the user to be represented. # @param DISPLAY_GROUP Reference to the display group this user representation is responsible for. # @param VIEW_TRANSFORM_NODE Transform node to be filled by one navigation of the display group. # @param HEAD_NODE_NAME Name of the UserRepresentation's head node in the scenegraph. # @param COMPLEX_SETUP If activated, the transformation policy is evaluated every frame to update head. If deactivated, # a standard mono viewing setup is assumed. def my_constructor(self, USER, DISPLAY_GROUP, VIEW_TRANSFORM_NODE, HEAD_NODE_NAME = 'head', COMPLEX_SETUP = True): ## @var USER # Reference to the user to be represented. self.USER = USER ## @var DISPLAY_GROUP # Reference to the display group this user representation is responsible for. self.DISPLAY_GROUP = DISPLAY_GROUP ## @var view_transform_node # Transform node to be filled by one navigation of the display group. self.view_transform_node = VIEW_TRANSFORM_NODE ## @var screens # List of screen nodes for each display of the display group. self.screens = [] ## @var dependent_nodes # Placeholder for scenegraph nodes which are relevant for the transformation policy. self.dependent_nodes = [] ## @var execute_transformation_policy # Boolean indicating if the transformation policy is evaluated every frame. self.execute_transformation_policy = True ## create user representation nodes ## ## @var stereo_display_group # Boolean saying if this DisplayGroup contains of only stereo displays. self.stereo_display_group = True for _display in DISPLAY_GROUP.displays: if _display.stereo == False: self.stereo_display_group = False break ## @var head # Head node of the user. self.head = avango.gua.nodes.TransformNode(Name = HEAD_NODE_NAME) self.view_transform_node.Children.value.append(self.head) ## @var left_eye # Left eye node of the user. self.left_eye = avango.gua.nodes.TransformNode(Name = "eyeL") self.head.Children.value.append(self.left_eye) ## @var right_eye # Right eye node of the user. self.right_eye = avango.gua.nodes.TransformNode(Name = "eyeR") self.head.Children.value.append(self.right_eye) # assign correct transformations to nodes if COMPLEX_SETUP: self.make_complex_viewing_setup() else: self.make_default_viewing_setup() ## @var connected_navigation_id # Navigation ID within the display group that is currently used. self.connected_navigation_id = -1 ## @var avatar # Avatar instance belonging to this UserRepresentation. self.avatar = Avatar() self.avatar.my_constructor(self) ## @var frame_trigger # Triggers framewise evaluation of frame_callback method. self.frame_trigger = avango.script.nodes.Update(Callback = self.frame_callback, Active = True) ## @var thumbnail_mode # Boolean indicating if the portal if a default viewing setup is activated although the portal might suggest it differently. self.thumbnail_mode = False ## Determines whether this UserRepresentation is repsonsible for a virtual display. def is_in_virtual_display(self): if self.view_transform_node.Name.value == "exit": return True return False ## Evaluated every frame. def frame_callback(self): if self.execute_transformation_policy: if not self.is_in_virtual_display(): self.perform_physical_user_head_transformation() else: self.perform_virtual_user_head_transformation() # activate thumbnail mode when scale is too small # make sure not to switch off own PortalCameraRepresentations _physical_nav_node = self.dependent_nodes[0].Parent.value _physical_nav_scale = _physical_nav_node.Transform.value.get_scale() _physical_user_w_id = _physical_nav_node.Name.value.split("_")[0].replace("w", "") _physical_user_dg_id = _physical_nav_node.Name.value.split("_")[1].replace("dg", "") _portal_w_id = self.view_transform_node.Parent.value.Name.value.split("_")[2].replace("w", "") _portal_dg_id = self.view_transform_node.Parent.value.Name.value.split("_")[3].replace("dg", "") if _physical_nav_scale.x > 30.0 and (_physical_user_w_id != _portal_w_id or _physical_user_dg_id != _portal_dg_id): self.thumbnail_mode = True self.make_default_viewing_setup() # handle reactivation in thumbnail mode elif self.thumbnail_mode: self.perform_virtual_user_head_transformation() # same check as performed above _physical_nav_node = self.dependent_nodes[0].Parent.value _physical_nav_scale = _physical_nav_node.Transform.value.get_scale() _physical_user_w_id = _physical_nav_node.Name.value.split("_")[0].replace("w", "") _physical_user_dg_id = _physical_nav_node.Name.value.split("_")[1].replace("dg", "") _portal_w_id = self.view_transform_node.Parent.value.Name.value.split("_")[2].replace("w", "") _portal_dg_id = self.view_transform_node.Parent.value.Name.value.split("_")[3].replace("dg", "") # remain in thumbnail mode if _physical_nav_scale.x > 30.0 and (_physical_user_w_id != _portal_w_id or _physical_user_dg_id != _portal_dg_id): self.make_default_viewing_setup() # deactive thumbnail mode else: if self.DISPLAY_GROUP.viewing_mode == "3D": self.make_complex_viewing_setup() else: self.make_default_viewing_setup() self.thumbnail_mode = False ## Transforms the head node according to the display group offset and the tracking matrix. def perform_physical_user_head_transformation(self): self.head.Transform.value = self.DISPLAY_GROUP.offset_to_workspace * self.USER.headtracking_reader.sf_abs_mat.value ## Transforms the head according to the head - portal entry relation. def perform_virtual_user_head_transformation(self): # express in coordinate system of first virtual display of group # the remaining screens are given via their screen offset transformation self.head.Transform.value = self.DISPLAY_GROUP.screen_nodes[0].Transform.value * \ avango.gua.make_inverse_mat(self.DISPLAY_GROUP.entry_node.Transform.value) * \ self.dependent_nodes[0].WorldTransform.value ## Deactivates the evaluation of the transformation policy and assigns fixed matrices # for the eye and head nodes. def make_default_viewing_setup(self): self.execute_transformation_policy = False self.head.Transform.value = avango.gua.make_trans_mat(0.0, 0.0, 1.5) self.left_eye.Transform.value = avango.gua.make_identity_mat() self.right_eye.Transform.value = avango.gua.make_identity_mat() ## Activates the evaluation of the transformation policy and sets the eye # distance properly. def make_complex_viewing_setup(self): if self.stereo_display_group: _eye_distance = self.USER.eye_distance else: _eye_distance = 0.0 self.execute_transformation_policy = True self.left_eye.Transform.value = avango.gua.make_trans_mat(-_eye_distance / 2, 0.0, 0.0) self.right_eye.Transform.value = avango.gua.make_trans_mat(_eye_distance / 2, 0.0, 0.0) ## Sets the GroupNames field on all avatar parts to a list of strings. # @param LIST_OF_STRINGS A list of group names to be set for the avatar parts. def set_avatar_group_names(self, LIST_OF_STRINGS): self.avatar.set_group_names(LIST_OF_STRINGS) ## Appends a string to the GroupNames field of all avatar parts. # @param STRING The string to be appended to the GroupNames field. def append_to_avatar_group_names(self, STRING): self.avatar.append_to_group_names(STRING) ## Adds a screen visualization for a display instance to the avatar. # @param DISPLAY_INSTANCE The Display instance to retrieve the screen visualization from. def add_screen_visualization_for(self, DISPLAY_INSTANCE): self.avatar.add_screen_visualization_for(DISPLAY_INSTANCE) ## Appends a screen node for a display instance to the view transformation node. # @param DISPLAY_INSTANCE The Display instance to retrieve the screen node from. def add_screen_node_for(self, DISPLAY_INSTANCE): ## @var workspace_id # Identification number of the workspace the associated user is belonging to. self.workspace_id = int(self.view_transform_node.Name.value.split("_")[0].replace("w", "")) _screen = DISPLAY_INSTANCE.create_screen_node("screen_" + str(len(self.screens))) self.view_transform_node.Children.value.append(_screen) self.screens.append(_screen) _loader = avango.gua.nodes.TriMeshLoader() _navigation_color_geometry = _loader.create_geometry_from_file('nav_color_plane', 'data/objects/plane.obj', 'data/materials/' + self.DISPLAY_GROUP.navigations[0].trace_material + 'Shadeless.gmd', avango.gua.LoaderFlags.LOAD_MATERIALS) _trans = avango.gua.Vec3(-0.45 * _screen.Width.value, 0.4 * _screen.Height.value, 0.0) _scale = 0.05 * _screen.Height.value _navigation_color_geometry.Transform.value = avango.gua.make_trans_mat(_trans) * \ avango.gua.make_rot_mat(90, 1, 0, 0) * \ avango.gua.make_scale_mat(_scale, _scale, _scale) _navigation_color_geometry.ShadowMode.value = avango.gua.ShadowMode.OFF _navigation_color_geometry.GroupNames.value = ["w" + str(self.workspace_id) + "_dg" + str(self.DISPLAY_GROUP.id) + "_u" + str(self.USER.id)] _screen.Children.value.append(_navigation_color_geometry) ## Adds an already existing screen node to this UserRepresentation. # @param SCREEN_NODE The screen node to be added. def add_existing_screen_node(self, SCREEN_NODE): self.screens.append(SCREEN_NODE) ## Adds a scenegraph node to the list of dependent nodes. # @param NODE The node to be added. def add_dependent_node(self, NODE): self.dependent_nodes.append(NODE) ## Connects a specific navigation of the display group to the user. # @param ID The ID of the navigation to connect with. def connect_navigation_of_display_group(self, ID): # change is not necessary if ID == self.connected_navigation_id: print_message("User " + str(self.USER.id) + " at display group " + str(self.DISPLAY_GROUP.id) + \ ": Already on Navigaton " + str(ID)) # change is necessary elif ID < len(self.DISPLAY_GROUP.navigations): _old_navigation = self.DISPLAY_GROUP.navigations[self.connected_navigation_id] _new_navigation = self.DISPLAY_GROUP.navigations[ID] self.view_transform_node.Transform.disconnect() if len(_new_navigation.active_user_representations) == 0 and self.connected_navigation_id != -1: try: _new_navigation.inputmapping.set_abs_mat(_old_navigation.sf_abs_mat.value) _new_navigation.inputmapping.set_scale(_old_navigation.sf_scale.value) # avoid field connection frame latency by setting value directly self.view_transform_node.Transform.value = _old_navigation.sf_abs_mat.value * avango.gua.make_scale_mat(_old_navigation.sf_scale.value) except: pass _old_navigation.remove_user_representation(self) _new_navigation.add_user_representation(self) # connect view transform node to new navigation self.view_transform_node.Transform.connect_from(_new_navigation.sf_nav_mat) self.connected_navigation_id = ID #try: # print_message("User " + str(self.USER.id) + " at display group " + str(self.DISPLAY_GROUP.id) + \ # ": Switch navigation to " + str(ID) + " (" + _new_navigation.input_device_name + ")") #except: # print_message("User " + str(self.USER.id) + " at display group " + str(self.DISPLAY_GROUP.id) + \ # ": Switch navigation to " + str(ID) + " (no input device)") # trigger avatar and screen geometry visibilities self.avatar.set_material('data/materials/' + _new_navigation.trace_material + ".gmd" , 'data/materials/' + _new_navigation.trace_material + "Shadeless.gmd") else: print_error("Error. Navigation ID does not exist.", False)
def setSprite(self): self.__sprite = Avatar.Avatar('/path/to/picture')
def paintGL(self): """ first call requires initialization """ if self.initialized == False: self.initialized = True self.initializeGL() print("initialization done") """ ----------------- """ """ >>> main loop <<< """ """ ----------------- """ # keep track of loop frequency flagStart = time.clock() """ Events management. Keyboard interactions between the user and the software are done here. """ Events.manage() """ Update all entities ID """ ID.setId([ Avatar.virtuMan.limbs, Avatar.virtuMan.muscles, Sensors.virtuSens, Sensors.zoiSens ]) """ Preprocess entities. Store all needed transformations to significantly lower calculation cost when rendering (redundancy otherwise between display buffer, ID buffer and bindings) """ # Preprocess of limbs Definitions.modelMatrix.push() Definitions.modelMatrix.translate(Avatar.virtuMan.position[0], Avatar.virtuMan.position[1], Avatar.virtuMan.position[2]) R = Definitions.vector4D.Quat2Vec( Definitions.vector4D((Avatar.virtuMan.orientation))) Definitions.modelMatrix.rotate(R.o, R.x, R.y, R.z) Avatar.limb = -1 # initialize the recursivity here Sensors.countID = 0 Graphics.SaturationModelMatrix = [] Avatar.stick(Avatar.virtuMan) Definitions.modelMatrix.pop() Avatar.oneMesh(Avatar.virtuMan) Muscles.preprocessMuscle(Avatar.virtuMan) Scene.preprocessScene() """ update camera """ Definitions.viewMatrix.push() Definitions.viewMatrix.translate(0, 0, Events.frontBack_cam) Definitions.viewMatrix.rotate(Events.upDown_cam, 1, 0, 0) Definitions.viewMatrix.rotate(Events.leftRight_cam, 0, 1, 0) if Definitions.lookingAtID != 0: Definitions.viewMatrix.translate(-Definitions.lookingAt[0][0], -Definitions.lookingAt[0][1], -Definitions.lookingAt[0][2]) glUniformMatrix4fv(Shaders.view_loc, 1, GL_FALSE, Definitions.viewMatrix.peek()) Definitions.viewMatrix.pop() """ Draw on the ID buffer. The ID BUFFER is used for the mouse implementation, to know which entity is targeted with the cursor. """ # bind the ID buffer glBindFramebuffer(GL_FRAMEBUFFER, self.idFBO) # clear the ID buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # fill ID buffer glViewport(0, 0, Graphics.display[0], Graphics.display[1]) Graphics.modelView(Graphics.opaque) Limbs.drawBodySurface(Avatar.virtuMan, Graphics.idBuffer, Events.SHOW) Muscles.drawMuscleSurface(Avatar.virtuMan, Graphics.idBuffer, Events.SHOW) Sensors.drawZoi(Graphics.idBuffer) Sensors.drawSensor(Graphics.idBuffer) """ Mouse interaction with ID buffer. Read the value of the ID buffer at mouse position, do some stuff. """ dx = -8 dy = -30 Cursor.mouse = [ QtGui.QCursor().pos().x() + dx, QtGui.QCursor().pos().y() + dy ] Cursor.mouseManage() """ Draw on the display buffer. The display buffer is what the user will see on his screen. """ # bind the display buffer glBindFramebuffer(GL_FRAMEBUFFER, self.displayFBO) # clear the display buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glViewport(0, 0, Graphics.display[0], Graphics.display[1]) # draw scene Graphics.modelView(Graphics.blending) Scene.drawScene() # draw saturation balls Graphics.modelView(Graphics.blending) Saturations.drawSaturationBalls(Avatar.virtuMan) # draw FADE body Graphics.modelView(Graphics.blending) Limbs.drawBodySurface(Avatar.virtuMan, Events.style, Events.FADE) # draw FADE muscles Graphics.modelView(Events.style) Muscles.drawMuscleSurface(Avatar.virtuMan, Events.style, Events.FADE) # draw SHOW body Graphics.modelView(Events.style) Limbs.drawBodySurface(Avatar.virtuMan, Events.style, Events.SHOW) Limbs.drawBodyEdge(Avatar.virtuMan, Events.style) # draw SHOW muscles Graphics.modelView(Events.style) Muscles.drawMuscleSurface(Avatar.virtuMan, Events.style, Events.SHOW) Muscles.drawMuscleEdge(Avatar.virtuMan, Events.style) # draw saturation lines Graphics.modelView(Graphics.opaque) Saturations.drawSaturationLines(Avatar.virtuMan) # draw sensors Graphics.modelView(Graphics.opaque) Sensors.drawLink(Events.style) Sensors.drawZoi(Events.style) Sensors.drawSensor(Events.style)
Events.eventKeyList = Events.eventKeyList + [event.key()] Events.eventPressList = Events.eventPressList + [True] def keyReleaseEvent(self, event): Events.eventModifierList = Events.eventModifierList + [ QtWidgets.QApplication.keyboardModifiers() ] if event.isAutoRepeat() == False: Events.eventKeyList = Events.eventKeyList + [event.key()] Events.eventPressList = Events.eventPressList + [False] if __name__ == '__main__': """ Create Entities """ State.updateAvatar() Avatar.virtuMan = Avatar.characteristics(1.7) State.loadAvatar(Avatar.virtuMan, State.avatarFileName[0]) Saturations.saturationBall = Saturations.saturation() Saturations.saturationBall.mesh = Graphics.VBO_sphere(32, 32, 32, 32) Graphics.buildVBO(Saturations.saturationBall) Sensors.zoi = Sensors.templates() Sensors.zoi.mesh = Graphics.VBO_circle() Graphics.buildVBO(Sensors.zoi) Sensors.link = Sensors.templates() Sensors.link.mesh = Graphics.VBO_dashed() Graphics.buildVBO(Sensors.link) Scene.tile = Avatar.characteristics(1.7) Scene.tile.mesh = Graphics.VBO_cube() Graphics.buildVBO(Scene.tile)
def plunder(aGbId, dGbId): aAvatar = Avatar.AvatarPool().getAvatar(aGbId) aSpaceGateLv = utils.getWarpGateLevel(aAvatar.score) if utils.isAvatar(dGbId): dAvatar = Avatar.AvatarPool().getAvatar(dGbId) targetScore = dAvatar.score completion = calcCompletion(aAvatar.score, dAvatar.score, aAvatar.effect, dAvatar.effect) dSpaceGateLv = utils.getWarpGateLevel(dAvatar.score) prCtx = PlunderRewardCtx(aAvatar.lqLv, dAvatar.ling, dAvatar.hun, dSpaceGateLv, completion, aSpaceGateLv, dAvatar.ckLv, dAvatar.lqLv, aAvatar.score, dAvatar.score, aAvatar.ckLv) else: targetScore = _randomValue(aAvatar.score, 'systemWorldScoreRange', 0) dSpaceGateLv = utils.getWarpGateLevel(targetScore) lingqiMax = gameconst.HomeBuildingType.getMaxLevel( gameconst.HomeBuildingType.LINGQI) targetLingqiLv = min( _randomValue(aAvatar.lqLv, 'systemWorldLingqiRange', 1), lingqiMax) cangkuMax = gameconst.HomeBuildingType.getMaxLevel( gameconst.HomeBuildingType.CANGKU) targetCangkuLv = min( _randomValue(aAvatar.ckLv, 'systemWorldCangkuRange', 1), cangkuMax) cangkuData = BCKD.datas[targetCangkuLv] lingStoneMax = cangkuData['lingStoneMax'] lingStone = random.randint( int(lingStoneMax * cangkuData['systemWorldLingStoneMin']), int(lingStoneMax * cangkuData['systemWorldLingStoneMax'])) hunStoneMax = cangkuData['hunStoneMax'] hunStone = random.randint( int(hunStoneMax * cangkuData['systemWorldHunStoneMin']), int(hunStoneMax * cangkuData['systemWorldHunStoneMax'])) dEffect = _calcEffective(dGbId, targetLingqiLv) completion = calcCompletion(aAvatar.score, targetScore, aAvatar.effect, dEffect) prCtx = PlunderRewardCtx(aAvatar.lqLv, lingStone, hunStone, dSpaceGateLv, completion, aSpaceGateLv, targetCangkuLv, targetLingqiLv, aAvatar.score, targetScore, aAvatar.ckLv) award = dropAward.getDropAward(aAvatar, int(PSD.datas['plunderRewardID']['value']), 1, rewardType=gameconst.RewardType.PLUNDER, ctx=prCtx)[0] ling = int(award.get(30000006, 0)) hun = int(award.get(30000007, 0)) if utils.isAvatar(dGbId): dAvatar.stole(ling, hun) exRate = BSGD.datas[prCtx.selfSpaceGateLv]['exAddRatio'] award[30000006] = int(ling * (1 + exRate)) award[30000007] = int(hun * (1 + exRate)) exAward = dropAward.getDropAward( aAvatar, int(PSD.datas['attackExRewardID']['value']), 1, rewardType=gameconst.RewardType.PLUNDER, ctx=prCtx)[0] for id, num in exAward.items(): award[id] = award.get(id, 0) + num ling = award.get(30000006, 0) hun = award.get(30000007, 0) tao = award.get(30000008, 0) cao = award.get(30000009, 0) aAvatar.award(award) aNew, dNew = eloCalc(aAvatar.score, targetScore, completion) aAvatar.score = aNew if utils.isAvatar(dGbId): dAvatar.score = dNew attackInfo = { 'defenceOwner': dGbId, 'completion': completion, 'ling': ling, 'hun': hun, 'tao': tao, 'cao': cao } aAvatar.addAttackInfo(attackInfo)
def my_constructor(self, USER, DISPLAY_GROUP, VIEW_TRANSFORM_NODE, VIRTUAL_USER_REPR_DISPLAY_INDEX=-1, HEAD_NODE_NAME='head', COMPLEX_SETUP=True): ## @var USER # Reference to the user to be represented. self.USER = USER ## @var DISPLAY_GROUP # Reference to the display group this user representation is responsible for. self.DISPLAY_GROUP = DISPLAY_GROUP ## @var view_transform_node # Transform node to be filled by one navigation of the display group. self.view_transform_node = VIEW_TRANSFORM_NODE ## @var screens # List of screen nodes for each display of the display group. self.screens = [] ## @var dependent_nodes # Placeholder for scenegraph nodes which are relevant for the transformation policy. self.dependent_nodes = [] ## @var execute_transformation_policy # Boolean indicating if the transformation policy is evaluated every frame. self.execute_transformation_policy = True ## create user representation nodes ## ## @var stereo_display_group # Boolean saying if this DisplayGroup contains of only stereo displays. self.stereo_display_group = True for _display in DISPLAY_GROUP.displays: if _display.stereo == False: self.stereo_display_group = False break ## @var head # Head node of the user. self.head = avango.gua.nodes.TransformNode(Name=HEAD_NODE_NAME) self.view_transform_node.Children.value.append(self.head) ## @var left_eye # Left eye node of the user. self.left_eye = avango.gua.nodes.TransformNode(Name="eyeL") self.head.Children.value.append(self.left_eye) ## @var right_eye # Right eye node of the user. self.right_eye = avango.gua.nodes.TransformNode(Name="eyeR") self.head.Children.value.append(self.right_eye) # assign correct transformations to nodes if COMPLEX_SETUP: self.make_complex_viewing_setup() else: self.make_default_viewing_setup() ## @var connected_navigation_id # Navigation ID within the display group that is currently used. self.connected_navigation_id = -1 ## @var avatar # Avatar instance belonging to this UserRepresentation. self.avatar = Avatar() self.avatar.my_constructor(self) ## @var virtual_user_repr_display_index # If this is a portal user representation, ID giving the display index within the display group. -1 otherwise. self.virtual_user_repr_display_index = VIRTUAL_USER_REPR_DISPLAY_INDEX ## @var frame_trigger # Triggers framewise evaluation of frame_callback method. self.frame_trigger = avango.script.nodes.Update( Callback=self.frame_callback, Active=True) ## @var thumbnail_mode # Boolean indicating if the portal if a default viewing setup is activated although the portal might suggest it differently. self.thumbnail_mode = False
class UserRepresentation: ## Default constructor. def __init__(self): pass ## Custom constructor. # @param USER Reference to the user to be represented. # @param DISPLAY_GROUP Reference to the display group this user representation is responsible for. # @param VIEW_TRANSFORM_NODE Transform node to be filled by one navigation of the display group. # @param VIRTUAL_USER_REPR_DISPLAY_INDEX If this is a portal user representation, ID giving the display index within the display group. -1 otherwise. # @param HEAD_NODE_NAME Name of the UserRepresentation's head node in the scenegraph. # @param COMPLEX_SETUP If activated, the transformation policy is evaluated every frame to update head. If deactivated, # a standard mono viewing setup is assumed. def my_constructor(self, USER, DISPLAY_GROUP, VIEW_TRANSFORM_NODE, VIRTUAL_USER_REPR_DISPLAY_INDEX=-1, HEAD_NODE_NAME='head', COMPLEX_SETUP=True): ## @var USER # Reference to the user to be represented. self.USER = USER ## @var DISPLAY_GROUP # Reference to the display group this user representation is responsible for. self.DISPLAY_GROUP = DISPLAY_GROUP ## @var view_transform_node # Transform node to be filled by one navigation of the display group. self.view_transform_node = VIEW_TRANSFORM_NODE ## @var screens # List of screen nodes for each display of the display group. self.screens = [] ## @var dependent_nodes # Placeholder for scenegraph nodes which are relevant for the transformation policy. self.dependent_nodes = [] ## @var execute_transformation_policy # Boolean indicating if the transformation policy is evaluated every frame. self.execute_transformation_policy = True ## create user representation nodes ## ## @var stereo_display_group # Boolean saying if this DisplayGroup contains of only stereo displays. self.stereo_display_group = True for _display in DISPLAY_GROUP.displays: if _display.stereo == False: self.stereo_display_group = False break ## @var head # Head node of the user. self.head = avango.gua.nodes.TransformNode(Name=HEAD_NODE_NAME) self.view_transform_node.Children.value.append(self.head) ## @var left_eye # Left eye node of the user. self.left_eye = avango.gua.nodes.TransformNode(Name="eyeL") self.head.Children.value.append(self.left_eye) ## @var right_eye # Right eye node of the user. self.right_eye = avango.gua.nodes.TransformNode(Name="eyeR") self.head.Children.value.append(self.right_eye) # assign correct transformations to nodes if COMPLEX_SETUP: self.make_complex_viewing_setup() else: self.make_default_viewing_setup() ## @var connected_navigation_id # Navigation ID within the display group that is currently used. self.connected_navigation_id = -1 ## @var avatar # Avatar instance belonging to this UserRepresentation. self.avatar = Avatar() self.avatar.my_constructor(self) ## @var virtual_user_repr_display_index # If this is a portal user representation, ID giving the display index within the display group. -1 otherwise. self.virtual_user_repr_display_index = VIRTUAL_USER_REPR_DISPLAY_INDEX ## @var frame_trigger # Triggers framewise evaluation of frame_callback method. self.frame_trigger = avango.script.nodes.Update( Callback=self.frame_callback, Active=True) ## @var thumbnail_mode # Boolean indicating if the portal if a default viewing setup is activated although the portal might suggest it differently. self.thumbnail_mode = False ## Evaluated every frame. def frame_callback(self): if self.execute_transformation_policy: if self.virtual_user_repr_display_index == -1: self.perform_physical_user_head_transformation() else: self.perform_virtual_user_head_transformation( self.virtual_user_repr_display_index) # activate thumbnail mode when scale is too small # make sure not to switch off own PortalCameraRepresentations _physical_nav_node = self.dependent_nodes[0].Parent.value _physical_nav_scale = _physical_nav_node.Transform.value.get_scale( ) _physical_user_w_id = _physical_nav_node.Name.value.split( "_")[0].replace("w", "") _physical_user_dg_id = _physical_nav_node.Name.value.split( "_")[1].replace("dg", "") _portal_w_id = self.view_transform_node.Parent.value.Name.value.split( "_")[2].replace("w", "") _portal_dg_id = self.view_transform_node.Parent.value.Name.value.split( "_")[3].replace("dg", "") if _physical_nav_scale.x > 30.0 and ( _physical_user_w_id != _portal_w_id or _physical_user_dg_id != _portal_dg_id): self.thumbnail_mode = True self.make_default_viewing_setup() # handle reactivation in thumbnail mode elif self.thumbnail_mode: self.perform_virtual_user_head_transformation( self.virtual_user_repr_display_index) # same check as performed above _physical_nav_node = self.dependent_nodes[0].Parent.value _physical_nav_scale = _physical_nav_node.Transform.value.get_scale( ) _physical_user_w_id = _physical_nav_node.Name.value.split( "_")[0].replace("w", "") _physical_user_dg_id = _physical_nav_node.Name.value.split( "_")[1].replace("dg", "") _portal_w_id = self.view_transform_node.Parent.value.Name.value.split( "_")[2].replace("w", "") _portal_dg_id = self.view_transform_node.Parent.value.Name.value.split( "_")[3].replace("dg", "") # remain in thumbnail mode if _physical_nav_scale.x > 30.0 and ( _physical_user_w_id != _portal_w_id or _physical_user_dg_id != _portal_dg_id): self.make_default_viewing_setup() # deactive thumbnail mode else: if self.DISPLAY_GROUP.displays[ self. virtual_user_repr_display_index].viewing_mode == "3D": self.make_complex_viewing_setup() else: self.make_default_viewing_setup() self.thumbnail_mode = False ## Transforms the head node according to the display group offset and the tracking matrix. def perform_physical_user_head_transformation(self): self.head.Transform.value = self.DISPLAY_GROUP.offset_to_workspace * self.USER.headtracking_reader.sf_abs_mat.value ## Transforms the head according to the head - portal entry relation. def perform_virtual_user_head_transformation(self, DISPLAY_INDEX): self.head.Transform.value = self.DISPLAY_GROUP.displays[DISPLAY_INDEX].portal_screen_node.Transform.value * \ avango.gua.make_inverse_mat(self.DISPLAY_GROUP.displays[DISPLAY_INDEX].portal_matrix_node.Transform.value) * \ self.dependent_nodes[0].WorldTransform.value ## Deactivates the evaluation of the transformation policy and assigns fixed matrices # for the eye and head nodes. def make_default_viewing_setup(self): self.execute_transformation_policy = False self.head.Transform.value = avango.gua.make_trans_mat(0.0, 0.0, 1.5) self.left_eye.Transform.value = avango.gua.make_identity_mat() self.right_eye.Transform.value = avango.gua.make_identity_mat() ## Activates the evaluation of the transformation policy and sets the eye # distance properly. def make_complex_viewing_setup(self): if self.stereo_display_group: _eye_distance = self.USER.eye_distance else: _eye_distance = 0.0 self.execute_transformation_policy = True self.left_eye.Transform.value = avango.gua.make_trans_mat( -_eye_distance / 2, 0.0, 0.0) self.right_eye.Transform.value = avango.gua.make_trans_mat( _eye_distance / 2, 0.0, 0.0) ## Sets the GroupNames field on all avatar parts to a list of strings. # @param LIST_OF_STRINGS A list of group names to be set for the avatar parts. def set_avatar_group_names(self, LIST_OF_STRINGS): self.avatar.set_group_names(LIST_OF_STRINGS) ## Appends a string to the GroupNames field of all avatar parts. # @param STRING The string to be appended to the GroupNames field. def append_to_avatar_group_names(self, STRING): self.avatar.append_to_group_names(STRING) ## Adds a screen visualization for a display instance to the avatar. # @param DISPLAY_INSTANCE The Display instance to retrieve the screen visualization from. def add_screen_visualization_for(self, DISPLAY_INSTANCE): self.avatar.add_screen_visualization_for(DISPLAY_INSTANCE) ## Appends a screen node for a display instance to the view transformation node. # @param DISPLAY_INSTANCE The Display instance to retrieve the screen node from. def add_screen_node_for(self, DISPLAY_INSTANCE): ## @var workspace_id # Identification number of the workspace the associated user is belonging to. self.workspace_id = int( self.view_transform_node.Name.value.split("_")[0].replace("w", "")) _screen = DISPLAY_INSTANCE.create_screen_node("screen_" + str(len(self.screens))) self.view_transform_node.Children.value.append(_screen) self.screens.append(_screen) _loader = avango.gua.nodes.TriMeshLoader() _navigation_color_geometry = _loader.create_geometry_from_file( 'nav_color_plane', 'data/objects/plane.obj', 'data/materials/' + self.DISPLAY_GROUP.navigations[0].trace_material + 'Shadeless.gmd', avango.gua.LoaderFlags.LOAD_MATERIALS) _trans = avango.gua.Vec3(-0.45 * _screen.Width.value, 0.4 * _screen.Height.value, 0.0) _scale = 0.05 * _screen.Height.value _navigation_color_geometry.Transform.value = avango.gua.make_trans_mat(_trans) * \ avango.gua.make_rot_mat(90, 1, 0, 0) * \ avango.gua.make_scale_mat(_scale, _scale, _scale) _navigation_color_geometry.ShadowMode.value = avango.gua.ShadowMode.OFF _navigation_color_geometry.GroupNames.value = [ "w" + str(self.workspace_id) + "_dg" + str(self.DISPLAY_GROUP.id) + "_u" + str(self.USER.id) ] _screen.Children.value.append(_navigation_color_geometry) ## Adds an already existing screen node to this UserRepresentation. # @param SCREEN_NODE The screen node to be added. def add_existing_screen_node(self, SCREEN_NODE): self.screens.append(SCREEN_NODE) ## Adds a scenegraph node to the list of dependent nodes. # @param NODE The node to be added. def add_dependent_node(self, NODE): self.dependent_nodes.append(NODE) ## Connects a specific navigation of the display group to the user. # @param ID The ID of the navigation to connect with. def connect_navigation_of_display_group(self, ID): # change is not necessary if ID == self.connected_navigation_id: print_message("User " + str(self.USER.id) + " at display group " + str(self.DISPLAY_GROUP.id) + \ ": Already on Navigaton " + str(ID)) # change is necessary elif ID < len(self.DISPLAY_GROUP.navigations): _old_navigation = self.DISPLAY_GROUP.navigations[ self.connected_navigation_id] _new_navigation = self.DISPLAY_GROUP.navigations[ID] self.view_transform_node.Transform.disconnect() if len(_new_navigation.active_user_representations ) == 0 and self.connected_navigation_id != -1: try: _new_navigation.inputmapping.set_abs_mat( _old_navigation.sf_abs_mat.value) _new_navigation.inputmapping.set_scale( _old_navigation.sf_scale.value) # avoid field connection frame latency by setting value directly self.view_transform_node.Transform.value = _old_navigation.sf_abs_mat.value * avango.gua.make_scale_mat( _old_navigation.sf_scale.value) except: pass _old_navigation.remove_user_representation(self) _new_navigation.add_user_representation(self) # connect view transform node to new navigation self.view_transform_node.Transform.connect_from( _new_navigation.sf_nav_mat) self.connected_navigation_id = ID try: print_message("User " + str(self.USER.id) + " at display group " + str(self.DISPLAY_GROUP.id) + \ ": Switch navigation to " + str(ID) + " (" + _new_navigation.input_device_name + ")") except: print_message("User " + str(self.USER.id) + " at display group " + str(self.DISPLAY_GROUP.id) + \ ": Switch navigation to " + str(ID) + " (no input device)") # trigger avatar and screen geometry visibilities self.avatar.set_material( 'data/materials/' + _new_navigation.trace_material + ".gmd", 'data/materials/' + _new_navigation.trace_material + "Shadeless.gmd") else: print_error("Error. Navigation ID does not exist.", False)
def setSprite(self, image): self.__sprite = Avatar.Avatar(image)
import Avatar avatar = Avatar.Avatar('Avatar.png') avatar.GetNewAvatar('circleflag')