/// <summary>
    /// Create and register a new location
    /// </summary>
    /// <param name="center"></param>
    /// <param name="radius"></param>
    public GameObject CreateLocation(Vector3 center, float radius)
    {
        //first, pull the genaric LocationSubject from the masterSubjectList and create prefab
        LocationSubject locFromMaster     = masterSubjectList.GetSubject(DbIds.Location) as LocationSubject;
        GameObject      newLocationObject = Instantiate(locFromMaster.Prefab, center, Quaternion.identity);

        newLocationObject.transform.localScale = new Vector3(radius * 2, 0.1f, radius * 2);

        //grab our connected script and create a fresh LocationSubject
        LocationObjectScript script        = newLocationObject.GetComponent <LocationObjectScript>() as LocationObjectScript;
        LocationSubject      newLocSubject = new LocationSubject();

        //now lets set the values to make a new locationSubject card
        newLocSubject.Name        = "Location " + Time.time;
        newLocSubject.Description = "New Location " + Time.time;
        newLocSubject.Radius      = radius;
        newLocSubject.Coordinates = center;
        newLocSubject.Layer       = 1;

        //add the next id available
        newLocSubject.SubjectID = masterSubjectList.GetNextID();
        script.InitializeFromSubject(masterSubjectList, newLocSubject);

        //now add our card to the master list
        if (!masterSubjectList.AddSubject(newLocSubject))
        {
            Debug.Log("FAIL ADD");
        }
        //store to the script attached to our new object
        return(newLocationObject);
    }
    /// <summary>
    /// !!!  FOR TESTING ONLY DO NOT USE !!! <para/>
    /// Place a new location in the world and add it to the MasterSubjectList.
    /// </summary>
    /// <param name="newPosition">The center point of the new location</param>
    /// <param name="newRadius">The radius of the new location.</param>
    public GameObject T_PlaceLocation(Vector3 newPosition, float newRadius)
    {
        LocationSubject newLocation = new LocationSubject(masterSubjectList.GetSubject(DbIds.Location) as LocationSubject);

        newLocation.Name        = "Location " + Time.time;
        newLocation.Description = "New Location " + Time.time;
        newLocation.Radius      = newRadius;
        newLocation.Coordinates = newPosition;
        newLocation.Icon        = null;
        newLocation.Layer       = 1;
        //add the next id available
        newLocation.SubjectID = masterSubjectList.GetNextID();

        GameObject           location1 = Instantiate(newLocation.Prefab, newPosition, Quaternion.identity);
        LocationObjectScript locScript = location1.GetComponent <LocationObjectScript>();

        locScript.InitializeFromSubject(masterSubjectList, newLocation);
        locScript.Relocate(newLocation);

        if (!masterSubjectList.AddSubject(newLocation))
        {
            Debug.Log("FAIL ADD");
        }
        return(location1);
    }
    public void TestSet2()
    {
        // testing location waypoint generation
        float                testLocationRadius = 6.0f;
        float                testSightRadius    = 2.0f;
        Vector3              loc1Offset         = new Vector3(-testLocationRadius - (2 * testSightRadius), 0, 0);
        Vector3              loc2Offset         = new Vector3(0, 0, -testLocationRadius - (2 * testSightRadius));
        GameObject           loc1      = T_PlaceLocation(loc1Offset, testLocationRadius);
        LocationObjectScript locScript = loc1.GetComponent <LocationObjectScript>();
        LocationSubject      locSub    = locScript.Subject as LocationSubject;

        Vector3[] locs = locSub.GetAreaWaypoints(testSightRadius, 1);
        if (locs.Length > 0)
        {
            for (int i = 0; i <= locs.Length - 1; i++)
            {
                //Debug.Log(i + " : " + locs[i].x + "," + locs[i].y + "," + locs[i].z + "\n");
                T_PlaceLocation(locs[i], testSightRadius);
            }
        }
        else
        {
            Debug.Log("  -- loc1 !  -- No waypoints generated.");
        }

        GameObject           loc2       = T_PlaceLocation(loc2Offset, testLocationRadius);
        LocationObjectScript loc2Script = loc2.GetComponent <LocationObjectScript>();
        LocationSubject      loc2Sub    = loc2Script.Subject as LocationSubject;

        Vector3[] locs2 = loc2Sub.GetAreaWaypoints(testSightRadius);
        if (locs2.Length > 0)
        {
            for (int i = 0; i <= locs2.Length - 1; i++)
            {
                //Debug.Log(i + " : " + locs[i].x + "," + locs[i].y + "," + locs[i].z + "\n");
                T_PlaceLocation(locs2[i], testSightRadius);
            }
        }
        else
        {
            Debug.Log(" -- loc2 !  -- No waypoints generated.");
        }
    }
예제 #4
0
    /// <summary>
    /// Add objectToInspect to the NPC's Memories.
    /// </summary>
    /// <param name="objectToInspect">The GameObject to learn about.</param>
    internal void Inspect(GameObject objectToInspect)
    {
        // inspect the object, add to memories.
        SubjectObjectScript inspectObjectScript = objectToInspect.GetComponent <SubjectObjectScript>();

        if (inspectObjectScript.GetType() == typeof(LocationObjectScript))
        {
            LocationObjectScript locObjScript = inspectObjectScript as LocationObjectScript;
            //only add location to memory if all waypoints are explored
            if (objectScript.IsCurrentLocationExplored)
            {
                // if it's in the unexploredLocations list, remove it.
                unexploredLocations.Remove(locObjScript.Subject as LocationSubject);
                // if it's in the reExploreLocations list, remove it.
                reExploreLocations.Remove(locObjScript.Subject as LocationSubject);
            }
        }
        else
        {
            inspectObjectScript.Subject.TeachNpc(this);
        }
    }
예제 #5
0
    // Update is called once per frame
    void Update()
    {
        if (!npcCharacter.IsDead)
        {
            MetabolizeTickCounter += Time.deltaTime;
            if (MetabolizeTickCounter >= npcCharacter.Definition.MetabolizeInterval)
            {
                int healthChange = npcCharacter.Metabolize();
                MetabolizeTickCounter -= npcCharacter.Definition.MetabolizeInterval;
                if (healthChange > 0)
                {
                    GameObject.FindGameObjectWithTag("GameController").GetComponent <PlacementControllerScript>().PopMessage(healthChange.ToString(), gameObject.transform.position, 2);
                }
                else if (healthChange < 0)
                {
                    GameObject.FindGameObjectWithTag("GameController").GetComponent <PlacementControllerScript>().PopMessage(healthChange.ToString(), gameObject.transform.position, 0);
                }
            }

            AiCoreTickCounter += Time.deltaTime;
            if (AiCoreTickCounter > AiTickRate)
            {
                npcCharacter.AiCoreProcess();
                AiCoreTickCounter -= AiTickRate;
            }

            // ===  Movement ===
            if (destination != null) // traveling to a new location
            {
                if (destinationWayPoints.Length != 0)
                {
                    float distance = Vector3.Distance(destinationWayPoints[currentWaypointIndex], transform.position);
                    if (distance > (npcCharacter.SightRangeNear))
                    {
                        MoveTowardsPoint(destinationWayPoints[currentWaypointIndex], npcCharacter.MoveSpeed);
                    }
                    else if (distance > 0.25)
                    {
                        MoveTowardsPoint(destinationWayPoints[currentWaypointIndex], npcCharacter.MoveSpeed * 0.85f);
                    }
                    else
                    {
                        if (currentWaypointIndex == destinationWayPoints.GetUpperBound(0))
                        {
                            // we have arrived at the final waypoint for this location
                            isCurrentLocationExplored = true;
                            npcCharacter.AddSearchedLocation(destination.SubjectID);
                            // remember the location now that it is explored fully
                            UnityEngine.Object[] scripts = FindObjectsOfType(typeof(LocationObjectScript));
                            LocationObjectScript inspectLocationScript = scripts.Single(o =>
                                                                                        (o as LocationObjectScript).Subject.SubjectID == destination.SubjectID)
                                                                         as LocationObjectScript;
                            inspectLocationScript.TeachNpc(npcCharacter);

                            npcCharacter.Inspect(inspectLocationScript.gameObject);

                            destinationWayPoints = new Vector3[0];
                            destination          = null;
                        }
                        else
                        {
                            currentWaypointIndex++;
                        }
                    }
                }
            }
            else if (chaseTarget != null) // chase the target
            {
                float distance = Vector3.Distance(chaseTarget.transform.position, transform.position);
                if (distance > 0.75)
                {
                    MoveTowardsPoint(chaseTarget.transform.position, npcCharacter.MoveSpeed);
                }
                else
                {
                    Vector3 targetDir = chaseTarget.transform.position - transform.position;
                    transform.rotation = Quaternion.LookRotation(targetDir);
                    chaseTarget        = null;
                }
            }
        }
        else // this animal is dead
        {
            if (!isDead) //newly dead
            {
                Inventory.Add(new InventoryItem(DbIds.Meat, 5));
                isDead    = true;
                decaytime = 20.0f;
            }
            decaytime -= Time.deltaTime;
            UpdateDeadnessColor();
            if (decaytime < 0)
            {
                Destroy(this.gameObject);
            }
        }

        // Debug: near vision range
        DrawDebugCircle(transform.position, npcCharacter.SightRangeNear, 20, new Color(0, 0, 1, 0.5f));
        // Debug: far vision range
        DrawDebugCircle(transform.position, npcCharacter.SightRangeFar, 20, new Color(0, 0, 0, 0.3f));
    }