init.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. #include "$mission:Scripts/CustomRevivalSuit/config.c"
  2. void main()
  3. {
  4. Hive ce = CreateHive();
  5. if ( ce )
  6. ce.InitOffline();
  7. int year, month, day, hour, minute;
  8. int reset_month = 9, reset_day = 20;
  9. GetGame().GetWorld().GetDate(year, month, day, hour, minute);
  10. if ((month == reset_month) && (day < reset_day))
  11. {
  12. GetGame().GetWorld().SetDate(year, reset_month, reset_day, hour, minute);
  13. }
  14. else
  15. {
  16. if ((month == reset_month + 1) && (day > reset_day))
  17. {
  18. GetGame().GetWorld().SetDate(year, reset_month, reset_day, hour, minute);
  19. }
  20. else
  21. {
  22. if ((month < reset_month) || (month > reset_month + 1))
  23. {
  24. GetGame().GetWorld().SetDate(year, reset_month, reset_day, hour, minute);
  25. }
  26. }
  27. }
  28. }
  29. class CustomMission: MissionServer
  30. {
  31. //------------------------------------------------------------------
  32. // 初始化方法:在服务器启动时调用
  33. // 功能:加载复活套装配置并打印加载状态
  34. //------------------------------------------------------------------
  35. override void OnInit()
  36. {
  37. super.OnInit();
  38. GetCustomRevivalSuitCfg();
  39. if ( g_CustomRevivalSuitCfg )
  40. Print( "[复活套装]: 已加载" );
  41. }
  42. //------------------------------------------------------------------
  43. // 创建角色方法:在玩家首次加入或重生时调用
  44. // 参数:
  45. // identity - 玩家身份信息
  46. // pos - 出生位置
  47. // ctx - 上下文参数
  48. // characterName - 角色名称
  49. // 返回:PlayerBase - 创建的角色对象
  50. //------------------------------------------------------------------
  51. override PlayerBase CreateCharacter(PlayerIdentity identity, vector pos, ParamsReadContext ctx, string characterName)
  52. {
  53. Entity playerEnt;
  54. playerEnt = GetGame().CreatePlayer( identity, characterName, pos, 0, "NONE" );
  55. Class.CastTo( m_player, playerEnt );
  56. GetGame().SelectPlayer( identity, m_player );
  57. return m_player;
  58. }
  59. //------------------------------------------------------------------
  60. // 初始装备设置方法:在玩家重生时调用
  61. // 功能:根据玩家身份加载VIP装备,并设置默认装备, 如果玩家不是VIP,则使用
  62. // 默认的系统装备, 注意如果你要添加非VIP玩家的装备,
  63. // 请在 DefaultPlayerEquipment 方法中添加.
  64. // 参数:
  65. // player - 玩家对象
  66. // clothesChosen - 是否已选择服装
  67. //------------------------------------------------------------------
  68. override void StartingEquipSetup( PlayerBase player, bool clothesChosen )
  69. {
  70. GetCustomRevivalSuitCfg();
  71. if ( !player || !player.GetIdentity() ) return;
  72. string steamid = player.GetIdentity().GetPlainId();
  73. ref PlayerRevivalEquipmentData rev = g_CustomRevivalSuitCfg.GetPlayerRevivalEquipmentData( steamid );
  74. if ( rev )
  75. ProcessVIPEquipment( player, rev );
  76. DefaultPlayerEquipment( player, clothesChosen );
  77. }
  78. //------------------------------------------------------------------
  79. // 处理VIP装备方法:为VIP玩家设置自定义装备
  80. // 参数:
  81. // player - 玩家对象
  82. // equ_data - VIP装备数据
  83. // VIP玩家的出生装备处理方法, 这里根据josn配置的来生成, 不懂,请勿改动
  84. //------------------------------------------------------------------
  85. void ProcessVIPEquipment( PlayerBase player, ref PlayerRevivalEquipmentData equ_data )
  86. {
  87. if ( !equ_data ) return;
  88. player.RemoveAllItems();
  89. ItemBase equipment;
  90. foreach ( string equ : equ_data.Equipments )
  91. player.GetInventory().CreateInInventory( equ );
  92. foreach ( string item : equ_data.ItemList )
  93. player.GetInventory().CreateInInventory( item );
  94. if ( !equ_data.WeaponData || equ_data.WeaponData.WeaponName == "" ) return;
  95. Weapon_Base weapon = Weapon_Base.Cast( player.GetInventory().CreateInInventory( equ_data.WeaponData.WeaponName ) );
  96. if ( !weapon ) return
  97. foreach ( string attachment : equ_data.WeaponData.WeaponComponents )
  98. {
  99. if ( String( attachment ).ToType().IsInherited( Magazine ) )
  100. {
  101. Magazine wpn_mag = weapon.SpawnAttachedMagazine( attachment );
  102. if ( wpn_mag )
  103. wpn_mag.SetSynchDirty();
  104. continue;
  105. }
  106. if ( weapon.GetInventory() )
  107. ItemBase.Cast( weapon.GetInventory().CreateInInventory( attachment ) );
  108. }
  109. }
  110. //------------------------------------------------------------------
  111. // 设置随机健康值方法:为物品设置随机的健康值
  112. // 参数:
  113. // itemEnt - 物品实体
  114. //------------------------------------------------------------------
  115. void SetRandomHealth(EntityAI itemEnt)
  116. {
  117. if (itemEnt)
  118. {
  119. float rndHlt = Math.RandomFloat( 0.50, 0.85 );
  120. itemEnt.SetHealth01( "", "", rndHlt );
  121. }
  122. }
  123. //------------------------------------------------------------------
  124. // 默认装备设置方法:为玩家设置默认的初始装备
  125. // 参数:
  126. // player - 玩家对象
  127. // clothesChosen - 是否已选择服装
  128. // 这里的代码是原版init.c中 StartingEquipSetup 方法中的内容, 只是换了个方法名字
  129. //------------------------------------------------------------------
  130. void DefaultPlayerEquipment( PlayerBase player, bool clothesChosen )
  131. {
  132. EntityAI itemClothing;
  133. EntityAI itemEnt;
  134. ItemBase itemBs;
  135. float rand;
  136. itemClothing = player.FindAttachmentBySlotName( "Body" );
  137. if ( itemClothing )
  138. {
  139. SetRandomHealth( itemClothing );
  140. itemEnt = itemClothing.GetInventory().CreateInInventory( "BandageDressing" );
  141. if ( Class.CastTo( itemBs, itemEnt ) )
  142. itemBs.SetQuantity( 2 );
  143. string chemlightArray[] = { "Chemlight_White", "Chemlight_Yellow", "Chemlight_Green", "Chemlight_Red" };
  144. int rndIndex = Math.RandomInt( 0, 4 );
  145. itemEnt = itemClothing.GetInventory().CreateInInventory( chemlightArray[rndIndex] );
  146. SetRandomHealth( itemEnt );
  147. ItemBase itemTop;
  148. rand = Math.RandomFloatInclusive( 0.0, 1.0 );
  149. if ( rand < 0.35 )
  150. {
  151. itemEnt = player.GetInventory().CreateInInventory( "Rag" );
  152. itemTop = ItemBase.Cast( itemEnt );
  153. itemTop.RemoveAllAgentsExcept(eAgents.BRAIN | eAgents.SALMONELLA | eAgents.CHOLERA);
  154. itemTop.SetCleanness(1);
  155. }
  156. else if ( rand > 0.65 )
  157. {
  158. itemEnt = player.GetInventory().CreateInInventory( "Rag" );
  159. itemTop = ItemBase.Cast( itemEnt );
  160. itemTop.RemoveAllAgentsExcept(eAgents.BRAIN | eAgents.SALMONELLA | eAgents.CHOLERA);
  161. itemTop.SetCleanness(1);
  162. }
  163. else
  164. itemEnt = player.GetInventory().CreateInInventory( "Rag" );
  165. // SetRandomHealth( itemEnt );
  166. }
  167. itemClothing = player.FindAttachmentBySlotName( "Legs" );
  168. if ( itemClothing )
  169. SetRandomHealth( itemClothing );
  170. itemClothing = player.FindAttachmentBySlotName( "Feet" );
  171. }
  172. };
  173. Mission CreateCustomMission(string path)
  174. {
  175. return new CustomMission();
  176. }