replaceitemwithnewlambda.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /**@class ReplaceItemWithNewLambda
  2. * @brief adds automatic QuickBar handling
  3. **/
  4. class ReplaceItemWithNewLambda : ReplaceItemWithNewLambdaBase
  5. {
  6. PlayerBase m_Player;
  7. int m_IndexQB;
  8. void ReplaceItemWithNewLambda(EntityAI old_item, string new_item_type, PlayerBase player)
  9. {
  10. m_Player = player;
  11. m_IndexQB = -1;
  12. if (m_Player)
  13. m_IndexQB = m_Player.FindQuickBarEntityIndex(old_item);
  14. }
  15. /**@fn CopyOldPropertiesToNew
  16. * @brief copy properties from old object to the created one
  17. *
  18. * @NOTE: This is supposed to be overriden in derived classes, like for example right now.
  19. **/
  20. override void CopyOldPropertiesToNew(notnull EntityAI old_item, EntityAI new_item)
  21. {
  22. super.CopyOldPropertiesToNew(old_item, new_item);
  23. if (m_Player && m_IndexQB != -1)
  24. {
  25. m_Player.SetQuickBarEntityShortcut(new_item, m_IndexQB, true);
  26. }
  27. }
  28. override void OnSuccess(EntityAI new_item)
  29. {
  30. super.OnSuccess(new_item);
  31. if (m_Player && m_IndexQB != -1)
  32. {
  33. m_Player.SetQuickBarEntityShortcut(new_item, m_IndexQB, true);
  34. }
  35. }
  36. };