Commit be42c966 authored by 15김민규's avatar 15김민규

주석 정돈. 코드 리프레시. 디버프 디버그(라임 오짐)할 예정.

parents 3b95427d 2d694d73
monsterid,name,itemid,weight
1,몬스터1,2,3
,,3,2
2,몬스터2,5,3
,,6,1
,,7,2
3,몬스터3,4,1
monsterid,name,itemid,prob
1,몬스터1,2,0.3
2,몬스터2,5,0.5
3,몬스터3,4,1
\ No newline at end of file
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enemy : MonoBehaviour {
using Random = UnityEngine.Random;
public class Enemy : MonoBehaviour {
// data
// health
private readonly float maxHealth;
private readonly float weight;
public float playerMaxHealth; //다른 스크립트에 있는 플레이어 최대체력 가져와야함
private float currHealth;
// unit distance when get damaged
static readonly float unitDist = 3;
// debuff
float[] immunity_time = new float[5] { 0.0f, 3.0f, 6.0f, 6.0f, 6.0f };//면역 시간
bool[] immunity = new bool[] { false, }; //현재 에너미가 디버프 상태에 대해서 면역인지를 체크하는 변수
enum debuffCase { fire, ice, stun, blind, charm };
// enemy manager
private readonly EnemyManager enemyManager = EnemyManager.Instance;
// action
private EnemyManager.State currState;
private List<int[]> dropTable; // [item ID, numerator]
private Dictionary<EnemyManager.State, EnemyManager.Action<int>> actionByState;
public Enemy(uint id, float maxHealth, float weight) {
private Dictionary<EnemyManager.State, EnemyManager.Action> actionByState;
// drop item
private readonly EnemyManager.DropItemInfo dropItem; // [item ID, probability]
// method
// constructor
public Enemy(int id, float maxHealth, float weight) {
this.maxHealth = maxHealth;
this.weight = weight;
this.currHealth = maxHealth;
this.dropTable = GetDropTable(id);
this.actionByState = GetActionByState(id);
EnemyManager.DropItemInfo dropItem_temp;
this.dropItem = (enemyManager.dropTableByID.TryGetValue(id, out dropItem_temp)) ?
dropItem_temp : new EnemyManager.DropItemInfo(-1, -1);
this.actionByState = enemyManager.actionDictByID[id];
this.currState = EnemyManager.State.Idle;
}
public void GetDamaged(float damage) {
float unitDist = 3;
// hit by player or debuff
public void GetDamaged(float damage) {
currHealth -= damage;
if(currHealth <= 0) {
mamaWooWooWoo_I_Dont_Wanna_Die();
if (dropItem.id != -1)
{
float dropProb = Random.Range(0.0f, 1.0f);
if (dropProb < dropItem.prob)
{
// spawn a item that has ID
}
}
Destroy(gameObject);
return;
}
float knockback_dist = damage * unitDist / weight;
// do something - knockback animation
}
private List<int[]> GetDropTable(uint id) {
List<int[]> resultList = new List<int[]>();
return resultList;
struct EnemyDebuffed
{
public debuffCase Case;
public float debuffTime;
}
private Dictionary<EnemyManager.State, EnemyManager.Action<int>> GetActionByState(uint id) {
var resultDictionary = new Dictionary<EnemyManager.State, EnemyManager.Action<int>>();
return resultDictionary;
IEnumerator DebuffCase(EnemyDebuffed sCase)
{
if (sCase.Case == debuffCase.fire)
{
StartCoroutine(OnFire(sCase));
}
else if (sCase.Case == debuffCase.ice && !immunity[(int)debuffCase.ice])
{
//Enemy 정지하는 코드 필요
immunity[(int)debuffCase.ice] = true;
yield return StartCoroutine(DebuffDoing(sCase));
}
else if (sCase.Case == debuffCase.stun && !immunity[(int)debuffCase.stun])
{
//Enemy 정지하는 코드 필요
immunity[(int)debuffCase.stun] = true;
yield return StartCoroutine(DebuffDoing(sCase));
}
else if (sCase.Case == debuffCase.blind && !immunity[(int)debuffCase.blind])
{
//Enemy의 공격이 적중하지 않는 코드 필요
immunity[(int)debuffCase.stun] = true;
yield return StartCoroutine(DebuffDoing(sCase));
}
else if (sCase.Case == debuffCase.charm && !immunity[(int)debuffCase.charm])
{
//Enemy 공격이 플레이어 회복하는 코드 필요
immunity[(int)debuffCase.stun] = true;
yield return StartCoroutine(DebuffDoing(sCase));
}
}
private void mamaWooWooWoo_I_Dont_Wanna_Die() {
int dropItemId = -1;
if (dropTable != null) {
float denominator = dropTable[dropTable.Count - 1][1];
float numerator = Random.Range(0f, denominator);
foreach (var drop in dropTable) {
if (numerator <= drop[1]) {
dropItemId = drop[0];
break;
}
}
IEnumerator OnFire(EnemyDebuffed sCase)
{
for (int i = 0; i < sCase.debuffTime / 1; i++)
{
yield return new WaitForSeconds(1.0f);
currHealth = currHealth - playerMaxHealth / 10;
}
// spawn a item that has ID
}
IEnumerator DebuffDoing(EnemyDebuffed sCase)
{
yield return new WaitForSeconds(sCase.debuffTime);
yield return StartCoroutine(DebuffEnd(sCase));
// destroy itself (or, deactivate for pooling)
Destroy(gameObject);
}
IEnumerator DebuffEnd(EnemyDebuffed sCase)
{
//다시 동작하는 코드 필요
yield return StartCoroutine(ImmunityTimer(sCase));
}
IEnumerator ImmunityTimer(EnemyDebuffed sCase)
{
yield return new WaitForSeconds(immunity_time[(int)sCase.Case]);
immunity[(int)sCase.Case] = false;
}
}
//얼음일때 깨어나기
//공격이 적중했을 때 매혹에서 깨어나기
\ No newline at end of file
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System;
public class EnemyManager : Singleton<EnemyManager> {
public enum State {
public class EnemyManager : Singleton<EnemyManager>
{
// static variable
// about action
public enum State
{
Idle,
Track,
Attack
} // 상속을 통해 수정할 가능성 높음. 염두만 해 두자.
public delegate void Action<T>();
public delegate void Action();
// about drop item
public struct DropItemInfo
{
public readonly int id;
public readonly float prob;
private Dictionary<uint, int[]> dropTableByID;
private Dictionary<uint, List<int[]>> actionDictByID;
public DropItemInfo(int inputID, float inputProb)
{
id = inputID;
prob = inputProb;
}
}
protected EnemyManager() {
// data
// dictionary
public readonly Dictionary<int, DropItemInfo> dropTableByID;
public readonly Dictionary<int, Dictionary<State, Action>> actionDictByID;
// method
// constructor
protected EnemyManager()
{
string dropTableDataPath = null;
string actionTableDataPath = null;
LoadDropTable(dropTableDataPath);
LoadActionTable(actionTableDataPath);
}
// Load Dictionary
private void LoadDropTable(string dataPath)
{
StreamReader strReader = new StreamReader(dataPath, Encoding.UTF8);
string[] cellValue = null; //csv파일 한 행에 포함되는 칸들의 값 넣을 배열
string tableLine = null; //파일 한 행
strReader.ReadLine(); //첫 줄 스킵
string[] cellValue = null;
string tableLine = null;
strReader.ReadLine();
while ((tableLine = strReader.ReadLine()) != null)
while ((tableLine = strReader.ReadLine()) != null)
{
if (string.IsNullOrEmpty(tableLine)) return; //행이 비었는지 체크
if (string.IsNullOrEmpty(tableLine)) return;
cellValue = tableLine.Split(',');
uint monsterID = 0;
int itemID = 0, dropWeight = 0;
int monsterID = -1;
int itemID = -1;
float prob = -1.0f;
uint.TryParse(cellValue[0], out monsterID);
int.TryParse(cellValue[0], out monsterID);
int.TryParse(cellValue[2], out itemID);
int.TryParse(cellValue[3], out dropWeight);
float.TryParse(cellValue[3], out prob);
int[] itemDrop = new int[] { itemID, dropWeight };
dropTableByID.Add(monsterID, itemDrop);
DropItemInfo dropItemInfo = new DropItemInfo(itemID, prob);
dropTableByID.Add(monsterID, dropItemInfo);
}
}
private void LoadActionTable(string dataPath) {
private void LoadActionTable(string dataPath)
{
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment