Esempio n. 1
0
        public bool RemoveItem(Item item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("Please select an item to remove");
            }

            EquipedItems.Remove(item);
            return(true);
        }
Esempio n. 2
0
        public bool AddItem(Item item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("Please select an item to add");
            }

            EquipedItems.Add(item);
            return(true);
        }
Esempio n. 3
0
        private void render()
        {
            equipped = new EquipedItems(ApplicationState.Model.GetInventory(Character, false, ApplicationState.AccountName).Where(i => i.InventoryId != "MainInventory"));
            davinci.Children.Clear();
            Dictionary <string, Item> itemsAtPosition = equipped.GetItems();

            foreach (string key in itemsAtPosition.Keys)
            {
                Grid childGrid = new Grid();
                childGrid.Margin = new Thickness(1);

                Item gearAtLocation = itemsAtPosition[key];
                if (gearAtLocation == null)
                {
                    continue;
                }

                if (key.Contains("Weapon") || key.Contains("Offhand"))
                {
                    bool isAlt = key.StartsWith("Alt");
                    childGrid.Height              = 187;
                    childGrid.Width               = 93;
                    childGrid.VerticalAlignment   = System.Windows.VerticalAlignment.Center;
                    childGrid.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;

                    if (!showAlts && isAlt)
                    {
                        continue;
                    }

                    if (showAlts && !isAlt)
                    {
                        continue;
                    }
                }


                Border border = getBorder();
                childGrid.Children.Add(border);

                childGrid.Children.Add(getImage(gearAtLocation));

                Canvas.SetTop(childGrid, absolutely[key].Item1);
                Canvas.SetLeft(childGrid, absolutely[key].Item2);

                davinci.Children.Add(childGrid);
            }
            this.davinci.Focus();
        }
    // Update is called once per frame
    void Update()
    {
        // Debug.Log(_mouseState);
        if (Input.GetMouseButtonDown(0))
        {
            origin = transform.localPosition;
            RaycastHit hitInfo;
            target = GetClickedObject(out hitInfo);
            if (target != null)
            {
                DragNDrop dnd = target.GetComponent <DragNDrop>();
                if (dnd != null)
                {
                    _mouseState = true;
                    screenSpace = Camera.main.WorldToScreenPoint(target.transform.position);
                    offset      = target.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z));
                    Collider col = target.GetComponent <Collider>();
                    if (col != null)
                    {
                        col.enabled = false;
                    }
                }
            }
        }
        if (Input.GetMouseButtonUp(0))
        {
            _mouseState = false;
            RaycastHit hitInfo;
            target = GetClickedObject(out hitInfo);
            if (target != null)
            {
                Collider col = GetComponent <Collider>();
                if (col != null)
                {
                    col.enabled = true;
                }
                Body body = target.GetComponent <Body>();
                if (body != null)
                {
                    if (body.TryEquipGameObject(this.gameObject))
                    {
                        isEquipped = true;
                        Rotate rotate = GetComponent <Rotate>();
                        if (rotate != null)
                        {
                            rotate.enabled          = false;
                            transform.localRotation = originRotation;
                            transform.localScale    = originScale;
                        }
                    }
                    else
                    {
                        transform.localPosition = origin;
                        isEquipped = false;
                    }
                }
                else
                {
                    body = target.GetComponentInParent <Body>();
                    if (body != null)
                    {
                        if (body.TryEquipGameObject(this.gameObject))
                        {
                            isEquipped = true;
                            Rotate rotate = GetComponent <Rotate>();
                            if (rotate != null)
                            {
                                rotate.enabled          = false;
                                transform.localRotation = originRotation;
                                transform.localScale    = originScale;
                            }
                        }
                        else
                        {
                            transform.localPosition = origin;
                            isEquipped = false;
                        }
                    }
                    else
                    {
                        // InspectPosition needs  rigidbody and collider and larger hot spot
                        // Player needs larger hotspot as well
                        if (isEquipped && target.name == "InspectPosition")
                        {
                            if (target.transform.childCount > 0)
                            {
                                for (int i = 0; i < target.transform.childCount; i++)
                                {
                                    DestroyObject(target.transform.GetChild(i).gameObject);
                                }
                            }
                            BodyPartHover bph = GetComponent <BodyPartHover>();
                            if (bph != null)
                            {
                                bph.isEnabled = false;
                            }
                            isEquipped              = false;
                            transform.parent        = target.transform;
                            transform.localRotation = originRotation;
                            transform.localScale    = originScale;
                            Rotate rotate = GetComponent <Rotate>();
                            if (rotate != null)
                            {
                                rotate.enabled = true;
                            }
                            BodyPart[]      bodyParts = GetComponents <BodyPart>();
                            InventoryObject io        = GetComponent <InventoryObject>();
                            if (io != null)
                            {
                                foreach (BodyPart bodyPart in bodyParts)
                                {
                                    if (bodyPart != null)
                                    {
                                        switch (bodyPart.bodyPartType)
                                        {
                                        case BodyPartType.Hat:
                                            if (EquipedItems.GetHat() == io.ResourceName)
                                            {
                                                EquipedItems.EquipHat(null);
                                            }
                                            break;

                                        case BodyPartType.EyeNose:
                                            if (EquipedItems.GetLeftEye() == io.ResourceName)
                                            {
                                                EquipedItems.EquipLeftEye(null);
                                            }
                                            if (EquipedItems.GetRightEye() == io.ResourceName)
                                            {
                                                EquipedItems.EquipRightEye(null);
                                            }
                                            if (EquipedItems.GetNose() == io.ResourceName)
                                            {
                                                EquipedItems.EquipNose(null);
                                            }
                                            break;

                                        case BodyPartType.Mouth:
                                            if (EquipedItems.GetMouth() == io.ResourceName)
                                            {
                                                EquipedItems.EquipMouth(null);
                                            }
                                            break;

                                        case BodyPartType.Scarf:
                                            if (EquipedItems.GetNeck() == io.ResourceName)
                                            {
                                                EquipedItems.EquipNeck(null);
                                            }
                                            break;

                                        case BodyPartType.Mitten:
                                            if (EquipedItems.GetLeftHand() == io.ResourceName)
                                            {
                                                EquipedItems.EquipLeftHand(null);
                                            }
                                            if (EquipedItems.GetRightHand() == io.ResourceName)
                                            {
                                                EquipedItems.EquipRightHand(null);
                                            }
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            transform.localPosition = origin;
                            isEquipped = false;
                        }
                    }
                }
            }
            else
            {
                transform.localPosition = origin;
                isEquipped = false;
            }
        }
        if (_mouseState)
        {
            //keep track of the mouse position
            var curScreenSpace = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z);

            //convert the screen mouse position to world point and adjust with offset
            var curPosition = Camera.main.ScreenToWorldPoint(curScreenSpace) + offset;

            //update the position of the object in the world
            target.transform.position = curPosition;
        }
    }
Esempio n. 5
0
 void Start()
 {
     if (EquipedItems.GetHat() != null)
     {
         GameObject obj = (GameObject)Resources.Load(EquipedItems.GetHat(), typeof(GameObject));
         GameObject ins = Instantiate(obj);
         ins.layer = 2;
         DragNDrop dnd = ins.AddComponent <DragNDrop>();
         dnd.isEquipped = true;
         BodyPart[] bodyParts = ins.GetComponents <BodyPart>();
         foreach (BodyPart bodyPart in bodyParts)
         {
             if (bodyPart != null && bodyPart.bodyPartType == BodyPartType.Hat)
             {
                 EquipGameObject(bodyPart, HatEquipmentPosition.ObjectPosition);
             }
         }
     }
     if (EquipedItems.GetLeftEye() != null)
     {
         GameObject obj = (GameObject)Resources.Load(EquipedItems.GetLeftEye(), typeof(GameObject));
         GameObject ins = Instantiate(obj);
         ins.layer = 2;
         DragNDrop dnd = ins.AddComponent <DragNDrop>();
         dnd.isEquipped = true;
         BodyPart[] bodyParts = ins.GetComponents <BodyPart>();
         foreach (BodyPart bodyPart in bodyParts)
         {
             if (bodyPart != null && bodyPart.bodyPartType == BodyPartType.EyeNose)
             {
                 EquipGameObject(bodyPart, LeftEyePosition);
             }
         }
     }
     if (EquipedItems.GetRightEye() != null)
     {
         GameObject obj = (GameObject)Resources.Load(EquipedItems.GetRightEye(), typeof(GameObject));
         GameObject ins = Instantiate(obj);
         ins.layer = 2;
         DragNDrop dnd = ins.AddComponent <DragNDrop>();
         dnd.isEquipped = true;
         BodyPart[] bodyParts = ins.GetComponents <BodyPart>();
         foreach (BodyPart bodyPart in bodyParts)
         {
             if (bodyPart != null && bodyPart.bodyPartType == BodyPartType.EyeNose)
             {
                 EquipGameObject(bodyPart, RightEyePosition);
             }
         }
     }
     if (EquipedItems.GetNose() != null)
     {
         GameObject obj = (GameObject)Resources.Load(EquipedItems.GetNose(), typeof(GameObject));
         GameObject ins = Instantiate(obj);
         ins.layer = 2;
         DragNDrop dnd = ins.AddComponent <DragNDrop>();
         dnd.isEquipped = true;
         BodyPart[] bodyParts = ins.GetComponents <BodyPart>();
         foreach (BodyPart bodyPart in bodyParts)
         {
             if (bodyPart != null && bodyPart.bodyPartType == BodyPartType.EyeNose)
             {
                 EquipGameObject(bodyPart, NosePosition);
             }
         }
     }
     if (EquipedItems.GetMouth() != null)
     {
         GameObject obj = (GameObject)Resources.Load(EquipedItems.GetMouth(), typeof(GameObject));
         GameObject ins = Instantiate(obj);
         ins.layer = 2;
         DragNDrop dnd = ins.AddComponent <DragNDrop>();
         dnd.isEquipped = true;
         BodyPart[] bodyParts = ins.GetComponents <BodyPart>();
         foreach (BodyPart bodyPart in bodyParts)
         {
             if (bodyPart != null && bodyPart.bodyPartType == BodyPartType.Mouth)
             {
                 EquipGameObject(bodyPart, MouthPosition);
             }
         }
     }
     if (EquipedItems.GetNeck() != null)
     {
         GameObject obj = (GameObject)Resources.Load(EquipedItems.GetNeck(), typeof(GameObject));
         GameObject ins = Instantiate(obj);
         ins.layer = 2;
         DragNDrop dnd = ins.AddComponent <DragNDrop>();
         dnd.isEquipped = true;
         BodyPart[] bodyParts = ins.GetComponents <BodyPart>();
         foreach (BodyPart bodyPart in bodyParts)
         {
             if (bodyPart != null && bodyPart.bodyPartType == BodyPartType.Scarf)
             {
                 EquipGameObject(bodyPart, ScarfPosition);
             }
         }
     }
     if (EquipedItems.GetLeftHand() != null)
     {
         GameObject obj = (GameObject)Resources.Load(EquipedItems.GetLeftHand(), typeof(GameObject));
         GameObject ins = Instantiate(obj);
         ins.layer = 2;
         obj.transform.localRotation = new Quaternion(0f, 0.9f, 0f, 1f);
         DragNDrop dnd = ins.AddComponent <DragNDrop>();
         dnd.isEquipped = true;
         BodyPart[] bodyParts = ins.GetComponents <BodyPart>();
         foreach (BodyPart bodyPart in bodyParts)
         {
             if (bodyPart != null && bodyPart.bodyPartType == BodyPartType.Mitten)
             {
                 EquipGameObject(bodyPart, LeftMittenPosition);
             }
         }
     }
     if (EquipedItems.GetRightHand() != null)
     {
         GameObject obj = (GameObject)Resources.Load(EquipedItems.GetRightHand(), typeof(GameObject));
         GameObject ins = Instantiate(obj);
         ins.layer = 2;
         ins.transform.localRotation = new Quaternion(0f, -0.9f, 0f, 1f);
         DragNDrop dnd = ins.AddComponent <DragNDrop>();
         dnd.isEquipped = true;
         BodyPart[] bodyParts = ins.GetComponents <BodyPart>();
         foreach (BodyPart bodyPart in bodyParts)
         {
             if (bodyPart != null && bodyPart.bodyPartType == BodyPartType.Mitten)
             {
                 EquipGameObject(bodyPart, RightMittenPosition);
             }
         }
     }
 }
Esempio n. 6
0
    public bool TryEquipGameObject(GameObject obj)
    {
        bool retval = false;

        if (obj != null)
        {
            BodyPart[] bodyParts = obj.GetComponents <BodyPart>();
            foreach (BodyPart bodyPart in bodyParts)
            {
                BodyPartHover bph = obj.GetComponent <BodyPartHover>();
                if (bph != null)
                {
                    if (bodyPart != null)
                    {
                        InventoryObject io = obj.GetComponent <InventoryObject>();
                        if (io != null)
                        {
                            switch (bodyPart.bodyPartType)
                            {
                            case BodyPartType.Hat:
                                if (EquipedItems.GetHat() == null)
                                {
                                    HatEquipmentPosition.Object = obj;
                                    EquipGameObject(bodyPart, HatEquipmentPosition.ObjectPosition);
                                    if (HatToggle != null)
                                    {
                                        HatToggle.isOn = true;
                                    }

                                    EquipedItems.EquipHat(io.ResourceName);

                                    retval = true;
                                }
                                break;

                            case BodyPartType.EyeNose:

                                if (EquipedItems.GetLeftEye() == null)
                                {
                                    EquipGameObject(bodyPart, LeftEyePosition);
                                    if (LeftEyeToggle != null)
                                    {
                                        LeftEyeToggle.isOn = true;
                                    }

                                    EquipedItems.EquipLeftEye(io.ResourceName);

                                    retval = true;
                                }
                                else if (EquipedItems.GetLeftEye() != io.ResourceName && EquipedItems.GetRightEye() == null)
                                {
                                    EquipGameObject(bodyPart, RightEyePosition);
                                    if (RightEyeToggle != null)
                                    {
                                        RightEyeToggle.isOn = true;
                                    }

                                    EquipedItems.EquipRightEye(io.ResourceName);

                                    retval = true;
                                }
                                else if (EquipedItems.GetLeftEye() != io.ResourceName && EquipedItems.GetRightEye() != io.ResourceName && EquipedItems.GetNose() == null)
                                {
                                    EquipGameObject(bodyPart, NosePosition);
                                    if (NoseToggle != null)
                                    {
                                        NoseToggle.isOn = true;
                                    }

                                    EquipedItems.EquipNose(io.ResourceName);

                                    retval = true;
                                }
                                break;

                            case BodyPartType.Mouth:
                                if (EquipedItems.GetMouth() == null)
                                {
                                    EquipGameObject(bodyPart, MouthPosition);
                                    if (MouthToggle != null)
                                    {
                                        MouthToggle.isOn = true;
                                    }

                                    EquipedItems.EquipMouth(io.ResourceName);

                                    retval = true;
                                }
                                break;

                            case BodyPartType.Scarf:
                                if (EquipedItems.GetNeck() == null)
                                {
                                    EquipGameObject(bodyPart, ScarfPosition);
                                    if (ScarfToggle != null)
                                    {
                                        ScarfToggle.isOn = true;
                                    }
                                    EquipedItems.EquipNeck(io.ResourceName);

                                    retval = true;
                                }
                                break;

                            case BodyPartType.Mitten:
                                if (EquipedItems.GetLeftHand() == null)
                                {
                                    EquipGameObject(bodyPart, LeftMittenPosition);
                                    if (LeftMittenToggle != null)
                                    {
                                        LeftMittenToggle.isOn = true;
                                    }

                                    EquipedItems.EquipLeftHand(io.ResourceName);

                                    // Rotate Mitten so Thumb is up.
                                    obj.transform.localRotation = new Quaternion(0f, 0.9f, 0f, 1f);
                                    retval = true;
                                }
                                else if (EquipedItems.GetLeftHand() != io.ResourceName && EquipedItems.GetRightHand() == null)
                                {
                                    EquipGameObject(bodyPart, RightMittenPosition);
                                    if (RightMittenToggle != null)
                                    {
                                        RightMittenToggle.isOn = true;
                                    }

                                    EquipedItems.EquipRightHand(io.ResourceName);

                                    // Rotate Mitten so Thumb is up.
                                    obj.transform.localRotation = new Quaternion(0f, -0.9f, 0f, 1f);
                                    retval = true;
                                }
                                break;
                            }
                        }
                    }
                }
            }
        }
        return(retval);
    }