IEnumerator KillNpc(MyAnimationEvent.Message msg) { GetComponent <PlayerAIController> ().enabled = false; NpcAttribute attribute = GetComponent <NpcAttribute> (); attribute._characterState = CharacterState.Story; DialogRender.KillNpcMessage m = (DialogRender.KillNpcMessage)msg; var targetName = m.dialog.dialog; var target = GameObject.Find(targetName); Debug.Log("start kill Npc"); yield return(StartCoroutine(commonAI.MoveToPos(target.transform.position))); //Rotation And Move To Target Position yield return(StartCoroutine(commonAI.KillNpc(target))); attribute._characterState = CharacterState.Idle; GetComponent <Animation>().CrossFade("idle"); GetComponent <PlayerAIController> ().enabled = false; }
/// <summary> ///检测附近如果有相关的机关则引爆 /// 当落到地面的时候 /// </summary> void CheckNearByBomb() { var sp = gameObject.AddComponent <SphereCollider>(); sp.isTrigger = true; sp.radius = 4; var col = Physics.OverlapSphere(transform.position, 4, 1 << (int)GameLayer.Npc); var goDie = false; var meType = attribute.ObjUnitData.ID; foreach (var c in col) { var npc = c.GetComponent <NpcAttribute>(); if (npc.ObjUnitData.ID == meType && npc.GetLocalId() != attribute.GetLocalId() && !npc.IsDead) { var evt = npc.GetComponent <MyAnimationEvent>(); var et = new MyAnimationEvent.Message(); et.type = MyAnimationEvent.MsgType.BOMB; evt.InsertMsg(et); goDie = true; } } Log.AI("CheckNearBy ToBomb " + goDie + " col " + col.Length + " name " + gameObject.name); if (goDie) { //GetComponent<MyAnimationEvent>().timeToDead = true; var evt = new MyAnimationEvent.Message(); evt.type = MyAnimationEvent.MsgType.BOMB; GetComponent <MyAnimationEvent>().InsertMsg(evt); } }
/// <summary> ///检查是否释放冲击技能 /// </summary> /// <returns>The rush.</returns> IEnumerator CheckRush() { var commonAI = GetComponent <CommonAI>(); while (true) { var target = commonAI.targetPlayer; var state = ai.state.type; if (target != null && !target.GetComponent <NpcAttribute>().IsDead&& state == AIStateEnum.COMBAT) { var diff = Util.XZSqrMagnitude(transform.position, target.transform.position); Log.Sys("Skill117 diff " + diff); //距离适中冲刺 if (diff > 25 && diff < 100) { var msg = new MyAnimationEvent.Message(); msg.type = MyAnimationEvent.MsgType.DoSkill; var sd = Util.GetSkillData(141, 1); msg.skillData = sd; GetComponent <MyAnimationEvent>().InsertMsg(msg); } } yield return(new WaitForSeconds(2)); } }
/// <summary> /// 恢复IDLE状态 /// </summary> public override void OnDie() { base.OnDie(); var ani = obj.GetComponent <MyAnimationEvent> (); var msg = new MyAnimationEvent.Message(MyAnimationEvent.MsgType.EXIT_STUNNED); ani.InsertMsg(msg); }
/// <summary> /// 进入STUNNED状态不出来了 如果死亡也会出来 /// </summary> public override void OnActive() { Log.AI("Stunned Buff Active"); var ani = obj.GetComponent <MyAnimationEvent> (); var msg = new MyAnimationEvent.Message(MyAnimationEvent.MsgType.STUNNED); ani.InsertMsg(msg); }
//所有命令执行函数需要注意命令执行结束的时候 设定当前命令为null void EnterUseSkill(ObjectCommand cmd) { //判断是否可以使用技能 var msg = new MyAnimationEvent.Message(MyAnimationEvent.MsgType.DoSkill); msg.skillData = Util.GetSkillData(cmd.skillId, cmd.skillLevel); GetComponent <MyAnimationEvent>().InsertMsg(msg); currentLogicCommand = null; }
protected override bool CheckEventOverride(MyAnimationEvent.Message msg) { Log.AI("CheckEventOverride " + msg.type); if (msg.type == MyAnimationEvent.MsgType.BOMB) { Log.AI("CheckBombEvent " + msg.type); var sdata = Util.GetSkillData(137, 1); aiCharacter.GetAttr().StartCoroutine(SkillLogic.MakeSkill(aiCharacter.GetAttr().gameObject, sdata, GetAttr().transform.position)); aiCharacter.ChangeState(AIStateEnum.DEAD); return(true); } return(base.CheckEventOverride(msg)); }
/// <summary> ///检查是否释放冲击技能 /// </summary> /// <returns>The rush.</returns> IEnumerator CheckRush() { var commonAI = GetComponent <CommonAI>(); while (true) { var target = commonAI.targetPlayer; var state = ai.state.type; if (target != null && !target.GetComponent <NpcAttribute>().IsDead&& state == AIStateEnum.COMBAT) { var msg = new MyAnimationEvent.Message(); msg.type = MyAnimationEvent.MsgType.DoSkill; var sd = Util.GetSkillData(142, 1); msg.skillData = sd; GetComponent <MyAnimationEvent>().InsertMsg(msg); } yield return(new WaitForSeconds(5)); } }
protected virtual bool CheckEventOverride(MyAnimationEvent.Message msg) { return(false); }
protected virtual bool CheckEventOverride(MyAnimationEvent.Message msg) { Log.AI("DefaultEvent " + msg.type); return(false); }
//TODO:检测一些事件 然后进行状态切换 //获得对应注册哪些事件, 就检测哪些事件? //只有状态切换成功才回 CheckEvent 返回true protected bool CheckEvent() { if (CheckBaseEvent()) { return(true); } var msg = GetEvent().NextMsg(); lastMsg = msg; if (msg != null) { Log.AI("CheckEventIs " + msg.type); if (msg.type == MyAnimationEvent.MsgType.IDLE) { return(aiCharacter.ChangeState(AIStateEnum.IDLE)); } else if (msg.type == MyAnimationEvent.MsgType.DoSkill) { var isBaseAttack = GetSkill().IsDefaultSkill(msg.skillData); Log.AI("CheckCastSkill " + isBaseAttack); if (isBaseAttack) { Log.AI("CheckAttack " + msg.type); var skillPart = GetSkill(); skillPart.SetDefaultActive(); return(aiCharacter.ChangeState(AIStateEnum.COMBAT)); } else { Log.AI("Enter CastSkill"); var skillPart = GetSkill(); skillPart.SetActiveSkill(msg.skillData); //技能动作为空 if (string.IsNullOrEmpty(msg.skillData.AnimationName)) { SkillLogic.UseSkill(GetAttr()); return(false); } else { return(aiCharacter.ChangeState(AIStateEnum.CAST_SKILL)); } } } else if (msg.type == MyAnimationEvent.MsgType.STUNNED) { return(aiCharacter.ChangeState(AIStateEnum.Stunned)); } else if (msg.type == MyAnimationEvent.MsgType.EXIT_STUNNED) { return(aiCharacter.ChangeState(AIStateEnum.IDLE)); } else if (msg.type == MyAnimationEvent.MsgType.DEAD) { return(aiCharacter.ChangeState(AIStateEnum.DEAD)); } else if (msg.type == MyAnimationEvent.MsgType.JUMP) { Log.AI("EnterJumpStateNow"); return(aiCharacter.ChangeState(AIStateEnum.JUMP)); } else { return(CheckEventOverride(msg)); } } return(false); //return CheckAttackEvent (); }