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๋กœ ์ค‘์ฒฉ ํƒ€์ž… ๊ตฌ๋ถ„ํ•ด์ฃผ๋ ค ํ–ˆ๋Š”๋ฐ ์‹ ๋‚˜์„œ ๊ธ€๋ถ€ํ„ฐ ์Œˆ