actiondetachpowersourcefrompanel.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. class ActionDetachPowerSourceFromPanel: ActionInteractBase
  2. {
  3. void ActionDetachPowerSourceFromPanel()
  4. {
  5. m_Text = "#detach_power_source";
  6. }
  7. override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item )
  8. {
  9. Object target_object = target.GetObject();
  10. if ( player && target_object )
  11. {
  12. EntityAI target_entity = EntityAI.Cast( target.GetObject() );
  13. string selection = target_object.GetActionComponentName( target.GetComponentIndex() );
  14. if ( target_entity && target_entity.GetInventory() && target_entity.GetInventory().AttachmentCount() > 0 && selection == "power_source" ) //has any power source attachment attached
  15. {
  16. return true;
  17. }
  18. }
  19. return false;
  20. }
  21. override void OnExecuteClient( ActionData action_data )
  22. {
  23. Process(action_data);
  24. }
  25. override void OnExecuteServer( ActionData action_data )
  26. {
  27. Process(action_data);
  28. }
  29. void Process( ActionData action_data )
  30. {
  31. EntityAI target_entity = EntityAI.Cast( action_data.m_Target.GetObject() );
  32. EntityAI attachment;
  33. int attachments_count = target_entity.GetInventory().AttachmentCount();
  34. for ( int j = 0; j < attachments_count; j++ ) //find any attached power source
  35. {
  36. // @TODO: vezme prvni att?
  37. attachment = target_entity.GetInventory().GetAttachmentFromIndex( j );
  38. if ( attachment )
  39. break;
  40. }
  41. if ( attachment )
  42. {
  43. action_data.m_Player.PredictiveTakeEntityToHands(attachment );
  44. }
  45. }
  46. }