Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
actionrestraintarget.c
Go to the documentation of this file.
2 {
3  const float DEFAULT_RESTRAIN_TIME = 2;
4 
5  override void CreateActionComponent()
6  {
7  float time = DEFAULT_RESTRAIN_TIME;
8 
9  if ( m_ActionData.m_MainItem.ConfigIsExisting("RestrainTime") )
10  {
11  time = m_ActionData.m_MainItem.ConfigGetFloat("RestrainTime");
12  }
13 
14  if ( m_ActionData.m_Player.IsQuickRestrain() )
15  {
17  }
18 
19  m_ActionData.m_ActionComponent = new CAContinuousTime(time);
20  }
21 };
22 
24 {
26  {
27  m_CallbackClass = ActionRestrainTargetCB;
28  m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_RESTRAINTARGET;
29  m_FullBody = true;
30  m_StanceMask = DayZPlayerConstants.STANCEMASK_ERECT | DayZPlayerConstants.STANCEMASK_CROUCH;
32  m_Text = "#restrain";
33  }
34 
35  override void CreateConditionComponents()
36  {
39  }
40 
41  override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item )
42  {
43  PlayerBase other_player = PlayerBase.Cast(target.GetObject());
44  if (!other_player)
45  return false;
46  if ( player.GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER )
47  {
48  return other_player.CanBeRestrained();
49  }
50  else
51  {
52  return !other_player.IsRestrained();
53  }
54 
55  }
56 
57  override int GetStanceMask(PlayerBase player)
58  {
59  if ( player.IsPlayerInStance(DayZPlayerConstants.STANCEMASK_CROUCH | DayZPlayerConstants.STANCEMASK_PRONE))
60  return DayZPlayerConstants.STANCEMASK_CROUCH;
61  else
62  return DayZPlayerConstants.STANCEMASK_ERECT;
63  }
64 
65  override bool ActionConditionContinue(ActionData action_data)
66  {
67  PlayerBase target_player = PlayerBase.Cast(action_data.m_Target.GetObject());
68 
69  if ( GetGame().IsServer() && GetGame().IsMultiplayer() )
70  {
71  if ( target_player.IsSurrendered() || !target_player.CanBeRestrained() )
72  {
73  return false;
74  }
75  }
76  if ( GetGame().IsServer() )
77  {
78  ActionRestrainTargetCB callback = ActionRestrainTargetCB.Cast(action_data.m_Callback);
79 
80  if ( callback.GetActionComponentProgress() > 0.75 && !target_player.IsRestrainPrelocked() )
81  {
82  target_player.SetRestrainPrelocked(true);
83  }
84 
85  return !GetGame().GetMission().IsPlayerDisconnecting(target_player);
86 
87  }
88  return true;
89  }
90 
91  override void OnStartServer(ActionData action_data)
92  {
93  PlayerBase target_player = PlayerBase.Cast(action_data.m_Target.GetObject());
94  if ( target_player.IsSurrendered() )
95  {
96  SurrenderDataRestrain sdr = new SurrenderDataRestrain;
97  target_player.EndSurrenderRequest(sdr);
98  }
99  else if ( target_player.IsEmotePlaying() )
100  {
101  target_player.m_EmoteManager.ServerRequestEmoteCancel();
102  }
103 
104  target_player.SetRestrainStarted(true);
105  }
106 
107  override void OnEndServer(ActionData action_data)
108  {
109  PlayerBase target_player = PlayerBase.Cast(action_data.m_Target.GetObject());
110  if (target_player)
111  {
112  target_player.SetRestrainStarted(false);
113  target_player.SetRestrainPrelocked(false);
114  }
115  }
116 
117  override void OnFinishProgressServer( ActionData action_data )
118  {
119  PlayerBase target_player = PlayerBase.Cast(action_data.m_Target.GetObject());
120  PlayerBase source_player = PlayerBase.Cast(action_data.m_Player);
121 
122  if (CanReceiveAction(action_data.m_Target) && !target_player.IsRestrained())
123  {
124  EntityAI item_in_hands_target = target_player.GetHumanInventory().GetEntityInHands();
125  EntityAI item_in_hands_source = source_player.GetHumanInventory().GetEntityInHands();
126 
127  if ( !item_in_hands_source )
128  {
129  Error("Restraining target failed, nothing in hands");
130  return;
131  }
132 
133  string new_item_name = MiscGameplayFunctions.ObtainRestrainItemTargetClassname(item_in_hands_source);
134  if (item_in_hands_target)
135  {
136  Print("Restraining player with item in hands, first drop & then restrain");
137 
138  ChainedDropAndRestrainLambda lambda2 = new ChainedDropAndRestrainLambda(item_in_hands_target, item_in_hands_target.GetType(), target_player, false, source_player);
139  MiscGameplayFunctions.TurnItemInHandsIntoItemEx(target_player, lambda2);
140  }
141  else
142  {
143  Print("Restraining player with empty hands");
144  RestrainTargetPlayerLambda lambda = new RestrainTargetPlayerLambda(item_in_hands_source, new_item_name, target_player);
145  source_player.LocalReplaceItemInHandsWithNewElsewhere(lambda);
146  }
147 
148  action_data.m_Player.GetSoftSkillsManager().AddSpecialty( m_SpecialtyWeight );
149  }
150  }
151 
152  override void OnFinishProgressClient( ActionData action_data )
153  {
154  super.OnFinishProgressClient( action_data );
155 
156  GetGame().GetAnalyticsClient().OnActionRestrain();
157  }
158 };
159 
161 {
162  PlayerBase m_SourcePlayer;
163  ExplosivesBase m_PairedExplosive;
164 
165  void ChainedDropAndRestrainLambda (EntityAI old_item, string new_item_type, PlayerBase player, bool destroy = false, PlayerBase src_player = null)
166  {
167  m_SourcePlayer = src_player;
168  }
169 
170  override void OnSuccess(EntityAI new_item)
171  {
172  super.OnSuccess(new_item);
173 
174  if (m_PairedExplosive)
175  {
176  m_PairedExplosive.UnpairRemote();
177  ItemBase ib = ItemBase.Cast(new_item);
178  ib.PairWithDevice(m_PairedExplosive);
179  m_PairedExplosive.Arm();
180  }
181 
182  // as soon as previous op is finish, start another one
183  EntityAI item_in_hands_source = m_SourcePlayer.GetHumanInventory().GetEntityInHands();
184  if (item_in_hands_source)
185  {
186  string new_item_name = MiscGameplayFunctions.ObtainRestrainItemTargetClassname(item_in_hands_source);
187  RestrainTargetPlayerLambda lambda = new RestrainTargetPlayerLambda(item_in_hands_source, new_item_name, m_Player);
188  if (m_SourcePlayer)
189  m_SourcePlayer.LocalReplaceItemInHandsWithNewElsewhere(lambda);
190  else
191  Error("ChainedDropAndRestrainLambda: missing source player!");
192  }
193  else
194  {
195  Error("ChainedDropAndRestrainLambda: missing source item in hands!");
196  }
197  }
198 
199  override void CopyOldPropertiesToNew (notnull EntityAI old_item, EntityAI new_item)
200  {
201  super.CopyOldPropertiesToNew(old_item, new_item);
202  RemoteDetonatorTrigger trigger = RemoteDetonatorTrigger.Cast(old_item);
203  if (trigger)
204  m_PairedExplosive = ExplosivesBase.Cast(trigger.GetControlledDevice());
205  }
206 }
207 
208 
210 {
212 
213  void RestrainTargetPlayerLambda (EntityAI old_item, string new_item_type, PlayerBase player)
214  {
215  m_TargetPlayer = player;
216 
217  InventoryLocation targetHnd = new InventoryLocation;
218  targetHnd.SetHands(m_TargetPlayer, null);
219  OverrideNewLocation(targetHnd);
220  }
221 
222  override void OnSuccess(EntityAI new_item)
223  {
224  super.OnSuccess(new_item);
225 
226  m_TargetPlayer.SetRestrained(true);
227  m_TargetPlayer.OnItemInHandsChanged();
228  }
229 };
230 
231 class SurrenderDataRestrain extends SurrenderData
232 {
233  override void End()
234  {
235 
236  }
237 }
ItemBase
Definition: inventoryitem.c:730
End
void End()
called on surrender end request end
GetGame
proto native CGame GetGame()
Error
void Error(string err)
Messagebox with error message.
Definition: endebug.c:90
CAContinuousTime
Definition: cacontinuoustime.c:1
ActionRestrainTargetCB
Definition: actionrestraintarget.c:1
DestroyItemInCorpsesHandsAndCreateNewOnGndLambda
Definition: miscgameplayfunctions.c:1681
CCTMan
Definition: cctman.c:1
UASoftSkillsWeight
Definition: actionconstants.c:118
ActionRestrainTarget
Definition: actionrestraintarget.c:23
Print
proto void Print(void var)
Prints content of variable to console/log.
InventoryLocation
InventoryLocation.
Definition: inventorylocation.c:27
OnSuccess
override void OnSuccess(EntityAI new_item)
Definition: actionrestraintarget.c:222
UAMaxDistances
Definition: actionconstants.c:104
m_FullBody
protected bool m_FullBody
Definition: actionbase.c:52
ExplosivesBase
void ExplosivesBase()
Definition: explosivesbase.c:40
SurrenderData
Definition: emotemanager.c:1146
PlayerBase
Definition: playerbaseclient.c:1
ActionTarget
class ActionTargets ActionTarget
ActionData
Definition: actionbase.c:20
DayZPlayerConstants
DayZPlayerConstants
defined in C++
Definition: dayzplayer.c:601
m_Player
DayZPlayer m_Player
Definition: hand_events.c:42
RestrainTargetPlayerLambda
void RestrainTargetPlayerLambda(EntityAI old_item, string new_item_type, PlayerBase player)
Definition: actionrestraintarget.c:213
RemoteDetonatorTrigger
Definition: remotedetonator.c:46
ActionContinuousBaseCB
Definition: actioncontinuousbase.c:1
m_TargetPlayer
ChainedDropAndRestrainLambda m_TargetPlayer
DEBUG_QUICK_UNRESTRAIN_TIME
const float DEBUG_QUICK_UNRESTRAIN_TIME
Definition: constants.c:599
m_Text
protected string m_Text
Definition: actionbase.c:49
m_ConditionItem
ref CCIBase m_ConditionItem
Definition: actionbase.c:55
ActionContinuousBase
Definition: actioncontinuousbase.c:132
CCINonRuined
Definition: ccinonruined.c:1
ChainedDropAndRestrainLambda
Definition: actionrestraintarget.c:160
m_ConditionTarget
ref CCTBase m_ConditionTarget
Definition: actionbase.c:56
m_SpecialtyWeight
protected float m_SpecialtyWeight
Definition: actionbase.c:68
m_StanceMask
protected int m_StanceMask
Definition: actionbase.c:53
TurnItemIntoItemLambda
Definition: miscgameplayfunctions.c:91
EntityAI
Definition: building.c:5
CanReceiveAction
bool CanReceiveAction(ActionTarget target)
Definition: actionbase.c:638
DayZPlayerInstanceType
DayZPlayerInstanceType
defined in C++
Definition: dayzplayer.c:1058