public override void Interact(GameObject originator, Vector3 position, string hand) { if (originator.GetComponent <PlayerScript>().canNotInteract()) { return; } if (!isServer) { UISlotObject uiSlotObject = new UISlotObject(hand, gameObject); //PreCheck if (UIManager.CanPutItemToSlot(uiSlotObject)) { //Simulation gameObject.GetComponent <CustomNetTransform>().DisappearFromWorld(); // UIManager.UpdateSlot(uiSlotObject); //Client informs server of interaction attempt InteractMessage.Send(gameObject, hand); } } else { //Server actions if (!ValidatePickUp(originator, hand)) { //Rollback prediction (inform player about item's true state) GetComponent <CustomNetTransform>().NotifyPlayer(originator); } } }
/// <summary> /// rather direct method that doesn't check anything. /// probably should check if you CanPutItemToSlot before using it /// </summary> public static void UpdateSlot(UISlotObject slotInfo) { Logger.LogTraceFormat("Updating slots: {0}", Category.UI, slotInfo); // InputTrigger.Touch(slotInfo.SlotContents); InventorySlots[slotInfo.Slot].SetItem(slotInfo.SlotContents); ClearObjectIfNotInSlot(slotInfo); }
/// <summary> /// rather direct method that doesn't check anything. /// probably should check if you CanPutItemToSlot before using it /// </summary> public static void UpdateSlot(UISlotObject slotInfo) { if (string.IsNullOrEmpty(slotInfo.SlotUUID) && !string.IsNullOrEmpty(slotInfo.FromSlotUUID)) { //Dropping updates: var _fromSlot = InventorySlotCache.GetSlotByUUID(slotInfo.FromSlotUUID); if (_fromSlot != null) { CheckStorageHandlerOnMove(_fromSlot.Item); _fromSlot.Clear(); return; } } //Logger.LogTraceFormat("Updating slots: {0}", Category.UI, slotInfo); // InputTrigger.Touch(slotInfo.SlotContents); var slot = InventorySlotCache.GetSlotByUUID(slotInfo.SlotUUID); if (slot != null) { slot.SetItem(slotInfo.SlotContents); } var fromSlot = InventorySlotCache.GetSlotByUUID(slotInfo.FromSlotUUID); bool fromS = fromSlot != null; bool fromSI = fromSlot?.Item != null; if (fromSlot && (fromSlot.image.enabled || fromSlot?.Item == slotInfo.SlotContents)) { CheckStorageHandlerOnMove(fromSlot.Item); fromSlot.Clear(); } }
public override void Interact(GameObject originator, string hand) { if (originator.GetComponent <PlayerScript>().canNotInteract()) { return; } if (!isServer) { var uiSlotObject = new UISlotObject(hand, gameObject); //PreCheck if (UIManager.CanPutItemToSlot(uiSlotObject)) { //Simulation // UIManager.UpdateSlot(uiSlotObject); //Client informs server of interaction attempt InteractMessage.Send(gameObject, hand); } } else { //Server actions if (ValidatePickUp(originator, hand)) { GetComponent <RegisterTile>().RemoveTile(); } else { //Rollback prediction // originator.GetComponent<PlayerNetworkActions>().RollbackPrediction(hand); } } }
public override void Interact(GameObject originator, Vector3 position, string hand) { if (originator.GetComponent <PlayerScript>().canNotInteract()) { return; } if (!isServer) { UISlotObject uiSlotObject = new UISlotObject(hand, gameObject); //PreCheck if (UIManager.CanPutItemToSlot(uiSlotObject)) { //Simulation // UIManager.UpdateSlot(uiSlotObject); //Client informs server of interaction attempt InteractMessage.Send(gameObject, hand); } } else { //Server actions if (ValidatePickUp(originator, hand)) { GetComponent <RegisterItem>().Unregister(); } } }
/// <summary> /// use this for client UI mangling attepts /// </summary> public static bool TryUpdateSlot(UISlotObject slotInfo) { if (!CanPutItemToSlot(slotInfo)) { return(false); } InventoryInteractMessage.Send(slotInfo.SlotUUID, slotInfo.FromSlotUUID, slotInfo.SlotContents, true); return(true); }
public static string FindEmptySlotForItem(GameObject itemToPlace) { foreach (UI_ItemSlot slot in Instance.inventorySlotCache) { UISlotObject slottingAttempt = new UISlotObject(slot.eventName, itemToPlace); if (CanPutItemToSlot(slottingAttempt)) { return(slot.eventName); } } return(null); }
private static void ClearObjectIfNotInSlot(UISlotObject slotInfo) { for (int i = 0; i < InventorySlots.Length; i++) { if (InventorySlots[i].eventName.Equals(slotInfo.Slot) || !InventorySlots[i].Item) { continue; } if (InventorySlots[i].Item.Equals(slotInfo.SlotContents)) { InventorySlots[i].Clear(); } } }
public override bool Interact(GameObject originator, Vector3 position, string hand) { var player = originator.GetComponent <PlayerScript>(); if (player.canNotInteract()) { return(true); } if (!isServer) { UISlotObject uiSlotObject = new UISlotObject(InventoryManager.GetClientUUIDFromSlotName(hand), gameObject); //PreCheck if (UIManager.CanPutItemToSlot(uiSlotObject)) { if (player.IsInReach(this.gameObject)) { //Predictive disappear only if item is within normal range gameObject.GetComponent <CustomNetTransform>().DisappearFromWorld(); } //Client informs server of interaction attempt InteractMessage.Send(gameObject, hand); return(true); } return(true); } else { //Server actions if (!ValidatePickUp(originator, hand)) { //Rollback prediction (inform player about item's true state) GetComponent <CustomNetTransform>().NotifyPlayer(originator); } else { OnPickUpServer(originator.GetComponent <NetworkIdentity>().netId); } return(true); } return(true); }
public static bool CanPutItemToSlot(UISlotObject proposedSlotInfo) { if (proposedSlotInfo.IsEmpty() || !SendUpdateAllowed(proposedSlotInfo.SlotContents)) { return(false); } UI_ItemSlot uiItemSlot = InventorySlots[proposedSlotInfo.Slot]; PlayerScript lps = PlayerManager.LocalPlayerScript; if (!lps || lps.canNotInteract() || uiItemSlot == null || uiItemSlot.IsFull || !uiItemSlot.CheckItemFit(proposedSlotInfo.SlotContents)) { return(false); } return(true); }
public static bool CanPutItemToSlot(UISlotObject proposedSlotInfo) { if (proposedSlotInfo.IsEmpty() || !SendUpdateAllowed(proposedSlotInfo.SlotContents)) { return(false); } InventorySlot invSlot = InventoryManager.GetSlotFromUUID(proposedSlotInfo.SlotUUID, false); PlayerScript lps = PlayerManager.LocalPlayerScript; if (!lps || lps.canNotInteract() || invSlot.Item != null) { return(false); } UI_ItemSlot uiItemSlot = InventorySlotCache.GetSlotByUUID(invSlot.UUID); if (uiItemSlot == null) { //Could it be a storage obj that is closed? ItemSize checkMaxSizeOfStorage; if (SlotIsFromClosedBag(invSlot, out checkMaxSizeOfStorage)) { var itemAtts = proposedSlotInfo.SlotContents.GetComponent <ItemAttributes>(); if (itemAtts != null) { if (itemAtts.size <= checkMaxSizeOfStorage) { return(true); } } } return(false); } if (!uiItemSlot.CheckItemFit(proposedSlotInfo.SlotContents)) { return(false); } return(true); }
public static void UpdateSlot(UISlotObject slotInfo) { // Debug.LogFormat("Updating slots: {0}", slotInfo); InventorySlots[slotInfo.Slot].SetItem(slotInfo.SlotContents); }