using System.Collections; using System.Collections.Generic; using UnityEngine; public enum StackType { Add, Cover } public class Buff { public string name; public int status; public float power; public float duration; public StackType stackType; public bool isApplying; public Buff(string name, int status, float power, float duration, StackType stackType) { this.name = name; this.status = status; this.power = power; this.duration = duration; this.stackType = stackType; isApplying = false; } public Buff(Buff bf) { this.name = bf.name; this.status = bf.status; this.power = bf.power; this.duration = bf.duration; this.stackType = bf.stackType; isApplying = false; } public Buff(Buff bf, float power) { this.name = bf.name; this.status = bf.status; this.power = power; this.duration = bf.duration; this.stackType = bf.stackType; isApplying = false; } public Buff(Buff bf, float power, float duration) { this.name = bf.name; this.status = bf.status; this.power = power; this.duration = duration; this.stackType = bf.stackType; isApplying = false; } } public struct BuffList { public static readonly Buff TEST_EXTRA_SPEED = new Buff(nameof(TEST_EXTRA_SPEED), STATUS.EXTRA_SPEED, 10, 3, StackType.Add); public static readonly Buff TEST_SPEED_MULT = new Buff(nameof(TEST_SPEED_MULT), STATUS.SPEED_MULTIPLIER, 0.5f, 3, StackType.Add); public static readonly Buff TEST_DAMAGE = new Buff(nameof(TEST_DAMAGE), STATUS.EXTRA_DAMAGE, 10, 2, StackType.Add); } public struct STATUS { public const int DEFAULT_SPEED = 0; public const int EXTRA_SPEED = 1; public const int SPEED_MULTIPLIER = 2; public const int EXTRA_DAMAGE = 3;
publicconstint=4;}publicclassEntity:MonoBehaviour{public<>=newList<Buff>();publicfloat[]=newfloat[STATUS.COUNT];publicfloat{get{return([STATUS.DEFAULT_SPEED]+[STATUS.EXTRA_SPEED])*[STATUS.SPEED_MULTIPLIER];}}publicfloat;privatevoidStart(){}publicvoidGivingBuff(Buff){StartCoroutine(ApplyBuff());}privateIEnumeratorApplyBuff(Buff){AddBuff();yieldreturnnewWaitForSeconds(.);.Log("END");RemoveBuff();}privatevoidAddBuff(Buff){.Add();StackProcess();}privatevoidRemoveBuff(Buff){DisableBuff();if(.Remove()==true){StackProcess();}}privatevoidAbleBuff(Buff){if(.==false){.=true;SetStatus(.,.);.Log("ABLE");}}privatevoidDisableBuff(Buff){if(.==true){.=false;SetStatus(.,-.);.Log("DISABLE");}}privatevoidSetStatus(int,float){this.[]+=;}privatevoidStackProcess(Buff){<>=newList<Buff>();for(int=0;<.;++){if([].==.){.Add([]);}}for(int=0;<.;++){DisableBuff([]);}if(.>0){int=0;for(int=1;<.;++){if([].<[].){=;}}AbleBuff([]);}}}
๊ฐ ๋ฅ๋ ฅ์น๋ณ๋ก ํจ์๋ฅผ ๋ง๋ค์ด์ฃผ๊ณ ์ถ์ง ์์๊ธฐ์ ๋ชจ๋ ๋ฅ๋ ฅ์น๋ฅผ status[]๋ก ๋ง๋ค๊ณ ๊ฐ ๋ฅ๋ ฅ์น์ STATUS์ const int๋ค์ ํตํด ์ ๊ทผํ๊ฒ ํ์.
๋ฆฌ์คํธ์ ๋ฒํ๊ฐ ์ถ๊ฐ/์ญ์ ๋ ๋๋ง๋ค ๋ชจ๋ ๋ฒํ๋ฅผ ํ์ธํ๊ณ ๋์ผํ ๋ฒํ์ ๋ํด์ ๊ฐ์ฅ ํฐ ๋ฒํ๋ง ํ์ฑํ, ๋๋จธ์ง๋ ๋นํ์ฑํ ์ํค๋ ๋ฐฉ์.
์ฌ์ค ์ด๊ฒ ๋ง๋์ง ๋ชจ๋ฅด๊ฒ ๊ณ ์ฌ๋ฐ์ ๊ฒ ๊ฐ์์ ํด๋ดค๋๋ฐ ์ฌ๋ฐ์๋ค.
๋ ์ข์ ๋ฐฉ์ ์์ผ๋ฉด ์กฐ์ธ์ข
+ Add๋ Cover๋ก ์ค์ฒฉ ํ์ ๊ตฌ๋ถํด์ฃผ๋ ค ํ๋๋ฐ ์ ๋์ ๊ธ๋ถํฐ ์
ํด๋น ๋๊ธ์ ์ญ์ ๋์์ต๋๋ค.
๊ทธ๋ฌ๊ฒ ์ ๊ฑฐ ์ฝ๋ ์์ ํ์ฃผ๋๊ฑฐ ํ๋ค์ ์ ์ฒด๋ณต์ฌ ๋๋ ๋๋ ๊ฐ์ด๋๋ค ๋ฌด์ํด์ค
๊ฐํ 1์ด์ง๋ฆฌ ๋ฒํ์ ์ฝํ 3์ด์ง๋ฆฌ ๋ฒํ๊ฐ ๊ฑธ๋ฆฌ๋ฉด ์ด๋ป๊ฒ ํด์ผ ํ๋๊ฐ
1์ด๋์ ๊ฐํ๊ฑฐ ์ ์ฉ๋ผ๋ค๊ฐ ๋จ์ 2์ด๊ฐ ์ฝํ๊ฑฐ ์ ์ฉ๋จ