Ejemplo n.º 1
0
    private bool ResolveBoolean(string[] boolean)
    {
        // Ensure proper length
        //if(boolean.Length >= 3) return false;

        // Comparing health of the current target
        if (boolean[0].Contains("targethp"))
        {
            // Set the values on the left and right sides of the comparison operator
            int targetHP = targeting.GetCurrentTarget().GetComponent <Health>().GetHealth();
            int compVal  = 0;
            int.TryParse(boolean[2], out compVal);

            // Determine and perform the comparison operator
            if (boolean[1].Contains("<="))
            {
                return(targetHP <= compVal);
            }
            else if (boolean[1].Contains(">="))
            {
                return(targetHP >= compVal);
            }
            else if (boolean[1].Contains("!="))
            {
                return(targetHP != compVal);
            }
            else if (boolean[1].Contains("<"))
            {
                return(targetHP < compVal);
            }
            else if (boolean[1].Contains(">"))
            {
                return(targetHP > compVal);
            }
            else if (boolean[1].Contains("=") || boolean[1].Contains("=="))
            {
                return(targetHP == compVal);
            }
        }
        // Comparing health of this NPC
        else if (boolean[0].Contains("npchp"))
        {
            // Set the values on the left and right sides of the comparison operator
            int npcHP   = hp.GetHealth();
            int compVal = 0;
            int.TryParse(boolean[2], out compVal);

            // Determine and perform the comparison operator
            if (boolean[1].Contains("<="))
            {
                return(npcHP <= compVal);
            }
            else if (boolean[1].Contains(">="))
            {
                return(npcHP >= compVal);
            }
            else if (boolean[1].Contains("!="))
            {
                return(npcHP != compVal);
            }
            else if (boolean[1].Contains("<"))
            {
                return(npcHP < compVal);
            }
            else if (boolean[1].Contains(">"))
            {
                return(npcHP > compVal);
            }
            else if (boolean[1].Contains("=") || boolean[1].Contains("=="))
            {
                return(npcHP == compVal);
            }
        }
        // Comparing the distance to the current target
        else if (boolean[0].Contains("distancetotarget") || boolean[0].Contains("disttotarget"))
        {
            // Set the values on the left and right sides of the comparison operator
            float targetDist = targeting.DistanceToCurrentTarget();
            float compVal    = 0f;
            float.TryParse(boolean[2], out compVal);

            // Determine and perform the comparison operator
            if (boolean[1].Contains("<="))
            {
                return(targetDist <= compVal);
            }
            else if (boolean[1].Contains(">="))
            {
                return(targetDist >= compVal);
            }
            else if (boolean[1].Contains("!="))
            {
                return(targetDist != compVal);
            }
            else if (boolean[1].Contains("<"))
            {
                return(targetDist < compVal);
            }
            else if (boolean[1].Contains(">"))
            {
                return(targetDist > compVal);
            }
            else if (boolean[1].Contains("=") || boolean[1].Contains("=="))
            {
                return(targetDist == compVal);
            }
        }
        // Comparing the distance remaining on the current path
        else if (boolean[0].Contains("pathdistance") || boolean[0].Contains("pathdist"))
        {
            // Set the values on the left and right sides of the comparison operator
            float targetDist = move.CalculatePathLength();
            float compVal    = 0f;
            float.TryParse(boolean[2], out compVal);
            // Determine and perform the comparison operator
            if (boolean[1].Contains("<="))
            {
                return(targetDist <= compVal);
            }
            else if (boolean[1].Contains(">="))
            {
                return(targetDist >= compVal);
            }
            else if (boolean[1].Contains("!="))
            {
                return(targetDist != compVal);
            }
            else if (boolean[1].Contains("<"))
            {
                return(targetDist < compVal);
            }
            else if (boolean[1].Contains(">"))
            {
                return(targetDist > compVal);
            }
            else if (boolean[1].Contains("=") || boolean[1].Contains("=="))
            {
                return(targetDist == compVal);
            }
        }
        // Comparing the distance to a given firepoint on the target
        else if (boolean[0].Contains("distancetofirepoint") || boolean[0].Contains("disttofirepoint"))
        {
            // Get the index of the firepoint to compare
            int index = 0;
            int.TryParse(boolean[1], out index);
            // Set the values on the left and right sides of the comparison operator
            float targetDist = Vector3.Distance(shoot.GetFirePoint(index).position.WithY(0f), targeting.GetCurrentTarget().transform.position.WithY(0f));
            float compVal    = 0f;
            float.TryParse(boolean[3], out compVal);

            // Determine and perform the comparison operator
            if (boolean[2].Contains("<="))
            {
                return(targetDist <= compVal);
            }
            else if (boolean[2].Contains(">="))
            {
                return(targetDist >= compVal);
            }
            else if (boolean[2].Contains("!="))
            {
                return(targetDist != compVal);
            }
            else if (boolean[2].Contains("<"))
            {
                return(targetDist < compVal);
            }
            else if (boolean[2].Contains(">"))
            {
                return(targetDist > compVal);
            }
            else if (boolean[2].Contains("=") || boolean[2].Contains("=="))
            {
                return(targetDist == compVal);
            }
        }
        // Comparing amount of shots left in the current burst
        else if (boolean[0].Contains("shots"))
        {
            // Get the amount of bullets we're comparing
            int shots   = shoot.GetRemainingBullets();
            int compVal = 0;
            int.TryParse(boolean[2], out compVal);


            // Determine and perform the comparison operator
            if (boolean[1].Contains("<="))
            {
                return(shots <= compVal);
            }
            else if (boolean[1].Contains(">="))
            {
                return(shots >= compVal);
            }
            else if (boolean[1].Contains("!="))
            {
                return(shots != compVal);
            }
            else if (boolean[1].Contains("<"))
            {
                return(shots < compVal);
            }
            else if (boolean[1].Contains(">"))
            {
                return(shots > compVal);
            }
            else if (boolean[1].Contains("=") || boolean[2].Contains("=="))
            {
                return(shots == compVal);
            }
        }
        // Is the NPC in a conversation
        else if (boolean[0].Contains("inconversation"))
        {
            return(talk.isInConversation());
        }
        // Is the NPC not in a conversation
        else if (boolean[0].Contains("notinconversation"))
        {
            return(!talk.isInConversation());
        }
        // Can the NPC see its target
        else if (boolean[0].Contains("canseetarget"))
        {
            RaycastHit rch;
            Vector3    rayDir = (targeting.GetCurrentTarget().transform.position.WithY(shoot.GetFirePoint(-1).position.y)
                                 - shoot.GetFirePoint(-1).position).normalized;
            // Raycast from the current firepoint (the last one fired)
            Physics.Raycast(shoot.GetFirePoint(-1).position, rayDir, out rch, 100f, Physics.DefaultRaycastLayers, QueryTriggerInteraction.Ignore);
            // True if the current target has a collider and the collider was hit
            if (targeting.GetCurrentTarget().GetComponent <Collider>() && rch.transform == targeting.GetCurrentTarget().transform)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        // Can the NPC NOT see its target
        else if (boolean[0].Contains("cannotseetarget"))
        {
            RaycastHit rch;
            Vector3    rayDir = (targeting.GetCurrentTarget().transform.position.WithY(shoot.GetFirePoint(-1).position.y)
                                 - shoot.GetFirePoint(-1).position).normalized;
            // Raycast from the current firepoint (the last one fired)
            Physics.Raycast(shoot.GetFirePoint(-1).position, rayDir, out rch, 100f, Physics.DefaultRaycastLayers, QueryTriggerInteraction.Ignore);
            // False if the current target has a collider and the collider was hit
            if (targeting.GetCurrentTarget().GetComponent <Collider>() && rch.transform == targeting.GetCurrentTarget().transform)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }

        // Given boolean statement not supported
        // Skip to the endif
        if (debug)
        {
            Debug.Log("Boolean statement /'" + actions[currentAction] + "/' not supported.");
        }
        return(false);
    }
Ejemplo n.º 2
0
 private void SetTalking()
 {
     anim.SetBool("talking", talk.isInConversation());
 }