Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using System.Linq;
- using PlinioJRM.Entities;
- using UnityEngine;
- namespace PlinioJRM.Systems.Waves {
- public struct SpawnData {
- public List<EnemyType> enemies;
- }
- public class WaveGenerator {
- private List<WaveGenerationRule> _rules;
- private bool _isGroup;
- private int _groupChance;
- private EnemyType _defaultEnemy;
- public WaveGenerator(
- List<WaveGenerationRule> rules,
- EnemyType defaultEnemy,
- bool isGroup = false,
- int groupChance = 0) {
- _rules = rules.OrderBy(R => R.chance).ToList();
- _defaultEnemy = defaultEnemy;
- _isGroup = isGroup;
- _groupChance = groupChance;
- }
- public SpawnData GenerateSpawnInfo() {
- float RandomRoll() {
- int roll = Random.Range(0, 10000);
- return (float)roll / 100;
- }
- SpawnData data = new () {
- enemies = new List<EnemyType>()
- };
- if (!_isGroup) {
- data.enemies.Add(Roll());
- return data;
- }
- float chance = _groupChance;
- float chanceRoll = 100f;
- while (chanceRoll <= chance) {
- data.enemies.Add(Roll());
- chance *= 0.12f;
- chanceRoll = RandomRoll();
- };
- return data;
- }
- private EnemyType Roll() {
- int chance = Random.Range(0, 100);
- foreach (WaveGenerationRule rule in _rules) {
- if (chance <= rule.chance)
- return rule.enemyType;
- }
- return _defaultEnemy;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement