/// <summary> /// 通过玩家id获取所属的npc /// </summary> /// <param name="playerID"></param> /// <returns></returns> public void GetOwnNpcByPlayerID(uint playerID, ref List <INPC> lstNPC) { IEntitySystem es = ClientGlobal.Instance().GetEntitySystem(); if (es == null) { return; } if (lstNPC == null) { return; } lstNPC.Clear(); es.FindAllEntity <INPC>(ref m_npcList); for (int i = 0; i < m_npcList.Count; i++) { INPC npc = m_npcList[i]; if (npc != null) { int masterID = npc.GetProp((int)NPCProp.Masterid); if (masterID == playerID) { lstNPC.Add(npc); } } } m_npcList.Clear(); }
void SetHP(long uid = 0) { if (m_petID == 0) { m_hpSpr.fillAmount = 1; return; } INPC npc = m_petData.GetNpcByPetID(m_petID); if (npc != null) { if (uid == 0 || uid == npc.GetUID()) { int curHP = npc.GetProp((int)CreatureProp.Hp); int maxHP = npc.GetProp((int)CreatureProp.MaxHp); if (maxHP != 0) { float v = curHP * 1.0f / maxHP; m_hpSpr.fillAmount = v; } } } }
void SetPetHP(long uid = 0) { if (m_petData.CurFightingPet != 0) { INPC npc = m_petData.GetNpcByPetID(m_petData.CurFightingPet); if (npc != null) { if (uid == 0 || uid == npc.GetUID()) { int curHP = npc.GetProp((int)CreatureProp.Hp); int maxHP = npc.GetProp((int)CreatureProp.MaxHp); if (maxHP != 0) { float v = curHP * 1.0f / maxHP; m_hpSlider.fillAmount = v; } } } else { m_hpSlider.fillAmount = 1; } } }
/// <summary> /// 判断npc是不是能攻击 根据表格 /// </summary> /// <param name="npc"></param> /// <returns></returns> public static bool IsNpcCanAttackByTable(IEntity en) { INPC npc = en as INPC; if (npc != null) { int modelID = npc.GetProp((int)EntityProp.BaseID); table.NpcDataBase ndb = GameTableManager.Instance.GetTableItem <table.NpcDataBase>((uint)modelID); if (ndb != null) { if (ndb.dwAttackType == 0) { return(false); } } } return(true); }
void PlayAudio() { Transform trans = m_Owner.GetTransForm(); if (trans != null) { uint resID = 0; uint delayTime = 0; if (m_Owner.GetEntityType() == EntityType.EntityType_Player) { int profession = m_Owner.GetProp((int)PlayerProp.Job); int nSex = m_Owner.GetProp((int)PlayerProp.Sex); var database = table.SelectRoleDataBase.Where((GameCmd.enumProfession)profession, (GameCmd.enmCharSex)nSex); if (database != null) { resID = database.deadAudio; delayTime = database.deadAudioDelay; } } else { INPC npc = m_Owner as INPC; if (npc != null) { int baseID = npc.GetProp((int)EntityProp.BaseID); table.NpcDataBase db = GameTableManager.Instance.GetTableItem <table.NpcDataBase>((uint)baseID); if (db != null) { resID = db.dwDeathMagicSoundID; delayTime = db.dwDeathMagicSoundDelay; } } } if (resID != 0) { table.ResourceDataBase rdb = GameTableManager.Instance.GetTableItem <table.ResourceDataBase>(resID); if (rdb != null) { m_strAudioPath = rdb.strPath; TimerAxis.Instance().SetTimer(m_timerID, delayTime, this, 1); } } } }
void ShowFlashColor(IEntity defender) { Profiler.BeginSample("ShowFlashColor"); INPC npc = defender as INPC; if (npc != null) { int baseID = npc.GetProp((int)EntityProp.BaseID); NpcDataBase npcDb = GameTableManager.Instance.GetTableItem <NpcDataBase>((uint)baseID); if (npcDb != null) { uint monsterType = npcDb.dwMonsterType; if (monsterType == 0) { return; } List <uint> configList = SkillSystem.GetColorList(monsterType); if (configList != null) { if (configList.Count > 0) { uint show = configList[0]; if (show == 1) { if (configList.Count != 6) { // Log.Error("全局配置FlashColor 长度错误 ,检查配置"); } else { FlashColor fc = new FlashColor(); fc.color = new Color(configList[2] * 1.0f / 255, configList[3] * 1.0f / 255, configList[4] * 1.0f / 255, configList[5] * 1.0f / 255); fc.fLift = configList[1] * 1.0f / 1000; defender.SendMessage(EntityMessage.EntityCommand_FlashColor, fc); // Log.Error("flash color " + defender.GetName()); } } } } } } Profiler.EndSample(); }
public INPC FindNPCByBaseId(int baseId, bool nearest = false) { allNpcList.Clear(); npcList.Clear(); EntityManager.Instance().FindAllEntity <INPC>(ref allNpcList); for (int i = 0; i < allNpcList.Count; ++i) { INPC npc = allNpcList[i]; if (npc.GetProp((int)EntityProp.BaseID) == baseId && !npc.IsDead()) { if (!nearest) { return(npc); } else { npcList.Add(npc); } } } if (m_ClientGlobal.MainPlayer == null) { return(null); } Vector3 pos = m_ClientGlobal.MainPlayer.GetPos(); INPC getNpc = null; float fMinDis = 5000000.0f; for (int i = 0; i < npcList.Count; i++) { float sqrlen = (npcList[i].GetPos() - pos).sqrMagnitude; if (sqrlen < fMinDis) { fMinDis = sqrlen; getNpc = npcList[i]; } } return(getNpc); }
public void PrepareUseSkill(GameCmd.stPrepareUseSkillSkillUserCmd_S cmd) { EntityType type = EntitySystem.EntityHelper.GetEntityEtype(cmd.usertype); ISkillPart skillPart = SkillHelper.GetSkillPart(cmd.userid, type); if (skillPart == null) { Engine.Utility.Log.Error("获取技能部件失败!" + cmd.userid + " type is " + Enum.GetName(typeof(EntityType), type)); return; } if (cmd.level == 0) { cmd.level = 1; } SkillDatabase database = GameTableManager.Instance.GetTableItem <table.SkillDatabase>(cmd.skillid, (int)cmd.level); if (database == null) { Engine.Utility.Log.Error(" skill database is null skillid is " + cmd.skillid.ToString() + " level is " + cmd.level.ToString()); return; } skillPart.OnPrepareUseSkill(cmd); if (type == EntityType.EntityType_Player) { uint time = (database.dwReadTime); if (time > 0) { TimerAxis.Instance().SetTimer(m_uReadSliderTimerID, time, this, 1); } } else if (type == EntityType.EntityType_NPC) { IEntitySystem es = ClientGlobal.Instance().GetEntitySystem(); if (es == null) { Engine.Utility.Log.Error("GetEntitySystem failed!"); return; } INPC npc = es.FindEntity <INPC>(cmd.userid); if (npc != null) { int masterID = npc.GetProp((int)NPCProp.Masterid); if (masterID == MainPlayerHelper.GetPlayerID()) { SkillDatabase db = GameTableManager.Instance.GetTableItem <SkillDatabase>((uint)cmd.skillid); if (db != null) { if (db.petType == 1 || db.petType == 2) { Client.stSkillCDChange st = new Client.stSkillCDChange(); st.skillid = (uint)cmd.skillid; st.cd = -1; Engine.Utility.EventEngine.Instance().DispatchEvent((int)Client.GameEventID.SKILLCD_BEGIN, st); TipsManager.Instance.ShowTips(npc.GetName() + CommonData.GetLocalString("使用") + db.strName); } } } } } }
void InitTargetChangeUI() { IEntity ie = Client.ClientGlobal.Instance().GetControllerSystem().GetActiveCtrl().GetCurTarget(); if (ie == null) { m_trans_target.gameObject.SetActive(false); } else { m_trans_target.gameObject.SetActive(true); IEntity entity = ie; string name = entity.GetName(); string lvstr = entity.GetProp((int)CreatureProp.Level).ToString(); m_label_MonsterLevel_Label.text = lvstr; bool showPackage = false; //怪 if (entity.GetEntityType() == EntityType.EntityType_NPC) { INPC npc = entity as INPC; NpcDataBase ndb = GameTableManager.Instance.GetTableItem <NpcDataBase>((uint)npc.GetProp((int)EntityProp.BaseID)); if (ndb == null) { return; } showPackage = npc.IsBoss(); if (ndb.dwMonsterType == 1) { InitTargetUIInMonster(); m_widget_player.gameObject.SetActive(false); m_widget_monster.gameObject.SetActive(true); m_lableTargetLevel.text = entity.GetProp((int)CreatureProp.Level).ToString(); } else { InitTargetUI(); string iconName = UIManager.GetIconName(ndb.npcIcon, npc.IsPet()); UIManager.GetTextureAsyn(iconName, ref m_curTargetIconAsynSeed, () => { if (null != m_spriteTargetIcon) { m_spriteTargetIcon.mainTexture = null; } }, m_spriteTargetIcon, false); m_widget_player.gameObject.SetActive(true); m_widget_monster.gameObject.SetActive(false); } } // 玩家 else { InitTargetUI(); m_widget_player.gameObject.SetActive(true); m_widget_monster.gameObject.SetActive(false); IPlayer player = entity as IPlayer; if (player != null) { int job = player.GetProp((int)PlayerProp.Job); int sex = player.GetProp((int)PlayerProp.Sex); SelectRoleDataBase sdb = table.SelectRoleDataBase.Where((GameCmd.enumProfession)job, (GameCmd.enmCharSex)sex); if (sdb != null) { UIManager.GetTextureAsyn(sdb.strprofessionIcon, ref m_curTargetIconAsynSeed, () => { if (null != m_spriteTargetIcon) { m_spriteTargetIcon.mainTexture = null; } }, m_spriteTargetIcon, false); } m_transHateList.gameObject.SetActive(false); } } m_toggle_packageState.gameObject.SetActive(showPackage); m_lableTargetName.text = name; UpdateTargetHp(entity); } }
//StringBuilder targetName = new StringBuilder(20); private void OnTargetChange(object param) { stTargetChange tc = (stTargetChange)param; if (tc.target == null) { m_trans_target.gameObject.SetActive(false); } else { IEntity entity = tc.target; string name = entity.GetName(); string lvstr = entity.GetProp((int)CreatureProp.Level).ToString(); m_label_MonsterLevel_Label.text = lvstr; bool showPackeage = false; if (entity.GetEntityType() == EntityType.EntityType_NPC) { INPC npc = entity as INPC; showPackeage = npc.IsBoss(); NpcDataBase ndb = GameTableManager.Instance.GetTableItem <NpcDataBase>((uint)npc.GetProp((int)EntityProp.BaseID)); if (ndb != null) { if (ndb.dwMonsterType == 1) { InitTargetUIInMonster(); m_widget_player.gameObject.SetActive(false); m_widget_monster.gameObject.SetActive(true); m_lableTargetLevel.text = entity.GetProp((int)CreatureProp.Level).ToString(); } else { InitTargetUI(); string iconName = UIManager.GetIconName(ndb.npcIcon, npc.IsPet()); UIManager.GetTextureAsyn(iconName, ref m_curTargetIconAsynSeed, () => { if (null != m_spriteTargetIcon) { m_spriteTargetIcon.mainTexture = null; } }, m_spriteTargetIcon, false); m_widget_player.gameObject.SetActive(true); m_widget_monster.gameObject.SetActive(false); } } if (npc.IsMonster() == false) { bool bVisit = true; if (npc.IsSummon() || npc.IsPet()) { bVisit = false; } CopyTypeTable ct = DataManager.Manager <ComBatCopyDataManager>().GetCurCopyType(); if (ct != CopyTypeTable.Arena) { if (bVisit) { Client.ClientGlobal.Instance().GetControllerSystem().GetActiveCtrl().VisiteNPC(npc.GetUID()); } } } else { //请 if (m_nLastNpcId != entity.GetUID()) { BShowEnemyList = false; m_transHateList.gameObject.SetActive(false); } } m_nLastNpcId = entity.GetUID(); if (m_nLastNpcId != 0) { stRefreshNPCBelongParam npcbelongdata = NpcAscription.Instance.GetNpcBelongByNpcID(m_nLastNpcId); UpdateTargetStatus(npcbelongdata.npcid, npcbelongdata.teamid, npcbelongdata.ownerid, npcbelongdata.clanid, npcbelongdata.ownerName); } } else { InitTargetUI(); m_widget_player.gameObject.SetActive(true); m_widget_monster.gameObject.SetActive(false); IPlayer player = entity as IPlayer; if (player != null) { int job = player.GetProp((int)PlayerProp.Job); int sex = player.GetProp((int)PlayerProp.Sex); SelectRoleDataBase sdb = table.SelectRoleDataBase.Where((GameCmd.enumProfession)job, (GameCmd.enmCharSex)sex); if (sdb != null) { UIManager.GetTextureAsyn(sdb.strprofessionIcon, ref m_curTargetIconAsynSeed, () => { if (null != m_spriteTargetIcon) { m_spriteTargetIcon.mainTexture = null; } }, m_spriteTargetIcon, false); } m_transHateList.gameObject.SetActive(false); //目标选择 OnSetSelectTargetGrid(player.GetID()); } } m_toggle_packageState.gameObject.SetActive(showPackeage); m_lableTargetName.text = name; //m_lableTargetLevel.text = entity.GetProp((int)CreatureProp.Level).ToString(); UpdateTargetHp(entity); BuffManager.TargetBuffList.Clear(); if (entity != null) { List <Client.stAddBuff> lstBuff; IBuffPart part = entity.GetPart(EntityPart.Buff) as IBuffPart; if (part != null) { part.GetBuffList(out lstBuff); for (int i = 0; i < lstBuff.Count; ++i) { stAddBuff buff = lstBuff[i]; table.BuffDataBase db = GameTableManager.Instance.GetTableItem <table.BuffDataBase>(buff.buffid); if (db != null) { if (db.dwShield == 1) {//不显示的直接跳过 continue; } } BuffManager.TargetBuffList.Add(lstBuff[i]); } } else { Engine.Utility.Log.Error("获取{0}Buff部件失败!", entity.GetName()); } } m_trans_target.gameObject.SetActive(true); RefreshBuffIcon(m_trans_TargetBUffContainer, BuffManager.TargetBuffList); } }
// 进入状态 public override void Enter(object param) { Engine.Utility.EventEngine.Instance().AddEventListener((int)Client.GameEventID.ENTITYSYSTEM_ENTITYSTOPMOVE, OnEvent); Engine.Utility.EventEngine.Instance().AddEventListener((int)Client.GameEventID.ENTITYSYSTEM_ENTITYBEGINMOVE, OnEvent); m_skillDoubleDb = null; m_fTotalTime = 0; skillPart = m_SkillPart; // m_skillDatabase = skillPart.GetCurSkillDataBase(); if (skillPart.GetSkillPartType() == SkillPartType.SKILL_PLAYERPART) { PlayerSkillPart playerSkill = skillPart as PlayerSkillPart; //m_nDoubleHitSkillId = (uint)playerSkill.NextSkillID; if (playerSkill.IsMainPlayer()) { Log.LogGroup("ZDY", "mainpalyer enter skillattackstate================"); } m_skillDatabase = GameTableManager.Instance.GetTableItem <SkillDatabase>(playerSkill.CurSkillID, 1); if (m_skillDatabase == null) { m_Statemachine.ChangeState((int)SkillState.None, null); return; } m_uDbJiangzhiTime = m_skillDatabase.wdStiffTime; playerSkill.SkillStiffTime = 0; m_skillDoubleDb = GameTableManager.Instance.GetTableItem <SkillDoubleHitDataBase>(playerSkill.CurSkillID); if (IsMainPlayer()) { Engine.Utility.EventEngine.Instance().DispatchEvent((int)GameEventID.SKILLSYSTEM_USESKILL, playerSkill.CurSkillID); } if (m_skillDatabase.dwMoveType == (uint)SkillMoveType.FastMove) { //处理位移技能 Move move = new Move(); Vector3 targePos = playerSkill.Master.GetPos(); if (playerSkill.GetSkillTarget() != null) { targePos = playerSkill.GetSkillTarget().GetPos(); Vector3 dir = targePos - playerSkill.Master.GetPos(); targePos = targePos - dir.normalized * 1f; move.m_target = targePos; // Vector3 lookat = playerSkill.GetSkillTarget().GetNode().GetTransForm().forward; } else { m_Statemachine.ChangeState((int)SkillState.None, playerSkill); Log.LogGroup("ZDY", "skilltarget is null"); return; } move.m_ignoreStand = true; if (Engine.Utility.Log.MaxLogLevel >= Engine.Utility.LogLevel.LogLevel_Group) { Log.LogGroup("ZDY", "冲锋 目标位置 " + targePos); } AnimationState ani = playerSkill.AttackAnimState; if (ani == null) { m_Statemachine.ChangeState((int)SkillState.None, playerSkill); Log.LogGroup("ZDY", "ani is null"); return; } move.strRunAct = ani.name; int curSpeed = playerSkill.Master.GetProp((int)WorldObjProp.MoveSpeed); uint flySpeed = m_skillDatabase.flyspeed; float speedFact = 1; if (flySpeed != 0) { speedFact = flySpeed * 1.0f / curSpeed; } Log.LogGroup("ZDY", "冲锋倍数 " + speedFact); playerSkill.Master.SendMessage(EntityMessage.EntityCommond_IgnoreMoveAction, true); playerSkill.Master.SendMessage(EntityMessage.EntityCommand_ChangeMoveSpeedFact, (object)speedFact); float dis = Vector3.Distance(targePos, playerSkill.Master.GetPos()); if (dis > 1) { Log.LogGroup("ZDY", " send moveto "); playerSkill.Master.SendMessage(EntityMessage.EntityCommand_MoveTo, (object)move); } playerSkill.gotoPos = targePos; } else { playerSkill.Master.SendMessage(EntityMessage.EntityCommand_ChangeMoveSpeedFact, (object)1f); } if (m_skillDatabase.useSkillType == (int)UseSkillType.GuideNoSlider) { if (m_skillDatabase.dwMoveType == (int)SkillMoveType.SkillOverMove) { playerSkill.Master.SendMessage(EntityMessage.EntityCommand_SetVisible, false); } if (m_skillDatabase.wdStiffTime == 0) {//狂扫八方的技能 playerSkill.Master.SendMessage(EntityMessage.EntityCommond_IgnoreMoveAction, true); } } else if (m_skillDatabase.useSkillType == (int)UseSkillType.GuideSlider) { if (playerSkill.IsMainPlayer()) { Client.stUninterruptMagic evenparam = new Client.stUninterruptMagic(); evenparam.time = m_skillDatabase.dwGuideTime; evenparam.type = GameCmd.UninterruptActionType.UninterruptActionType_SkillCJ; evenparam.uid = SkillSystem.GetClientGlobal().MainPlayer.GetUID(); EventEngine.Instance().DispatchEvent((int)GameEventID.SKILLGUIDE_PROGRESSSTART, evenparam); } playerSkill.Master.SendMessage(EntityMessage.EntityCommond_IgnoreMoveAction, true); } // if (m_skillDatabase.dwUseMethod == (int)UseMethod.ContinueLock) { playerSkill.Master.SendMessage(EntityMessage.EntityCommand_SetVisible, false); } INPC npc = playerSkill.Master as INPC; if (npc != null) { int masterID = npc.GetProp((int)NPCProp.Masterid); if (masterID == PlayerSkillPart.m_ClientGlobal.MainPlayer.GetID()) { /* Engine.Utility.EventEngine.Instance().DispatchEvent((int)GameEventID.SKILLCD_BEGIN, playerSkill.CurSkillID);*/ } } } }
private void SendPlayDefenerAniMessage(IEntity defender, string aniName) { CreatureState state = defender.GetCurState(); ShowFlashColor(defender); if (state != CreatureState.Dead) { bool bRide = (bool)defender.SendMessage(EntityMessage.EntityCommond_IsRide, null); if (bRide) { return; } SkillState skillState = GetTargetSkillState(defender); if (skillState != SkillState.Attack && skillState != SkillState.Prepare) { if (defender.GetCurState() == CreatureState.Contrl) { return; } if (state != CreatureState.Move) { Client.IControllerSystem cs = m_ClientGlobal.GetControllerSystem(); if (cs != null) { Client.ICombatRobot robot = cs.GetCombatRobot(); if (robot.Status == CombatRobotStatus.RUNNING) { if (SkillSystem.GetClientGlobal().IsMainPlayer(defender.GetID())) {//自动挂机 不播受击 return; } } } INPC npc = defender as INPC; if (npc != null) { int baseID = npc.GetProp((int)EntityProp.BaseID); NpcDataBase ndb = GameTableManager.Instance.GetTableItem <NpcDataBase>((uint)baseID); if (ndb != null) { if (ndb.dwMonsterType == 3) { return; } } } //defender.SendMessage( EntityMessage.EntityCommand_StopMove , defender.GetPos() ); //移动不播放受击动作 PlayAni anim_param = new PlayAni(); anim_param.strAcionName = aniName; anim_param.fSpeed = 1; anim_param.nStartFrame = 0; anim_param.nLoop = 1; anim_param.fBlendTime = 0.2f; anim_param.aniCallback = OnHitCallback; anim_param.callbackParam = defender; // if (SkillSystem.GetClientGlobal().IsMainPlayer(m_Master.GetID())) // { // Engine.Utility.Log.Info("技能 播放受击动作 {0} {1}", anim_param.strAcionName, state); // } defender.SendMessage(EntityMessage.EntityCommand_PlayAni, anim_param); } else { if (SkillSystem.GetClientGlobal().IsMainPlayer(m_Master.GetID())) { //Engine.Utility.Log.Info("移动不播放受击动作"); } } } else { // Engine.Utility.Log.Error(string.Format("{0}技能状态错误不能播放受击动作 状态:{1}", defender.GetName(), GetTargetSkillState(defender))); } } }