actionenterladder.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. class ActionEnterLadder: ActionInteractBase
  2. {
  3. private const string GEOM_LOD_NAME = LOD.NAME_GEOMETRY;
  4. private const string MEM_LOD_NAME = LOD.NAME_MEMORY;
  5. void ActionEnterLadder()
  6. {
  7. m_StanceMask = DayZPlayerConstants.STANCEMASK_CROUCH | DayZPlayerConstants.STANCEMASK_ERECT;
  8. m_Text = "#enter_ladder";
  9. }
  10. override void CreateConditionComponents()
  11. {
  12. m_ConditionItem = new CCINone;
  13. m_ConditionTarget = new CCTCursor;
  14. }
  15. override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item )
  16. {
  17. //! is action_data.m_Target ? not on ladder and not falling ?
  18. if (!target || !target.GetObject() || player.GetCommand_Ladder() || player.GetCommand_Fall() )
  19. return false;
  20. Building building;
  21. if (!Class.CastTo(building, target.GetObject()))
  22. return false;
  23. // TODO: direction tests
  24. // Get memory LOD from p3d and save all its selections
  25. LOD lod = building.GetLODByName(MEM_LOD_NAME);
  26. if(lod == NULL)
  27. return false;
  28. array<Selection> memSelection = new array<Selection>();
  29. if(!lod.GetSelections(memSelection))
  30. return false;
  31. //!
  32. string compName = building.GetActionComponentName( target.GetComponentIndex() );
  33. if( compName.Length() < 6 || compName.Substring(0,6) != "ladder" )
  34. {
  35. return false;
  36. }
  37. // ze stringu compName dostat posledni cislo a to je index zebriku
  38. //building.GetActionComponentNameList( action_data.m_Target.GetComponentIndex(), components );
  39. string condCompName = string.Format("%1_con", compName);
  40. vector pos = player.GetPosition();
  41. //Print(w);
  42. bool found = false;
  43. vector ladderEnterPointGlobal;
  44. vector ladderDirPointGlobal;
  45. float minDistanceSq = 100.0;
  46. string dirCompName = string.Format("%1_con_dir", compName);
  47. for ( int i = 0; i < memSelection.Count(); i++ )
  48. {
  49. if ( memSelection[i].GetName() == condCompName )
  50. {
  51. for( int j = 0; j < memSelection[i].GetVertexCount(); j++ )
  52. {
  53. ladderEnterPointGlobal = building.ModelToWorld( memSelection[i].GetVertexPosition(lod, j) );
  54. if( vector.DistanceSq(ladderEnterPointGlobal,pos) < UAMaxDistances.LADDERS * UAMaxDistances.LADDERS)
  55. {
  56. HumanCommandLadder.DebugDrawLadder(building, HumanCommandLadder.DebugGetLadderIndex(compName));
  57. found = true;
  58. break;
  59. }
  60. }
  61. }
  62. }
  63. if (found)
  64. {
  65. for (int k = 0; k < memSelection.Count(); k++)
  66. {
  67. if( memSelection[k].GetName() == dirCompName )
  68. {
  69. for( int l = 0; l < memSelection[k].GetVertexCount(); l++ )
  70. {
  71. vector dirPoint = building.ModelToWorld( memSelection[k].GetVertexPosition(lod, l) );
  72. float dst = vector.DistanceSq(ladderEnterPointGlobal,dirPoint);
  73. if( dst < minDistanceSq)
  74. {
  75. minDistanceSq = dst;
  76. ladderDirPointGlobal = dirPoint;
  77. //HumanCommandLadder.DebugDrawLadder(building, HumanCommandLadder.DebugGetLadderIndex(compName));
  78. //found = true;
  79. }
  80. }
  81. }
  82. }
  83. pos = pos - ladderEnterPointGlobal;
  84. ladderDirPointGlobal = ladderDirPointGlobal - ladderEnterPointGlobal;
  85. float angle = Math.AbsFloat(pos.VectorToAngles()[0] - ladderDirPointGlobal.VectorToAngles()[0]);
  86. if ( angle < 90 || angle > 270)
  87. {
  88. return true;
  89. }
  90. }
  91. return false;
  92. }
  93. override void Start( ActionData action_data )
  94. {
  95. super.Start( action_data );
  96. Building b;
  97. Class.CastTo(b, action_data.m_Target.GetObject());
  98. if (b)
  99. {
  100. string compName = b.GetActionComponentName( action_data.m_Target.GetComponentIndex() );
  101. int ladderIndex = HumanCommandLadder.DebugGetLadderIndex(compName);
  102. LOD geomLod = action_data.m_Target.GetObject().GetLODByName(GEOM_LOD_NAME);
  103. string ladderType = "metal";
  104. for (int i = 0; i < geomLod.GetPropertyCount(); ++i)
  105. {
  106. if (geomLod.GetPropertyName(i) == "laddertype")
  107. {
  108. ladderType = geomLod.GetPropertyValue(i);
  109. break;
  110. }
  111. }
  112. action_data.m_Player.SetClimbingLadderType(ladderType);
  113. action_data.m_Player.StartCommand_Ladder(b, ladderIndex );
  114. }
  115. /* if( GetGame().IsServer() )
  116. {
  117. OnStartServer(action_data);
  118. }
  119. else
  120. {
  121. OnStartClient(action_data);
  122. }*/
  123. }
  124. /* override void WriteToContext (ParamsWriteContext ctx,ActionTarget target)
  125. {
  126. ctx.Write(INPUT_UDT_STANDARD_ACTION);
  127. ctx.Write(GetType());
  128. PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
  129. ActionManagerClient AM = ActionManagerClient.Cast( player.GetActionManager());
  130. //ActionTarget target = AM.FindActionTarget();
  131. Object targetObject = target.GetObject();
  132. ctx.Write(targetObject);
  133. Object targetParent = target.GetParent();
  134. ctx.Write(targetParent);
  135. int componentIndex = target.GetComponentIndex();
  136. ctx.Write(componentIndex);
  137. }
  138. override void OnStartServer( ActionData action_data )
  139. {
  140. Print("psovis - server/single");
  141. Building building;
  142. if ( Class.CastTo(building, action_data.m_Target.GetObject()) )
  143. {
  144. ref array<Selection> memSelections = new array<Selection>();
  145. // Get memory LOD from p3d and save all its selections
  146. LOD lod = building.GetLODByName(MEM_LOD_NAME);
  147. if(lod != NULL && lod.GetSelections(memSelections))
  148. {
  149. Print("Memory selections:");
  150. for( int i =0; i < memSelections.Count(); i++ )
  151. {
  152. if (memSelections[i].GetVertexCount() > 0)
  153. {
  154. vector pos = memSelections[i].GetVertexPosition(lod, 0);
  155. Print(memSelections[i].GetName());
  156. Print(pos);
  157. }
  158. }
  159. }
  160. }
  161. }*/
  162. /*override void OnStartClient( ActionData action_data )
  163. {
  164. Print("psovis - client");
  165. }*/
  166. override bool IsLockTargetOnUse()
  167. {
  168. return false;
  169. }
  170. override bool IsInstant()
  171. {
  172. return true;
  173. }
  174. override bool CanBeUsedSwimming()
  175. {
  176. return true;
  177. }
  178. };