반응형
오늘의 목표
- 몬스터 웨이브 별 추가 속성(스탯) 적용
- 웨이브 증가 기능 추가 구현
몬스터에 스탯을 적용하기 위한 클래스 추가 후 몬스터 스포너에서 생성을 하는 시점에 몬스터의
ApplyWaveModifiers
함수를 호출하여 스탯을 적용시킵니다.
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
using System.Collections.Generic;
using UnityEngine;
public static class WaveModifierRoller
{
private enum ModType
{
SpeedUp,
Tanky,
Shield
}
private struct WeightedMod
{
public ModType type;
public int weight;
public WeightedMod(ModType t, int w) { type = t; weight = w; }
}
private static readonly Dictionary<ModType, float> SpeedMul = new Dictionary<ModType, float>
{
{ ModType.SpeedUp, 1.25f }
};
private static readonly Dictionary<ModType, float> HpMul = new Dictionary<ModType, float>
{
{ ModType.Tanky, 1.50f }
};
private static readonly Dictionary<ModType, int> ShieldHp = new Dictionary<ModType, int>
{
{ ModType.Shield, 30 }
};
private static readonly WeightedMod[] Pool =
{
new WeightedMod(ModType.SpeedUp, 40),
new WeightedMod(ModType.Tanky, 35),
new WeightedMod(ModType.Shield, 25),
};
public static WaveModifiers Roll(int minCount, int maxCount)
{
int count = Random.Range(minCount, maxCount + 1);
// Copy pool to list for no-duplicate draws
List<WeightedMod> temp = new List<WeightedMod>(Pool);
WaveModifiers result = new WaveModifiers
{
speedMul = 1f,
hpMul = 1f,
shieldHp = 0,
label = ""
};
List<string> labels = new List<string>();
for (int i = 0; i < count; i++)
{
if (temp.Count == 0)
break;
int pickedIndex = PickWeightedIndex(temp);
ModType picked = temp[pickedIndex].type;
temp.RemoveAt(pickedIndex);
ApplyOne(ref result, picked, labels);
}
result.label = labels.Count == 0 ? "None" : string.Join(", ", labels);
return result;
}
private static int PickWeightedIndex(List<WeightedMod> list)
{
int total = 0;
for (int i = 0; i < list.Count; i++)
total += list[i].weight;
int r = Random.Range(0, total);
int acc = 0;
for (int i = 0; i < list.Count; i++)
{
acc += list[i].weight;
if (r < acc)
return i;
}
return list.Count - 1;
}
private static void ApplyOne(ref WaveModifiers mods, ModType type, List<string> labels)
{
switch (type)
{
case ModType.SpeedUp:
mods.speedMul *= SpeedMul[type];
labels.Add("SpeedUp");
break;
case ModType.Tanky:
mods.hpMul *= HpMul[type];
labels.Add("Tanky");
break;
case ModType.Shield:
mods.shieldHp += ShieldHp[type];
labels.Add("Shield");
break;
}
}
}
|
cs |
|
1
2
3
4
5
6
7
8
9
10
|
using System;
[Serializable]
public struct WaveModifiers
{
public float speedMul; // 1.25f
public float hpMul; // 1.50f
public int shieldHp; // +30
public string label; // "SpeedUp, Shield"
}
|
cs |
게임 매니저에서 다음 스테이지를 호출 할 수 있는 함수를 만들어 호출하는 방식으로 다음 스테이지를 불러옵니다.
|
1
2
3
4
5
6
7
8
9
10
|
public void NextWave()
{
currentWave++;
if (currentWave > maxWave)
currentWave = maxWave;
UIManager.Instance.UpdateWave(currentWave, maxWave);
StartWave(currentWave);
}
|
cs |
반응형
'게임 개발 > 랜덤 타워 디펜스' 카테고리의 다른 글
| [랜덤 타워 디펜스] Day 9 버프/디버프 시스템 (0) | 2026.01.08 |
|---|---|
| [랜덤 타워 디펜스] Day 7 타워 투사체 및 연출 구현 (0) | 2025.12.30 |
| [랜덤 타워 디펜스] Day 6 타워 랜덤 생성 시스템 구현 (0) | 2025.12.27 |
| [랜덤 타워 디펜스] Day 5 타워 데이터 셋팅 및 합성 시스템 (0) | 2025.12.21 |
| [랜덤 타워 디펜스] Day 4 기초 UI 및 타워 건설 (0) | 2025.12.12 |