/** * Key-Value data that will feed the GOAP actions and system while planning. */ public virtual HashSet <KeyValuePair <string, object> > getWorldState() { HashSet <KeyValuePair <string, object> > worldData = new HashSet <KeyValuePair <string, object> >(); worldData.Add(new KeyValuePair <string, object>("hasFood", (backpack.HasFood()))); return(worldData); }
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); }
public override bool perform(GameObject agent) { BackpackComponent backpack = (BackpackComponent)agent.GetComponent(typeof(BackpackComponent)); if (backpack.KindsOfFoodAvailable().Contains(FillerFood)) { if (startTime == 0) { startTime = Time.time; } targetEstanteComponent.isUsed = true; //Se ocupa la estanteria por tanto nadie mas puede acceder. //(Asi tambien resolvemos temas de concurrencia , aunque se podria hacer que pudieran "modificar" varios) if (Time.time - startTime > workDuration) { // finished filled EstanteComponent estante = targetEstanteComponent; int filledAmount = estante.canFill(FillerFood, backpack.dictionary[FillerFood]); // Debug.LogError(filledAmount + " Amount i can fill"); int takedAmount = backpack.Take(FillerFood, filledAmount); // Debug.LogError(takedAmount + " Amount i take considering the one i can fill"); int a = estante.Fill(FillerFood, takedAmount); // Debug.LogError(a + " Amount i fill considering the one i take"); filled = true; //SOLO si nos quedamos sin comida en la mochila añadimos el efecto //(Se deberia hacer en el constructor, yo creo q no porq no es algo q se sabe que se cumple a priori) if (!backpack.HasFood()) { addEffect("hasFood", false); } targetEstanteComponent.isUsed = false; } } else { return(false); } return(true); }