Exemplo n.º 1
0
    void SpawnRandom()
    {
        Vector2    position = RandomUtils.InBox(area.offset, area.size);
        GameObject spawn    = Instantiate(RandomUtils.Choice(spawns), position, Quaternion.identity, transform.parent);

        spawned.Add(spawn);
    }
Exemplo n.º 2
0
        public override void StateStarted()
        {
            /*
             *  при условии что контракта активного нет
             *
             *  выбрать рандомный контракт
             *  открыть popup с названием описанием и reward?
             *
             *  делаем его активным
             */

            var availableContracts = Context.Contracts.Where(c => c.IsAvailable(Context));
            var selectedContract   = RandomUtils.Choice(availableContracts.ToList());

            Debug.Log($"{selectedContract.Name} started {selectedContract.Description}");

            Context.Company.ActiveContract = new ContractState(selectedContract);

            _votingState = new NotificationVotingState(Common.InformationPopupDisplayTime);
            //var eventInfo = new EventInfo(selectedContract.Name, selectedContract.Description);
            var eventInfo = new EventInfo("New contract!",
                                          $"<b>{selectedContract.Name}</b>\n\n{selectedContract.Description}");

            UIManager.Instance.ShowNotificationPopup(eventInfo);
            SoundManager.Instance.Play(SoundBank.Instance.ContractStarted);
        }
Exemplo n.º 3
0
    void Start()
    {
        if (ItemPool == null || ItemPool.Length == 0)
        {
            Debug.LogWarning("ItemPool for Shop is empty");
        }

        if (PlaceTransform == null)
        {
            PlaceTransform = transform;
        }

        Text.text = string.Empty;

        if (ActiveItem != null && ActiveItem.Prefab != null)
        {
            Restock(ActiveItem);
        }

        if (RestockOnStart)
        {
            var entry = RandomUtils.Choice(ItemPool, e => e.Weight);
            Restock(entry.Item);
        }
    }
Exemplo n.º 4
0
        public IActionEffect <LevelState> Perform(LevelState state)
        {
            var catIndex       = state.GetCatGirlIndex();
            var catPos         = state.GetPositionFromIndex(catIndex);
            var unsetPositions = new List <int>();

            for (var y = catPos.y + 1; y < state.Height; y++)
            {
                if (state.GetTileAt(catPos.x, y) == TileType.Unset)
                {
                    unsetPositions.Add(state.GetIndexFromPosition(catPos.x, y));
                }
            }

            var unsetTileIndex = RandomUtils.Choice(unsetPositions);
            var pos            = state.GetPositionFromIndex(unsetTileIndex);

            var targetIndices = new List <int>();

            for (var y = pos.y - 1; y >= catPos.y; y--)
            {
                targetIndices.Add(pos.x + y * state.Width);
            }

            var constraints = new List <IConstraint <LevelState> >
            {
                new ThereShouldBeAtLeastOneTileInIndices(TileType.CatGirl, targetIndices)
            };

            return(new TileSetEffect(unsetTileIndex, TileType.Shooter, Direction.Back, constraints));
        }
Exemplo n.º 5
0
        public static IEnumerable <ContractInfo> ReturnContracts(GameContext context, UserDb db)
        {
            var availableContracts = context.Contracts.Where(c => c.IsAvailable(context));

            var minPower      = db.CountActive() * Common.InintialWorkPower;
            var contracts     = new List <ContractInfo>();
            var contractNames = new HashSet <string>();

            for (var level = 1; level < 5; level++)
            {
                /*
                 * var mult = Mathf.Pow(2, (_contract.i - 1));
                 * var difficulty = Mathf.Max(mult * minPower, 1.4f * Common.InintialWorkPower);
                 * contract.Earnings = Mathf.Pow(_contract.value.Reward, 0.1f*_contract.i + 0.9f)*(0.9f + 0.2f * Random.value);
                 *
                 * if (context.Company.Level > _contract.i)
                 *  contract.DisplayName = $"{contract.Info.Name} -available, R: {contract.Earnings: 0}$, D: {contract.Difficulty}";
                 * else
                 *  contract.DisplayName += $"{contract.Info.Name} - office too small,  R: {contract.Earnings: 0}$";
                 */
                var mult       = Mathf.Pow(2, (level - 3));
                var difficulty = Mathf.Max(mult * minPower, Mathf.Pow(level, 2) * Common.InintialWorkPower);

                var contractsLvlBased = availableContracts.Where(c => c.Level == level && !contractNames.Contains(c.Name));
                var baseContract      = RandomUtils.Choice(contractsLvlBased.ToList());
                contractNames.Add(baseContract.Name);

                var baseVoting = baseContract.WorkVoting;
                var options    = baseVoting.Options.Select(old => new WorkVotingInfo.Option()
                {
                    TargetAmount = Mathf.Floor(difficulty * old.TargetAmount),
                    Name         = $"{old.Name}\n <color=#AAA>!{old.Key}</color>",
                    Key          = old.Key,
                    CanPay       = old.CanPay,
                    CanWork      = old.CanWork,
                    IsEnabled    = old.IsEnabled
                });

                var voting = new WorkVotingInfo(
                    options,
                    baseVoting.Duration,
                    baseVoting.AllowMultipleVotes,
                    baseVoting.SuccessAction,
                    baseVoting.FailAction);

                var reward      = Mathf.Pow(baseContract.Reward, 0.1f * level + 0.8f) * (0.9f + 0.2f * Random.value); // TODO: balance
                var name        = $"{baseContract.Name} \nlvl:{level} reward: ${reward:N0}";                          // TODO: balance
                var description = baseContract.Description;

                var contract = new ContractInfo(
                    name,
                    description,
                    voting,
                    level,
                    reward);

                contracts.Add(contract);
            }
            return(contracts);
        }
Exemplo n.º 6
0
    public void RestockAll()
    {
        foreach (var shop in Shops)
        {
            var entry = RandomUtils.Choice(ItemPool, e =>
            {
                if (_previousStock.Contains(e.Item))
                {
                    return(e.Weight * PreviousStockWeightMod);
                }
                return(e.Weight);
            });
            shop.Restock(entry.Item);
        }

        _previousStock.Clear();

        foreach (var shop in Shops)
        {
            _previousStock.Add(shop.ActiveItem);
        }

        if (RestockEffect != null)
        {
            GameObject.Instantiate(RestockEffect, transform.position, Quaternion.identity);
        }
    }
Exemplo n.º 7
0
 public void SpawnNextChunk()
 {
     if (_lastChunkData != null)
     {
         SpawnNextChunk(RandomUtils.Choice(_lastChunkData.Adjacent, cd => cd.Weight).Chunk);
     }
     else
     {
         SpawnNextChunk(StartChunk);
     }
 }
Exemplo n.º 8
0
    void CreateRoom(Room room)
    {
        Vector3 drawPos = room.gridPos;

        drawPos.x *= 50;//aspect ratio of map sprite
        drawPos.z *= 50;
        var possibleRooms2 = new GameObject[_allRooms.Count];

        _allRooms.CopyTo(possibleRooms2);
        var possibleRooms = possibleRooms2.ToList();

        if (room.doorRight)
        {
            possibleRooms = possibleRooms.Intersect(RoomTemplates.Instance.RightRooms).ToList();
        }
        else
        {
            possibleRooms = possibleRooms.Except(RoomTemplates.Instance.RightRooms).ToList();
        }

        if (room.doorBot)
        {
            possibleRooms = possibleRooms.Intersect(RoomTemplates.Instance.DownRooms).ToList();
        }
        else
        {
            possibleRooms = possibleRooms.Except(RoomTemplates.Instance.DownRooms).ToList();
        }

        if (room.doorTop)
        {
            possibleRooms = possibleRooms.Intersect(RoomTemplates.Instance.UpRooms).ToList();
        }
        else
        {
            possibleRooms = possibleRooms.Except(RoomTemplates.Instance.UpRooms).ToList();
        }

        if (room.doorLeft)
        {
            possibleRooms = possibleRooms.Intersect(RoomTemplates.Instance.LeftRooms).ToList();
        }
        else
        {
            possibleRooms = possibleRooms.Except(RoomTemplates.Instance.LeftRooms).ToList();
        }

        Debug.Log(possibleRooms.Count);
        var placedRoom = RandomUtils.Choice(possibleRooms);

        _lastRoom = Instantiate(placedRoom, drawPos, placedRoom.transform.rotation);
        //_lastRoom.GetComponent<NavMeshSurface>().BuildNavMesh();
    }
Exemplo n.º 9
0
 // Use this for initialization
 void Start()
 {
     for (int x = 0; x < worldWidth; x++)
     {
         for (int y = 0; y < worldHeight; y++)
         {
             Vector3    tilePosition = new Vector3(x * tileSize, y * tileSize, 0);
             GameObject newTile      = GameObject.Instantiate(tile, tilePosition, Quaternion.identity, transform);
             newTile.GetComponent <SpriteRenderer> ().sprite = RandomUtils.Choice(sprites);
         }
     }
 }
Exemplo n.º 10
0
        public void Spawn(GameObject enemyPrefab)
        {
            if (EnemySpawns == null || EnemySpawns.Length == 0)
            {
                Debug.LogWarningFormat("Enemy Spawns is not set for: {0}", name);
                return;
            }

            var spawner = RandomUtils.Choice(EnemySpawns, s => s.Weight);

            var offset2d = Random.insideUnitCircle;
            var offset   = new Vector3(offset2d.x, 0, offset2d.y) * spawner.Radius;

            // Todo: Modify spawn
            var enemy = Instantiate(enemyPrefab, transform.TransformPoint(spawner.Position) + offset, Quaternion.identity);
        }
Exemplo n.º 11
0
        public AIState?StateUpdate()
        {
            if (!_agent.IsAlive())
            {
                return(_fallbackState);
            }

            if (!_agent.HasTarget())
            {
                return(_fallbackState);
            }

            if (!_agent.IsBetweenFearAndAggro())
            {
                return(_fallbackState);
            }

            if (!_agent.CanCast())
            {
                return(_fallbackState);
            }

            // If no intentions to choose from -> fallback
            if (_agent.Config.AI.SlotConfig == null || _agent.Config.AI.SlotConfig.Length == 0)
            {
                return(_fallbackState);
            }

            // Select a slot to cast that is ready;
            var readySlots = _agent.Config.AI.SlotConfig.Where(s =>
            {
                var slotState = _agent.SpellBook.GetSpellSlotState(s.Slot);
                return(slotState.State == SpellbookState.SlotState.Ready);
            }).ToList();

            // Find and randomly choose an active slot
            if (readySlots.Count >= 0)
            {
                var intention = RandomUtils.Choice(readySlots, s => s.Weight);
                _agent.IntendedSpell = intention;
                return(_nextState);
            }

            // No slots to cast
            _agent.Logger.Log("No active slots to cast");
            return(_fallbackState);
        }
Exemplo n.º 12
0
 // Use this for initialization
 void Start()
 {
     for (int i = 0; i < width; i++)
     {
         for (int j = 0; j <= height; j++)
         {
             GameObject tile = Instantiate(prefab, new Vector3(i, j, 0) + transform.position, Quaternion.identity, transform);
             if (j == height)
             {
                 tile.GetComponent <SpriteRenderer> ().sprite = walls;
             }
             else
             {
                 tile.GetComponent <SpriteRenderer> ().sprite = RandomUtils.Choice(floors);
             }
         }
     }
     gameObject.SetActive(false);
 }
Exemplo n.º 13
0
    public Level GetLevel(int index)
    {
        if (index < levels.Length)
        {
            return(levels[index]);
        }

        switch (overflow)
        {
        case LevelOverflow.Loop:
            return(levels[index % levels.Length]);

        case LevelOverflow.Random:
            return(RandomUtils.Choice(levels));

        case LevelOverflow.Clamp:
        default:
            return(levels[Mathf.Min(levels.Length - 1, index)]);
        }
    }
Exemplo n.º 14
0
    public void PlayHitImpactAnimation()
    {
        if (_disabled)
        {
            return;
        }

        _impactTime = ImpactDecayTime;
        if (TakeDamageVariations == null || TakeDamageVariations.Length == 0)
        {
            if (!string.IsNullOrEmpty(TakeDamage))
            {
                Animator.SetTrigger(TakeDamage);
            }
        }
        else
        {
            Animator.SetTrigger(RandomUtils.Choice(TakeDamageVariations));
        }
    }
Exemplo n.º 15
0
        void HandleDeath()
        {
            if (!IsAlive)
            {
                return;
            }

            IsAlive = false;
            if (DropSpells.Count > 0 && Random.value < character.DropRate)
            {
                var spell = RandomUtils.Choice(DropSpells);
                if (spell != null)
                {
                    DroppedSpell.InstantiateDroppedSpell(spell, GetNodeTransform(NodeRole.Chest).position);
                }
            }

            _animationController.PlayDeathAnimation();
            Debug.Log($"<b>{gameObject.name}</b> died");
            Died?.Invoke();
        }
Exemplo n.º 16
0
    public void PlayDeathAnimation()
    {
        if (_disabled)
        {
            return;
        }

        if (DisableAnimationsAfterDeath)
        {
            _disabled = true;
        }
        if (DeathVariations == null || DeathVariations.Length == 0)
        {
            Animator.SetTrigger(DeathTrigger);
        }
        else
        {
            Animator.SetTrigger(RandomUtils.Choice(DeathVariations));
        }
        _impactTime   = ImpactDecayTime;
        _killingFloor = transform.position.y - 3f;
    }
Exemplo n.º 17
0
        private void QueryTargets(List <Target> queried, Query query, Target defaultOrigin)
        {
            queried.Clear();
            var origin = ResolveTarget(query.Origin, defaultOrigin);

            if (!origin.IsValid)
            {
                return;
            }

            switch (query.NewTargetsQueryType)
            {
            case Query.QueryType.None:
                return;

            case Query.QueryType.OriginAsTarget:
                queried.Add(origin);
                return;

            case Query.QueryType.FillAoE:
                FillTargetsInAoe(queried, query.Area, origin);
                return;

            case Query.QueryType.RandomLocationInAoe:
                var randomLoc = RandomLocationInAoe(query.Area, origin);
                queried.Add(new Target(randomLoc, origin.Forward));
                return;

            default:
                break;
            }

            // Find all characters inside AoE and put them inside buffer
            CharactersInAoe(QueriedCharactersBuffer, query.Area, origin);

            // Filter characters
            for (var i = QueriedCharactersBuffer.Count - 1; i >= 0; i--)
            {
                var c = QueriedCharactersBuffer[i];

                // Team filtering
                if (!TargetUtility.IsValidTeam(SpellHandler.Source.Character, c, query.AffectsTeam))
                {
                    QueriedCharactersBuffer.RemoveAt(i);
                    continue;
                }

                // Filter affected
                if (query.ExcludeAlreadyAffected &&
                    _spellHandler.AffectedCharacters != null &&
                    _spellHandler.AffectedCharacters.Contains(c))
                {
                    QueriedCharactersBuffer.RemoveAt(i);
                }
            }

            // If we are empty after filtering
            if (QueriedCharactersBuffer.Count == 0)
            {
                return;
            }

            if (query.NewTargetsQueryType == Query.QueryType.RandomTargetInAoe)
            {
                queried.Add(new Target(RandomUtils.Choice(QueriedCharactersBuffer)));
                return;
            }

            if (query.NewTargetsQueryType == Query.QueryType.AllTargetsInAoe)
            {
                for (var i = 0; i < QueriedCharactersBuffer.Count; i++)
                {
                    queried.Add(new Target(QueriedCharactersBuffer[i]));
                }
                return;
            }

            if (query.NewTargetsQueryType == Query.QueryType.ClosestToOriginInAoe)
            {
                var minDistance = 1e8f;
                var minIndex    = 0;
                var originPos   = origin.Position;
                for (var i = 1; i < QueriedCharactersBuffer.Count; i++)
                {
                    var c        = QueriedCharactersBuffer[i];
                    var distance = Vector3.Distance(originPos, c.transform.position);
                    if (distance < minDistance)
                    {
                        minIndex    = i;
                        minDistance = distance;
                    }
                }

                queried.Add(new Target(QueriedCharactersBuffer[minIndex]));
                return;
            }
        }
Exemplo n.º 18
0
        public void Call(GameContext context)
        {
            var randomActiveUser = RandomUtils.Choice(context.Db.GetActiveUsers().ToList());

            randomActiveUser.Balance = Mathf.Max(0, randomActiveUser.Balance + _amount);
        }
Exemplo n.º 19
0
        public EnemiesConfigurationEntry Sample(int level, ChunkType cType, float budgetRemaining)
        {
            var items = Enemies.Where(e => e.CanSpawn(level, cType, budgetRemaining)).ToList();

            return(RandomUtils.Choice(items, enemy => enemy.GetWeight(level)));
        }
Exemplo n.º 20
0
 public void PlayExplosion(Vector3 position)
 {
     PlayAudio(position, RandomUtils.Choice(explosionSounds));
 }