Dayz Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
Loading...
Searching...
No Matches
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;
7 m_SpecialtyWeight = UASoftSkillsWeight.PRECISE_LOW;
8 m_Text = "#place_object";
9 }
10
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 fireplaceInHands = FireplaceBase.Cast(action_data.m_MainItem);
66 Object targetObject = action_data.m_Target.GetObject();
67 BuildingWithFireplace buildingFireplace = BuildingWithFireplace.Cast(targetObject);
68
69 //replace fireplace with lambda
70 FireplaceToIndoorsLambda lambda = new FireplaceToIndoorsLambda(fireplaceInHands, buildingFireplace.GetFireplaceType(0), action_data.m_Player, action_data.m_Player.GetLastFirePoint(), action_data.m_Target.GetObject());
71 lambda.SetTransferParams(true, true, true);
72 action_data.m_Player.ServerReplaceItemInHandsWithNewElsewhere(lambda);
73 }
74
75 override bool IsLockTargetOnUse()
76 {
77 return false;
78 }
79}
80
81
83{
87
88 void FireplaceToIndoorsLambda( EntityAI old_item, string new_item_type, PlayerBase player, vector pos, Object target )
89 {
91 vector mtx[4];
93 mtx[3] = pos;
94 gnd.SetGround( NULL, mtx );
95 OverrideNewLocation( gnd );
96
97 //set fire point index and smoke point position in world
98 m_FirePointIndex = player.GetLastFirePointIndex();
99 m_FireplaceRot = player.GetLastFirePointRot();
100
101 vector smoke_point_pos = target.GetSelectionPositionMS( FireplaceIndoor.FIREPOINT_SMOKE_POSITION + m_FirePointIndex.ToString() );
102 vector smoke_point_pos_world = target.ModelToWorld( smoke_point_pos );
103 m_SmokePosition = smoke_point_pos_world;
104 }
105
106 override void CopyOldPropertiesToNew (notnull EntityAI old_item, EntityAI new_item)
107 {
108 super.CopyOldPropertiesToNew( old_item, new_item );
109
110 FireplaceIndoor fireplace_indoor = FireplaceIndoor.Cast( new_item );
111 if ( fireplace_indoor )
112 {
113 //set fire point index
114 fireplace_indoor.SetFirePointIndex( m_FirePointIndex );
115
116 //get fire and smoke position
117 fireplace_indoor.SetSmokePointPosition( m_SmokePosition );
118
119 vector fprot = vector.Zero;
120 fprot[0] = m_FireplaceRot;
121 fireplace_indoor.SetOrientation( fprot );
122
123 //synchronize
124 fireplace_indoor.Synchronize();
125 }
126 }
127};
ActionBase ActionData
Definition actionbase.c:30
ActionPlaceFireplaceIndoor m_FirePointIndex
vector m_SmokePosition
void FireplaceToIndoorsLambda(EntityAI old_item, string new_item_type, PlayerBase player, vector pos, Object target)
float m_FireplaceRot
class ActionTargets ActionTarget
string m_Text
Definition actionbase.c:64
bool IsInReach(PlayerBase player, ActionTarget target, float maxDistance=1.0)
ref CCIBase m_ConditionItem
Definition actionbase.c:70
float m_SpecialtyWeight
Definition actionbase.c:83
ref CCTBase m_ConditionTarget
Definition actionbase.c:71
int m_StanceMask
Definition actionbase.c:68
override void OnExecuteServer(ActionData action_data)
override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
string GetFireplaceType(int firePointIndex)
void SetSmokePointPosition(vector smoke_point_pos)
static int GetFirePointIndex(string action_selection)
static const string FIREPOINT_ACTION_SELECTION
void SetFirePointIndex(int fire_point_index)
static const string FIREPOINT_SMOKE_POSITION
static bool CanPlaceFireplaceInSelectedSpot(Object building, int fire_point_index, out vector fire_point_pos_world, out vector fire_point_rot_world)
static const string FIREPOINT_PLACE_ROT
InventoryLocation.
proto native void SetGround(EntityAI e, vector mat[4])
Definition enmath.c:7
const float DEFAULT
static proto native float Distance(vector v1, vector v2)
Returns the distance between tips of two 3D vectors.
proto float Normalize()
Normalizes vector.
static const vector Zero
Definition enconvert.c:123
static float Dot(vector v1, vector v2)
Returns Dot product of vector v1 and vector v2.
Definition enconvert.c:284
DayZPlayerConstants
defined in C++
Definition dayzplayer.c:602
static void MatrixIdentity4(out vector mat[4])
Creates identity matrix.
Definition enmath3d.c:256
static proto float Acos(float c)
Returns angle in radians from cosinus.
static const float RAD2DEG
Definition enmath.c:16
bool Contains(string sample)
Returns true if sample is substring of string.
Definition enstring.c:286
override void CopyOldPropertiesToNew(notnull EntityAI old_item, EntityAI new_item)