Exemplo n.º 1
0
    public void OnEndDrag(PointerEventData eventData)
    {
        // canvas blocks raycasts again.
        canvasGroup.blocksRaycasts = true;

        // if its current parent is its original parent or the HUD, move it back to its original slot.
        if (transform.parent == originalParent || transform.parent == transform.root)
        {
            transform.position = originalPosition;
            transform.SetParent(originalParent);
        }
        else
        {
            // if outside its original position and inside an empty slot, remove it from its original slot.
            if (inventorySlot != null && !aSwapped)
            {
                inventorySlot.RemoveItem();
                inventorySlot.isTaken = false;
                Inventory.instance.Remove(inventorySlot.item);
            }
            else if (storageSlot != null && !aSwapped)
            {
                storageSlot.RemoveItem();
                storageSlot.isTaken = false;
                Storage.instance.Remove(storageSlot.item);
            }
        }

        // reset static variables for next item drag;
        draggedItem   = null;
        draggedItemGO = null;
        inventorySlot = null;
        storageSlot   = null;
        aSwapped      = false;
    }
Exemplo n.º 2
0
        public void RemoveItem(NitroxId ownerId, bool silent = false)
        {
            GameObject             owner   = NitroxEntity.RequireObjectFrom(ownerId);
            Optional <EnergyMixin> opMixin = Optional.OfNullable(owner.GetComponent <EnergyMixin>());

            if (opMixin.HasValue)
            {
                EnergyMixin mixin = opMixin.Value;
                StorageSlot slot  = mixin.batterySlot;

                // Suppress sound when silent is active
                // Will be used to suppress swap sound at the initialisation of the game
                bool allowedToPlaySounds = true;
                if (silent)
                {
                    allowedToPlaySounds       = mixin.allowedToPlaySounds;
                    mixin.allowedToPlaySounds = !silent;
                }
                using (packetSender.Suppress <StorageSlotItemRemove>())
                {
                    slot.RemoveItem();
                }
                if (silent)
                {
                    mixin.allowedToPlaySounds = allowedToPlaySounds;
                }
            }
            else
            {
                Log.Error("Removing storage slot item: Could not find storage slot field on object " + owner.name);
            }
        }
Exemplo n.º 3
0
    public override void OnBeginDrag(PointerEventData data)
    {
        base.OnBeginDrag(data);

        if (data.button == PointerEventData.InputButton.Left)
        {
            if (_slot != null)
            {
                if (_slot.GetType() == typeof(EquipmentSlot))
                {
                    EquipmentSlot es = (EquipmentSlot)_slot;
                    es.DeSlot(this);
                    _slot = null;
                }
                else if (_slot.GetType() == typeof(StorageSlot))
                {
                    StorageSlot   ss = (StorageSlot)_slot;
                    StorageWindow sw = ss.StorageWindow;
                    if (sw != null)
                    {
                        sw.DeSlot(ss, this);
                        _storageWindow = null;
                        _slot          = null;
                    }
                }
            }
        }
    }
Exemplo n.º 4
0
        public void RemoveItem(NitroxId ownerId, bool silent = false)
        {
            GameObject             owner   = NitroxIdentifier.RequireObjectFrom(ownerId);
            Optional <EnergyMixin> opMixin = Optional <EnergyMixin> .OfNullable(owner.GetComponent <EnergyMixin>());

            if (opMixin.IsPresent())
            {
                EnergyMixin mixin = opMixin.Get();
                StorageSlot slot  = (StorageSlot)mixin.ReflectionGet("batterySlot");

                // Suppress sound when silent is active
                // Will be used to suppress swap sound at the initialisation of the game
                bool allowedToPlaySounds = true;
                if (silent)
                {
                    allowedToPlaySounds = (bool)mixin.ReflectionGet("allowedToPlaySounds");
                    mixin.ReflectionSet("allowedToPlaySounds", !silent);
                }
                using (packetSender.Suppress <StorageSlotItemRemove>())
                {
                    slot.RemoveItem();
                }
                if (silent)
                {
                    mixin.ReflectionSet("allowedToPlaySounds", allowedToPlaySounds);
                }
            }
            else
            {
                Log.Error("Removing storage slot item: Could not find storage slot field on object " + owner.name);
            }
        }
        public virtual T GetValue<T>(StorageSlot key)
        {
            if (Storage.TryGetValue(key, out var value))
            {
                return (T) value;
            }

            return default;
        }
Exemplo n.º 6
0
    private void CheckMagazineStorage(Magazine m)
    {
        UIItem        uIItem = m.UIItem;
        StorageWindow sw     = m.UIItem.StorageWindow;
        StorageSlot   ss     = (StorageSlot)m.UIItem.Slot;

        if (sw && ss && uIItem)
        {
            sw.DeSlot(ss, uIItem);
        }
    }
Exemplo n.º 7
0
 public override void ReceiveInteraction(Player thisActor)
 {
     if (!isBeingCarried)
     {
         if (currentType == PickupType.FishBox)
         {
             if (isStored)
             {
                 storedLocation.RemoveFishBox();
                 storedLocation = null;
                 isStored       = false;
             }
             transform.SetParent(thisActor.holdPoint, true);
             transform.localPosition     = Vector3.zero;
             isBeingCarried              = true;
             thisActor.carryingSomething = true;
         }
         else if (currentType == PickupType.Monkey)
         {
             transform.SetParent(thisActor.holdPoint, true);
             transform.localPosition     = Vector3.zero;
             isBeingCarried              = true;
             thisActor.carryingSomething = true;
             var monkey = GetComponent <Monkey>();
             monkey.stateMachine.currentState.ExitState();
             monkey.stateMachine.currentState = new PickedUpState(monkey);
             monkey.stateMachine.currentState.EnterState();
         }
     }
     else if (isBeingCarried && thisActor.carryingSomething)
     {
         if (currentType == PickupType.FishBox)
         {
             Debug.Log("Dropping FishBox");
             DropFishBox(thisActor);
         }
         if (currentType == PickupType.Monkey)
         {
             Debug.Log("Dropping Monkey");
             DropMonkey(thisActor);
         }
     }
 }
Exemplo n.º 8
0
    public override void OnPointerUp(PointerEventData data)
    {
        base.OnPointerUp(data);

        if (data.button == PointerEventData.InputButton.Left)
        {
            if (_canUseLinkednItem)
            {
                UseLinkedItem();
                return;
            }

            ItemSlot slotHit = uIItemManager.CastToItemSlot(RectTransform.position);

            if (slotHit != null)
            {
                if (slotHit.GetType() == typeof(EquipmentSlot))
                {
                    EquipmentSlot es = (EquipmentSlot)slotHit;
                    es.Slot(this);
                    _slot = es;
                }

                else if (slotHit.GetType() == typeof(StorageSlot))
                {
                    StorageSlot   ss = (StorageSlot)slotHit;
                    StorageWindow sw = ss.StorageWindow;
                    if (sw != null)
                    {
                        sw.Slot(ss, this, true);
                        _storageWindow = sw;
                        _slot          = ss;
                    }
                }
            }
            else
            {
                Debug.Log("No Slot");
                LinkedItem.Drop(new object[] { gameManager.Actor.Character.transform.position });
            }
        }
    }
Exemplo n.º 9
0
    public void OnBeginDrag(PointerEventData eventData)
    {
        // set buttonGO GO.
        GameObject buttonGO = transform.parent.gameObject;
        // set slot GO.
        GameObject slotGO = buttonGO.transform.parent.gameObject;

        // if it's from inventory.
        if (slotGO.GetComponent <InventorySlot>())
        {
            inventorySlot = slotGO.GetComponent <InventorySlot>();
        }
        // if it's from storage (i.e. chest, box, etc)
        else if (slotGO.GetComponent <StorageSlot>())
        {
            storageSlot = slotGO.GetComponent <StorageSlot>();
        }

        // set this gameobject as the dragged item.
        draggedItemGO = gameObject;
        // check if it's an inventory item.
        if (inventorySlot != null)
        {
            draggedItem = inventorySlot.item;
        }
        // check if it's a storage item.
        else if (storageSlot != null)
        {
            draggedItem = storageSlot.item;
        }

        // remember its start position.
        originalPosition = transform.position;
        // remember its original parent.
        originalParent = transform.parent;
        // canvas allows raycasts.
        canvasGroup.blocksRaycasts = false;

        // detach it from its original parent and set the HUD as its parent.
        transform.SetParent(transform.root);
    }
Exemplo n.º 10
0
    private void DropFishBox(Player thisActor)
    {
        bool     storageAvailable = false;
        Collider foundCollider    = null;

        if (canBeStored)
        {
            LayerMask  layerMask      = LayerMask.GetMask("Storage");
            Collider[] foundColliders = Physics.OverlapBox(transform.position, new Vector3(1.5f, 2f, 1.5f), Quaternion.identity, layerMask);

            foundCollider = GetNearestCollider(foundColliders); //will return null if colliders were found but all were full / taken
            if (foundCollider)
            {
                storageAvailable = true;
            }
        }

        if (storageAvailable)
        {
            transform.SetParent(foundCollider.transform, false);
            var storageSlot = foundCollider.GetComponent <StorageSlot>();
            storageSlot.AddFishBox(GetComponent <FishBox>());
            storedLocation = storageSlot;

            thisActor.carryingSomething = false;
            isBeingCarried = false;
            isStored       = true;
        }
        else
        {
            LayerMask layerMask0 = LayerMask.GetMask("Deck");
            Physics.Raycast(transform.position, Vector3.down, out RaycastHit hit, Mathf.Infinity, layerMask0);

            var temp = transform.rotation;
            transform.SetParent(thisActor.transform.parent, true);
            transform.SetPositionAndRotation(hit.point, temp);

            thisActor.carryingSomething = false;
            isBeingCarried = false;
        }
    }
Exemplo n.º 11
0
        public void AddItem(GameObject item, NitroxId containerId, bool silent = false)
        {
            Optional <GameObject> owner = NitroxEntity.GetObjectFrom(containerId);

            if (!owner.HasValue)
            {
                Log.Error("Could not place " + item.name + " in storageSlot container with id " + containerId);
                return;
            }

            // only need to watch EnergyMixin slots for now (only other type will be propulsion cannon)
            Optional <EnergyMixin> opEnergy = Optional.OfNullable(owner.Value.GetComponent <EnergyMixin>());

            if (opEnergy.HasValue)
            {
                EnergyMixin mixin = opEnergy.Value;
                StorageSlot slot  = mixin.batterySlot;

                Pickupable pickupable = item.RequireComponent <Pickupable>();

                // Suppress sound when silent is active
                // Will be used to suppress swap sound at the initialisation of the game
                bool allowedToPlaySounds = true;
                if (silent)
                {
                    allowedToPlaySounds       = mixin.allowedToPlaySounds;
                    mixin.allowedToPlaySounds = !silent;
                }
                using (packetSender.Suppress <StorageSlotItemAdd>())
                {
                    slot.AddItem(new InventoryItem(pickupable));
                }
                if (silent)
                {
                    mixin.allowedToPlaySounds = allowedToPlaySounds;
                }
            }
        }
Exemplo n.º 12
0
        public void AddItem(GameObject item, NitroxId containerId, bool silent = false)
        {
            GameObject owner = NitroxEntity.RequireObjectFrom(containerId);

            // only need to watch EnergyMixin slots for now (only other type will be propulsion cannon)
            Optional <EnergyMixin> opEnergy = Optional <EnergyMixin> .OfNullable(owner.GetComponent <EnergyMixin>());

            if (opEnergy.IsPresent())
            {
                EnergyMixin mixin = opEnergy.Get();
                StorageSlot slot  = (StorageSlot)mixin.ReflectionGet("batterySlot");

                Pickupable pickupable = item.RequireComponent <Pickupable>();

                // Suppress sound when silent is active
                // Will be used to suppress swap sound at the initialisation of the game
                bool allowedToPlaySounds = true;
                if (silent)
                {
                    allowedToPlaySounds = (bool)mixin.ReflectionGet("allowedToPlaySounds");
                    mixin.ReflectionSet("allowedToPlaySounds", !silent);
                }
                using (packetSender.Suppress <StorageSlotItemAdd>())
                {
                    slot.AddItem(new InventoryItem(pickupable));
                }
                if (silent)
                {
                    mixin.ReflectionSet("allowedToPlaySounds", allowedToPlaySounds);
                }
            }
            else
            {
                Log.Error("Add storage slot item: Could not find BatterySource field on object " + owner.name);
            }
        }
Exemplo n.º 13
0
	private void SetItem( sITEM sitem, int iSlot )
	{	
		if( m_ItemList.Length <= iSlot )
		{
			Debug.LogError("Storagetory::SetItem() [m_ItemList.Length <= iSlot] [ index : " + iSlot );
			return;
		}
		
		if ( 0 == sitem.nItemTableIdx ) 
		{
			if( null != m_ItemList[ iSlot ] )
			{
				m_ItemList[ iSlot ].Clear();	
			}
		}
		else
		{
			if( null == m_ItemList[ iSlot ] )
			{
				m_ItemList[ iSlot ] = new StorageSlot( new RealItem( sitem, iSlot) );
			}
			else
			{
				m_ItemList[ iSlot ].SetItem( sitem, iSlot );
			}
		}	
	}	
 protected override void Start()
 {
     Slot = WarehouseController.Instance.RegisterStorage(Model.RawMaterial.Name);
 }
 public virtual void StoreValue(StorageSlot key, object value)
 {
     Storage[key] = value;
     StorageValueChanged?.Invoke(this, key);
 }
 protected void RaiseStorageValueChanged(StorageSlot key)
 {
     StorageValueChanged?.Invoke(this, key);
 }
Exemplo n.º 17
0
    public void OnDrop(PointerEventData eventData)
    {
        if (transform.parent.GetComponent <InventorySlot>())
        {
            inventorySlot = GetComponentInParent <InventorySlot>();
        }
        else if (transform.parent.GetComponent <StorageSlot>())
        {
            storageSlot = GetComponentInParent <StorageSlot>();
        }

        // if this script's GO is an inventorySlot or else if this script's GO is a storageSlot.
        if (inventorySlot != null)
        {
            // if empty inventory slot.
            if (!ItemGO)
            {
                ItemDragHandler.draggedItemGO.transform.SetParent(this.transform);
                inventorySlot.item    = ItemDragHandler.draggedItem;
                inventorySlot.isTaken = true;

                // if adding from toolbar.
                if (ItemDragHandler.storageSlot != null)
                {
                    inventory.Add(ItemDragHandler.storageSlot.item);
                    toolbar.Remove(ItemDragHandler.storageSlot.item);
                }
            }
            else
            {
                // swap
                ItemDragHandler.aSwapped = true;

                if (ItemDragHandler.storageSlot != null)
                {
                    // swap from inventory to toolbar slot.
                    SwapFromInventoryToStorage();
                }
                else if (ItemDragHandler.inventorySlot != null)
                {
                    // swap between inventory slots.

                    Item temp = inventorySlot.item;
                    inventorySlot.item = ItemDragHandler.draggedItem;
                    ItemDragHandler.inventorySlot.item = temp;

                    ItemDragHandler.draggedItemGO.transform.SetParent(this.transform);
                    inventorySlot.transform.GetChild(0).transform.GetChild(0).transform.SetParent(ItemDragHandler.inventorySlot.transform.GetChild(0));
                }
            }
        }
        else if (storageSlot != null)
        {
            // if empty toolbar slot.
            if (!ItemGO)
            {
                ItemDragHandler.draggedItemGO.transform.SetParent(this.transform);
                storageSlot.item    = ItemDragHandler.draggedItem;
                storageSlot.isTaken = true;

                // if adding from inventory.
                if (ItemDragHandler.inventorySlot != null)
                {
                    toolbar.Add(ItemDragHandler.inventorySlot.item);
                    inventory.Remove(ItemDragHandler.inventorySlot.item);
                }
                ;
            }
            else
            {
                // swap
                ItemDragHandler.aSwapped = true;

                // if swapping to inventory.
                if (ItemDragHandler.inventorySlot != null)
                {
                    SwapFromToolbarToInventory();
                }
                else if (ItemDragHandler.storageSlot != null)
                {
                    // swap between storage slots.

                    Item temp = storageSlot.item;
                    storageSlot.item = ItemDragHandler.draggedItem;
                    ItemDragHandler.storageSlot.item = temp;

                    ItemDragHandler.draggedItemGO.transform.SetParent(this.transform);
                    storageSlot.transform.GetChild(0).transform.GetChild(0).transform.SetParent(ItemDragHandler.storageSlot.transform.GetChild(0));
                }
            }
        }
    }