def OnBulletFlyFrame(self, data): logger.info("OnBulletFlyFrame: %s", data) bindId = data.get("bindId", "-1") # 同服务端的解释,tempEntity保存来自各个Component的数据 tempEntity = self.CreateTempEntity() typeComp = self.CreateComponent(tempEntity.mId, modConfig.Minecraft, modConfig.ScriptTypeCompClient) typeComp.type = clientApi.GetMinecraftEnum().EntityConst.TYPE_SFX pathComp = self.CreateComponent(tempEntity.mId, modConfig.Minecraft, modConfig.PathComponent) pathComp.path = modConfig.BulletFlyFrameSfx # 创建真正的特效SFX实体绑定在子弹上 frameEntityId = self.CreateEntity(tempEntity) entityBindComp = self.CreateComponent(frameEntityId, modConfig.Minecraft, modConfig.FrameAniBindComponent) entityBindComp.bindEntityId = bindId entityBindComp.offset = (-1, 0, 0) entityBindComp.rot = (0, 0, 0) self.NeedsUpdate(entityBindComp) playerPosComp = self.GetComponent(self.mPlayerId, modConfig.Minecraft, modConfig.PosComponent) transComp = self.CreateComponent(frameEntityId, modConfig.Minecraft, modConfig.FrameAniTransComponent) transComp.pos = playerPosComp.pos self.NeedsUpdate(transComp) ctrlComp = self.CreateComponent(frameEntityId, modConfig.Minecraft, modConfig.FrameAniCtrlComponent) ctrlComp.open = True ctrlComp.loop = True ctrlComp.faceCamera = True self.NeedsUpdate(ctrlComp) # 将特效实体Id保存在self.mHitDestroyIdList中,后续更新中会清除 bindList = self.mHitDestroyIdList.setdefault(bindId, []) bindList.append(frameEntityId)
def OnChangeButtonClick(self, args): if args["ButtonState"]: logger.info("OnChangeButtonClick down") return ViewRequest.Refresh else: logger.info("OnChangeButtonClick up") return ViewRequest.Refresh | ViewRequest.Exit
def DelayPlayAnimRun(self): yield -modConfig.DatiangouFengxiAnimFrames logger.info("Delay play run anim") modelComp = self.GetComponent(self.mPlayerId, modConfig.Minecraft, modConfig.ModelCompClient) modelComp.modelName = modConfig.DatiangouModel modelComp.aniName = modConfig.DatiangouRunAnim modelComp.isLoop = True self.NeedsUpdate(modelComp)
def Create(self): logger.info("===== FpsBattleScreen Create =====") self.mButtonPanel = "/buttonPanel" self.mAimButton = self.mButtonPanel + "/aimButton" self.mShootButtonRight = self.mButtonPanel + "/shootButtonRight" self.mChangeButton = self.mButtonPanel + "/changeButton" self.mShootButtonLeft = self.mButtonPanel + "/shootButtonLeft" self.mAimPanel = "/aimPanel" self.mAimImage = self.mAimPanel + "/aimImage" self.mAimingImage = self.mAimPanel + "/aimingImage"
def __init__(self, namespace, systemName): ClientSystem.__init__(self, namespace, systemName) logger.info("===== Client Listen =====") self.ListenEvent() # 保存ui界面节点 self.mFpsBattleUINode = None # 拼接ShootComponent的Key self.mShootKey = modConfig.ModName + ":" + modConfig.ClientShootComponent # 获取客户端本地玩家的playerId self.mPlayerId = clientApi.GetLocalPlayerId() # 用于保存在击中后需要释放的实体 self.mHitDestroyIdList = {}
def OnBulletHit(self, data): logger.info("OnBulletHit %s", data) bulletId = data.get("bulletId", "-1") targetId = data.get("targetId", "-1") hitFace = data.get("hitFace", -1) pos = data.get("pos", (0, 0, 0)) pos = tuple(pos) # 添加播放声音的Component audioComp = self.CreateComponent(self.mPlayerId, modConfig.Minecraft, modConfig.AudioComponent) audioComp.name = modConfig.BulletHitSound audioComp.pos = pos audioComp.volume = 1.0 audioComp.pitch = 1.0 audioComp.needPlay = True self.NeedsUpdate(audioComp) # 添加击中后在原地产生的爆炸粒子特效 tempEntity = self.CreateTempEntity() typeComp = self.CreateComponent(tempEntity.mId, modConfig.Minecraft, modConfig.ScriptTypeCompClient) typeComp.type = clientApi.GetMinecraftEnum().EntityConst.TYPE_PARTICLE pathComp = self.CreateComponent(tempEntity.mId, modConfig.Minecraft, modConfig.PathComponent) pathComp.path = modConfig.BulletHitEffect transComp = self.CreateComponent(tempEntity.mId, modConfig.Minecraft, modConfig.ParticleTransComponent) transComp.pos = pos particleEntityId = self.CreateEntity(tempEntity) ctrlComp = self.CreateComponent(particleEntityId, modConfig.Minecraft, modConfig.ParticleControlComponent) ctrlComp.open = True self.NeedsUpdate(ctrlComp) # 爆炸的粒子特效延迟销毁 CoroutineMgr.StartCoroutine(self.DelayCloseParticleControl(ctrlComp)) # 在每次射中后删除绑定在子弹上的特效 destroyList = self.mHitDestroyIdList.get(bulletId, None) if destroyList: for entityId in destroyList: self.DestroyEntity(entityId)
def OnUIInitFinished(self, args): logger.info("OnUIInitFinished : %s", args) # 注册UI 详细解释参照《UI API》 clientApi.RegisterUI(modConfig.ModName, modConfig.FpsBattleUIName, modConfig.FpsBattleUIPyClsPath, modConfig.FpsBattleUIScreenDef) # 创建UI 详细解释参照《UI API》 clientApi.CreateUI(modConfig.ModName, modConfig.FpsBattleUIName, {"isHud": 1}) self.mFpsBattleUINode = clientApi.GetUI(modConfig.ModName, modConfig.FpsBattleUIName) if self.mFpsBattleUINode: self.mFpsBattleUINode.Init() else: logger.error("create ui %s failed!" % modConfig.FpsBattleUIScreenDef) logger.info("change model datiangou") # 客户端换上模型大天狗并循环播放动作大天狗跑步 modelComp = self.CreateComponent(self.mPlayerId, modConfig.Minecraft, modConfig.ModelCompClient) modelComp.modelName = modConfig.DatiangouModel modelComp.aniName = modConfig.DatiangouRunAnim modelComp.isLoop = True self.NeedsUpdate(modelComp)
def Destroy(self): logger.info("===== Fps Client System Destroy =====") self.UnListenEvent()
def OnShootButtonRightClickCancel(self, args): logger.info("OnShootButtonRightClickCancel Cancel")
def OnShootButtonRightClick(self, args): logger.info("OnShootButtonRightClick Up") self.Shoot() return ViewRequest.Refresh | ViewRequest.Exit
def OnAimButtonClick(self, args): logger.info("OnAimButtonClick Up") self.Aim() return ViewRequest.Refresh | ViewRequest.Exit