File size: 8,865 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 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
class ActionManagerServer: ActionManagerBase
{
protected ActionBase m_PendingAction;
ref ActionReciveData m_PendingActionReciveData;
void ActionManagerServer(PlayerBase player)
{
m_PendingAction = null;
m_PendingActionReciveData = null;
}
//------------------------------------------
//EVENTS
//------------------------------------------
override void OnJumpStart()
{
if (m_CurrentActionData)
{
if (m_CurrentActionData.m_State == UA_AM_PENDING || m_CurrentActionData.m_State == UA_AM_REJECTED || m_CurrentActionData.m_State == UA_AM_ACCEPTED)
{
OnActionEnd();
m_PendingActionAcknowledgmentID = -1;
}
else
{
m_CurrentActionData.m_Action.Interrupt(m_CurrentActionData);
}
}
}
override bool OnInputUserDataProcess(int userDataType, ParamsReadContext ctx)
{
switch (userDataType)
{
case INPUT_UDT_STANDARD_ACTION_START:
{
bool success = true;
int actionID = 0;
if (!ctx.Read(actionID))
return false;
ActionBase recvAction = GetAction(actionID);
if (!recvAction)
return false;
if (!recvAction.ReadFromContext(ctx, m_PendingActionReciveData))
success = false;
m_PendingAction = recvAction;
if (recvAction.UseAcknowledgment())
{
int ackID;
if (!ctx.Read(ackID))
success = false;
m_PendingActionAcknowledgmentID = ackID;
}
break;
}
case INPUT_UDT_STANDARD_ACTION_END_REQUEST:
{
//Debug.Log("Action want end request, STS = " + m_Player.GetSimulationTimeStamp());
int commandID = -10;
ctx.Read(commandID);
if (commandID == DayZPlayerConstants.CMD_ACTIONINT_INTERRUPT)
{
//Print("INPUT_UDT_STANDARD_ACTION_END_REQUEST | CMD_ACTIONINT_INTERRUPT");
Interrupt();
}
else
{
//Print("INPUT_UDT_STANDARD_ACTION_END_REQUEST | m_ActionWantEndRequest");
m_ActionWantEndRequest = true;
}
}
case INPUT_UDT_STANDARD_ACTION_INPUT_END:
{
//Debug.Log("Action input ended, STS = " + m_Player.GetSimulationTimeStamp());
m_ActionInputWantEnd = true;
}
default:
return false;
}
if (!success)
{
//Debug.Log("[AM] OnInputUserDataProcess INPUT_UDT_STANDARD_ACTION_START Error");
if (recvAction.UseAcknowledgment())
{
DayZPlayerSyncJunctures.SendActionAcknowledgment(m_Player, m_PendingActionAcknowledgmentID, false);
}
else
{
Interrupt();
}
return false;
}
return true;
}
override void StartDeliveredAction()
{
if (!m_CurrentActionData)
{
//! error - expected action data
return;
}
m_Interrupted = false;
bool accepted = false;
ActionBase pickedAction = m_CurrentActionData.m_Action;
ActionTarget target = m_CurrentActionData.m_Target;
ItemBase item = m_CurrentActionData.m_MainItem;
if (LogManager.IsActionLogEnable())
{
Debug.ActionLog("Item = " + item + ", " + target.DumpToString(), pickedAction.ToString() , "n/a", "DeliveredAction", m_Player.ToString());
}
if (!m_Player.GetCommandModifier_Action() && !m_Player.GetCommand_Action() && !m_Player.IsSprinting() && pickedAction && pickedAction.Can(m_Player,target,item))
{
accepted = true;
if (pickedAction.HasTarget())
{
EntityAI targetEntity;
if (EntityAI.CastTo(targetEntity,target.GetObject()))
{
if (!AdvancedCommunication.Cast(targetEntity) && !Building.Cast(targetEntity) && pickedAction.IsLockTargetOnUse())
{
//Lock target
if (!GetGame().AddActionJuncture(m_Player, targetEntity, 10000))
{
accepted = false;
}
}
}
}
}
if (accepted)
{
if (LogManager.IsActionLogEnable())
{
Debug.ActionLog("Action accepted", pickedAction.ToString() , "n/a", "CheckDeliveredAction", m_Player.ToString() );
}
//Debug.Log("[AM] Action acccepted");
if (pickedAction.UseAcknowledgment())
{
//Unlock target
m_CurrentActionData.m_State = UA_AM_PENDING;
DayZPlayerSyncJunctures.SendActionAcknowledgment(m_Player, m_PendingActionAcknowledgmentID, true);
}
else
{
m_CurrentActionData.m_State = UA_AM_ACCEPTED;
}
}
else
{
if (LogManager.IsActionLogEnable())
{
Debug.ActionLog("Action rejected", pickedAction.ToString() , "n/a", "CheckDeliveredAction", m_Player.ToString() );
}
if (pickedAction.UseAcknowledgment())
{
DayZPlayerSyncJunctures.SendActionAcknowledgment(m_Player, m_PendingActionAcknowledgmentID, false);
}
else
{
Interrupt();
}
}
}
override void OnActionEnd()
{
//Debug.Log("Action ended - hard, STS = " + m_Player.GetSimulationTimeStamp());
if (m_CurrentActionData)
{
if ( m_CurrentActionData.m_Target )
{
EntityAI targetEntity;
if (targetEntity.CastTo(targetEntity, m_CurrentActionData.m_Target.GetObject()) && !Building.Cast(targetEntity))
{
GetGame().ClearJuncture(m_CurrentActionData.m_Player, targetEntity);
}
}
super.OnActionEnd();
}
}
//pCurrentCommandID is command ID at time of call command handler, some called methods can change actual true value (need call m_Player.GetCurrentCommandID() for actual command ID)
override void Update(int pCurrentCommandID)
{
super.Update(pCurrentCommandID);
int currentCommandID = m_Player.GetCurrentCommandID();
//Debug.Log("m_ActionWantEnd " + m_ActionInputWantEnd);
if (m_PendingAction)
{
if (m_CurrentActionData)
{
DayZPlayerSyncJunctures.SendActionAcknowledgment(m_Player, m_PendingActionAcknowledgmentID, false);
}
else
{
m_ActionWantEndRequest = false;
m_ActionInputWantEnd = false;
bool success = true;
ActionTarget target = new ActionTarget(null, null, -1, vector.Zero, 0);
if ( LogManager.IsActionLogEnable() )
{
Debug.ActionLog("n/a", m_PendingAction.ToString() , "n/a", "HandlePendingAction", m_Player.ToString() );
}
if (!m_PendingAction.SetupAction(m_Player,target,m_Player.GetItemInHands(),m_CurrentActionData))
{
success = false;
}
//Debug.Log("[AM] Action data synced (" + m_Player + ") success: " + success);
if (success)
{
StartDeliveredAction();
}
else
{
if (m_PendingAction.UseAcknowledgment())
{
DayZPlayerSyncJunctures.SendActionAcknowledgment(m_Player, m_PendingActionAcknowledgmentID, false);
}
else
{
Interrupt();
}
}
}
m_PendingAction = null;
m_PendingActionReciveData = null;
}
if (m_CurrentActionData)
{
if (m_CurrentActionData.m_State != UA_AM_PENDING && m_CurrentActionData.m_State != UA_AM_REJECTED && m_CurrentActionData.m_State != UA_AM_ACCEPTED)
{
m_CurrentActionData.m_Action.OnUpdateServer(m_CurrentActionData);
if (m_CurrentActionData.m_RefreshJunctureTimer > 0)
{
m_CurrentActionData.m_RefreshJunctureTimer--;
}
else
{
m_CurrentActionData.m_RefreshJunctureTimer = m_CurrentActionData.m_Action.GetRefreshReservationTimerValue();
if (m_CurrentActionData.m_Target)
{
EntityAI targetEntity;
if ( targetEntity.CastTo(targetEntity, m_CurrentActionData.m_Target.GetObject()) && !Building.Cast(targetEntity) )
{
GetGame().ExtendActionJuncture(m_CurrentActionData.m_Player, targetEntity, 10000);
}
}
}
}
//Debug.Log("m_CurrentActionData.m_State: " + m_CurrentActionData.m_State +" m_ActionWantEnd: " + m_ActionWantEndRequest );
switch (m_CurrentActionData.m_State)
{
case UA_AM_PENDING:
break;
case UA_AM_ACCEPTED:
// check currentCommandID before start or reject
bool canActionPerform = m_CurrentActionData.m_Action.Can(m_Player, m_CurrentActionData.m_Target, m_CurrentActionData.m_MainItem);
if (canActionPerform && ActionPossibilityCheck(currentCommandID))
{
m_CurrentActionData.m_State = UA_START;
m_CurrentActionData.m_Action.Start(m_CurrentActionData);
if (m_CurrentActionData.m_Action && m_CurrentActionData.m_Action.IsInstant())
OnActionEnd();
}
else
{
Interrupt();
}
m_PendingActionAcknowledgmentID = -1;
break;
case UA_AM_REJECTED:
OnActionEnd();
m_PendingActionAcknowledgmentID = -1;
break;
default:
if (m_ActionInputWantEnd)
{
m_ActionInputWantEnd = false;
m_CurrentActionData.m_Action.EndInput(m_CurrentActionData);
}
if (m_ActionWantEndRequest)
{
m_ActionWantEndRequest = false;
m_CurrentActionData.m_Action.EndRequest(m_CurrentActionData);
}
break;
}
}
}
override void Interrupt()
{
super.Interrupt();
if (m_CurrentActionData)
DayZPlayerSyncJunctures.SendActionInterrupt(m_Player);
}
override ActionReciveData GetReciveData()
{
return m_PendingActionReciveData;
}
}
|