actioncreateindoorfireplace.c 3.8 KB

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