오늘의 학습 키워드
Callback
공부한 내용
단일 타겟 스킬과 다중 타겟 스킬 나누기
단일 타겟 스킬과 다중 타겟 스킬을 나누기 위해 공통이라는 Skill을 두고 타입에 따라 스킬을 사용하는 콜백을 등록해 사용하도록 구현하였다.
나중에 배틀 로직을 구현하는 팀원의 작업이 끝났을 때 콜백으로 받을지 말지를 정해야겠다. - 이번 개인 과제 피드백 시간에 콜백이 디버깅 과정에서 추적하기 어렵다는 단점이 있다고 배웠다.
namespace TextRPG_Team
{
public enum SkillType
{
SigleTarget,
MultipleTarget
}
public class SigleSkill : Skill
{
Action<string, float, float> skill;
public SigleSkill(string name, string description, int cost, float damage, float damageMod, Action<string, float, float> skillAction) : base(name, description, SkillType.SigleTarget, cost, damage, damageMod)
{
skill = skillAction;
}
public void UseSkill(string target)
{
skill?.Invoke(target, Damage, DamageMod);
}
}
public class MultipleSkill : Skill
{
Action<List<string>, float, float, int> mutipleSkill;
public MultipleSkill(string name, string description, int cost, float damage, float damageMod, Action<List<string>, float, float, int> mutipleSkill) : base(name, description, SkillType.SigleTarget, cost, damage, damageMod)
{
this.mutipleSkill = mutipleSkill;
}
public void UseSkill(List<string> targets, int targetCount = 2)
{
mutipleSkill?.Invoke(targets, Damage, DamageMod, targetCount);
}
}
public class Skill
{
// 정보 MP 추가
// 캐릭터에서 가져오기
// 2. 스킬 항목 추가
// TODO :
// Program에 있는 배틀 로직 배틀 쪽에 붙이기
public string Name { get; }
public SkillType Type { get; }
public int Cost { get; }
public float Damage { get; }
public float DamageMod { get; }
public string Description { get; }
// 단일 타겟 스킬과 다중 타겟 스킬을 생성자로 나눴다.
// 배틀 시스템 들어갔을 때 type에 따라 캐스팅하여 UseSkill 호출하면 됨
public Skill(string name, string description, SkillType type, int cost, float damage, float damageMod)
{
Name = name;
Cost = cost;
Damage = damage;
DamageMod = damageMod;
Description = description;
}
}
}
타겟은 CharacterSkills 객체에서 단일 타겟 인지 다중 타겟 인지에 따라 데미지를 입게끔 구현 하였다. (타겟은 객체인데 임시로 string이라고 해놨음)
namespace TextRPG_Team
{
public class CharacterSkills
{
public void AttackSigleTarget(string target, float damage, float damageMod)
{
damage *= damageMod;
//target.TakeDamage(damage);
}
public void AttackMutipleTarget(List<string> targets, float damage, float damageMod, int targetCount = 2)
{
List<string> newTarget = new List<string>(targets);
damage *= damageMod;
int count = 0;
while (count < newTarget.Count)
{
int index = Utility.rand.Next(0, count);
//targets[index].TakeDamage(damage);
newTarget.Remove(newTarget[index]);
count++;
}
}
}
}
크리티컬 공격과 회피
이 또한 배틀 구현과 합쳐졌을 때 적용할 코드들이며 어느 클래스에 합쳐질지는 머지 이후에 확인할 것이다. (일단 더미 배틀 로직이라고 해놨음)
#region 배틀구현 이후 추가할 메서드들 - 주찬
int criticalPercentage = 15;
int dodgePercentage = 10;
float criticalMod = 1.6f;
void DummyBattleLogic()
{
// 크리티컬 데미지
float damage = 0;
damage = IsCritical() ? GetCriticalDamage(damage) : damage;
// 피하기 로직
string attackSentence = "~을";
attackSentence += IsDodged() ? GetDodgeSentence() : "";
}
bool IsCritical()
{
int randomPercentage = Utility.rand.Next(0, 100);
if (randomPercentage < criticalPercentage)
{
return true;
}
else
{
return false;
}
}
float GetCriticalDamage(float damage)
{
return damage * criticalMod;
}
bool IsDodged()
{
int randomPercentage = Utility.rand.Next(0, 100);
if (randomPercentage < dodgePercentage)
{
return true;
}
else
{
return false;
}
}
public string GetDodgeSentence()
{
return "공격했지만 아무일도 일어나지 않았습니다.";
}
#endregion
오늘의 회고
오늘은 새로운 팀원과 함께 하는 TextRPG 구현의 기반을 다졌다. 저번에 해봤던 Git으로 하는 미니 팀 프로젝트와 개인 과제로 주어진 TextRPG를 수행하고 나니까 작업이 훨씬 더 빠르게 진행 되어서 좋았다. 또한 이미 구현한 것을 더 좋게 만드는 과정도 더 깊은 고민을 할 수 있게 해서 더 좋은 시간이었다.
내일은 아마 다른 팀원분들이 구현한 것과 합치고 수정하는 작업 + 소비 아이템 관련해서 작업이 예상되는데 재미있을 것 같다. 내일도 열심히 해보자!
'스파르타 Unity 1기' 카테고리의 다른 글
내일배움캠프 16일차 TIL - JsonSerializer.Deserialize InvalidOperationException 오류 (0) | 2023.08.29 |
---|---|
내일배움캠프 3주차 WIL - TextRPG (0) | 2023.08.28 |
내일배움캠프 14일차 TIL - TextRPG 리팩토링 2 (0) | 2023.08.25 |
내일배움캠프 13일차 TIL - TextRPG 리팩토링 (0) | 2023.08.24 |
내일배움캠프 12일차 TIL - TextRPG 만들기 4 (0) | 2023.08.23 |