Exemplo n.º 1
0
    public void Act(EventAction action, List <Dependency> deps = null)
    {
        //Debug.Log("Act " + action.GetType().Name, gameObject);
        //Debug.Log(action.State);
        ActionWrapper wrapper = new ActionWrapper();

        wrapper.Action = action;
        bool canDo = true;

        if (deps == null)
        {
            wrapper.Deps = action.GetDependencies(); //Here it should ask the action to get its dependencies
            canDo        = Traverse(wrapper.Deps);   //Here it should traverse those and answer whether it's possible to achieve this action at all,
                                                     //while also marking external dependencies
        }
        else
        {
            wrapper.Deps = deps;
        }
        if (!canDo)
        {
            action.State = EventAction.ActionState.Failed;
        }
        else
        {
            //Debug.Log("Put as current action");
            PutAsCurrentAction(wrapper);
        }
    }
Exemplo n.º 2
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);
    }
Exemplo n.º 3
0
 private void Start()
 {
     InteractionName.text = Interaction.GetType().Name;
     deps    = Interaction.GetDependencies();
     tooltip = GetComponent <HoverTooltip>();
     if (tooltip == null)
     {
         tooltip = gameObject.AddComponent <HoverTooltip>();
     }
     Button.onClick.AddListener(OnButtonClicked);
     InterAvailable();
     RebuildTooltip();
     wasAvailable = !InterAvailable();
 }