File size: 3,377 Bytes
24b81cb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
class HeatComfortAnimHandler
{
const float TICK_INTERVAL = 2;
float m_TimeSinceLastTick;
float m_ProcessTimeAccuFreeze;
float m_ProcessTimeAccuHot;
PlayerBase m_Player;
float m_EventTimeFreeze = -1;
float m_EventTimeHot = -1;
protected ref HumanMovementState m_MovementState = new HumanMovementState();
const float TIME_INTERVAL_HC_MINUS_LOW_MIN = 5; const float TIME_INTERVAL_HC_MINUS_LOW_MAX = 12;
const float TIME_INTERVAL_HC_MINUS_HIGH_MIN = 15; const float TIME_INTERVAL_HC_MINUS_HIGH_MAX = 25;
const float TIME_INTERVAL_HC_PLUS_LOW_MIN = 5; const float TIME_INTERVAL_HC_PLUS_LOW_MAX = 12;
const float TIME_INTERVAL_HC_PLUS_HIGH_MIN = 15; const float TIME_INTERVAL_HC_PLUS_HIGH_MAX = 25;
void HeatComfortAnimHandler(PlayerBase player)
{
m_Player = player;
}
void Update(float delta_time, HumanMovementState hms)
{
m_TimeSinceLastTick += delta_time;
if( m_TimeSinceLastTick > TICK_INTERVAL )
{
Process(m_TimeSinceLastTick);
m_TimeSinceLastTick = 0;
}
}
float GetEventTime(float hc_value ,float threshold_low, float threshold_high, float low_min, float high_min, float low_max, float high_max)
{
float inv_value = Math.InverseLerp(threshold_low, threshold_high, hc_value);
float value_min = Math.Lerp(low_min, high_min,inv_value);
float value_max = Math.Lerp(low_max,high_max,inv_value);
return Math.RandomFloatInclusive(value_min,value_max);
}
void Process(float delta_time)
{
if( GetGame().IsServer() )
{
float hc = m_Player.GetStatHeatComfort().Get();
float inv_value;
float value_min;
float value_max;
float offset_time;
if ( hc <= PlayerConstants.THRESHOLD_HEAT_COMFORT_MINUS_WARNING )
{
m_ProcessTimeAccuFreeze++;
if(m_EventTimeFreeze < 0)//if not set
{
m_EventTimeFreeze = GetEventTime(hc, PlayerConstants.THRESHOLD_HEAT_COMFORT_MINUS_EMPTY,PlayerConstants.THRESHOLD_HEAT_COMFORT_MINUS_WARNING, TIME_INTERVAL_HC_MINUS_LOW_MIN, TIME_INTERVAL_HC_MINUS_HIGH_MIN, TIME_INTERVAL_HC_MINUS_LOW_MAX, TIME_INTERVAL_HC_MINUS_HIGH_MAX);
}
if( m_ProcessTimeAccuFreeze > m_EventTimeFreeze )
{
m_ProcessTimeAccuFreeze = 0;
m_EventTimeFreeze = -1;
m_Player.GetSymptomManager().QueueUpPrimarySymptom(SymptomIDs.SYMPTOM_FREEZE);
/*
Print("-----======== freezing ========-------");
Print(inv_value);
Print(value_min);
Print(value_max);
Print(offset_time);
Print("-----======== freezing ========-------");
*/
}
}
else if ( hc >= PlayerConstants.THRESHOLD_HEAT_COMFORT_PLUS_WARNING )
{
m_ProcessTimeAccuHot++;
if(m_EventTimeHot < 0)//if not set
{
m_EventTimeHot = GetEventTime(hc, PlayerConstants.THRESHOLD_HEAT_COMFORT_PLUS_EMPTY,PlayerConstants.THRESHOLD_HEAT_COMFORT_PLUS_WARNING, TIME_INTERVAL_HC_PLUS_LOW_MIN, TIME_INTERVAL_HC_PLUS_LOW_MIN, TIME_INTERVAL_HC_PLUS_LOW_MAX, TIME_INTERVAL_HC_PLUS_HIGH_MAX);
}
if( m_ProcessTimeAccuHot > m_EventTimeHot )
{
m_ProcessTimeAccuHot = 0;
m_EventTimeHot = -1;
m_Player.GetSymptomManager().QueueUpPrimarySymptom(SymptomIDs.SYMPTOM_HOT);
//Print("-----======== freezing ========-------");
//Print(inv_value);
//Print(value_min);
//Print(value_max);
//Print(offset_time);
//Print("-----======== freezing ========-------");
}
}
}
}
} |