void lookForFood() { //first see if we are carrying any food foreach (Item item in inventory.getItems()) { if (item is Food) { behavior = BEHAVIORTYPE.EATING; break; } } //if no food is found in the invetory then see if we are standing near it if (behavior == BEHAVIORTYPE.LOOKINGFORFOOD) { List <GameObject> stuffInReach = WorldController.stuffInRadius(transform.position, reach); foreach (GameObject inReachThing in stuffInReach) { if (inReachThing.GetComponent <Plant>() != null) { if (inReachThing.GetComponent <Plant>().getPlantType() == preferredFood) { behavior = BEHAVIORTYPE.HARVESTING; break; } } } } //if no food plant is near then look for it in sight radius }
public override void FixedUpdate() { base.FixedUpdate(); consumeMetabolism(); checkHunger(); //do stuff based on the current behavior switch (behavior) { case BEHAVIORTYPE.IDLE: if (status == STATUS.HUNGRY) { behavior = BEHAVIORTYPE.LOOKINGFORFOOD; } break; case BEHAVIORTYPE.LOOKINGFORFOOD: lookForFood(); break; case BEHAVIORTYPE.EATING: biteFood(); break; case BEHAVIORTYPE.HARVESTING: harvestFood(); break; } }
void biteFood() { Food tempFood = null; foreach (Item item in inventory.getItems()) { if (item is Food) { tempFood = (Food)item; break; } } //last bite can be too big, fix later if (tempFood != null) { tempFood.beEaten(biteValue); metabolism += biteValue; if (tempFood.isGone()) { inventory.retrieveItem(tempFood); } } behavior = BEHAVIORTYPE.IDLE; }
void harvestFood() { List <GameObject> stuffInReach = WorldController.stuffInRadius(transform.position, reach); foreach (GameObject inReachThing in stuffInReach) { if (inReachThing.GetComponent <Plant>() != null) { if (inReachThing.GetComponent <Plant>().getPlantType() == preferredFood) { inventory.putItem(inReachThing.GetComponent <Plant>().harvestFood()); break; } } } behavior = BEHAVIORTYPE.IDLE; }
public void setBehavior(BEHAVIORTYPE inBehavior) { behavior = inBehavior; }