void OnSceneGUI() { ActionDeath action = target as ActionDeath; LevelBuilderCommon.Default5ActionButton(action.transform.position + new Vector3(0, 1.5f, 0), action); LevelBuilderCommon.DeleteButton(action); }
void OnTriggerEnter(Collider collider) { if (!this.active) { return; } Debug.Log("touched"); Player player = collider.GetComponent <Player>(); if (player != null && !player.isInAir()) { ActionDeath action = new ActionDeath(); action.type = DeathType.Gap; player.doAction(action); this.falling = true; } }
override public void OnDeactivate() { // Time.timeScale = 1.0f; if (ActionDeath != null) { ActionDeath.SetSuccess(); } ActionDeath = null; Action.SetSuccess(); Action = null; Owner.BlackBoard.MotionType = E_MotionType.None; base.OnDeactivate(); }
protected override void Initialize(ActionBase action) { base.Initialize(action); Action = action as ActionDeath; // play owner anims string animName = Owner.AnimSet.GetDeathAnim(Action.FromWeapon, Action.DamageType); CrossFade(animName, 0.1f); // Debug.Log(Action.AnimName + " " + EndOfStateTime ); Owner.BlackBoard.MotionType = E_MotionType.None; StartPosition = Transform.position; if (Action.Attacker != null) { FinalPosition = StartPosition + Action.Attacker.Forward; StartRotation = Transform.rotation; FinalRotation.SetLookRotation(-Action.Attacker.Forward); PositionOK = false; RotationOk = false; RotationProgress = 0; } else { StartPosition = Transform.position; FinalPosition = StartPosition + Action.Impuls; PositionOK = false; RotationOk = true; } CurrentMoveTime = 0; MoveTime = AnimEngine[animName].length * 0.6f; Owner.Invoke("SpawnBlood", AnimEngine[animName].length); Owner.BlackBoard.MotionType = E_MotionType.Death; Owner.DisableCollisions(); }
override public bool HandleNewAction(ActionBase action) { if (action as ActionKnockdown != null) { Debug.LogError("obsolete AgentActionBlock arrived"); action.SetFailed(); return(true); } if (action as ActionDeath != null) { ActionDeath = action as ActionDeath; //if (Owner.debugAnims == true) Debug.Log(Time.timeSinceLevelLoad + " " + this.ToString() + " Handle new action " + action.ToString()); InitializeDeath(); return(true); } return(false); }
// 生成动作 static public ActionBase Create(E_Type type) { int index = (int)type; ActionBase a; if (m_UnusedActions[index].Count > 0) { a = m_UnusedActions[index].Dequeue(); } else { switch (type) { case E_Type.E_IDLE: a = new ActionIdle(); break; case E_Type.E_MOVE: a = new ActionMove(); break; case E_Type.E_GOTO: a = new ActionGoTo(); break; case E_Type.E_COMBAT_MOVE: a = new ActionCombatMove(); break; case E_Type.E_ATTACK: a = new ActionAttack(); break; case E_Type.E_ATTACK_ROLL: a = new ActionAttackRoll(); break; case E_Type.E_ATTACK_WHIRL: a = new ActionAttackWhirl(); break; case E_Type.E_INJURY: a = new ActionInjury(); break; case E_Type.E_DAMAGE_BLOCKED: a = new ActionDamageBlocked(); break; case E_Type.E_BLOCK: a = new ActionBlock(); break; case E_Type.E_ROLL: a = new ActionRoll(); break; case E_Type.E_INCOMMING_ATTACK: a = new ActionIncommingAttack(); break; case E_Type.E_WEAPON_SHOW: a = new ActionWeaponShow(); break; case E_Type.E_Rotate: a = new ActionRotate(); break; case E_Type.E_USE_LEVER: a = new ActionUseLever(); break; case E_Type.E_PLAY_ANIM: a = new ActionPlayAnim(); break; case E_Type.E_PLAY_IDLE_ANIM: a = new ActionPlayIdleAnim(); break; case E_Type.E_DEATH: a = new ActionDeath(); break; case E_Type.E_KNOCKDOWN: a = new ActionKnockdown(); break; case E_Type.E_Teleport: a = new ActionTeleport(); break; default: Debug.LogError("no Action to create"); return(null); } } a.Reset(); a.SetActive(); m_ActionsInAction.Add(a); return(a); }
override public void Update() { //if (m_Human.PlayerProperty != null) //Debug.Log(Time.timeSinceLevelLoad + " " + this.ToString() + " - update " + State.ToString() + " " + EndOfStateTime); if (State == E_State.Death) { return; } if (RotationOk == false) { CurrentRotationTime += Time.deltaTime; if (CurrentRotationTime >= RotationTime) { CurrentRotationTime = RotationTime; RotationOk = true; } float progress = CurrentRotationTime / RotationTime; Quaternion q = Quaternion.Lerp(StartRotation, FinalRotation, progress); Owner.Transform.rotation = q; } if (PositionOK == false) { CurrentMoveTime += Time.deltaTime; if (CurrentMoveTime >= MoveTime) { CurrentMoveTime = MoveTime; PositionOK = true; } float progress = CurrentMoveTime / MoveTime; Vector3 finalPos = Mathfx.Sinerp(StartPosition, FinalPosition, progress); //MoveTo(finalPos); if (Move(finalPos - Transform.position) == false) { PositionOK = true; } } switch (State) { case E_State.Start: if (EndOfStateTime <= Time.timeSinceLevelLoad) { InitializeKnockdownLoop(); } break; case E_State.Loop: if (EndOfStateTime <= Time.timeSinceLevelLoad) { InitializeKnockdownUp(); } break; case E_State.Fatality: if (EndOfStateTime <= Time.timeSinceLevelLoad) { if (ActionDeath != null) { ActionDeath.SetSuccess(); ActionDeath = null; } InitializeDeath(); } break; case E_State.End: if (EndOfStateTime <= Time.timeSinceLevelLoad) { Release(); } break; case E_State.Death: break; } }
override public void Update() { if (State == E_State.E_PREPARING) { bool dontMove = false; if (RotationOk == false) { //Debug.Log("rotate"); CurrentRotationTime += Time.deltaTime; if (CurrentRotationTime >= RotationTime) { CurrentRotationTime = RotationTime; RotationOk = true; } float progress = CurrentRotationTime / RotationTime; Quaternion q = Quaternion.Lerp(StartRotation, FinalRotation, progress); Owner.transform.rotation = q; if (Quaternion.Angle(q, FinalRotation) > 20.0f) { dontMove = true; } } if (dontMove == false && PositionOK == false) { CurrentMoveTime += Time.deltaTime; if (CurrentMoveTime >= MoveTime) { CurrentMoveTime = MoveTime; PositionOK = true; } if (CurrentMoveTime > 0) { float progress = CurrentMoveTime / MoveTime; Vector3 finalPos = Mathfx.Hermite(StartPosition, FinalPosition, progress); //if (MoveToCollideWithEnemy(finalPos, Transform.forward) == false) if (Move(finalPos - Transform.position) == false) { PositionOK = true; } } } if (RotationOk && PositionOK) { State = E_State.E_ATTACKING; PlayAnim(); } } else if (State == E_State.E_ATTACKING) { CurrentMoveTime += Time.deltaTime; if (AttackPhaseTime < Time.timeSinceLevelLoad) { //Debug.Log(Time.timeSinceLevelLoad + " attack phase done"); Action.AttackPhaseDone = true; State = E_State.E_FINISHED; } if (CurrentMoveTime >= MoveTime) { CurrentMoveTime = MoveTime; } if (CurrentMoveTime > 0 && CurrentMoveTime <= MoveTime) { float progress = Mathf.Min(1.0f, CurrentMoveTime / MoveTime); Vector3 finalPos = Mathfx.Hermite(StartPosition, FinalPosition, progress); //if (MoveToCollideWithEnemy(finalPos, Transform.forward) == false) if (Move(finalPos - Transform.position, false) == false) { CurrentMoveTime = MoveTime; } // Debug.Log(Time.timeSinceLevelLoad + " moving"); } if (Action.Hit == false && HitTime <= Time.timeSinceLevelLoad) { Action.Hit = true; if (Owner.IsPlayer && AnimAttackData.FullCombo) { // 在游戏UI上显示满的连招信息 Owner.SoundPlayKnockdown(); MainPanelCtrl.Instance.SkillShowMessage(AnimAttackData.ComboIndex); } // 显示攻击的光影效果 if (AnimAttackData.LastAttackInCombo) { Owner.StartCoroutine(ShowTrail(AnimAttackData, 1, 0.3f, Critical, MoveTime - Time.timeSinceLevelLoad)); } else { Owner.StartCoroutine(ShowTrail(AnimAttackData, 2, 0.1f, Critical, MoveTime - Time.timeSinceLevelLoad)); } //Debug.Log("DoMeleeDamage " + (Action.AttackTarget != null ? Action.AttackTarget.name : "no target")); if (Action.Target == null) { Owner.SoundPlayMiss(); } if (Action.Target != null) { // 当攻击完成,如果当前的攻击目标是敌人 // 通过当前的攻击位置,攻击方向和攻击范围,敌人是否仍在此攻击范围内,如果在就受到伤害,如果不在就不会受到伤害 // 当前的攻击位置和方位 // 就是计算攻击完成后当前怪物和人的相对位置,通过相对位置来判断 if (Owner.IsPlayer) { List <Agent> enemies = Player.Instance.currentSpawnZone.EnemiesAlive; Agent enemy; Vector3 dirToEnemy; if (enemies == null || enemies.Count <= 0) { Owner.SoundPlayMiss(); return; } for (int i = 0; i < enemies.Count; i++) { enemy = enemies[i]; dirToEnemy = enemy.transform.position - Owner.Transform.position; if (dirToEnemy.magnitude < Owner.BlackBoard.WeaponRange + 0.2f) { if (Vector3.Angle(Owner.Forward, dirToEnemy) < 50) { // 判断敌人是否背对玩家,如果是就一刀必杀,慢动作,直接死(角度在120之内) // 根据是横向还是纵向中刀,判断不同的死亡动画 if (Vector3.Angle(Owner.Forward, enemy.Forward) < 90) { Debug.Log("一刀必杀"); Owner.SoundPlayKnockdown(); MainPanelCtrl.Instance.ShowBloodPanel(); Player.Instance.comboHitNum++; Player.Instance.coin += enemy.Experience; MainPanelCtrl.Instance.ShowComboMessage(Player.Instance.comboHitNum); // Action.Data.HitCriticalType enemy.BlackBoard.Health = 0; enemy.Status = E_CurrentStatus.E_Death; ActionDeath actionDeath = ActionFactory.Create(ActionFactory.E_Type.E_DEATH) as ActionDeath; enemy.GetComponent <AnimComponent>().HandleAction(actionDeath); CombatEffectsManager.Instance.PlayCriticalEffect(enemy.Transform.position, enemy.Forward); return; } // 技能格挡 else if (Vector3.Angle(Owner.Forward, enemy.Forward) > 165 && enemy.canBlock) { // 2/3概率格挡成功 if (Random.Range(0, 3) < 2) { ActionBlock actionBlock = ActionFactory.Create(ActionFactory.E_Type.E_BLOCK) as ActionBlock; actionBlock.Attacker = Owner; enemy.GetComponent <AnimComponent>().HandleAction(actionBlock); enemy.Status = E_CurrentStatus.E_Block; Owner.SoundPlayBlockHit(); CombatEffectsManager.Instance.PlayBlockHitEffect(enemy.Transform.position, enemy.Forward); return; } } Owner.SoundPlayHit(); enemy.BlackBoard.Health -= Owner.Attack; // 判断敌人是否死亡,主UI面板显示血液 if (enemy.BlackBoard.Health <= 0) { Player.Instance.coin += enemy.Experience; enemy.BlackBoard.Health = 0; enemy.Status = E_CurrentStatus.E_Death; ActionDeath actionDeath = ActionFactory.Create(ActionFactory.E_Type.E_DEATH) as ActionDeath; enemy.GetComponent <AnimComponent>().HandleAction(actionDeath); CombatEffectsManager.Instance.PlayBloodBigEffect(enemy.Transform.position, enemy.Forward); } else { ActionInjury injury = ActionFactory.Create(ActionFactory.E_Type.E_INJURY) as ActionInjury; injury.DamageType = E_DamageType.Front; injury.Impuls = (dirToEnemy).normalized; enemy.GetComponent <AnimComponent>().HandleAction(injury); // 将敌人的状态切回Idle,不然切不回去 enemy.WorldState.SetWSProperty(E_PropKey.E_IDLING, true); enemy.Status = E_CurrentStatus.E_Injury; // 播放流血效果 CombatEffectsManager.Instance.PlayBloodEffect(enemy.Transform.position, enemy.Forward); } Player.Instance.comboHitNum++; MainPanelCtrl.Instance.ShowComboMessage(Player.Instance.comboHitNum); } else { Owner.SoundPlayMiss(); } } } } // 如果目标是玩家 else { Vector3 dirToPlayer = Player.Instance.transform.position - Owner.Transform.position; if (dirToPlayer.magnitude < Owner.BlackBoard.WeaponRange - 0.5f) { if (Vector3.Angle(dirToPlayer, Owner.Forward) < 40) { ActionInjury injury = ActionFactory.Create(ActionFactory.E_Type.E_INJURY) as ActionInjury; injury.Impuls = (dirToPlayer).normalized; Owner.SoundPlayHit(); Player.Instance.GetComponent <AnimComponent>().HandleAction(injury); Player.Instance.Owner.BlackBoard.Health -= Owner.Attack; Player.Instance.comboHitNum = 0; MainPanelCtrl.Instance.ShowComboMessage(Player.Instance.comboHitNum); } } } } // 判断玩家是否打中木桶的 // 首先需要获得到当前场景中的所有木桶对象 if (Owner.IsPlayer) { if (Player.Instance.currentGameZone == null) { Debug.Log("不在游戏区域内"); return; } BreakableObject[] suds = Player.Instance.currentGameZone.GetComponentsInChildren <BreakableObject>(); if (suds == null || suds.Length <= 0) { return; } foreach (var sud in suds) { Vector3 dirToSud = sud.transform.position - Owner.Transform.position; float angle = Vector3.Angle(Owner.Forward, dirToSud); if (dirToSud.magnitude < Owner.BlackBoard.WeaponRange + 0.2f && angle < 60) { if (sud.Breakable == false) { sud.Break(); sud.Breakable = true; Player.Instance.coin += 50; } } } } } } else if (State == E_State.E_FINISHED && EndOfStateTime <= Time.timeSinceLevelLoad) { Action.AttackPhaseDone = true; Owner.WorldState.SetWSProperty(E_PropKey.E_IDLING, true); //Debug.Log(Time.timeSinceLevelLoad + " attack finished"); Release(); } }
// Update is called once per frame void Update() { if (!Owner.IsAlive) { Debug.Log("Game Over"); ActionDeath actionDeath = ActionFactory.Create(ActionFactory.E_Type.E_DEATH) as ActionDeath; GetComponent <AnimComponent>().HandleAction(actionDeath); StartCoroutine(BackToMainMenu()); } #region 测试代码 // Debug.Log(currentGameZone.name); //if (Input.GetKeyDown(KeyCode.Alpha1)) //{ // // 受伤动作 // ActionInjury actionInjury=ActionFactory.Create(ActionFactory.E_Type.E_INJURY)as ActionInjury; // actionInjury.Attacker = null; // actionInjury.DamageType = E_DamageType.Back; // actionInjury.FromWeapon = E_WeaponType.Katana; // GetComponent<AnimComponent>().HandleAction(actionInjury); // // 死亡动作 // ActionDeath actionDeath = ActionFactory.Create(ActionFactory.E_Type.E_DEATH) as ActionDeath; // actionDeath.Attacker = null; // actionDeath.DamageType = E_DamageType.Back; // actionDeath.FromWeapon = E_WeaponType.Katana; // GetComponent<AnimComponent>().HandleAction(actionDeath); // isDeath = true; // Debug.Log("GameOver"); //} #endregion if (Owner.BlackBoard.Stop) { lastAttacketTarget = null; comboProgress.Clear(); ClearBufferedOrder(); CreateOrderStop(); control.Update(); return; } // 玩家操作更新 control.Update(); // 当玩家进行UI界面操作时,所有按键操作停止工作 if (!useMode) { comboProgress.Clear(); return; } // 方向控制不够灵活,后续再优化 if (control.buttons[(int)PlayerControl.E_ButtonName.Up].status == PlayerControl.E_ButtonStatus.Down) { // 首先需要判断当前是否可以进行该操作 // 玩家在进行闪避,攻击或者使用道具时,不能执行行走操作 if (CanAddNewAction()) { // Debug.Log("玩家向前移动"); CreateOrderMove(Vector3.forward); } } if (control.buttons[(int)PlayerControl.E_ButtonName.Down].status == PlayerControl.E_ButtonStatus.Down) { if (CanAddNewAction()) { // Debug.Log("玩家向后移动"); CreateOrderMove(Vector3.back); } } if (control.buttons[(int)PlayerControl.E_ButtonName.Left].status == PlayerControl.E_ButtonStatus.Down) { if (CanAddNewAction()) { // Debug.Log("向左移动"); CreateOrderMove(Vector3.left); } } if (control.buttons[(int)PlayerControl.E_ButtonName.Right].status == PlayerControl.E_ButtonStatus.Down) { if (CanAddNewAction()) { // Debug.Log("向右移动"); CreateOrderMove(Vector3.right); } } if (control.buttons[(int)PlayerControl.E_ButtonName.Roll].status == PlayerControl.E_ButtonStatus.Down) { // Debug.Log("闪避动作"); CreateOrderDodge(); } if (control.buttons[(int)PlayerControl.E_ButtonName.AttackX].status == PlayerControl.E_ButtonStatus.Down) { // Debug.Log("将X添加组合攻击链表"); CreateOrderAttack(E_AttackType.X); } if (control.buttons[(int)PlayerControl.E_ButtonName.AttackO].status == PlayerControl.E_ButtonStatus.Down) { // Debug.Log("将O添加组合攻击链表"); CreateOrderAttack(E_AttackType.O); } // 当没有任何按键操作时,切回idle状态 bool hasAnyKeyDown = false; for (int i = 0; i < control.buttons.Length; i++) { if (control.buttons[i].status == PlayerControl.E_ButtonStatus.Down) { hasAnyKeyDown = true; } } if (hasAnyKeyDown == false) { weaponStartTime += Time.deltaTime; if (weaponStartTime > weaponTime) { weaponStartTime = 0; ClearBufferedOrder(); comboProgress.Clear(); MainPanelCtrl.Instance.ComboProgressMessage(comboProgress); if (Owner.BlackBoard.WeaponState != E_WeaponState.NotInHands) { GetComponent <Animation>().CrossFade("hideSword", 0.1f); GetComponent <Animation>().CrossFadeQueued("idle", 0.1f); Owner.SoundPlayWeaponOff(); Owner.BlackBoard.WeaponState = E_WeaponState.NotInHands; } CreateOrderStop(); } else { CreateOrderStop(); } } }