public MaterialConcept.MaterialType?GetMaterialType(ScheduledJob job) { if (job.Action is GetMaterialAction) { GetMaterialAction action = job.Action as GetMaterialAction; return(action.GetMaterial().GetMaterialType()); } return(null); }
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); }
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); }
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); }
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"); } }