Advertisement
Guest User

Репликация

a guest
Aug 22nd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class TraderReplicationInfo extends ReplicationInfo
  2.     config( TestMutator );
  3.  
  4. struct StructItem
  5. {
  6.     var string  DefPath;
  7.     var int     TraderId;
  8. };
  9.  
  10. var array<StructItem> ClientItems;
  11.  
  12. var private int CurrentIndex;
  13.  
  14. static final function SaveSettings()
  15. {
  16.     StaticSaveConfig();
  17. }
  18.  
  19. final function StartSyncItems()
  20. {
  21.     SetTimer( 0.05f, true, nameof( SyncItems ) );
  22. }
  23.  
  24. private final function SyncItems()
  25. {
  26.     local StructItem Item;
  27.  
  28.     if ( CurrentIndex < ClientItems.Length )
  29.     {
  30.         Item = ClientItems[CurrentIndex];
  31.         ClientSyncItem( Item.DefPath, Item.TraderId );
  32.         ++CurrentIndex;
  33.     }
  34.     else
  35.     {
  36.         ClearTimer(nameof( SyncItems ));
  37.         ClientSyncFinished();
  38.         CleanupRepLink( false );
  39.     }
  40. }
  41.  
  42. private final function CleanupRepLink( bool bClient )
  43. {
  44.     CurrentIndex = 0;
  45.     ClientItems.Length = 0;
  46.    
  47.     Destroy();
  48. }
  49.  
  50. private reliable client final function ClientSyncItem( string DefPath, int TraderId )
  51. {
  52.     local StructItem Item;
  53.  
  54.     Item.DefPath = DefPath;
  55.     Item.TraderId = TraderId;
  56.    
  57.     ClientItems.AddItem( Item );
  58. }
  59.  
  60. private reliable client final function ClientSyncFinished()
  61. {  
  62.     Timer();
  63. }
  64.  
  65. simulated event Timer()
  66. {
  67.     while( !AddClientItems() );
  68.  
  69.     CleanupRepLink( true );
  70. }
  71.  
  72. private simulated final function bool AddClientItems()
  73. {
  74.     local KFGameReplicationInfo KFGRI;
  75.     local KFGFxObject_TraderItems TraderItems;
  76.     local StructItem ClientItem;
  77.     local STraderItem Item;
  78.     local int i, Number;
  79.  
  80.     if ( WorldInfo == None )
  81.     {
  82.         return False;
  83.     }
  84.  
  85.     KFGRI = KFGameReplicationInfo( WorldInfo.GRI );
  86.    
  87.     if ( KFGRI == None )
  88.     {
  89.         return False;
  90.     }
  91.  
  92.     TraderItems = new class'KFGFxObject_TraderItems';
  93.  
  94.     Number = 0;
  95.    
  96.     foreach ClientItems( ClientItem, i )
  97.     {
  98.         Item.WeaponDef = class<KFWeaponDefinition>(DynamicLoadObject( ClientItem.DefPath, class'Class' ) );
  99.  
  100.         if (  Item.WeaponDef == None )
  101.         {  
  102.             return true;
  103.         }
  104.        
  105.         Item.ItemID = ClientItem.TraderId ;
  106.         TraderItems.SaleItems.AddItem( Item );
  107.         Number++;
  108.     }
  109.  
  110.     if ( Number > 0 )
  111.         TraderItems.SetItemsInfo( TraderItems.SaleItems );
  112.  
  113.     KFGRI.TraderItems = TraderItems;
  114.    
  115.     return true;
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement