154 {
156 {
157 PlayerBase controlledPlayer = PlayerBase.Cast(
g_Game.GetPlayer());
158 if (controlledPlayer.GetInventory().HasInventoryReservation(
m_Obj, null) || controlledPlayer.GetInventory().IsInventoryLocked() || controlledPlayer.IsItemsToDelete())
159 return;
160
161 ItemPreviewWidget targetIpw = ItemPreviewWidget.Cast(w.FindAnyWidget("Render"));
162 if (!targetIpw)
163 {
164 string name = w.GetName();
165 name.Replace(
"PanelWidget",
"Render");
166 targetIpw = ItemPreviewWidget.Cast(w.FindAnyWidget(
name));
167 }
168
169 if (!targetIpw)
170 targetIpw = ItemPreviewWidget.Cast(w);
171
173 if (targetIpw)
174 {
175 if (!targetEntity.GetInventory().CanRemoveEntity())
176 return;
177
179 {
180 if (controlledPlayer.GetHumanInventory().CanRemoveEntityInHands())
181 controlledPlayer.PredictiveMoveItemFromHandsToInventory();
182
184
185 return;
186 }
187
188 EntityAI entityInHands = controlledPlayer.GetEntityInHands();
189 EntityAI entityRootParent = targetEntity.GetHierarchyRoot();
190
191 if (controlledPlayer.GetInventory().HasEntityInInventory(targetEntity) && controlledPlayer.GetHumanInventory().CanAddEntityInHands(targetEntity))
192 {
193 controlledPlayer.PredictiveTakeEntityToHands(targetEntity);
194 }
195 else if (entityInHands && entityRootParent == controlledPlayer)
196 {
197 InventoryLocation targetItemLocation = new InventoryLocation();
198 InventoryLocation handsItemLocation = new InventoryLocation();
199 entityInHands.GetInventory().GetCurrentInventoryLocation(handsItemLocation);
200 int index = controlledPlayer.GetHumanInventory().FindUserReservedLocationIndex(entityInHands);
201 if (index >= 0)
202 controlledPlayer.GetHumanInventory().GetUserReservedLocation(index, targetItemLocation);
203
204 if (controlledPlayer.GetInventory().CanForceSwapEntitiesEx(targetEntity, targetItemLocation, entityInHands, handsItemLocation))
205 {
206 controlledPlayer.PredictiveForceSwapEntities(targetEntity, entityInHands, targetItemLocation);
207 }
208 else if (controlledPlayer.GetInventory().CanSwapEntitiesEx(targetEntity, entityInHands ))
209 {
210 controlledPlayer.PredictiveSwapEntities(targetEntity, entityInHands);
211 }
212 else
213 {
215 if (targetItemLocation.
IsValid() && controlledPlayer.GetInventory().LocationCanAddEntity(targetItemLocation))
216 SplitItemUtils.TakeOrSplitToInventoryLocation(controlledPlayer, targetItemLocation);
217 }
218 }
219 else
220 {
221 bool found = false;
222 if (targetEntity.GetInventory().CanRemoveEntity())
223 {
224 InventoryLocation i2 = new InventoryLocation();
226 if (found)
227 {
229 {
231 found = false;
232 }
233 }
234 }
235
236 if (found)
237 {
238 if (controlledPlayer.GetHumanInventory().CanAddEntityToInventory(targetEntity))
240 }
241 else
242 {
243 if (controlledPlayer.GetHumanInventory().CanAddEntityInHands(targetEntity))
244 controlledPlayer.PredictiveTakeEntityToHands(targetEntity);
245 }
246 }
247
249 }
250 }
251 }
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
FindInventoryLocationType
flags for searching locations in inventory
proto native bool IsValid()
verify current set inventory location
proto native EntityAI GetParent()
returns parent of current inventory location
proto native int GetType()
returns type of InventoryLocation