Example #1
0
        internal static bool HandleClientRequest(ZetDropRequest dropRequest)
        {
            if (!Enabled)
            {
                return(false);
            }

            CharacterBody body = dropRequest.Body;

            if (!body)
            {
                return(false);
            }

            Inventory inventory = body.inventory;

            if (!inventory)
            {
                return(false);
            }

            if (dropRequest.DropType == 2)
            {
                EquipmentIndex equipIndex = (EquipmentIndex)dropRequest.Index;

                if (!ValidDropRequest(equipIndex, false))
                {
                    return(false);
                }

                if (DropItem(body, inventory, equipIndex, dropRequest.Angle))
                {
                    return(true);
                }
            }
            else
            {
                bool scrap = dropRequest.DropType == 1;

                ItemIndex itemIndex = (ItemIndex)dropRequest.Index;

                if (!ValidDropRequest(itemIndex, scrap))
                {
                    return(false);
                }

                if (DropItem(body, inventory, itemIndex, dropRequest.Angle, scrap))
                {
                    return(true);
                }
            }

            return(false);
        }
Example #2
0
        internal static void HandlePointerClick(ZetDropHandler handler, PointerEventData eventData)
        {
            if (!Enabled)
            {
                return;
            }

            Inventory inventory = handler.GetInventory();

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

            CharacterMaster master = inventory.GetComponent <CharacterMaster>();

            if (!master)
            {
                return;
            }
            CharacterBody body = master.GetBody();

            if (!body)
            {
                return;
            }

            bool scrap = Input.GetKey(KeyCode.LeftAlt) && eventData.button == PointerEventData.InputButton.Right;

            float aimAngle = GetAimAngle(body);

            if (!NetworkServer.active)
            {
                // Client, send message
                ZetDropRequest dropMessage;

                if (handler.EquipmentIcon)
                {
                    EquipmentIndex equipIndex = inventory.GetEquipmentIndex();

                    if (!ValidDropRequest(equipIndex, scrap))
                    {
                        return;
                    }

                    dropMessage = new ZetDropRequest {
                        Body = body, DropType = 2, Index = (int)equipIndex, Angle = aimAngle
                    };
                }
                else
                {
                    ItemIndex itemIndex = handler.GetItemIndex();

                    if (!ValidDropRequest(itemIndex, scrap))
                    {
                        return;
                    }

                    dropMessage = new ZetDropRequest {
                        Body = body, DropType = scrap ? 1 : 0, Index = (int)itemIndex, Angle = aimAngle
                    };
                }

                // used to identify self when we recieve drop confirmation to display notification
                LocalBody = body;

                dropMessage.Send(NetworkDestination.Server);
            }
            else
            {
                // Server, execute action
                if (handler.EquipmentIcon)
                {
                    EquipmentIndex equipIndex = inventory.GetEquipmentIndex();

                    if (!ValidDropRequest(equipIndex, scrap))
                    {
                        return;
                    }

                    if (DropItem(body, inventory, equipIndex, aimAngle))
                    {
                        CreateNotification(body, equipIndex);
                    }
                }
                else
                {
                    ItemIndex itemIndex = handler.GetItemIndex();

                    if (!ValidDropRequest(itemIndex, scrap))
                    {
                        return;
                    }

                    if (DropItem(body, inventory, itemIndex, aimAngle, scrap))
                    {
                        CreateNotification(body, itemIndex, scrap);
                    }
                }
            }
        }