public void SetBlackboard(WormBlackboard bb)
 {
     this.bb                 = bb;
     head                    = bb.head;
     currentDamage           = 0;
     currentDamageWrongColor = 0;
 }
Beispiel #2
0
    void Awake()
    {
        navMeshLayersDistance = new Vector3(0, WormBlackboard.NAVMESH_LAYER_HEIGHT, 0);

        headTrf = transform.FindDeepChild("Head");
        head    = headTrf.GetComponent <WormAIBehaviour>();
        head.SetBlackboard(this);

        bodySegmentsGroupTrf   = transform.FindDeepChild("BodyParts");
        bodySegmentsTrf        = new Transform[bodyParts];
        bodySegmentControllers = new WormBodySegmentController[bodyParts];

        for (int i = 0; i < bodySegmentsTrf.Length; ++i)
        {
            GameObject bodySegment = Instantiate(bodyPrefab, initialPosition, Quaternion.identity) as GameObject;
            bodySegmentsTrf[i] = bodySegment.transform;
            bodySegmentsTrf[i].SetParent(bodySegmentsGroupTrf);
            bodySegmentControllers[i] = bodySegment.GetComponent <WormBodySegmentController>();
            bodySegmentControllers[i].SetBlackboard(this);
        }

        junctionsGroupTrf = transform.FindDeepChild("Junctions");

        junctionsTrf        = new Transform[bodyParts + 1];
        junctionControllers = new WormJunctionController[bodyParts + 1];
        for (int i = 0; i < junctionsTrf.Length; ++i)
        {
            GameObject junction = Instantiate(junctionPrefab, initialPosition, Quaternion.identity) as GameObject;
            junctionsTrf[i] = junction.transform;
            junctionsTrf[i].SetParent(junctionsGroupTrf);
            junctionControllers[i] = junction.GetComponent <WormJunctionController>();
        }

        tailTrf        = transform.FindDeepChild("Tail");
        tailController = tailTrf.GetComponent <WormTailController>();
        tailController.SetBlackboard(this);

        GameObject bezierContainer = Instantiate(bezierCurvesPrefab, Vector3.zero, Quaternion.identity) as GameObject;
        Transform  bezierTrf       = bezierContainer.transform;

        localEnterBezier11     = bezierTrf.FindDeepChild("Enter11").position;
        localEnterBezier12     = bezierTrf.FindDeepChild("Enter12").position;
        localEnterBezierMiddle = bezierTrf.FindDeepChild("EnterMiddle").position;
        localEnterBezier21     = bezierTrf.FindDeepChild("Enter21").position;
        localEnterBezier22     = bezierTrf.FindDeepChild("Enter22").position;

        localExitBezier11     = bezierTrf.FindDeepChild("Exit11").position;
        localExitBezier12     = bezierTrf.FindDeepChild("Exit12").position;
        localExitBezierMiddle = bezierTrf.FindDeepChild("ExitMiddle").position;
        localExitBezier21     = bezierTrf.FindDeepChild("Exit21").position;
        localExitBezier22     = bezierTrf.FindDeepChild("Exit22").position;

        sinDistanceFactor = 360 / WanderingSettingsPhase.sinLongitude;
        sinTimeFactor     = 360 / WanderingSettingsPhase.sinCycleDuration;

        ResetValues();
        SetInitialBodyWayPoints();
    }
    void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Enemy")
        {
            EnemyBaseAIBehaviour enemy = other.GetComponent <EnemyBaseAIBehaviour>();

            //Mosquito has the collider in a children object so we need to search for script in parent
            if (enemy == null)
            {
                enemy = other.GetComponentInParent <EnemyBaseAIBehaviour>();
            }

            if (enemy != null)
            {
                bb.enemiesInRange.Add(enemy);
            }
        }
        else if (other.tag == "Shot")
        {
            EnemyShotControllerBase shot = other.GetComponent <EnemyShotControllerBase>();

            if (shot != null)
            {
                bb.shotsInRange.Add(shot);
            }
        }
        else if (other.tag == "WormHead")
        {
            WormAIBehaviour worm = other.GetComponent <WormAIBehaviour>();

            if (worm != null)
            {
                bb.worm = worm;
                worm.SpecialAttackInRange();
            }
        }
        else if (other.tag == "Vortex")
        {
            VortexController vortex = other.GetComponent <VortexController>();

            if (vortex != null)
            {
                bb.vortexInRange.Add(vortex);
            }
        }
        else if (other.tag == "Turret")
        {
            TurretAIBehaviour turret = other.GetComponent <TurretAIBehaviour>();

            if (turret != null)
            {
                bb.turretsInRange.Add(turret);
            }
        }
    }
    //This variables have to be reset every spawn
    public void ResetLifeVariables()
    {
        alive   = true;
        playing = true;

        animationEnded = false;
        isGrounded     = true;
        falling        = false;

        currentHealth = player.maxHealth;
        currentEnergy = 0;
        player.CheckEnergyFullPS();
        isInvulnerable = false;
        contactFlag    = false;

        horizontalDirection    = Vector3.zero;
        currentSpeed           = 0f;
        isAffectedByContact    = false;
        isContactCooldown      = false;
        updateVerticalPosition = true;
        currentGravity         = Physics.gravity.y;
        //fastMovementCharge = 0f;

        canShoot  = true;
        firstShot = true;
        nextFire  = 0;

        enemiesInRange.Clear();
        shotsInRange.Clear();
        vortexInRange.Clear();
        turretsInRange.Clear();
        worm = null;
        specialAttackDetector.SetActive(false);

        capacitor = null;
        device    = null;
        hexagons.Clear();
        infectionOrigin  = Vector3.zero;
        infectionForces  = Vector2.zero;
        destinationPoint = Vector3.zero;
    }
 public WormAIBaseState(WormBlackboard bb)
 {
     this.bb = bb;
     head    = bb.head;
     headTrf = bb.headTrf;
 }
    void OnCollisionEnter(Collision collision)
    {
        //Stop shot
        rigidBody.velocity = Vector3.zero;
        projectileParticle.SetActive(false);

        impactParticle.GetComponent <AudioSource>().clip = wrongImpact;

        if (collision.collider.tag == "Enemy")
        {
            EnemyBaseAIBehaviour enemy = collision.collider.GetComponent <EnemyBaseAIBehaviour>();
            if (enemy == null)
            {
                enemy = collision.collider.GetComponentInParent <EnemyBaseAIBehaviour>();
            }

            if (enemy != null)
            {
                if (enemy.color == color)
                {
                    impactParticle.GetComponent <AudioSource>().clip = goodImpact;
                }

                enemy.ImpactedByShot(color, damage, transform.forward * forceMultiplier, player);
            }
        }
        else if (collision.collider.tag == "Vortex")
        {
            VortexController vortex = collision.collider.GetComponent <VortexController>();
            if (vortex != null)
            {
                vortex.ImpactedByShot(color, damage, player);
                if (vortex.Active)
                {
                    impactParticle.GetComponent <AudioSource>().clip = goodImpact;
                }
                else
                {
                    impactParticle.GetComponent <AudioSource>().clip = wrongImpact;
                }
            }
        }
        else if (collision.collider.tag == "Barrel")
        {
            CapacitorImpacted barrel = collision.collider.GetComponent <CapacitorImpacted>();
            if (barrel != null)
            {
                barrel.controller.ImpactedByShot(color, player);
            }

            impactParticle.GetComponent <AudioSource>().clip = goodImpact;
        }
        else if (collision.collider.tag == "WormBody")
        {
            WormBodySegmentController worm = collision.collider.GetComponent <WormBodySegmentController>();
            if (worm != null)
            {
                if (worm.Color == color)
                {
                    impactParticle.GetComponent <AudioSource>().clip = goodImpact;
                }

                worm.ImpactedByShot(color, damage, player);
            }
        }
        else if (collision.collider.tag == "WormHead")
        {
            WormAIBehaviour worm = collision.collider.GetComponent <WormAIBehaviour>();
            if (worm != null)
            {
                worm.ImpactedByShot(color, damage, player);
            }

            impactParticle.GetComponent <AudioSource>().clip = goodImpact;
        }
        else if (collision.collider.tag == "Hexagon")
        {
            HexagonController hexagon = collision.collider.GetComponentInParent <HexagonController>();
            if (hexagon != null)
            {
                hexagon.ImpactedByShot(player);
                if (hexagon.HasActiveTurret())
                {
                    impactParticle.GetComponent <AudioSource>().clip = goodImpact;
                }
                else
                {
                    impactParticle.GetComponent <AudioSource>().clip = wrongImpact;
                }
            }
        }

        if (collision.contacts.Length > 0)
        {
            impactParticle.transform.rotation = Quaternion.FromToRotation(Vector3.up, collision.contacts[0].normal);
        }
        impactParticle.SetActive(true);

        shotCollider.enabled = false;
        //We let the impactParticle do its job
        StartCoroutine(WaitAndReturnToPool());
    }