Exemplo n.º 1
0
    void changeState(SubState newState)
    {
        switch (newState)
        {
        case SubState.Patrol:

            StartCoroutine(aiUnit_.GetComponent <AIUnit>().patrol(patrolNodes));

            break;

        case SubState.Empty:

            Debug.Log("Is in empty State: Defend");
            StopAllCoroutines();
            aiUnit_.path_.Clear();

            break;

        case SubState.Fighting:

            if (aiUnit_.isFighting == false)
            {
                aiUnit_.path_.Clear();
                StartCoroutine(aiUnit_.GetComponent <AIUnit>().fight());
            }

            break;
        }
    }
Exemplo n.º 2
0
    // Changes from one state to another
    void changeState(SubState newState)
    {
        switch (newState)
        {
        case SubState.Capturing:
            if (!aiUnit_.hasFlag)
            {
                StopAllCoroutines();
                StartCoroutine(aiUnit_.GetComponent <AIUnit>().capturing());
            }
            else
            {
                subState = SubState.DeliverFlag;
            }

            break;

        case SubState.Empty:

            Debug.Log("Is in empty Capture");
            StopAllCoroutines();
            aiUnit_.path_.Clear();
            //restartCaptureState();

            break;


        case SubState.DeliverFlag:

            if (!aiUnit_.isDelivering)
            {
                aiUnit_.path_.Clear();

                Node startNode = aiUnit_.getClosestNode();
                aiUnit_.getNewPath(startNode, aiUnit_.deliveryNode);

                if (aiUnit_.path_.Count > 0)
                {
                    aiUnit_.isDelivering = true;
                    StartCoroutine(aiUnit_.GetComponent <AIUnit>().deliverFlag());
                }
            }

            break;

        case SubState.Fighting:

            if (!aiUnit_.hasFlag && aiUnit_.isFighting == false)
            {
                //aiUnit_.isFighting = true;
                StartCoroutine(aiUnit_.GetComponent <AIUnit>().fight());
            }

            break;
        }
    }
Exemplo n.º 3
0
    IEnumerator Go(Vector3 D, float V, Vector3 N)
    {
        float   targetDistance = Vector3.Distance(transform.position, D);
        float   lerp           = 0f;
        Vector3 startPosition  = transform.position;

        float stopDistance = targetDistance / 100f;

        while (lerp <= stopDistance)
        {
            lerp += V;
            transform.position = Vector3.Lerp(startPosition, startPosition + (MoveVector * 100f), lerp);

            yield return(null);
        }

        if (HitTarget != null)
        {
            if (HitTarget.health - DamageAmount <= 0)
            {
                Creator.GetComponent <UnitStats>().Kills++;
            }

            HitTarget.Damage(DamageAmount);
        }

        MakeDecal(D, N);

        Destroy(this.gameObject);
    }
    private void DoAttack(AIUnit unit)
    {
        unit.CDTimer += unit.DeltaT;
        if (unit.TargetPlayerHealth == null)
        {
            return;
        }

        if (Vector3.Distance(unit.transform.position, unit.TargetPlayerHealth.transform.position) < unit.AttackRange)
        {
            unit.WalkAnim = false;
            if (unit.CDTimer >= unit.AttackCD && unit.AttackEnemy == true)
            {
                if (unit.TargetPlayerHealth != null && unit.TargetPlayerHealth.MyHealth > 0)
                {
                    if (unit._MinionType == MinionType.Ghost && unit.TargetPlayerHealth != null)
                    {
                        unit.Agent.transform.LookAt(unit.TargetPlayerHealth.transform.position);
                        MinionRangeAttack Attack = unit.GetComponent <MinionRangeAttack>();
                        if (unit.TargetPlayerHealth != null)
                        {
                            unit.AnimController.SetTrigger("IsAttacking");
                            Attack.RangeAttack(unit.TargetPlayerHealth.transform.position);
                            unit.CDTimer = 0;
                        }
                    }

                    else if (unit._MinionType == MinionType.Golem && unit.TargetPlayerHealth != null && unit.CDTimer >= unit.AttackCD)
                    {
                        unit.CDTimer  = 0;
                        unit.WalkAnim = false;
                        unit.Agent.transform.LookAt(unit.TargetPlayerHealth.transform.position);
                        unit.AttackCount = (unit.AttackCount + 1) % 3;
                        unit.AnimController.SetInteger("AttackState", unit.AttackCount);
                        unit.AnimController.SetTrigger("IsAttacking");
                        unit.StartCoroutine(unit.SetAnimWalking());
                    }
                    else if (unit._MinionType == MinionType.Mummy && unit.TargetPlayerHealth != null)
                    {
                        unit.Agent.transform.LookAt(unit.TargetPlayerHealth.transform.position);

                        // Make a random attack animation
                        int randomAttack = Random.Range(1, 3);
                        unit.AnimController.SetInteger("AttackState", randomAttack);
                        unit.AnimController.SetTrigger("IsAttacking");

                        // unit.SendRPC_Damage();
                        unit.StartCoroutine(unit.SetAnimWalking());
                        unit.CDTimer = 0;
                    }
                }
                else
                {
                    unit.TargetPlayerHealth = null;
                }
            }
        }
    }
Exemplo n.º 5
0
    public void ExecuteAction(AIUnit u)
    {
        AttackHandler attackHandler = u.GetComponent <AttackHandler>();

        if (attackHandler && attackHandler.isAttacking)
        {
        }
        else
        {
            float performActionValue = Random.Range(0f, 1f);
            if (performActionValue >= dontPerformActionRange)
            {
                if (u.Movement != null)
                {
                    Vector2 newMovePoint = Random.insideUnitCircle * u.Character.lineOfSight;
                    Vector3 newPosition  = transform.position + new Vector3(newMovePoint.x, transform.position.y, newMovePoint.y);
                    u.Movement.Move(newPosition);
                    u.IsIdle = false;
                }
            }
        }
    }