160 {
162 {
164 if (controlledPlayer.GetInventory().HasInventoryReservation(
m_Obj, null) || controlledPlayer.GetInventory().IsInventoryLocked() || controlledPlayer.IsItemsToDelete())
165 return;
166
167 ItemPreviewWidget targetIpw = ItemPreviewWidget.Cast(w.FindAnyWidget("Render"));
168 if (!targetIpw)
169 {
170 string name = w.GetName();
171 name.Replace(
"PanelWidget",
"Render");
172 targetIpw = ItemPreviewWidget.Cast(w.FindAnyWidget(
name));
173 }
174
175 if (!targetIpw)
176 targetIpw = ItemPreviewWidget.Cast(w);
177
179 if (targetIpw)
180 {
181 if (!targetEntity.GetInventory().CanRemoveEntity())
182 return;
183
185 {
186 if (controlledPlayer.GetHumanInventory().CanRemoveEntityInHands())
187 controlledPlayer.PredictiveMoveItemFromHandsToInventory();
188
190
191 return;
192 }
193
194 EntityAI entityInHands = controlledPlayer.GetHumanInventory().GetEntityInHands();
195 EntityAI entityRootParent = targetEntity.GetHierarchyRoot();
196
197 if (controlledPlayer.GetInventory().HasEntityInInventory(targetEntity) && controlledPlayer.GetHumanInventory().CanAddEntityInHands(targetEntity))
198 {
199 controlledPlayer.PredictiveTakeEntityToHands(targetEntity);
200 }
201 else if (entityInHands && entityRootParent == controlledPlayer)
202 {
203 InventoryLocation targetItemLocation = new InventoryLocation();
204 InventoryLocation handsItemLocation = new InventoryLocation();
205 entityInHands.GetInventory().GetCurrentInventoryLocation(handsItemLocation);
206 int index = controlledPlayer.GetHumanInventory().FindUserReservedLocationIndex(entityInHands);
207 if (index >= 0)
208 controlledPlayer.GetHumanInventory().GetUserReservedLocation(index, targetItemLocation);
209
210 if (controlledPlayer.GetInventory().CanForceSwapEntitiesEx(targetEntity, targetItemLocation, entityInHands, handsItemLocation))
211 {
212 controlledPlayer.PredictiveForceSwapEntities(targetEntity, entityInHands, targetItemLocation);
213 }
214 else if (controlledPlayer.GetInventory().CanSwapEntitiesEx(targetEntity, entityInHands ))
215 {
216 controlledPlayer.PredictiveSwapEntities(targetEntity, entityInHands);
217 }
218 else
219 {
221 if (targetItemLocation.
IsValid() && controlledPlayer.GetInventory().LocationCanAddEntity(targetItemLocation))
222 SplitItemUtils.TakeOrSplitToInventoryLocation(controlledPlayer, targetItemLocation);
223 }
224 }
225 else
226 {
227 bool found = false;
228 if (targetEntity.GetInventory().CanRemoveEntity())
229 {
230 InventoryLocation i2 = new InventoryLocation();
232 if (found)
233 {
235 {
237 found = false;
238 }
239 }
240 }
241
242 if (found)
243 {
244 if (controlledPlayer.GetHumanInventory().CanAddEntityToInventory(targetEntity))
246 }
247 else
248 {
249 if (controlledPlayer.GetHumanInventory().CanAddEntityInHands(targetEntity))
250 controlledPlayer.PredictiveTakeEntityToHands(targetEntity);
251 }
252 }
253
255 }
256 }
257 }
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
proto native CGame GetGame()