Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
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
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 IsLockTargetOnUse()
200 {
201 return false;
202 }
203
204 override bool IsInstant()
205 {
206 return true;
207
208 }
209
210 override bool CanBeUsedSwimming()
211 {
212 return true;
213 }
214};
int m_StanceMask
Definition actionbase.c:62
string m_Text
Definition actionbase.c:58
ref CCIBase m_ConditionItem
Definition actionbase.c:64
ref CCTBase m_ConditionTarget
Definition actionbase.c:65
Super root of all classes in Enforce script.
Definition enscript.c:11
LOD class.
Definition gameplay.c:204
Definition enmath.c:7
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
DayZPlayerConstants
defined in C++
Definition dayzplayer.c:602
void Start()
Plays all elements this effects consists of.
Definition effect.c:157