Exemplo n.º 1
0
 public MaterialConcept.MaterialType?GetMaterialType(ScheduledJob job)
 {
     if (job.Action is GetMaterialAction)
     {
         GetMaterialAction action = job.Action as GetMaterialAction;
         return(action.GetMaterial().GetMaterialType());
     }
     return(null);
 }
Exemplo n.º 2
0
    override protected void Action()
    {
        MaterialConcept materialConcept = new MaterialConcept(materialType);
        AgentAction     action          = new GetMaterialAction(materialConcept, amount);
        AgentMessage    message         = new AgentMessage(AgentMessage.PerformativeType.INFORM);

        message.Receiver = AgentId.ParseGlobalId(receiver);
        message.Content  = action;
        Agent.Send(message);
    }
Exemplo n.º 3
0
    private void requestCollectingStone(AgentId agentId)
    {
        string       conversationId  = "stone_" + agentId.GetGlobalName() + "_" + Time.fixedTime;
        int          totalStoneCount = RPGAgentTools.FindObjectsOfType <StorageComponent> ().Select(component => component.GetStoneCount()).Sum();
        int          amount          = controller.StoneToCollect - totalStoneCount;
        AgentAction  action          = new GetMaterialAction(new MaterialConcept(MaterialConcept.MaterialType.Stone), amount);
        AgentMessage message         = new AgentMessage(AgentMessage.PerformativeType.REQUEST);

        message.Sender         = coordinatorAgent.AId;
        message.Receiver       = agentId;
        message.Protocol       = Protocols.FIPA_REQUEST;
        message.Content        = action;
        message.ConversationId = conversationId;
        ScheduledJob job = new ScheduledJob(agentId, action, conversationId);

        coordinatorAgent.ScheduledJobs.Add(job);
        coordinatorAgent.Send(message);
    }
Exemplo n.º 4
0
    private void processCancelMaterialActionRequest(AgentMessage message)
    {
        GetMaterialAction action = message.Content as GetMaterialAction;

        MaterialConcept.MaterialType materialType = action.GetMaterial().GetMaterialType();
        if (materialType == MaterialConcept.MaterialType.Wood)
        {
            behaviours.FindAll(it => it.GetType() == typeof(CollectWoodBehaviour)).ForEach(it => it.Stop());
        }
        else if (materialType == MaterialConcept.MaterialType.Stone)
        {
            behaviours.FindAll(it => it.GetType() == typeof(CollectStoneBehaviour)).ForEach(it => it.Stop());
        }
        AgentMessage reply = message.Reply(AgentMessage.PerformativeType.INFORM);

        reply.Content = new CancelledJobConcept();
        Send(reply);
    }
Exemplo n.º 5
0
    private RPGAgentToolkit.Core.Behaviour getCollectingBehaviour(AgentMessage message, Action <GatheredMaterialConcept> actionOnCollectingCompleted)
    {
        GetMaterialAction action = message.Content as GetMaterialAction;
        int amount = action.GetAmount();

        MaterialConcept.MaterialType materialType = action.GetMaterial().GetMaterialType();
        if (materialType == MaterialConcept.MaterialType.Wood)
        {
            return(new CollectWoodBehaviour(this, controller.gameObject, controller.Speed, amount, actionOnCollectingCompleted));
        }
        else if (materialType == MaterialConcept.MaterialType.Stone)
        {
            return(new CollectStoneBehaviour(this, controller.gameObject, controller.Speed, amount, actionOnCollectingCompleted));
        }
        else
        {
            throw new UnityException("Unknown material type");
        }
    }