Example #1
0
 public bool FollowInteraction(ref InteractionContext context)
 {
     context.flagsAdded   = new HashSet <string>();
     context.flagsRemoved = new HashSet <string>();
     if (context.complete)
     {
         return(true);
     }
     if (context.interaction_at is DialogueNode dialogue)
     {
         return(MoveNext(ref context, context.ui_controller.Select()));
     }
     else
     {
         return(MoveNext(ref context, context.interaction_at.GetNextNode()));
     }
 }
 public bool FollowInteraction(ref InteractionContext context)
 {
     if (context.complete)
     {
         return(true);
     }
     if (context.interaction_at is DialogueNode dialogue)
     {
         if (context.ui_controller.TrySelect(out var next_node))
         {
             return(MoveNext(ref context, next_node));
         }
     }
     else if (handle_custom_node_continue(context.interaction_at, context, out var next_node))
     {
         return(MoveNext(ref context, next_node));
     }
     return(false);
 }
Example #3
0
        private bool MoveNext(ref InteractionContext context, InteractionNode node)
        {
            if (node == null)
            {
                context.complete       = true;
                context.interaction_at = null;
                return(true);
            }
            if (!node.FlagsMeetRequirements(context.flags))
            {
                context.complete       = true;
                context.interaction_at = null;
                return(true);
            }
            active_context         = context;
            context.interaction_at = node;
            foreach (var flag in node.flagInteractions.flags)
            {
                if (flag.Instruction == FlagInstruction.Add)
                {
                    var flagValue = flag.Value.ToLower();
                    context.flags.Add(flagValue);
                    context.flagsAdded.Add(flagValue);
                }
                else if (flag.Instruction == FlagInstruction.Remove)
                {
                    var flagValue = flag.Value.ToLower();
                    context.flags.Remove(flagValue);
                    context.flagsRemoved.Add(flagValue);
                }
            }

            if (node is VarSetNode var_set)
            {
                var target = var_set.Target;
                if (target == null)
                {
                    throw new System.Exception("Trying to set a variable on a null target!");
                }
                if (target.GetVariable(var_set.var_name, out var var))
                {
                    if (var.var_type != var_set.VarType)
                    {
                        throw new System.Exception($"Variable {var_set.var_name} exists but is of type {var.var_type} not {var_set.VarType}.");
                    }
                    target.SetVariable(var_set.var_name, var_set.Input);
                }
                else
                {
                    throw new System.Exception($"Variable {var_set.var_name} does not exist.");
                }
            }
            if (node is SetAnimatorBooleanNode anim_var_set)
            {
                var anim = anim_var_set.Animator;
                if (anim != null)
                {
                    anim.SetBool(anim_var_set.ParameterName, anim_var_set.Value);
                }
                else
                {
                    throw new System.Exception($"Trying to set animation variable {anim_var_set.ParameterName} on null animator!");
                }
            }
            if (node is SetGameobjectEnabled game_obj_enabled)
            {
                var gameobject = game_obj_enabled.Gameobject;
                if (gameobject != null)
                {
                    gameobject.SetActive(game_obj_enabled.Value);
                }
                else
                {
                    throw new System.Exception("Trying to set active state on null game object!");
                }
            }
            if (node is DestroyGameobjectNode destroy_node)
            {
                var gameobject = destroy_node.Gameobject;
                if (gameobject != null)
                {
                    Destroy(gameobject);
                }
                else
                {
                    throw new System.Exception("Trying to destroy a null game object!");
                }
            }
            if (node is FlipPlayerNode filpNode)
            {
                filpNode.player.AnimateFlipTo(filpNode.destination);
            }

            if (node is DialogueNode dialogue)
            {
                context.ui_controller.Show(dialogue, context.flags);
                return(false);
            }
            else
            {
                return(MoveNext(ref context, context.interaction_at.GetNextNode()));
            }
        }
Example #4
0
 public bool StartInteraction(InteractionEntryNode start, HashSet <string> flags, UIController ui_controller, out InteractionContext context)
 {
     context = new InteractionContext {
         complete       = false,
         interaction_at = start,
         flags          = flags,
         ui_controller  = ui_controller,
     };
     return(FollowInteraction(ref context));
 }
        private bool MoveNext(ref InteractionContext context, InteractionNode node)
        {
            while (true)
            {
                if (node == null)
                {
                    context.complete       = true;
                    context.interaction_at = null;
                    return(true);
                }
                if (!node.FlagsMeetRequirements(context.flags))
                {
                    context.complete       = true;
                    context.interaction_at = null;
                    return(true);
                }
                active_context         = context;
                context.interaction_at = node;
                foreach (var flag in node.flagInteractions.flags)
                {
                    if (flag.Instruction == FlagInstruction.Set)
                    {
                        context.flags[flag.Value] = true;
                    }
                    else if (flag.Instruction == FlagInstruction.Unset)
                    {
                        context.flags[flag.Value] = false;
                    }
                }

                if (node is VarSetNode var_set)
                {
                    var target = var_set.Target;
                    if (target == null)
                    {
                        throw new System.Exception("Trying to set a variable on a null target!");
                    }
                    if (target.GetVariable(var_set.var_name, out var var))
                    {
                        if (var.var_type != var_set.VarType)
                        {
                            throw new System.Exception($"Variable {var_set.var_name} exists but is of type {var.var_type} not {var_set.VarType}.");
                        }
                        target.SetVariable(var_set.var_name, var_set.Input);
                    }
                    else
                    {
                        throw new System.Exception($"Variable {var_set.var_name} does not exist.");
                    }
                }
                else if (node is SetAnimatorBooleanNode anim_var_set)
                {
                    var anim = anim_var_set.Animator;
                    if (anim != null)
                    {
                        anim.SetBool(anim_var_set.ParameterName, anim_var_set.Value);
                    }
                    else
                    {
                        throw new System.Exception($"Trying to set animation variable {anim_var_set.ParameterName} on null animator!");
                    }
                }
                else if (node is SetGameobjectEnabled game_obj_enabled)
                {
                    var gameobject = game_obj_enabled.Gameobject;
                    if (gameobject != null)
                    {
                        gameobject.SetActive(game_obj_enabled.Value);
                    }
                    else
                    {
                        throw new System.Exception("Trying to set active state on null game object!");
                    }
                }
                else if (node is DestroyGameobjectNode destroy_node)
                {
                    var gameobject = destroy_node.Gameobject;
                    if (gameobject != null)
                    {
                        Destroy(gameobject);
                    }
                    else
                    {
                        throw new System.Exception("Trying to destroy a null game object!");
                    }
                }
                else if (node is TakeItemNode take_item_node)
                {
                    node = take_item_node.TryTakeItem(context.inventory);
                    continue;
                }
                else if (node is DialogueNode dialogue)
                {
                    context.ui_controller.ShowNode(dialogue, context.inventory, context.flags);
                    return(false);
                }
                else
                {
                    if (handle_custom_node(node, context, out var next_node))
                    {
                        node = next_node;
                        continue;
                    }
                    else
                    {
                        return(false);
                    }
                }
                node = node.GetNextNode();
            }
        }
 public bool StartInteraction(InteractionEntryNode start, Inventory inventory, FlagSet flags, UIController ui_controller, out InteractionContext context)
 {
     context = new InteractionContext {
         complete       = false,
         interaction_at = start,
         inventory      = inventory,
         flags          = flags,
         ui_controller  = ui_controller,
     };
     return(FollowInteraction(ref context));
 }