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

        // 锻造工具
        ForgeToolAction fogeToolAction = new ForgeToolAction(tr);

        goapActionList.Add(fogeToolAction);

        // 放下工具
        DropOffToolsAction dropOffToolsAction = new DropOffToolsAction(tr);

        goapActionList.Add(dropOffToolsAction);

        // 获取铁
        PickUpOreAction pickUpOreAction = new PickUpOreAction(tr);

        goapActionList.Add(pickUpOreAction);

        return(goapActionList);
    }
Example #2
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");
            }
        }
    }