[Feature] 전투 시스템 기반 구현 (엔티티, 웨이브, 자동 전투, 스킬 트리) #18
[Feature] 전투 시스템 기반 구현 (엔티티, 웨이브, 자동 전투, 스킬 트리) #18
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a comprehensive battle loop and skill tree system for a 2D idle RPG. It includes core entity management, automated combat logic via state machines, and a flexible skill tree architecture using the Strategy pattern to support different class-specific progression rules. Key feedback focuses on preventing potential runtime crashes during enemy spawning, optimizing performance by caching component references instead of repeated lookups in loops, and correcting a logic issue where applying stat modifiers unintentionally fully heals the entity.
| /// 웨이브 데이터에 따라 적을 스폰한다. | ||
| /// 스폰된 Enemy 인스턴스 목록을 반환한다. | ||
| /// </summary> | ||
| public List<Enemy> SpawnWave(WaveData waveData, Transform[] spawnPoints) |
There was a problem hiding this comment.
| { | ||
| // Enemy 프리팹에 AttackCollider가 있으면 Attack()으로 애니메이션+충돌 처리. | ||
| // AttackCollider가 없는 경우 DamageCalculator로 직접 피해 적용. | ||
| if (HasAttackCollider()) |
| MaxHp = statData.Hp + modifier.BonusHp; | ||
| Hp = MaxHp; |
There was a problem hiding this comment.
ApplyStatModifier가 호출될 때마다 Hp가 MaxHp로 재설정되어 체력이 완전히 회복됩니다. 이는 스킬 트리에서 패시브 스킬을 해금할 때마다 플레이어의 체력이 가득 차는 의도치 않은 동작을 유발할 수 있습니다. 체력을 완전히 회복시키는 대신, 기존 체력 비율을 유지하는 방식으로 수정해야 합니다.
float hpPercentage = MaxHp > 0 ? (float)Hp / MaxHp : 1f;
MaxHp = statData.Hp + modifier.BonusHp;
Hp = Mathf.RoundToInt(MaxHp * hpPercentage);| foreach (Enemy e in _currentWaveEnemies) | ||
| e.GetComponent<EnemyAI>()?.Initialize(_player); |
| { | ||
| // Enemy 프리팹에 AttackCollider가 있으면 Attack()으로 애니메이션+충돌 처리. | ||
| // AttackCollider가 없는 경우 DamageCalculator로 직접 피해 적용. | ||
| if (HasAttackCollider()) |
There was a problem hiding this comment.
GetComponentInChildren은 비용이 매우 큰 연산이므로 AttackCollider를 캐싱하거나 bool값을 캐싱해서 사용하는 것을 권장합니다
There was a problem hiding this comment.
혹시 런타임에 AttackCollider를 추가/삭제 하는 방식을 사용하고 계신가요?
|
안녕하세요! 전투 시스템 구현에 대한 코드 리뷰를 요청해주셔서 감사합니다. 구현하신 전투 시스템의 구조와 데이터 기반 설계는 매우 체계적입니다. 특히 전략 패턴을 활용한 스킬 트리 구현과 ScriptableObject를 통한 데이터 관리는 유지보수 측면에서 훌륭한 접근 방식입니다. 전체적인 코드 흐름을 검토한 결과, 몇 가지 개선 제안을 드립니다. 1.
|
|
안녕하세요! 추가적인 질문이나 도움이 필요하신가요? 구현하신 전투 시스템에 대해 궁금한 점이 있으시거나, 코드 리뷰에서 제안드린 내용 중 추가 설명이 필요하시면 언제든 말씀해주세요. |
내용
변경 사항
전투 시스템 (
Assets/Scripts/Battle/)Entity.cs— HP, 공격력,TakeDamage(),Death()기반 클래스Player/Player.cs,Player/Warrior.cs— 플레이어 계열Enemy/Enemy.cs,Enemy/EnemyAI.cs,Enemy/TestEnemy.cs— 적 계열 및 AIBattleManager.cs— 전투 흐름 전체 관리 (던전 진입/종료, 웨이브 순서 제어)WaveController.cs— 웨이브 단위 적 스폰 및 클리어 감지AutoAttackController.cs— 자동 공격 루프AttackCollider.cs— 2D Trigger 기반 히트 판정, 타겟 지정 수정데이터 구조 (
Assets/Scripts/Battle/Data/)DungeonData.cs,WaveData.cs,EnemyRewardData.cs— 던전/웨이브/보상 데이터 클래스TestDungeonData,TestWaveData,TestRewardDataCore 시스템 (
Assets/Scripts/Core/)EntityStatData.cs— 스탯 ScriptableObjectEntityStatModifier.cs— 스탯 수정자DamageCalculator.cs— 데미지 계산 로직SkillData.cs— 스킬 데이터 기반 클래스스킬 트리 (
Assets/Scripts/Core/SkillTree/)SkillTreeData.cs,SkillNodeData.cs,SkillTreeComponent.csBranchingTreeStrategy(검사),LinearTreeStrategy(법사),RowSelectTreeStrategy(궁수)재화 시스템 (
Assets/Scripts/Core/Goods/)SO_Goods.cs(추상),SO_Gold,SO_XP,SO_SP,SO_Mithril,SO_UpgradeScroll씬 및 프리팹
Assets/Scenes/BattleTestScene.unity— 전투 테스트용 씬Assets/Prefabs/Enemy/Enemy.prefab— 적 프리팹테스트