Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
actionworldcraft.c
Go to the documentation of this file.
1 class WorldCraftActionReciveData : ActionReciveData
2 {
3  int m_RecipeID;
4 }
5 class WorldCraftActionData : ActionData
6 {
7  int m_RecipeID;
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 
36  void ActionWorldCraft()
37  {
38  m_CallbackClass = ActionWorldCraftCB;
39  m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_CRAFTING;
40  m_FullBody = true;
41  m_StanceMask = DayZPlayerConstants.STANCEMASK_CROUCH;
42  }
43 
44  override ActionData CreateActionData()
45  {
46  ActionData action_data = new WorldCraftActionData;
47  return action_data;
48  }
49 
50  override void CreateConditionComponents()
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 
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
Param
Base Param Class with no parameters. Used as general purpose parameter overloaded with Param1 to Para...
Definition: param.c:11
m_RecipeID
WorldCraftActionReciveData m_RecipeID
CCINone
Definition: ccinone.c:1
CCTObject
Definition: cctobject.c:1
ActionWorldCraft
Definition: actionworldcraft.c:32
UAMaxDistances
Definition: actionconstants.c:104
GetPlugin
PluginBase GetPlugin(typename plugin_type)
Definition: pluginmanager.c:316
Serializer
Serialization general interface. Serializer API works with:
Definition: serializer.c:55
m_FullBody
protected bool m_FullBody
Definition: actionbase.c:52
PlayerBase
Definition: playerbaseclient.c:1
WorldCraftActionReciveData
Definition: actionworldcraft.c:1
vector
Definition: enconvert.c:105
CAContinuousCraft
Definition: cacontinuouscraft.c:1
ActionTarget
class ActionTargets ActionTarget
m_VariantID
protected int m_VariantID
Definition: actionbase.c:59
ActionData
Definition: actionbase.c:20
DayZPlayerConstants
DayZPlayerConstants
defined in C++
Definition: dayzplayer.c:601
UATimeSpent
Definition: actionconstants.c:26
ActionContinuousBaseCB
Definition: actioncontinuousbase.c:1
GetPlayer
protected void GetPlayer()
Definition: crosshairselector.c:127
m_Text
protected string m_Text
Definition: actionbase.c:49
ActionWorldCraftCB
Definition: actionworldcraft.c:10
m_ConditionItem
ref CCIBase m_ConditionItem
Definition: actionbase.c:55
ActionContinuousBase
Definition: actioncontinuousbase.c:132
m_ConditionTarget
ref CCTBase m_ConditionTarget
Definition: actionbase.c:56
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10
m_StanceMask
protected int m_StanceMask
Definition: actionbase.c:53