init.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. bool isVIP = false;
  75. if ( rev )
  76. {
  77. isVIP = true;
  78. ProcessVIPEquipment( player, rev );
  79. }
  80. DefaultPlayerEquipment( player, clothesChosen, isVIP );
  81. }
  82. //------------------------------------------------------------------
  83. // 处理VIP装备方法:为VIP玩家设置自定义装备
  84. // 参数:
  85. // player - 玩家对象
  86. // equ_data - VIP装备数据
  87. // VIP玩家的出生装备处理方法, 这里根据josn配置的来生成, 不懂,请勿改动
  88. //------------------------------------------------------------------
  89. void ProcessVIPEquipment( PlayerBase player, ref PlayerRevivalEquipmentData equ_data )
  90. {
  91. if ( !equ_data ) return;
  92. player.RemoveAllItems();
  93. ItemBase equipment;
  94. foreach ( string equ : equ_data.Equipments )
  95. player.GetInventory().CreateInInventory( equ );
  96. foreach ( string item : equ_data.ItemList )
  97. player.GetInventory().CreateInInventory( item );
  98. if ( !equ_data.WeaponData || equ_data.WeaponData.WeaponName == "" ) return;
  99. Weapon_Base weapon = Weapon_Base.Cast( player.GetInventory().CreateInInventory( equ_data.WeaponData.WeaponName ) );
  100. if ( !weapon ) return
  101. foreach ( string attachment : equ_data.WeaponData.WeaponComponents )
  102. {
  103. if ( String( attachment ).ToType().IsInherited( Magazine ) )
  104. {
  105. Magazine wpn_mag = weapon.SpawnAttachedMagazine( attachment );
  106. if ( wpn_mag )
  107. wpn_mag.SetSynchDirty();
  108. continue;
  109. }
  110. if ( weapon.GetInventory() )
  111. ItemBase.Cast( weapon.GetInventory().CreateInInventory( attachment ) );
  112. }
  113. }
  114. //------------------------------------------------------------------
  115. // 设置随机健康值方法:为物品设置随机的健康值
  116. // 参数:
  117. // itemEnt - 物品实体
  118. //------------------------------------------------------------------
  119. void SetRandomHealth(EntityAI itemEnt)
  120. {
  121. if (itemEnt)
  122. {
  123. float rndHlt = Math.RandomFloat( 0.50, 0.85 );
  124. itemEnt.SetHealth01( "", "", rndHlt );
  125. }
  126. }
  127. //------------------------------------------------------------------
  128. // 默认装备设置方法:为玩家设置默认的初始装备
  129. // 参数:
  130. // player - 玩家对象
  131. // clothesChosen - 是否已选择服装
  132. // isVIP - 是否为VIP玩家
  133. // 这里的代码是原版init.c中 StartingEquipSetup 方法中的内容, 只是换了个方法名字
  134. //------------------------------------------------------------------
  135. void DefaultPlayerEquipment( PlayerBase player, bool clothesChosen, bool isVIP )
  136. {
  137. EntityAI itemClothing;
  138. EntityAI itemEnt;
  139. ItemBase itemBs;
  140. float rand;
  141. if ( !isVIP )
  142. {
  143. // TODO: 这里给普通玩家创建装备. 以前在StartingEquipSetup中如何给玩家创建新的装备这里就如何写
  144. // player.RemoveAllItems(); // 移除所有默认装备
  145. // itemEnt = player.GetInventory().CreateInInventory( "" /*这里写服装代码 */ );
  146. }
  147. itemClothing = player.FindAttachmentBySlotName( "Body" );
  148. if ( itemClothing )
  149. {
  150. SetRandomHealth( itemClothing );
  151. itemEnt = itemClothing.GetInventory().CreateInInventory( "BandageDressing" );
  152. if ( Class.CastTo( itemBs, itemEnt ) )
  153. itemBs.SetQuantity( 2 );
  154. string chemlightArray[] = { "Chemlight_White", "Chemlight_Yellow", "Chemlight_Green", "Chemlight_Red" };
  155. int rndIndex = Math.RandomInt( 0, 4 );
  156. itemEnt = itemClothing.GetInventory().CreateInInventory( chemlightArray[rndIndex] );
  157. SetRandomHealth( itemEnt );
  158. ItemBase itemTop;
  159. rand = Math.RandomFloatInclusive( 0.0, 1.0 );
  160. if ( rand < 0.35 )
  161. {
  162. itemEnt = player.GetInventory().CreateInInventory( "Rag" );
  163. itemTop = ItemBase.Cast( itemEnt );
  164. itemTop.RemoveAllAgentsExcept(eAgents.BRAIN | eAgents.SALMONELLA | eAgents.CHOLERA);
  165. itemTop.SetCleanness(1);
  166. }
  167. else if ( rand > 0.65 )
  168. {
  169. itemEnt = player.GetInventory().CreateInInventory( "Rag" );
  170. itemTop = ItemBase.Cast( itemEnt );
  171. itemTop.RemoveAllAgentsExcept(eAgents.BRAIN | eAgents.SALMONELLA | eAgents.CHOLERA);
  172. itemTop.SetCleanness(1);
  173. }
  174. else
  175. itemEnt = player.GetInventory().CreateInInventory( "Rag" );
  176. // SetRandomHealth( itemEnt );
  177. }
  178. itemClothing = player.FindAttachmentBySlotName( "Legs" );
  179. if ( itemClothing )
  180. SetRandomHealth( itemClothing );
  181. itemClothing = player.FindAttachmentBySlotName( "Feet" );
  182. }
  183. };
  184. Mission CreateCustomMission(string path)
  185. {
  186. return new CustomMission();
  187. }