actioncreateindooroven.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. class ActionCreateIndoorOven: ActionSingleUseBase
  2. {
  3. void ActionCreateIndoorOven()
  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. Object obj = GetGame().CreateObjectEx( "OvenIndoor", action_data.m_Player.GetLastFirePoint(), ECE_PLACE_ON_SURFACE );
  57. int m_FirePointIndex = action_data.m_Player.GetLastFirePointIndex();
  58. float m_FireplaceRot = action_data.m_Player.GetLastFirePointRot();
  59. vector smoke_point_pos = action_data.m_Target.GetObject().GetSelectionPositionMS( OvenIndoor.OVENPOINT_SMOKE_POSITION + m_FirePointIndex.ToString() );
  60. vector smoke_point_pos_world = action_data.m_Target.GetObject().ModelToWorld( smoke_point_pos );
  61. vector m_SmokePosition = smoke_point_pos_world;
  62. OvenIndoor fp_indoor = OvenIndoor.Cast( obj );
  63. if ( fp_indoor )
  64. {
  65. fp_indoor.SetFirePointIndex( m_FirePointIndex );
  66. fp_indoor.SetSmokePointPosition( m_SmokePosition );
  67. vector fprot = vector.Zero;
  68. fprot[0] = m_FireplaceRot;
  69. fp_indoor.SetOrientation( fprot );
  70. fp_indoor.Synchronize();
  71. //move item to target fireplace
  72. if (!GetGame().IsMultiplayer())
  73. {
  74. ClearInventoryReservationEx(action_data);
  75. action_data.m_Player.LocalTakeEntityToTargetAttachment(fp_indoor, action_data.m_MainItem);
  76. }
  77. else
  78. action_data.m_Player.ServerTakeEntityToTargetAttachment(fp_indoor, action_data.m_MainItem);
  79. }
  80. }
  81. override bool IsLockTargetOnUse()
  82. {
  83. return false;
  84. }
  85. }