Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
actionremoveseed.c
Go to the documentation of this file.
2 {
3  SeedBase m_Seed;
4 
5  void ActionRemoveSeed()
6  {
7  m_Text = "#take";
8  }
9 
10  override typename GetInputType()
11  {
13  }
14 
15  override void CreateConditionComponents()
16  {
19  }
20 
21  override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item )
22  {
23  if ( player.GetCommand_Vehicle() )
24  return false;
25 
26  GardenBase garden_base;
27  if ( Class.CastTo( garden_base, target.GetObject() ) )
28  {
29  Slot slot;
30 
31  array<string> selections = new array<string>;
32  garden_base.GetActionComponentNameList( target.GetComponentIndex(), selections );
33  string selection;
34 
35  for (int s = 0; s < selections.Count(); s++)
36  {
37  selection = selections[s];
38  slot = garden_base.GetSlotBySelection( selection );
39  if ( slot )
40  break;
41  }
42 
43  //Can only remove seed if slot is not watered to prevent VME
44  if ( slot && slot.GetSeed() )
45  {
46  if ( slot.GetWateredState() != 0 )
47  return false;
48 
49  m_Seed = SeedBase.Cast( slot.GetSeed() );
50 
51  if ( m_Seed )
52  {
53  if ( player.GetInventory().CanAddEntityIntoInventory( m_Seed ) && m_Seed.GetHierarchyRootPlayer() != player )
54  return true;
55  else
56  return player.GetInventory().CanAddEntityIntoHands( m_Seed );
57  }
58  }
59  }
60  return false;
61  }
62 
63  override bool InventoryReservation(ActionData action_data)
64  {
65  bool success = true;
66 
68 
69  if ( m_Seed )
70  {
71  action_data.m_Player.GetInventory().FindFreeLocationFor( m_Seed , FindInventoryLocationType.ANY, il );
72  if ( action_data.m_Player.GetInventory().HasInventoryReservation( m_Seed, il ) )
73  {
74  success = false;
75  }
76  else
77  {
78  action_data.m_Player.GetInventory().AddInventoryReservationEx( m_Seed, il, GameInventory.c_InventoryReservationTimeoutMS );
79  }
80  }
81 
82  if ( success )
83  {
84  if ( il )
85  action_data.m_ReservedInventoryLocations.Insert( il );
86  }
87 
88  return success;
89  }
90 
91  override void OnExecute( ActionData action_data )
92  {
93  if ( GetGame().IsMultiplayer() && GetGame().IsServer() )
94  return;
95 
96  PlayerBase player = action_data.m_Player;
97  float stackable;
99 
100  //We place in inventory
101  if ( !player.GetInventory().CanAddEntityIntoHands( m_Seed ) )
102  {
103  il = action_data.m_ReservedInventoryLocations.Get( 0 );
104  InventoryLocation targetInventoryLocation = new InventoryLocation;
105  m_Seed.GetInventory().GetCurrentInventoryLocation( targetInventoryLocation );
106 
107  stackable = m_Seed.GetTargetQuantityMax( il.GetSlot() );
108 
109  if ( stackable == 0 || stackable >= m_Seed.GetQuantity() )
110  {
111  player.PredictiveTakeToDst( targetInventoryLocation, il );
112  }
113  else
114  {
115  m_Seed.SplitIntoStackMaxToInventoryLocationClient( il );
116  }
117  }
118  else
119  {
120  //We place in hands
121  ClearInventoryReservationEx( action_data );
122 
123  stackable = m_Seed.GetTargetQuantityMax( -1 );
124 
125  if ( stackable == 0 || stackable >= m_Seed.GetQuantity() )
126  {
127  action_data.m_Player.PredictiveTakeEntityToHands( m_Seed );
128  }
129  else
130  {
131  il = new InventoryLocation;
132  il.SetHands( action_data.m_Player, m_Seed );
133  m_Seed.SplitIntoStackMaxToInventoryLocationClient( il );
134  }
135  }
136  }
137 };
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
ContinuousInteractActionInput
Definition: actioninput.c:521
CCINone
Definition: ccinone.c:1
InventoryLocation
InventoryLocation.
Definition: inventorylocation.c:27
ActionRemoveSeed
Definition: actionremoveseed.c:1
UAMaxDistances
Definition: actionconstants.c:104
ClearInventoryReservationEx
void ClearInventoryReservationEx(ActionData action_data)
Definition: actionbase.c:862
ActionInteractBase
Definition: actioninteractbase.c:54
PlayerBase
Definition: playerbaseclient.c:1
ActionTarget
class ActionTargets ActionTarget
ActionData
Definition: actionbase.c:20
SeedBase
Definition: cultivation.c:52
CCTCursor
Definition: cctcursor.c:1
FindInventoryLocationType
FindInventoryLocationType
flags for searching locations in inventory
Definition: inventorylocation.c:15
array< string >
m_Text
protected string m_Text
Definition: actionbase.c:49
m_ConditionItem
ref CCIBase m_ConditionItem
Definition: actionbase.c:55
m_ConditionTarget
ref CCTBase m_ConditionTarget
Definition: actionbase.c:56
GardenBase
Definition: gardenplot.c:1
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10
GameInventory
script counterpart to engine's class Inventory
Definition: inventory.c:78