actionplaceovenindoor.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. class ActionPlaceOvenIndoor: ActionSingleUseBase
  2. {
  3. void ActionPlaceOvenIndoor()
  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( OvenIndoor.OVENPOINT_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 = OvenIndoor.GetFirePointIndex( action_selection );
  26. if ( OvenIndoor.CanPlaceFireplaceInSelectedSpot( building, fire_point_index, fire_point_pos_world, fire_point_rot_world ) )
  27. {
  28. float rot_deg = 0.0;
  29. if ( building.HasSelection( OvenIndoor.OVENPOINT_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 fireplace_in_hands = FireplaceBase.Cast( action_data.m_MainItem );
  57. //replace fireplace with lambda
  58. FireplaceToIndoorOvenLambda lambda = new FireplaceToIndoorOvenLambda( fireplace_in_hands, "OvenIndoor", action_data.m_Player, action_data.m_Player.GetLastFirePoint(), action_data.m_Target.GetObject() );
  59. lambda.SetTransferParams( true, true, true );
  60. action_data.m_Player.ServerReplaceItemInHandsWithNewElsewhere( lambda );
  61. }
  62. override bool IsLockTargetOnUse()
  63. {
  64. return false;
  65. }
  66. }
  67. class FireplaceToIndoorOvenLambda : TurnItemIntoItemLambda
  68. {
  69. int m_FirePointIndex;
  70. float m_FireplaceRot;
  71. vector m_SmokePosition;
  72. void FireplaceToIndoorOvenLambda( EntityAI old_item, string new_item_type, PlayerBase player, vector pos, Object target )
  73. {
  74. InventoryLocation gnd = new InventoryLocation;
  75. vector mtx[4];
  76. Math3D.MatrixIdentity4( mtx );
  77. mtx[3] = pos;
  78. gnd.SetGround( NULL, mtx );
  79. OverrideNewLocation( gnd );
  80. //set fire point index and smoke point position in world
  81. m_FirePointIndex = player.GetLastFirePointIndex();
  82. m_FireplaceRot = player.GetLastFirePointRot();
  83. vector smoke_point_pos = target.GetSelectionPositionMS( OvenIndoor.OVENPOINT_SMOKE_POSITION + m_FirePointIndex.ToString() );
  84. vector smoke_point_pos_world = target.ModelToWorld( smoke_point_pos );
  85. m_SmokePosition = smoke_point_pos_world;
  86. }
  87. override void CopyOldPropertiesToNew (notnull EntityAI old_item, EntityAI new_item)
  88. {
  89. super.CopyOldPropertiesToNew( old_item, new_item );
  90. OvenIndoor fireplace_indoor = OvenIndoor.Cast( new_item );
  91. if ( fireplace_indoor )
  92. {
  93. //set fire point index
  94. fireplace_indoor.SetFirePointIndex( m_FirePointIndex );
  95. // rotate fireplace
  96. vector fprot = vector.Zero;
  97. fprot[0] = m_FireplaceRot;
  98. fireplace_indoor.SetOrientation( fprot );
  99. Print(fireplace_indoor.GetOrientation());
  100. // smoke pos (chimney)
  101. fireplace_indoor.SetSmokePointPosition( m_SmokePosition );
  102. //synchronize
  103. fireplace_indoor.Synchronize();
  104. }
  105. }
  106. };