123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315 |
- 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()
- {
- EndOrInterruptCurrentAction();
- }
-
- override void EndOrInterruptCurrentAction()
- {
- 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");
- RequestInterruptAction();
- }
- 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
- {
- RequestInterruptAction();
- }
- 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())
- {
- if (target)
- {
- Debug.ActionLog("Item = " + item + ", " + target.DumpToString(), pickedAction.ToString() , "n/a", "DeliveredAction", m_Player.ToString());
- }
- else
- {
- Debug.ActionLog("Item = " + item + ", NULL", 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))
- {
- if (pickedAction.AddActionJuncture(m_CurrentActionData))
- accepted = true;
- }
-
- 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
- {
- RequestInterruptAction();
- }
- }
- }
-
- override void OnActionEnd()
- {
- //Debug.Log("Action ended - hard, STS = " + m_Player.GetSimulationTimeStamp());
- if (m_CurrentActionData)
- {
- m_CurrentActionData.m_Action.ClearActionJuncture(m_CurrentActionData);
- 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
- {
- RequestInterruptAction();
- }
- }
- }
- 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);
- }
-
- //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
-
- int condition_mask = ActionBase.ComputeConditionMask(m_Player, m_CurrentActionData.m_Target, m_CurrentActionData.m_MainItem);
- bool canActionPerform = ((condition_mask & m_CurrentActionData.m_Action.m_ConditionMask) == condition_mask);
- 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
- {
- RequestInterruptAction();
- }
- 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;
- }
- }
- }
-
- //! server requests action interrupt
- override void RequestInterruptAction()
- {
- if (m_CurrentActionData)
- DayZPlayerSyncJunctures.SendActionInterrupt(m_Player);
- }
-
- override ActionReciveData GetReciveData()
- {
- return m_PendingActionReciveData;
- }
- }
|