Beispiel #1
0
    public void TestSimpleChainedPlan(IGoapPlanner planner)
    {
        var gameObject = new GameObject();

        ReGoapTestsHelper.GetCustomAction(gameObject, "CreateAxe",
                                          new Dictionary <string, bool> {
            { "hasWood", true }, { "hasSteel", true }
        },
                                          new Dictionary <string, bool> {
            { "hasAxe", true }, { "hasWood", false }, { "hasSteel", false }
        }, 10);
        ReGoapTestsHelper.GetCustomAction(gameObject, "ChopTree",
                                          new Dictionary <string, bool> {
        },
                                          new Dictionary <string, bool> {
            { "hasRawWood", true }
        }, 2);
        ReGoapTestsHelper.GetCustomAction(gameObject, "WorksWood",
                                          new Dictionary <string, bool> {
            { "hasRawWood", true }
        },
                                          new Dictionary <string, bool> {
            { "hasWood", true }, { "hasRawWood", false }
        }, 5);
        ReGoapTestsHelper.GetCustomAction(gameObject, "MineOre",
                                          new Dictionary <string, bool> {
            { "hasOre", false }
        },
                                          new Dictionary <string, bool> {
            { "hasOre", true }
        }, 10);
        ReGoapTestsHelper.GetCustomAction(gameObject, "SmeltOre",
                                          new Dictionary <string, bool> {
            { "hasOre", true }, { "hasSteel", false }
        },
                                          new Dictionary <string, bool> {
            { "hasSteel", true }, { "hasOre", false }
        }, 10);

        var hasAxeGoal = ReGoapTestsHelper.GetCustomGoal(gameObject, "HasAxeGoal",
                                                         new Dictionary <string, bool> {
            { "hasAxe", true }
        });

        var memory = gameObject.AddComponent <ReGoapTestMemory>();

        memory.Init();

        var agent = gameObject.AddComponent <ReGoapTestAgent>();

        agent.Init();

        var plan = planner.Plan(agent, null, null, null);

        Assert.That(plan, Is.EqualTo(hasAxeGoal));
        // validate plan actions
        ReGoapTestsHelper.ApplyAndValidatePlan(plan, memory);
    }
Beispiel #2
0
    public void TestTwoPhaseChainedPlan(IGoapPlanner planner)
    {
        var gameObject = new GameObject();

        ReGoapTestsHelper.GetCustomAction(gameObject, "CCAction",
                                          new Dictionary <string, bool> {
            { "hasWeaponEquipped", true }, { "isNearEnemy", true }
        },
                                          new Dictionary <string, bool> {
            { "killedEnemy", true }
        }, 4);
        ReGoapTestsHelper.GetCustomAction(gameObject, "EquipAxe",
                                          new Dictionary <string, bool> {
            { "hasAxe", true }
        },
                                          new Dictionary <string, bool> {
            { "hasWeaponEquipped", true }
        }, 1);
        ReGoapTestsHelper.GetCustomAction(gameObject, "GoToEnemy",
                                          new Dictionary <string, bool> {
            { "hasTarget", true }
        },
                                          new Dictionary <string, bool> {
            { "isNearEnemy", true }
        }, 3);
        ReGoapTestsHelper.GetCustomAction(gameObject, "CreateAxe",
                                          new Dictionary <string, bool> {
            { "hasWood", true }, { "hasSteel", true }
        },
                                          new Dictionary <string, bool> {
            { "hasAxe", true }, { "hasWood", false }, { "hasSteel", false }
        }, 10);
        ReGoapTestsHelper.GetCustomAction(gameObject, "ChopTree",
                                          new Dictionary <string, bool> {
        },
                                          new Dictionary <string, bool> {
            { "hasRawWood", true }
        }, 2);
        ReGoapTestsHelper.GetCustomAction(gameObject, "WorksWood",
                                          new Dictionary <string, bool> {
            { "hasRawWood", true }
        },
                                          new Dictionary <string, bool> {
            { "hasWood", true }, { "hasRawWood", false }
        }, 5);
        ReGoapTestsHelper.GetCustomAction(gameObject, "MineOre", new Dictionary <string, bool> {
            { "hasOre", false }
        },
                                          new Dictionary <string, bool> {
            { "hasOre", true }
        }, 10);
        ReGoapTestsHelper.GetCustomAction(gameObject, "SmeltOre",
                                          new Dictionary <string, bool> {
            { "hasOre", true }
        },
                                          new Dictionary <string, bool> {
            { "hasSteel", true }, { "hasOre", false }
        }, 10);

        var readyToFightGoal = ReGoapTestsHelper.GetCustomGoal(gameObject, "ReadyToFightGoal",
                                                               new Dictionary <string, bool> {
            { "hasWeaponEquipped", true }
        }, 2);

        ReGoapTestsHelper.GetCustomGoal(gameObject, "HasAxeGoal",
                                        new Dictionary <string, bool> {
            { "hasAxe", true }
        });
        var killEnemyGoal = ReGoapTestsHelper.GetCustomGoal(gameObject, "KillEnemyGoal",
                                                            new Dictionary <string, bool> {
            { "killedEnemy", true }
        }, 3);

        var memory = gameObject.AddComponent <ReGoapTestMemory>();

        memory.Init();

        var agent = gameObject.AddComponent <ReGoapTestAgent>();

        agent.Init();

        // first plan should create axe and equip it, through 'ReadyToFightGoal', since 'hasTarget' is false (memory should handle this)
        var plan = planner.Plan(agent, null, null, null);

        Assert.That(plan, Is.EqualTo(readyToFightGoal));
        // we apply manually the effects, but in reality the actions should do this themselves
        //  and the memory should understand what happened
        //  (e.g. equip weapon action? memory should set 'hasWeaponEquipped' to true if the action equipped something)
        // validate plan actions
        ReGoapTestsHelper.ApplyAndValidatePlan(plan, memory);

        // now we tell the memory that we see the enemy
        memory.SetValue("hasTarget", true);
        // now the planning should choose KillEnemyGoal
        plan = planner.Plan(agent, null, null, null);

        Assert.That(plan, Is.EqualTo(killEnemyGoal));
        ReGoapTestsHelper.ApplyAndValidatePlan(plan, memory);
    }