public void OnPointerClick(PointerEventData eventData)
        {
            KookehsDropItemMod.Logger.LogDebug("KDI: Pointer click, trying to send network message");
            var master = getMaster();

            if (!master.inventory.hasAuthority)
            {
                return;
            }

            var pickupIndex = getPickupIndex();
            var identity    = master.GetBody().gameObject.GetComponent <NetworkIdentity>();
            var pickupDef   = PickupCatalog.GetPickupDef(pickupIndex);

            if (pickupDef.itemIndex != ItemIndex.None)
            {
                if (!ItemTierCatalog.GetItemTierDef(pickupDef.itemTier).isDroppable)
                {
                    return;
                }
            }

            KookehsDropItemMod.Logger.LogDebug("KDI: Sending network message");

            DropItemMessage itemDropMessage = new DropItemMessage(identity.netId, pickupIndex);

            itemDropMessage.Send(NetworkDestination.Server);
        }
예제 #2
0
        public void OnPointerClick(PointerEventData eventData)
        {
            var inventory = GetInventory();

            if (!inventory.hasAuthority)
            {
                return;
            }

            if (!NetworkServer.active)
            {
                // Client, send command
                DropItemMessage itemDropMessage;
                if (EquipmentIcon)
                {
                    var equipmentIndex = inventory.GetEquipmentIndex();
                    itemDropMessage = new DropItemMessage(equipmentIndex);
                }
                else
                {
                    var itemIndex = GetItemIndex();
                    itemDropMessage = new DropItemMessage(itemIndex);
                }

                KookehsDropItemMod.DropItemCommand.Invoke(itemDropMessage);
            }
            else
            {
                // Server, execute command
                var characterBody = inventory.GetComponent <CharacterMaster>().GetBody();
                var charTransform = characterBody.GetFieldValue <Transform>("transform");

                var pickupIndex = EquipmentIcon
                                        ? new PickupIndex(inventory.GetEquipmentIndex())
                                        : new PickupIndex(GetItemIndex());

                DropItem(charTransform, inventory, pickupIndex);
                CreateNotification(characterBody, charTransform, pickupIndex);
            }
        }