actionplacefireplaceindoor.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. class ActionPlaceFireplaceIndoor: ActionSingleUseBase
  2. {
  3. void ActionPlaceFireplaceIndoor()
  4. {
  5. m_CommandUID = DayZPlayerConstants.CMD_ACTIONMOD_OPENDOORFW;
  6. m_StanceMask = DayZPlayerConstants.STANCEMASK_CROUCH | DayZPlayerConstants.STANCEMASK_ERECT;
  7. m_SpecialtyWeight = UASoftSkillsWeight.PRECISE_LOW;
  8. m_Text = "#place_object";
  9. }
  10. override void CreateConditionComponents()
  11. {
  12. m_ConditionItem = new CCINonRuined;
  13. m_ConditionTarget = new CCTCursor;
  14. }
  15. override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item )
  16. {
  17. if ( !target ) return false;
  18. Object target_object = target.GetObject();
  19. string action_selection = target_object.GetActionComponentName( target.GetComponentIndex() );
  20. BuildingWithFireplace building = BuildingWithFireplace.Cast( target_object );
  21. if ( target_object && building && action_selection.Contains( FireplaceIndoor.FIREPOINT_ACTION_SELECTION ) )
  22. {
  23. if ( !IsInReach(player, target, UAMaxDistances.DEFAULT) ) return false;
  24. vector fire_point_pos_world, fire_point_rot_world;
  25. int fire_point_index = FireplaceIndoor.GetFirePointIndex( action_selection );
  26. if ( FireplaceIndoor.CanPlaceFireplaceInSelectedSpot( building, fire_point_index, fire_point_pos_world, fire_point_rot_world ) )
  27. {
  28. float rot_deg = 0.0;
  29. if ( building.HasSelection( FireplaceIndoor.FIREPOINT_PLACE_ROT + fire_point_index.ToString() ) )
  30. {
  31. vector diff = fire_point_rot_world - fire_point_pos_world;
  32. diff[1] = 0.0;
  33. diff.Normalize();
  34. float dotp = vector.Dot( "0 0 1" , diff );
  35. rot_deg = Math.Acos( dotp ) * Math.RAD2DEG;
  36. if ( ( diff[0] < 0 ) && ( diff[2] < 0 ) )
  37. rot_deg = 360.0 - rot_deg;
  38. else if ( ( diff[0] < 0 ) && ( diff[2] > 0 ) )
  39. rot_deg = 360.0 - rot_deg;
  40. //Debug.DrawArrow( fire_point_pos_world, fire_point_pos_world + diff );
  41. }
  42. float fire_point_dist = vector.Distance( fire_point_pos_world, player.GetPosition() );
  43. if ( fire_point_dist <= 2 )
  44. {
  45. player.SetLastFirePoint( fire_point_pos_world );
  46. player.SetLastFirePointIndex( fire_point_index );
  47. player.SetLastFirePointRot( rot_deg );
  48. return true;
  49. }
  50. }
  51. }
  52. return false;
  53. }
  54. override void OnExecuteServer(ActionData action_data)
  55. {
  56. FireplaceBase fireplaceInHands = FireplaceBase.Cast(action_data.m_MainItem);
  57. Object targetObject = action_data.m_Target.GetObject();
  58. BuildingWithFireplace buildingFireplace = BuildingWithFireplace.Cast(targetObject);
  59. //replace fireplace with lambda
  60. FireplaceToIndoorsLambda lambda = new FireplaceToIndoorsLambda(fireplaceInHands, buildingFireplace.GetFireplaceType(0), action_data.m_Player, action_data.m_Player.GetLastFirePoint(), action_data.m_Target.GetObject());
  61. lambda.SetTransferParams(true, true, true);
  62. action_data.m_Player.ServerReplaceItemInHandsWithNewElsewhere(lambda);
  63. }
  64. override bool IsLockTargetOnUse()
  65. {
  66. return false;
  67. }
  68. }
  69. class FireplaceToIndoorsLambda : TurnItemIntoItemLambda
  70. {
  71. int m_FirePointIndex;
  72. float m_FireplaceRot;
  73. vector m_SmokePosition;
  74. void FireplaceToIndoorsLambda( EntityAI old_item, string new_item_type, PlayerBase player, vector pos, Object target )
  75. {
  76. InventoryLocation gnd = new InventoryLocation;
  77. vector mtx[4];
  78. Math3D.MatrixIdentity4( mtx );
  79. mtx[3] = pos;
  80. gnd.SetGround( NULL, mtx );
  81. OverrideNewLocation( gnd );
  82. //set fire point index and smoke point position in world
  83. m_FirePointIndex = player.GetLastFirePointIndex();
  84. m_FireplaceRot = player.GetLastFirePointRot();
  85. vector smoke_point_pos = target.GetSelectionPositionMS( FireplaceIndoor.FIREPOINT_SMOKE_POSITION + m_FirePointIndex.ToString() );
  86. vector smoke_point_pos_world = target.ModelToWorld( smoke_point_pos );
  87. m_SmokePosition = smoke_point_pos_world;
  88. }
  89. override void CopyOldPropertiesToNew (notnull EntityAI old_item, EntityAI new_item)
  90. {
  91. super.CopyOldPropertiesToNew( old_item, new_item );
  92. FireplaceIndoor fireplace_indoor = FireplaceIndoor.Cast( new_item );
  93. if ( fireplace_indoor )
  94. {
  95. //set fire point index
  96. fireplace_indoor.SetFirePointIndex( m_FirePointIndex );
  97. //get fire and smoke position
  98. fireplace_indoor.SetSmokePointPosition( m_SmokePosition );
  99. vector fprot = vector.Zero;
  100. fprot[0] = m_FireplaceRot;
  101. fireplace_indoor.SetOrientation( fprot );
  102. //synchronize
  103. fireplace_indoor.Synchronize();
  104. }
  105. }
  106. };