示例#1
0
    override public void Update()
    {
        UpdateFinalRotation();
//		Debug.DrawLine(OwnerTransform.position + new Vector3(0, 1, 0), FinalPosition + new Vector3(0, 1, 0));

        RotationProgress += Time.deltaTime * Owner.BlackBoard.RotationSmoothInMove;
        RotationProgress  = Mathf.Min(RotationProgress, 1);
        Quaternion q = Quaternion.Slerp(StartRotation, FinalRotation, RotationProgress);

        Owner.Transform.rotation = q;

        if (MoveOk && AnimEngine[Action.Data.AnimName].time > AnimEngine[Action.Data.AnimName].length * 0.1f)
        {
            // Smooth the speed based on the current target direction
            float curSmooth = Owner.BlackBoard.SpeedSmooth * Time.deltaTime;

            Owner.BlackBoard.Speed   = Mathfx.Hermite(Owner.BlackBoard.Speed, MaxSpeed, curSmooth);
            Owner.BlackBoard.MoveDir = Owner.Forward;

            float dist = Owner.BlackBoard.Speed * 2 * Time.deltaTime;
            MoveOk = Move(Owner.BlackBoard.MoveDir * dist);

            if (NoHitTimer < Time.timeSinceLevelLoad)
            {
                Owner.SoundPlayRoll();
                NoHitTimer = Time.timeSinceLevelLoad + 0.75f;
            }

            //  Åжϼ¼ÄÜÉ˺¦
            Vector3 dirToPlayer = Player.Instance.transform.position - Owner.Transform.position;

            if (dirToPlayer.magnitude < Owner.BlackBoard.WeaponRange)
            {
                ActionInjury injury = ActionFactory.Create(ActionFactory.E_Type.E_INJURY) as ActionInjury;
                injury.Impuls = (dirToPlayer).normalized;

                Player.Instance.GetComponent <AnimComponent>().HandleAction(injury);
                Player.Instance.Owner.BlackBoard.Health -= 10;
                Player.Instance.comboHitNum              = 0;
            }
        }

        if (Effect == null && Time.timeSinceLevelLoad > TimeToStartEffect && Time.timeSinceLevelLoad < TimeToEndEffect)
        {
            Effect = CombatEffectsManager.Instance.PlayWhirlEffect(Transform);
        }
        else if (Effect != null && Time.timeSinceLevelLoad > TimeToEndEffect)
        {
            CombatEffectsManager.Instance.ReturnWhirlEffect(Effect);
            Effect = null;
        }


        if (TimeToEndState < Time.timeSinceLevelLoad)
        {
            Owner.WorldState.SetWSProperty(E_PropKey.E_IDLING, true);
            Release();
        }
    }
示例#2
0
    override public void OnDeactivate()
    {
        //  Time.timeScale = 1;

        Action.SetSuccess();
        Action = null;

        Owner.BlackBoard.MotionType = E_MotionType.None;

        base.OnDeactivate();
    }
示例#3
0
    public void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.CompareTag("Player"))
        {
            //  玩家受到伤害
            ActionInjury injury = ActionFactory.Create(ActionFactory.E_Type.E_INJURY) as ActionInjury;
            injury.Impuls = (other.gameObject.transform.position - transform.position).normalized * 2;

            Player.Instance.GetComponent <AnimComponent>().HandleAction(injury);
            Player.Instance.comboHitNum              = 0;
            Player.Instance.Owner.BlackBoard.Health -= 10;
            MainPanelCtrl.Instance.ShowComboMessage(Player.Instance.comboHitNum);
        }
    }
示例#4
0
    public void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.CompareTag("Player"))
        {
            ActionInjury injury = ActionFactory.Create(ActionFactory.E_Type.E_INJURY) as ActionInjury;
            injury.Impuls = (Direction).normalized;

            Player.Instance.GetComponent <AnimComponent>().HandleAction(injury);
            Player.Instance.comboHitNum              = 0;
            Player.Instance.Owner.BlackBoard.Health -= 10;
            MainPanelCtrl.Instance.ShowComboMessage(Player.Instance.comboHitNum);

            Destroy(this.gameObject, 0.2f);
        }
        else
        {
            Destroy(this.gameObject, 2);
        }
    }
示例#5
0
    protected override void Initialize(ActionBase action)
    {
        base.Initialize(action);

        Action = action as ActionInjury;

        // play owner anims
        string animName = Owner.AnimSet.GetInjuryAnim(Action.FromWeapon, Action.DamageType);

        CrossFade(animName, 0.1f);
        //end of state
        EndOfStateTime = AnimEngine[animName].length + Time.timeSinceLevelLoad;

        // Debug.Log(Action.AnimName + " " + EndOfStateTime );
        Owner.BlackBoard.MotionType = E_MotionType.None;

        MoveTime        = AnimEngine[animName].length * 0.5f;
        CurrentMoveTime = 0;

        if (Action.Attacker != null && Owner.IsPlayer == false)
        {
            Vector3 dir = Action.Attacker.Position - Transform.position;
            dir.Normalize();
            FinalRotation.SetLookRotation(dir);
            StartRotation    = Transform.rotation;
            RotationProgress = 0;
            RotationOk       = false;
        }
        else
        {
            RotationOk = true;
        }

        Impuls = Action.Impuls * 10;

        PositionOK = Impuls == Vector3.zero;

        // Debug.Log("recieve injury : " + animName + " end time " + EndOfStateTime + " start time "  + Time.timeSinceLevelLoad);

        Owner.BlackBoard.MotionType = E_MotionType.Injury;
    }
示例#6
0
    //  生成动作
    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 (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();
        }
    }