Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
actionenterladder.c
Go to the documentation of this file.
1 
3 {
4  private const string GEOM_LOD_NAME = LOD.NAME_GEOMETRY;
5  private const string MEM_LOD_NAME = LOD.NAME_MEMORY;
6 
7  void ActionEnterLadder()
8  {
9  m_StanceMask = DayZPlayerConstants.STANCEMASK_CROUCH | DayZPlayerConstants.STANCEMASK_ERECT;
10  m_Text = "#enter_ladder";
11  }
12 
13  override void CreateConditionComponents()
14  {
17  }
18 
19  override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item )
20  {
22  if (!target || !target.GetObject() || player.GetCommand_Ladder() || player.GetCommand_Fall() )
23  return false;
24 
25  Building building;
26  if (!Class.CastTo(building, target.GetObject()))
27  return false;
28 
29  // TODO: direction tests
30  // Get memory LOD from p3d and save all its selections
31  LOD lod = building.GetLODByName(MEM_LOD_NAME);
32  if(lod == NULL)
33  return false;
34 
35  array<Selection> memSelection = new array<Selection>();
36  if(!lod.GetSelections(memSelection))
37  return false;
38 
40  string compName = building.GetActionComponentName( target.GetComponentIndex() );
41  if( compName.Length() < 6 || compName.Substring(0,6) != "ladder" )
42  {
43  return false;
44  }
45 
46  // ze stringu compName dostat posledni cislo a to je index zebriku
47 
48  //building.GetActionComponentNameList( action_data.m_Target.GetComponentIndex(), components );
49 
50  string condCompName = string.Format("%1_con", compName);
51  vector pos = player.GetPosition();
52  //Print(w);
53  bool found = false;
54  vector ladderEnterPointGlobal;
55  vector ladderDirPointGlobal;
56  float minDistanceSq = 100.0;
57 
58  string dirCompName = string.Format("%1_con_dir", compName);
59 
60  for ( int i = 0; i < memSelection.Count(); i++ )
61  {
62  if ( memSelection[i].GetName() == condCompName )
63  {
64 
65  for( int j = 0; j < memSelection[i].GetVertexCount(); j++ )
66  {
67  ladderEnterPointGlobal = building.ModelToWorld( memSelection[i].GetVertexPosition(lod, j) );
68  if( vector.DistanceSq(ladderEnterPointGlobal,pos) < UAMaxDistances.LADDERS * UAMaxDistances.LADDERS)
69  {
70  HumanCommandLadder.DebugDrawLadder(building, HumanCommandLadder.DebugGetLadderIndex(compName));
71  found = true;
72  break;
73  }
74  }
75  }
76  }
77 
78  if (found)
79  {
80  for (int k = 0; k < memSelection.Count(); k++)
81  {
82  if( memSelection[k].GetName() == dirCompName )
83  {
84  for( int l = 0; l < memSelection[k].GetVertexCount(); l++ )
85  {
86  vector dirPoint = building.ModelToWorld( memSelection[k].GetVertexPosition(lod, l) );
87  float dst = vector.DistanceSq(ladderEnterPointGlobal,dirPoint);
88  if( dst < minDistanceSq)
89  {
90  minDistanceSq = dst;
91  ladderDirPointGlobal = dirPoint;
92  //HumanCommandLadder.DebugDrawLadder(building, HumanCommandLadder.DebugGetLadderIndex(compName));
93  //found = true;
94  }
95  }
96  }
97  }
98 
99  pos = pos - ladderEnterPointGlobal;
100  ladderDirPointGlobal = ladderDirPointGlobal - ladderEnterPointGlobal;
101 
102  float angle = Math.AbsFloat(pos.VectorToAngles()[0] - ladderDirPointGlobal.VectorToAngles()[0]);
103 
104  if ( angle < 90 || angle > 270)
105  {
106  return true;
107  }
108  }
109 
110  return false;
111  }
112 
113  override void Start( ActionData action_data )
114  {
115  super.Start( action_data );
116  Building b;
117  Class.CastTo(b, action_data.m_Target.GetObject());
118 
119  if (b)
120  {
121  string compName = b.GetActionComponentName( action_data.m_Target.GetComponentIndex() );
122  int ladderIndex = HumanCommandLadder.DebugGetLadderIndex(compName);
123 
124  LOD geomLod = action_data.m_Target.GetObject().GetLODByName(GEOM_LOD_NAME);
125  string ladderType = "metal";
126 
127  for (int i = 0; i < geomLod.GetPropertyCount(); ++i)
128  {
129  if (geomLod.GetPropertyName(i) == "laddertype")
130  {
131  ladderType = geomLod.GetPropertyValue(i);
132  break;
133  }
134  }
135 
136  action_data.m_Player.SetClimbingLadderType(ladderType);
137  action_data.m_Player.StartCommand_Ladder(b, ladderIndex );
138  }
139 
140 
141  /* if( GetGame().IsServer() )
142  {
143  OnStartServer(action_data);
144  }
145  else
146  {
147  OnStartClient(action_data);
148  }*/
149  }
150 
151 /* override void WriteToContext (ParamsWriteContext ctx,ActionTarget target)
152  {
153  ctx.Write(INPUT_UDT_STANDARD_ACTION);
154  ctx.Write(GetType());
155 
156  PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
157  ActionManagerClient AM = ActionManagerClient.Cast( player.GetActionManager());
158  //ActionTarget target = AM.FindActionTarget();
159  Object targetObject = target.GetObject();
160  ctx.Write(targetObject);
161  Object targetParent = target.GetParent();
162  ctx.Write(targetParent);
163  int componentIndex = target.GetComponentIndex();
164  ctx.Write(componentIndex);
165  }
166 
167  override void OnStartServer( ActionData action_data )
168  {
169  Print("psovis - server/single");
170 
171  Building building;
172  if ( Class.CastTo(building, action_data.m_Target.GetObject()) )
173  {
174  ref array<Selection> memSelections = new array<Selection>();
175 
176  // Get memory LOD from p3d and save all its selections
177  LOD lod = building.GetLODByName(MEM_LOD_NAME);
178  if(lod != NULL && lod.GetSelections(memSelections))
179  {
180  Print("Memory selections:");
181  for( int i =0; i < memSelections.Count(); i++ )
182  {
183  if (memSelections[i].GetVertexCount() > 0)
184  {
185  vector pos = memSelections[i].GetVertexPosition(lod, 0);
186  Print(memSelections[i].GetName());
187  Print(pos);
188  }
189  }
190  }
191  }
192  }*/
193 
194  /*override void OnStartClient( ActionData action_data )
195  {
196  Print("psovis - client");
197  }*/
198 
199  override bool IsInstant()
200  {
201  return true;
202  }
203 
204  override bool UseAcknowledgment()
205  {
206  return false;
207  }
208 
209  override bool CanBeUsedSwimming()
210  {
211  return true;
212  }
213 };
ItemBase
Definition: inventoryitem.c:730
GetName
proto native owned string GetName()
Definition: syncedvalue.c:117
CCINone
Definition: ccinone.c:1
LOD
LOD class.
Definition: gameplay.c:202
UAMaxDistances
Definition: actionconstants.c:104
ActionInteractBase
Definition: actioninteractbase.c:54
ActionEnterLadder
Definition: actionenterladder.c:2
PlayerBase
Definition: playerbaseclient.c:1
vector
Definition: enconvert.c:105
ActionTarget
class ActionTargets ActionTarget
ActionData
Definition: actionbase.c:20
DayZPlayerConstants
DayZPlayerConstants
defined in C++
Definition: dayzplayer.c:601
CCTCursor
Definition: cctcursor.c:1
array
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Definition: isboxcollidinggeometryproxyclasses.c:27
m_Text
protected string m_Text
Definition: actionbase.c:49
m_ConditionItem
ref CCIBase m_ConditionItem
Definition: actionbase.c:55
HumanCommandLadder
Definition: human.c:644
Math
Definition: enmath.c:6
m_ConditionTarget
ref CCTBase m_ConditionTarget
Definition: actionbase.c:56
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10
m_StanceMask
protected int m_StanceMask
Definition: actionbase.c:53