Merge branch 'dev' of https://github.com/2aurore/Gameton-06 into dev
This commit is contained in:
@@ -4,23 +4,28 @@ namespace TON
|
||||
{
|
||||
public class Attack : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private MonsterBase _monsterBase;
|
||||
|
||||
public void SetMonsterBase(MonsterBase monsterBase)
|
||||
{
|
||||
_monsterBase = monsterBase;
|
||||
}
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D other)
|
||||
{
|
||||
if (other.CompareTag("Player"))
|
||||
{
|
||||
_monsterBase.IsAttacking = true;
|
||||
_monsterBase.IsFinishAttack = false; // 공격 시작 시 FinishAttack 초기화
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void OnTriggerExit2D(Collider2D other)
|
||||
{
|
||||
if (other.CompareTag("Player"))
|
||||
{
|
||||
_monsterBase.IsAttacking = false;
|
||||
_monsterBase.IsFinishAttack = true; // 공격 종료 상태로 설정
|
||||
_monsterBase.IsFinishAttack = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,11 @@ namespace TON
|
||||
[SerializeField]
|
||||
private MonsterBase _monsterBase;
|
||||
|
||||
public void SetMonsterBase(MonsterBase monsterBase)
|
||||
{
|
||||
_monsterBase = monsterBase;
|
||||
}
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D other)
|
||||
{
|
||||
if (other.CompareTag("Player"))
|
||||
|
||||
@@ -33,11 +33,13 @@ namespace TON
|
||||
public bool IsDetect { get; set; } // 몬스터가 대상을 인식했는지 여부
|
||||
public bool IsAttacking { get; set; } // 몬스터가 공격했는지 여부
|
||||
public bool IsFinishAttack { get; set; } // 몬스터 공격 모션이 끝났는지 여부
|
||||
public bool IsSkillAttackable => _skillPattern.IsAttackable;
|
||||
public bool IsSkillAttackable;
|
||||
|
||||
public int Gold = 0;
|
||||
public int Exp = 0;
|
||||
public int Score = 0;
|
||||
|
||||
private CharacterBase _characterBase;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
@@ -49,13 +51,29 @@ namespace TON
|
||||
|
||||
InitializeMonsterData(); // 몬스터 데이터 로드 및 적용
|
||||
|
||||
_skillPattern = new Monster1SkillPattern(_monsterData, this);
|
||||
if (_monsterData.monsterSkillID != 0)
|
||||
{
|
||||
_skillPattern = new MonsterSkillPattern(_monsterData, this);
|
||||
IsSkillAttackable = _skillPattern.IsAttackable;
|
||||
}
|
||||
|
||||
_direction = new Vector3(1, 0, 0); // 초기 이동 방향 (x 축 양의 방향)
|
||||
|
||||
_spriteRenderer.flipX = !(_direction.x > 0); // 이동 방향에 따라 스프라이트 플립
|
||||
|
||||
_collider = GetComponent<Collider2D>(); // 콜라이더 컴포넌트 초기화
|
||||
|
||||
// CharacterBase 참조 설정
|
||||
_characterBase = GameObject.Find("TON.Player").GetComponentInChildren<CharacterBase>();
|
||||
|
||||
// HP 바 초기화
|
||||
if (_hpBarImage != null)
|
||||
{
|
||||
RectTransform rectTransform = _hpBarImage.GetComponent<RectTransform>();
|
||||
hpMaxWidth = rectTransform.sizeDelta.x; // 초기 최대 너비 저장
|
||||
_maxHP = _monsterData.hp;
|
||||
currentHP = _maxHP;
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializeMonsterData()
|
||||
@@ -64,7 +82,8 @@ namespace TON
|
||||
|
||||
if (_monsterData != null)
|
||||
{
|
||||
currentHP = _monsterData.hp;
|
||||
_maxHP = _monsterData.hp;
|
||||
currentHP = _maxHP;
|
||||
defencePower = _monsterData.defencePower;
|
||||
Gold = _monsterData.Gold;
|
||||
Exp = _monsterData.Exp;
|
||||
@@ -93,7 +112,11 @@ namespace TON
|
||||
private void Update()
|
||||
{
|
||||
_stateMachine.Update();
|
||||
_skillPattern.Update();
|
||||
|
||||
if (_monsterData.monsterSkillID != 0)
|
||||
{
|
||||
_skillPattern.Update();
|
||||
}
|
||||
}
|
||||
|
||||
public void FinishAttack()
|
||||
@@ -123,10 +146,23 @@ namespace TON
|
||||
{
|
||||
if (_hpBarImage != null)
|
||||
{
|
||||
float minHPBarWidth = 5f; // 최소 HP 바 길이 (원하는 값으로 설정)
|
||||
float hpBarWidth = Mathf.Max(currentHP / _maxHP * hpMaxWidth, minHPBarWidth); // 최소 길이 적용
|
||||
|
||||
_hpBarImage.GetComponent<RectTransform>().sizeDelta = new Vector2(hpBarWidth, _hpBarImage.GetComponent<RectTransform>().sizeDelta.y);
|
||||
// 현재 HP가 0 이하로 내려가지 않도록 보정
|
||||
currentHP = Mathf.Max(0, currentHP);
|
||||
|
||||
// HP 비율 계산 (0~1 사이 값)
|
||||
float hpRatio = currentHP / _maxHP;
|
||||
|
||||
// RectTransform 컴포넌트 가져오기
|
||||
RectTransform rectTransform = _hpBarImage.GetComponent<RectTransform>();
|
||||
|
||||
// 현재 크기 가져오기
|
||||
Vector2 sizeDelta = rectTransform.sizeDelta;
|
||||
|
||||
// x 크기를 HP 비율에 따라 조정
|
||||
sizeDelta.x = hpMaxWidth * hpRatio;
|
||||
|
||||
// 변경된 크기 적용
|
||||
rectTransform.sizeDelta = sizeDelta;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,7 +178,9 @@ namespace TON
|
||||
// 기본 데미지 계산 (치명타 없음)
|
||||
float damage = damageCalculator.CalculateBaseDamage(baseAttack, equipmentAttack, defense);
|
||||
|
||||
Debug.Log($" 몬스터 공격! 최종 데미지: {damage}"); // 데미지 출력
|
||||
_characterBase.ApplyDamage(damage);
|
||||
|
||||
// Debug.Log($" 몬스터 공격! 최종 데미지: {damage}"); // 데미지 출력
|
||||
}
|
||||
|
||||
public void SetOppositionDirection()
|
||||
@@ -158,8 +196,8 @@ namespace TON
|
||||
|
||||
public void Chasing()
|
||||
{
|
||||
var target = GameObject.FindGameObjectWithTag("Player");
|
||||
UnityEngine.Vector2 direction = target.transform.position - transform.position; // 타겟과의 방향 계산
|
||||
var target = GameObject.Find("TON.Player").GetComponentInChildren<CharacterBase>();
|
||||
Vector2 direction = target.transform.position - transform.position; // 타겟과의 방향 계산
|
||||
_spriteRenderer.flipX = target.transform.position.x < transform.position.x; // 타겟이 왼쪽에 있으면 스프라이트를 왼쪽으로, 오른쪽에 있으면 오른쪽으로 바라보도록 설정
|
||||
|
||||
transform.Translate(direction.normalized * moveSpeed * Time.deltaTime); // 타겟 방향으로 이동
|
||||
@@ -179,5 +217,10 @@ namespace TON
|
||||
RewardData();
|
||||
Destroy(gameObject); // 몬스터 파괴
|
||||
}
|
||||
|
||||
public SkillPattern GetSkillPattern()
|
||||
{
|
||||
return _skillPattern;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,12 +5,13 @@ namespace TON
|
||||
public class MonsterSkill : MonoBehaviour
|
||||
{
|
||||
public float speed = 5f;
|
||||
public float damage = 1;
|
||||
|
||||
public float damage = 0f;
|
||||
|
||||
Vector2 direction;
|
||||
Transform playerTransform; // 플레이어의 Transform을 저장할 변수
|
||||
[SerializeField] private SpriteRenderer _spriteRenderer; // 스킬의 스프라이트 렌더러
|
||||
|
||||
private MonsterBase _monsterBase;
|
||||
private CharacterBase _characterBase;
|
||||
public Vector2 Direction
|
||||
{
|
||||
set { direction = value.normalized; }
|
||||
@@ -20,11 +21,11 @@ namespace TON
|
||||
{
|
||||
_spriteRenderer = GetComponent<SpriteRenderer>();
|
||||
|
||||
GameObject player = GameObject.FindGameObjectWithTag("Player");
|
||||
|
||||
if (player != null)
|
||||
_characterBase = GameObject.Find("TON.Player").GetComponentInChildren<CharacterBase>();
|
||||
|
||||
if (_characterBase != null)
|
||||
{
|
||||
playerTransform = player.transform;
|
||||
playerTransform = _characterBase.transform;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -42,10 +43,22 @@ namespace TON
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D collision)
|
||||
{
|
||||
if (collision.CompareTag("Player") || collision.CompareTag("Ground"))
|
||||
if (collision.CompareTag("Player"))
|
||||
{
|
||||
// 플레이어에게 직접 데미지 적용
|
||||
_characterBase?.ApplyDamage(damage);
|
||||
Destroy(gameObject);
|
||||
}
|
||||
else if (collision.CompareTag("Ground"))
|
||||
{
|
||||
// 지형에 부딪히면 스킬 오브젝트만 파괴
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetSkillDamage(float skillDamage)
|
||||
{
|
||||
damage += skillDamage;
|
||||
}
|
||||
|
||||
void SetDirection()
|
||||
|
||||
@@ -19,6 +19,9 @@ namespace TON
|
||||
private const int TOTAL_WAVES = 10;
|
||||
private const int NORMAL_MONSTER_COUNT = 6;
|
||||
|
||||
private float initialDelay = 5f; // 게임 시작 후 첫 웨이브 시작까지의 대기 시간
|
||||
private bool gameStarted = false;
|
||||
|
||||
private float nextWaveDelay = 5f; // 다음 웨이브 시작 전 대기 시간
|
||||
private bool isWaitingForNextWave = false;
|
||||
|
||||
@@ -44,12 +47,39 @@ namespace TON
|
||||
availableSpawnPoints = new List<int>();
|
||||
activeMonsters = new List<GameObject>();
|
||||
|
||||
// 5초 후에 첫 웨이브 시작
|
||||
StartCoroutine(StartGameWithDelay());
|
||||
}
|
||||
|
||||
private IEnumerator StartGameWithDelay()
|
||||
{
|
||||
// 초기 카운트다운 표시
|
||||
float timer = initialDelay;
|
||||
while (timer > 0)
|
||||
{
|
||||
if (waveCounter != null)
|
||||
{
|
||||
waveCounter.text = Mathf.CeilToInt(timer).ToString();
|
||||
}
|
||||
timer -= Time.deltaTime;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
if (waveCounter != null)
|
||||
{
|
||||
waveCounter.text = null;
|
||||
}
|
||||
|
||||
gameStarted = true;
|
||||
StartNextWave();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
// 게임이 시작되지 않았다면 업데이트 건너뛰기
|
||||
if (!gameStarted) return;
|
||||
|
||||
// 활성화된 몬스터 리스트에서 파괴된 몬스터 제거
|
||||
activeMonsters.RemoveAll(monster => monster == null);
|
||||
|
||||
@@ -77,10 +107,10 @@ namespace TON
|
||||
|
||||
private void StartNextWave()
|
||||
{
|
||||
currentWave++;
|
||||
|
||||
StageManager.Singleton.SetWaveData(currentWave); // 웨이브 정보 전달.
|
||||
|
||||
currentWave++;
|
||||
|
||||
if (currentWave > TOTAL_WAVES)
|
||||
{
|
||||
// Debug.Log("모든 웨이브 완료!");
|
||||
@@ -130,9 +160,26 @@ namespace TON
|
||||
{
|
||||
foreach (Transform spawnPoint in spawnPoints)
|
||||
{
|
||||
GameObject normalMonster = Instantiate(GetNormalMonsterPrefab(), spawnPoint.position, Quaternion.identity);
|
||||
monsterPool.Add(normalMonster);
|
||||
activeMonsters.Add(normalMonster);
|
||||
GameObject monsterPrefab = GetNormalMonsterPrefab();
|
||||
Vector3 spawnPosition = spawnPoint.position;
|
||||
|
||||
GameObject monster = Instantiate(monsterPrefab, spawnPosition, Quaternion.identity);
|
||||
monster.transform.parent = transform;
|
||||
|
||||
// MonsterBase 컴포넌트 가져오기
|
||||
MonsterBase monsterBase = monster.GetComponent<MonsterBase>();
|
||||
|
||||
// Attack과 Eyesight 컴포넌트 찾아서 MonsterBase 참조 설정
|
||||
Attack attackComponent = monster.GetComponentInChildren<Attack>();
|
||||
Eyesight eyesightComponent = monster.GetComponentInChildren<Eyesight>();
|
||||
|
||||
if (attackComponent != null)
|
||||
attackComponent.SetMonsterBase(monsterBase);
|
||||
if (eyesightComponent != null)
|
||||
eyesightComponent.SetMonsterBase(monsterBase);
|
||||
|
||||
monsterPool.Add(monster);
|
||||
activeMonsters.Add(monster);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -143,9 +190,26 @@ namespace TON
|
||||
{
|
||||
foreach (Transform spawnPoint in spawnPoints)
|
||||
{
|
||||
GameObject normalMonster = Instantiate(GetNormalMonsterPrefab(), spawnPoint.position, Quaternion.identity);
|
||||
monsterPool.Add(normalMonster);
|
||||
activeMonsters.Add(normalMonster);
|
||||
GameObject monsterPrefab = GetNormalMonsterPrefab();
|
||||
Vector3 spawnPosition = spawnPoint.position;
|
||||
|
||||
GameObject monster = Instantiate(monsterPrefab, spawnPosition, Quaternion.identity);
|
||||
monster.transform.parent = transform;
|
||||
|
||||
// MonsterBase 컴포넌트 가져오기
|
||||
MonsterBase monsterBase = monster.GetComponent<MonsterBase>();
|
||||
|
||||
// Attack과 Eyesight 컴포넌트 찾아서 MonsterBase 참조 설정
|
||||
Attack attackComponent = monster.GetComponentInChildren<Attack>();
|
||||
Eyesight eyesightComponent = monster.GetComponentInChildren<Eyesight>();
|
||||
|
||||
if (attackComponent != null)
|
||||
attackComponent.SetMonsterBase(monsterBase);
|
||||
if (eyesightComponent != null)
|
||||
eyesightComponent.SetMonsterBase(monsterBase);
|
||||
|
||||
monsterPool.Add(monster);
|
||||
activeMonsters.Add(monster);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,118 +14,81 @@ namespace TON
|
||||
}
|
||||
|
||||
public bool IsAttackable { get; set; }
|
||||
|
||||
public abstract bool IsSkillInCooldown();
|
||||
|
||||
public abstract void Attack(GameObject target);
|
||||
|
||||
|
||||
public abstract void Update();
|
||||
}
|
||||
|
||||
public class Monster1SkillPattern : SkillPattern
|
||||
public class MonsterSkillPattern : SkillPattern
|
||||
{
|
||||
private float _skill1CoolTime;
|
||||
// private float _skill2CoolTime;
|
||||
|
||||
private float _lastSkillTime;
|
||||
private MonsterSkillData _monsterSkillData;
|
||||
// private MonsterSkillData _monsterSkillDataTwo;
|
||||
|
||||
private MonsterSkill _skill1;
|
||||
// private MonsterSkill _skill2;
|
||||
private MonsterSkill _skill;
|
||||
private Vector3 _skillOffset = new Vector3(0, -0.5f, 0);
|
||||
|
||||
private Vector3 _skillOffset = new Vector3(0, -0.5f, 0); // 스킬 생성 위치 조정값
|
||||
|
||||
public Monster1SkillPattern(MonsterData monsterData, MonsterBase monsterBase) : base(monsterData, monsterBase)
|
||||
public MonsterSkillPattern(MonsterData monsterData, MonsterBase monsterBase) : base(monsterData, monsterBase)
|
||||
{
|
||||
_monsterSkillData = MonsterSkillDataManager.Singleton.GetMonsterSkillData(_monsterData.monsterSkillID);
|
||||
// if (_monsterData.monsterSkillIDTwo > -1)
|
||||
// {
|
||||
// _monsterSkillDataTwo = MonsterSkillDataManager.Singleton.GetMonsterSkillData(_monsterData.monsterSkillIDTwo);
|
||||
// }
|
||||
|
||||
// if (_monsterSkillData != null && _monsterSkillDataTwo != null)
|
||||
_lastSkillTime = -_monsterSkillData.cooldown; // 시작시 스킬 사용 가능하도록
|
||||
IsAttackable = true;
|
||||
|
||||
if (_monsterSkillData != null)
|
||||
{
|
||||
|
||||
Debug.Log($"몬스터 {_monsterSkillData.skillName} 데이터 로드 완료");
|
||||
// Debug.Log($"몬스터 {_monsterSkillDataTwo.skillName} 데이터 로드 완료");
|
||||
|
||||
// 프리팹을 연결한 코드
|
||||
_skill1 = Resources.Load<MonsterSkill>($"MonsterSkillPrefabs/{_monsterSkillData.skillName}");
|
||||
// _skill2 = Resources.Load<MonsterSkill>($"MonsterSkillPrefabs/{_monsterSkillDataTwo.skillName}");
|
||||
// Debug.Log($"몬스터 {_monsterSkillData.skillName} 데이터 로드 완료");
|
||||
_skill = Resources.Load<MonsterSkill>($"MonsterSkillPrefabs/{_monsterSkillData.skillName}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"몬스터 스킬 ID {_monsterSkillData.skillId}에 대한 데이터를 찾을 수 없습니다.");
|
||||
// Debug.LogError($"몬스터 스킬 ID {_monsterSkillDataTwo.skillId}에 대한 데이터를 찾을 수 없습니다.");
|
||||
}
|
||||
|
||||
_skill1CoolTime = Time.realtimeSinceStartup;
|
||||
// _skill2CoolTime = Time.realtimeSinceStartup;
|
||||
|
||||
}
|
||||
|
||||
public override void Attack(GameObject target)
|
||||
{
|
||||
if (target == null) return;
|
||||
|
||||
// 스킬 스프라이트 방향 플레이어 바라보게
|
||||
_monsterBase.GetComponent<SpriteRenderer>().flipX = target.transform.position.x < _monsterBase.transform.position.x;
|
||||
// 몬스터의 현재 위치에서 offset만큼 아래에 스킬 생성
|
||||
Vector3 spawnPosition = _monsterBase.transform.position - _skillOffset;
|
||||
|
||||
// 프리팹을 지정된 위치에 생성
|
||||
Object.Instantiate(_skill1, spawnPosition, Quaternion.identity);
|
||||
|
||||
Object.Instantiate(_skill, spawnPosition, Quaternion.identity);
|
||||
SkillAttack(_monsterSkillData.damage);
|
||||
|
||||
// 스킬 사용 후 쿨다운 시작
|
||||
_lastSkillTime = Time.time;
|
||||
IsAttackable = false;
|
||||
|
||||
// Debug.Log($"스킬 사용, 쿨다운 시작: {_monsterSkillData.cooldown}초");
|
||||
}
|
||||
|
||||
public void SkillAttack(float skillDamage)
|
||||
{
|
||||
// 데미지 계산 (현재 임시 값)
|
||||
DamageCalculator damageCalculator = new DamageCalculator();
|
||||
|
||||
float baseAttack = _monsterData.attackPower * skillDamage; // 기본 공격력 * 스킬 데미지
|
||||
float equipmentAttack = 0; // 장비 공격력
|
||||
float defense = PlayerDataManager.Singleton.player.defensivePower / (PlayerDataManager.Singleton.player.defensivePower + PlayerDataManager.Singleton.defensiveIntention); // 캐릭터 방어력
|
||||
|
||||
// 기본 데미지 계산 (치명타 없음)
|
||||
float damage = damageCalculator.CalculateBaseDamage(baseAttack, equipmentAttack, defense);
|
||||
|
||||
_skill.SetSkillDamage(damage);
|
||||
|
||||
// Debug.Log($" 몬스터 스킬 공격! 최종 데미지: {damage}"); // 데미지 출력
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
if (Time.realtimeSinceStartup - _skill1CoolTime >= _monsterSkillData.cooldown)
|
||||
// 스킬 쿨다운 체크
|
||||
if (!IsAttackable && Time.time - _lastSkillTime >= _monsterSkillData.cooldown)
|
||||
{
|
||||
// TODO : 범위 체크
|
||||
IsAttackable = true;
|
||||
// Debug.Log("스킬 쿨다운 완료");
|
||||
}
|
||||
|
||||
// if (Time.realtimeSinceStartup - _skill2CoolTime >= _monsterSkillDataTwo.cooldown)
|
||||
// {
|
||||
// // TODO : 범위 체크
|
||||
// IsAttackable = true;
|
||||
// }
|
||||
}
|
||||
|
||||
public override bool IsSkillInCooldown()
|
||||
{
|
||||
return !IsAttackable;
|
||||
}
|
||||
}
|
||||
|
||||
// public class Monster2AttackPattern : AttackPattern
|
||||
// {
|
||||
//
|
||||
//
|
||||
// public Monster2AttackPattern(MonsterBase monsterBase) : base(monsterBase)
|
||||
// {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// public override void Attack()
|
||||
// {
|
||||
//
|
||||
// Skill1();
|
||||
//
|
||||
// Skill2();
|
||||
//
|
||||
// MeleeAttack();
|
||||
//
|
||||
// }
|
||||
//
|
||||
// private void Skill1()
|
||||
// {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// private void Skill2()
|
||||
// {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// private void MeleeAttack()
|
||||
// {
|
||||
// _monsterBase.PlayerAttack();
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -245,7 +245,7 @@ namespace TON
|
||||
private const string AniAttack = "Attack"; // 공격 애니메이션
|
||||
private MonsterBase _monsterBase;
|
||||
private float _skillAttackAnimationDuration = 0.5f; // 공격 애니메이션 지속 시간
|
||||
private float _skillAttackDelayTime = 2f; // 공격 딜레이 시간
|
||||
private float _skillAttackDelayTime = 10f; // 공격 딜레이 시간
|
||||
private float _lastSkillAttackTime; // 마지막 공격 시간
|
||||
|
||||
private bool _isSkillAttacking;
|
||||
|
||||
Reference in New Issue
Block a user