misceffects.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. class MiscEffects : Managed
  2. {
  3. protected static const int VEGE_COLLISION_COOLDOWN = 3000; // ms
  4. protected static ref map <Object, float> m_VegeCollideColldowns = new map <Object, float>();
  5. // Called by individual clients when player collides with a vegetation
  6. static void PlayVegetationCollideParticles(Object object, DayZPlayerImplement player)
  7. {
  8. UpdateVegeCollisionCooldowns();
  9. if (m_VegeCollideColldowns.Get(object))
  10. return;
  11. int particleID;
  12. string particleName;
  13. string configPath = "CfgNonAIVehicles " + object.GetType() + " collisionParticle";
  14. GetGame().ConfigGetText(configPath, particleName);
  15. if (particleName == string.Empty) // no ptc assigned
  16. return;
  17. particleID = ParticleList.GetParticleIDByName(particleName);
  18. vector playerPos = player.GetPosition();
  19. vector ptcPos = playerPos - object.GetPosition();
  20. ptcPos[0] = ptcPos[0] * Math.RandomFloat(0, 0.5); // randomize
  21. ptcPos[2] = ptcPos[2] * Math.RandomFloat(0, 0.5);
  22. ptcPos = playerPos - ptcPos;
  23. ptcPos[1] = playerPos[1] + Math.RandomFloat(0.5, 1.5);
  24. ParticleManager.GetInstance().PlayInWorld(particleID, ptcPos);
  25. m_VegeCollideColldowns.Insert(object, GetWorldTime());
  26. }
  27. protected static void UpdateVegeCollisionCooldowns()
  28. {
  29. float time = GetWorldTime();
  30. foreach (Object key, float cd : m_VegeCollideColldowns)
  31. {
  32. if ((time - cd) > VEGE_COLLISION_COOLDOWN)
  33. {
  34. m_VegeCollideColldowns.Remove(key);
  35. break;
  36. }
  37. }
  38. }
  39. }