actionworldcraft.c 5.8 KB

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