public override void Action() { time++; //This timer might be awfully ugly if (time > _transaction_duration) { AgentTicketOffice agent = _stateMachine.Agent as AgentTicketOffice; Ticket ticket = Environment.GetInstance().environment.RequestSeat((agent.askForTicket.Type as MessageAskForTicket).door); agent.receivedAskForTicket = false; if (ticket != null) { agent.SendMessage(agent.queue.Pop(), new MessageGiveTicket(ticket)); agent.transactionFinished = true; } else { List <int> availableCategories = Environment.GetInstance().environment.StillAvailableCategories((agent.queue.First() as AgentSpectator).side); agent.SendMessage(agent.queue.First(), new MessageNoTicketAvailable(availableCategories, (agent.askForTicket.Type as MessageAskForTicket).door)); //No seat available, the transaction is finished if (availableCategories.Count == 0) { agent.queue.Pop(); //Eliminate the first agent in the queue agent.transactionFinished = true; } } } }
public override State Next() { AgentTicketOffice agent = _stateMachine.Agent as AgentTicketOffice; State res = this; if (time > _transaction_duration && agent.transactionFinished) { //Envoyer la nouvelle position à tout le monde foreach (Agent a in agent.queue.agents) { agent.SendMessage(a, new MessageSendQueuePosition(agent.queue.GetPositionForAgent(a), agent.queue.GetNumberInQueueForAgent(a))); } res = new StateTicketOfficeWaiting(_stateMachine); } else if (time > _transaction_duration) { time = 0; } return(res); }