File size: 6,063 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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
class HitDirectionEffectBase
{
const float DURATION_COEF_MIN = 0.6;
const float INTENSITY_MIN = 0.6;
float m_HitDirection;
float m_Duration;
float m_BreakPoint;
float m_TimeActive;
float m_IntensityMax;
Widget m_LayoutRoot;
Widget m_Image;
DayZPlayer m_Player;
bool m_Initialized;
int m_SizeXEnf;
int m_SizeYEnf;
float m_PosX;
float m_PosY;
float m_PosXScreenEdge;
float m_PosYScreenEdge;
float m_AngleRad;
float m_AngleRadPrev;
float m_SmoothVel[1];
ref HitDirectionImagesBase m_ImageData;
void HitDirectionEffectBase()
{
m_Initialized = false;
m_PosX = 0.0;
m_PosY = 0.0;
m_AngleRad = 0.0;
m_SmoothVel[0] = 0.0;
m_ImageData = GetImageData();
m_ImageData.GetCurrentImageData(m_LayoutRoot,m_Image);
}
//! Called manually after object spawn
void Init(DayZPlayer player, float hit_direction, float intensity_max)
{
m_Player = player;
float duration_coef = Math.Clamp(intensity_max,DURATION_COEF_MIN,1);
m_IntensityMax = Math.Clamp(intensity_max,INTENSITY_MIN,1);
m_Duration = m_DurationMax * duration_coef;
m_BreakPoint = Math.Clamp(m_BreakPointBase * m_Duration,0,m_Duration);
m_Scatter = Math.Clamp(m_Scatter,0.0,180.0);
m_HitDirection = hit_direction + (Math.RandomFloatInclusive(0,m_Scatter) * Math.Pow(-1.0,Math.RandomIntInclusive(0,1)));
Widget w = m_LayoutRoot;
w = w.GetChildren();
while (w)
{
w.Show(m_Image == w);
w = w.GetSibling();
}
m_Image.SetColor(m_Color);
m_LayoutRoot.Show(true);
CalculateArrowPosition();
SetIndicatorRotation();
SetIndicatorPositon();
m_Initialized = true;
}
HitDirectionImagesBase GetImageData(){}
void ~HitDirectionEffectBase()
{
m_LayoutRoot.Show(false);
delete m_LayoutRoot;
}
bool DurationCheck()
{
if ( m_TimeActive >= m_Duration )
{
return true;
}
return false;
}
void Update( float timeslice )
{
float intensity;
if ( m_TimeActive <= m_BreakPoint )
{
intensity = m_IntensityMax;
}
else
{
float tmp_value = Math.InverseLerp(m_BreakPoint, m_Duration, m_TimeActive);
intensity = Math.Lerp(m_IntensityMax,0.0,tmp_value);
}
m_TimeActive += timeslice;
intensity = Math.Clamp(intensity,0,1);
if ( m_TimeActive >= m_Duration )
{
m_LayoutRoot.Show(false);
}
else
{
m_LayoutRoot.SetAlpha(intensity);
if ( m_Mode == HitDirectionModes.DYNAMIC )
{
CalculateArrowPosition(timeslice);
SetIndicatorPositon(timeslice);
SetIndicatorRotation(timeslice);
}
}
}
void CalculateArrowPosition(float timeslice = -1.0)
{
m_HitDirection = Math.NormalizeAngle(m_HitDirection);
float angle_direction = m_Player.GetOrientation()[0];
angle_direction = Math.NormalizeAngle(angle_direction);
float camera_angle = GetGame().GetCurrentCameraDirection().VectorToAngles()[0];
camera_angle = Math.NormalizeAngle(camera_angle);
float angle_camera_diff = angle_direction - camera_angle;
m_AngleRad = m_HitDirection + angle_camera_diff;
m_AngleRad = Math.NormalizeAngle(m_AngleRad);
m_AngleRad = m_AngleRad * Math.DEG2RAD;
m_PosX = 0.0;
m_PosY = 0.0;
GetScreenSize(m_SizeXEnf,m_SizeYEnf);
if ( m_Initialized && timeslice != -1.0 )
{
float val = m_AngleRadPrev - m_AngleRad + Math.PI;
val = Math.ModFloat(val, Math.PI2);
val -= Math.PI;
m_AngleRad = m_AngleRadPrev - Math.SmoothCD(0, val, m_SmoothVel, 0.1, 1000, timeslice);
}
m_AngleRadPrev = m_AngleRad;
m_PosXScreenEdge = Math.Clamp(Math.Sin(m_AngleRad)/Math.Sin(Math.PI/4),-1,1) * ( m_SizeXEnf/2 + m_DistanceAdjust * m_SizeXEnf);
m_PosYScreenEdge = Math.Clamp(-1 * Math.Cos(m_AngleRad)/Math.Cos(Math.PI/4),-1,1) * ( m_SizeYEnf/2 + m_DistanceAdjust * m_SizeYEnf);
FinalizePositionCalculation();
}
//! specific handling on individual indicator type
void FinalizePositionCalculation(){}
void SetIndicatorRotation(float timeslice = -1.0){}
void SetIndicatorPositon(float timeslice = -1.0)
{
m_LayoutRoot.SetPos(m_PosX,m_PosY,true);
}
//-----------------------------------------------------------------------
//Static stuff below
//-----------------------------------------------------------------------
static bool m_ServerOverrideEnabled;
static int m_Mode;
static int m_ID;
static int m_Color;
static protected typename m_Type;
static float m_DurationMax;
static float m_BreakPointBase; //! range 0..1, a point where the fading starts
static float m_DistanceAdjust;
static int m_RotationOverride;
static float m_Scatter; //! range 0..180, randomized offset of direction to make it less acurate
//!sets override values, or defaults
static void CheckValues()
{
m_ServerOverrideEnabled = CfgGameplayHandler.GetHitIndicationOverrideEnabled();
if (m_ServerOverrideEnabled)
{
m_Mode = CfgGameplayHandler.GetHitIndicationMode();
m_ID = CfgGameplayHandler.GetHitIndicationTypeID();
m_Color = CfgGameplayHandler.GetHitIndicationIndicatorColor();
m_DurationMax = CfgGameplayHandler.GetHitIndicationMaxDuration();
m_BreakPointBase = CfgGameplayHandler.GetHitIndicationBreakPoint();
m_Scatter = CfgGameplayHandler.GetHitIndicationScatter();
}
else
{
m_Mode = HitDirectionModes.STATIC;
m_ID = HitIndicatorType.SPLASH;
m_Color = HitDirectionConstants.COLOR_DEFAULT;
m_DurationMax = HitDirectionConstants.DURATION_BASE;
m_BreakPointBase = HitDirectionConstants.BREAKPOINT_BASE;
m_Scatter = HitDirectionConstants.SCATTER;
}
m_DistanceAdjust = HitDirectionConstants.DISTANCE_ADJUST;
m_RotationOverride = HitDirectionConstants.ROTATION_DEFAULT;
}
static typename GetCurrentType()
{
switch (m_ID)
{
case HitIndicatorType.SPLASH:
m_Type = HitDirectionEffectSplash;
break;
case HitIndicatorType.SPIKE:
m_Type = HitDirectionEffectSpike;
break;
case HitIndicatorType.ARROW:
m_Type = HitDirectionEffectArrow;
break;
default:
ErrorEx("Unknown HitDirection mode, using HitIndicatorType.SPLASH",ErrorExSeverity.INFO);
m_Type = HitDirectionEffectSplash;
break;
}
return m_Type;
}
} |