File size: 3,055 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 |
class DayZPlayerImplementSwimming
{
DayZPlayer m_pPlayer;
SHumanCommandSwimSettings m_pSettings;
bool m_bWasSwimming = false; // important for shallow water, so we know if we should get back into swimming when other fullbody command (like damage) finished
void DayZPlayerImplementSwimming(DayZPlayer pPlayer)
{
m_pPlayer = pPlayer;
m_pSettings = pPlayer.GetDayZPlayerType().CommandSwimSettingsW();
}
float GetWaterDepth()
{
vector pp = m_pPlayer.GetPosition();
vector wl = HumanCommandSwim.WaterLevelCheck(m_pPlayer, pp);
return wl[0];
}
float GetCharacterDepth()
{
vector pp = m_pPlayer.GetPosition();
vector wl = HumanCommandSwim.WaterLevelCheck(m_pPlayer, pp);
return wl[1];
}
bool CheckSwimmingStart(out vector waterLevel)
{
return DayZPlayerUtils.CheckWaterLevel(m_pPlayer,waterLevel) == EWaterLevels.LEVEL_SWIM_START;
}
//! ha
bool HandleSwimming(int pCurrentCommandID, HumanCommandMove pCMove, HumanMovementState pState)
{
if ( pCurrentCommandID == DayZPlayerConstants.COMMANDID_UNCONSCIOUS || pCurrentCommandID == DayZPlayerConstants.COMMANDID_DAMAGE )
return false;
m_bWasSwimming = false;
//! get water level
if (pCurrentCommandID != DayZPlayerConstants.COMMANDID_SWIM)
{
vector wl;
if (CheckSwimmingStart(wl))
{
m_pPlayer.StartCommand_Swim();
m_bWasSwimming = true;
return true;
}
//! now movement
if ((pCurrentCommandID == DayZPlayerConstants.COMMANDID_MOVE) && (pCMove != null))
{
pCMove.SetCurrentWaterLevel(wl[1]);
m_pPlayer.SetCurrentWaterLevel(wl[1]);
if (wl[1] > m_pSettings.m_fToErectLevel && pState.m_iStanceIdx != DayZPlayerConstants.STANCEIDX_ERECT && pState.m_iStanceIdx != DayZPlayerConstants.STANCEIDX_RAISEDERECT )
{
if ( DayZPlayerUtils.PlayerCanChangeStance(m_pPlayer, DayZPlayerConstants.STANCEIDX_ERECT) )
{
pCMove.ForceStanceUp(DayZPlayerConstants.STANCEIDX_ERECT);
}
else
{
m_pPlayer.StartCommand_Swim();
m_bWasSwimming = true;
return true;
}
}
else if (wl[1] > m_pSettings.m_fToCrouchLevel && (pState.m_iStanceIdx == DayZPlayerConstants.STANCEIDX_PRONE || pState.m_iStanceIdx == DayZPlayerConstants.STANCEIDX_RAISEDPRONE))
{
if ( DayZPlayerUtils.PlayerCanChangeStance(m_pPlayer, DayZPlayerConstants.STANCEIDX_CROUCH) )
{
pCMove.ForceStanceUp(DayZPlayerConstants.STANCEIDX_CROUCH);
}
else
{
m_pPlayer.StartCommand_Swim();
m_bWasSwimming = true;
return true;
}
}
}
// not handled
return false;
}
else // if (pCurrentCommandID == DayZPlayerConstants.COMMANDID_SWIM)
{
if (GetWaterDepth() < m_pSettings.m_fWaterLevelOut)
{
if (DayZPlayerUtils.PlayerCanChangeStance(m_pPlayer, DayZPlayerConstants.STANCEIDX_ERECT, true))
{
HumanCommandSwim hcs = m_pPlayer.GetCommand_Swim();
hcs.StopSwimming();
m_bWasSwimming = false;
return true;
}
}
//! handled !
m_bWasSwimming = true;
return true;
}
}
} |