areaexposure.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. class AreaExposureMdfr: ModifierBase
  2. {
  3. const int EVENT_1_INTERVAL_MIN = 3;
  4. const int EVENT_1_INTERVAL_MAX = 5;
  5. const float AGENTS_PER_SEC = 5;
  6. protected float m_NextEvent1;
  7. protected float m_Time1;
  8. const int EVENT_2_INTERVAL_MIN = 13;
  9. const int EVENT_2_INTERVAL_MAX = 18;
  10. const float AGENT_DOSE_PER_BS_SEC = 0.33;//how many agents will be injected in one sec per a single bleeding source
  11. protected float m_NextEvent2;
  12. protected float m_Time2;
  13. override void Init()
  14. {
  15. m_TrackActivatedTime = false;
  16. m_AnalyticsStatsEnabled = true;
  17. m_ID = eModifiers.MDF_AREAEXPOSURE;
  18. m_TickIntervalInactive = DEFAULT_TICK_TIME_INACTIVE_LONG;
  19. m_TickIntervalActive = DEFAULT_TICK_TIME_ACTIVE_SHORT;
  20. m_SyncID = eModifierSyncIDs.MODIFIER_SYNC_ZONE_EXPOSURE;
  21. DisableActivateCheck();
  22. DisableDeactivateCheck();
  23. }
  24. override bool ActivateCondition(PlayerBase player)
  25. {
  26. return false;
  27. }
  28. override void OnActivate(PlayerBase player)
  29. {
  30. JsonDataContaminatedAreas data = EffectAreaLoader.GetData();
  31. if (data)
  32. {
  33. MiscGameplayFunctions.TeleportCheck(player, data.SafePositions);
  34. player.SetPersistentFlag(PersistentFlag.AREA_PRESENCE, false);
  35. }
  36. //make the player cough immediately
  37. float transmitted = TransmitAgents(player, 1);
  38. if(transmitted)
  39. player.GetSymptomManager().QueueUpPrimarySymptom(SymptomIDs.SYMPTOM_COUGH);
  40. m_NextEvent1 = Math.RandomFloatInclusive( EVENT_1_INTERVAL_MIN, EVENT_1_INTERVAL_MAX );
  41. }
  42. override void OnDeactivate(PlayerBase player)
  43. {
  44. }
  45. override bool DeactivateCondition(PlayerBase player)
  46. {
  47. return false;
  48. }
  49. override void OnTick(PlayerBase player, float deltaT)
  50. {
  51. #ifdef DEVELOPER
  52. if(!player.GetCanBeDestroyed())
  53. return;
  54. #endif
  55. float transmitted = TransmitAgents(player, AGENTS_PER_SEC * deltaT);
  56. m_Time2 += deltaT;
  57. if (transmitted)
  58. {
  59. m_Time1 += deltaT;
  60. if (m_Time1 >= m_NextEvent1 )
  61. {
  62. player.GetSymptomManager().QueueUpPrimarySymptom(SymptomIDs.SYMPTOM_COUGH);
  63. if(Math.RandomFloat01() < 0.25)//creates a cough cooldown once in a while
  64. {
  65. m_NextEvent1 = Math.RandomFloatInclusive( EVENT_1_INTERVAL_MIN * 2, EVENT_1_INTERVAL_MAX * 2 );
  66. }
  67. else
  68. {
  69. m_NextEvent1 = Math.RandomFloatInclusive( EVENT_1_INTERVAL_MIN, EVENT_1_INTERVAL_MAX );
  70. }
  71. m_Time1 = 0;
  72. }
  73. }
  74. if ( m_Time2 >= m_NextEvent2 )
  75. {
  76. BleedingSourceCreateCheck(player);
  77. m_Time2 = 0;
  78. m_NextEvent2 = Math.RandomFloatInclusive( EVENT_2_INTERVAL_MIN, EVENT_2_INTERVAL_MAX );
  79. }
  80. ApplyAgentsToBleedingSources(player, deltaT);
  81. }
  82. void ApplyAgentsToBleedingSources(PlayerBase player, float deltaT)
  83. {
  84. int count = player.GetBleedingSourceCount();
  85. float agent_dose = count * AGENT_DOSE_PER_BS_SEC * deltaT;
  86. player.InsertAgent(eAgents.CHEMICAL_POISON, agent_dose);
  87. }
  88. void BleedingSourceCreateCheck(PlayerBase player)
  89. {
  90. int free_bs_locations = 0;//bitmask where each bit set to 1 represents available bleeding source location
  91. set<int> list = player.GetBleedingManagerServer().GetBleedingSourcesLocations();
  92. foreach(int location: list)
  93. {
  94. float prot_level = PluginTransmissionAgents.GetProtectionLevelEx(DEF_CHEMICAL, location, player, true);
  95. float dice_throw = Math.RandomFloat01();
  96. if(dice_throw > prot_level)
  97. {
  98. free_bs_locations = player.GetBleedingManagerServer().GetFreeBleedingSourceBitsByInvLocation(location) | free_bs_locations;
  99. }
  100. }
  101. int num_of_free_bs = Math.GetNumberOfSetBits(free_bs_locations);//gets us the number of bits set to 1, where each represents a free bleeding source location
  102. if ( num_of_free_bs > 0 )
  103. {
  104. int random_bs_index = Math.RandomIntInclusive(0, num_of_free_bs - 1 );// - 1 on the max to convert count to index
  105. int random_bs_bit = Math.Pow(2, Math.GetNthBitSet(free_bs_locations,random_bs_index));
  106. player.GetBleedingManagerServer().AttemptAddBleedingSourceDirectly(random_bs_bit, eBleedingSourceType.CONTAMINATED);
  107. }
  108. }
  109. float TransmitAgents(PlayerBase player, float count)
  110. {
  111. PluginTransmissionAgents plugin = PluginTransmissionAgents.Cast(GetPlugin(PluginTransmissionAgents));
  112. return plugin.TransmitAgentsEx(null, player, AGT_AIRBOURNE_CHEMICAL, count, eAgents.CHEMICAL_POISON);
  113. }
  114. };