public void Sense() { List <CreatureAI> sensed = new List <CreatureAI>(); List <CreatureAI> collide = new List <CreatureAI>(); foreach (KeyValuePair <string, Faction> faction in PlayState.ComponentManager.Factions.Factions) { if (Alliance.GetRelationship(Creature.Creature.Allies, faction.Value.Name) == Relationship.Hates) { foreach (CreatureAI minion in faction.Value.Minions) { float dist = (minion.Position - GlobalTransform.Translation).LengthSquared(); if (dist < SenseRadius) { sensed.Add(minion); } if (dist < 1.0f) { collide.Add(minion); } } } } if (sensed.Count > 0) { OnEnemySensed.Invoke(sensed); } foreach (CreatureAI minion in collide) { Vector3 diff = minion.Position - Creature.Position; diff.Normalize(); minion.Physics.ApplyForce(diff * 10, DwarfTime.Dt); Creature.Physics.ApplyForce(diff * 10, DwarfTime.Dt); } }
public override void OnBodiesSelected(List <Body> bodies, InputManager.MouseButton button) { foreach (Body other in bodies) { Creature creature = other.GetChildrenOfType <Creature>().FirstOrDefault(); if (creature == null) { continue; } if (Alliance.GetRelationship(creature.Allies, Player.Faction.Name) == Relationship.Loves) { continue; } Drawer3D.DrawBox(other.BoundingBox, DesignationColor, 0.1f, false); if (button == InputManager.MouseButton.Left) { if (!Player.Faction.AttackDesignations.Contains(other)) { Player.Faction.AttackDesignations.Add(other); foreach (CreatureAI minion in Player.Faction.SelectedMinions) { minion.Tasks.Add(new KillEntityTask(other, KillEntityTask.KillType.Attack)); } } } else if (button == InputManager.MouseButton.Right) { if (Player.Faction.AttackDesignations.Contains(other)) { Player.Faction.AttackDesignations.Remove(other); } } } }
public override void Update(DwarfTime gameTime, ChunkManager chunks, Camera camera) { bool got = false; foreach (var faction in Manager.Factions.Factions) { if (faction.Value.Name == Faction.Name) { continue; } else if (Alliance.GetRelationship(faction.Value.Name, Faction.Name) != Relationship.Loves) { foreach (CreatureAI creature in faction.Value.Minions) { if ((creature.Position - Position).LengthSquared() < DamageRadius) { creature.Creature.Damage(Damage.Amount, Damage.DamageType); got = true; break; } } } if (got) { break; } } if (got) { Die(); } base.Update(gameTime, chunks, camera); }