123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293 |
- typedef map<typename,ref array<ActionBase_Basic>> TInputActionMap;
- typedef map<typename,ref ActionInput> TTypeNameActionInputMap;
- class ActionManagerClient: ActionManagerBase
- {
-
- //Last send AcknowledgmentID (client can send more requests before recive ackfor first action)
- protected int m_LastAcknowledgmentID;
- protected bool m_ActionPossible;
- protected ref array<ref InventoryLocation> m_ReservedInventoryLocations; // obsolete
- protected ref InventoryActionHandler m_InventoryActionHandler;
- protected ref InventoryLocation m_HandInventoryLocationTest;
- protected ref TTypeNameActionInputMap m_RegistredInputsMap;
- protected ref array<ActionInput> m_OrederedAllActionInput;
- protected ref array<ActionInput> m_OrderedStandartActionInputs;
- protected ref array<ActionInput> m_DefaultOrderOfActionInputs;
- protected int m_SelectedActionInputToSrollIndex;
- protected bool m_IgnoreAutoInputEnd;
-
- protected ref ActionData m_PendingActionData;
- protected bool m_ActionWantEndRequest_Send; //Request to server was sended
- protected bool m_ActionInputWantEnd_Send;
- void ActionManagerClient(PlayerBase player)
- {
- m_HandInventoryLocationTest = new InventoryLocation;
- m_HandInventoryLocationTest.SetHands(player,null);
- m_LastAcknowledgmentID = 1;
- m_Targets = new ActionTargets(player);
- //m_ReservedInventoryLocations = new array<ref InventoryLocation>;
- m_InventoryActionHandler = new InventoryActionHandler(player);
- m_ActionWantEndRequest_Send = false;
- m_ActionInputWantEnd_Send = false;
- RegisterInputs(player);
- m_SelectedActionInputToSrollIndex = 0;
- }
-
- //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)
- {
- m_InventoryActionHandler.OnUpdate();
- super.Update(pCurrentCommandID);
- int currentCommandID = m_Player.GetCurrentCommandID();
- m_ActionPossible = ActionPossibilityCheck(currentCommandID);
-
- if (m_PendingActionData) //SP only
- {
- m_CurrentActionData = m_PendingActionData;
-
- m_CurrentActionData.m_Action.Start(m_CurrentActionData);
-
- if (m_CurrentActionData.m_Action.IsInstant())
- OnActionEnd();
-
- m_PendingActionData = 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.OnUpdateClient(m_CurrentActionData);
-
- switch (m_CurrentActionData.m_State)
- {
- case UA_AM_PENDING:
- break;
-
- case UA_AM_ACCEPTED:
- int condition_mask = ActionBase.ComputeConditionMask(m_Player, m_CurrentActionData.m_Target, m_CurrentActionData.m_MainItem);
-
- m_CurrentActionData.m_Action.ClearInventoryReservationEx(m_CurrentActionData);
- bool can_be_action_done = ((condition_mask & m_CurrentActionData.m_Action.m_ConditionMask) == condition_mask);
- // check currentCommandID before start or reject
- if (m_ActionPossible && can_be_action_done)
- {
- m_CurrentActionData.m_Action.InventoryReservation(m_CurrentActionData);
- m_CurrentActionData.m_State = UA_START;
- m_CurrentActionData.m_Action.Start(m_CurrentActionData);
-
- if (m_CurrentActionData.m_Action.IsInstant())
- OnActionEnd();
- }
- else
- {
- RequestInterruptAction();
- OnActionEnd();
- }
- m_PendingActionAcknowledgmentID = -1;
- break;
-
- case UA_AM_REJECTED:
- OnActionEnd();
- m_PendingActionAcknowledgmentID = -1;
- break;
-
- default:
- ProcessActionRequestEnd();
- ProcessActionInputEnd();
- break;
- }
- }
-
- #ifdef DEVELOPER
- if (DeveloperFreeCamera.IsFreeCameraEnabled())
- {
- m_ActionPossible = false;
- ResetInputsActions();
- }
- else
- {
- #endif
- if (!m_CurrentActionData)
- {
- bool isMenuOpen = false;
- #ifndef NO_GUI
- isMenuOpen = GetGame().GetUIManager().IsMenuOpen(MENU_INVENTORY);
- #endif
- if (m_Player.IsRaised() || isMenuOpen)
- {
- m_Targets.Clear();
- }
- else
- {
- m_Targets.Update();
- }
- FindContextualUserActions(currentCommandID);
- }
-
- InputsUpdate();
- #ifdef DEVELOPER
- }
- #endif
- }
-
- void RegisterInputs(PlayerBase player)
- {
- if (!m_RegistredInputsMap)
- {
- m_RegistredInputsMap = new TTypeNameActionInputMap;
- for (int i = 0; i < m_ActionsArray.Count(); i++)
- {
- ActionBase action = m_ActionsArray.Get(i);
- typename input_type_name = action.GetInputType();
- ref ActionInput ai;
-
- ai = ActionInput.Cast(m_RegistredInputsMap.Get(input_type_name));
- if (!ai)
- {
- ai = ActionInput.Cast(input_type_name.Spawn());
- m_RegistredInputsMap.Insert(input_type_name, ai);
- }
- action.SetInput(ai);
- }
-
- for (int j = 0; j < m_RegistredInputsMap.Count(); j++)
- {
- m_RegistredInputsMap.GetElement(j).Init(player, this);
- }
- SetActioninputOrder();
- }
-
- }
-
- //Set order of inputs base of priority (output -> m_OrederedAllActionInput)
- void SetActioninputOrder()
- {
- int i, j;
- int priority;
- ActionInput input;
- m_OrederedAllActionInput = new array<ActionInput>;
-
- map<int, ref array<ActionInput>> temp_map_for_sort = new map<int, ref array<ActionInput>>;
- array<int> array_of_priorities_to_sort = new array<int>;
- ref array<ActionInput> same_priority_input_array;
-
- for (i = 0; i < m_RegistredInputsMap.Count(); i++)
- {
- input = m_RegistredInputsMap.GetElement(i);
- priority = input.GetPriority();
- same_priority_input_array = temp_map_for_sort.Get(priority);
- if (same_priority_input_array)
- {
- same_priority_input_array.Insert(input);
- continue;
- }
-
- same_priority_input_array = new array<ActionInput>;
- same_priority_input_array.Insert(input);
- temp_map_for_sort.Insert(priority,same_priority_input_array);
- array_of_priorities_to_sort.Insert(priority);
- }
- array_of_priorities_to_sort.Sort();
-
- for (i = 0; i < array_of_priorities_to_sort.Count(); i++)
- {
- priority = array_of_priorities_to_sort[i];
- same_priority_input_array = temp_map_for_sort.Get(priority);
- for (j = 0; j < same_priority_input_array.Count(); j++)
- {
- input = same_priority_input_array.Get(j);
- m_OrederedAllActionInput.Insert(input);
- }
- }
-
- SetDefaultInputsOrder();
- }
-
- //Order for user action inputs - will be dynamically change base on context (more complex handling viz set m_OrderedStandartActionInputs in UpdateActionCategoryPriority())
- void SetDefaultInputsOrder()
- {
- int i, j;
- m_DefaultOrderOfActionInputs = new array<ActionInput>;
- m_OrderedStandartActionInputs = new array<ActionInput>;
- ActionInput input = m_RegistredInputsMap.Get(ContinuousDefaultActionInput);
- if (input)
- {
- m_OrderedStandartActionInputs.Insert(input);
- }
- input = m_RegistredInputsMap.Get(DefaultActionInput);
- if (input)
- {
- m_OrderedStandartActionInputs.Insert(input);
- }
-
- input = m_RegistredInputsMap.Get(ContinuousInteractActionInput);
- if (input)
- {
- m_OrderedStandartActionInputs.Insert(input);
- }
-
- input = m_RegistredInputsMap.Get(InteractActionInput);
- if (input)
- {
- m_OrderedStandartActionInputs.Insert(input);
- }
-
- for (i = 0; i < m_OrederedAllActionInput.Count(); i++)
- {
- for (j = 0; j < m_OrderedStandartActionInputs.Count(); j++)
- {
- if (m_OrederedAllActionInput[i] == m_OrderedStandartActionInputs[j])
- {
- m_DefaultOrderOfActionInputs.Insert(m_OrederedAllActionInput[i]);
- break;
- }
- }
- }
- }
-
- static ActionVariantManager GetVariantManager(typename actionName)
- {
- ActionBase action = GetAction(actionName);
- if (action)
- {
- return action.GetVariantManager();
- }
- //VME ACTION not exist typo most likely
- return null;
- }
-
- override void RequestEndAction()
- {
- if (!m_ActionWantEndRequest_Send)
- {
- m_ActionWantEndRequest = true;
- }
- }
-
- override void EndActionInput()
- {
- if (!m_ActionInputWantEnd_Send)
- {
- m_ActionInputWantEnd = true;
- }
- }
-
- void InputsUpdate()
- {
- ActionInput ain;
- if (m_CurrentActionData)
- {
- if (!m_ActionInputWantEnd)
- {
- ActionInput ai = m_CurrentActionData.m_Action.GetInput();
- ai.Update();
- if (m_Player.IsQBControl())
- {
- if (ai.JustActivate())
- m_Player.SetActionEndInput(m_CurrentActionData.m_Action);
- }
- else
- {
- if (ai.WasEnded() && (ai.GetInputType() == ActionInputType.AIT_CONTINUOUS || ai.GetInputType() == ActionInputType.AIT_CLICKCONTINUOUS) && !m_IgnoreAutoInputEnd)
- {
- EndActionInput();
- }
- }
- }
- }
- else
- {
- if (m_ActionsAvaibale)
- {
- for (int i = 0; i < m_OrederedAllActionInput.Count();i++)
- {
-
- ain = m_OrederedAllActionInput[i];
- ain.Update();
-
- if (ain.JustActivate())
- {
- ActionBase action = ain.GetAction();
- if (action)
- {
- ActionStart(action, ain.GetUsedActionTarget(), ain.GetUsedMainItem());
- break;
- }
- }
- }
- }
- }
- }
-
- void ProcessActionRequestEnd()
- {
- if (m_ActionWantEndRequest)
- {
- if (GetGame().IsMultiplayer() && !m_CurrentActionData.m_Action.IsLocal())
- {
- if (!m_ActionWantEndRequest_Send && ScriptInputUserData.CanStoreInputUserData())
- {
- if (LogManager.IsActionLogEnable())
- {
- Debug.ActionLog("Time stamp: " + m_Player.GetSimulationTimeStamp(), m_CurrentActionData.m_Action.ToString() , "n/a", "EndRequest", m_CurrentActionData.m_Player.ToString());
- }
- ScriptInputUserData ctx = new ScriptInputUserData;
- ctx.Write(INPUT_UDT_STANDARD_ACTION_END_REQUEST);
- ctx.Send();
-
- m_ActionWantEndRequest_Send = true;
-
- m_ActionWantEndRequest = false;
- m_CurrentActionData.m_Action.EndRequest(m_CurrentActionData);
- }
- }
- else
- {
- m_ActionWantEndRequest = false;
- m_CurrentActionData.m_Action.EndRequest(m_CurrentActionData);
- }
- }
- }
-
- void ProcessActionInputEnd()
- {
- if (m_ActionInputWantEnd)
- {
- if (GetGame().IsMultiplayer() && !m_CurrentActionData.m_Action.IsLocal())
- {
- if (!m_ActionInputWantEnd_Send && ScriptInputUserData.CanStoreInputUserData())
- {
- if (LogManager.IsActionLogEnable())
- {
- Debug.ActionLog("Time stamp: " + m_Player.GetSimulationTimeStamp(), m_CurrentActionData.m_Action.ToString() , "n/a", "EndInput", m_CurrentActionData.m_Player.ToString());
- }
- ScriptInputUserData ctxi = new ScriptInputUserData;
- ctxi.Write(INPUT_UDT_STANDARD_ACTION_INPUT_END);
- ctxi.Send();
-
- m_ActionInputWantEnd_Send = true;
-
- m_ActionInputWantEnd = false;
- m_CurrentActionData.m_Action.EndInput(m_CurrentActionData);
- }
- }
- else
- {
- if (!m_ActionInputWantEnd_Send)
- {
- m_ActionInputWantEnd_Send = true;
- m_ActionInputWantEnd = false;
- m_CurrentActionData.m_Action.EndInput(m_CurrentActionData);
- }
- }
- }
- }
-
- ActionBase GetPossibleAction(typename inputType)
- {
- ActionInput action_input = m_RegistredInputsMap.Get(inputType);
- if (action_input)
- {
- return action_input.GetAction();
- }
- return NULL;
- }
-
- array<ActionBase> GetPossibleActions(typename inputType)
- {
- ActionInput action_input = m_RegistredInputsMap.Get(inputType);
- if (action_input)
- {
- return action_input.GetPossibleActions();
- }
- return NULL;
- }
-
- int GetPossibleActionIndex(typename inputType)
- {
- ActionInput action_input = m_RegistredInputsMap.Get(inputType);
- if (action_input)
- {
- return action_input.GetPossibleActionIndex();
- }
- return -1;
- }
-
- int GetPossibleActionCount(typename inputType)
- {
- ActionInput action_input = m_RegistredInputsMap.Get(inputType);
- if (action_input)
- {
- return action_input.GetPossibleActionsCount();
- }
- return 0;
- }
- //--------------------------------------------------------
- // Alows to set different action to current contextual one
- //--------------------------------------------------------
- void InjectAction(ActionBase action, ActionTarget target, ItemBase item)
- {
- ActionInput ai = action.GetInput();
- ai.ForceAction(action, target, item);
- }
-
- void InjectAction(typename actionType, ActionTarget target, ItemBase item)
- {
- ActionBase action = GetAction(actionType);
- InjectAction(action, target, item);
- }
-
- void EjectAction(ActionBase action)
- {
- ActionInput ai = action.GetInput();
- ai.ClearForcedAction();
- }
-
- void EjectAction(typename actionType)
- {
- ActionBase action = GetAction(actionType);
- EjectAction(action);
- }
-
- void ForceTarget(Object targetObject)
- {
- Object parent = null;
- EntityAI targetEntity = EntityAI.Cast(targetObject);
- if (targetEntity)
- parent = targetEntity.GetHierarchyParent();
- m_ForceTarget = new ActionTarget(targetObject, parent, -1, vector.Zero, -1);
- }
-
- void ClearForceTarget()
- {
- m_ForceTarget = NULL;
- }
-
-
- //-------------------------------------------------------------------------
- override ActionTarget FindActionTarget()
- {
- if (m_ForceTarget)
- return m_ForceTarget;
-
- ActionTarget action_target;
- action_target = NULL;
- int targetsCount = m_Targets.GetTargetsCount();
- if (targetsCount)
- {
- for (int i = 0; i < targetsCount; ++i)
- {
- action_target = m_Targets.GetTarget(i);
- Object targetObject = action_target.GetObject();
- Object targetParent = action_target.GetParent();
-
- if (targetParent)
- {
- break;
- }
-
- if (targetObject)
- {
- break;
- }
- }
- }
- else
- {
- action_target = new ActionTarget(null, null, -1, vector.Zero, -1);
- }
- return action_target;
- }
-
- ItemBase FindActionItem()
- {
- ItemBase item;
- if (m_Player && m_Player.GetItemInHands() && m_Player.GetItemInHands().IsItemBase())
- {
- item = m_Player.GetItemInHands();
- }
- return item;
- }
-
- protected bool HasHandInventoryReservation()
- {
- m_HandInventoryLocationTest.SetHands(m_Player,m_Player.GetItemInHands());
- if (m_Player.GetHumanInventory().HasInventoryReservation(m_Player.GetItemInHands(),m_HandInventoryLocationTest))
- return true;
- return false;
- }
-
- protected void FindContextualUserActions(int pCurrentCommandID)
- {
- // TODO: NEEDS OPTIMIZATION (focus on UpdatePossibleActions > CraftingManager::OnUpdate)
-
- m_ActionsAvaibale = false;
- if (!m_ActionPossible || HasHandInventoryReservation() || GetGame().IsInventoryOpen())
- {
- ResetInputsActions();
- return;
- }
-
- if (!GetRunningAction())
- {
- ActionBase action;
- ActionTarget target;
- ItemBase item;
- // Gathering current inputs
- m_ActionsAvaibale = true;
-
- item = FindActionItem();
- target = FindActionTarget();
-
- int actionConditionMask = ActionBase.ComputeConditionMask(m_Player,target,item);
- for (int i = 0; i < m_OrederedAllActionInput.Count();i++)
- {
- ActionInput ain = m_OrederedAllActionInput[i];
- ain.UpdatePossibleActions(m_Player,target,item, actionConditionMask);
- }
- UpdateActionCategoryPriority();
- SetActionContext(target,item);
- }
- }
-
- //TOOD MW In progress
- protected bool LockInventory(ActionData action_data)
- {
- bool success = false;
- if (action_data.m_Action.IsInstant())
- {
- if (LogManager.IsActionLogEnable())
- {
- Debug.ActionLog("(-) Inventory lock - Not Used", action_data.m_Action.ToString() , "n/a", "LockInventory", action_data.m_Player.ToString());
- }
- success = true;
- }
- else
- {
- if (LogManager.IsActionLogEnable())
- {
- Debug.ActionLog("(X) Inventory lock", action_data.m_Action.ToString() , "n/a", "LockInventory", action_data.m_Player.ToString());
- }
- if (action_data.m_Action)
- {
- success = action_data.m_Action.InventoryReservation(action_data);
- }
- }
- return success;
- }
- void UnlockInventory(ActionData action_data)
- {
- if (LogManager.IsActionLogEnable())
- {
- Debug.ActionLog("(O) Inventory unlock", action_data.m_Action.ToString() , "n/a", "UnlockInventory", action_data.m_Player.ToString());
- }
- if (action_data.m_Action)
- action_data.m_Action.ClearInventoryReservationEx(action_data);
- }
-
- protected void ActionStart(ActionBase action, ActionTarget target, ItemBase item, Param extra_data = NULL)
- {
- if (!m_CurrentActionData && action && ActionPossibilityCheck(m_Player.GetCurrentCommandID()))
- {
- m_ActionWantEndRequest_Send = false;
- m_ActionInputWantEnd_Send = false;
- m_ActionWantEndRequest = false;
- m_ActionInputWantEnd = false;
-
- if (action.CanBePerformedFromQuickbar())
- m_Player.SetActionEndInput(action);
-
- HandleInputsOnActionStart(action);
- if (LogManager.IsActionLogEnable())
- {
- if ( target )
- {
- Debug.ActionLog("Item = " + item + ", " + target.DumpToString(), action.ToString() , "n/a", "ActionStart", m_Player.ToString());
- }
- else
- {
- Debug.ActionLog("Item = " + item + ", no target", action.ToString() , "n/a", "ActionStart", m_Player.ToString());
- }
- }
- m_Interrupted = false;
- if (GetGame().IsMultiplayer() && !action.IsLocal())
- {
- if (!ScriptInputUserData.CanStoreInputUserData())
- {
- DPrint("ScriptInputUserData already posted - ActionManagerClient");
-
- if (LogManager.IsActionLogEnable())
- {
- Debug.ActionLog("Cannot start because ScriptInputUserData is already used", action.ToString() , "n/a", "ActionStart", m_Player.ToString());
- }
- return;
- }
- }
-
- if (!action.SetupAction(m_Player, target, item, m_CurrentActionData, extra_data))
- {
- DPrint("Can not inicialize action" + action + " - ActionManagerClient");
- m_CurrentActionData = NULL;
- return;
- }
-
- if (LogManager.IsActionLogEnable())
- {
- Debug.ActionLog("Action data created wait to start", action.ToString() , "n/a", "ActionStart", m_Player.ToString());
- }
- if (GetGame().IsMultiplayer() && !action.IsLocal())
- {
- ScriptInputUserData ctx = new ScriptInputUserData;
- ctx.Write(INPUT_UDT_STANDARD_ACTION_START);
- ctx.Write(action.GetID());
- action.WriteToContext(ctx, m_CurrentActionData);
-
- if (action.UseAcknowledgment())
- {
- m_CurrentActionData.m_State = UA_AM_PENDING;
- m_PendingActionAcknowledgmentID = ++m_LastAcknowledgmentID;
-
- ctx.Write(m_PendingActionAcknowledgmentID);
- }
-
- ctx.Send();
-
- if (!action.UseAcknowledgment())
- {
- action.Start(m_CurrentActionData);
- if (action.IsInstant())
- OnActionEnd();
- }
- }
- else
- {
- action.Start(m_CurrentActionData);
- if (action.IsInstant())
- OnActionEnd();
- }
- }
- }
- void HandleInputsOnActionStart(ActionBase action)
- {
- for (int i = 0; i < m_OrederedAllActionInput.Count();i++)
- {
- ActionInput ain = m_OrederedAllActionInput[i];
- if (action.GetInput() == ain)
- {
- ain.OnActionStart();
- }
- else
- {
- ain.Reset();
- }
- }
- }
-
- void HandleInputsOnActionEnd()
- {
- ResetInputsState();
- }
-
- void ResetInputsState()
- {
- for (int i = 0; i < m_OrederedAllActionInput.Count();i++)
- {
- ActionInput ain = m_OrederedAllActionInput[i];
- ain.Reset();
- }
- }
-
- void ResetInputsActions()
- {
- for (int i = 0; i < m_OrederedAllActionInput.Count();i++)
- {
- ActionInput ain = m_OrederedAllActionInput[i];
- ain.ActionsSelectReset();
- }
- }
- 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);
- }
- }
- }
-
- //Instant Action (Debug Actions) ---------------------------------
- override void OnInstantAction(typename user_action_type, Param data = NULL)
- {
- ActionBase action = GetAction(user_action_type);
- if (action)
- {
- ActionStart(action,NULL,NULL, data);
- }
- }
-
- #ifdef BOT
- /// used for bots
- void PerformAction(int user_action_id, ActionTarget target, ItemBase item, Param extraData = NULL)
- {
- ActionStart(GetAction(user_action_id), target, item, extraData);
- }
- #endif
-
- void PerformActionStart(ActionBase action, ActionTarget target, ItemBase item, Param extra_data = NULL)
- {
- if (!GetGame().IsMultiplayer())
- {
- m_PendingActionData = new ActionData;
-
- if (!action.SetupAction(m_Player,target,item,m_PendingActionData,extra_data))
- m_PendingActionData = null;
- }
- else
- ActionStart(action, target, item, extra_data);
- }
-
- override void OnActionEnd()
- {
- if (m_CurrentActionData)
- {
- UnlockInventory(m_CurrentActionData);
- if (m_CurrentActionData.m_Action.RemoveForceTargetAfterUse())
- m_InventoryActionHandler.DeactiveAction();
-
- super.OnActionEnd();
- HandleInputsOnActionEnd();
- }
- }
- void SetInventoryAction(ActionBase action_name, ItemBase target_item, ItemBase main_item)
- {
- m_InventoryActionHandler.SetAction(action_name, target_item, main_item);
- }
- void SetInventoryAction(ActionBase action_name, ActionTarget target, ItemBase main_item)
- {
- m_InventoryActionHandler.SetAction(action_name, target, main_item);
- }
-
- void UnsetInventoryAction()
- {
- m_InventoryActionHandler.DeactiveAction();
- }
-
- override typename GetSelectedActionCategory()
- {
- return m_OrderedStandartActionInputs[m_SelectedActionInputToSrollIndex].Type();
- }
-
- void UpdateActionCategoryPriority()
- {
- int i;
- int last_target_index = 0;
- for (i = 0; i < m_DefaultOrderOfActionInputs.Count(); i++)
- {
- if (m_DefaultOrderOfActionInputs[i].HasTarget())
- {
- m_OrderedStandartActionInputs[last_target_index] = m_DefaultOrderOfActionInputs[i];
- last_target_index++;
- }
- }
-
- for (i = 0; i < m_DefaultOrderOfActionInputs.Count(); i++)
- {
- if (!m_DefaultOrderOfActionInputs[i].HasTarget())
- {
- m_OrderedStandartActionInputs[last_target_index] = m_DefaultOrderOfActionInputs[i];
- last_target_index++;
- }
- }
- }
-
- override void SelectFirstActionCategory()
- {
- UpdateActionCategoryPriority();
- m_SelectedActionInputToSrollIndex = 0;
-
- for (int index = 0; index < m_OrderedStandartActionInputs.Count(); index++)
- {
- if (m_OrderedStandartActionInputs[index].GetPossibleActionsCount() > 1)
- {
- m_SelectedActionInputToSrollIndex = index;
- break;
- }
- }
- }
-
- override void SelectNextActionCategory()
- {
- int index;
-
- for (index = m_SelectedActionInputToSrollIndex + 1; index != m_SelectedActionInputToSrollIndex;;)
- {
- if (++index >= m_OrderedStandartActionInputs.Count())
- {
- index = 0;
- }
- if (m_OrderedStandartActionInputs[index].GetPossibleActionsCount() > 1)
- {
- m_SelectedActionInputToSrollIndex = index;
- break;
- }
- }
- }
-
- override void SelectPrevActionCategory()
- {
- int index;
-
- for (index = m_SelectedActionInputToSrollIndex; index != m_SelectedActionInputToSrollIndex;;)
- {
- if (--index < 0)
- {
- index = m_OrderedStandartActionInputs.Count() - 1;
- }
-
- if (m_OrderedStandartActionInputs[index].GetPossibleActionsCount() > 1)
- {
- m_SelectedActionInputToSrollIndex = index;
- break;
- }
- }
- }
-
- override void SelectNextAction()
- {
- ActionInput ai;
- if (m_SelectedActionInputToSrollIndex < m_OrderedStandartActionInputs.Count())
- {
- ai = m_OrderedStandartActionInputs[m_SelectedActionInputToSrollIndex];
- if (ai && ai.GetPossibleActionsCount() > 1)
- {
- ai.SelectNextAction();
- }
- }
- }
-
- override void SelectPrevAction()
- {
- ActionInput ai;
- if (m_SelectedActionInputToSrollIndex < m_OrderedStandartActionInputs.Count())
- {
- ai = m_OrderedStandartActionInputs[m_SelectedActionInputToSrollIndex];
- if (ai && ai.GetPossibleActionsCount() > 1)
- {
- ai.SelectPrevAction();
- }
- }
- }
- bool CanPerformActionFromQuickbar(ItemBase mainItem, ItemBase targetItem)
- {
- ItemBase itemInHand = m_Player.GetItemInHands();
- ActionTarget target;
- target = new ActionTarget(targetItem, null, -1, vector.Zero, -1);
- bool hasTarget = targetItem != NULL;
-
- if (mainItem)
- {
- array<ActionBase_Basic> actions;
- ActionBase picked_action;
- int i;
-
- mainItem.GetActions(QuickaBarActionInput, actions);
- if (actions)
- {
- for (i = 0; i < actions.Count(); i++)
- {
- picked_action = ActionBase.Cast(actions[i]);
- if (picked_action && picked_action.Can(m_Player,target, itemInHand))
- {
- if (hasTarget == picked_action.HasTarget())
- return true;
- }
- }
- }
- //First check continuous actions
- mainItem.GetActions(ContinuousDefaultActionInput, actions);
- if (actions)
- {
- for (i = 0; i < actions.Count(); i++)
- {
- picked_action = ActionBase.Cast(actions[i]);
- if (picked_action && picked_action.Can(m_Player,target, itemInHand) && picked_action.CanBePerformedFromQuickbar())
- {
- if (hasTarget == picked_action.HasTarget())
- return true;
- }
- }
- }
- //second single use actions
- mainItem.GetActions(DefaultActionInput, actions);
- if (actions)
- {
- for (i = 0; i < actions.Count(); i++)
- {
- picked_action = ActionBase.Cast(actions[i]);
- if (picked_action && picked_action.HasTarget() && picked_action.Can(m_Player,target, itemInHand) && picked_action.CanBePerformedFromQuickbar())
- {
- if (hasTarget == picked_action.HasTarget())
- return true;
- }
- }
- }
- }
- return false;
- }
-
- void PerformActionFromQuickbar(ItemBase mainItem, ItemBase targetItem)
- {
- ItemBase itemInHand = m_Player.GetItemInHands();
- ActionTarget target;
- ItemBase parent = null;
- if (targetItem)
- parent = ItemBase.Cast(targetItem.GetHierarchyParent());
- target = new ActionTarget(targetItem, parent, -1, vector.Zero, -1);
- bool hasTarget = targetItem != NULL;
-
- if (mainItem)
- {
- ActionBase picked_action;
- array<ActionBase_Basic> actions;
- int i;
-
- mainItem.GetActions(QuickaBarActionInput, actions);
- if (actions)
- {
- for (i = 0; i < actions.Count(); i++)
- {
- picked_action = ActionBase.Cast(actions[i]);
- if (picked_action && picked_action.HasTarget() && picked_action.Can(m_Player,target, itemInHand))
- {
- if (hasTarget == picked_action.HasTarget())
- {
- ActionStart(picked_action, target, mainItem);
- return;
- }
- }
- }
- }
-
- //First continuous actions
- mainItem.GetActions(ContinuousDefaultActionInput, actions);
- if (actions)
- {
- for (i = 0; i < actions.Count(); i++)
- {
- picked_action = ActionBase.Cast(actions[i]);
- if (picked_action && picked_action.HasTarget() && picked_action.Can(m_Player,target, itemInHand) && picked_action.CanBePerformedFromQuickbar())
- {
- if (hasTarget == picked_action.HasTarget())
- {
- ActionStart(picked_action, target, mainItem);
- return;
- }
- }
- }
- }
- //Second check single use actions
- mainItem.GetActions(DefaultActionInput, actions);
- if (actions)
- {
- for (i = 0; i < actions.Count(); i++)
- {
- picked_action = ActionBase.Cast(actions[i]);
- if (picked_action && picked_action.Can(m_Player,target, itemInHand) && picked_action.CanBePerformedFromQuickbar())
- {
- if (hasTarget == picked_action.HasTarget())
- {
- ActionStart(picked_action, target, mainItem);
- return;
- }
- }
- }
- }
- }
- }
-
- //TODO Variants support ???
- bool CanPerformActionFromInventory(ItemBase mainItem, ItemBase targetItem)
- {
- ItemBase itemInHand = m_Player.GetItemInHands();
- ActionTarget target;
- target = new ActionTarget(targetItem, null, -1, vector.Zero, -1);
- bool hasTarget = targetItem != NULL;
-
- if (mainItem)
- {
- array<ActionBase_Basic> actions;
- ActionBase picked_action;
- int i;
-
- //First check single use actions
- mainItem.GetActions(DefaultActionInput, actions);
- if (actions)
- {
- for (i = 0; i < actions.Count(); i++)
- {
- picked_action = ActionBase.Cast(actions[i]);
- if (picked_action && picked_action.Can(m_Player,target, itemInHand) && picked_action.CanBePerformedFromInventory())
- {
- if (hasTarget == picked_action.HasTarget())
- return true;
- }
- }
- }
-
- //Inventory specific actions
- mainItem.GetActions(InventoryOnlyActionInput, actions);
- if (actions)
- {
- for (i = 0; i < actions.Count(); i++)
- {
- picked_action = ActionBase.Cast(actions[i]);
- if (picked_action && picked_action.Can(m_Player,target, itemInHand))
- {
- if (hasTarget == picked_action.HasTarget())
- return true;
- }
- }
- }
- }
- return false;
- }
-
- //TODO Variants support ???
- void PerformActionFromInventory(ItemBase mainItem, ItemBase targetItem)
- {
- ItemBase itemInHand = m_Player.GetItemInHands();
- ActionTarget target;
- target = new ActionTarget(targetItem, null, -1, vector.Zero, -1);
- bool hasTarget = targetItem != NULL;
-
- if (mainItem)
- {
- ActionBase picked_action;
- array<ActionBase_Basic> actions;
- int i;
-
- //First check single use actions
- mainItem.GetActions(DefaultActionInput, actions);
- if (actions)
- {
- for (i = 0; i < actions.Count(); i++)
- {
- picked_action = ActionBase.Cast(actions[i]);
- if (picked_action && picked_action.Can(m_Player,target, itemInHand) && picked_action.CanBePerformedFromInventory())
- {
- if (hasTarget == picked_action.HasTarget())
- {
- ActionStart(picked_action, target, mainItem);
- return;
- }
- }
- }
- }
-
- //Inventory specific actions
- mainItem.GetActions(InventoryOnlyActionInput, actions);
- if (actions)
- {
- for (i = 0; i < actions.Count(); i++)
- {
- picked_action = ActionBase.Cast(actions[i]);
- if (picked_action && picked_action.Can(m_Player,target, itemInHand))
- {
- if (hasTarget == picked_action.HasTarget())
- {
- ActionStart(picked_action, target, mainItem);
- return;
- }
- }
- }
- }
- }
- }
-
- bool CanSetActionFromInventory(ItemBase mainItem, ItemBase targetItem)
- {
- ItemBase itemInHand = m_Player.GetItemInHands();
- ActionTarget target;
- EntityAI parent = null;
- if (targetItem)
- {
- parent = targetItem.GetHierarchyParent();
- }
- target = new ActionTarget(targetItem, parent, -1, vector.Zero, -1);
- bool hasTarget = targetItem != NULL;
-
- if (mainItem)
- {
- array<ActionBase_Basic> actions;
- array<ref ActionBase> variant_actions;
- ActionBase picked_action;
- int variants_count,v;
-
- //First check single use actions
- mainItem.GetActions(DefaultActionInput, actions);
- if (actions)
- {
- for (int i = 0; i < actions.Count(); i++)
- {
- picked_action = ActionBase.Cast(actions[i]);
- if (picked_action.HasVariants())
- {
- picked_action.UpdateVariants(itemInHand, targetItem, -1);
- picked_action.GetVariants(variant_actions);
- for (v = 0; v < variant_actions.Count(); v ++)
- {
- picked_action = variant_actions[v];
- if (picked_action && picked_action.CanBeSetFromInventory() && picked_action.Can(m_Player,target, itemInHand))
- {
- if (hasTarget == picked_action.HasTarget())
- return true;
- }
- }
- }
- else
- {
- if (picked_action && picked_action.CanBeSetFromInventory() && picked_action.Can(m_Player,target, itemInHand))
- {
- if (hasTarget == picked_action.HasTarget())
- return true;
- }
- }
- }
- }
- //second continuous actions
- mainItem.GetActions(ContinuousDefaultActionInput, actions);
- if (actions)
- {
- for (int j = 0; j < actions.Count(); j++)
- {
- picked_action = ActionBase.Cast(actions[j]);
- if (picked_action.HasVariants())
- {
- picked_action.UpdateVariants(itemInHand, targetItem, -1);
- picked_action.GetVariants(variant_actions);
- for (v = 0; v < variant_actions.Count(); v ++)
- {
- picked_action = variant_actions[v];
- if (picked_action && picked_action.HasTarget() && picked_action.CanBeSetFromInventory() && picked_action.Can(m_Player,target, itemInHand))
- {
- if (hasTarget == picked_action.HasTarget())
- return true;
- }
- }
- }
- else
- {
- if (picked_action && picked_action.HasTarget() && picked_action.CanBeSetFromInventory() && picked_action.Can(m_Player,target, itemInHand))
- {
- if (hasTarget == picked_action.HasTarget())
- return true;
- }
- }
- }
- }
- }
- return false;
- }
-
- //TODO fix for variants
- void SetActionFromInventory(ItemBase mainItem, ItemBase targetItem)
- {
- ItemBase itemInHand = m_Player.GetItemInHands();
- ActionTarget target;
- target = new ActionTarget(targetItem, null, -1, vector.Zero, -1);
- bool hasTarget = targetItem != NULL;
-
- if (mainItem)
- {
- array<ActionBase_Basic> actions;
- ActionBase picked_action;
-
- //First check single use actions
- mainItem.GetActions(DefaultActionInput, actions);
- if (actions)
- {
- for (int i = 0; i < actions.Count(); i++)
- {
- picked_action = ActionBase.Cast(actions[i]);
- if (picked_action && picked_action.Can(m_Player,target, itemInHand) && picked_action.CanBeSetFromInventory())
- {
- if (hasTarget == picked_action.HasTarget())
- {
- SetInventoryAction(picked_action, target, itemInHand);
- return;
- }
- }
- }
- }
- //second continuous actions
- mainItem.GetActions(ContinuousDefaultActionInput, actions);
- if (actions)
- {
- for (int j = 0; j < actions.Count(); j++)
- {
- picked_action = ActionBase.Cast(actions[j]);
- if (picked_action && picked_action.HasTarget() && picked_action.Can(m_Player,target, itemInHand) && picked_action.CanBeSetFromInventory())
- {
- if (hasTarget == picked_action.HasTarget())
- {
- SetInventoryAction(picked_action, target, itemInHand);
- return;
- }
- }
- }
- }
- }
- }
-
- // disables automatic end of continuous action when input ended
- void SetIgnoreAutomaticInputEnd(bool state)
- {
- m_IgnoreAutoInputEnd = state;
- }
- //! client requests action interrupt
- override void RequestInterruptAction()
- {
- if (ScriptInputUserData.CanStoreInputUserData())
- {
- ScriptInputUserData ctx = new ScriptInputUserData;
- ctx.Write(INPUT_UDT_STANDARD_ACTION_END_REQUEST);
- ctx.Write(DayZPlayerConstants.CMD_ACTIONINT_INTERRUPT);
- ctx.Send();
- }
- }
-
- private ref ActionTarget m_ForceTarget;
- private ref ActionTargets m_Targets;
- };
|