actiontakefireplacefrombarrel.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //!DEPRECATED
  2. class ActionTakeFireplaceFromBarrel: ActionInteractBase
  3. {
  4. void ActionTakeFireplaceFromBarrel()
  5. {
  6. m_CommandUID = DayZPlayerConstants.CMD_ACTIONMOD_PICKUP_HANDS;
  7. m_StanceMask = DayZPlayerConstants.STANCEMASK_CROUCH | DayZPlayerConstants.STANCEMASK_ERECT;
  8. m_Text = "#take_fireplace";
  9. }
  10. override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item )
  11. {
  12. Object target_object = target.GetObject();
  13. if ( target_object && target_object.IsFireplace() )
  14. {
  15. BarrelHoles_ColorBase fireplace_barrel = BarrelHoles_ColorBase.Cast( target_object );
  16. //check barrel fireplace state
  17. if ( fireplace_barrel && fireplace_barrel.IsOpen() && !fireplace_barrel.HasAshes() && !fireplace_barrel.IsBurning() )
  18. {
  19. //check cargo and attachments
  20. if ( fireplace_barrel.IsCargoEmpty() && fireplace_barrel.GetInventory().AttachmentCount() > 0 )
  21. {
  22. return true;
  23. }
  24. }
  25. }
  26. return false;
  27. }
  28. override void OnExecuteServer( ActionData action_data )
  29. {
  30. Object target_object = action_data.m_Target.GetObject();
  31. BarrelHoles_ColorBase fireplace_barrel = BarrelHoles_ColorBase.Cast( target_object );
  32. string newTypeName = "Fireplace";
  33. InventoryLocation targetIL = new InventoryLocation;
  34. bool found = action_data.m_Player.GetInventory().FindFirstFreeLocationForNewEntity( newTypeName, FindInventoryLocationType.ANY, targetIL );
  35. if ( found )
  36. {
  37. // allow action only if there is place in inventory
  38. auto lambda = TakeFireplaceFromBarrelLambda( fireplace_barrel, newTypeName, action_data.m_Player );
  39. lambda.OverrideNewLocation( targetIL );
  40. action_data.m_Player.ServerReplaceItemWithNew( lambda );
  41. }
  42. }
  43. }
  44. class TakeFireplaceFromBarrelLambda : ReplaceItemWithNewLambdaBase
  45. {
  46. PlayerBase m_Player;
  47. void TakeFireplaceFromBarrelLambda ( EntityAI old_item, string new_item_type, PlayerBase player )
  48. {
  49. m_Player = player;
  50. }
  51. override protected void RemoveOldItemFromLocation ()
  52. {
  53. // intentional no-operation
  54. m_RemoveFromLocationPassed = true; // but indicate the operation to be success
  55. }
  56. override protected void UndoRemoveOldItemFromLocation ()
  57. {
  58. // undo nothing
  59. }
  60. override void CopyOldPropertiesToNew( notnull EntityAI old_item, EntityAI new_item )
  61. {
  62. super.CopyOldPropertiesToNew( old_item, new_item );
  63. MiscGameplayFunctions.TransferInventory(old_item, new_item, m_Player);
  64. }
  65. override protected void DeleteOldEntity ()
  66. {
  67. // intentional no-operation
  68. }
  69. override protected void CreateNetworkObjectInfo (EntityAI new_item)
  70. {
  71. super.CreateNetworkObjectInfo(new_item);
  72. GetGame().RemoteObjectTreeCreate(m_OldItem); // re-create network for old item
  73. }
  74. }