Guest User

TradeWnd Refinery

a guest
Feb 10th, 2022
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.70 KB | None | 0 0
  1. class TradeWnd extends UICommonAPI;
  2.  
  3. const DIALOG_ID_TRADE_REQUEST = 0;
  4. const DIALOG_ID_ITEM_NUMBER = 1;
  5.  
  6. function OnLoad()
  7. {
  8.     registerEvent( EV_DialogOK );
  9.     registerEvent( EV_DialogCancel );
  10.  
  11.     registerEvent( EV_TradeStart );
  12.     registerEvent( EV_TradeAddItem );
  13.     registerEvent( EV_TradeDone );
  14.     registerEvent( EV_TradeOtherOK );
  15.     registerEvent( EV_TradeUpdateInventoryItem );
  16.     registerEvent( EV_TradeRequestStartExchange );
  17. }
  18.  
  19. function OnSendPacketWhenHiding()
  20. {
  21.     RequestTradeDone( false );
  22. }
  23.  
  24. function OnHide()
  25. {
  26.     Clear();
  27. }
  28.  
  29. function OnEvent( int eventID, string param )
  30. {
  31.     //debug("eventID " $ eventID $ ", param : " $ param );
  32.     switch( eventID )
  33.     {
  34.     case EV_TradeStart:
  35.         HandleStartTrade(param);
  36.         break;
  37.     case EV_TradeAddItem:
  38.         HandleTradeAddItem(param);
  39.         break;
  40.     case EV_TradeDone:
  41.         HandleTradeDone(param);
  42.         break;
  43.     case EV_TradeOtherOK:
  44.         HandleTradeOtherOK(param);
  45.         break;
  46.     case EV_TradeUpdateInventoryItem:
  47.         HandleTradeUpdateInventoryItem(param);
  48.         break;
  49.     case EV_TradeRequestStartExchange:
  50.         HandleReceiveStartTrade(param);
  51.         break;
  52.     case EV_DialogOK:
  53.         HandleDialogOK();
  54.         break;
  55.     case EV_DialogCancel:
  56.         HandleDialogCancel();
  57.         break;
  58.     default:
  59.         break;
  60.     };
  61. }
  62.  
  63. function OnClickButton( string ControlName )
  64. {
  65.     //debug("ControlName : " $ ControlName);
  66.     if( ControlName == "OKButton" )
  67.     {
  68.         // ±³È¯ ¼ö¶ô.
  69.         class'UIAPI_ITEMWINDOW'.static.SetFaded( "TradeWnd.MyList", true );
  70.         RequestTradeDone( true );
  71.         //HideWindow( "TradeWnd" );
  72.     }
  73.     else if( ControlName == "CancelButton" )
  74.     {
  75.         RequestTradeDone( false );
  76.         //HideWindow( "TradeWnd" );
  77.     }
  78.     else if( ControlName == "MoveButton" )
  79.     {
  80.         HandleMoveButton();
  81.     }
  82. }
  83.  
  84. function OnDBClickItem( string ControlName, int index )
  85. {
  86.     local ItemInfo info;
  87.     if(ControlName == "InventoryList")  // remove the item from InventoryList and move it to MyList
  88.     {
  89.         if( class'UIAPI_ITEMWINDOW'.static.GetItem("TradeWnd.InventoryList", index, info) )
  90.         {
  91.             if( IsStackableItem( info.ConsumeType ) &&  (info.ItemNum!=1))      // stackable? //1°³¸é ¼ö·®ÀÔ·ÂâÀ» ¶ç¿ìÁö ¾Ê´Â´Ù.
  92.             {
  93.                 DialogSetID( DIALOG_ID_ITEM_NUMBER );
  94.                 DialogSetReservedInt( info.ServerID );
  95.                 DialogSetParamInt( info.ItemNum );
  96.                 DialogShow( DIALOG_NumberPad, MakeFullSystemMsg( GetSystemMessage(72), info.Name, "" ) );
  97.             }
  98.             else
  99.                 RequestAddTradeItem( info.ServerID, 1 );
  100.         }
  101.     }
  102. }
  103.  
  104. function OnDropItem( string strID, ItemInfo info, int x, int y)
  105. {
  106.     //debug("OnDropItem strID " $ strID $ ", src=" $ info.DragSrcName);
  107.     if( strID == "MyList" && info.DragSrcName == "InventoryList" )
  108.     {
  109.         if( IsStackableItem( info.ConsumeType ) )       // stackable?
  110.         {
  111.             if( info.AllItemCount > 0 )             // ÀüüÀ̵¿
  112.             {
  113.                 RequestAddTradeItem( info.ServerID, info.AllItemCount );
  114.             }
  115.             else if( info.ItemNum==1)
  116.             {
  117.                 RequestAddTradeItem( info.ServerID, 1);
  118.             }
  119.             else
  120.             {
  121.                 DialogSetID( DIALOG_ID_ITEM_NUMBER );
  122.                 DialogSetReservedInt( info.ServerID );
  123.                 DialogSetParamInt( info.ItemNum );
  124.                 DialogShow( DIALOG_NumberPad, MakeFullSystemMsg( GetSystemMessage(72), info.Name, "" ) );
  125.             }
  126.         }
  127.         else
  128.             RequestAddTradeItem( info.ServerID, 1 );
  129.     }
  130. }
  131.  
  132. function MoveToMyList( int index, int num )
  133. {
  134.     local ItemInfo info;
  135.     if( class'UIAPI_ITEMWINDOW'.static.GetItem("TradeWnd.InventoryList", index, info) ) // success returns true
  136.     {
  137.         RequestAddTradeItem( info.ServerID, num );
  138.         //if( num >= info.ItemNum )
  139.         //  class'UIAPI_ITEMWINDOW'.static.DeleteItem("TradeWnd.InventoryList", index);
  140.  
  141.         //info.ItemNum = num;
  142.         //class'UIAPI_ITEMWINDOW'.static.AddItem("TradeWnd.MyList", info);
  143.     }
  144. }
  145.  
  146. function HandleMoveButton()
  147. {
  148.     local int selected;
  149.     local ItemInfo info;
  150.     selected = class'UIAPI_ITEMWINDOW'.static.GetSelectedNum("TradeWnd.InventoryList");
  151.     if( selected >= 0 )
  152.     {
  153.         class'UIAPI_ITEMWINDOW'.static.GetItem("TradeWnd.InventoryList", selected, info);
  154.         if( info.ItemNum == 1 )     // stackable??
  155.             MoveToMyList(selected, 1);
  156.         else
  157.         {
  158.             DialogSetID( DIALOG_ID_ITEM_NUMBER );
  159.             DialogSetReservedInt( info.ServerID );
  160.             DialogSetParamInt( info.ItemNum );
  161.             DialogShow( DIALOG_NumberPad, MakeFullSystemMsg( GetSystemMessage(72), info.Name, "" ) );
  162.         }
  163.     }
  164. }
  165.  
  166. function HandleStartTrade( string param )
  167. {
  168.     local int targetID;
  169.     local UserInfo targetInfo;
  170.     local string clanName;
  171.     local WindowHandle m_inventoryWnd;
  172.     local WindowHandle m_warehouseWnd;
  173.     local WindowHandle m_privateShopWnd;
  174.     local WindowHandle m_shopWnd;
  175.     local WindowHandle m_multiSellWnd;
  176.  
  177.     //°¢Á¾ À©µµ¿ì ÇÚµéÀ» ¾ò¾î¿Â´Ù.
  178.     m_inventoryWnd = GetHandle( "InventoryWnd" );   //Àκ¥Å丮
  179.     m_warehouseWnd = GetHandle( "WarehouseWnd" );       //°³ÀÎâ°í, Ç÷¸Íâ°í, È­¹°Ã¢°í
  180.     m_privateShopWnd = GetHandle( "PrivateShopWnd" );   //°³ÀÎÆÇ¸Å, °³Àα¸¸Å
  181.     m_shopWnd = GetHandle( "ShopWnd" );             //»óÁ¡±¸¸Å, ÆÇ¸Å
  182.     m_multiSellWnd = GetHandle( "MultiSellWnd" );           //¸ÖƼ¼¿
  183.  
  184.     if( m_inventoryWnd.IsShowWindow() )         //Àκ¥Å丮 âÀÌ ¿­·ÁÀÖÀ¸¸é ´Ý¾ÆÁØ´Ù.
  185.     {
  186.         m_inventoryWnd.HideWindow();
  187.     }  
  188.     if( m_warehouseWnd.IsShowWindow() )         //â°í âÀÌ ¿­·ÁÀÖÀ¸¸é ´Ý¾ÆÁØ´Ù.
  189.     {
  190.         m_warehouseWnd.HideWindow();
  191.     }  
  192.     if( m_privateShopWnd.IsShowWindow() )       //°³ÀλóÁ¡ âÀÌ ¿­·ÁÀÖÀ¸¸é ´Ý¾ÆÁØ´Ù.
  193.     {
  194.         m_privateShopWnd.HideWindow();
  195.     }  
  196.     if( m_shopWnd.IsShowWindow() )              //»óÁ¡ âÀÌ ¿­·ÁÀÖÀ¸¸é ´Ý¾ÆÁØ´Ù.
  197.     {
  198.         m_shopWnd.HideWindow();
  199.     }
  200.     if( m_multiSellWnd.IsShowWindow() )         //¸ÖƼ¼¿ âÀÌ ¿­·ÁÀÖÀ¸¸é ´Ý¾ÆÁØ´Ù.
  201.     {
  202.         m_multiSellWnd.HideWindow();
  203.     }
  204.    
  205.     class'UIAPI_WINDOW'.static.ShowWindow("TradeWnd");
  206.     class'UIAPI_WINDOW'.static.SetFocus("TradeWnd");
  207.  
  208.     ParseInt( param, "targetId", targetID );
  209.    
  210.     if( targetID > 0 )
  211.     {
  212.         GetUserInfo( targetID, targetInfo );
  213.         if( targetInfo.nClanID > 0 )
  214.         {
  215.             clanName = GetClanName( targetInfo.nClanID );
  216.             class'UIAPI_TEXTBOX'.static.SetText( "TradeWnd.Targetname", targetInfo.Name $ " - " $ clanName );
  217.         }
  218.         else
  219.         {
  220.             class'UIAPI_TEXTBOX'.static.SetText( "TradeWnd.Targetname", targetInfo.Name);       //Ç÷¸ÍÀÌ ¾ø¾îµµ À̸§À» Ç¥½ÃÇØÁØ´Ù.
  221.         }
  222.     }
  223. }
  224.  
  225. function HandleTradeAddItem( string param )
  226. {
  227.     local string    strDest;
  228.     local ItemInfo  itemInfo, tempInfo;
  229.     local int       index;
  230.  
  231.     ParseString( param, "destination", strDest );
  232.  
  233.     ParamToItemInfo( param, itemInfo );
  234.     if( strDest == "inventoryList" )
  235.     {
  236.         strDest = "TradeWnd.InventoryList";
  237.     }
  238.     else if( strDest == "myList" )
  239.     {
  240.         strDest = "TradeWnd.MyList";
  241.         class'UIAPI_INVENWEIGHT'.static.ReduceWeight( "TradeWnd.InvenWeight", itemInfo.ItemNum * itemInfo.Weight );
  242.         //debug("AddWeight " $ itemInfo.ItemNum * itemInfo.Weight );
  243.     }
  244.     else if( strDest == "otherList" )
  245.     {
  246.         strDest = "TradeWnd.OtherList";
  247.         class'UIAPI_INVENWEIGHT'.static.AddWeight( "TradeWnd.InvenWeight", itemInfo.ItemNum * itemInfo.Weight );
  248.         //debug("ReduceWeight " $ itemInfo.ItemNum * itemInfo.Weight );
  249.     }
  250.     itemInfo.RefineryOp2 = itemInfo.Blessed;
  251.     itemInfo.RefineryOp1 = itemInfo.Damaged;
  252.     index = class'UIAPI_ITEMWINDOW'.static.FindItemWithServerID( strDest, itemInfo.ServerID );
  253.     //debug( "HandleTradeAddItem " $ strDest $ ", index " $ index );
  254.     if( index >= 0 )
  255.     {
  256.         if( IsStackableItem( ItemInfo.ConsumeType ) )
  257.         {
  258.             class'UIAPI_ITEMWINDOW'.static.GetItem( strDest, index, tempInfo );
  259.             itemInfo.ItemNum += tempInfo.ItemNum;
  260.             class'UIAPI_ITEMWINDOW'.static.SetItem( strDest, index, itemInfo );
  261.         }
  262.         // ¾ÆÀÌÅÛÀÌ À̹Ì ÀÖ°í ¼ö·®¼º ¾ÆÀÌÅÛµµ ¾Æ´Ï¶ó¸é ¾Æ¹«°Íµµ ÇÏÁö ¾Ê´Â´Ù.
  263.     }
  264.     else
  265.     {
  266.         class'UIAPI_ITEMWINDOW'.static.AddItem( strDest, itemInfo );
  267.     }
  268. }
  269.  
  270. // ±³È¯ÀÌ ³¡³µÀ½
  271. function HandleTradeDone( string param )
  272. {
  273.     class'UIAPI_WINDOW'.static.HideWindow("TradeWnd");
  274. }
  275.  
  276. // ´Ù¸¥ ÂÊ¿¡¼­ OK ¹öưÀ» ´­·¯¼­ ´õÀÌ»ó º¯°æÇÒ ¼ö ¾øÀ½. »ó´ë¹æÀÇ ¾ÆÀÌÅÛ ¸®½ºÆ®¸¦ º¯°æ ºÒ°¡ »óÅ·Πº¯°æ.
  277. function HandleTradeOtherOK( string param )
  278. {
  279.     class'UIAPI_ITEMWINDOW'.static.SetFaded( "TradeWnd.OtherList", true );
  280. }
  281.  
  282. // ¾ÆÀÌÅÛÀ» ¿Å±â°Å³ª ÇÒ¶§ ÀÚ½ÅÀÇ Àκ¥Å丮 »óȲÀ» ¾÷µ¥ÀÌÆ® ÇÑ´Ù.
  283. function HandleTradeUpdateInventoryItem( string param )
  284. {
  285.     local ItemInfo info;
  286.     local string type;
  287.     local int   index;
  288.  
  289.     ParseString( param, "type", type );
  290.     ParamToItemInfo( param, info );
  291.     if( type == "add" )
  292.     {
  293.         class'UIAPI_ITEMWINDOW'.static.AddItem( "TradeWnd.InventoryList", info );
  294.     }
  295.     else if( type == "update" )
  296.     {
  297.         index = class'UIAPI_ITEMWINDOW'.static.FindItemWithServerID( "TradeWnd.InventoryList", info.ServerID );
  298.         if( index >= 0 )
  299.             class'UIAPI_ITEMWINDOW'.static.SetItem( "TradeWnd.InventoryList", index, info );
  300.     }
  301.     else if( type == "delete" )
  302.     {
  303.         index = class'UIAPI_ITEMWINDOW'.static.FindItemWithServerID( "TradeWnd.InventoryList", info.ServerID );
  304.         //debug("HandleTradeUpdateInventoryItem delete : index(" $ index $ ")");
  305.         if( index >= 0 )
  306.             class'UIAPI_ITEMWINDOW'.static.DeleteItem( "TradeWnd.InventoryList", index );
  307.     }
  308. }
  309.  
  310. function HandleReceiveStartTrade( string param )
  311. {
  312.     local int targetID;
  313.     local UserInfo info;
  314.     ParseInt( param, "targetID", targetID );
  315.     if( targetID > 0 && GetUserInfo( targetID, info ) )
  316.     {
  317.         DialogSetID( DIALOG_ID_TRADE_REQUEST );
  318.         DialogSetParamInt( 10*1000 );           // 10 seconds
  319.         DialogShow( DIALOG_Progress, MakeFullSystemMsg(GetSystemMessage(100), info.Name, "" ) );
  320.     }
  321. }
  322.  
  323. function HandleDialogOK()
  324. {
  325.     local int serverID;
  326.     local int num;
  327.     if( DialogIsMine() )
  328.     {
  329.         if( DialogGetID() == DIALOG_ID_TRADE_REQUEST )
  330.         {
  331.             //debug("DialogOK DIALOG_ID_TRADE_REQUEST");
  332.             AnswerTradeRequest( true );
  333.         }
  334.         else if( DialogGetID() == DIALOG_ID_ITEM_NUMBER )
  335.         {
  336.             //debug("DialogOK DIALOG_ID_ITEM_NUMBER");
  337.             serverID = DialogGetReservedInt();
  338.             num = int( DialogGetString() );
  339.             //debug("serverID " $ serverID $ ", num " $ num );
  340.             RequestAddTradeItem( serverID, num );
  341.         }
  342.     }
  343. }
  344.  
  345. function HandleDialogCancel()
  346. {
  347.     if( DialogIsMine() )
  348.     {
  349.         if( DialogGetID() == DIALOG_ID_TRADE_REQUEST )
  350.         {
  351.             //debug("DialogCancel DIALOG_ID_TRADE_REQUEST");
  352.             AnswerTradeRequest( false );
  353.         }
  354.     }
  355. }
  356.  
  357. function Clear()
  358. {
  359.     class'UIAPI_ITEMWINDOW'.static.Clear( "TradeWnd.InventoryList" );
  360.     class'UIAPI_ITEMWINDOW'.static.Clear( "TradeWnd.MyList" );
  361.     class'UIAPI_ITEMWINDOW'.static.Clear( "TradeWnd.OtherList" );
  362.     class'UIAPI_TEXTBOX'.static.SetText( "TradeWnd.TargetName", "" );
  363.     class'UIAPI_INVENWEIGHT'.static.ZeroWeight( "TradeWnd.InvenWeight" );
  364. }
  365. defaultproperties
  366. {
  367. }
Advertisement
Add Comment
Please, Sign In to add comment