DayZ 1.24
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
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
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 return false;
43
44 // ze stringu compName dostat posledni cislo a to je index zebriku
45
46 //building.GetActionComponentNameList( action_data.m_Target.GetComponentIndex(), components );
47
48 string condCompName = string.Format("%1_con", compName);
49 vector pos = player.GetPosition();
50 //Print(w);
51 bool found = false;
54 float minDistanceSq = 100.0;
55
56 string dirCompName = string.Format("%1_con_dir", compName);
57
58 for (int i = 0; i < memSelection.Count(); i++)
59 {
61 {
62
63 for (int j = 0; j < memSelection[i].GetVertexCount(); j++)
64 {
65 ladderEnterPointGlobal = building.ModelToWorld(memSelection[i].GetVertexPosition(lod, j));
67 {
69 found = true;
70 break;
71 }
72 }
73 }
74 }
75
76 if (found)
77 {
78 for (int k = 0; k < memSelection.Count(); k++)
79 {
81 {
82 for (int l = 0; l < memSelection[k].GetVertexCount(); l++)
83 {
84 vector dirPoint = building.ModelToWorld(memSelection[k].GetVertexPosition(lod, l));
86 if (dst < minDistanceSq)
87 {
90 //HumanCommandLadder.DebugDrawLadder(building, HumanCommandLadder.DebugGetLadderIndex(compName));
91 //found = true;
92 }
93 }
94 }
95 }
96
97 pos = pos - ladderEnterPointGlobal;
99
100 float angle = Math.AbsFloat(pos.VectorToAngles()[0] - ladderDirPointGlobal.VectorToAngles()[0]);
101
102 if (angle < 90 || angle > 270)
103 return true;
104 }
105
106 return false;
107 }
108
110 {
111 super.Start(action_data);
112 Building b;
113 Class.CastTo(b, action_data.m_Target.GetObject());
114
115 if (b)
116 {
117 string compName = b.GetActionComponentName(action_data.m_Target.GetComponentIndex());
119
120 LOD geomLod = action_data.m_Target.GetObject().GetLODByName(GEOM_LOD_NAME);
121 string ladderType = "metal";
122
123 for (int i = 0; i < geomLod.GetPropertyCount(); ++i)
124 {
125 if (geomLod.GetPropertyName(i) == "laddertype")
126 {
127 ladderType = geomLod.GetPropertyValue(i);
128 break;
129 }
130 }
131
132 action_data.m_Player.SetClimbingLadderType(ladderType);
133 action_data.m_Player.StartCommand_Ladder(b, ladderIndex);
134 }
135
136
137 /* if( GetGame().IsServer() )
138 {
139 OnStartServer(action_data);
140 }
141 else
142 {
143 OnStartClient(action_data);
144 }*/
145 }
146
147 /* override void WriteToContext (ParamsWriteContext ctx,ActionTarget target)
148 {
149 ctx.Write(INPUT_UDT_STANDARD_ACTION);
150 ctx.Write(GetType());
151
152 PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
153 ActionManagerClient AM = ActionManagerClient.Cast( player.GetActionManager());
154 //ActionTarget target = AM.FindActionTarget();
155 Object targetObject = target.GetObject();
156 ctx.Write(targetObject);
157 Object targetParent = target.GetParent();
158 ctx.Write(targetParent);
159 int componentIndex = target.GetComponentIndex();
160 ctx.Write(componentIndex);
161 }
162
163 override void OnStartServer( ActionData action_data )
164 {
165 Print("psovis - server/single");
166
167 Building building;
168 if ( Class.CastTo(building, action_data.m_Target.GetObject()) )
169 {
170 ref array<Selection> memSelections = new array<Selection>();
171
172 // Get memory LOD from p3d and save all its selections
173 LOD lod = building.GetLODByName(MEM_LOD_NAME);
174 if(lod != NULL && lod.GetSelections(memSelections))
175 {
176 Print("Memory selections:");
177 for( int i =0; i < memSelections.Count(); i++ )
178 {
179 if (memSelections[i].GetVertexCount() > 0)
180 {
181 vector pos = memSelections[i].GetVertexPosition(lod, 0);
182 Print(memSelections[i].GetName());
183 Print(pos);
184 }
185 }
186 }
187 }
188 }*/
189
190 /*override void OnStartClient( ActionData action_data )
191 {
192 Print("psovis - client");
193 }*/
194
195 override bool IsInstant()
196 {
197 return true;
198 }
199
200 override bool UseAcknowledgment()
201 {
202 return false;
203 }
204
205 override bool CanBeUsedSwimming()
206 {
207 return true;
208 }
209};
string m_Text
Definition ActionBase.c:49
ref CCIBase m_ConditionItem
Definition ActionBase.c:55
ref CCTBase m_ConditionTarget
Definition ActionBase.c:56
int m_StanceMask
Definition ActionBase.c:53
override bool CanBeUsedSwimming()
override void CreateConditionComponents()
override void Start(ActionData action_data)
override bool IsInstant()
const string MEM_LOD_NAME
override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
const string GEOM_LOD_NAME
override bool UseAcknowledgment()
Super root of all classes in Enforce script.
Definition EnScript.c:11
proto static native bool DebugDrawLadder(Building pBuilding, int pLadderIndex)
debug draws any ladder
proto static native int DebugGetLadderIndex(string pComponentName)
LOD class.
Definition gameplay.c:203
static const string NAME_MEMORY
Definition gameplay.c:208
static const string NAME_GEOMETRY
Definition gameplay.c:205
Definition EnMath.c:7
const float LADDERS
static proto native float DistanceSq(vector v1, vector v2)
Returns the square distance between tips of two 3D vectors.
proto vector VectorToAngles()
Converts vector to spherical coordinates with radius = 1.
DayZPlayerConstants
defined in C++
Definition dayzplayer.c:597
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
static proto float AbsFloat(float f)
Returns absolute value.
proto native owned string GetName()