반응형
오늘의 목표
- 증강 시스템 추가
- 임시 보스 몬스터 추가
- 버프/디버프 시스템 적용
특정 패턴(보스 잡기)등이 끝난 후 증강을 고를 수 있는 카드를 출력하고 선택하게 하는 기능을 구현하였습니다.
|
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
using UnityEngine;
public class AugmentSystem : MonoBehaviour
{
[Header("UI")]
[SerializeField] private AugmentChoiceUI augmentUI;
[Header("Pool")]
[SerializeField] private AugmentSO[] augmentPool;
public bool IsChoosing { get; private set; }
private readonly AugmentSO[] _offered = new AugmentSO[3];
private System.Action _onChoiceComplete;
// 누적값 (런 동안 유지)
private float _towerDamageMul = 1f;
private float _towerAttackSpeedMul = 1f;
private float _towerRangeAdd = 0f;
private float _enemySpeedMul = 1f;
private float _enemyHpMul = 1f;
public float TowerDamageMul => _towerDamageMul;
public float TowerAttackSpeedMul => _towerAttackSpeedMul;
public float TowerRangeAdd => _towerRangeAdd;
public float EnemySpeedMul => _enemySpeedMul;
public float EnemyHpMul => _enemyHpMul;
public void BeginChoice(System.Action onChoiceComplete)
{
if (IsChoosing)
return;
if (augmentUI == null)
{
Debug.LogWarning("[AugmentSystem] augmentUI is null. Skip choice.");
onChoiceComplete?.Invoke();
return;
}
IsChoosing = true;
_onChoiceComplete = onChoiceComplete;
RollOptions(_offered);
Time.timeScale = 0f;
augmentUI.Show(_offered, OnPicked);
}
private void OnPicked(AugmentSO picked)
{
if (!IsChoosing)
return;
if (picked != null)
{
ApplyAugment(picked);
RefreshAllTowers();
}
if (augmentUI != null)
augmentUI.Hide();
Time.timeScale = 1f;
IsChoosing = false;
var cb = _onChoiceComplete;
_onChoiceComplete = null;
cb?.Invoke();
}
private void RefreshAllTowers()
{
TowerBase[] towers = FindObjectsOfType<TowerBase>();
for (int i = 0; i < towers.Length; i++)
{
if (towers[i] != null)
towers[i].RefreshStats();
}
}
private void RollOptions(AugmentSO[] outArr)
{
for (int i = 0; i < outArr.Length; i++)
outArr[i] = null;
if (augmentPool == null || augmentPool.Length == 0)
return;
int filled = 0;
int safety = 0;
while (filled < outArr.Length && safety < 200)
{
safety++;
AugmentSO pick = augmentPool[Random.Range(0, augmentPool.Length)];
if (pick == null) continue;
bool dup = false;
for (int j = 0; j < filled; j++)
{
if (outArr[j] == pick) { dup = true; break; }
}
if (dup) continue;
outArr[filled] = pick;
filled++;
}
}
private void ApplyAugment(AugmentSO a)
{
if (a == null) return;
// 타워 버프
if (a.target == AugmentTarget.Tower)
{
switch (a.type)
{
case AugmentType.TowerDamageMul:
_towerDamageMul *= a.value;
break;
case AugmentType.TowerAttackSpeedMul:
_towerAttackSpeedMul *= a.value;
break;
case AugmentType.TowerRangeAdd:
_towerRangeAdd += a.value;
break;
}
return;
}
// 적 디버프
if (a.target == AugmentTarget.Enemy)
{
switch (a.type)
{
case AugmentType.EnemySpeedMul:
_enemySpeedMul *= a.value;
break;
case AugmentType.EnemyHpMul:
_enemyHpMul *= a.value;
break;
}
}
}
}
|
cs |
|
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
|
using UnityEngine;
public enum AugmentTarget
{
Tower,
Enemy
}
public enum AugmentType
{
// Tower buffs
TowerDamageMul,
TowerAttackSpeedMul,
TowerRangeAdd,
// Enemy debuffs
EnemySpeedMul,
EnemyHpMul
}
[CreateAssetMenu(menuName = "RTD/Augment/Augment", fileName = "Augment_")]
public class AugmentSO : ScriptableObject
{
public string augmentId;
public string title;
[TextArea] public string desc;
public AugmentTarget target;
public AugmentType type;
public float value = 1f;
}
|
cs |
선택 된 증강에 따라 타워 혹은 몬스터들에게 버프/디버프 값을 적용합니다.
선택 된 증강에 해당하는 값을 AugmentSystem에 누적하여 저장하고
GameManager를 통하여 타워와 몬스터들에게 적용합니다.
반응형
'게임 개발 > 랜덤 타워 디펜스' 카테고리의 다른 글
| [랜덤 타워 디펜스] Day 8 몬스터 Wave별 추가 스탯 적용 (0) | 2026.01.02 |
|---|---|
| [랜덤 타워 디펜스] 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 |