예제 #1
0
 public static void AttachStatic()
 {
     instance    = BattleStatic.instance.itemSpace.GetComponent <ItemSpace>();
     description = BattleStatic.instance.itemSpace.transform.RecursiveFind("Description").gameObject.GetComponent <TextMeshProUGUI>();
 }
예제 #2
0
    void DecideNextAction()
    {
        //SET THE WEIGHTS ACCORDING TO THE CAT'S CURRENT STATS
        //later: could also be influenced by personality, e.g. how lazy cat is
        //as well as maybe availability of favourite toy/food/etc ?

        //sitting is the default activity so we'll leave that as it is
        sittingAction.weight = 4;

        //sleeping has a weight according to how tired the cat is
        sleepingAction.weight = 10 - currentTiredness;

        //but also cats like to sleep a lot
        sleepingAction.weight += 2;

        //eating has a weight depending on how hungry the cat is
        eatingAction.weight = 10 - currentHunger;

        //cat is more likely to play if it's not tired
        playingAction.weight = currentTiredness;

        //whatever the cat is currently doing, we'll add some extra weight to that
        currentAction.weight = currentAction.weight * 3;

        //OVERRIDES

        //if there is no food, the weight is 0
        if (itemInventory.foodBowl.currentFood == 0)
        {
            eatingAction.weight = 0;
            //TO DO:
            //reduce happiness ?
        }

        //end of overrides


        //get the total weightings

        _totalActionWeight = 0f;
        foreach (Action action in actionList)
        {
            //	Debug.Log(action.actionName + " : " + action.weight);
            _totalActionWeight += action.weight;
        }

        //TO DO:
        //figure out here: if some actions _require_ an object to be available
        //and there isn't one available, then this needs to be checked
        //before the decision is finalised


        // Generate a random position in the list.
        float pick = Random.value * _totalActionWeight;
        // int chosenIndex = 0;
        float  cumulativeWeight = 0;
        Action chosenAction     = actionList[0];

        //  Debug.Log(pick);

        //for each item in the list
        foreach (Action action in actionList)
        {
            cumulativeWeight += action.weight;
            chosenAction      = action;
            if (pick <= cumulativeWeight)
            {
                break;
            }
        }

        // Debug.Log(chosenAction.actionName);
        currentAction = chosenAction;

        Debug.Log(chosenAction.itemRequired);

        //do we need an item for this action?
        if (chosenAction.itemRequired)
        {
            //Debug.Log("need an item");

            //now choose an item to go and do it with
            ItemSpace newSpace = ChooseObject(chosenAction.itemType);

            if (newSpace == null)
            {
                Debug.Log("no item found");
            }
            else
            {
                //set the cat to go to the new item
                //Debug.Log("going to " + newSpace.currentItem.displayName);
                catSprite.GoToObject(newSpace.transform);
            }
        }
    }