public bool EmitOnEntityCollision(Simulation.Simulation simulation, SimulationEntity otherEntity) { bool defaultAction = true; foreach (EntityComponent simulationComponent in EntityComponents) { if (!simulationComponent.OnEntityCollision(simulation, this, otherEntity)) { defaultAction = false; } } return(defaultAction); }
public static SimulationEntity SimulationEntityFactory(string entityKey, ClientSocket socket = null) { Random rand = new Random(); ConfigurationRegistry registry = ConfigurationRegistry.GetInstance(); EntityConfiguration config = registry.GetEntityConfiguration(entityKey); config.EntityKey = entityKey; //create new entity SimulationEntity newEntity = new SimulationEntity(socket?.ClientId ?? Guid.NewGuid().ToString(), new EntityOptions { TextureKey = config.TextureKey, Dimensions = config.DimensionRange == null ? config.Dimensions : new BfbVector( rand.Next((int)config.DimensionRange.X, (int)config.DimensionRange.Y), rand.Next((int)config.DimensionRange.X, (int)config.DimensionRange.Y)), Origin = config.Origin, EntityType = config.EntityType }, socket) { CollideFilter = config.CollideFilter, CollideWithFilters = config.CollideWithFilters, Meta = new EntityMeta { Health = config.Health, Mana = config.Mana, MaxHealth = config.Health, MaxMana = config.Mana }, EntityConfiguration = config }; //Required components newEntity.EntityComponents.Add(new EntityFacing()); //Add a lifetime component if needed if (config.Lifetime > 0) { newEntity.EntityComponents.Add(new LifetimeComponent(config.Lifetime)); } //Add components foreach (string configComponent in config.Components) { newEntity.EntityComponents.Add(registry.GetEntityComponent(configComponent)); } if (newEntity.EntityType == EntityType.Mob || newEntity.EntityType == EntityType.Player) { newEntity.EntityComponents.Add(new ManaRegen()); } if (socket == null)//We can assume if a socket is supplied then its a player { return(newEntity); } newEntity.EntityType = EntityType.Player; newEntity.EntityComponents.Add(new InputRemote()); newEntity.EntityComponents.Add(new InventoryComponent()); newEntity.EntityComponents.Add(new InventoryConnection()); newEntity.EntityComponents.Add(new AnimatedHolding()); return(newEntity); }