public IViewController SpawnEntity(IEntityRecipee entityRecipee, Position position, bool forceAggressive = true) { GameEntity entity; _entityGenerator.GenerateActorFromRecipeeAndAddToContext(_context, entityRecipee, position, out entity); return(InitializeViewForEntity(entity)); }
public void TurnManagerAssignsTurnsToEntitiesWithEnergy() { GameContext context = Contexts.sharedInstance.game; var entityGenerator = Container.Resolve <IEntityGenerator>(); IEntityRecipee recipee = Mock.Of <IEntityRecipee>(); // entityGenerator.GenerateActorFromRecipeeAndAddToContext(context, recipee, new Position(0, 0), out GameEntity entity); var entity1 = context.CreateEntity(); entity1.ReplacePosition(new Position(0, 0)); entity1.ReplaceEnergy(1f, 0.5f); var entity2 = context.CreateEntity(); entity2.ReplaceEnergy(0.3f, 0f); entity2.ReplacePosition(new Position(1, 1)); var turnManager = Container.Resolve <ITurnManager>(); turnManager.OnGameStart(); for (int i = 1; i < 10; i++) { _log.Add($"{i} has turn!"); turnManager.Update(); } Assert.Pass(string.Join(Environment.NewLine, _log)); }
public void GenerateActorFromRecipeeAndAddToContext(IContext <GameEntity> context, IEntityRecipee entityRecipee, Position position, out GameEntity entity, bool controlledByPlayer = false) { entity = context.CreateEntity(); entity.AddRecipee(entityRecipee.Id); List <IEntityRecipee> allApplyingRecipees = GetAllRecipeesWithBaseFirst(entityRecipee); foreach (IEntityRecipee applyingRecipee in allApplyingRecipees) { if (applyingRecipee.NewComponents.Any(c => c == null)) { _logger.Warning($"Null component in {applyingRecipee.Name} recipee"); } } List <IComponentRecipee> allComponentRecipees = allApplyingRecipees.SelectMany(r => r.NewComponents).ToList(); foreach (IComponentRecipee recipee in allComponentRecipees) { recipee.ApplyToEntity(entity, _rng); } if (entity.hasPosition) { entity.ReplacePosition(position); } List <Skill> allSkills = allApplyingRecipees.SelectMany(r => r.NewSkills).ToList(); if (allSkills.Count > 0) { entity.AddSkills(allSkills); } List <Sprite> spritePool = allApplyingRecipees.LastOrDefault(r => r.Sprites != null && r.Sprites.Count > 0).Sprites; if (spritePool != null) { var sprite = _rng.Choice(spritePool); entity.ReplaceLooks(sprite); } if (controlledByPlayer) { _context.ReplacePlayerEntity(entity.id.Id); } // duplicated from GameInitializer: entity.isFinishedTurn = true; if (_context.playerEntity.Id == entity.id.Id) { entity.isPlayerControlled = true; } }
private void GenerateSingleMonsters(IOsnowaContext osnowaContext, IEntityRecipee monsterRecipee, int count, float enemyCountRate) { for (int i = 0; i < count; i++) { Position position; position = GetRandomWalkablePositionOnBiggestArea(osnowaContext); GameEntity singleAnimal; _entityGenerator.GenerateActorFromRecipeeAndAddToContext(_context, monsterRecipee, position, out singleAnimal); } }
private static List <IEntityRecipee> GetAllRecipeesWithBaseFirst(IEntityRecipee entityRecipee) { var allRecipees = new List <IEntityRecipee>(); var currentRecipee = entityRecipee; while (currentRecipee != null) { allRecipees.Add(currentRecipee); currentRecipee = currentRecipee.Parent; } allRecipees.Reverse(); return(allRecipees); }