Beispiel #1
0
    /// <summary>
    /// Copy an existing AnimalSubject.
    /// </summary>
    public override Subject Copy()
    {
        AnimalSubject newAnimalSubject = new AnimalSubject();

        newAnimalSubject.subjectID       = subjectID;
        newAnimalSubject.name            = name;
        newAnimalSubject.description     = description;
        newAnimalSubject.icon            = icon;
        newAnimalSubject.prefab          = prefab;
        newAnimalSubject.relatedSubjects = relatedSubjects;

        newAnimalSubject.maxGrowth     = maxGrowth;
        newAnimalSubject.growthTime    = growthTime;
        newAnimalSubject.matureTime    = matureTime;
        newAnimalSubject.inventorySize = inventorySize;
        newAnimalSubject.lootID        = lootID;
        newAnimalSubject.definition    = new NpcDefinition(definition);
        return(newAnimalSubject);
    }
Beispiel #2
0
 /// <summary>
 /// Initialize a new NpcCharacter.
 /// </summary>
 /// <param name="ParentObject">The in-game object that represents this NPC.</param>
 /// <param name="MasterSubjectListRef">A reference to the main MasterSubjectList.</param>
 /// <param name="BasedOnSubject">Subject's NpcDefinition will define the character's initial resource pools, thresholds for fulfilling basic needs, and memories.</param>
 public NpcCore(AnimalObjectScript ParentObjectScript, MasterSubjectList MasterSubjectListRef, Subject BasedOnSubject)
 {
     db = MasterSubjectListRef;
     if (BasedOnSubject is AnimalSubject)
     {
         objectScript = ParentObjectScript;
         AnimalSubject animalSubject = BasedOnSubject as AnimalSubject;
         definition          = animalSubject.Definition;
         subjectID           = animalSubject.SubjectID;
         health              = definition.HealthMax;
         food                = definition.FoodMax;
         safety              = definition.SafetyHigh;
         status              = new NpcStatus();
         drivers             = new NpcDriversList();
         unexploredLocations = new List <LocationSubject>();
         searchedObjects     = new List <int>();
         searchedLocations   = new List <int>();
         reExploreLocations  = new List <LocationSubject>();
         SetFoodPreference();
     }
 }
    // Update is called once per frame
    void Update()
    {
        // ------------------------------------------------------------------------
        // ------------------------ START CAMERA MOVEMENT -------------------------
        // ------------------------------------------------------------------------
        if (lastSelector != null)
        {
            cameraDestination = new Vector3(lastSelector.transform.position.x,
                                            cameraDestination.y,
                                            lastSelector.transform.position.z);
        }
        else if (Input.GetMouseButton(2))
        {
            // panning camera
            float mouseY = Input.GetAxis("Mouse Y");
            if (mouseY != 0)
            {
                cameraDestination = new Vector3(cameraDestination.x,
                                                cameraDestination.y,
                                                Camera.main.transform.position.z + mouseY * (cameraDestination.y / 25));
            }
            float mouseX = Input.GetAxis("Mouse X");
            if (mouseX != 0)
            {
                cameraDestination = new Vector3(Camera.main.transform.position.x + mouseX * (cameraDestination.y / 25),
                                                cameraDestination.y,
                                                cameraDestination.z);
            }
        }
        float mouseWheelDelta = Input.GetAxis("Mouse ScrollWheel");

        if (mouseWheelDelta != 0)
        {
            Vector3 camPosition = Camera.main.transform.position;
            cameraDestination = new Vector3(camPosition.x,
                                            camPosition.y - mouseWheelDelta * (camPosition.y),
                                            Camera.main.transform.position.z);
        }
        if (Vector3.Distance(Camera.main.transform.position, cameraDestination) > 0.1f)
        {
            Camera.main.transform.position = Vector3.Slerp(Camera.main.transform.position, cameraDestination, Time.deltaTime * 20.0f);
        }
        // ------------------------------------------------------------------------
        // ------------------------ END CAMERA MOVEMENT ---------------------------
        // ------------------------------------------------------------------------

        if ((lastSelector != null) && (lastSelector.transform.parent != null))
        {
            SubjectObjectScript script = lastSelector.transform.parent.GetComponent <SubjectObjectScript>() as SubjectObjectScript;
            _ID.text          = "ID: <b>" + script.Subject.SubjectID.ToString() + "</b>";
            _Name.text        = "Name: <b>" + script.Subject.Name.ToString() + "</b>";
            _Description.text = "Desc: <b>" + script.Subject.Description.ToString() + "</b>";

            testPanel.SetActive(true);
            PlantSubject plantSub = script.Subject as PlantSubject;
            if (plantSub != null)
            {
                PlantObjectScript plantScript    = script as PlantObjectScript;
                Subject           produceSubject = masterSubjectList.GetSubject(plantSub.ProduceID);
                float             maturePercent  = Mathf.Min(plantScript.CurrentGrowth / plantSub.MatureGrowth, 1.0f);
                plantPanel.SetActive(true);
                animalPanel.SetActive(false);
                locationPanel.SetActive(false);
                _Produce.text   = "Produce: <b>" + plantSub.ProduceID.ToString() + " - " + produceSubject.Name.ToString() + "</b>";
                _Growth.text    = "Growth: <b>" + plantScript.CurrentGrowth.ToString() + " / " + plantSub.MaxGrowth.ToString() + "</b>";
                _Maturity.text  = "Maturity: <b>" + maturePercent.ToString() + "</b>";
                _Inventory.text = "Inventory: <b>" + plantScript.InventoryPercent().ToString() + "</b>";
            }
            else
            {
                AnimalSubject animalSub = script.Subject as AnimalSubject;
                if (animalSub != null)
                {
                    animalPanel.SetActive(true);
                    plantPanel.SetActive(false);
                    locationPanel.SetActive(false);
                    AnimalObjectScript animalScript = script as AnimalObjectScript;
                    _Health.text = "Health: <b>" + animalScript.GetHealth().ToString() + "</b>";
                    _Safety.text = "Safety: <b>" + animalScript.GetSafety().ToString() + "</b>";
                    _Food.text   = "Food: <b>" + animalScript.GetFood().ToString() + "</b>";
                }
                else
                {
                    LocationSubject locationSub = script.Subject as LocationSubject;
                    if (locationSub != null)
                    {
                        locationPanel.SetActive(true);
                        plantPanel.SetActive(false);
                        animalPanel.SetActive(false);
                        _Center.text = "Center: <b>" + locationSub.Coordinates.ToString() + "</b>";
                        _Radius.text = "Radius: <b>" + locationSub.Radius.ToString() + "</b>";
                    }
                    else
                    {
                        locationPanel.SetActive(false);
                        plantPanel.SetActive(false);
                        animalPanel.SetActive(false);
                    }
                }
            }
        }
        else
        {
            //testPanel.SetActive(false);
        }

        //Place or use tool
        if (placeID < 1)
        {
            if (placeID < -1) //placeID == -2
            {
                if (!IsOverMenu() && (Input.GetMouseButtonDown(0)))
                {
                    centerPosition = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.transform.position.y));
                    SelectAtPosition(centerPosition, 0.4f);
                }
            }
            else if (placeID < 0) //placeID == -1
            {
                //setting to Damage
                if (!IsOverMenu() && (Input.GetMouseButtonDown(0)))
                {
                    centerPosition = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.transform.position.y));
                    if (HarmAtPosition(centerPosition, 1.0f))
                    {
                        PopMessage("Kill!", centerPosition, 0);
                    }
                }
            }
            else //placeID == 0
            {
                //setting to delete objects
                if (!IsOverMenu() && (Input.GetMouseButtonDown(0)))
                {
                    centerPosition = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.transform.position.y));
                    if (DeleteAtPosition(centerPosition, 1.0f))
                    {
                        PopMessage("DELETED", centerPosition, 1);
                    }
                }
            }
        }
        else // is placeable
        {
            if (!placementStarted)
            {
                //Since we have not started, we can look for our mouse for placement
                if (!IsOverMenu() && (Input.GetMouseButtonDown(0)))
                {
                    //Set the center based on mouse position
                    centerPosition = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.transform.position.y));

                    //We will let everything start with a radius of 0.5
                    if (CheckPlacementPosition(centerPosition, 0.5f, null))
                    {
                        if (placeID == 2) //this is a location, which requires 2 steps
                        {
                            placedObject = Instantiate(locationStart, centerPosition, Quaternion.identity);
                            //calculate our edge and manipulate the scale until finalized
                            edgePosition = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.transform.position.y));
                            float distance = Vector3.Distance(centerPosition, edgePosition);
                            if (CheckPlacementPosition(centerPosition, distance, placedObject))
                            {
                                placedObject.transform.localScale = new Vector3(distance * 2, 0.1f, distance * 2);
                            }
                            placementStarted = true;
                        }
                        else
                        {
                            //Use the id to pull the Subject card
                            Subject newSubject = masterSubjectList.GetSubject(placeID);
                            if (newSubject != null)
                            {
                                placedObject = Instantiate(newSubject.Prefab, centerPosition, Quaternion.identity);
                                if (placedObject != null)
                                {
                                    SubjectObjectScript script = placedObject.GetComponent <SubjectObjectScript>() as SubjectObjectScript;
                                    script.InitializeFromSubject(masterSubjectList, newSubject);
                                    placementStarted = true;
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                //We have started to place - is it a location?
                if (placeID == 2)
                {
                    //calculate our edge and manipulate the scale until finalized
                    edgePosition = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.transform.position.y));
                    float distance = Vector3.Distance(centerPosition, edgePosition);
                    if (CheckPlacementPosition(centerPosition, distance, placedObject))
                    {
                        placedObject.transform.localScale = new Vector3(distance * 2, 0.1f, distance * 2);
                        lastDistance = distance;
                    }

                    //Look for a second mouse click to finalize the location
                    //No more changes to distance
                    if (!IsOverMenu() && (Input.GetMouseButtonDown(0)))
                    {
                        placementStarted = false;
                        Destroy(placedObject); //get rid of our temp area
                        //create a new location using the above values
                        CreateLocation(centerPosition, lastDistance);
                    }
                }
                else
                {
                    //We can finalize everything else automatically
                    placementStarted = false;
                }
            }
        }
    }
    public MasterSubjectList()
    {
        masterSubjectList = new List <Subject>();

        //`-.,.-'-.,.-'-.,.-'-.,.-'-.,.-'
        maxID = DbIds.Plinkett; // == Plinkett
        //,.-`-.,.-`-.,.-`-.,.-`-.,.-`-.,
        NpcDefinition plinkettNpcDefinition = new NpcDefinition()
        {
            Memories           = new List <SubjectMemory>(),
            AttackDamage       = 10,
            FoodHungry         = 60,
            FoodMax            = 100,
            FoodMetabolizeRate = 1,
            HealthDanger       = 40,
            HealthMax          = 50,
            HealthRegen        = 1,
            MetabolizeInterval = 1,
            MoveSpeed          = 5,
            Nest           = null,
            SafetyDeadly   = -10,
            SafetyHigh     = 10,
            SightRangeFar  = 10,
            SightRangeNear = 2.5f,
            StarvingDamage = 3,
            Traits         = new NpcCharacterTraits(NpcTraits.Herbivore)
        };
        AnimalSubject plinkett = new AnimalSubject()
        {
            Definition      = plinkettNpcDefinition,
            Description     = "A herbivore.",
            GrowthTime      = 5,
            Icon            = new UnityEngine.Sprite(),
            InventorySize   = 1,
            LootID          = 5,
            MatureTime      = 200,
            MaxGrowth       = 400,
            Name            = "Plinkett",
            RelatedSubjects = new int[0],
            SubjectID       = maxID,
            Prefab          = Resources.Load("GameObjects/Plinkett") as GameObject
        };

        masterSubjectList.Add(plinkett);

        //`-.,.-'-.,.-'-.,.-'-.,.-'-.,.-'
        maxID = DbIds.Location; // == Location
        //,.-`-.,.-`-.,.-`-.,.-`-.,.-`-.,
        LocationSubject NewLocationOne = new LocationSubject()
        {
            Coordinates     = new UnityEngine.Vector3(1, 1, 1),
            Description     = "A very positional kind of location",
            Icon            = new UnityEngine.Sprite(),
            Layer           = 1,
            Name            = "Location",
            Radius          = 2,
            RelatedSubjects = new int[0],
            SubjectID       = maxID,
            Prefab          = Resources.Load("GameObjects/LocationMarker") as GameObject
        };

        masterSubjectList.Add(NewLocationOne);

        //`-.,.-'-.,.-'-.,.-'-.,.-'-.,.-'
        maxID = DbIds.Bush; // == Bush
        //,.-`-.,.-`-.,.-`-.,.-`-.,.-`-.,
        PlantSubject Bush = new PlantSubject()
        {
            SubjectID       = maxID,
            Name            = "Bush",
            Description     = "A Berry Bush",
            Icon            = new UnityEngine.Sprite(),
            RelatedSubjects = new int[0],
            Prefab          = Resources.Load("GameObjects/Bush") as GameObject,

            ProduceID     = 4,
            ProduceTime   = 2,
            MaxGrowth     = 30,
            GrowthTime    = 1,
            MatureGrowth  = 2,
            InventorySize = 3
        };

        masterSubjectList.Add(Bush);

        //`-.,.-'-.,.-'-.,.-'-.,.-'-.,.-'
        maxID = DbIds.Berry; // == Berry
        //,.-`-.,.-`-.,.-`-.,.-`-.,.-`-.,
        FoodSubject Berry = new FoodSubject()
        {
            SubjectID       = maxID,
            Name            = "Berry",
            Description     = "A Juicy Berry",
            Icon            = new UnityEngine.Sprite(),
            RelatedSubjects = new int[0],

            BuildDirections = null,
            MaxStack        = 10,
            FoodType        = 0,
            FoodValue       = 10
        };

        masterSubjectList.Add(Berry);

        //`-.,.-'-.,.-'-.,.-'-.,.-'-.,.-'
        maxID = DbIds.Meat; // == Meat
        //,.-`-.,.-`-.,.-`-.,.-`-.,.-`-.,
        FoodSubject Meat = new FoodSubject()
        {
            SubjectID       = maxID,
            Name            = "Meat",
            Description     = "It was once muscle...",
            Icon            = new UnityEngine.Sprite(),
            RelatedSubjects = new int[0],

            BuildDirections = null,
            MaxStack        = 10,
            FoodType        = 1,
            FoodValue       = 10
        };

        masterSubjectList.Add(Meat);

        //`-.,.-'-.,.-'-.,.-'-.,.-'-.,.-'
        maxID = DbIds.Gobber; // == Gobber
        //,.-`-.,.-`-.,.-`-.,.-`-.,.-`-.,
        NpcDefinition gobberNpcDefinition = new NpcDefinition()
        {
            Memories           = new List <SubjectMemory>(),
            AttackDamage       = 10,
            FoodHungry         = 50,
            FoodMax            = 100,
            FoodMetabolizeRate = 1,
            HealthDanger       = 40,
            HealthMax          = 100,
            HealthRegen        = 1,
            MetabolizeInterval = 1,
            MoveSpeed          = 5,
            Nest           = null,
            SafetyDeadly   = -10,
            SafetyHigh     = 10,
            SightRangeFar  = 10,
            SightRangeNear = 2,
            StarvingDamage = 5,
            Traits         = new NpcCharacterTraits(NpcTraits.Carnivore)
        };
        AnimalSubject gobber = new AnimalSubject()
        {
            Definition      = gobberNpcDefinition,
            Description     = "A carnivore.",
            GrowthTime      = 5,
            Icon            = new UnityEngine.Sprite(),
            InventorySize   = 1,
            LootID          = 5,
            MatureTime      = 200,
            MaxGrowth       = 400,
            Name            = "Gobber",
            RelatedSubjects = new int[0],
            SubjectID       = maxID,
            Prefab          = Resources.Load("GameObjects/Gobber") as GameObject
        };

        masterSubjectList.Add(gobber);

        // \/ \/ DO NOT CHANGE \/ \/
        maxID = DbIds.LastIndex;
        // /\ /\ DO NOT CHANGE /\ /\
    }