Beispiel #1
0
    public override List <GoapAction> initAction(Transform tr)
    {
        List <GoapAction> goapActionList = new List <GoapAction>();

        // ¼ñľ²ñ
        ChopFirewoodAction chopFireWoodAction = new ChopFirewoodAction(tr);

        goapActionList.Add(chopFireWoodAction);

        // ¼ñľ²ñ
        DropOffFirewoodAction dropOffFireWoodAction = new DropOffFirewoodAction(tr);

        goapActionList.Add(dropOffFireWoodAction);

        PickUpToolAction pickUpToolAction = new PickUpToolAction(tr);

        goapActionList.Add(pickUpToolAction);

        return(goapActionList);
    }
Beispiel #2
0
    public override List <GoapAction> initAction(Transform tr)
    {
        List <GoapAction> goapActionList = new List <GoapAction>();

        // 砍树
        ChopTreeAction chopTreeAction = new ChopTreeAction(tr);

        goapActionList.Add(chopTreeAction);

        // 放下木头
        DropOffLogsAction dropOffLogsAction = new DropOffLogsAction(tr);

        goapActionList.Add(dropOffLogsAction);

        // 获取工具
        PickUpToolAction pickUpToolAction = new PickUpToolAction(tr);

        goapActionList.Add(pickUpToolAction);

        return(goapActionList);
    }
Beispiel #3
0
    public override List <GoapAction> initAction(Transform tr)
    {
        List <GoapAction> goapActionList = new List <GoapAction>();

        // 获取工具
        PickUpToolAction pickUpToolAction = new PickUpToolAction(tr);

        goapActionList.Add(pickUpToolAction);

        // 挖矿石
        MineOreAction mineOreAction = new MineOreAction(tr);

        goapActionList.Add(mineOreAction);

        // 放下铁
        DropOffOreAction dropOffOreAction = new DropOffOreAction(tr);

        goapActionList.Add(dropOffOreAction);

        return(goapActionList);
    }
Beispiel #4
0
    public void ProcessMessage(string message)
    {
        Debug.Log("Json Message: " + message);
        GoapResposeObject obj = JsonConvert.DeserializeObject <GoapResposeObject>(message);

        Debug.Log(obj.ID);

        // enqueue the action list
        Queue <GoapAction> queue = new Queue <GoapAction>();
        List <GoapAction>  temp  = new List <GoapAction>();

        Debug.Log(obj.solutionList.Count);

        foreach (var a in obj.solutionList)
        {
            GoapAction tempAction;

            switch (a.type)
            {
            case "ChopFirewoodAction":
                tempAction = new ChopFirewoodAction();
                break;

            case "ChopTreeAction":
                tempAction = new ChopTreeAction();
                break;

            case "DropOffFirewoodAction":
                tempAction = new DropOffFirewoodAction();
                break;

            case "DropOffLogsAction":
                tempAction = new DropOffLogsAction();
                break;

            case "DropOffOreAction":
                tempAction = new DropOffOreAction();
                break;

            case "DropOffToolsAction":
                tempAction = new DropOffToolsAction();
                break;

            case "ForgeToolAction":
                tempAction = new ForgeToolAction();
                break;

            case "MineOreAction":
                tempAction = new MineOreAction();
                break;

            case "PickUpLogsAction":
                tempAction = new PickUpLogsAction();
                break;

            case "PickUpOreAction":
                tempAction = new PickUpOreAction();
                break;

            case "PickUpToolAction":
                tempAction = new PickUpToolAction();
                break;

            default:
                tempAction = new GoapAction();
                break;
            }

            foreach (var subList in a.preconditions)
            {
                if (subList[1] == "true")
                {
                    tempAction.addPrecondition(subList[0], true);
                }
                else
                {
                    tempAction.addPrecondition(subList[0], false);
                }
            }

            foreach (var subList in a.effects)
            {
                if (subList[1] == "true")
                {
                    tempAction.addEffect(subList[0], true);
                    Debug.Log("Effect key" + subList[0]);
                }
                else
                {
                    tempAction.addEffect(subList[0], false);
                }
            }

            tempAction.cost = a.cost;

            //Debug.Log(a.targetID);
            for (int i = 0; i < targets.Count; i++)
            {
                if (targetsID[i] == a.targetID)
                {
                    tempAction.targetID = a.targetID;
                    //Debug.Log("Match");
                }
            }

            //tempAction.checkProceduralPrecondition()
            temp.Add(tempAction);
            queue.Enqueue(tempAction);
        }

        foreach (var item in agents)
        {
            if (item.ID == obj.ID)
            {
                item.hasPlan = true;
                item.plan    = queue;
                Debug.Log("Set plan");
            }
        }
    }