示例#1
0
    public void buyProducts(Alimento.enAlimentos a)
    {
        WareHouseComponent[] wareHouses = FindObjectsOfType(typeof(WareHouseComponent)) as WareHouseComponent[];
        WareHouseComponent   closest    = wareHouses[0]; //A priori solo hay un warehouse en el supermercado

        closest.GetComponent <BackpackComponent>().Add(a, 1);
    }
 public void Add(Alimento.enAlimentos a, int amount)
 {
     if (maxAmount > alimentos.Count)
     {
         alimentos.Add(a);
         ToDictionary();
     }
 }
示例#3
0
 //Actualiza la lista borrando los articulos tomados
 public void updateBuyList(Alimento.enAlimentos a, int amount)
 {
     for (int j = 0; j < amount; j++)
     {
         listaDelaCompra.Remove(a);
     }
     ToDictionary();
 }
示例#4
0
    //Rellena la estanteria con la cantidad maxima posible de cierto producto.
    //Devuelve la cantidad que se ha rellenado
    public int Fill(Alimento.enAlimentos a, int amount)
    {
        int cFill = canFill(a, amount);//Se vuelve a comprobar si la cantidad introducida es apropiada.

        for (int i = 0; i < cFill; i++)
        {
            currentAmount++;
        }
        return(cFill);
    }
    public int Take(Alimento.enAlimentos a, int amount)
    {
        ToDictionary();
        int cTake = canTake(a, amount);

        for (int i = 0; i < cTake; i++)
        {
            alimentos.Remove(a);
        }
        return(cTake);
    }
    public int Fill(Alimento.enAlimentos a, int amount)
    {
        ToDictionary();
        int cFill = canFill(a, amount);

        for (int i = 0; i < cFill; i++)
        {
            alimentos.Add(a);
        }
        //Actualiza el diccionario
        return(cFill);
    }
    //Devuelve la maxima cantidad que se puede tomar
    public int canTake(Alimento.enAlimentos a, int amount)
    {
        ToDictionary();
        int c   = dictionary[a];
        int aux = 0;

        while (c > 0 && aux < amount)
        {
            aux++;
            c--;
        }
        //Debug.LogError("Can take: " + aux);
        return(aux);
    }
    //Devuelve la maxima cantidad que se puede rellenar
    public int canFill(Alimento.enAlimentos a, int amount)
    {
        ToDictionary();
        int aux  = amount;
        int aux2 = alimentos.Count;

        while (maxAmount > aux2 && aux > 0)
        {
            //alimentos.Add(a);
            aux--;
            aux2++;
        }
        //ToDictionary();
        return(amount - aux);
    }
示例#9
0
    public override bool checkProceduralPrecondition(GameObject agent)
    {
        EstanteComponent[] estantes = FindObjectsOfType(typeof(EstanteComponent)) as EstanteComponent[];
        EstanteComponent   closest  = null;
        float closestDist           = 0;

        if (agent.GetComponent <Client>().listaDelaCompra.Count != 0)
        {
            DesiredFood = agent.GetComponent <Client>().listaDelaCompra[Random.Range(0, agent.GetComponent <Client>().listaDelaCompra.Count)];
        }
        //Busca una estanteria no vacia , sin usar y con el alimento que desea
        foreach (EstanteComponent estante in estantes)
        {
            if (!estante.isEmpty() && !estante.isUsed && estante.alimento == DesiredFood)
            {
                if (closest == null)
                {
                    // first one, so choose it for now
                    closest     = estante;
                    closestDist = (estante.gameObject.transform.position - agent.transform.position).magnitude;
                }
                else
                {
                    // is this one closer than the last?
                    float dist = (estante.gameObject.transform.position - agent.transform.position).magnitude;
                    if (dist < closestDist)
                    {
                        // we found a closer one, use it
                        closest     = estante;
                        closestDist = dist;
                    }
                }
                Debug.Log(closest.name);
            }
        }

        targetEstanteComponent = closest;
        if (targetEstanteComponent != null)
        {
            target = targetEstanteComponent.gameObject;
        }
        return(closest != null);
    }
    public override bool perform(GameObject agent)
    {
        if (startTime == 0)
        {
            startTime = Time.time;
        }
        //Debug.Log("startTime" + startTime);

        if (Time.time - startTime > workDuration)
        {
            //Debug.Log(Time.time-startTime);
            // finished filled
            BackpackComponent  backpack          = (BackpackComponent)agent.GetComponent(typeof(BackpackComponent));
            WareHouseComponent wareHouse         = targetWareHouseComponent;
            BackpackComponent  backpackWareHouse = (BackpackComponent)wareHouse.GetComponent(typeof(BackpackComponent));

            while (!filled && backpackWareHouse.HasFood())
            {
                //Seleccionamos de los alimentos disponibles en el almacen uno aleatorio.
                List <Alimento.enAlimentos> ListofAlimentosAvailable = backpackWareHouse.KindsOfFoodAvailable();
                Alimento.enAlimentos        alimentoRandom           = ListofAlimentosAvailable[(int)UnityEngine.Random.Range(0.0f, ListofAlimentosAvailable.Count - 1)];

                int preTakeAmount = 0;
                if (agent.GetComponent <Labourer>() is StoreRestocker)
                {
                    StoreRestocker aux = (StoreRestocker)agent.GetComponent <Labourer>();
                    preTakeAmount = aux.RandomTakenAmount();                         //ESTA CANTIDAD NO ES LA CANTIDAD QUE SE COGE FINALMENTE , SIMPLEMENTE ES LA CANTIDAD QUE DESEA COGER
                }
                int canFillAmount = backpack.canFill(alimentoRandom, preTakeAmount); //Cantidad de ese alimento que puede meter en su inventario a pesar de que su idea fuera meter mas.
                //Debug.LogError(canFillAmount + " canfill");
                //TakedAmount es la cantidad que si ha podido coger en base a la disponibilidad de ese producto en el almacen y teniendo en cuenta que ya se valoro la disponibilidad del propio inventario
                int takedAmount = backpackWareHouse.Take(alimentoRandom, canFillAmount);
                //Debug.LogError(takedAmount+ " taked");
                int r = backpack.Fill(alimentoRandom, takedAmount);
                //Debug.LogError(r + " fill");
                //Debug.Log("Creo que estoy embuclado " + canFillAmount + " " + alimentoRandom);
                filled = true;
            }
            //Debug.Log("He salido de un bucle");
        }
        return(true);
    }
示例#11
0
    //VISUAL EXCLUSIVAMENTE ESTE METODO//
    public void DrawnFoodContained()
    {
        //Para que solo ejecute una vez
        VisualAlimento = alimento;
        VisualAmount   = currentAmount;

        Bounds EstanteriaBounds = this.GetComponent <MeshRenderer>().bounds;//Se usa meshrenderer para que las posiciones sean globales.
        //Hallamos el longitud en z de la estanteria
        float zLenghtEstanteria = EstanteriaBounds.size.z;
        float minPosBoundsZ     = EstanteriaBounds.min.z;
        //Hallamos cuantos alimentos van en la primera linea y en la segunda en funcion de la cantidad que tenemos
        int numberOfCurrentFood1 = (currentAmount / 2);
        int numberOfCurrentFood2 = currentAmount - numberOfCurrentFood1;

        Vector3 line1 = transform.Find("line1").transform.position;
        Vector3 line2 = transform.Find("line2").transform.position;


        List <Vector3> ListPosFood1 = getPositionOnLine(line1, zLenghtEstanteria, numberOfCurrentFood1, minPosBoundsZ);
        List <Vector3> ListPosFood2 = getPositionOnLine(line2, zLenghtEstanteria, numberOfCurrentFood2, minPosBoundsZ);

        ListPosFood1.AddRange(ListPosFood2);

        GameObject food = Alimento.GetAlimentoPrefab(alimento);

        //Destroy Previus Intances
        foreach (FoodComponent c in GetComponentsInChildren <FoodComponent>())
        {
            Destroy(c.gameObject);
        }

        //Instance new ones
        foreach (Vector3 p in ListPosFood1)
        {
            Vector3    originalScale = food.transform.lossyScale;
            GameObject aux           = Instantiate(food, p, food.transform.rotation);
            aux.transform.parent = this.transform;
            ExtensionMethods.MyExtensions.SetGlobalScale(aux.transform, originalScale);
        }
    }
示例#12
0
    //Devuelve la maxima cantidad que se puede rellenar
    //Devuelve la cantidad que es posible rellenar de cierto producto.
    public int canFill(Alimento.enAlimentos a, int amount)
    {
        if (currentAmount == 0)//Cambiamos el tipo de producto que guarda
        {
            alimento  = a;
            maxAmount = Alimento.Alimentos_MaxAmountEstante[a];//CAMBIAMOS EL MAXIMO DE CANTIDAD PERMITIDA EN FUNCION DEL NUEVO PRODUCTO
        }

        int aux  = amount;
        int aux2 = currentAmount;
        int c    = 0;

        while (maxAmount > aux2 && aux > 0)
        {
            //alimentos.Add(a);
            aux--;
            aux2++;
            c++;
        }
        //ToDictionary();
        return(c);
    }
示例#13
0
    void GenerateBuyList()
    {
        currentFoodOnList = 0;
        int numFood = (int)Random.Range(minFoodToBuy, maxFoodToBuy); //Numero de articulos que desea comprar.

        listaDelaCompra = new List <Alimento.enAlimentos>();

        while (currentFoodOnList < numFood)
        {
            System.Array         values    = Alimento.enAlimentos.GetValues(typeof(Alimento.enAlimentos));
            System.Random        random    = new System.Random();
            Alimento.enAlimentos randomBar = (Alimento.enAlimentos)values.GetValue(Random.Range(0, values.Length));

            int amountToBuy = Mathf.RoundToInt(Random.Range(minFoodToBuyOfCertainProduct, maxFoodToBuyOfCertainProduct));
            for (int i = 0; i < amountToBuy; i++)
            {
                listaDelaCompra.Add(randomBar);
                currentFoodOnList++;
            }
        }

        ToDictionary();
    }
 public int FoodAmount(Alimento.enAlimentos a)
 {
     return(dictionary[a]);
 }
 public bool HasFood(Alimento.enAlimentos a)
 {
     return(dictionary.ContainsKey(a));
 }
    public override bool checkProceduralPrecondition(GameObject agent)
    {
        Debug.Log("Check Procedural");
        // find the nearest stand we can fill
        EstanteComponent[] estantes = FindObjectsOfType(typeof(EstanteComponent)) as EstanteComponent[];
        EstanteComponent   closest  = null;
        float closestDist           = 0;

        //PRIMERO SE PRIORIZA RELLENAR LAS ESTANTERIAS VACIAS && QUE NO ESTEN EN USO
        foreach (EstanteComponent estante in estantes)
        {
            if (estante.isEmpty() && !estante.isUsed)
            {
                if (closest == null)
                {
                    // first one, so choose it for now
                    closest     = estante;
                    closestDist = (estante.gameObject.transform.position - agent.transform.position).magnitude;
                }
                else
                {
                    // is this one closer than the last?
                    float dist = (estante.gameObject.transform.position - agent.transform.position).magnitude;
                    if (dist < closestDist)
                    {
                        // we found a closer one, use it
                        closest     = estante;
                        closestDist = dist;
                    }
                }
            }
        }

        //SI HEMOS ENCONTRADO UNA VACIA SE SELECCIONA ESA Y SE DICE QUE SE PUEDE RELLENAR && QUE NO ESTEN EN USO
        if (closest != null)
        {
            //Toma un alimento al azar pero tienen mayor probabilidad aquellos de los que almacene mas cantidad
            List <Alimento.enAlimentos> auxList = agent.GetComponent <BackpackComponent>().alimentos;
            if (auxList.Count > 0)
            {
                FillerFood = auxList[(int)(UnityEngine.Random.Range(0, auxList.Count - 1.0f))];
            }
            //Debug.Log(FillerFood);
            targetEstanteComponent = closest;
            target = targetEstanteComponent.gameObject;
            return(closest != null);
        }

        //SEGUNDO SE PRIORIZA RELLENAR AQUELLAS CON EL MISMO PRODUCTO QUE SE TIENE Y QUE NO ESTEN LLENAS Y QUE NO ESTE EN USO
        foreach (EstanteComponent estante in estantes)
        {
            if (agent.GetComponent <BackpackComponent>().HasFood(estante.alimento) && !estante.isFull() && !estante.isUsed)//DEBUG
            {
                if (closest == null)
                {
                    // first one, so choose it for now
                    closest     = estante;
                    closestDist = (estante.gameObject.transform.position - agent.transform.position).magnitude;
                }
                else
                {
                    // is this one closer than the last?
                    float dist = (estante.gameObject.transform.position - agent.transform.position).magnitude;
                    if (dist < closestDist)
                    {
                        // we found a closer one, use it
                        closest     = estante;
                        closestDist = dist;
                    }
                }
            }
        }

        if (closest != null)
        {
            //SI HEMOS ENCONTRADO UNA QUE CUMPLA LA SEGUNDA POSIBLE SE SELECCIONA ESA Y SE DICE QUE SE PUEDE RELLENAR
            FillerFood             = closest.alimento;
            targetEstanteComponent = closest;
            target = targetEstanteComponent.gameObject;
        }
        return(closest != null);
    }