init.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #include "$mission:Scripts/CustomRevivalSuit/config.c"
  2. void main()
  3. {
  4. //INIT ECONOMY--------------------------------------
  5. Hive ce = CreateHive();
  6. if ( ce )
  7. ce.InitOffline();
  8. //DATE RESET AFTER ECONOMY INIT-------------------------
  9. int year, month, day, hour, minute;
  10. int reset_month = 9, reset_day = 20;
  11. GetGame().GetWorld().GetDate(year, month, day, hour, minute);
  12. if ((month == reset_month) && (day < reset_day))
  13. {
  14. GetGame().GetWorld().SetDate(year, reset_month, reset_day, hour, minute);
  15. }
  16. else
  17. {
  18. if ((month == reset_month + 1) && (day > reset_day))
  19. {
  20. GetGame().GetWorld().SetDate(year, reset_month, reset_day, hour, minute);
  21. }
  22. else
  23. {
  24. if ((month < reset_month) || (month > reset_month + 1))
  25. {
  26. GetGame().GetWorld().SetDate(year, reset_month, reset_day, hour, minute);
  27. }
  28. }
  29. }
  30. }
  31. class CustomMission: MissionServer
  32. {
  33. override void OnInit()
  34. {
  35. super.OnInit();
  36. GetCustomRevivalSuitCfg();
  37. if ( g_CustomRevivalSuitCfg )
  38. Print( "[复活套装]: 已加载" );
  39. }
  40. override PlayerBase CreateCharacter(PlayerIdentity identity, vector pos, ParamsReadContext ctx, string characterName)
  41. {
  42. Entity playerEnt;
  43. playerEnt = GetGame().CreatePlayer( identity, characterName, pos, 0, "NONE" );
  44. Class.CastTo( m_player, playerEnt );
  45. GetGame().SelectPlayer( identity, m_player );
  46. return m_player;
  47. }
  48. override void StartingEquipSetup( PlayerBase player, bool clothesChosen )
  49. {
  50. GetCustomRevivalSuitCfg();
  51. if ( !player || !player.GetIdentity() ) return;
  52. string steamid = player.GetIdentity().GetPlainId();
  53. ref PlayerRevivalEquipmentData rev = g_CustomRevivalSuitCfg.GetPlayerRevivalEquipmentData( steamid );
  54. bool isVIP = false;
  55. if ( rev )
  56. {
  57. isVIP = true;
  58. ProcessVIPEquipment( player, rev );
  59. }
  60. DefaultPlayerEquipment( player, clothesChosen, isVIP );
  61. }
  62. void ProcessVIPEquipment( PlayerBase player, ref PlayerRevivalEquipmentData equ_data )
  63. {
  64. if ( !equ_data ) return;
  65. player.RemoveAllItems();
  66. ItemBase equipment;
  67. foreach ( string equ : equ_data.Equipments )
  68. player.GetInventory().CreateInInventory( equ );
  69. foreach ( string item : equ_data.ItemList )
  70. player.GetInventory().CreateInInventory( item );
  71. if ( !equ_data.WeaponData || equ_data.WeaponData.WeaponName == "" ) return;
  72. Weapon_Base weapon = Weapon_Base.Cast( player.GetInventory().CreateInInventory( equ_data.WeaponData.WeaponName ) );
  73. if ( !weapon ) return
  74. foreach ( string attachment : equ_data.WeaponData.WeaponComponents )
  75. {
  76. if ( String( attachment ).ToType().IsInherited( Magazine ) )
  77. {
  78. Magazine wpn_mag = weapon.SpawnAttachedMagazine( attachment );
  79. if ( wpn_mag )
  80. wpn_mag.SetSynchDirty();
  81. continue;
  82. }
  83. if ( weapon.GetInventory() )
  84. ItemBase.Cast( weapon.GetInventory().CreateInInventory( attachment ) );
  85. }
  86. }
  87. void SetRandomHealth(EntityAI itemEnt)
  88. {
  89. if (itemEnt)
  90. {
  91. float rndHlt = Math.RandomFloat( 0.50, 0.85 );
  92. itemEnt.SetHealth01( "", "", rndHlt );
  93. }
  94. }
  95. void DefaultPlayerEquipment( PlayerBase player, bool clothesChosen, bool isVIP )
  96. {
  97. EntityAI itemClothing;
  98. EntityAI itemEnt;
  99. ItemBase itemBs;
  100. float rand;
  101. if ( !isVIP )
  102. {
  103. // TODO: 这里给普通玩家创建装备. 以前在StartingEquipSetup中如何给玩家创建新的装备这里就如何写
  104. // player.RemoveAllItems(); // 移除所有默认装备
  105. // itemEnt = player.GetInventory().CreateInInventory( "" /*这里写服装代码 */ );
  106. }
  107. itemClothing = player.FindAttachmentBySlotName( "Body" );
  108. if ( itemClothing )
  109. {
  110. SetRandomHealth( itemClothing );
  111. itemEnt = itemClothing.GetInventory().CreateInInventory( "BandageDressing" );
  112. if ( Class.CastTo( itemBs, itemEnt ) )
  113. itemBs.SetQuantity( 2 );
  114. string chemlightArray[] = { "Chemlight_White", "Chemlight_Yellow", "Chemlight_Green", "Chemlight_Red" };
  115. int rndIndex = Math.RandomInt( 0, 4 );
  116. itemEnt = itemClothing.GetInventory().CreateInInventory( chemlightArray[rndIndex] );
  117. SetRandomHealth( itemEnt );
  118. ItemBase itemTop;
  119. rand = Math.RandomFloatInclusive( 0.0, 1.0 );
  120. if ( rand < 0.35 )
  121. {
  122. itemEnt = player.GetInventory().CreateInInventory( "Rag" );
  123. itemTop = ItemBase.Cast( itemEnt );
  124. itemTop.RemoveAllAgentsExcept(eAgents.BRAIN | eAgents.SALMONELLA | eAgents.CHOLERA);
  125. itemTop.SetCleanness(1);
  126. }
  127. else if ( rand > 0.65 )
  128. {
  129. itemEnt = player.GetInventory().CreateInInventory( "Rag" );
  130. itemTop = ItemBase.Cast( itemEnt );
  131. itemTop.RemoveAllAgentsExcept(eAgents.BRAIN | eAgents.SALMONELLA | eAgents.CHOLERA);
  132. itemTop.SetCleanness(1);
  133. }
  134. else
  135. itemEnt = player.GetInventory().CreateInInventory( "Rag" );
  136. // SetRandomHealth( itemEnt );
  137. }
  138. itemClothing = player.FindAttachmentBySlotName( "Legs" );
  139. if ( itemClothing )
  140. SetRandomHealth( itemClothing );
  141. itemClothing = player.FindAttachmentBySlotName( "Feet" );
  142. }
  143. };
  144. Mission CreateCustomMission(string path)
  145. {
  146. return new CustomMission();
  147. }