Example #1
0
        public static void AddBackAttackComboToMovesList(System.Collections.Generic.List <MoveDescription> movesList)
        {
            MoveDescription backAttack = null;

            foreach (MoveDescription move in movesList)
            {
                if (move.MoveName.ToLower().Contains("block") && move.ComboList.Count > 0)
                {
                    backAttack = move.ComboList[0].ToMove;
                }
            }

            if (backAttack != null)
            {
                foreach (MoveDescription move in movesList)
                {
                    ComboMove backCombo = null;
                    foreach (ComboMove combo in move.ComboList)
                    {
                        foreach (ComboCondition condition in combo.Conditions)
                        {
                            if (condition is InputCondition)
                            {
                                InputCondition inputCondition = condition as InputCondition;
                                if (inputCondition.DirectionModifier == InputDirectionModifier.None && inputCondition.ComboInputs == ComboInputs.Heavy)
                                {
                                    backCombo             = new ComboMove();
                                    backCombo.MoveName    = backAttack.MoveName;
                                    backCombo.ToMove      = backAttack;
                                    backCombo.Priority    = combo.Priority + 1;
                                    backCombo.AI_Followup = combo.AI_Followup;
                                    backCombo.Conditions  = new System.Collections.Generic.List <ComboCondition>();
                                    foreach (ComboCondition comboCondition in combo.Conditions)
                                    {
                                        if (comboCondition is InputCondition)
                                        {
                                            InputCondition newInputCondition = ScriptableObject.CreateInstance <InputCondition>();
                                            newInputCondition.ComboInputs       = ComboInputs.Heavy;
                                            newInputCondition.DirectionModifier = InputDirectionModifier.Back;
                                            backCombo.Conditions.Add(newInputCondition);
                                        }
                                        else
                                        {
                                            backCombo.Conditions.Add(comboCondition);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (backCombo != null)
                    {
                        move.ComboList.Add(backCombo);
                    }
                }
            }
        }
Example #2
0
        public string loop(InputCondition condition)
        {
            string buffer = "";

            while (this.hasMore() && condition(this))
            {
                buffer += this.step().Character;
            }
            return(buffer);
        }
 private void DrawCondition(Rect pos, InputCondition condition, GUIContent label)
 {
     InLine.SetRect(pos, 0, 0, 3);
     {
         EditorGUI.LabelField(InLine.NextRect(), "Button");
         condition.button = EditorGUI.TextField(InLine.NextRect(), condition.button);
     }
     InLine.SetRect(pos, 1, 0, 3);
     {
         EditorGUI.LabelField(InLine.NextRect(), "InputType");
         condition.type = (InputType)EditorGUI.EnumPopup(InLine.NextRect(), condition.type);
     }
 }
Example #4
0
        protected override NodeResultBuilder GetValue()
        {
            //return null;
            var builder = new NodeResultBuilder();
            //string condition = ConditionType.DropdownValue == "Expression" ? InputCondition.GetValue() : InputGroupID.GetValue();
            string condition = InputCondition.GetValue();

            builder.Append($"(?({condition})", this);
            builder.Append(InputThen.Value);
            builder.Append("|", this);
            builder.Append(InputElse.Value);
            builder.Append(")", this);
            //return $"(?({condition}){InputThen.GetValue()}|{InputElse.GetValue()})";
            return(builder);
        }
Example #5
0
 public static void AddQuickOverrideToMovesList(System.Collections.Generic.List <MoveDescription> movesList)
 {
     foreach (MoveDescription move in movesList)
     {
         ComboMove lightAttack = null;
         foreach (ComboMove combo in move.ComboList)
         {
             if (combo.Priority == 0)
             {
                 foreach (ComboCondition condition in combo.Conditions)
                 {
                     if (condition is InputCondition)
                     {
                         InputCondition inputCondition = condition as InputCondition;
                         if (inputCondition.DirectionModifier == InputDirectionModifier.None && inputCondition.ComboInputs == ComboInputs.Quick)
                         {
                             lightAttack             = new ComboMove();
                             lightAttack.MoveName    = combo.MoveName;
                             lightAttack.ToMove      = combo.ToMove;
                             lightAttack.Priority    = 3;
                             lightAttack.AI_Followup = combo.AI_Followup;
                             lightAttack.Conditions  = new System.Collections.Generic.List <ComboCondition>();
                             foreach (ComboCondition comboCondition in combo.Conditions)
                             {
                                 if (comboCondition is InputCondition)
                                 {
                                     InputCondition newInputCondition = ScriptableObject.CreateInstance <InputCondition>();
                                     newInputCondition.ComboInputs       = ComboInputs.Quick;
                                     newInputCondition.DirectionModifier = InputDirectionModifier.Up;
                                     lightAttack.Conditions.Add(newInputCondition);
                                 }
                                 else
                                 {
                                     lightAttack.Conditions.Add(comboCondition);
                                 }
                             }
                         }
                     }
                 }
             }
         }
         if (lightAttack != null)
         {
             move.ComboList.Add(lightAttack);
         }
     }
 }
Example #6
0
        private bool SetInventoryTargets(Agent agent, Mapping mapping, InputCondition inputCondition)
        {
            List <Entity> possibleTargets;
            List <KeyValuePair <Entity, float> > targetsRanked;

            List <TypeGroup> groupings = inputCondition.InventoryTypeGroups(mapping.mappingType, out List <int> indexesToSet);

            // Target is from the agent's inventory if the input condition does not require an Entity Target
            if (!inputCondition.RequiresEntityTarget())
            {
                List <EntityType> allAgentInventoryEntityTypes = agent.inventoryType.GetAllEntityTypes(agent);
                List <Entity>     allAgentInventoryEntities    = agent.inventoryType.GetAllEntities(agent, true);

                List <EntityType> entityTypes = TypeGroup.InAllTypeGroups(groupings, allAgentInventoryEntityTypes);
                possibleTargets = allAgentInventoryEntities.Where(x => entityTypes.Contains(x.entityType)).ToList();
            }
            else
            {
                List <EntityType> entityTypes = mapping.target.inventoryType.GetAllEntityTypes(mapping.target);
                entityTypes     = TypeGroup.InAllTypeGroups(groupings, entityTypes);
                possibleTargets = mapping.target.inventoryType.GetAllEntities(mapping.target, entityTypes, false);
            }

            if (possibleTargets.Count == 0)
            {
                return(false);
            }

            targetsRanked = SelectTarget(agent, mapping, possibleTargets, true);
            if (targetsRanked != null)
            {
                // TODO: Handle more selection algorithms - this is just best
                Entity target = targetsRanked[0].Key;
                foreach (int index in indexesToSet)
                {
                    mapping.inventoryTargets[index] = target;
                }
            }
            else
            {
                Debug.Log(agent.name + ": UtilityAIPT.BestInventoryTargets unable to find target - MT = " + mapping.mappingType);
                return(false);
            }

            return(true);
        }
Example #7
0
        public PauseHandler()
        {
            var scene = QuickGameScene.Current;

            scene.AddObject(this);

            pauseInputCondition = new InputCondition(GameKeys.Start, Input.GetInput(scene));

            foreach (var group in scene.UpdateGroups)
            {
                if (group.Priority != UpdatePriority.ModalMenu && group.Priority != UpdatePriority.Input)
                {
                    group.AddPauseCondition(IsPaused);
                }
            }

            pauseMenu = new LayoutPanel(GameTiles.Border(), scene.InterfaceLayer);
            pauseMenu.AddItem(new GameText(Fonts.BigFont, "PAUSED", scene.InterfaceLayer));
            pauseMenu.AddItem(new DynamicText <King>(scene.Player, p => "COINS: " + p.Coins, Fonts.BigFont, scene.InterfaceLayer));

            pauseMenu.Position.Center = Engine.GetScreenSize().Center;
            pauseMenu.Visible         = false;
        }
Example #8
0
        private Plans PossiblePlans(Agent agent, DriveType driveType)
        {
            List <Mapping> possibleMappings = new List <Mapping>();

            foreach (MappingType mappingType in agent.availableMappingTypes)
            {
                Mapping possibleMapping = new Mapping(mappingType);

                // If MappingType needs an Entity Target - find best target based on TargetFactors
                // TODO: Return all targets each one as a seperate Mapping - so Utility Modifiers can decide between them
                if (mappingType.ForEntityType())
                {
                    Entity target = BestEntityTarget(agent, possibleMapping);
                    if (target == null)
                    {
                        continue;
                    }

                    possibleMapping.target = target;
                }

                // Check non-entity target ICs
                bool passedAllChecks = true;
                foreach (InputCondition inputCondition in mappingType.NonEntityTypeInputConditions())
                {
                    if (!inputCondition.inputConditionType.Check(inputCondition, agent, possibleMapping, null, false))
                    {
                        passedAllChecks = false;
                        break;
                    }
                }
                if (!passedAllChecks)
                {
                    continue;
                }

                if (mappingType.HasAnyInventoryTargets())
                {
                    // TODO: Move this conditional inits into Mapping constructor
                    possibleMapping.inventoryTargets = new List <Entity>();
                    for (int i = 0; i < mappingType.inputConditions.Count; i++)
                    {
                        possibleMapping.inventoryTargets.Add(null);
                    }

                    passedAllChecks = true;
                    for (int i = 0; i < mappingType.inputConditions.Count; i++)
                    {
                        InputCondition inputCondition = mappingType.inputConditions[i];
                        if (inputCondition.RequiresInventoryTarget() && possibleMapping.inventoryTargets[i] == null)
                        {
                            // Finally make sure we can find all of the InventoryTargets
                            if (!SetInventoryTargets(agent, possibleMapping, inputCondition))
                            {
                                passedAllChecks = false;
                                break;
                            }
                        }
                    }
                    if (!passedAllChecks)
                    {
                        continue;
                    }
                }

                // Passed all checks - add it as a possible state to transition into
                possibleMapping.isComplete = true;
                possibleMappings.Add(possibleMapping);
            }

            return(new Plans(driveType, possibleMappings));
        }
    /*每帧更新的部分*/
    private void Update()
    {
        current_state = InputState();                //获取当前输入状态

        if (current_state == InputCondition.forward) /*关闭除了前进的所有动画*/
        {
            if (!animator.GetBool("forward"))
            {
                animator.SetBool("forward", true);
            }
            if (animator.GetBool("backward"))
            {
                animator.SetBool("backward", false);
            }
            if (animator.GetBool("left"))
            {
                animator.SetBool("left", false);
            }
            if (animator.GetBool("right"))
            {
                animator.SetBool("right", false);
            }
        }
        else if (current_state == InputCondition.backward)   /*关闭除了后退的所有动画*/
        {
            if (animator.GetBool("forward"))
            {
                animator.SetBool("forward", false);
            }
            if (!animator.GetBool("backward"))
            {
                animator.SetBool("backward", true);
            }
            if (animator.GetBool("left"))
            {
                animator.SetBool("left", false);
            }
            if (animator.GetBool("right"))
            {
                animator.SetBool("right", false);
            }
        }
        else if (current_state == InputCondition.left || current_state == InputCondition.forward_left || current_state == InputCondition.backward_right)   /*关闭除了向左行进的所有动画*/
        {
            if (animator.GetBool("forward"))
            {
                animator.SetBool("forward", false);
            }
            if (animator.GetBool("backward"))
            {
                animator.SetBool("backward", false);
            }
            if (!animator.GetBool("left"))
            {
                animator.SetBool("left", true);
            }
            if (animator.GetBool("right"))
            {
                animator.SetBool("right", false);
            }

            /*同时按下多个按键时改变动画速度*/
            switch (current_state)
            {
            case InputCondition.left:
                if (animator.GetFloat("speed") != 1)
                {
                    animator.SetFloat("speed", 1);
                }
                break;

            case InputCondition.forward_left:
                if (animator.GetFloat("speed") != 1.5f)
                {
                    animator.SetFloat("speed", 1.5f);
                }
                break;

            case InputCondition.backward_right:
                if (animator.GetFloat("speed") != -1.5f)
                {
                    animator.SetFloat("speed", -1.5f);
                }
                break;
            }
        }
        else if (current_state == InputCondition.right || current_state == InputCondition.forward_right || current_state == InputCondition.backward_left)   /*关闭除了向右行进的所有动画*/
        {
            if (animator.GetBool("forward"))
            {
                animator.SetBool("forward", false);
            }
            if (animator.GetBool("backward"))
            {
                animator.SetBool("backward", false);
            }
            if (animator.GetBool("left"))
            {
                animator.SetBool("left", false);
            }
            if (!animator.GetBool("right"))
            {
                animator.SetBool("right", true);
            }

            /*同时按下多个按键时改变动画速度*/
            switch (current_state)
            {
            case InputCondition.right:
                if (animator.GetFloat("speed") != 1)
                {
                    animator.SetFloat("speed", 1);
                }
                break;

            case InputCondition.forward_right:
                if (animator.GetFloat("speed") != 1.5f)
                {
                    animator.SetFloat("speed", 1.5f);
                }
                break;

            case InputCondition.backward_left:
                if (animator.GetFloat("speed") != -1.5f)
                {
                    animator.SetFloat("speed", -1.5f);
                }
                break;
            }
        }
        else   //关闭所有动画
        {
            if (animator.GetBool("forward"))
            {
                animator.SetBool("forward", false);
            }
            if (animator.GetBool("backward"))
            {
                animator.SetBool("backward", false);
            }
            if (animator.GetBool("left"))
            {
                animator.SetBool("left", false);
            }
            if (animator.GetBool("right"))
            {
                animator.SetBool("right", false);
            }
        }
    }
Example #10
0
        private Plans PossiblePlans(Agent agent, DriveType driveType, Mapping currentMapping)
        {
            ActionType actionType;

            // If there is a parent this is a GoTo Mapping that was added - use the parent's ActionType
            if (currentMapping.parent != null)
            {
                actionType = currentMapping.parent.mappingType.actionType;
            }
            else
            {
                actionType = currentMapping.mappingType.actionType;
            }

            List <Mapping> possibleMappings = new List <Mapping>();

            foreach (MappingType mappingType in agent.availableMappingTypes)
            {
                // Need to find the CurrentActionTypeICT and see if it matches
                InputCondition actionTypeIC = mappingType.inputConditions.Find(x => x.inputConditionType == currentActionTypeICT);
                if (actionTypeIC != null && actionTypeIC.levelTypes.Contains(currentMapping.mappingType.actionType))
                {
                    // This MT is a possible transition from current ActionType
                    // See if all the ICs pass
                    Mapping possibleMapping = new Mapping(mappingType);

                    // If MappingType needs an Entity Target - find best target based on TargetFactors
                    if (mappingType.ForEntityType())
                    {
                        Entity target = BestEntityTarget(agent, possibleMapping);
                        if (target == null)
                        {
                            continue;
                        }

                        possibleMapping.target = target;
                    }

                    // Check non-entity target ICs
                    bool passedAllChecks = true;
                    foreach (InputCondition inputCondition in mappingType.NonEntityTypeInputConditions())
                    {
                        if (!inputCondition.inputConditionType.Check(inputCondition, agent, possibleMapping, null, false))
                        {
                            passedAllChecks = false;
                            break;
                        }
                    }
                    if (!passedAllChecks)
                    {
                        continue;
                    }

                    if (mappingType.HasAnyInventoryTargets())
                    {
                        // TODO: Move this conditional inits into Mapping constructor
                        possibleMapping.inventoryTargets = new List <Entity>();
                        for (int i = 0; i < mappingType.inputConditions.Count; i++)
                        {
                            possibleMapping.inventoryTargets.Add(null);
                        }

                        passedAllChecks = true;
                        for (int i = 0; i < mappingType.inputConditions.Count; i++)
                        {
                            InputCondition inputCondition = mappingType.inputConditions[i];
                            if (inputCondition.RequiresInventoryTarget() && possibleMapping.inventoryTargets[i] == null)
                            {
                                // Finally make sure we can find all of the InventoryTargets
                                if (!SetInventoryTargets(agent, possibleMapping, inputCondition))
                                {
                                    passedAllChecks = false;
                                    break;
                                }
                            }
                        }
                        if (!passedAllChecks)
                        {
                            continue;
                        }
                    }

                    // Passed all checks - add it as a possible state to transition into
                    possibleMapping.isComplete = true;
                    possibleMappings.Add(possibleMapping);
                }
            }

            return(new Plans(driveType, possibleMappings));
        }