//Inicialización de variables de mundo void Start() { puestoCamarero = mundo.puestoCamareros; posCatmareroCocina = mundo.posCatmereroCocina.transform.position; juguete = mundo.juguete; transform.position = puestoCamarero; posMesaPedidos = mundo.mesaPedidos.transform.GetChild(0).position; estadoActual = EstadosFSM1.ESPERAR; estadoDistraerse = EstadosDistraerse.TRABAJAR; veJuguete = false; vuelveAlTrabajo = false; distraido = false; mirarEncargado = false; timer = waitingTime; timerDistraerse = 30; bandeja = transform.Find("bandeja"); idle(); }
void FSM() { switch (estadoActual) { case EstadosFSM1.ESPERAR: timer -= Time.deltaTime; if (timer <= 0) { if (mundo.hayPlatos()) { walkTo(posMesaPedidos); estadoActual = EstadosFSM1.ENTRAR_COCINA; } else if (mundo.clientesSinAtender()) { mesaActual = mundo.clientePorAtender(); clienteActual = mundo.getClienteEnMesa(mesaActual); posMesaCliente = mundo.mesas[mesaActual].transform.parent.GetChild(0).position; walkTo(posMesaCliente); estadoActual = EstadosFSM1.IR_MESA; } } break; case EstadosFSM1.ENTRAR_COCINA: if (isInPosition()) { estadoActual = EstadosFSM1.COGER_PEDIDO; } break; case EstadosFSM1.COGER_PEDIDO: Plato platoActual = mundo.takePlato(); pedidoActual = platoActual.comida; mesaActual = platoActual.mesa; clienteActual = platoActual.cliente; posMesaCliente = mundo.mesas[mesaActual].transform.parent.GetChild(0).position; pick(platoActual.plato); //Ponemos el plato en la bandeja del catmarero platoLlevando = Instantiate(mundo.plato, bandeja.position + transform.up * 0.05f, mundo.plato.transform.rotation); platoLlevando.transform.SetParent(bandeja); walkTo(posMesaCliente); estadoActual = EstadosFSM1.LLEVAR_PEDIDO; break; case EstadosFSM1.LLEVAR_PEDIDO: if (isInPosition()) { Destroy(platoLlevando); GameObject pedido = Instantiate(mundo.plato, mundo.mesas[mesaActual].transform.GetChild(0).position, mundo.plato.transform.rotation); clienteActual.servir(pedido); pedidoActual = null; walkTo(puestoCamarero); estadoActual = EstadosFSM1.VOLVER; } break; case EstadosFSM1.IR_MESA: if (isInPosition()) { timer = waitingTime; idle(); estadoActual = EstadosFSM1.CONSULTAR_CLIENTE; } break; case EstadosFSM1.CONSULTAR_CLIENTE: timer -= Time.deltaTime; rotateTowards(clienteActual.transform.position); if (timer <= 0 && isLookingTowards(clienteActual.transform.position)) { if (clienteActual.estaDecidido()) { //Si se ha decidido sacamos al cliente de la cola mundo.popCliente(); clienteActual.atender(); estadoActual = EstadosFSM1.TOMAR_NOTA; } else { //Si no se ha decidido pasamos al cliente al final de la cola int mesa = mundo.popCliente(); mundo.pushCliente(mesa, mundo.getClienteEnMesa(mesa)); walkTo(puestoCamarero); estadoActual = EstadosFSM1.VOLVER; } } break; case EstadosFSM1.TOMAR_NOTA: pedidoActual = mundo.ComidaAleatoria(); walkTo(posCatmareroCocina); estadoActual = EstadosFSM1.LLEVAR_COMANDA; break; case EstadosFSM1.LLEVAR_COMANDA: if (isInPosition()) { mundo.pushComanda(mesaActual, pedidoActual, clienteActual); estadoActual = EstadosFSM1.VOLVER; } break; case EstadosFSM1.VOLVER: if (isInPosition()) { timer = waitingTime; idle(); estadoActual = EstadosFSM1.ESPERAR; } break; } }