DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
ActionWorldCraft.c
Go to the documentation of this file.
1class WorldCraftActionReciveData : ActionReciveData
2{
4}
5class WorldCraftActionData : ActionData
6{
8}
9
11{
12 override void CreateActionComponent()
13 {
14 m_ActionData.m_ActionComponent = new CAContinuousCraft(UATimeSpent.DEFAULT_CRAFT); //default value can be set in recipes
15 }
16
17 /*override void OnFinish(bool pCanceled)
18 {
19 super.OnFinish(pCanceled);
20 if( !GetGame().IsDedicatedServer() )
21 {
22 PlayerBase player;
23 if( Class.CastTo(player, GetGame().GetPlayer()) )
24 {
25 if( player.GetCraftingManager().IsInventoryCraft() )
26 player.GetCraftingManager().CancelInventoryCraft();
27 }
28 }
29 }*/
30};
31
33{
34 private string m_ActionPrompt;
35
37 {
39 m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_CRAFTING;
40 m_FullBody = true;
41 m_StanceMask = DayZPlayerConstants.STANCEMASK_CROUCH;
42 }
43
45 {
46 ActionData action_data = new WorldCraftActionData;
47 return action_data;
48 }
49
51 {
54 }
55
56 override void OnActionInfoUpdate( PlayerBase player, ActionTarget target, ItemBase item )
57 {
58 PluginRecipesManager module_recipes_manager;
59 Class.CastTo(module_recipes_manager, GetPlugin(PluginRecipesManager) );
60 m_Text = module_recipes_manager.GetRecipeName( player.GetCraftingManager().GetRecipeID(m_VariantID) );
61 }
62
63 override string GetText()
64 {
65 PlayerBase player;
66 if( Class.CastTo(player, GetGame().GetPlayer()) )
67 {
68 PluginRecipesManager module_recipes_manager;
69 Class.CastTo(module_recipes_manager, GetPlugin(PluginRecipesManager) );
70 return module_recipes_manager.GetRecipeName( player.GetCraftingManager().GetRecipeID(m_VariantID) );
71 }
72
73 return "Default worldcraft text";
74 }
75
76 override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item )
77 {
78 //Client
79 if ( !GetGame().IsDedicatedServer() )
80 {
81 return true;
82 }
83 else //Server
84 {
85 if ( !target.GetObject() || !item )
86 return false;
87 }
88
89 return true;
90 }
91
92 override string GetSoundCategory(ActionData action_data)
93 {
94 WorldCraftActionData actionDataWorldCraft = WorldCraftActionData.Cast(action_data);
95
96 ItemBase target = ItemBase.Cast(actionDataWorldCraft.m_Target.GetObject());
97 ItemBase item = actionDataWorldCraft.m_MainItem;
98
99 PluginRecipesManager recipesManager = PluginRecipesManager.Cast(GetPlugin(PluginRecipesManager));
100
101 string soundCat = recipesManager.GetSoundCategory(actionDataWorldCraft.m_RecipeID,target, item);
102
103 return soundCat;
104 }
105
106 override bool SetupAction(PlayerBase player, ActionTarget target, ItemBase item, out ActionData action_data, Param extra_data = NULL )
107 {
108 if (super.SetupAction(player, target, item, action_data, extra_data ))
109 {
110 if (!GetGame().IsDedicatedServer())
111 {
112 WorldCraftActionData action_data_wc;
113 Class.CastTo(action_data_wc, action_data);
114 action_data_wc.m_RecipeID = player.GetCraftingManager().GetRecipeID(m_VariantID);
115 }
116 return true;
117 }
118 return false;
119 }
120
121 override void Start( ActionData action_data ) //Setup on start of action
122 {
123 super.Start(action_data);
124 if ( action_data.m_Player ) action_data.m_Player.TryHideItemInHands(true);
125 }
126
127 override void OnEndServer( ActionData action_data )
128 {
129 if ( action_data.m_Player ) action_data.m_Player.TryHideItemInHands(false);
130 }
131
132 override void OnEndClient( ActionData action_data )
133 {
134 if ( action_data.m_Player ) action_data.m_Player.TryHideItemInHands(false);
135 }
136
137 override void OnFinishProgressServer( ActionData action_data )
138 {
139 /*if (!GetGame().IsMultiplayer())
140 {
141 ActionManagerClient am = ActionManagerClient.Cast(action_data.m_Player.GetActionManager());
142 am.UnlockInventory(action_data);
143 }*/
144
145 WorldCraftActionData action_data_wc;
146 PluginRecipesManager module_recipes_manager;
147 ItemBase item2;
148
149 Class.CastTo(action_data_wc, action_data);
150 Class.CastTo(module_recipes_manager, GetPlugin(PluginRecipesManager) );
151 Class.CastTo(item2, action_data.m_Target.GetObject() );
152
153 if( action_data.m_MainItem && item2 )
154 {
155 module_recipes_manager.PerformRecipeServer( action_data_wc.m_RecipeID, action_data.m_MainItem, item2, action_data.m_Player );
156 }
157 }
158
159 override void OnFinishProgressClient( ActionData action_data )
160 {
161 /*ActionManagerClient am = ActionManagerClient.Cast(action_data.m_Player.GetActionManager());
162 am.UnlockInventory(action_data);*/
163 }
164
165 override void WriteToContext(ParamsWriteContext ctx, ActionData action_data)
166 {
167 super.WriteToContext(ctx, action_data);
168
169 WorldCraftActionData action_data_wc = WorldCraftActionData.Cast(action_data);
170
171 ctx.Write(action_data_wc.m_RecipeID);
172 }
173
174 override bool ReadFromContext(ParamsReadContext ctx, out ActionReciveData action_recive_data )
175 {
176 if (!action_recive_data)
177 {
178 action_recive_data = new WorldCraftActionReciveData;
179 }
180
181 super.ReadFromContext(ctx, action_recive_data);
182
183 int recipeID;
184 if (!ctx.Read(recipeID))
185 return false;
186
187 WorldCraftActionReciveData recive_data_wc = WorldCraftActionReciveData.Cast(action_recive_data);
188 recive_data_wc.m_RecipeID = recipeID;
189
190 return true;
191 }
192
193 override void HandleReciveData(ActionReciveData action_recive_data, ActionData action_data)
194 {
195
196 WorldCraftActionReciveData recive_data_wc = WorldCraftActionReciveData.Cast(action_recive_data);
197 WorldCraftActionData action_data_wc = WorldCraftActionData.Cast(action_data);
198
199 action_data_wc.m_MainItem = recive_data_wc.m_MainItem;
200 if (!action_recive_data.m_Target)
201 {
202 action_data.m_Target = new ActionTarget(NULL, NULL, -1, vector.Zero, 0);
203 }
204 else
205 {
206 action_data_wc.m_Target = recive_data_wc.m_Target;
207 }
208 action_data_wc.m_RecipeID = recive_data_wc.m_RecipeID;
209 }
210};
211
ref CCIBase m_ConditionItem
Definition ActionBase.c:55
ref CCTBase m_ConditionTarget
Definition ActionBase.c:56
protected int m_VariantID
Definition ActionBase.c:59
protected string m_Text
Definition ActionBase.c:49
protected bool m_FullBody
Definition ActionBase.c:52
protected int m_StanceMask
Definition ActionBase.c:53
class ActionTargets ActionTarget
WorldCraftActionReciveData m_RecipeID
PlayerBase GetPlayer()
PluginBase GetPlugin(typename plugin_type)
protected ActionData m_ActionData
ItemBase m_MainItem
Definition ActionBase.c:28
PlayerBase m_Player
Definition ActionBase.c:33
ref CABase m_ActionComponent
Definition ActionBase.c:30
ref ActionTarget m_Target
Definition ActionBase.c:32
override void CreateActionComponent()
override void OnFinishProgressServer(ActionData action_data)
override void OnActionInfoUpdate(PlayerBase player, ActionTarget target, ItemBase item)
override void OnEndServer(ActionData action_data)
override void Start(ActionData action_data)
override ActionData CreateActionData()
override void CreateConditionComponents()
override bool ReadFromContext(ParamsReadContext ctx, out ActionReciveData action_recive_data)
override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
override void OnFinishProgressClient(ActionData action_data)
override bool SetupAction(PlayerBase player, ActionTarget target, ItemBase item, out ActionData action_data, Param extra_data=NULL)
override void WriteToContext(ParamsWriteContext ctx, ActionData action_data)
override string GetSoundCategory(ActionData action_data)
override void OnEndClient(ActionData action_data)
override void HandleReciveData(ActionReciveData action_recive_data, ActionData action_data)
override string GetText()
private string m_ActionPrompt
Super root of all classes in Enforce script.
Definition EnScript.c:11
Base Param Class with no parameters. Used as general purpose parameter overloaded with Param1 to Para...
Definition param.c:12
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
proto bool Write(void value_out)
proto bool Read(void value_in)
const float DEFAULT
const float DEFAULT_CRAFT
static const vector Zero
Definition EnConvert.c:110
DayZPlayerConstants
defined in C++
Definition dayzplayer.c:602
proto native CGame GetGame()
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.