Пример #1
0
    public static given_action GetNextMove(Person prsn)
    {
        List <given_action> potential_actions = new List <given_action>();

        given_action hngr = new given_action();

        hngr.value  = HungerExpert(prsn);
        hngr.action = Enums.actions.eat;
        potential_actions.Add(hngr);

        given_action stress = new given_action();

        stress.value  = StressExpert(prsn);
        stress.action = Enums.actions.stress;
        potential_actions.Add(stress);


        //sort with reference to the value.
        potential_actions.Sort((s1, s2) => s2.value.CompareTo(s1.value));


        //TODO: return most important value based on logic. Right now just returns highest vlaue.

        return(potential_actions[0]);
    }
Пример #2
0
    private string PerformAction()
    {
        given_action next_action = Blackboard.GetNextMove(this);

        if (current_action.action != next_action.action)
        {
            current_action = next_action;

            return(name + " realized he needed to satisfy " + current_action.action + " with a value of " + next_action.value);
        }
        else
        {
            current_action.value = next_action.value;
        }
        //Basic movement algorithm
        if (wanted_object == null)
        {
            bool found = false;
            //If we remmeber there is a item @ position, we set that as the item we want to get to to interact with.
            if (memory.remember_items.ContainsKey(current_place.name))
            {
                foreach (memory_thing item in memory.remember_items[current_place.name])
                {
                    if (Enums.IsInDictionary(item.thing.uses, current_action.action))
                    {
                        found           = true;
                        wanted_object   = item.thing;
                        moveto_position = item.pos_at_place;
                        path_to_obj     = Pathfinding.GetPath(position, moveto_position,
                                                              new List <Vector2Int>(), new Vector2Int(999, 999));
                        break;
                    }
                }
            }
            if (!found)
            {
                wanted_object = null_object;
            }
        }

        if (wanted_object != null_object)
        {
            //IF we're at the position, do the stuff.
            if (position == moveto_position)
            {
                //How long does it take to do the stuff? Need this functionality.
                //current_room.RemoveItem(moveto_position);

                //REDO: TODO: What happens when bar is full?

                //Big switch case odds are? This is EAT
                if (wanted_object.durability > 0)
                {
                    if (current_action.action == Enums.actions.eat)
                    {
                        if (needs["hunger"] < 1)
                        {
                            //TODO: Add handling when duravility is 0.
                            wanted_object.Damage();
                            needs["hunger"] = Mathf.Clamp(needs["hunger"] + wanted_object.nutrition, 0, 1);

                            return(name + " is doing action " + next_action.action + " with original intention of " + next_action.value + " onto " + wanted_object.name +
                                   " and his new hunger value is " + needs["hunger"] + ".");
                        }
                        else
                        {
                            return(FinishedAction());
                        }
                    }
                }
                else
                {
                    return(name + "'s item is out of durabililty.");
                }
            }
        }
        else
        {
            return(name + " has no idea what to do!");
        }

        //Move towards item; use actual pathfinding at some point.
        position = path_to_obj[0];
        path_to_obj.RemoveAt(0);


        return(name + " is moving towards the " + wanted_object.name + " at position " + moveto_position +
               " with action " + current_action.action + " with intention " + current_action.value +
               "\nCurrently " + name + " is at now at position " + position);
    }