Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
actionunrestraintarget.c
Go to the documentation of this file.
2 {
3  const float DEFAULT_UNRESTRAIN_TIME = 2;
4 
5  override void CreateActionComponent()
6  {
7  float time = ObtainUnrestrainTime();
8 
9  if( time <=0 )
10  {
11  time = DEFAULT_UNRESTRAIN_TIME;
12  }
13 
14  if( m_ActionData.m_Player.IsQuickRestrain() )
15  {
17  }
18 
19  m_ActionData.m_ActionComponent = new CAContinuousTime(time);
20  }
21 
22  float ObtainUnrestrainTime()
23  {
24  PlayerBase target_player = PlayerBase.Cast(m_ActionData.m_Target.GetObject());
25  PlayerBase source_player = m_ActionData.m_Player;
26 
27  if (target_player.IsRestrained())
28  {
29  EntityAI item_in_hands_source = source_player.GetItemInHands();
30 
31  ItemBase item_in_hands_target = target_player.GetItemInHands();
32 
33  CachedObjectsArrays.ARRAY_STRING.Clear();
34  item_in_hands_target.ConfigGetTextArray( "CanBeUnrestrainedBy", CachedObjectsArrays.ARRAY_STRING );
35 
36  string item_in_hands_name = item_in_hands_source.GetType();
37 
38  for(int i = 0; i < CachedObjectsArrays.ARRAY_STRING.Count(); i++)
39  {
40  if((i % 2) == 0)
41  {
42  string class_name = CachedObjectsArrays.ARRAY_STRING.Get(i);
43  if( GetGame().IsKindOf(item_in_hands_name, class_name) )
44  {
45  float value = CachedObjectsArrays.ARRAY_STRING.Get(i+1).ToFloat();
46  return value;
47  }
48  }
49  }
50  }
51  return -1;
52  }
53 };
54 
56 {
58  {
59  m_CallbackClass = ActionUnrestrainTargetCB;
60  m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_UNRESTRAINTARGET;
61  m_FullBody = true;
62  m_StanceMask = DayZPlayerConstants.STANCEMASK_ERECT | DayZPlayerConstants.STANCEMASK_CROUCH;
64  m_Text = "#unrestrain";
65  }
66 
67  override void CreateConditionComponents()
68  {
69  m_ConditionTarget = new CCTMan(UAMaxDistances.DEFAULT, false);
71  }
72 
73  override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item )
74  {
75  PlayerBase other_player = PlayerBase.Cast(target.GetObject());
76  EntityAI item_in_hands_source = player.GetItemInHands();
77 
78  if( other_player.IsRestrained() )
79  {
80  //Print("is restrained");
81  EntityAI item_in_hands_target = other_player.GetItemInHands();
82 
83  CachedObjectsArrays.ARRAY_STRING.Clear();
84 
85  if( item_in_hands_target )
86  {
87  item_in_hands_target.ConfigGetTextArray( "CanBeUnrestrainedBy", CachedObjectsArrays.ARRAY_STRING );
88 
89  string item_in_hands_name = item_in_hands_source.GetType();
90 
91  for(int i = 0; i < CachedObjectsArrays.ARRAY_STRING.Count(); i++)
92  {
93  if((i % 2) == 0)
94  {
95  string class_name = CachedObjectsArrays.ARRAY_STRING.Get(i);
96  if( GetGame().IsKindOf(item_in_hands_name, class_name) )
97  {
98  return true;
99  }
100  }
101  }
102  }
103  }
104  return false;
105  }
106 
107  override void OnFinishProgressServer( ActionData action_data )
108  {
109  PlayerBase player_target = PlayerBase.Cast(action_data.m_Target.GetObject());
110  PlayerBase player_source = PlayerBase.Cast(action_data.m_Player);
111 
112  if (CanReceiveAction(action_data.m_Target) && player_target.IsRestrained())
113  {
114  EntityAI unrestraining_tool = action_data.m_MainItem;
115  EntityAI restraining_item = player_target.GetItemInHands();
116 
117  player_target.SetRestrained(false);
118 
119 
120  //Damage applied to tool
121  CachedObjectsArrays.ARRAY_STRING.Clear();
122 
123  restraining_item.ConfigGetTextArray( "CanBeUnrestrainedBy", CachedObjectsArrays.ARRAY_STRING );
124  restraining_item.ConfigGetFloatArray( "CanBeUnrestrainedByDMG", CachedObjectsArrays.ARRAY_FLOAT );
125 
126  string item_in_hands_name = unrestraining_tool.GetType();
127  float damageToTool = 0;
128 
129  for(int i = 0; i < CachedObjectsArrays.ARRAY_STRING.Count(); i++)
130  {
131  string class_name = CachedObjectsArrays.ARRAY_STRING.Get(i);
132  if( GetGame().IsKindOf(item_in_hands_name, class_name) )
133  {
134  damageToTool = CachedObjectsArrays.ARRAY_FLOAT.Get(i/2);
135  break;
136  }
137  }
138 
139  MiscGameplayFunctions.DealAbsoluteDmg(action_data.m_MainItem, damageToTool);
140  //---------------------------
141 
142  MiscGameplayFunctions.TransformRestrainItem(restraining_item, unrestraining_tool, player_source, player_target);
143 
144  action_data.m_Player.GetSoftSkillsManager().AddSpecialty( m_SpecialtyWeight );
145  }
146  }
147 };
148 
149 class ReplaceAndDestroyLambda : TurnItemIntoItemLambdaAnimSysNotifyLambda
150 {
151  PlayerBase m_TargetPlayer;
152  bool m_Destroy;
153  bool m_Drop;
154 
155  void ReplaceAndDestroyLambda(EntityAI old_item, string new_item_type, PlayerBase player, bool destroy = false)
156  {
157  m_TargetPlayer = player;
158  m_Destroy = destroy;
159  m_OldItem = old_item;
160  }
161 
162  override void OnSuccess(EntityAI new_item)
163  {
164  super.OnSuccess(new_item);
165 
166  if ( m_Destroy )
167  {
168  new_item.SetHealth("","",0);
169  }
170  }
171 };
172 
174 {
175  void ReplaceAndDestroyLambdaEx(EntityAI old_item, string new_item_type, PlayerBase player, bool destroy = false, bool enableDrop = true)
176  {
177  m_Drop = enableDrop;
178  }
179 
180  override protected EntityAI CreateNewEntity()
181  {
182  EntityAI newItem = super.CreateNewEntity();
183 
184  if (!newItem && m_Drop)
185  {
186  newItem = EntityAI.Cast(GetGame().CreateObjectEx(m_NewItemType, m_TargetPlayer.GetPosition(), ECE_PLACE_ON_SURFACE|ECE_LOCAL));
187  }
188 
189  return newItem;
190  }
191 };
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
ActionUnrestrainTarget
Definition: actionunrestraintarget.c:55
CAContinuousTime
Definition: cacontinuoustime.c:1
CCTMan
Definition: cctman.c:1
UASoftSkillsWeight
Definition: actionconstants.c:118
ECE_PLACE_ON_SURFACE
const int ECE_PLACE_ON_SURFACE
Definition: centraleconomy.c:37
UAMaxDistances
Definition: actionconstants.c:104
m_FullBody
protected bool m_FullBody
Definition: actionbase.c:52
PlayerBase
Definition: playerbaseclient.c:1
ActionTarget
class ActionTargets ActionTarget
ActionData
Definition: actionbase.c:20
DayZPlayerConstants
DayZPlayerConstants
defined in C++
Definition: dayzplayer.c:601
class_name
class OptionSelectorMultistate extends OptionSelector class_name
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
ActionUnrestrainTargetCB
Definition: actionunrestraintarget.c:1
ActionContinuousBase
Definition: actioncontinuousbase.c:132
ECE_LOCAL
const int ECE_LOCAL
Definition: centraleconomy.c:24
CCINonRuined
Definition: ccinonruined.c:1
m_ConditionTarget
ref CCTBase m_ConditionTarget
Definition: actionbase.c:56
ReplaceAndDestroyLambda
Definition: actionunrestraintarget.c:149
m_SpecialtyWeight
protected float m_SpecialtyWeight
Definition: actionbase.c:68
m_StanceMask
protected int m_StanceMask
Definition: actionbase.c:53
EntityAI
Definition: building.c:5
CachedObjectsArrays
Definition: utilityclasses.c:40
ReplaceAndDestroyLambdaEx
Definition: actionunrestraintarget.c:173
CanReceiveAction
bool CanReceiveAction(ActionTarget target)
Definition: actionbase.c:638