// Respawn the virus around a circle with the radius of respawnRadius
    void Respawn()
    {
        if (hs && hs.IsDead())
        {
            return;
        }

        for (int i = 0; i < respawnCount; ++i)
        {
            GameObject newVirus =
                Instantiate(virusPrefab, transform.position, transform.rotation);
            if (fov)
            {
                newVirus.GetComponentInChildren <VirusPosReceiver>().transform.up = fov.facing;
            }
            newVirus.transform.parent = transform;

            ControlStatus cs = newVirus.GetComponentInChildren <ControlStatus> ();
            if (cs)
            {
                cs.Hacker = this.hacker;
                cs.Boss   = transform;
            }

            // stop the virus from changing its virusState until it is
            // reaching the spreadRadius
            VirusStateControl vsc = newVirus.GetComponentInChildren <VirusStateControl> ();
            vsc.enabled = false;
            StartCoroutine(EnableStateChange(newVirus.transform));
        }
//		if(virusPrefab == null || respawnCount == 0){
//			return;
//		}
//		float deltaAngle = 360f / respawnCount;
//		float curAngle = 0f;
//		for(int virusIndex = 0; virusIndex < respawnCount; virusIndex ++){
//			float dirx = Mathf.Cos (curAngle * Mathf.Deg2Rad);
//			float diry = Mathf.Sin (curAngle * Mathf.Deg2Rad);
//			Vector3 virusDir = new Vector3 (dirx, diry, 0f);
//			virusDir.Normalize ();
//
//			Vector3 virusPosOffset = virusDir * respawnRadius;
//			Vector3 virusNewPos = transform.position + virusPosOffset;
//
//			Quaternion newRot = new Quaternion();
//			newRot.eulerAngles = new Vector3 (0f, 0f, curAngle - 90f);
//			// instantiate the virus
//			GameObject newVirus = Instantiate (virusPrefab, virusNewPos, newRot);
//			newVirus.transform.SetParent (this.transform);
//
//			curAngle += deltaAngle;
//		}
//		currentCount += respawnCount;
    }
    /* Paralyze
     * stop the enemy from chasing the target
     * in a given amount of time (seconds)
     */
    public void Paralyze(float time)
    {
        // set the paralyze time in VirusStateControl
        // and change the state to paralyze
        VirusStateControl sc = GetComponent <VirusStateControl> ();

        if (sc)
        {
            sc.paralyzeTime = time;
            sc.virusState   = VirusStateControl.VirusState.Paralyze;
        }
    }
    IEnumerator EnableStateChange(Transform virusTrans)
    {
        yield return(new WaitUntil(() => { return ReachingSpreadRadius(virusTrans); }));

        if (virusTrans)
        {
            VirusStateControl vsc = virusTrans.GetComponentInChildren <VirusStateControl> ();
            if (vsc)
            {
                vsc.enabled = true;
            }
        }
    }
Beispiel #4
0
    void ReleaseIdleVirus()
    {
        // release all idle virus
        // get all childs which is a virus
        foreach (Transform child in transform)
        {
            // does if have a objectIdentity and the identity is virus?
            ObjectIdentity oi = child.GetComponent <ObjectIdentity> ();
            if (oi && oi.objType == ObjectType.Virus)
            {
                // is the virus Idle?
                VirusStateControl sc = child.GetComponent <VirusStateControl> ();
                if (sc)
                {
                    if (sc.virusState == VirusStateControl.VirusState.Idle)
                    {
                        // change the state to "chase"
                        sc.OnChaseStart += SetReleaseParent;
                        sc.OnChaseStart += DisableLineRenderer;

                        sc.virusState = VirusStateControl.VirusState.Chase;

                        // WTF? hack to stop virus from lingering on the wall
                        HurtAndDamage hd = sc.GetComponent <HurtAndDamage> ();
                        if (hd)
                        {
                            hd.instantKillSelf = true;
                        }
                        ChaseTarget ct = sc.GetComponent <ChaseTarget> ();
                        ct.moveSpeed = ct.moveSpeed * moveSpeedFactor;

                        sc.OnChaseStart -= SetReleaseParent;
                        sc.OnChaseStart -= DisableLineRenderer;
                    }
                }
            }
        }
    }
Beispiel #5
0
    // Update is called once per frame
    void Update()
    {
        if (fov)
        {
            facing = fov.facing;
        }


        virusList.Clear();
        // get all childs which is a virus
        foreach (Transform child in transform)
        {
            // does if have a objectIdentity and the identity is virus?
            ObjectIdentity oi = child.GetComponentInChildren <ObjectIdentity> ();
            if (oi && oi.objType == ObjectType.Virus)
            {
                // append it to the virus list
                // only append idle and controlling
                VirusStateControl sc = oi.transform.GetComponent <VirusStateControl> ();
                ControlStatus     cs = oi.transform.GetComponent <ControlStatus> ();
                bool controlling     = (cs.controller != Controller.None);
                bool nowIdle         = (sc.virusState == VirusStateControl.VirusState.Idle);

                if (sc && controlling && nowIdle)
                {
                    virusList.Add(oi.transform);
                }
            }
        }
        virusCount = virusList.Count;
        if (virusCount == 0)
        {
            return;
        }
        // set the facing vector
        if (facing == Vector3.zero)
        {
            facing = transform.up;
        }
        facing.Normalize();

        // set the pos and rotation for each enemy
        float startAngle = 0f;

        if (virusCount != 1)
        {
            startAngle = -intervalAngle * (virusCount - 1) / 2.0f;
        }

        // initialize rotCursor
        Quaternion rotCursor = Quaternion.FromToRotation(Vector3.up, facing);

        rotCursor *= Quaternion.Euler(0f, 0f, startAngle);

        //Debug.Log (rotCursor.eulerAngles);

        foreach (Transform virus in virusList)
        {
            VirusPosReceiver receiver = virus.GetComponent <VirusPosReceiver> ();
            if (receiver)
            {
                // set the desiredRotation
                receiver.desiredRot = rotCursor;
                // set the desiredPosition
                Vector3 dirToVirus = rotCursor * Vector3.up;
                dirToVirus.Normalize();
                Vector3 newPos = transform.position + dirToVirus * spreadRadius;
                //Debug.Log (newPos);
                receiver.desiredPos = newPos;



                // set child virus speed
                receiver.moveSpeed = moveSpeed;
                receiver.rotSpeed  = rotSpeed;
            }

            rotCursor = Quaternion.AngleAxis(intervalAngle, Vector3.forward) * rotCursor;
        }
    }