actionworldcraft.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. class WorldCraftActionReciveData : ActionReciveData
  2. {
  3. int m_RecipeID;
  4. }
  5. class WorldCraftActionData : ActionData
  6. {
  7. int m_RecipeID;
  8. int m_AnimationID;
  9. bool m_ShowItem;
  10. }
  11. class ActionWorldCraftCB : ActionContinuousBaseCB
  12. {
  13. override void CreateActionComponent()
  14. {
  15. m_ActionData.m_ActionComponent = new CAContinuousCraft(UATimeSpent.DEFAULT_CRAFT); //default value can be set in recipes
  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. class ActionWorldCraft: ActionContinuousBase
  32. {
  33. private string m_ActionPrompt;
  34. void ActionWorldCraft()
  35. {
  36. m_CallbackClass = ActionWorldCraftCB;
  37. m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_CRAFTING;
  38. m_FullBody = true;
  39. m_StanceMask = DayZPlayerConstants.STANCEMASK_CROUCH;
  40. }
  41. override ActionData CreateActionData()
  42. {
  43. ActionData action_data = new WorldCraftActionData;
  44. return action_data;
  45. }
  46. override void CreateConditionComponents()
  47. {
  48. m_ConditionItem = new CCINone;
  49. m_ConditionTarget = new CCTObject(UAMaxDistances.DEFAULT);
  50. }
  51. override void OnActionInfoUpdate( PlayerBase player, ActionTarget target, ItemBase item )
  52. {
  53. PluginRecipesManager module_recipes_manager;
  54. Class.CastTo(module_recipes_manager, GetPlugin(PluginRecipesManager) );
  55. m_Text = module_recipes_manager.GetRecipeName( player.GetCraftingManager().GetRecipeID(m_VariantID) );
  56. }
  57. override string GetText()
  58. {
  59. PlayerBase player;
  60. if( Class.CastTo(player, GetGame().GetPlayer()) )
  61. {
  62. PluginRecipesManager moduleRecipesManager;
  63. Class.CastTo(moduleRecipesManager, GetPlugin(PluginRecipesManager) );
  64. return moduleRecipesManager.GetRecipeName( player.GetCraftingManager().GetRecipeID(m_VariantID) );
  65. }
  66. return "Default worldcraft text";
  67. }
  68. override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item )
  69. {
  70. if (GetGame().IsServer())
  71. {
  72. if (!target.GetObject() || !item)
  73. return false;
  74. }
  75. return true;
  76. }
  77. override bool ActionConditionContinue(ActionData action_data)
  78. {
  79. if (GetGame().IsServer())
  80. {
  81. if (!action_data.m_Target.GetObject() || !action_data.m_MainItem)
  82. return false;
  83. PluginRecipesManager moduleRecipesManager;
  84. Class.CastTo(moduleRecipesManager, GetPlugin(PluginRecipesManager) );
  85. WorldCraftActionData action_data_wc = WorldCraftActionData.Cast(action_data);
  86. ItemBase item2;
  87. Class.CastTo(item2, action_data_wc.m_Target.GetObject());
  88. if(!moduleRecipesManager.IsRecipePossibleToPerform(action_data_wc.m_RecipeID, action_data.m_MainItem, item2, action_data.m_Player))
  89. {
  90. return false;
  91. }
  92. }
  93. return true;
  94. }
  95. override string GetSoundCategory(ActionData action_data)
  96. {
  97. WorldCraftActionData actionDataWorldCraft = WorldCraftActionData.Cast(action_data);
  98. ItemBase target = ItemBase.Cast(actionDataWorldCraft.m_Target.GetObject());
  99. ItemBase item = actionDataWorldCraft.m_MainItem;
  100. PluginRecipesManager recipesManager = PluginRecipesManager.Cast(GetPlugin(PluginRecipesManager));
  101. string soundCat = recipesManager.GetSoundCategory(actionDataWorldCraft.m_RecipeID,target, item);
  102. return soundCat;
  103. }
  104. override bool SetupAction(PlayerBase player, ActionTarget target, ItemBase item, out ActionData action_data, Param extra_data = NULL )
  105. {
  106. if (super.SetupAction(player, target, item, action_data, extra_data ))
  107. {
  108. WorldCraftActionData action_data_wc = WorldCraftActionData.Cast(action_data);
  109. if (!GetGame().IsDedicatedServer()) // server synchs the recipe id through HandleReceiveData before this
  110. action_data_wc.m_RecipeID = player.GetCraftingManager().GetRecipeID(m_VariantID);
  111. PluginRecipesManager moduleRecipesManager;
  112. Class.CastTo(moduleRecipesManager, GetPlugin(PluginRecipesManager));
  113. RecipeAnimationInfo recipeAnimationInfo = moduleRecipesManager.GetRecipeAnimationInfo(action_data_wc.m_RecipeID, player, action_data_wc.m_MainItem, ItemBase.Cast(action_data_wc.m_Target.GetObject()));
  114. action_data_wc.m_AnimationID = recipeAnimationInfo.m_AnimationUID;
  115. action_data_wc.m_ShowItem = recipeAnimationInfo.m_ItemVisible;
  116. m_CommandUID = action_data_wc.m_AnimationID;
  117. return true;
  118. }
  119. return false;
  120. }
  121. override void Start( ActionData action_data ) //Setup on start of action
  122. {
  123. super.Start(action_data);
  124. WorldCraftActionData action_data_wc = WorldCraftActionData.Cast(action_data);
  125. if ( action_data_wc.m_Player && !action_data_wc.m_ShowItem )
  126. action_data.m_Player.TryHideItemInHands(true);
  127. }
  128. override void OnEndServer( ActionData action_data )
  129. {
  130. if ( action_data.m_Player ) action_data.m_Player.TryHideItemInHands(false);
  131. super.OnEndServer(action_data);
  132. }
  133. override void OnEndClient( ActionData action_data )
  134. {
  135. if ( action_data.m_Player ) action_data.m_Player.TryHideItemInHands(false);
  136. }
  137. override void OnFinishProgressServer(ActionData action_data)
  138. {
  139. WorldCraftActionData action_data_wc;
  140. PluginRecipesManager module_recipes_manager;
  141. ItemBase item2;
  142. Class.CastTo(action_data_wc, action_data);
  143. Class.CastTo(module_recipes_manager, GetPlugin(PluginRecipesManager));
  144. Class.CastTo(item2, action_data.m_Target.GetObject());
  145. if (action_data.m_MainItem && item2)
  146. {
  147. if (GetGame().IsMultiplayer())
  148. ClearActionJuncture(action_data);
  149. else
  150. ClearInventoryReservationEx(action_data);
  151. module_recipes_manager.PerformRecipeServer(action_data_wc.m_RecipeID, action_data.m_MainItem, item2, action_data.m_Player);
  152. if (GetGame().IsMultiplayer())
  153. AddActionJuncture(action_data);
  154. else
  155. InventoryReservation(action_data);
  156. }
  157. }
  158. override void WriteToContext(ParamsWriteContext ctx, ActionData action_data)
  159. {
  160. super.WriteToContext(ctx, action_data);
  161. WorldCraftActionData action_data_wc = WorldCraftActionData.Cast(action_data);
  162. ctx.Write(action_data_wc.m_RecipeID);
  163. }
  164. override bool ReadFromContext(ParamsReadContext ctx, out ActionReciveData action_recive_data )
  165. {
  166. if (!action_recive_data)
  167. {
  168. action_recive_data = new WorldCraftActionReciveData;
  169. }
  170. super.ReadFromContext(ctx, action_recive_data);
  171. int recipeID;
  172. if (!ctx.Read(recipeID))
  173. return false;
  174. WorldCraftActionReciveData recive_data_wc = WorldCraftActionReciveData.Cast(action_recive_data);
  175. recive_data_wc.m_RecipeID = recipeID;
  176. return true;
  177. }
  178. override void HandleReciveData(ActionReciveData action_recive_data, ActionData action_data)
  179. {
  180. WorldCraftActionReciveData recive_data_wc = WorldCraftActionReciveData.Cast(action_recive_data);
  181. WorldCraftActionData action_data_wc = WorldCraftActionData.Cast(action_data);
  182. action_data_wc.m_MainItem = recive_data_wc.m_MainItem;
  183. if (!action_recive_data.m_Target)
  184. {
  185. action_data.m_Target = new ActionTarget(NULL, NULL, -1, vector.Zero, 0);
  186. }
  187. else
  188. {
  189. action_data_wc.m_Target = recive_data_wc.m_Target;
  190. }
  191. action_data_wc.m_RecipeID = recive_data_wc.m_RecipeID;
  192. }
  193. };