예제 #1
0
        public void Swap(InventoryType inventory, short slot1, short slot2)
        {
            bool equippedSlot2 = slot2 < 0;

            if (inventory == InventoryType.Equipment && equippedSlot2)
            {
            }
            else
            {
                Item item1 = this[inventory, slot1];
                Item item2 = this[inventory, slot2];

                if (item1 == null)
                {
                    return;
                }

                if (item2 != null && item1.MapleID == item2.MapleID)
                {
                }
                else
                {
                    this[inventory, slot1] = item2;
                    this[inventory, slot2] = item1;

                    InventoryOperation operation = new InventoryOperation(InventoryOperationType.ModifySlot, item1, slot1, slot2);

                    this.Operate(true, operation);
                }
            }
        }
예제 #2
0
    public void TargetPerformInventoryAction(NetworkConnection conn, byte[] operationInfo, string actionType)
    {
        NetworkReader      reader = new NetworkReader(operationInfo);
        InventoryOperation op     = new InventoryOperation(InventoryOperation.Operation.Clear, null);

        op.Deserialize(reader);
        PerformInventoryAction(op, actionType);
    }
예제 #3
0
    private void checkIfPickedUp()
    {
        if (!isServer)
        {
            return;
        }

        GameObject[] players = GameObject.FindGameObjectsWithTag("Player");

        foreach (GameObject player in players)
        {
            MoleController playerController = player.GetComponent <MoleController> ();

            if (playerController == null || playerController.gamePos == null)
            {
                continue;
            }

            float heightDiff = Mathf.Abs(gamePos.depth - playerController.gamePos.depth);
            float planeDiff  = (gamePos.planePosition - playerController.gamePos.planePosition).magnitude;

            if (heightDiff < HEIGHT_CUTOFF && planeDiff < PICK_UP_DISTANCE)
            {
                Player p = player.GetComponent <Player> ();

                Debug.Log(getItem() + " getting picked up of quantity " + quantity);
                InventoryOperation invOp = new InventoryOperation(InventoryOperation.Operation.AddItems, new byte[][] { itemData.data, System.Text.Encoding.Default.GetBytes(quantity.ToString()) });

                int remainder = player.GetComponent <Player> ().PerformInventoryAction(invOp, "general");
                Debug.Log("remainder: " + remainder);

                if (remainder >= quantity)
                {
                    return;
                }
                quantity = remainder;

                if (!player.GetComponent <NetworkIdentity> ().isLocalPlayer)
                {
                    //player.GetComponent<Player> ().beltUI.updateUI ();
                    //} else {

                    NetworkWriter writer = new NetworkWriter();
                    invOp.Serialize(writer);
                    p.TargetPerformInventoryAction(player.GetComponent <NetworkIdentity> ().connectionToClient, writer.AsArray(), "general");
                    //p.TargetPickUpItem (player.GetComponent<NetworkIdentity> ().connectionToClient, getItem().Encode ());
                }

                if (quantity <= 0)
                {
                    NetworkServer.Destroy(gameObject);
                }
            }
        }
    }
예제 #4
0
    public int PerformInventoryAction(InventoryOperation op, string actionType)
    {
        if (actionType.ToLower().Equals("backpackonly"))
        {
            int result = InventoryOperation.PerformOperation(info.backpack.inventory, op);
            if (isLocalPlayer)
            {
                backpackUI.updateUI();
            }

            return(result);
        }
        else if (actionType.ToLower().Equals("beltonly"))
        {
            int result = InventoryOperation.PerformOperation(info.belt, op);
            if (isLocalPlayer)
            {
                beltUI.updateUI();
            }

            return(result);
        }
        else if (actionType.ToLower().Equals("general"))
        {
            int result = InventoryOperation.PerformOperation(info.belt, op);
            if (result < 0)
            {
                Debug.LogError("Error adding to belt");
                return(-1);
            }

            if (isLocalPlayer)
            {
                beltUI.updateUI();
            }

            if (op.op.Equals(InventoryOperation.Operation.AddItems) && info.backpack != null && result > 0)
            {
                Item item    = Item.ReadItem(op.paramaters [0]);
                int  result2 = info.backpack.inventory.addItemMany(item, result);
                if (isLocalPlayer)
                {
                    backpackUI.updateUI();
                }

                return(result2);
            }
            return(result);
        }
        else
        {
            Debug.LogError("Recieved unrecognized inventory action type '" + actionType + "'");
            return(-1);
        }
    }
예제 #5
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (Operations == null)
            {
                return;
            }

            InventoryOperation op = new InventoryOperation();

            Operations.Add(op);
            UpdateUI();
            SelectedOperation = op;
        }
예제 #6
0
        private void btnMoveDown_Click(object sender, EventArgs e)
        {
            if (SelectedOperation == null)
            {
                return;
            }

            int Index = Operations.IndexOf(SelectedOperation);

            if (Index == Operations.Count - 1)
            {
                return;                                            // Can't move down anymore.
            }
            InventoryOperation higher = Operations[Index];
            InventoryOperation lower  = Operations[Index + 1];

            Operations[Index]     = lower;
            Operations[Index + 1] = higher;

            lbOperations.Refresh();
        }
예제 #7
0
        public void Add(int mapleID, short quantity = 1)
        {
            Item item;

            InventoryType inventory = Item.GetInventory(mapleID);

            if (inventory == InventoryType.Equipment)
            {
                item = new Equip(mapleID);
            }
            else
            {
                item = new Item(mapleID, quantity);
            }

            short slot = this.GetNextFreeSlot(inventory);

            this[inventory, slot] = item;

            InventoryOperation operation = new InventoryOperation(InventoryOperationType.AddItem, item, 0, slot);

            this.Operate(false, operation);
        }
예제 #8
0
    public static int PerformOperation(Inventory inv, InventoryOperation operation)
    {
        switch (operation.op)
        {
        case Operation.AddItems:
            return(AddItems(inv, operation.paramaters));

        case Operation.AddItemsToSlot:
            return(AddItemsToSlot(inv, operation.paramaters));

        case Operation.RemoveItemsFromSlot:
            return(RemoveItemsFromSlot(inv, operation.paramaters));

        case Operation.Set:
            return(SetSlot(inv, operation.paramaters));

        case Operation.Clear:
            return(ClearSlot(inv, operation.paramaters));

        default:
            Debug.Log("Unhandled InventoryOperation case");
            return(-1);
        }
    }
예제 #9
0
        private void UpdateUI()
        {
            Updating = true;

            InventoryOperation previous = SelectedOperation;

            lbOperations.Items.Clear();
            if (Operations == null)
            {
                btnAdd.Enabled    = false;
                btnRemove.Enabled = false;
            }
            else
            {
                btnAdd.Enabled    = true;
                btnRemove.Enabled = true;

                lbOperations.Items.AddRange(Operations.ToArray());

                if (previous != null && lbOperations.Items.Contains(previous))
                {
                    lbOperations.SelectedItem = previous;
                }
            }

            if (SelectedOperation == null)
            {
                cbItemName.Text    = "";
                cbItemName.Enabled = false;

                cbOperationType.SelectedItem = null;
                cbOperationType.Enabled      = false;

                nudValue.Value   = 0;
                nudValue.Enabled = false;

                btnMoveUp.Enabled   = false;
                btnMoveDown.Enabled = false;
            }
            else
            {
                cbItemName.Text    = SelectedOperation.ItemName;
                cbItemName.Enabled = true;

                cbOperationType.SelectedValue = SelectedOperation.Operation;
                cbOperationType.Enabled       = true;

                nudValue.Value = SelectedOperation.Value;
                if (SelectedOperation.Operation == Operation.Add ||
                    SelectedOperation.Operation == Operation.Set ||
                    SelectedOperation.Operation == Operation.Subtract)
                {
                    nudValue.Enabled = true;
                }
                else
                {
                    nudValue.Enabled = false;
                }

                int Index = Operations.IndexOf(SelectedOperation);
                if (Index == 0)
                {
                    btnMoveUp.Enabled = false;
                }
                else
                {
                    btnMoveUp.Enabled = true;
                }

                if (Index == Operations.Count - 1)
                {
                    btnMoveDown.Enabled = false;
                }
                else
                {
                    btnMoveDown.Enabled = true;
                }
            }

            Updating = false;
        }
예제 #10
0
 public InventoryEventArgs(InventoryOperation operation, Item item = null, int newCount = 0)
 {
     Operation = operation;
     Item      = item;
     NewCount  = newCount;
 }