private Dictionary <string, int> CountAnimalsInChunk(IntVector2 chunkIndex) { Dictionary <string, int> count = new Dictionary <string, int>(); if (player.HasNode("AnimalArea")) { Vector3 playerPos = player.GetTranslation(); Array bodies = (player.GetNode("AnimalArea") as Area).GetOverlappingBodies(); Vector3 chunkCentre = (new Vector3(chunkIndex.x * Chunk.SIZE.x, Chunk.SIZE.y / 2.0f, chunkIndex.y * Chunk.SIZE.z) * Block.SIZE) + (new Vector3((Chunk.SIZE.x * Block.SIZE), 0, (Chunk.SIZE.y * Block.SIZE)) / 2.0f); foreach (PhysicsBody body in bodies) { if (body.IsInGroup("animals")) { AnimalBehaviourComponent behaviour = ((Entity)body.GetNode("Entity")).GetComponent <AnimalBehaviourComponent>(); if (!count.ContainsKey(behaviour.PresetName)) { count.Add(behaviour.PresetName, 1); } else { count[behaviour.PresetName]++; } } } } return(count); }
private void KillAnimal(Node animalNode) { AnimalBehaviourComponent animal = (animalNode.GetNode("Entity") as Entity).GetComponent <AnimalBehaviourComponent>(); animal.Kill(); player.AddItem(ItemID.MEAT, animal.FoodDrop); }
public void ObjectOutOfRange(object[] args) { PhysicsBody body = (PhysicsBody)args[0]; if (body.IsInGroup("animals")) { AnimalBehaviourComponent behaviourComponent = ((Entity)body.GetNode("Entity")).GetComponent <AnimalBehaviourComponent>(); if (behaviourComponent.PresetName.Equals(component.PresetName) && behaviourComponent.Sex != component.Sex) { breedableTargets.Remove(body); } } }
private void eat(Godot.Object nom) { component.Satiated = Math.Max(100.0f, component.Satiated + 20.0f); if (nom is PhysicsBody) { PhysicsBody otherBody = (PhysicsBody)nom; if (otherBody.IsInGroup("animals")) { AnimalBehaviourComponent behaviourComponent = ((Entity)otherBody.GetNode("Entity")).GetComponent <AnimalBehaviourComponent>(); behaviourComponent.Kill(); } else if (otherBody.IsInGroup("plants")) { otherBody.QueueFree(); otherBody.RemoveFromGroup("alive"); } } active = false; }
public void ObjectOutOfRange(object[] args) { PhysicsBody otherBody = (PhysicsBody)args[0]; if (otherBody.IsInGroup("animals")) { AnimalBehaviourComponent behaviourComponent = ((Entity)otherBody.GetNode("Entity")).GetComponent <AnimalBehaviourComponent>(); if (IsFood(otherBody) && behaviourComponent.FoodChainLevel < component.FoodChainLevel) { foodInRange.Remove(otherBody); } } else { if (IsFood(otherBody)) { foodInRange.Remove(otherBody); } } }
public void SpawnAnimal(string presetName, AnimalBehaviourComponent.AnimalSex sex, Vector3 position) { // Choose preset AnimalPreset preset = null; foreach (AnimalPreset p in presets) { if (p.presetName.Equals(presetName) && p.sex == sex) { preset = p; break; } } // Use preset to generate animal PackedScene chosenScene = preset.scene; KinematicBody kb = (KinematicBody)chosenScene.Instance(); Entity entity = new Entity(); kb.AddChild(entity); entity.SetName("Entity"); AnimalBehaviourComponent behaviourComponent = new AnimalBehaviourComponent(entity, preset.sex, preset.diet, preset.foodChainLevel, preset.breedability, preset.presetName, preset.oxygenConsumption, preset.co2Production, preset.foodDrop, preset.birthDrop); PhysicsComponent physicsComponent = new PhysicsComponent(entity); entity.AddComponent(behaviourComponent); entity.AddComponent(physicsComponent); kb.SetTranslation(position); AddChild(kb); }
public EatStrategy(AnimalBehaviourComponent component) : base(component) { }
public BaseStrategy(AnimalBehaviourComponent component) { this.component = component; }