--
--	LuaScriptFile "scripts/roguelikemode_kor.lua"
--  CustomUpgradesFile mvm_upgrades_clickin_v8_roguelike_v2.txt
--	ExtendedUpgradesOnly 1

--		Explanation
--		{
--			Line "{#ff0000}로그라이크 모드"
--			Line "{blue}시작시 주어지는 포인트로 업그레이드를 할 수 있으며"
--			Line "{blue}7번 버튼을 통해 목록을 새로 갱신 할 수 있습니다."
--			Line "{blue}매 라운드마다 선택 3포인트와 리롤 1포인트를 얻습니다."
--			Line "{blue}매 라운드마다 목록이 새로 갱신됩니다."
--			Line "{red}기존 업그레이드가 비활성화 됩니다."
--			Line "{yellow}서버 파일 다운로드가 필요합니다."
--		}

--[[Global variables 
    MenuCapacity - How many upgrades can be stored in the menu, keep as integer
	Note that the sourcemod menu has a 512 byte limit, try to keep names/descriptions short
	Byte limit as opposed to a character limit means that inserting unicode characters which contain more than 1 byte
	will use up more of the limit
	
	You can use special characters like \n in sourcemod menus
	
	If you go above 7 selections (6+1 reroll selections) the sourcemod menu will display the Next and Previous buttons
	Personally I find this to be a bit clunky so I would stick with using a MenuCapacity of 6, 7 if you want to
	prevent accidental rerolls
	
TotalUpgradePoints - Determines the starting amount of upgrade points on wave 1, and for any late joiners, keep as integer

TotalRerollPoints - Determines the starting amount of upgrade points on wave 1, and for any late joiners, keep as integer]]

MenuCapacity = 6 --6 -- 상점에 팝업되는 메뉴의 수 6 = 5개의 항목 + 리롤
TotalUpgradePoints = 4 -- 웨이브 1 에 지급되는 선택 횟수 (5)
TotalRerollPoints = 4 -- 웨이브 1에 지급되는 리롤 횟수 (4)


--[[AllShops is a table that controls what upgrades are shown to players, based on what class they are
	Note that it uses the game's interal reference for classes, which is different from their class selection screen order
	
	Each class can have any number of subtables or sub categories, I use this to define four different rarities
	
	You can also go for a shared upgrade pool between all classes, or Demo and Soldier etc.]]

--attributes are defined as text on menu, attribute name, min, increment, max

--[[The 1st field is actually the most important, as it used to uniquely identify upgrades, this allows the second field
	to exist beyond just attributes, and you can utilize "custom" to write a function that can do anything, as shown in
	Max Ammo and Mixed Concotion On Hit
	
	Note that max is typicallly optional for attributes, and if you're using "custom", min increment and max are also optional
	and can be defined in the AddUpgrade function instead]]
	
--	어트리뷰트 문법 {"상점 표기 업그레이드 이름", "어트리뷰트 이름" 기준점, 상승/하락폭, 최대/최저 수치} 최대/최저 수치는 적지않으면 MAX 없음
--  어트리뷰트 이름 작성시 "," 가 들어갈시 오류발생함 / 로 바꾸는것을 추천

AllShops =
{
	[1] = --Scout Shop [참조 하는 배열][주석 1]
	{
		CommonAttribute =
		{
			{"피해량 +25%", "damage bonus",1,0.25},
			{"공격 속도 +15%", "fire rate bonus",1,-0.15,0.1},
 			{"재장전 속도 +20%", "faster reload rate",1,-0.2,0.1},
			{"처치 시 체력 25 회복", "heal on kill",0,25},
			{"최대 체력 +25", "max health additive bonus",0,25},
			{"모든 탄약수 +50%", "custom",1,0.5},
			{"이동 속도 +15%", "move speed bonus",1,0.15},
			{"점프 높이 +20%", "increased jump height",1,0.2},
			{"무기 전환 속도 +35%", "deploy time decreased",1,-0.35,0},
			{"재충전 속도 +25%", "effect bar recharge rate increased",1,-0.25,0.05},
			{"3 속성 저항 +30%", "custom",1,1,4},
			--{"탄환 피해 저항력 +25%", "dmg taken from bullets reduced",1,-0.25,0.1},
			--{"폭발 피해 저항력 +25%", "dmg taken from blast reduced",1,-0.25,0.1},
			--{"화염 피해 저항력 +25%", "dmg taken from fire reduced",1,-0.25,0.1},
			{"치명타 피해 저항력 +45%", "dmg taken from crit reduced",1,-0.45,0.1},
			--{"근거리 피해 저항력 +30%", "dmg from melee increased",1,-0.3,0.1},
			{"초당 체력 회복량 +4", "health regen",0,4},
			{"5초 마다 최대 탄약의 5% 보급", "ammo regen",0,0.05,1},
			{"적중 시 체력 15 회복", "heal on hit for rapidfire",0,15},
			{"밀어내기 저항력 +30%", "damage force reduction",1,-0.3,0},
		},
		RareAttribute =
		{
			{"( R ) 장탄수 +75%", "clip size bonus",1,0.75},
			{"( R ) 투사체 관통 [탄환]", "projectile penetration",0,1,1},
			{"( R ) 우유 적중시 대상 이동 속도 감소", "applies snare effect",1,-0.35,0.65},
			{"( R ) 적중 시 5초간 이동속도 증진", "speed_boost_on_hit",0,5,5},
			{"( R ) 로봇 센트리 무시", "ignored by enemy sentries",0,1,1},
			{"( R ) 기절, 둔화 면역", "mult stun resistance",0,0,0},
			--{"( R ) 추가 점프 횟수 +1", "air dash count",0,1},
			--{"( R ) 투사체 피해량 +400%"",},[[공, 방울, 혈적자 등. 피해량 0인건 냅둠]]
			--{"( R ) 투사체 적중 대상이 2초 내로 사망시 투사체 재충전"",},[[어시스트 포함]]
			--{"( R ) 처치 시: 소형 치료제 드롭", "drop health pack on kill",0,1,1},
		},
		EpicAttribute =
		{
			{"( SR ) 발사 당 탄환수 +100%", "bullets per shot bonus",1,1},
			{"( SR ) 전차 대상 피해량 +50%", "mult dmg vs tanks",1,0.5},
			{"( SR ) 사망 직전 즉시 귀환", "teleport instead of die",0,1,1},
			{"( SR ) 폭주 미터/우유 지속시간 +50%", "mult effect duration",1,0.5},
			{"( SR ) 모든 받는 치료량 +200%", "healing received bonus",1,2,3},
			--{"( SR ) 상태이상 지속 시간 -75%",}, [[말 그대로]]
		},
		LegendaryAttribute =
		{
			{"【 SSR 】 재장전을 한번에 다 함", "reload full clip at once",0,1,1},
			{"【 SSR 】 처치 시 2초간 치명타 증진", "critboost on kill",0,2,2},
			{"【 SSR 】 소형 치명타 발생시 크리티컬로 전환", "minicrits become crits",0,1,1},
			--{"【 SSR 】 적중 시 죽음의 표식 부착", "mark for death",0,1,1},
			{"【 SSR 】 공중에서 공격시 소형 치명타 / 점프 횟수 +7", "air dash count",0,7,7},
			--{"【 SSR 】 밟은 적을 기절시킴",}, [[밟은 후 위로 튀어오름, 이단 점프는 초기화 안 함]]
		}
	},
	[3] = --Soldier Shop
	{
		CommonAttribute =
		{
			{"피해량 +25%", "damage bonus",1,0.25},
			{"주무기: 장탄수 +2", "clip size upgrade atomic",0,2},
			{"공격 속도 +15%", "fire rate bonus",1,-0.15,0.1},
			{"재장전 속도 +20%", "faster reload rate",1,-0.2,0.1},
			{"처치 시 체력 25 회복", "heal on kill",0,25},
			{"최대 체력 +25", "max health additive bonus",0,25},
			{"모든 탄약수 +50%", "custom",1,0.5},
			{"이동 속도 +10%", "move speed bonus",1,0.1},
			{"점프 높이 +20%", "increased jump height",1,0.2},
			{"무기 전환 속도 +35%", "deploy time decreased",1,-0.35,0},
			{"3 속성 저항 +25%", "custom",1,1,4},
			--{"탄환 피해 저항력 +25%", "dmg taken from bullets reduced",1,-0.25,0.1},
			--{"폭발 피해 저항력 +25%", "dmg taken from blast reduced",1,-0.25,0.1},
			--{"화염 피해 저항력 +25%", "dmg taken from fire reduced",1,-0.25,0.1},
			{"치명타 피해 저항력 +45%", "dmg taken from crit reduced",1,-0.45,0.1},
			--{"근거리 피해 저항력 +30%", "dmg from melee increased",1,-0.3,0.1},
			{"초당 체력 회복량 +4", "health regen",0,4},
			{"5초 마다 최대 탄약의 5% 보급", "ammo regen",0,0.05,1},
			{"적중 시 체력 15 회복", "heal on hit for rapidfire",0,15},
			{"투사체 비행 속도 +25%", "Projectile speed increased",1,0.25},
			{"깃발: 증진 지속시간 +25%", "increase buff duration",1,0.25},
			{"고지 도약기: 무한 재사용", "parachute redeploy",0,1,1},
			{"폭발로 공중에 뜬 대상 소형 치명타", "mod mini-crit airborne",0,1,1},
			
			--{"깃발: 분노 획득량 +25%", "rage giving scale",1,0.25},
			--{"탈출계획: 더이상 소형 치명타를 받지 않음",},
		},
		RareAttribute =
		{
			{"( R ) 장탄수 +50%", "clip size bonus",1,0.5},
			{"( R ) 처치 시: 소형 치료제 드롭", "drop health pack on kill",0,1,1},
			{"( R ) 로켓 특화", "rocket specialist",0,1,1},
			{"( R ) 폭발 범위 +25%", "Blast radius increased",1,0.25},
			{"( R ) 낙하 피해 무시", "cancel falling damage",0,1,1},
			{"( R ) 깃발: 증진 지속시간 +50%", "increase buff duration",1,0.5},
			
		    --{"( R ) 깃발: 분노 획득량 +75%", "rage giving scale",1,0.75,2.5},
			--{"( R ) 추가 점프 횟수 +1", "air dash count",0,1},
			--{"( R ) 사망에 이를시 즉시 뒤로 로켓점프, 이 상태에서 지면에 닿기 전까지 무적 상태가 됨",},[[전방에 피해 500을 주며 뒤로 날아감, 쿨타임 40초]]
			--{"( R ) 근접 피해량 +100%, 근접 처치시 체력, 탄약 +35% 회복",},
		},
		EpicAttribute =
		{
			{"( SR ) 깃발: 증진 반경 +50%", "mod soldier buff range",1,0.5},
			{"( SR ) 전차 대상 피해량 +50%", "mult dmg vs tanks",1,0.5},
			{"( SR ) 처치 시 5초간 이동속도 증진", "speed_boost_on_kill",0,5,5},
			{"( SR ) 투사체 반사/파괴 불가", "projectile no deflect",0,1,1},
			{"( SR ) 투사체 유도 활성화", "custom",0,1,1},
			--{"( SR ) 사망 시 귀환 확률 +25%", "teleport instead of die",0,0.25,1},
			--{"( SR ) 체공중 피해, 밀어냄 저항 +50%",}, --[[공중에 떠있는 동안 적용]]
		},
		LegendaryAttribute =
		{
			{"【 SSR 】 처치 시 1초간 치명타 증진", "critboost on kill",0,1,2},
			{"【 SSR 】 적중 시 죽음의 표식 부착", "mark for death",0,1,1},
			{"【 SSR 】 범위 최대 피해", "dmg falloff decreased",1,-0.5,0.5},
			{"【 SSR 】 모든 깃발 효과 발동", "effect cond override",0,1907216,1907216}, -- 16+26*256+29*65536 = 16+6656+1900544=1907216
			{"【 SSR 】 수직이착륙 솔저", "custom",0,1,1},
			{"【 SSR 】 중력 로켓 / 폭발 범위 +70%", "custom",0,1,1},  --서버폭팔원인추정1
			
			--{"【 SSR 】 폭발 범위 +50%", "Blast radius increased",1,0.5},
			--{"【 SSR 】 이중 사격", "custom",0,1,1}, --밀리공속버그
			
			--{"【 SSR 】 모든 받는 치료량 +100%", "healing received bonus",1,1},
			--{"【 SSR 】 소형 치명타 발생시 크리티컬로 전환", "minicrits become crits",0,1,1},
			--{"【 SSR 】 로켓이 조준점으로 유도됨, 자해 피해 -50%",},[[로켓 유도율, 선회 속도는 맘대로]]
		}
	},
	[7] = --Pyro Shop
	{
		CommonAttribute =
		{
			{"피해량 +25%", "damage bonus",1,0.25},
			{"산탄총: 장탄수 +50%", "clip size bonus",1,0.5},
			{"공격 속도 +15% (용격 제외)", "fire rate bonus",1,-0.15,0.1},
			{"재장전 속도 +20%", "faster reload rate",1,-0.2,0.1},
			{"처치 시 체력 25 회복", "heal on kill",0,25},
			{"최대 체력 +25", "max health additive bonus",0,25},
			{"모든 탄약수 +50%", "custom",1,0.5},
			{"이동 속도 +10%", "move speed bonus",1,0.1},
			{"점프 높이 +20%", "increased jump height",1,0.2},
			{"무기 전환 속도 +35%", "deploy time decreased",1,-0.35,0},
			{"3 속성 저항 +30%", "custom",1,1,4},
			--{"탄환 피해 저항력 +25%", "dmg taken from bullets reduced",1,-0.25,0.1},
			--{"폭발 피해 저항력 +25%", "dmg taken from blast reduced",1,-0.25,0.1},
			--{"화염 피해 저항력 +25%", "dmg taken from fire reduced",1,-0.25,0.1},
			{"치명타 피해 저항력 +45%", "dmg taken from crit reduced",1,-0.45,0.1},
			--{"근거리 피해 저항력 +30%", "dmg from melee increased",1,-0.3,0.1},
			{"초당 체력 회복량 +4", "health regen",0,4},
			{"5초 마다 최대 탄약의 5% 보급", "ammo regen",0,0.05,1},
			{"초당 화염 방사기 탄약 소모량 -35%", "flame ammopersec decreased",1,-0.35,0},
			{"밀어내기 저항력 +30%", "damage force reduction",1,-0.3,0},
			{"조명총: 투사체 비행 속도 +100%", "Projectile speed increased",1,1},
			{"가열 가속기: 공중 재사용", "thermal_thruster_air_launch",0,1,1},
			{"가열 가속기: 착륙 시 주변 대상 기절", "falling_impact_radius_stun",0,1,1},
			{"각종 재충전 대기 시간 -15% (용격 포함)", "mult_item_meter_charge_rate",1,-0.15,0.55},
			
			--{"반사 시킨 투사체 속도 +100%", "mult reflect velocity",1,1},
			--{"팀원 압축 공기 분사 시 이동속도 증진", "airblast_give_teammate_speed_boost",0,1,1},
			--{"네온 전멸기: 들고 있을 시 이동 속도 +75%, 치명타 피해량이 주변으로 퍼짐",},[[힛 앤 런]]
		},
		RareAttribute =
		{
			{"( R ) 추가 점프 횟수 +1", "air dash count",0,1},
			{"( R ) 화염 비거리 +10%", "flame_drag",0,-0.425,-4.25},
			{"( R ) 각종 폭발 반경 +40%", "Blast radius increased",1,0.4},
			{"( R ) 압축 공기 분사 탄약 소모량 -25%", "airblast cost decreased",1,-0.25,0},
			{"( R ) 적중 시 대상 이동속도 감소", "slow enemy on hit",0,1,1},
			{"( R ) 로봇 센트리 무시", "ignored by enemy sentries",0,1,1},
			{"( R ) 화상 피해 +100%", "weapon burn dmg increased",1,1},
			{"( R ) 기절, 둔화 면역", "mult stun resistance",0,0,0},
			
			--{"( R ) 처치 시 5초간 이동속도 증진", "speed_boost_on_kill",0,5,5},
			--{"( R ) 처치 시: 소형 치료제 드롭", "drop health pack on kill",0,1,1},
			--{"( R ) 받는 범위 폭발피해 -30%",}, [[직격 제외]]
		},
		EpicAttribute =
		{
			{"( SR ) 가스통 폭발", "explode_on_ignite",0,1,1},
			{"( SR ) 적중 시 체력 6 회복", "heal on hit for rapidfire",0,6,18},
			{"( SR ) 전차 대상 피해량 +50%", "mult dmg vs tanks",1,0.5},
			{"( SR ) 사망 직전 즉시 귀환", "teleport instead of die",0,1,1},--[[사망에 이를 시 귀환할 확률]]
			{"( SR ) 주무기: 후방 공격 시 치명타", "mod flamethrower back crit",0,1,1},
			{"( SR ) 압축 공기 분사 재사용 대기 시간 -50%", "mult airblast refire time",1,-0.5,0},
			
			--{"( SR ) 사망 시 자폭 확률 75%",}, [[피해량 300]]
		},
		LegendaryAttribute =
		{
			{"【 SSR 】 처치 시 1초간 치명타 증진", "critboost on kill",0,1,2},
			{"【 SSR 】 적중 시 죽음의 표식 부착", "mark for death",0,1,1},
			{"【 SSR 】 모든 받는 치료량 +200%", "healing received bonus",1,2,3},
			{"【 SSR 】 불타는 적에게 50% 추가 피해", "damage bonus vs burning",1,0.5,1.5},
			{"【 SSR 】 화상 피해 속도 x4", "weapon burn time increased",0,4},
			{"【 SSR 】 화염 수명 +500%", "custom",0,1,1}, --화염 수명 5배, 오래있을수록 화염크기 증가
			--{"【 SSR 】 불타는 적에게 피해량 -40%",},[[알아서 밸런스 조절하셈]]
		},
		Contraband =
		{
			{"【 UR 】적중 시 가스 상태 부여", "add cond on hit",0,123,123},
		}
	},
	[4] = --Demoman Shop
	{
		CommonAttribute =
		{
			{"피해량 +25%", "damage bonus",1,0.25},
			{"주무기: 소지수 +2", "clip size upgrade atomic",0,2},
			{"장탄수 +50%", "clip size bonus",1,0.5},
			{"공격 속도 +15%", "fire rate bonus",1,-0.15,0.1},
			{"재장전 속도 +20%", "faster reload rate",1,-0.2,0.1},
			{"처치 시 체력 25 회복", "heal on kill",0,25},
			{"최대 체력 +25", "max health additive bonus",0,25},
			{"모든 탄약수 +50%", "custom",1,0.5},
			{"이동 속도 +10%", "move speed bonus",1,0.1},
			{"점프 높이 +20%", "increased jump height",1,0.2},
			{"무기 전환 속도 +35%", "deploy time decreased",1,-0.35,0},
			{"방패: 돌격 재충전 속도 +200%", "charge recharge rate increased",1,2},
			--{"방패: 돌격 충돌 피해 +100%", "charge impact damage increased",1,1},
			{"3 속성 저항 +30%", "custom",1,1,4},
			--{"탄환 피해 저항력 +25%", "dmg taken from bullets reduced",1,-0.25,0.1},
			--{"폭발 피해 저항력 +25%", "dmg taken from blast reduced",1,-0.25,0.1},
			--{"화염 피해 저항력 +25%", "dmg taken from fire reduced",1,-0.25,0.1},
			{"치명타 피해 저항력 +45%", "dmg taken from crit reduced",1,-0.45,0.1},
			--{"근거리 피해 저항력 +30%", "dmg from melee increased",1,-0.3,0.1},
			{"초당 체력 회복량 +4", "health regen",0,4},
			{"5초 마다 최대 탄약의 5% 보급", "ammo regen",0,0.05,1},
			{"적중 시 체력 15 회복", "heal on hit for rapidfire",0,15},
			{"투사체 비행 속도 +25%", "Projectile speed increased",1,0.25},
			{"밀어내기 저항력 +30%", "damage force reduction",1,-0.3,0},
			{"점착 폭탄 최대 설치량 +2", "max pipebombs increased",1,2},
			{"고지 도약기: 무한 재사용", "parachute redeploy",0,1,1},
			{"폭발로 공중에 뜬 대상 소형 치명타", "mod mini-crit airborne",0,1,1},
			
			--{"처치 시: 소형 치료제 드롭", "drop health pack on kill",0,1,1},
		},
		RareAttribute =
		{
			{"( R ) 폭발 반경 +25%", "Blast radius increased",1,0.25},
			{"( R ) 전차 대상 피해량 +50%", "mult dmg vs tanks",1,0.5},
			{"( R ) 근거리 공격 너비 +50% / 사거리 +25%", "custom",1,1},
			{"( R ) 추가 점프 횟수 +1", "air dash count",0,1},
			{"( R ) 낙하 피해 무시", "cancel falling damage",0,1,1},
			{"( R ) 투사체 반사/파괴 불가", "projectile no deflect",0,1,1},
			{"( R ) 방패: 돌격 유지 시간 +3초 / 돌격 완전 제어", "custom",0,1},
			{"( R ) 돌격 충돌 피해 +1000%", "charge impact damage increased",1,10},
			{"( R ) 기절, 둔화 면역", "mult stun resistance",0,0,0},
		},
		EpicAttribute =
		{
			{"( SR ) 유탄: 벽/지면 충돌시 폭발", "grenade explode on impact",0,1,1},
			{"( SR ) 사망 직전 즉시 귀환", "teleport instead of die",0,1,1},
			{"( SR ) 처치 시 5초간 이동속도 증진", "speed_boost_on_kill",0,5,5},
			{"( SR ) 점착: 충전 비례 피해량 +75%", "stickybomb_charge_damage_increase",1,0.75},
			{"( SR ) 점착: 폭파 대기 시간 -0.15초", "sticky arm time bonus",0,-0.15,-0.45},
			{"( SR ) 근거리 공격 시 범위 내 모든 적 타격", "melee cleave attack",0,1,1},
			
			--{"( SR ) 술병 도발 후 무작위 우버차지를 얻음",}, [[무적, 크리, 응급, 무작위 예접, 10초지속]]
		},
		LegendaryAttribute =
		{
			{"【 SSR 】 점착: 즉시 충전", "stickybomb charge rate",1,-0.97,0.03},
			{"【 SSR 】 처치 시 1초간 치명타 증진", "critboost on kill",0,1,2},
			{"【 SSR 】 소형 치명타 발생시 크리티컬로 전환", "minicrits become crits",0,1,1},
			{"【 SSR 】 범위 최대 피해", "dmg falloff decreased",1,-0.5,0.5},
			{"【 SSR 】 적중 시 죽음의 표식 부착", "mark for death",0,1,1},
			
			--{"【 SSR 】 이중 사격", "custom",0,1,1},
			--{"【 SSR 】 한번에 모두 발사함", "fire full clip at once",0,1,1},
			--{"【 SSR 】 모든 받는 치료량 +100%", "healing received bonus",1,1},
			--{"【 SSR 】 한 번에 적을 셋 이상 죽이면 탄창을 장전함, 해당 탄창 피해량 +30%",}, [[1발이라도 직접 장전시 사라짐]]
		}
	},
	[6] = --Heavy Shop
	{
		CommonAttribute =
		{
			{"공격 속도 +10%", "fire rate bonus",1,-0.1,0.1},
			{"도시락 재충전 속도 +30%", "charge recharge rate increased",1,-0.3,0.1},
			{"처치 시 체력 25 회복", "heal on kill",0,25},
			{"최대 체력 +25", "max health additive bonus",0,25},
			{"모든 탄약수 +50% / 장탄수 +50%", "custom",1,0.5},
			{"이동 속도 +10%", "move speed bonus",1,0.1},
			{"점프 높이 +20%", "increased jump height",1,0.2},
			{"무기 전환 속도 +35%", "deploy time decreased",1,-0.35,0},
			{"3 속성 저항 +30%", "custom",1,1,4},
			--{"탄환 피해 저항력 +25%", "dmg taken from bullets reduced",1,-0.25,0.1},
			--{"폭발 피해 저항력 +25%", "dmg taken from blast reduced",1,-0.25,0.1},
			--{"화염 피해 저항력 +25%", "dmg taken from fire reduced",1,-0.25,0.1},
			{"치명타 피해 저항력 +45%", "dmg taken from crit reduced",1,-0.45,0.1},
			{"근거리 피해 저항력 +45%", "dmg from melee increased",1,-0.45,0.1},
			{"초당 체력 회복량 +4", "health regen",0,4},
			{"5초 마다 최대 탄약의 5% 보급", "ammo regen",0,0.05,1},
			{"투사체 관통", "projectile penetration heavy",0,1,3},
			{"밀어내기 저항력 +30%", "damage force reduction",1,-0.3,0},
			{"사격 준비 속도 +15%", "minigun spinup time decreased",1,-0.15,0},
			{"총열 회전 중 이동 속도 +20%", "aiming movespeed increased",1,0.20},
			
			--{"산탄총: 장탄수 +100%", "clip size bonus",1,1},
			--{"산탄총: 재장전 속도 +20%", "faster reload rate",1,-0.2,0.1},
			--{"샷건: 장전이 필요 없어짐",}, [[탄약이 알아서 장전됨]]
			--{"도시락: 먹는 중 은신 상태가 됨",},[[데드링어]]
		},
		RareAttribute =
		{
			{"( R ) 처치 시: 소형 치료제 드롭", "drop health pack on kill",0,1,1},
			{"( R ) 추가 점프 횟수 +1", "air dash count",0,1,1},
			{"( R ) 투사체 파괴", "attack projectiles",0,1,2},
			{"( R ) 밀침 분노", "generate rage on damage",0,1,3},
			{"( R ) 적중 시 대상 이동속도 감소", "slow enemy on hit",0,1,1},
			{"( R ) 총열 회전 중 무기 교체", "mod minigun can holster while spinning",0,1,1},
			{"( R ) 총열 회전 시 화염 고리 생성", "ring of fire while aiming",0,1,1},
		},
		EpicAttribute =
		{
			{"( SR ) 적중 시 체력 2 회복", "heal on hit for rapidfire",0,2,4},
			{"( SR ) 피해량 +10%", "damage bonus",1,0.1,1.3},
			{"( SR ) 전차 대상 피해량 +50%", "mult dmg vs tanks",1,0.5},
			{"( SR ) 사망 직전 즉시 귀환", "teleport instead of die",0,1,1},
			{"( SR ) 적중 시 5초간 이동속도 증진", "speed_boost_on_hit",0,5,5},
			{"( SR ) 발사 당 탄환수 +10%", "bullets per shot bonus",1,0.1,1.5},
			--{"( SR ) 산탄총 : 재장전이 필요하지 않음", "faster reload rate",1,-1,0},
			--{"( SR ) 주변 아군의 피해 저항 +15%",}, [[범위는 깃발과 동일]]
		},
		LegendaryAttribute =
		{
			{"【 SSR 】 처치 시 1초간 치명타 증진", "critboost on kill",0,1,2},
			{"【 SSR 】 모든 받는 치료량 +100%", "healing received bonus",1,1},
			{"【 SSR 】 적중 시 죽음의 표식 부착", "mark for death",0,1,1},
			{"【 SSR 】 메딕이 치료하는 동안 피해량 +30%", "mod medic healed damage bonus",1,0.3,1.3},
			{"【 SSR 】 거대화 / 최대 체력 +700", "custom",0,1,1},
			{"【 SSR 】 폭발 탄환 개조", "explosive bullets",0,147,147},
			
			--{"【 SSR 】 소형 치명타 발생시 크리티컬로 전환", "minicrits become crits",0,1,1},
			--{"【 SSR 】 치료 광선이 연결된 메딕이 받는 피해를 대신 받음",},
		}
	},
	[9] = --Engineer Shop
	{
		CommonAttribute =
		{
 			{"무기: 피해량 +25%", "damage bonus",1,0.25},
			{"무기: 공격 속도 +15%", "fire rate bonus",1,-0.15,0.1},
			{"무기: 재장전 속도 +35%", "faster reload rate",1,-0.35,0.1},
			{"최대 체력 +25", "max health additive bonus",0,25},
			{"모든 탄약수 +50% / 장탄수 +50%", "custom",1,0.5},
			{"이동 속도 +15%", "move speed bonus",1,0.15},
			{"점프 높이 +20%", "increased jump height",1,0.2},
			{"무기 전환 속도 +50%", "deploy time decreased",1,-0.5,0},
			{"3 속성 저항 +30%", "custom",1,1,4},
			--{"탄환 피해 저항력 +25%", "dmg taken from bullets reduced",1,-0.25,0.1},
			--{"폭발 피해 저항력 +25%", "dmg taken from blast reduced",1,-0.25,0.1},
			--{"화염 피해 저항력 +25%", "dmg taken from fire reduced",1,-0.25,0.1},
			{"치명타 피해 저항력 +45%", "dmg taken from crit reduced",1,-0.45,0.1},
			----{"근거리 피해 저항력 +30%", "dmg from melee increased",1,-0.3,0.1},
			{"초당 체력 회복량 +4", "health regen",0,4},
			{"5초 마다 최대 탄약의 5% 보급", "ammo regen",0,0.05,1},
			{"적중 시 체력 25 회복", "heal on hit for rapidfire",0,25},
			{"최대 금속 보유량 +50%", "maxammo metal increased",1,0.50},
			{"구조물 최대 내구도 +100%", "engy building health bonus",1,1},
			{"센트리 건 공격 속도 +10%", "engy sentry fire rate increased",1,-0.1,0},
			{"디스펜서 효과 범위 +100%", "engy dispenser radius increased",1,1},
			{"센트리 건 최대 탄약량 +50%", "mvm sentry ammo",1,0.50},
			{"수리 효율 +30%", "Repair rate increased",1,0.3},
			
			--{"무기: 장탄수 +50%", "clip size bonus",1,0.5},
			--{"처치 시 체력 25 회복", "heal on kill",0,25},
			--{"건설 속도 +25%", "build rate bonus",1,-0.25,0},
			--{"렌치 타격 시 건설 속도 +30%", "Construction rate increased",1,0.3},
			--{"업그레이드 효율 +20%", "upgrade rate decrease",1,0.2},
			--{"탄약 상자/디스펜서 에서 얻는 금속량 +25%", "metal_pickup_decreased",1,0.25},
		},
		RareAttribute =
		{
			{"( R ) 센트리 건 속도 증가", "sentry rapid fire",0,1,1},
			{"( R ) 적중 시 5초간 이동속도 증진", "speed_boost_on_hit",0,5,5},
			{"( R ) 추가 점프 횟수 +1", "air dash count",0,1},
			{"( R ) 투사체 관통[무기]", "projectile penetration",0,1,1},
			{"( R ) 센트리 건 사정거리 +50%", "engy sentry radius increased",1,0.5},
			{"( R ) 디스펜서 회복/보급 효율 +50%", "mult dispenser rate",1,0.5},
			{"( R ) 텔레포터 개선", "custom",0,1,1},
			{"( R ) 무기: 발사 당 탄환수 +50%", "bullets per shot bonus",1,0.5},
			{"( R ) 무기: 전차 대상 피해량 +50%", "mult dmg vs tanks",1,0.5},
			--{"( SR ) 텔레포터 사용 후 이동속도 증진", "mod teleporter speed boost",0,1,1},
			--{"양방향 텔레포터", "bidirectional teleport",0,1,1},
		},
		EpicAttribute =
		{
			{"( SR ) 일회용 센트리 건설 수 +3", "engy disposable sentries",0,3},
			{"( SR ) 5초 마다 금속 100 보급", "metal regen",0,100,100},
			{"( SR ) 사망 직전 즉시 귀환", "teleport instead of die",0,1,1},
			{"( SR ) 센트리 건 로켓 발사 속도 +30% / 로켓 특화 +1", "custom",1,1},
			{"( SR ) 타격시 건물 단계 바로 증가", "upgrade rate decrease",1,7},
			{"( SR ) 적중 시 죽음의 표식 부착", "mark for death",0,1,1},
			{"( SR ) 센트리 건 목표 대상 피해량 +100%", "damage bonus bullet vs sentry target",1,1},
			{"( SR ) 구조물 건설시 금속이 들지 않음", "building cost reduction",1,-1,0},
			--{"( SR ) 사망에 이르면 텔레포터 출구로 탈출함",}, [[쿨타임 없음]]
		},
		LegendaryAttribute =
		{
			{"【 SSR 】 처치 시 5초간 치명타 증진", "critboost on kill",0,5,5},
			{"【 SSR 】 소형 치명타 발생시 크리티컬로 전환", "minicrits become crits",0,1,1},
			{"【 SSR 】 모든 받는 치료량 +200%", "healing received bonus",1,2,3},
			{"【 SSR 】 센트리 건 피해량 +100%", "engy sentry damage bonus",1,1},
			{"【 SSR 】 건물 즉시 건설", "build rate bonus",1,-0.99,0.01},
			--{"【 SSR 】 활성화된 구조물당 피해 저항 +20%",},
		}
	},
	[5] = --Medic Shop
	{
		CommonAttribute =
		{
			{"피해량 +35%", "damage bonus",1,0.35},
			{"모든 탄약수 +50% / 장탄수 +50%", "custom",1,0.5},
			{"쇠뇌: 장탄수 +2", "clip size upgrade atomic",0,2},
			{"공격 속도 +15%", "fire rate bonus",1,-0.15,0.1},
			{"재장전 속도 +30%", "faster reload rate",1,-0.3,0.1},
			{"처치 시 체력 25 회복", "heal on kill",0,25},
			{"최대 체력 +25", "max health additive bonus",0,25},
			{"이동 속도 +15%", "move speed bonus",1,0.15},
			{"점프 높이 +20%", "increased jump height",1,0.2},
			{"무기 전환 속도 +50%", "deploy time decreased",1,-0.50,0},
			{"3 속성 저항 +25%", "custom",1,1,4},
			--{"탄환 피해 저항력 +25%", "dmg taken from bullets reduced",1,-0.25,0.1},
			--{"폭발 피해 저항력 +25%", "dmg taken from blast reduced",1,-0.25,0.1},
			--{"화염 피해 저항력 +25%", "dmg taken from fire reduced",1,-0.25,0.1},
			{"치명타 피해 저항력 +45%", "dmg taken from crit reduced",1,-0.45,0.1},
			----{"근거리 피해 저항력 +30%", "dmg from melee increased",1,-0.3,0.1},
			{"초당 체력 회복량 +4", "health regen",0,4},
			{"5초 마다 최대 탄약의 5% 보급", "ammo regen",0,0.05,1},
			{"적중 시 체력 6 회복", "heal on hit for rapidfire",0,3},
			{"우버 충전율 +25%", "ubercharge rate bonus",1,0.25},
			{"치료 통달 +1", "healing mastery",0,1},
			{"과치료 전문가 +1", "overheal expert",0,1},
			{"투사체 보호막", "generate rage on heal",0,1,2},
			{"수통 전문가", "canteen specialist",0,1,3},
			
			--{"과치료 유지 시간 +35%", "overheal decay bonus",1,0.35,2},
			--{"장탄수 +50%", "clip size bonus",1,0.5},
			--{"밀어내기 저항력 +30%", "damage force reduction",1,-0.3,0},
			--{"test1", "medigun passive attributes",0,"damage force reduction|-2|"},
			--{"test2", "custom",0,1,1},
		},
		RareAttribute =
		{
			{"( R ) 피격 시 3 초간 무적이 될 확률 +20%", "uber on damage taken",0,0.2,0.4},
			{"( R ) 추가 점프 횟수 +1", "air dash count",0,1},
			{"( R ) 미치광이 우유 주사기", "mad milk syringes",0,1,1},
			{"( R ) 메디건 사정거리 +25%", "mult medigun range",1,0.25},
			{"( R ) 과치료 최대량 +50", "overheal bonus",1,0.5},
			{"( R ) 우버차지 지속시간 +2 초", "uber duration bonus",0,2},
			--{"( R ) 적중 시 우버 충전률 +1%", "add uber charge on hit",0,0.01},
			--{"( R ) 환자의 이동속도를 얻음, 메딕과 환자의 이동 속도 +20%",}, [[응조 효과+a]]
		},
		EpicAttribute =
		{
			{"( SR ) 치료율 +50%", "heal rate bonus",1,0.5},
			{"( SR ) 사망 직전 즉시 귀환", "teleport instead of die",0,1,1},
			{"( SR ) 치료율의 50% 만큼 구조물 치유", "medic machinery beam",0,5},
			{"( SR ) 근거리 공격 시 범위 내 모든 적 타격", "melee cleave attack",0,1,1},
			{"( SR ) 적중 시 7초간 이동속도 증진", "speed_boost_on_hit",0,7,7},
			{"( SR ) 모든 받는 치료량 +150%", "healing received bonus",1,1,5},
			--{"( SR ) 처치 시 2초간 치명타 증진", "critboost on kill",0,2},
		},
		LegendaryAttribute =
		{
			--{"【 SSR 】 소형 치명타 발생시 크리티컬로 전환", "minicrits become crits",0,1,1},
			{"【 SSR 】 예방접종기: 활성화된 저항 유형 100% 저항", "custom",0,1,1},
			{"【 SSR 】 적중 시 화상/우유/자라테 효과 부여", "custom",0,1,1},
			{"【 SSR 】 즉시 소생", "revive rate",1,20,21},
			{"【 SSR 】 차단막 지속 시간 +50%", "increase buff duration",1,0.5,1.5},
			--{"【 SSR 】 차단막 너비, 두께 +35%, 피해량 +50%",}, [[그냥 서서 적이랑 붙어도 피해 안 닿는 정도]]
		}
	},
	[2] = --Sniper Shop
	{
		CommonAttribute =
		{
			{"피해량 +25%", "damage bonus",1,0.25},
			{"공격 속도 +15%", "fire rate bonus",1,-0.15,0.1},
			{"재장전 속도 +20%", "faster reload rate",1,-0.2,0.1},
			{"처치 시 체력 25 회복", "heal on kill",0,25},
			{"최대 체력 +25", "max health additive bonus",0,25},
			{"모든 탄약수 +50% / 장탄수 +50%", "custom",1,0.5},
			{"이동 속도 +10%", "move speed bonus",1,0.1},
			{"점프 높이 +20%", "increased jump height",1,0.2},
			{"무기 전환 속도 +35%", "deploy time decreased",1,-0.35,0},
			{"기타 재충전 속도 +15%", "effect bar recharge rate increased",1,-0.15,0.1},
			{"3 속성 저항 +25%", "custom",1,1,4},
			--{"탄환 피해 저항력 +25%", "dmg taken from bullets reduced",1,-0.25,0.1},
			--{"폭발 피해 저항력 +25%", "dmg taken from blast reduced",1,-0.25,0.1},
			--{"화염 피해 저항력 +25%", "dmg taken from fire reduced",1,-0.25,0.1},
			{"치명타 피해 저항력 +45%", "dmg taken from crit reduced",1,-0.45,0.1},
			----{"근거리 피해 저항력 +30%", "dmg from melee increased",1,-0.3,0.1},
			{"초당 체력 회복량 +4", "health regen",0,4},
			{"5초 마다 최대 탄약의 5% 보급", "ammo regen",0,0.05,1},
			{"적중 시 체력 15 회복", "heal on hit for rapidfire",0,3},
			{"저격소총: 충전 속도 +25%", "SRifle Charge rate increased",1,0.25},
			{"적중 시 5 초간 출혈", "bleeding duration",0,5},
			
			--{"활: 도발 상태중 우버차지 발동,}, [[무적 우버]]
			--{"기관단총: 장탄수 +50%", "clip size bonus",1,0.5},
		},
		RareAttribute =
		{
			{"( R ) 추가 점프 횟수 +1", "air dash count",0,1},
			{"( R ) 투사체 관통", "projectile penetration",0,1,1},
			{"( R ) 병수도 적중시 대상 이동 속도 감소", "applies snare effect",1,-0.35,0.65},
			{"( R ) 조준 시 조준선이 흔들리지 않음", "no damage view flinch",0,1,1},
			{"( R ) 기관단총: 집탄율 +100%", "weapon spread bonus",1,-1,0},
			{"( R ) 기관단총: 헤드샷 가능", "can headshot",0,1,1},
			{"( R ) 헤드샷 폭발", "explosive sniper shot",0,1},
			--{"( R ) 투사체 유도 활성화", "custom",0,1,1},
			--{"( R ) 처치 시: 소형 치료제 드롭", "drop health pack on kill",0,1,1},
			--{"( R ) 헤드샷 면역, 헤드샷 피해량 +20%",},[[역저격]]
		},
		EpicAttribute =
		{
			{"( SR ) 활: 추가 화살 +2", "arrow mastery",0,1,4},
			{"( SR ) 사망 직전 즉시 귀환", "teleport instead of die",0,1,1},
			{"( SR ) 각종 효과 지속시간 +50%", "mult effect duration",1,0.5},
			{"( SR ) 폭발 탄환 개조", "explosive bullets",0,147,147},
			{"( SR ) 처치 시 5초간 이동속도 증진", "speed_boost_on_kill",0,5,5},
			{"( SR ) 메디건 치료 광선이 연결된 모든 대상 타격", "damage all connected",0,1,1},
		},
		LegendaryAttribute =
		{
			{"【 SSR 】 저격소총: 완전 충전 시 피해량 +100%", "sniper full charge damage bonus",1,1,2},
			{"【 SSR 】 소형 치명타 발생시 크리티컬로 전환", "minicrits become crits",0,1,1},
			{"【 SSR 】 적중 시 죽음의 표식 부착", "mark for death",0,1,1},
			{"【 SSR 】 전차 대상 피해량 +200%", "mult dmg vs tanks",1,2,3},
			--{"【 SSR 】 모든 받는 치료량 +100%", "healing received bonus",1,1},
			--{"【 SSR 】 앉아있을 시 초당 피해량 10% 증가",}, [[최대 100%, 앉기만 하면 됨]]
		}
	},
	[8] = --Spy Shop
	{
		CommonAttribute =
		{
			{"피해량 +25%", "damage bonus",1,0.25},
			{"거대 로봇 백스탭 피해량 +30%", "armor piercing",0,30,150},
			{"공격 속도 +15%", "fire rate bonus",1,-0.15,0.1},
			{"재장전 속도 +20%", "faster reload rate",1,-0.2,0.1},
			{"모든 탄약수 +50% / 장탄수 +50%", "custom",1,0.5},
			{"5초 마다 최대 탄약의 5% 보급", "ammo regen",0,0.05,1},
			{"최대 체력 +25", "max health additive bonus",0,25},
			{"이동 속도 +15%", "move speed bonus",1,0.15},
			{"점프 높이 +20%", "increased jump height",1,0.2},
			{"3 속성 저항 +30%", "custom",1,1,3},
			--{"탄환 피해 저항력 +25%", "dmg taken from bullets reduced",1,-0.25,0.1},
			--{"폭발 피해 저항력 +25%", "dmg taken from blast reduced",1,-0.25,0.1},
			--{"화염 피해 저항력 +25%", "dmg taken from fire reduced",1,-0.25,0.1},
			{"치명타 피해 저항력 +45%", "dmg taken from crit reduced",1,-0.45,0.1},
			----{"근거리 피해 저항력 +30%", "dmg from melee increased",1,-0.3,0.1},
			{"초당 체력 회복량 +4", "health regen",0,4},
			{"적중 시 체력 15 회복", "heal on hit for rapidfire",0,15},
			{"은폐 재생량 +50%", "mult cloak meter regen rate",1,0.5},
			{"처치 시 은폐 에너지 +35%", "add cloak on kill",0,35},
			{"처치 시 체력 25 회복", "heal on kill",0,25},
			{"처치 시: 소형 치료제 드롭", "drop health pack on kill",0,1,1},
			{"전자 교란기 동력 강화", "robo sapper",0,1,3},
			{"무기 전환 속도 +35%", "deploy time decreased",1,-0.35,0},
			{"자금 회수 범위 +50%", "mult credit collect range",1,0.5,3},
			{"리볼버: 집탄율 +100%", "weapon spread bonus",1,-1,0},
			
			--{"장탄수 +50%", "clip size bonus",1,0.5},
			--{"은폐 지속시간 +20%", "cloak consume rate decreased",1,-0.2},
			--{"전자 교란기 재충전 속도 +15%", "charge recharge rate increased",1,0.15}, --안됨
		},
		RareAttribute =
		{
			{"( R ) 처치 시 5초간 이동속도 증진", "speed_boost_on_kill",0,1,1},
			{"( R ) 적중 시 은폐 에너지 +30%", "add cloak on hit",0,3},
			{"( R ) 투사체 관통", "projectile penetration",0,1,1},
			{"( R ) 화상/병수도/자라테 면역", "custom",0,1,1},
			{"( R ) 로봇 센트리 무시", "ignored by enemy sentries",0,1,1},
			{"( R ) 백스탭 처치 시 변장", "disguise on backstab",0,1,1},
			{"( R ) 백스탭 및 건물 새핑 시 치명타 누적", "sapper kills collect crits",0,1,1},
			{"( R ) 사망 직전 즉시 귀환", "teleport instead of die",0,1,1},
			{"( R ) 기절, 둔화 면역", "mult stun resistance",0,0,0},
			
			--{"( R ) 헤드샷 가능", "can headshot",0,1,1},
			--{"( R ) 은폐 해제 대기 시간 -50%", "mult decloak rate",1,-0.5,0.01},
		},
		EpicAttribute =
		{
			{"( SR ) 추가 점프 횟수 +3", "air dash count",0,3,6},
			{"( SR ) 근접 공격 사거리 +50%", "melee range multiplier",1,0.5},
			{"( SR ) 전자 교란기: 디버프 지속시간 +50%", "mult effect duration",1,0.5},
			{"( SR ) 리볼버: 변장 시 피해량 +200%", "damage bonus while disguised",1,2},
			{"( SR ) 건물 적중 시 7초 정지", "disable buildings on hit",0,7,14},
			{"( SR ) 메디건 치료 광선이 연결된 모든 대상 타격", "damage all connected",0,1,1},
			{"( SR ) 전차 대상 피해량 +300%", "mult dmg vs tanks",1,3,7},
			--{"( SR ) 마지막 장탄 항상 치명타", "last shot crits",0,1,1},
			--{"( SR ) 화상 면역", "afterburn immunity",0,1,1},
		},
		LegendaryAttribute =
		{
			{"【 SSR 】 은폐 지속 시간 +500% / 은폐 즉시 해제", "custom",0,1,1},
			{"【 SSR 】 근접 적중 시 0.4초 무적", "melee grants protection",0,0.4,0.4},
			{"【 SSR 】 모든 공격 75% 확률로 회피", "add cond when active",0,79,79},
			{"【 SSR 】 헤드샷 폭발 +3 / 헤드샷 활성화", "custom",0,1,1},
			--{"【 SSR 】 변장시 무적", "disguise damage reduction",1,-1,0},
 			
 			--{"【 SSR 】 모든 받는 치료량 +100%", "healing received bonus",1,1},
			--{"【 SSR 】 리볼버 사격 시 변장 유지", "keep disguise on attack",0,1,1},
		}
	}
}

--Used for returning the class name  [주석 1]
classIndices_Internal = {
    [1] = "스카웃",
    [3] = "솔저",
    [7] = "파이로",
    [4] = "데모맨",
    [6] = "헤비",
    [9] = "엔지니어",
    [5] = "메딕",
    [2] = "스나이퍼",
    [8] = "스파이",
}


--[[This table is essential, it will store the SteamID3 of a player and act as a "save file" for the player,
		Things that are stored in here for each player:
			UpgradePoints - how many upgrade points the player has, persists between classes
			RerollPoints - how many rerolls the player has, persists between classes

			An index from [1] to [9] which will represent the player's class
			Inside the index, each class has its own
				hasRolled - boolean, used as a flag if the player has rolled for upgrades on that class
				PurchasedUpgrades - table, which upgrades have been purchased for that player on that class
				MaxedUpgrades - table, which upgrades are maxed for that player on that class
				UpgradeMenu - table, show a unique upgrade menu for that player on that class
			]]
UniqueAccountIDs = {}

--[[Also very important, this table is akin to an emulator's "save state" where it will copy everything from
	UniqueAccountIDs, TotalUpgradePoints, and TotalRerollPoints. In the case that players lose a wave, this table is used
	to store save states]]
WaveState = {}

--[[Finds all func_upgradestation's on the map and lets the player interact with them for bringing up the menu]]
function EnableUpgradeStations()
	for _, v in pairs(ents.FindAllByClass("func_upgradestation")) do
		v:AddCallback(ON_START_TOUCH,
		function(_,player)
		    if player:IsRealPlayer() then
				RollUpgrades(player)
				ShowUpgradeMenu(player)
				--player:Print(2, "Weclome to the Randomizer Upgrade Station!") --없어도 되지 않을까요
			end
		end)
		v:AddCallback(ON_END_TOUCH,
		function(_,player)
		    if player:IsRealPlayer() then
				CloseUpgradeMenu(player) --probably redundnant
				--player:Print(2, "You have left the Randomizer Upgrade Station.")-- 없어도 되지 않을까요
			end
		end)
	end
end

--[[Adds the OnSpawn callback so that everytime a player spawns their upgrades are reapplied]]
function OnPlayerConnected(player)
    if player:IsRealPlayer() then
        player:AddCallback(ON_SPAWN, function(player)
			InitUserId(player)
			ReAddPurchasedUpgrades(player)
		end)
    end
end

--[[If the player joins the server for the first time, their SteamID3 is added to UniqueAccountIDs
	Note that the function for pruchasing upgrades is stored here]]
function InitUserId(activator)
	local player = (ents.FindByClass("tf_player_manager", nil)):DumpProperties().m_iAccountID[activator:GetNetIndex()+1]
	if UniqueAccountIDs[player] == nil then
		UniqueAccountIDs[player] =
		{
			UpgradePoints = TotalUpgradePoints,
			RerollPoints = TotalRerollPoints,
		}
	end

	local class = activator:DumpProperties().m_iClass
	if UniqueAccountIDs[player][class] == nil then
		UniqueAccountIDs[player][class] =
		{
			hasRolled = false,
			PurchasedUpgrades = {}, --Stored as key [Upgrade name] with value equal to how many times it was purchased
			MaxedUpgrades = {}, --Used a temporary table, similar to PurchasedUpgrades, probably not needed in style2
			UpgradeMenu =
			{
				timeout = 0,
				title = "Select an upgrade - ",
				itemsPerPage = nil,
				flags = MENUFLAG_BUTTON_EXIT,
				onSelect = function(activator, index, value) --Responsible for subtracting upgrade/reroll points, disabling purchased upgrades
					local player = UniqueAccountIDs[(ents.FindByClass("tf_player_manager", nil)):DumpProperties().m_iAccountID[activator:GetNetIndex()+1]]
					local class = activator:DumpProperties().m_iClass
					local purchased = player[class].PurchasedUpgrades
					local menu = player[class].UpgradeMenu
					local playername = activator:DumpProperties().m_szNetname[1]

					if value ~= "reroll" then
						if purchased[value] == nil then
							purchased[value] = 1
						else
							purchased[value] = purchased[value] + 1
						end

						menu[index].disabled = true
						AddUpgrade(activator, value)

						local upgradetable = {}
						for i in (string.gmatch(value, "[^,]+")) do
							upgradetable[#upgradetable + 1] = i
						end
						local upgrade = upgradetable[1]

						if string.find(upgrade, "( R )",1,true) then -- 루아 string.sub (참조 문자열,시작 문자열 위치,끝 문자열 위치) \x074B69FF = 색상코드 \x07RRGGBB
							util.PrintToChatAll("\x07ff3d3d"  .. playername .." " .. "\x074B69FF".. string.sub(upgrade,1,5) .. "\x07FFD700".. string.sub(upgrade,6,#upgrade) .. "\x07fbeccb Level " .. purchased[value] .. "\x07fbeccb 을 구입 하였습니다. ")
						elseif string.find(upgrade, "( SR )",1,true) then
							util.PrintToChatAll("\x07ff3d3d"  .. playername .. " " .. "\x078847FF".. string.sub(upgrade,1,6) .. "\x07FFD700".. string.sub(upgrade,7,#upgrade) .. "\x07fbeccb Level " .. purchased[value] .. "\x07fbeccb 을 구입 하였습니다. ")
						elseif string.find(upgrade, "【 SSR 】",1,true) then
							util.PrintToChatAll("\x07ff3d3d"  .. playername .. " " .. "\x07EB4B4B".. string.sub(upgrade,1,11) .. "\x07FFD700".. string.sub(upgrade,12,#upgrade) .. "\x07fbeccb Level " .. purchased[value] .. "\x07fbeccb 을 구입 하였습니다. ")
						else
						util.PrintToChatAll("\x07ff3d3d"  .. playername .. " "  .. "\x07FFD700" .. upgrade .. "\x07fbeccb Level " .. purchased[value] .. "\x07fbeccb 을 구입 하였습니다. ")
						end

						player.UpgradePoints = player.UpgradePoints - 1

						player[class].hasRolled = false
						RollUpgrades(activator) --after purchasing an upgrade, reroll for new set of upgrades

					else
						RerollUpgrades(activator)
					end

					ShowUpgradeMenu(activator)
				end,
				onCancel = nil
			}
		}
	end
end

--[[Your random number generator, returns a float to allow for decimal probabilities
	In this example, it rolls for rarity first, then rolls a second time to pick an upgrade
	So the probability of a specific upgrade is based on two rng rolls]]
function UpgradeRoulette(activator)
	local number = math.random() --returns float from 0 to 1
	local class = activator:DumpProperties().m_iClass
	local shop = AllShops[class]
	local pool = {}

	if number < 0.80 then --확률 조정
		pool = shop.CommonAttribute
	elseif (number >= 0.80 and number < 0.96) then
		pool = shop.RareAttribute
	elseif (number >= 0.96 and number < 0.99) then
		pool = shop.EpicAttribute
	elseif number >= 0.99 then --probably should be less than 1%
		pool = shop.LegendaryAttribute
	end

	local index = math.random(1,(#pool)) --returns integer from 1 to number of upgrades in pool
	local upgrade = pool[index]

	return upgrade
end

--[[This function calls UpgradeRoulette and sends the chosen upgrades to the upgrade menu]]
function RollUpgrades(activator)
	local player = UniqueAccountIDs[(ents.FindByClass("tf_player_manager", nil)):DumpProperties().m_iAccountID[activator:GetNetIndex()+1]]
	local class = activator:DumpProperties().m_iClass
	local menu = player[class].UpgradeMenu
	local purchased = player[class].PurchasedUpgrades
	local maxed = player[class].MaxedUpgrades

	if player[class].hasRolled ~= true then
		for index = 1, MenuCapacity, 1 do
			menu[index] = {}
			maxed = {}
		end

		for index = 1, MenuCapacity, 1 do
			local upgrade = UpgradeRoulette(activator)
			local upgradestring = table.concat(upgrade,",")

			--[[Used to prevent maxed out upgrades from reappearing in the shop
				Note that this is possibly bugged in style2, will fix later]]
			function CheckMaxed(upgrade)
				local min = upgrade[3]
				local increment = upgrade[4]
				local max = upgrade[5]
				if max ~= nil then
					if maxed[upgradestring] == nil then
						if purchased[upgradestring] == nil then
							maxed[upgradestring] = 0
						else
							maxed[upgradestring] = purchased[upgradestring]
						end
					else
						maxed[upgradestring] = maxed[upgradestring] + 1
					end
					local value = min + maxed[upgradestring] * increment
					if increment > 0 then
						return (tostring(value) >= tostring(max))  --floating point issue
					else
						return (tostring(value) <= tostring(max))
					end
				end
			end

			if CheckMaxed(upgrade) == true then --If upgrade is maxed, reroll
				while CheckMaxed(upgrade) == true do
					upgrade = UpgradeRoulette(activator)
				end
			end

			for i = 1, MenuCapacity, 1 do --If upgrade is duplicate, reroll
				if menu[i].text == upgrade[1] then
					while menu[i].text == upgrade[1] do
						upgrade = UpgradeRoulette(activator)
					end
				end
			end

			menu[index] = {text = upgrade[1], value = table.concat(upgrade,","), disabled = false} --value can't accept tables, only strings/numbers
		end
		player[class].hasRolled = true
	end
end

--Called when the reroll option is selected, subtracts a reroll point
function RerollUpgrades(activator)
	local player = UniqueAccountIDs[(ents.FindByClass("tf_player_manager", nil)):DumpProperties().m_iAccountID[activator:GetNetIndex()+1]]
	local class = activator:DumpProperties().m_iClass

	player.RerollPoints = player.RerollPoints - 1
	player[class].hasRolled = false
	RollUpgrades(activator)
end

--Sets hasRolled to false for all players in the game, usually called on wave end
function ResetRolls()
	for _, v in pairs(UniqueAccountIDs) do
		for i = 1, 9, 1 do
			if v[i] ~= nil then
				v[i].hasRolled = false
			end
		end
	end
end

--[[Apply upgrades to players
	using "custom" allows you do anything you define in the function as an upgrade
	meaning PointTemplate upgrades are possible]]
function AddUpgrade(activator, value)
	local player = UniqueAccountIDs[(ents.FindByClass("tf_player_manager", nil)):DumpProperties().m_iAccountID[activator:GetNetIndex()+1]]
	local class = activator:DumpProperties().m_iClass
	local purchased = player[class].PurchasedUpgrades
	local upgradetable = {}

	for i in string.gmatch(value, "[^,]+") do
		upgradetable[#upgradetable + 1] = i
	end
	local upgrade = upgradetable[1]
	local attributename = upgradetable[2]
	local min = tonumber(upgradetable[3])
	local increment = tonumber(upgradetable[4])
	local max = tonumber(upgradetable[5])

	if attributename == "custom" then
		if upgrade == "모든 탄약수 +50%" then
			activator:SetAttributeValue("maxammo primary increased",min+increment*purchased[value])
			activator:SetAttributeValue("maxammo secondary increased",min+increment*purchased[value])
			activator:SetAttributeValue("maxammo grenades1 increased",min+increment*2*purchased[value])
		elseif upgrade == "모든 탄약수 +50% / 장탄수 +50%" then
			activator:SetAttributeValue("maxammo primary increased",min+increment*purchased[value])
			activator:SetAttributeValue("maxammo secondary increased",min+increment*purchased[value])
			activator:SetAttributeValue("clip size bonus",min+increment*purchased[value])
			activator:SetAttributeValue("maxammo grenades1 increased",min+increment*2*purchased[value])
			activator:SetAttributeValue("maxammo grenades1 increased",min+increment*2*purchased[value])
		elseif upgrade == "( R ) 투사체 유도 활성화" then
			activator:SetAttributeValue("mod projectile heat seek power",270)
			activator:SetAttributeValue("mod projectile heat aim error",90)
			activator:SetAttributeValue("mod projectile heat no predict target speed",1)
			activator:SetAttributeValue("mod projectile heat aim time",1.25)
			activator:SetAttributeValue("mod projectile heat aim start time",0.25)
		elseif upgrade == "( SR ) 투사체 유도 활성화" then
			activator:SetAttributeValue("mod projectile heat seek power",270)
			activator:SetAttributeValue("mod projectile heat aim error",90)
		elseif upgrade == "3 속성 저항 +25%" then
			activator:SetAttributeValue("dmg taken from blast reduced",math.max(1+(-0.25*purchased[value]),0.25))
			activator:SetAttributeValue("dmg taken from fire reduced",math.max(1+(-0.25*purchased[value]),0.25))
			activator:SetAttributeValue("dmg taken from bullets reduced",math.max(1+(-0.25*purchased[value]),0.25))
		elseif upgrade == "3 속성 저항 +30%" then
			activator:SetAttributeValue("dmg taken from blast reduced",math.max(1+(-0.3*purchased[value]),0.1))
			activator:SetAttributeValue("dmg taken from fire reduced",math.max(1+(-0.3*purchased[value]),0.1))
			activator:SetAttributeValue("dmg taken from bullets reduced",math.max(1+(-0.3*purchased[value]),0.1))
		elseif upgrade == "3 속성 저항 +45%" then
			activator:SetAttributeValue("dmg taken from blast reduced",math.max(1+(-0.45*purchased[value]),0.1))
			activator:SetAttributeValue("dmg taken from fire reduced",math.max(1+(-0.45*purchased[value]),0.1))
			activator:SetAttributeValue("dmg taken from bullets reduced",math.max(1+(-0.45*purchased[value]),0.1))
			
		--솔저
		elseif upgrade == "【 SSR 】 중력 로켓 / 폭발 범위 +70%" then
			activator:SetAttributeValue("projectile gravity",1200)
			activator:SetAttributeValue("Blast radius increased",1.7)
		elseif upgrade == "【 SSR 】 수직이착륙 솔저" then
			activator:SetAttributeValue("add cond when active",107)
			activator:SetAttributeValue("move speed penalty",8)
		elseif upgrade == "【 SSR 】 이중 사격" then
			activator:SetAttributeValue("burst fire count",2)
			activator:SetAttributeValue("burst fire rate mult",20)
			activator:SetAttributeValue("fire rate penalty HIDDEN",0.05)
			
		--파이로
		elseif upgrade == "【 SSR 】 화염 수명 +500%" then
			activator:SetAttributeValue("flame_lifetime",6)
			activator:SetAttributeValue("flame_up_speed",-100)
			activator:SetAttributeValue("flame_ignore_player_velocity",1)
			
		--데모맨
		elseif upgrade == "( R ) 근거리 공격 너비 +50% / 사거리 +25%" then
			activator:SetAttributeValue("melee bounds multiplier",1+(0.5*purchased[value]))
			activator:SetAttributeValue("melee range multiplier",1+(0.25*purchased[value]))
		elseif upgrade == "( R ) 방패: 돌격 유지 시간 +3초 / 돌격 완전 제어" then
			activator:SetAttributeValue("full charge turn control",1)
			activator:SetAttributeValue("mult charge turn control",11)
			activator:SetAttributeValue("charge time increased",3*purchased[value])
		
		--헤비
		elseif upgrade == "【 SSR 】 거대화 / 최대 체력 +700" then
			activator:SetAttributeValue("is miniboss",1)
			activator:SetAttributeValue("max health additive penalty",700)
			activator:SetAttributeValue("move speed penalty",0.5)
			activator:SetAttributeValue("patient overheal penalty",0.5)
			
		--엔지
		elseif upgrade == "( R ) 텔레포터 개선" then
			activator:SetAttributeValue("mod teleporter speed boost",1)
			activator:SetAttributeValue("mult teleporter recharge rate",0.05)
			activator:SetAttributeValue("bidirectional teleport",1)
		elseif upgrade == "( SR ) 센트리 건 로켓 발사 속도 +30% / 로켓 특화 +1" then
			activator:SetAttributeValue("mult firerocket rate",math.max(1-(0.3*purchased[value]),0.1))
			activator:SetAttributeValue("rocket specialist",1*purchased[value])
			
		--메딕
		elseif upgrade == "【 SSR 】 적중 시 화상/우유/자라테 효과 부여" then
			activator:SetAttributeValue("add cond on hit",123 + 27*256 + 24*65536) --123 = gas, 27 = milk, 24 = jarate, total is 1579899
			activator:SetAttributeValue("add cond on hit duration",10)
			activator:SetAttributeValue("bleeding duration",10)
		elseif upgrade == "【 SSR 】 예방접종기: 활성화된 저항 유형 100% 저항" then
			activator:SetAttributeValue("medigun bullet resist passive",1)
			activator:SetAttributeValue("medigun blast resist passive",1)
			activator:SetAttributeValue("medigun fire resist passive",1)
		elseif upgrade == "test1" then
			activator:SetAttributeValue("medigun passive attributes","damage force reduction|-2|")
			--activator:SetAttributeValue("medigun blast resist passive",1)
			--activator:SetAttributeValue("medigun fire resist passive",1)
			
		--스파이
		elseif upgrade == "( R ) 화상/병수도/자라테 면역" then
			activator:SetAttributeValue("afterburn immunity",1)
			activator:SetAttributeValue("wet immunity",1)
		elseif upgrade == "【 SSR 】 헤드샷 폭발 +3 / 헤드샷 활성화" then
			activator:SetAttributeValue("explosive sniper shot",3)
			activator:SetAttributeValue("can headshot",1)
		elseif upgrade == "【 SSR 】 은폐 지속 시간 +500% / 은폐 즉시 해제" then
			activator:SetAttributeValue("cloak consume rate decreased",-4)
			activator:SetAttributeValue("mult decloak rate",0.01)
			
		end
	elseif attributename ~= "custom" then
		if max ~= nil then
			if increment > 0 then
				activator:SetAttributeValue(attributename,math.min(min+increment*purchased[value],max))
			else
				activator:SetAttributeValue(attributename,math.max(min+increment*purchased[value],max))
			end
		else
			activator:SetAttributeValue(attributename,min+increment*purchased[value])
		end
	end
end

--Give all players specified amount of upgrade points, adds running total to TotalUpgradePoints for late joiners
function AddUpgradePoints(number)
	for _, v in pairs(UniqueAccountIDs) do
		v.UpgradePoints = v.UpgradePoints + number
	end
	TotalUpgradePoints = TotalUpgradePoints + number
end

--Give all players specified amount of rerolls, adds running total to TotalRerollPoints for late joiners
function AddRerollPoints(number)
	for _, v in pairs(UniqueAccountIDs) do
		v.RerollPoints = v.RerollPoints + number
	end
	TotalRerollPoints = TotalRerollPoints + number
end

--Set all players's upgrade points to specified value without adding or subtracting to TotalUpgradePoints
function SetUpgradePoints(number)
	for _, v in pairs(UniqueAccountIDs) do
		v.UpgradePoints = number
	end
end

--Set all players's rerolls to specified value without adding or subtracting to TotalRerollPoints
function SetRerollPoints(number)
	for _, v in pairs(UniqueAccountIDs) do
		v.RerollPoints = number
	end
end

--Iterates upon PurchasedUpgrades table and calls AddUpgrade for each upgrade, called OnSpawn of every player
function ReAddPurchasedUpgrades(activator)
	local player = UniqueAccountIDs[(ents.FindByClass("tf_player_manager", nil)):DumpProperties().m_iAccountID[activator:GetNetIndex()+1]]
	local class = activator:DumpProperties().m_iClass
	local purchased = player[class].PurchasedUpgrades

	for k, _ in pairs(purchased) do
		AddUpgrade(activator, k)
	end
	activator:RefillAmmo()
end

--[[This function will display the shop menu
	It shows how many upgrade levels were purchased and the max if it exists
	It will also show the corresponding class you are playing as in the title
	Shows how many upgrade points are remaining
	Always adds the reroll option to the bottom of the list
	Will disable the shop if the player has no more upgrade points]]
function ShowUpgradeMenu(activator)
	local player = UniqueAccountIDs[(ents.FindByClass("tf_player_manager", nil)):DumpProperties().m_iAccountID[activator:GetNetIndex()+1]]
	local class = activator:DumpProperties().m_iClass
	local menu = player[class].UpgradeMenu
	local purchased = player[class].PurchasedUpgrades

	menu[MenuCapacity+1] = {text= classIndices_Internal[class] .. " 상점 새로고침\n    새로고침 " .. player.RerollPoints .. " 번 남음", value="reroll"}
	if player.RerollPoints == 1 then
		menu[MenuCapacity+1] = {text= classIndices_Internal[class] .. " 상점 새로고침\n    새로고침 "  .. player.RerollPoints .. " 번 남음", value="reroll"}
	elseif player.RerollPoints <= 0 then
		menu[MenuCapacity+1] = {text= classIndices_Internal[class] .. " 상점 새로고침\n    새로고침 "  .. player.RerollPoints .. " 번 남음", value="reroll", disabled = true}
	end

	menu.title = classIndices_Internal[class] .. " 상점\n업그레이드를 선택 하세요\n" ..  player.UpgradePoints .. " 업그레이드 포인트 남음\n "
	if player.UpgradePoints == 1 then
		menu.title = classIndices_Internal[class] .. " 상점\n업그레이드를 선택 하세요\n" .. player.UpgradePoints .. " 업그레이드 포인트 남음\n "
	elseif player.UpgradePoints <= 0 then
		for i = 1, MenuCapacity+1, 1 do
			menu[i].disabled = true
		end
	end

	for i = 1, MenuCapacity, 1 do
		local value = menu[i].value
		local upgradetable = {}
		for k in string.gmatch(value, "[^,]+") do
			upgradetable[#upgradetable + 1] = k
		end
		local min = upgradetable[3]
		local increment = upgradetable[4]
		local max = upgradetable[5]

		if purchased[value] ~= nil then
			menu[i].text = menu[i].text .. "\n    #: " .. purchased[value]
		else
			menu[i].text = menu[i].text .. "\n    #: 0"
		end
		if max ~= nil then
			menu[i].text = menu[i].text .. "          Max: " .. math.ceil((max-min)/increment) --big brain math
		end
	end

	activator:DisplayMenu(menu)

	for i = 1, MenuCapacity, 1 do
		local value = menu[i].value
		local upgradetable = {}
		for k in string.gmatch(value, "[^,]+") do
			upgradetable[#upgradetable + 1] = k
		end
		upgrade = upgradetable[1]

		menu[i].text = upgrade
	end
end

function CloseUpgradeMenu(activator) --probably redundnant
	activator:HideMenu()
end

function deepCopy(original) --special thx to https://developer.roblox.com
	local copy = {}
	for k, v in pairs(original) do
		if type(v) == "table" then
			v = deepCopy(v)
		end
		copy[k] = v
	end
	return copy
end

function OnWaveSuccess(wave) --웨이브당 업그레이드 포인트, 리롤 포인트 지급량 설정
	AddUpgradePoints(4) 
	AddRerollPoints(3)
end

function OnWaveReset(wave) --on wave reset, load save state from WaveState
	if WaveState[wave] ~= nil then
		TotalUpgradePoints = WaveState[wave].TotalUpgradePoints
		TotalRerollPoints = WaveState[wave].TotalRerollPoints
		UniqueAccountIDs = deepCopy(WaveState[wave].UniqueAccountIDs)
	end
end

function OnWaveInit(wave) --on wave init, create save state in WaveState, reset rolls
	EnableUpgradeStations() --for wave 1
	if WaveState[wave] == nil then
		WaveState[wave] =
		{
			TotalUpgradePoints = TotalUpgradePoints,
			TotalRerollPoints = TotalRerollPoints,
			UniqueAccountIDs = deepCopy(UniqueAccountIDs)
		}
	end
	ResetRolls()
end