Esempio n. 1
0
    public EventAction FindAction(Type category, out List <Dependency> maxDeps, Dependency targetDep = null)
    {
        var         maxUt     = 0f;
        EventAction maxAction = null;

        maxDeps = null;
        List <EventAction> actions = allActions;

        if (category != null)
        {
            actionsSet.TryGetValue(category, out actions);
        }
        if (DebugFindAction)
        {
            builder.Length = 0;
            builder.Append("Actor choosing action: ");
            builder.Append(gameObject.name).AppendLine();
        }

        foreach (var action in actions)
        {
            EventAction a = action;
            if (DebugFindAction)
            {
                builder.Append(action.GetType().Name).Append(" ");
            }
            int countUsed = 0;
            if (actionsInUse.TryGetValue(action.GetType(), out countUsed))
            {
                a = Actions.Instance.GetAction(action.GetType());
            }
            a.Init();
            if (targetDep != null)
            {
                targetDep.InitAction(a);
            }
            a.Root = gameObject;
            var ut = a.Utility();
            ut = ut * (1f + ((float)fuzziness.NextDouble() - 0.5f) * 2f * 0.1f);
            if (DebugFindAction)
            {
                builder.Append(ut).Append(" ").Append(a.State).AppendLine();
            }
            var deps = a.GetDependencies();
            if (ut > maxUt && Traverse(deps))
            {
                maxUt     = ut;
                maxAction = a;
                maxDeps   = deps;
            }
        }
        if (DebugFindAction)
        {
            Debug.Log(builder.ToString());
        }
        return(maxAction);
    }