/**
 * 
 *   자동 숏컷 시스템 (상하이팀에서 데리고 와서, 스팀 버전을 위한 기능 변경 및 추가 버전)
 *   
 **/
class AutoShotItemWnd extends UICommonAPI;

const ITEM_ADD      =  1;
const ITEM_SET      =  2;
const ITEM_CLEAR    =  3;

const TIME_ID     = 30021;
const TIME_DELAY  = 5000;

struct slotData
{
	var bool bNoticeShow;
	var string toolTipStr;
};


var WindowHandle  Me;

var WindowHandle AutoShotItemSubWnd;

// 펫(펫, 컴페니언), 소환수, 0과 같거나 작으면 소환 안된 상태
var int PetID, SummonID;

//var WindowHandle  AutoShotNoticeWnd;
//var TextBoxHandle AutoShotNotice_TextBox;

var TextureHandle petIconTexture;

// 무기를 소유 했나?
var bool hasWeapon;

// 소환수, 펫, 컴페니언 활성화 여부
var bool bSummon, bPet, bBeforeSummon, bBeforePet;

// 탄이 없다고 메세지를 보여 줄 것인가?
// 알림을 보여줄 카운트 
var int showNoticeNum;

// 현재 선택된 윈도우 번호 플레이어1,2   ,팻 3,4
var int currentSelectSoulShotWndIndex;

var ItemInfo weaponItemInfo;
var ItemInfo beforeWeaponInfo;
var ShortcutWnd ShortcutWndScript;
//var AutoTargetWnd AutoTargetWndScript;

var AutoPotionWnd AutoPotionWndScript;
var YetiPCModeChangeWnd YetiPCModeChangeWndScript;

/**
 *  OnRegisterEvent
 **/ 
function OnRegisterEvent()
{
	RegisterEvent( EV_SoulShotUpdate );
	
	RegisterEvent( EV_BeginSoulShotUpdate );

	RegisterEvent( EV_InventoryUpdateItem );
	RegisterEvent( EV_InventoryAddItem );

	RegisterEvent( EV_Restart );

	RegisterEvent( EV_ShortcutkeyassignChanged );

	RegisterEvent(EV_GameStart); //최초 접속 시 오는 이벤트로 교체 TT#73058
}

/**
 *  OnLoad
 **/ 
function OnLoad()
{
	Initialize();
}

/**
 *  Initialize
 **/
function Initialize()
{
	Me = GetWindowHandle ( "AutoShotItemWnd" );
	AutoShotItemSubWnd = GetWindowHandle( "AutoShotItemWnd.AutoShotItemSubWnd" );
	ShortcutWndScript  = ShortcutWnd(GetScript("ShortcutWnd"));
	//AutoTargetWndScript = AutoTargetWnd(GetScript("AutoTargetWnd"));
	AutoPotionWndScript = AutoPotionWnd(GetScript("AutoPotionWnd"));
	YetiPCModeChangeWndScript = YetiPCModeChangeWnd(GetScript("YetiPCModeChangeWnd"));
	init();
}

function CustomTooltip SetTooltip(string Text)
{
	local CustomTooltip Tooltip;
	local DrawItemInfo info;
	
	Tooltip.MinimumWidth = 144;
	Tooltip.DrawList.Length = 1;
	
	info.eType = DIT_TEXT;
	info.t_color.R = 178;
	info.t_color.G = 190;
	info.t_color.B = 207;
	info.t_color.A = 255;
	info.t_strText = Text;
	Tooltip.DrawList[0] = info;

	return Tooltip;
}

/**
 * 데이타 초기화
 **/
function init()
{
	local int i;
	local ItemInfo tempInfo;


	for (i = 1; i < 5; i++)
	{
		GetItemWindowHandle("AutoShotItemWnd.AutoShotItemWnd_HorWnd.ShotItemSlot" $ i).Clear();
		GetItemWindowHandle("AutoShotItemWnd.AutoShotItemWnd_VerWnd.ShotItemSlot" $ i).Clear();

		// 플레이어
		if(i == 1 || i == 2)
		{
			GetItemWindowHandle("AutoShotItemWnd.AutoShotItemWnd_HorWnd.ShotItemSlot" $ i).SetTooltipText(GetSystemMessage(6828));
			GetItemWindowHandle("AutoShotItemWnd.AutoShotItemWnd_VerWnd.ShotItemSlot" $ i).SetTooltipText(GetSystemMessage(6828));
			// [Explicit Continue]
			continue;
		}
		if(IsAdenServer())
		{
			GetTextureHandle("AutoShotItemWnd.AutoShotItemWnd_HorWnd.PetSlotGroupWnd_HorWnd.shotbg_PetWarrior_horTexture").SetTexture("L2UI_ct1.AutoShotItemWnd.shotbg_WeaponWarrior");
			GetTextureHandle("AutoShotItemWnd.AutoShotItemWnd_HorWnd.PetSlotGroupWnd_HorWnd.shotbg_PetMagic_horTexture").SetTexture("L2UI_ct1.AutoShotItemWnd.shotbg_WeaponMagic");
			GetTextureHandle("AutoShotItemWnd.AutoShotItemWnd_VerWnd.PetSlotGroupWnd_VerWnd.shotbg_PetWarrior_VerTexture").SetTexture("L2UI_ct1.AutoShotItemWnd.shotbg_WeaponWarrior");
			GetTextureHandle("AutoShotItemWnd.AutoShotItemWnd_VerWnd.PetSlotGroupWnd_VerWnd.shotbg_PetMagic_VerTexture").SetTexture("L2UI_ct1.AutoShotItemWnd.shotbg_WeaponWarrior");
			GetItemWindowHandle("AutoShotItemWnd.AutoShotItemWnd_HorWnd.ShotItemSlot" $ string(i)).SetTooltipText(GetSystemMessage(6828));
			GetItemWindowHandle("AutoShotItemWnd.AutoShotItemWnd_VerWnd.ShotItemSlot" $ string(i)).SetTooltipText(GetSystemMessage(6828));
			// [Explicit Continue]
			continue;
		}
		
		GetTextureHandle("AutoShotItemWnd.AutoShotItemWnd_HorWnd.PetSlotGroupWnd_HorWnd.shotbg_PetWarrior_horTexture").SetTexture("L2UI_ct1.AutoShotItemWnd.shotbg_PetWarrior");
		GetTextureHandle("AutoShotItemWnd.AutoShotItemWnd_HorWnd.PetSlotGroupWnd_HorWnd.shotbg_PetMagic_horTexture").SetTexture("L2UI_ct1.AutoShotItemWnd.shotbg_PetMagic");
		GetTextureHandle("AutoShotItemWnd.AutoShotItemWnd_VerWnd.PetSlotGroupWnd_VerWnd.shotbg_PetWarrior_VerTexture").SetTexture("L2UI_ct1.AutoShotItemWnd.shotbg_PetWarrior");
		GetTextureHandle("AutoShotItemWnd.AutoShotItemWnd_VerWnd.PetSlotGroupWnd_VerWnd.shotbg_PetMagic_VerTexture").SetTexture("L2UI_ct1.AutoShotItemWnd.shotbg_PetMagic");
		GetItemWindowHandle("AutoShotItemWnd.AutoShotItemWnd_HorWnd.ShotItemSlot" $ string(i)).SetTooltipText(GetSystemMessage(6829));
		GetItemWindowHandle("AutoShotItemWnd.AutoShotItemWnd_VerWnd.ShotItemSlot" $ string(i)).SetTooltipText(GetSystemMessage(6829));
	}

	PetID = 0;
	SummonID = 0;
	showNoticeNum = 0;

	hasWeapon = false;
	bBeforeSummon = false;
	bBeforePet = false;

	beforeWeaponInfo = tempInfo;
	weaponItemInfo = tempInfo;

	// 캐릭터 무기
	GetWindowHandle(getSlotPath(false, 1)).HideWindow();
	GetWindowHandle(getSlotPath(true, 1)).HideWindow();

	// 펫 
	GetWindowHandle(getSlotPath(false, 3)).HideWindow();
	GetWindowHandle(getSlotPath(true, 3)).HideWindow();

	// 보조창 숨기기
	HideWindow("AutoShotItemWnd.AutoShotItemSubWnd");

	// 기본창 숨기기
	Me.HideWindow();
	Me.KillTimer(TIME_ID);
}

function onShow()
{
	windowPositionAutoMove();
}

function OnDefaultPosition()
{
	windowPositionAutoMove();
	checkSlotShowState();
}

/** 고정 위치로 자동 이동 */
function windowPositionAutoMove()
{
	//Debug("GetGameStateName()" @ GetGameStateName());
	if (GetGameStateName() != "GAMINGSTATE") 
	{
		return;
	}

	//Debug("windowPositionAutoMove"@ GetGameStateName());
	
	// 다 숨겨 놓고..
	//GetWindowHandle("AutoShotItemWnd.AutoShotItemWnd_VerWnd").HideWindow();
	//GetWindowHandle("AutoShotItemWnd.AutoShotItemWnd_HorWnd").HideWindow();

	// 세로로 숏컷창이 배치 되어 있나?
	if(IsVertical())
	{
		if(GetWindowHandle("ShortcutWnd.ShortcutWndVertical" $ getShortcutIndexStr()).m_pTargetWnd == none)
		{
			return;			
		}
		else
		{
			GetWindowHandle("AutoShotItemWnd").ClearAnchor();
			GetWindowHandle("AutoShotItemWnd").SetAnchor("ShortcutWnd.ShortcutWndVertical" $ getShortcutIndexStr(), "TopLeft", "TopRight", -1, 17);
		}
	}
	else
	{
		if(GetWindowHandle("ShortcutWnd.ShortcutWndHorizontal" $ getShortcutIndexStr()).m_pTargetWnd == none)
		{
			return;			
		}
		else
		{
			GetWindowHandle("AutoShotItemWnd").ClearAnchor();
			GetWindowHandle("AutoShotItemWnd").SetAnchor("ShortcutWnd.ShortcutWndHorizontal" $ getShortcutIndexStr(), "TopLeft", "BottomLeft", 16, -1);
		}
	}

	AutoPotionWndScript.windowPositionAutoMove();
	//checkSlotShowState();
}

// 숏컷 확장 슬롯의 현재 상태에 따라 뒤에 붙는 최종 슬롯 수 string을 리턴
function string getShortcutIndexStr()
{
	local int nIndex;
	local string rValue;

	nIndex = ShortcutWndScript.getExpandNum();

	if (nIndex <= 0) rValue = "";
	else rValue = "_" $ nIndex;

	return rValue;
}
/**
 * OnEvent 
 **/
function OnEvent(int Event_ID, string param)
{
	if(getInstanceUIData().getIsArenaServer())
	{
		return;
	}

	// 클래식 서버만 사용하도록..
	//if ( !getInstanceUIData().getIsClassicServer() ) return;
	
	// Debug("--자동정탄-- " @ Event_ID);
	// Debug("--param    " @ param);	

	switch( Event_ID )
	{	
		case EV_GameStart:
			checkSlotShowState();
			windowPositionAutoMove();
			break;
		case EV_BeginSoulShotUpdate:
			beginSoulShotUpdateHandle(param);
			break;
	    case EV_SoulShotUpdate:
			soulShotUpdateHandle(param);
			break;
		case EV_InventoryUpdateItem:
		case EV_InventoryAddItem:
			syncInventory(param);
			break;
		case EV_Restart:
			init();
			break;
		case EV_ResolutionChanged:
			windowPositionAutoMove();
			Me.SetTimer(TIME_ID, TIME_DELAY);
			break;
		case EV_ShortcutkeyassignChanged:
			windowPositionAutoMove();
			break;
	}
}

/**
 *  정탄, 마정탄 정보 추가 시작!
 **/
function beginSoulShotUpdateHandle(string param)
{
	local int i;

	ParamToItemInfo(param, weaponItemInfo);

	// 알림을 보여줘야 하는 정탄, 마정탄의 수, 초기화
	showNoticeNum = 0;

	//Debug("-->"@ weaponItemInfo.ID.ClassID);
	//Debug("-> beginSoulShotUpdateHandle" @ param);

	// 무기 업데이트
	updateSlotWeapon(weaponItemInfo);

	for(i = 0; i < 4; i++)
	{
		showTextureCounter(false, true, i + 1);
		showTextureCounter(false, false, i + 1);
	}
	
	windowPositionAutoMove();

	//checkSlotShowState();
}

// 무기나 팻 소환 상태에 따라 정탄 슬롯 윈도우를 보이게, 안보이게
function checkSlotShowState()
{
	if ( GetGameStateName() != "GAMINGSTATE" )
		return;

	if ( YetiPCModeChangeWndScript.isYetiMode() )
	{
		if ( Me.IsShowWindow() )
			Me.HideWindow();
		return;
	}
	else if ( !Me.IsShowWindow() )
		Me.ShowWindow();

	if ( !Me.IsShowWindow() )
		Me.ShowWindow();

	AutoPotionWndScript.windowPositionAutoMove();
	GetWindowHandle(getSlotPath(false, 1)).HideWindow();
	GetWindowHandle(getSlotPath(true, 1)).HideWindow();
	GetWindowHandle(getSlotPath(false, 3)).HideWindow();
	GetWindowHandle(getSlotPath(true, 3)).HideWindow();
	GetWindowHandle(getSlotPath(IsVertical(), 1)).ShowWindow();
	if(hasWeapon == false)
	{
		showTextureCounter(false, true, 1);
		showTextureCounter(false, true, 2);
		showTextureCounter(false, false, 1);
		showTextureCounter(false, false, 2);
	}

	// 소환수, 팻 둘 중 하나라도 있으면..
	if (bBeforeSummon || bBeforePet)
	{
		GetWindowHandle(getSlotPath(IsVertical(), 3)).ShowWindow();
		//if(IsVertical())
		//{
		//	showTextureCounter(true, true, 3);
		//	showTextureCounter(true, true, 4);
		//}
		//else
		//{
		//	showTextureCounter(true, false, 3);
		//	showTextureCounter(true, false, 4);
		//}
	}
	else
	{
		GetWindowHandle(getSlotPath(false, 3)).HideWindow();
		GetWindowHandle(getSlotPath(true , 3)).HideWindow();
	}
	AutoPotionWndScript.windowPositionAutoMove();
}

/**
 *  정탄, 마정탄 정보 완료!
 **/
function endSoulShotUpdateHandle()
{
	bBeforeSummon = bSummonException();
	bBeforePet = class'UIDATA_PET'.static.IsHavePet();
	beforeWeaponInfo = weaponItemInfo;	
}

function bool bSummonException()
{
	local bool bSummonFlag;
	local int nPlayClassID;

	if(getInstanceUIData().getIsLiveServer())
	{
		nPlayClassID = DetailStatusWnd(GetScript("DetailStatusWnd")).CurrentSubjobClassID;
		switch(nPlayClassID)
		{
			case 176:
			case 177:
			case 178:
				bSummonFlag = false;
				break;
			default:
				bSummonFlag = numToBool(class'UIDATA_PET'.static.GetSummonNum());
				break;
		}		
	}
	else
	{
		bSummonFlag = numToBool(class'UIDATA_PET'.static.GetSummonNum());
	}
	return bSummonFlag;	
}

/** 
 * soulShotUpdateHandle 
 * 
 * int type : 1.정령탄, 2.마법탄, 3.야수정령탄, 4.야수 마법탄 
 * int have : 0 없다,1 있다. 
 * int activate : 0 비활성화 1.활성화 
 * ItemInfo itemInfo : 아이템 정보. 
 *  
 **/
function soulShotUpdateHandle(string param)
{
	// 1~4번 슬롯 , 정령 마정탄을 소유 했나?
	local int nType, nHave;

	// 활성화 여부 (정령, 마정탄)
	local int nActivate;

	// String
	local string itemCountStr, toolTipStr, gradeName;
	local int nToolTipStringMessage;

	// 정령, 마정탄 정보, 착용한 무기정보
	local ItemInfo targetItemInfo, beforeTargetItemInfo;

	// 아이템 주변을 반짝이는 효과 보여 줄지 여부
	local bool bTwinkleEffect;

	// 아이템 ID 임시저장용
	local ItemID tempItemID;
	local string gradeString, effectPath;

	// local string meiYouEffectUIParam;

	//bShowNotice = false;

	ParseInt  (param, "type", nType);
	ParseInt  (param, "have", nHave);
	ParseInt  (param, "activate", nActivate);
	
	ParamToItemInfo(param, targetItemInfo);

	// debug("->" @ targetItemInfo.Name @ " " @ targetItemInfo.AdditionalName @ " " @ targetItemInfo.ItemNum);

	//Debug("----------AutoShotItemWnd-----------------------------");
	//Debug("nType"      @ nType);
	//Debug("have"       @ nHave);
	//Debug("nActivate"  @ nActivate);
	//Debug("ItemClassID"@ targetItemInfo.ID.ClassID);
	//Debug("무기착용여부 "@ hasWeapon);

	//Debug("-> "@ class'UIDATA_PET'.static.GetSummonNum());		
	//Debug("-> "@ class'UIDATA_PET'.static.IsHavePet());

	bPet = class'UIDATA_PET'.static.IsHavePet();
	bSummon = bSummonException();


	//  아이템 윈도우에 추가
	if (nType > -1)
	{
		bTwinkleEffect = true;

		// 활성, 비활성 토글
		if(nActivate == 1 || nActivate == 3)
		{
			targetItemInfo.IsToggle = true;
		}
		else
		{
			targetItemInfo.IsToggle = false;
		}
		//targetItemInfo.IsToggle = (nActivate == 1 || nActivate == 3) ? true : false; //numToBool(nActivate);
		
		// 아이템 슬롯에 뭔가 있으면..
		if (getShotItemSlot(false, nType).GetItem(0, beforeTargetItemInfo))
		{
			// 새로 들어온 정보와 이전 아이템 정보의 ClassID 가 같다면..반짝이면 안된다.
			if (beforeTargetItemInfo.ID.ClassID == targetItemInfo.ID.ClassID)
			{
				if (targetItemInfo.ItemNum > 0) bTwinkleEffect = false;
			}
			else
			{
				// Debug("bTwinkleEffect" @ bTwinkleEffect);
				// 아이템 삭제
				//GetItemWindowHandle( "AutoShotItemWnd.ShotItemSlot" $ nType).Clear();
				setItemSlot(nType, ITEM_CLEAR);
			}			
		}
		else
		{
			if (targetItemInfo.ItemNum <= 0) bTwinkleEffect = false;
		}

		// 정령탄, 마정탄 없다면..
		if (nHave <= 0)
		{
		}
		// 정령탄, 마정탄 가지고 있다면..
		else
		{
			//GetTextureHandle("AutoShotItemWnd.meiyou" $ nType).HideWindow();

			// pc
			if (nType == 1 || nType == 2)
			{
				if (hasWeapon)
				{
					if (targetItemInfo.ID.ClassID > 0) 
					{
						if (beforeTargetItemInfo.ID.ClassID == targetItemInfo.ID.ClassID)
						{
							setItemSlot(nType, ITEM_SET, targetItemInfo);
						}
						else
						{
							setItemSlot(nType, ITEM_ADD, targetItemInfo);
							
							// 새로 장착 될때 반짝 거리는 효과
							effectPath = "AutoShotItemWnd.EffectSlot" $ nType;
							if(IsVertical()) effectPath = effectPath $ "_ver_AniTex";
							else effectPath = effectPath $ "_hor_AniTex";
							GetAnimTextureHandle(effectPath).Stop();
							GetAnimTextureHandle(effectPath).Play();
							HideWindow("AutoShotItemWnd.AutoShotItemSubWnd");
						}						
					}
				}
				else
				{
					bTwinkleEffect = false;
				}
			}
			// 펫, 컴페니언, 소환수
			else if (nType == 3 || nType == 4)
			{
				// 아무거나 하나라도 존재 한다면..
				if (bSummon || bPet)
				{					
					if (targetItemInfo.ID.ClassID > 0) 
					{
						// 정탄 , 마정탄 변경 여부에 따라서..
						if (beforeTargetItemInfo.ID.ClassID == targetItemInfo.ID.ClassID)
						{
							setItemSlot(nType, ITEM_SET, targetItemInfo);
						}
						else
						{
							setItemSlot(nType, ITEM_ADD, targetItemInfo);

							// 새로 장착 될때 반짝 거리는 효과
							effectPath = "AutoShotItemWnd.EffectSlot" $ nType;
							if(IsVertical()) effectPath = effectPath $ "_ver_AniTex";
							else effectPath = effectPath $ "_hor_AniTex";
							GetAnimTextureHandle(effectPath).Stop();
							GetAnimTextureHandle(effectPath).Play();
							HideWindow("AutoShotItemWnd.AutoShotItemSubWnd");
						}							
					}
					else
					{
						setItemSlot(nType, ITEM_CLEAR);
					}
				}
				else
				{
					bTwinkleEffect = false;

					// 펫, 소환수가 없다면.. 값과 관계 없이 슬롯도 비운다.
					setItemSlot(nType, ITEM_CLEAR);
				}
			}
		}

		// 99개 이상 인 경우 경우와 이하인 경우의 수량 표기
		if (GetItemWindowHandle( "AutoShotItemWnd.ShotItemSlot" $ nType).GetItemNum() > 0)
		{
			if (targetItemInfo.ItemNum > 99) 
			{
				itemCountStr = "99+";
			}
			else
			{
				itemCountStr = String(targetItemInfo.ItemNum);
			}
		}
	}
	
	endSoulShotUpdateHandle();

	checkSlotShowState();
}

/**
 * 인벤토리, 정탄, 마정탄 슬롯에 추가, 삭제, 갱신
 * ITEM_ADD, ITEM_SET, ITEM_CLEAR
 **/
function setItemSlot(int nType, int nItemCommand, optional ItemInfo info)
{
	if (nItemCommand == ITEM_ADD)
	{
		getShotItemSlot(false, nType).AddItem(info);
		getShotItemSlot(true, nType).AddItem(info);
		
		setTextureCounter( true, nType, info.ItemNum);
		setTextureCounter(false, nType, info.ItemNum);

		if (info.ItemNum <= 0) 
		{
			showTextureCounter(false, true, nType);
			showTextureCounter(false, false, nType);
		}
	}
	else if (nItemCommand == ITEM_SET)
	{
		getShotItemSlot(false, nType).SetItem(0, info);
		getShotItemSlot(true, nType).SetItem(0, info);

		setTextureCounter(true , nType, info.ItemNum);
		setTextureCounter(false, nType, info.ItemNum);

		if (info.ItemNum <= 0) 
		{
			showTextureCounter(false, true, nType);
			showTextureCounter(false, false, nType);
		}
	}
	else if (nItemCommand == ITEM_CLEAR)
	{
		getShotItemSlot(true , nType).Clear();
		getShotItemSlot(false, nType).Clear();

		showTextureCounter(false, false, nType);
		showTextureCounter(false, true, nType);
	}
}

/**
 * 
 * OnTimer
 * 
 **/
function OnTimer(int timerID)
{
	// 해상도 조절이 후 문제가 생긴다고 해서 이벤트 오는 타이밍이 문제일 확율이 
	// 높아 보여서 타이머로 보정 처리를 하도록 추가 했다.
	if (timerID == TIME_ID)
	{
		windowPositionAutoMove();
		Me.KillTimer(TIME_ID);
	}
}

/** 무기 갱신 */
function updateSlotWeapon(ItemInfo Info)
{
	weaponItemInfo = Info;
	if(Info.Id.ClassID > 0)
	{
		hasWeapon = true;		
	}
	else
	{
		hasWeapon = false;
	}
}

function ExHideSubWnd ()
{
	HideWindow("AutoShotItemWnd.AutoShotItemSubWnd");
}

function OnClickItem( string strID, int index )
{	
	local ItemInfo infItem, selectItemInfo;
	local array<ItemInfo> itemInfoArray;
	local int i, wndIndex;

	// Debug("strID" @ strID);
	// 정탄 슬롯 1~4 중 하나 클릭
	if (Left(strID, 12)  == "ShotItemSlot")
	{
		// Debug("mm: " @ int(Right(strID, 1)));

		wndIndex = int(Right(strID, 1));

		// clickShotcutItem(a_WindowHandle, X, Y);
		// Debug("정탄 슬롯 index" @ wndIndex);
		
		// 방금 열었던 슬롯을 또 클릭 했다면 닫는다.
		if (currentSelectSoulShotWndIndex == wndIndex && IsShowWindow("AutoShotItemWnd.AutoShotItemSubWnd")) 
		{
			currentSelectSoulShotWndIndex = -1;
			HideWindow("AutoShotItemWnd.AutoShotItemSubWnd");
			return;
		}

		//ShotItemSlot1~4
		currentSelectSoulShotWndIndex = wndIndex;
		
		// 1~4 인 경우만 창을 연다.
		if (currentSelectSoulShotWndIndex > 0 && currentSelectSoulShotWndIndex < 5)
		{
			GetAutoEquipShotList(currentSelectSoulShotWndIndex, itemInfoArray);
			//toggleWindow("AutoShotItemWnd.AutoShotItemSubWnd", true);
			ShowWindowWithFocus("AutoShotItemWnd.AutoShotItemSubWnd");

			// 세로
			if (IsVertical())
			{
				GetWindowHandle("AutoShotItemWnd.AutoShotItemSubWnd.ArrowHor_Texture_SubWnd").HideWindow();
				GetWindowHandle("AutoShotItemWnd.AutoShotItemSubWnd.ArrowVer_Texture_SubWnd").ShowWindow();
				GetWindowHandle("AutoShotItemWnd.AutoShotItemSubWnd").SetAnchor(getSlotPath(IsVertical(), wndIndex) $ ".ShotItemSlot" $ wndIndex, "TopRight", "TopLeft", -135, 0);
			}
			// 가로 
			else
			{
				GetWindowHandle("AutoShotItemWnd.AutoShotItemSubWnd.ArrowHor_Texture_SubWnd").ShowWindow();
				GetWindowHandle("AutoShotItemWnd.AutoShotItemSubWnd.ArrowVer_Texture_SubWnd").HideWindow();
				GetWindowHandle("AutoShotItemWnd.AutoShotItemSubWnd").SetAnchor(getSlotPath(IsVertical(), wndIndex) $ ".ShotItemSlot" $ wndIndex, "TopLeft", "TopLeft", -62, -95);
			}
		}
		else
		{
			currentSelectSoulShotWndIndex = -1;
			HideWindow("AutoShotItemWnd.AutoShotItemSubWnd");
		}

		// Debug("itemInfoArray Len : " @ itemInfoArray.Length);

		if (itemInfoArray.Length > 0)
		{
			// 현재 슬롯에 꼽혀 있는 정탄 아이템 정보 얻기
			if(getShotItemSlot(false, wndIndex).GetItemNum() > 0)
				getShotItemSlot(false, wndIndex).GetItem(0, infItem);

			GetItemWindowHandle("AutoShotItemWnd.AutoShotItemSubWnd.AutoShotItem_ItemWnd_SubWnd").Clear();
			for (i = 0; i < itemInfoArray.Length; i++)
			{
				// 현재 정탄 슬롯에 꼽혀 있는 것이 아닌 경우 목록에 넣는다.
				if (infItem.Id.ClassId != itemInfoArray[i].Id.ClassID)
				{
					setShowItemCount(itemInfoArray[i]);
					GetItemWindowHandle("AutoShotItemWnd.AutoShotItemSubWnd.AutoShotItem_ItemWnd_SubWnd").AddItem(itemInfoArray[i]);
				}
			}
		}
	}
	// 정탄 선택 아이템 윈도우 클릭
	else if(strID == "AutoShotItem_ItemWnd_SubWnd")
	{
		// Debug("getShotItemSlot(false, wndIndex).GetItemNum()" @ getShotItemSlot(false, currentSelectSoulShotWndIndex).GetItemNum());

		GetItemWindowHandle("AutoShotItemWnd.AutoShotItemSubWnd.AutoShotItem_ItemWnd_SubWnd").GetItem(index, selectItemInfo);

		if (selectItemInfo.ID.ClassID > 0 && currentSelectSoulShotWndIndex != -1) 
		{
			// Debug("슬롯 " @ currentSelectSoulShotWndIndex);
			// Debug("정탄 장착 ClassID " @ infItem.ID.ClassID);
			SoulShotSlotSelected(currentSelectSoulShotWndIndex, selectItemInfo.ID.ClassID);  
			HideWindow("AutoShotItemWnd.AutoShotItemSubWnd");
		}
	}
}

function syncInventory (string param)
{
	local array<ItemInfo> itemInfoArray;
	local int Index;
	local int i;
	local ItemInfo infItem;
	local ItemInfo updatedItemInfo;
	local string Type;
	local bool bPassItem;
	local ItemWindowHandle shotSubInvenWnd;

	if ( IsShowWindow("AutoShotItemWnd.AutoShotItemSubWnd") == False )
		return;

	shotSubInvenWnd = GetItemWindowHandle("AutoShotItemWnd.AutoShotItemSubWnd.AutoShotItem_ItemWnd_SubWnd");
	if ( (currentSelectSoulShotWndIndex > 0) && (currentSelectSoulShotWndIndex < 5) )
	{
		GetAutoEquipShotList(currentSelectSoulShotWndIndex,itemInfoArray);
		if ( getShotItemSlot(False,currentSelectSoulShotWndIndex).GetItemNum() > 0 )
		{
			getShotItemSlot(False,currentSelectSoulShotWndIndex).GetItem(0,infItem);
			Index = shotSubInvenWnd.FindItemByClassID(infItem.Id);
			if ( Index > -1 )
				shotSubInvenWnd.DeleteItem(Index);
		}
	}
	ParamToItemInfo(param,updatedItemInfo);
	ParseString(param,"type",Type);

	//ShotItemSlot1~4
	switch(currentSelectSoulShotWndIndex)
	{
		case 1 : GetAutoEquipShotList(1, itemInfoArray); break;
		case 2 : GetAutoEquipShotList(2, itemInfoArray); break;
		case 3 : GetAutoEquipShotList(3, itemInfoArray); break;
		case 4 : GetAutoEquipShotList(4, itemInfoArray); break;
	}

	for ( i = 0; i < itemInfoArray.Length; i++ )
	{
		if ( itemInfoArray[i].Id.ClassID == updatedItemInfo.Id.ClassID )
		{
			bPassItem = True;
			break;
		}
	}

	if ( bPassItem == False )
		return;

	Index = shotSubInvenWnd.FindItemByClassID(updatedItemInfo.Id);
	if ( Type == "delete" )
	{
		if ( Index > -1 )
			shotSubInvenWnd.DeleteItem(Index);
	}
	else
	{
		setShowItemCount(updatedItemInfo);
		if ( Index > -1 )
			shotSubInvenWnd.SetItem(Index,updatedItemInfo);
		else if ( infItem.Id.ClassID != updatedItemInfo.Id.ClassID )
			shotSubInvenWnd.AddItem(updatedItemInfo);
	}
}

function OnRButtonUp( WindowHandle a_WindowHandle, int X, int Y )
{
	clickShotcutItem(a_WindowHandle, X, Y);
}

/**
 *  정령탄, 마정탄 활성화, 비활성 처리
 **/
function clickShotcutItem( WindowHandle a_WindowHandle, int X, int Y )
{
	local string targetStr, targetID;
	local itemInfo targetItemInfo;

	targetStr = a_WindowHandle.GetWindowName();
	targetID = Mid(targetStr, len(targetStr) -1, len(targetStr));

	switch (targetID)
	{
		case "1" : 
		case "2" : 
		case "3" : 
		case "4" : if(GetItemWindowHandle( "AutoShotItemWnd.ShotItemSlot" $ targetID).GetItem(0, targetItemInfo)) 
				   {
					  SoulShotSlotClicked(int(targetID), targetItemInfo.ID.ClassID);  
					  //Me.SetFocus();
				   }				   
				   break;
	}
}

// 정탄 아이템 윈도우 얻기
function ItemWindowHandle getShotItemSlot(bool IsShortcutWndVertical, int slotIndex)
{
	local ItemWindowHandle itemWnd;

	// 1,2 
	if(IsShortcutWndVertical)
	{
		// 펫
		if (slotIndex > 2)
		{
			itemWnd = GetItemWindowHandle( "AutoShotItemWnd.AutoShotItemWnd_VerWnd.PetSlotGroupWnd_VerWnd.ShotItemSlot" $ slotIndex);
		}
		// 무기 (플레이어)
		else
		{
			itemWnd = GetItemWindowHandle( "AutoShotItemWnd.AutoShotItemWnd_VerWnd.WeaponSlotGroupWnd_VerWnd.ShotItemSlot" $ slotIndex);
		}
	}
	else
	{
		// 펫
		if (slotIndex > 2)
		{
			itemWnd = GetItemWindowHandle( "AutoShotItemWnd.AutoShotItemWnd_HorWnd.PetSlotGroupWnd_HorWnd.ShotItemSlot" $ slotIndex);
		}
		// 무기 (플레이어)
		else
		{
			itemWnd = GetItemWindowHandle( "AutoShotItemWnd.AutoShotItemWnd_HorWnd.WeaponSlotGroupWnd_HorWnd.ShotItemSlot" $ slotIndex);
		}
	}

	return itemWnd;
}

// 정탄 수량 보여주는 텍스쳐 show, hide
function setTextureCounter(bool IsShortcutWndVertical, int slotIndex, INT64 count)
{
	local string tempStr, valueStr;

	if (count > 99) valueStr = "99+";
	else valueStr = String(count);

	showTextureCounter(false, IsShortcutWndVertical, slotIndex);

	tempStr = getSlotPath(IsShortcutWndVertical, slotIndex);

	switch(Len(valueStr))
	{
		// 99+
		case 3 : showTextureCounter(true, IsShortcutWndVertical, slotIndex);
				 GetTextureHandle(tempStr $ "." $ "counter100_slot" $ slotIndex $ "_texture").SetTexture("l2UI_CT1.AutoShotItemWnd.ItemCountNum_9");
				 GetTextureHandle(tempStr $ "." $ "counter10_slot" $ slotIndex $ "_texture").SetTexture("l2UI_CT1.AutoShotItemWnd.ItemCountNum_9");
				 GetTextureHandle(tempStr $ "." $ "counter1_slot" $ slotIndex $ "_texture").SetTexture("l2UI_CT1.AutoShotItemWnd.ItemCountNum_Plus");
				 break;

		// 10자리
		case 2 : GetTextureHandle(tempStr $ "." $ "counter10_slot" $ slotIndex $ "_texture").ShowWindow();
				 GetTextureHandle(tempStr $ "." $ "counter10_slot" $ slotIndex $ "_texture").SetTexture("l2UI_CT1.AutoShotItemWnd.ItemCountNum_" $ Left(valueStr, 1));

		// 1자리
		case 1 : GetTextureHandle(tempStr $ "." $ "counter1_slot" $ slotIndex $ "_texture").ShowWindow();
				 GetTextureHandle(tempStr $ "." $ "counter1_slot" $ slotIndex $ "_texture").SetTexture("l2UI_CT1.AutoShotItemWnd.ItemCountNum_" $ Right(valueStr, 1));
	}
}

// 정탄 수량 보여주는 텍스쳐 show, hide
function showTextureCounter(bool bShow, bool IsShortcutWndVertical, int SlotIndex)
{
	local string tempStr;

	tempStr = getSlotPath(IsShortcutWndVertical, SlotIndex);
	if(bShow)
	{
		GetTextureHandle(tempStr $ "." $ "counter1_slot" $ SlotIndex $ "_texture").ShowWindow();
		GetTextureHandle(tempStr $ "." $ "counter10_slot" $ SlotIndex $ "_texture").ShowWindow();
		GetTextureHandle(tempStr $ "." $ "counter100_slot" $ SlotIndex $ "_texture").ShowWindow();
	}
	else
	{
		GetTextureHandle(tempStr $ "." $ "counter1_slot" $ SlotIndex $ "_texture").HideWindow();
		GetTextureHandle(tempStr $ "." $ "counter10_slot" $ SlotIndex $ "_texture").HideWindow();
		GetTextureHandle(tempStr $ "." $ "counter100_slot" $ SlotIndex $ "_texture").HideWindow();
	}
}


// 정탄 슬롯 경로를 조합하여 스트링을 리턴
function string getSlotPath(bool IsShortcutWndVertical, int SlotIndex)
{
	local string tempStr;

	tempStr = "AutoShotItemWnd";
	if(IsShortcutWndVertical)
	{
		tempStr = tempStr $ ".AutoShotItemWnd_VerWnd";
		if(SlotIndex > 2)
		{
			tempStr = tempStr $ ".PetSlotGroupWnd_VerWnd";
		}
		else
		{
			tempStr = tempStr $ ".WeaponSlotGroupWnd_VerWnd";
		}		
	}
	else
	{
		tempStr = tempStr $ ".AutoShotItemWnd_HorWnd";
		if(SlotIndex > 2)
		{
			tempStr = tempStr $ ".PetSlotGroupWnd_HorWnd";
		}
		else
		{
			tempStr = tempStr $ ".WeaponSlotGroupWnd_HorWnd";
		}
	}

	return tempStr;
}

function bool IsVertical()
{
	return ShortcutWndScript.IsVertical();
}
