Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
actionplacefireplaceindoor.c
Go to the documentation of this file.
2 {
4  {
5  m_CommandUID = DayZPlayerConstants.CMD_ACTIONMOD_OPENDOORFW;
6  m_StanceMask = DayZPlayerConstants.STANCEMASK_CROUCH | DayZPlayerConstants.STANCEMASK_ERECT;
8  m_Text = "#place_object";
9  }
10 
11  override void CreateConditionComponents()
12  {
15  }
16 
17  override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item )
18  {
19  if ( !target ) return false;
20 
21  Object target_object = target.GetObject();
22  string action_selection = target_object.GetActionComponentName( target.GetComponentIndex() );
23  BuildingWithFireplace building = BuildingWithFireplace.Cast( target_object );
24 
25  if ( target_object && building && action_selection.Contains( FireplaceIndoor.FIREPOINT_ACTION_SELECTION ) )
26  {
27  if ( !IsInReach(player, target, UAMaxDistances.DEFAULT) ) return false;
28 
29  vector fire_point_pos_world, fire_point_rot_world;
30  int fire_point_index = FireplaceIndoor.GetFirePointIndex( action_selection );
31  if ( FireplaceIndoor.CanPlaceFireplaceInSelectedSpot( building, fire_point_index, fire_point_pos_world, fire_point_rot_world ) )
32  {
33  float rot_deg = 0.0;
34  if ( building.HasSelection( FireplaceIndoor.FIREPOINT_PLACE_ROT + fire_point_index.ToString() ) )
35  {
36  vector diff = fire_point_rot_world - fire_point_pos_world;
37  diff[1] = 0.0;
38  diff.Normalize();
39  float dotp = vector.Dot( "0 0 1" , diff );
40  rot_deg = Math.Acos( dotp ) * Math.RAD2DEG;
41  if ( ( diff[0] < 0 ) && ( diff[2] < 0 ) )
42  rot_deg = 360.0 - rot_deg;
43  else if ( ( diff[0] < 0 ) && ( diff[2] > 0 ) )
44  rot_deg = 360.0 - rot_deg;
45 
46  //Debug.DrawArrow( fire_point_pos_world, fire_point_pos_world + diff );
47  }
48 
49  float fire_point_dist = vector.Distance( fire_point_pos_world, player.GetPosition() );
50  if ( fire_point_dist <= 2 )
51  {
52  player.SetLastFirePoint( fire_point_pos_world );
53  player.SetLastFirePointIndex( fire_point_index );
54  player.SetLastFirePointRot( rot_deg );
55  return true;
56  }
57  }
58  }
59 
60  return false;
61  }
62 
63  override void OnExecuteServer( ActionData action_data )
64  {
65  FireplaceBase fireplace_in_hands = FireplaceBase.Cast( action_data.m_MainItem );
66 
67  //replace fireplace with lambda
68  FireplaceToIndoorsLambda lambda = new FireplaceToIndoorsLambda( fireplace_in_hands, "FireplaceIndoor", action_data.m_Player, action_data.m_Player.GetLastFirePoint(), action_data.m_Target.GetObject() );
69  lambda.SetTransferParams( true, true, true );
70  action_data.m_Player.ServerReplaceItemInHandsWithNewElsewhere( lambda );
71 
72  //add to soft skills
73  action_data.m_Player.GetSoftSkillsManager().AddSpecialty( m_SpecialtyWeight );
74  }
75 }
76 
77 
79 {
80  int m_FirePointIndex;
83 
84  void FireplaceToIndoorsLambda( EntityAI old_item, string new_item_type, PlayerBase player, vector pos, Object target )
85  {
87  vector mtx[4];
88  Math3D.MatrixIdentity4( mtx );
89  mtx[3] = pos;
90  gnd.SetGround( NULL, mtx );
91  OverrideNewLocation( gnd );
92 
93  //set fire point index and smoke point position in world
94  m_FirePointIndex = player.GetLastFirePointIndex();
95  m_FireplaceRot = player.GetLastFirePointRot();
96 
97  vector smoke_point_pos = target.GetSelectionPositionMS( FireplaceIndoor.FIREPOINT_SMOKE_POSITION + m_FirePointIndex.ToString() );
98  vector smoke_point_pos_world = target.ModelToWorld( smoke_point_pos );
99  m_SmokePosition = smoke_point_pos_world;
100  }
101 
102  override void CopyOldPropertiesToNew (notnull EntityAI old_item, EntityAI new_item)
103  {
104  super.CopyOldPropertiesToNew( old_item, new_item );
105 
106  FireplaceIndoor fireplace_indoor = FireplaceIndoor.Cast( new_item );
107  if ( fireplace_indoor )
108  {
109  //set fire point index
110  fireplace_indoor.SetFirePointIndex( m_FirePointIndex );
111 
112  //get fire and smoke position
113  fireplace_indoor.SetSmokePointPosition( m_SmokePosition );
114 
115  vector fprot = vector.Zero;
116  fprot[0] = m_FireplaceRot;
117  fireplace_indoor.SetOrientation( fprot );
118 
119  //synchronize
120  fireplace_indoor.Synchronize();
121  }
122  }
123 };
ItemBase
Definition: inventoryitem.c:730
m_FireplaceRot
float m_FireplaceRot
Definition: actionplacefireplaceindoor.c:81
UASoftSkillsWeight
Definition: actionconstants.c:118
InventoryLocation
InventoryLocation.
Definition: inventorylocation.c:27
m_FirePointIndex
ActionPlaceFireplaceIndoor m_FirePointIndex
FireplaceBase
Definition: barrelholes_colorbase.c:1
BuildingWithFireplace
Definition: mil_barracks1.c:1
UAMaxDistances
Definition: actionconstants.c:104
FireplaceToIndoorsLambda
void FireplaceToIndoorsLambda(EntityAI old_item, string new_item_type, PlayerBase player, vector pos, Object target)
Definition: actionplacefireplaceindoor.c:84
PlayerBase
Definition: playerbaseclient.c:1
vector
Definition: enconvert.c:105
ActionTarget
class ActionTargets ActionTarget
ActionData
Definition: actionbase.c:20
DayZPlayerConstants
DayZPlayerConstants
defined in C++
Definition: dayzplayer.c:601
Object
Definition: objecttyped.c:1
CCTCursor
Definition: cctcursor.c:1
IsInReach
protected bool IsInReach(PlayerBase player, ActionTarget target, float maxDistance=1.0)
Definition: actionbase.c:928
m_SmokePosition
vector m_SmokePosition
Definition: actionplacefireplaceindoor.c:82
m_Text
protected string m_Text
Definition: actionbase.c:49
ActionSingleUseBase
Definition: actionsingleusebase.c:41
m_ConditionItem
ref CCIBase m_ConditionItem
Definition: actionbase.c:55
CCINonRuined
Definition: ccinonruined.c:1
Math
Definition: enmath.c:6
m_ConditionTarget
ref CCTBase m_ConditionTarget
Definition: actionbase.c:56
m_SpecialtyWeight
protected float m_SpecialtyWeight
Definition: actionbase.c:68
m_StanceMask
protected int m_StanceMask
Definition: actionbase.c:53
TurnItemIntoItemLambda
Definition: miscgameplayfunctions.c:91
EntityAI
Definition: building.c:5
ActionPlaceFireplaceIndoor
Definition: actionplacefireplaceindoor.c:1
Math3D
Definition: enmath3d.c:27
CopyOldPropertiesToNew
override void CopyOldPropertiesToNew(notnull EntityAI old_item, EntityAI new_item)
Definition: actionplacefireplaceindoor.c:102