actionfoldentitytoslot.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. class ActionFoldEntityToSlot : ActionSingleUseBase
  2. {
  3. int m_SlotID = InventorySlots.INVALID;
  4. override void CreateConditionComponents ()
  5. {
  6. m_ConditionItem = new CCINonRuined;
  7. m_ConditionTarget = new CCTNone;
  8. }
  9. override bool HasTarget () { return false; }
  10. override bool ActionCondition ( PlayerBase player, ActionTarget target, ItemBase item )
  11. {
  12. EntityAI att = player.GetInventory().FindAttachment(m_SlotID);
  13. if ( item && att == null )
  14. return true;
  15. return false;
  16. }
  17. override bool ActionConditionContinue ( ActionData action_data ) { return true; }
  18. override void OnExecuteClient ( ActionData action_data )
  19. {
  20. ClearInventoryReservationEx(action_data);
  21. }
  22. override void OnExecuteServer ( ActionData action_data )
  23. {
  24. if ( !GetGame().IsMultiplayer() )
  25. ClearInventoryReservationEx(action_data);
  26. ItemBase old_item = action_data.m_MainItem;
  27. if (old_item.ConfigIsExisting("ChangeIntoOnAttach"))
  28. {
  29. string slot_name = InventorySlots.GetSlotName(m_SlotID);
  30. string str = old_item.ChangeIntoOnAttach(slot_name);
  31. if (str != "")
  32. {
  33. FoldBandanaToSlotLambda lambda = new FoldBandanaToSlotLambda(action_data.m_MainItem, str, action_data.m_Player, m_SlotID);
  34. action_data.m_Player.ServerReplaceItemInHandsWithNewElsewhere(lambda);
  35. }
  36. }
  37. }
  38. };
  39. class FoldBandanaToSlotLambda : TurnItemIntoItemLambda
  40. {
  41. void FoldBandanaToSlotLambda (EntityAI old_item, string new_item_type, PlayerBase player, int slot)
  42. {
  43. InventoryLocation targetAtt = new InventoryLocation;
  44. targetAtt.SetAttachment(player, NULL, slot);
  45. OverrideNewLocation(targetAtt);
  46. }
  47. };