actionattachpowersourcetopanel.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //!DEPRECATED
  2. class ActionAttachPowerSourceToPanel: ActionSingleUseBase
  3. {
  4. void ActionAttachPowerSourceToPanel()
  5. {
  6. m_Text = "#attach";
  7. }
  8. override void CreateConditionComponents()
  9. {
  10. m_ConditionItem = new CCINonRuined;
  11. m_ConditionTarget = new CCTNonRuined(UAMaxDistances.DEFAULT);
  12. }
  13. override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item )
  14. {
  15. EntityAI target_entity = EntityAI.Cast( target.GetObject() );
  16. if ( player && target_entity && item )
  17. {
  18. if ( target_entity.IsStaticTransmitter() && target_entity.GetInventory().AttachmentCount() == 0 ) //has any power source attachment attached
  19. {
  20. return true;
  21. }
  22. }
  23. return false;
  24. }
  25. protected void OnExecuteImpl( ActionData action_data )
  26. {
  27. EntityAI target_entity = EntityAI.Cast( action_data.m_Target.GetObject() );
  28. EntityAI item_entity = action_data.m_MainItem;
  29. //find inventory location for attachment
  30. InventoryLocation target_location = new InventoryLocation;
  31. if ( target_entity.GetInventory().FindFirstFreeLocationForNewEntity( item_entity.GetType(), FindInventoryLocationType.ATTACHMENT, target_location ) )
  32. {
  33. action_data.m_Player.PredictiveTakeEntityToTargetAttachmentEx( target_entity, item_entity, target_location.GetSlot() );
  34. }
  35. }
  36. override void OnExecuteClient( ActionData action_data )
  37. {
  38. ClearInventoryReservationEx(action_data);
  39. OnExecuteImpl(action_data);
  40. }
  41. override void OnExecuteServer( ActionData action_data )
  42. {
  43. if (GetGame().IsMultiplayer())
  44. return; // multiplayer handled on client side via OnExecuteClient
  45. else
  46. OnExecuteImpl(action_data); // single player
  47. }
  48. override void OnEndClient( ActionData action_data )
  49. {
  50. // Probably not needed since attaching is done server side.
  51. /*
  52. EntityAI target_entity = EntityAI.Cast( action_data.m_Target.GetObject() );
  53. EntityAI item_entity = EntityAI.Cast( action_data.m_MainItem );
  54. //find inventory location for attachment
  55. InventoryLocation target_location = new InventoryLocation;
  56. if( target_entity.GetInventory().FindFirstFreeLocationForNewEntity( item_entity.GetType(), FindInventoryLocationType.ATTACHMENT, target_location ) )
  57. {
  58. //target_entity.PredictiveTakeEntityToTargetAttachmentEx( target_entity, item_entity, target_location.GetSlot() );
  59. target_entity.LocalTakeEntityAsAttachmentEx( item_entity, target_location.GetSlot() );
  60. }
  61. */
  62. }
  63. }