Ejemplo n.º 1
0
 protected override void Start()
 {
     actionComponent = GetComponent <ActionComponent>();
     unitInfo        = GetComponent <UnitInfo>();
     movement        = GetComponent <CharacterMovement>();
     ik = unitInfo.GetComponent <GenericIK>();
     unitInfo.AddDamageEvent(delegate(UnitInfo _causer, float _damage)
     {
         if (unitInfo.GetHP() <= 0)
         {
             SetState(AIState.die);
             return;
         }
         float[] roarHPs = { 75, 50, 25 };
         for (int i = 0; i < roarHPs.Length; i++)
         {
             if (unitInfo.GetLastHP() > roarHPs[i] && unitInfo.GetHP() <= roarHPs[i])
             {
                 if (unitInfo.GetCondition() >= ConditionData.UnitCondition.stuned)
                 {
                     unitInfo.GetComponent <ActionComponent>().UseSkill("WakeUp", true);
                 }
                 readyType = ActionReadyType.Roar;
                 unitInfo.RemoveCrowdControlAll();
             }
         }
     }
                             );
     unitInfo.AddStateChangeEvent(delegate(UnitInfo.UnitState _new, UnitInfo.UnitState _old)
     {
     }
                                  );
     weaknessPointObject.AddEvent(
         delegate(Transform caller)
     {
         Debug.Log(caller);
         StartCoroutine(DisappearWeakness());
         unitInfo.AddCrowdControl(ConditionData.UnitCondition.stuned, 5,
                                  delegate()
         {
             unitInfo.GetComponent <ActionComponent>().UseSkill("WakeUp", true);
             StartCoroutine(AppearWeakness(UnityEngine.Random.Range(0, weaknessPoints.Count)));
         }
                                  );
         actionComponent.StopAction();
         movement.Stop();
         movement.StopRotating();
     }
         );
     actionTarget = new GameObject(transform.name + " Action Target").transform;
     StartCoroutine(AppearWeakness(UnityEngine.Random.Range(0, weaknessPoints.Count)));
     base.Start();
     //actionTarget = pivot;
 }
Ejemplo n.º 2
0
    protected override IEnumerator combat()
    {
        Vector3 forward = (targetUnit.transform.position - pivot.position);

        forward.y = 0;
        forward.Normalize();
        float targetAngle = Quaternion.Angle(transform.rotation, Quaternion.LookRotation(forward));

        float targetDistance = Vector3.Distance(pivot.position, actionTarget.transform.position);

        float delay = 0;

        float rotateDelay = 0;


        actionComponent.GetBehaviour("DragonDash").SetTarget(targetUnit.transform);
        actionComponent.GetBehaviour("DragonBreathAir").SetTarget(targetUnit.transform);
        ik.SetAllTarget(actionTarget);
        actionComponent.UseSkill("DragonRoar", true);

        while (true)
        {
            if (unitInfo.GetCondition() >= ConditionData.UnitCondition.stuned)
            {
                yield return(null);

                continue;
            }
            forward = (targetUnit.transform.position - transform.position);
            forward.Normalize();
            targetAngle = Quaternion.Angle(transform.rotation, Quaternion.LookRotation(forward));
            if (delay > 0 && !actionComponent.IsUsingAction())
            {
                delay = Mathf.Clamp(delay - Time.deltaTime, 0, 10);
            }
            if (rotateDelay > 0)
            {
                rotateDelay = Mathf.Clamp(rotateDelay - Time.deltaTime, 0, 10);
            }
            ActionBehaviour currentAction = actionComponent.GetUsingAction();
            if (readyType == ActionReadyType.Roar)
            {// POINT -- ACTION ETC
                if (currentAction == null || currentAction.GetActionName() != "WakeUp")
                {
                    actionComponent.UseSkill("DragonRoar", true);
                    readyType = ActionReadyType.Fly;
                    delay     = 0.5f;
                }
            }
            else if (delay == 0 && readyType == ActionReadyType.Fly)
            {
                actionComponent.UseSkill("DragonFly", true);
                readyType = ActionReadyType.none;
                delay     = 0.5f;
            }
            else if (delay == 0)
            {
                if (!weaknessPointObject.isEnable)
                {
                    StartCoroutine(AppearWeakness(UnityEngine.Random.Range(0, weaknessPoints.Count)));
                }
                bool isGroundMoving = movement.GetMovingType() == CharacterMovement.MOVING_TYPE.ground;
                if (!movement.isOnGround && isGroundMoving)
                {
                    yield return(null);

                    continue;
                }
                if (isGroundMoving)
                {
                    targetDistance = Vector3.Distance(transform.position, targetUnit.transform.position);
                }
                else
                {
                    Vector2 p1 = new Vector2(transform.position.x, transform.position.z);
                    Vector2 p2 = new Vector2(targetUnit.transform.position.x, targetUnit.transform.position.z);
                    targetDistance = Vector2.Distance(p1, p2);
                }
                foreach (AIStateActionDragon sA in aiStateAction)
                {
                    //POINT -- ACTION
                    if (sA.enable && sA.movingType == movement.GetMovingType() && targetAngle < sA.angleLimit && !sA.behaviour.IsCoolDown() && IsInRange(targetDistance, sA.minDistance, sA.maxDistance))
                    {
                        movement.Stop();
                        movement.StopRotating();
                        actionComponent.UseSkill(sA.behaviour, false);
                        delay = 0.5f;
                        break;
                    }
                }
                if (!actionComponent.IsUsingAction() && (!isGroundMoving || (isGroundMoving && movement.isOnGround)))
                {
                    float minD = (isGroundMoving) ? minMovingDistance : minAirMovingDistance;
                    float maxD = (isGroundMoving) ? maxMovingDistance : maxAirMovingDistance;
                    if (IsInRange(targetDistance, minD, maxD))
                    {
                        float speed = (isGroundMoving) ? walkSpeed : flySpeed;
                        //POINT -- moving
                        forward.y = 0;
                        movement.Move(forward, speed, 0.2f);
                        movement.RotateTo(forward, 5);
                        actionTarget.position = Vector3.Lerp(actionTarget.position, targetUnit.transform.position, Time.deltaTime * lookSpeed);
                    }
                    else
                    {
                        //POINT -- rotating
                        if (movement.IsMoving())
                        {
                            movement.Stop();
                            movement.StopRotating();
                        }
                        ik.ToggleIK(true);
                        float      a   = Quaternion.Angle(transform.rotation, Quaternion.LookRotation(forward));
                        Quaternion rot = Quaternion.LookRotation(forward);
                        forward.y = 0;
                        if (a > 40 && !movement.IsRotating() && rotateDelay == 0)
                        {
                            movement.RotateTo(forward, turnSpeed);
                            rotateDelay = 3;
                        }
                        if (a < 90)
                        {
                            actionTarget.position = Vector3.Lerp(actionTarget.position, targetUnit.transform.position, Time.deltaTime * lookSpeed);
                        }
                    }
                }
            }
            yield return(null);
        }
    }
Ejemplo n.º 3
0
    void KeyInput()
    {
        if (myUnit.GetCondition() != ConditionData.UnitCondition.none)
        {
            movement.Stop();
            return;
        }

        // Zoom IN
        if (myUnit.GetAction().IsUsingAction("ThrowHarpoon"))
        {
            if (myUnit.GetAction().behaviourState < 3)
            {
                if ((!Input.GetKey(KeyCode.Mouse1) || myUnit.currentWeapon.weaponName != "Harpoon"))
                {
                    /*camSpring.ChangeCamInfo("Player");
                     * zoomIn = false;*/
                    if (zoomIn)
                    {
                        camSpring.ChangeCamInfo("Player");
                        zoomIn = false;
                    }
                    myUnit.GetAction().StopAction();
                }
            }

            /*if (zoomIn && !movement.isOnGround)
             * {
             *  Time.timeScale = 0.3f;
             *  Time.fixedDeltaTime = 0.02F * Time.timeScale;
             * }
             * else
             * {
             *  Time.timeScale = 1f;
             *  Time.fixedDeltaTime = 0.02F * Time.timeScale;
             * }*/
        }
        else
        {
            if (myUnit.currentWeapon.weaponName == "Harpoon")
            {
                if (Input.GetKeyDown(KeyCode.Mouse1))
                {
                    if (myUnit.GetAction().UseSkill("ThrowHarpoon"))
                    {
                        camSpring.ChangeCamInfo("Player_Aim");
                        zoomIn = true;
                    }
                }
            }
            else if (harpoonProjectile.harpoonState == PHarpoon.HARPOON_STATE.FIXED)
            {
                if (Input.GetKeyDown(KeyCode.Mouse1))
                {
                    myUnit.GetAction().UseSkill("PullHarpoon");
                }
            }
        }

        if (Input.GetKeyDown(KeyCode.Mouse0))
        {
            if (harpoonProjectile.harpoonState == PHarpoon.HARPOON_STATE.FIXED)
            {
                myUnit.GetAction().UseSkill("HookShot", false);
            }
            else if (!zoomIn && harpoonProjectile.harpoonState == PHarpoon.HARPOON_STATE.NONE)
            {
                myUnit.GetAction().UseSkill("SwingWeapon");
            }
            else if (zoomIn && harpoonProjectile.harpoonState == PHarpoon.HARPOON_STATE.NONE)
            {
                myUnit.GetAction().UseSkill("ThrowHarpoon");
            }
        }
        MovementInput();
        if (Input.GetKey(KeyCode.E) && harpoonProjectile.harpoonState == PHarpoon.HARPOON_STATE.FIXED)
        {
            if (harpoonProjectile.fixedTarget.tag == "Monster")
            {
                SoulInfo soulInfo = harpoonProjectile.fixedTarget.GetComponent <SoulInfo>();
                if (soulInfo && soulInfo.IsAnEvil())
                {
                    myUnit.GetAction().UseSkill("HealingSoul", false);
                }
            }
        }
        if (Input.GetKeyDown(KeyCode.Space) && !myUnit.GetAction().IsUsingAction())
        {
            if (!movement.isOnGround)
            {
                if (myUnit.IsHaveBuff(BuffBehaviour.BuffType.Fly))
                {
                    myUnit.GetAction().UseSkill("Flying");
                }
            }
            else
            {
                movement.Jump(jumpPower);
            }
        }
    }