Пример #1
0
    private void GenerateItem(GameEntity generator, int amount, ItemTypeInBoard type, bool bottomCellConsiderate,
                              GeneratorRadius generatorRadius)
    {
        var generationAmount = generator.goalEffectType.Type == GoalEffectType.Decrease
            ? CalculateGenerationAmountForItem(type, amount)
            : amount;

        var positionsToCheck = GetPositionsToCheck(generator.gridPosition.value, generatorRadius);

        var itemIds = SelectSuitableItems(positionsToCheck, bottomCellConsiderate).Shuffle().Take(generationAmount)
                      .ToList();

        var reservations = new List <Tuple <int, int> >();

        foreach (var id in itemIds)
        {
            var reservationId = IdHelper.GetNewReservationId();
            var item          = _contexts.game.GetEntityWithId(id);
            item.AddItemReservation(reservationId, id, type);
            reservations.Add(new Tuple <int, int>(reservationId, id));
            WaitHelper.Increase(WaitType.CriticalAnimation);
        }

        generator.AddReservedItems(reservations);

        if (generator.goalEffectType.Type == GoalEffectType.Decrease)
        {
            _contexts.game.goalForGenerators.Goals[type.GoalType] -= generationAmount;

            if (CalculateItemLeftToGenerate(type) == 0)
            {
                CloseGenerators(generator);
            }
        }
    }
Пример #2
0
    private void CreateItem(ItemTypeInBoard type, int x, int y)
    {
        var entity = _contexts.game.CreateEntity();

        entity.AddWillSpawnItem(type, new Vector2Int(x, y), y);
        entity.AddId(IdHelper.GetNewId());
    }
Пример #3
0
    private int CalculateItemLeftToGenerate(ItemTypeInBoard type)
    {
        var itemCountInBoard = _contexts.game.GetEntities(GameMatcher.AllOf(GameMatcher.Item))
                               .Count(e => Equals(e.itemType.Value, type.ItemType));
        var itemCountInReservations = _contexts.game.GetEntities(GameMatcher.ItemReservation)
                                      .Count(e => Equals(e.itemReservation.ItemType, type));
        var itemCountLeftInGoal = CalculateItemCountLeftInGoal(type.GoalType);

        return(itemCountLeftInGoal - (itemCountInBoard + itemCountInReservations));
    }
Пример #4
0
    private int CalculateGenerationAmountForItem(ItemTypeInBoard type, int defaultAmount)
    {
        var itemCountInBoard = _contexts.game.GetEntities(GameMatcher.AllOf(GameMatcher.GoalType))
                               .Count(e => Equals(e.goalType.Value, type.GoalType));
        var itemCountInReservations = _contexts.game.GetEntities(GameMatcher.ItemReservation)
                                      .Count(e => Equals(e.itemReservation.ItemType, type));
        var itemCountLeftInGoal = CalculateItemCountLeftInGoal(type.GoalType);

        var generationAmount =
            Mathf.Min(defaultAmount, itemCountLeftInGoal - (itemCountInBoard + itemCountInReservations));

        return(Mathf.Max(generationAmount, 0));
    }
Пример #5
0
    private void CreateCell(ItemTypeInBoard type, int x, int y)
    {
        var entity = _contexts.game.CreateEntity();

        var pos = new Vector2(x, y);

        entity.AddPosition(pos);
        entity.AddGridPosition(new Vector2Int(x, y));
        entity.AddCellId(new Tuple <int, int>(x, y));
        entity.AddCellState(Equals(type, ItemTypeInBoard.Invalid) ? CellState.Invalid : CellState.Empty);
        entity.AddCanAcceptFall(true, 0);
        entity.AddId(IdHelper.GetNewId());

        entity.AddCell(true, true);
    }