コード例 #1
0
    public void DropItem(Transform centerpoint, Tapestry_ItemData id, int amount = 1)
    {
        if (amount >= 0)
        {
            foreach (Tapestry_ItemStack stack in items)
            {
                if (stack.item.Equals(id))
                {
                    if (amount > stack.quantity)
                    {
                        amount = stack.quantity;
                    }
                    GameObject clone = GameObject.Instantiate(Resources.Load("Items/" + stack.item.prefabName) as GameObject);
                    clone.transform.position = centerpoint.position + centerpoint.forward * Tapestry_Config.ItemDropDistance;
                    clone.transform.rotation = Quaternion.Euler(0, Random.Range(0, 360), 0);

                    stack.quantity -= amount;
                    if (stack.quantity == 0)
                    {
                        items.Remove(stack);
                    }
                    break;
                }
            }
        }
    }
コード例 #2
0
    protected override void Reset()
    {
        data        = new Tapestry_ItemData();
        displayName = data.displayName;

        base.Reset();
    }
コード例 #3
0
 public void AddItem(Tapestry_ItemData item, int quantity)
 {
     if (item != null)
     {
         if (items == null)
         {
             items = new List <Tapestry_ItemStack>();
         }
         bool added = false;
         for (int i = 0; i < items.Count; i++)
         {
             if (items[i].item.IsEqual(item))
             {
                 items[i].quantity += quantity;
                 added              = true;
                 break;
             }
         }
         if (!added)
         {
             items.Add(new Tapestry_ItemStack(item, quantity));
         }
         //items.Sort();
     }
 }
コード例 #4
0
    public override void Equip(Tapestry_ItemData item, Tapestry_EquipSlot slot)
    {
        base.Equip(item, slot);

        if (slot == Tapestry_EquipSlot.LeftHand || slot == Tapestry_EquipSlot.RightHand)
        {
            GameObject obj = (GameObject)Instantiate(Resources.Load("Items/" + item.prefabName));

            //TODO: Dupe bug when switching hands
            if (slot == Tapestry_EquipSlot.LeftHand)
            {
                CleanEquippedItem(Tapestry_EquipSlot.LeftHand);
                obj.transform.SetParent(holdContainerLeft.transform);
                if (equippedLeft != null)
                {
                    equippedLeft = item;
                }
                else
                {
                    inventory.AddItem(equippedLeft, 1);
                    equippedLeft = item;
                }
            }
            if (slot == Tapestry_EquipSlot.RightHand)
            {
                CleanEquippedItem(Tapestry_EquipSlot.RightHand);
                obj.transform.SetParent(holdContainerRight.transform);
                if (equippedRight != null)
                {
                    equippedRight = item;
                }
                else
                {
                    inventory.AddItem(equippedLeft, 1);
                    equippedLeft = item;
                }
            }
            obj.transform.localPosition = Vector3.zero;
            obj.transform.localRotation = Quaternion.identity;

            obj.layer = 8;
            foreach (Transform t in obj.transform)
            {
                t.gameObject.layer = 8;
            }
            foreach (Collider c in obj.GetComponentsInChildren <Collider>())
            {
                if (!c.isTrigger)
                {
                    c.enabled = false;
                }
            }
            foreach (Rigidbody rb in obj.GetComponentsInChildren <Rigidbody>())
            {
                Destroy(rb);
            }
        }
    }
コード例 #5
0
    public bool IsEqual(Tapestry_ItemData data)
    {
        bool check = true;

        if (prefabName != data.prefabName)
        {
            check = check && false;
        }
        if (value != data.value)
        {
            check = check && false;
        }
        if (icon != data.icon)
        {
            check = check && false;
        }
        if (size != data.size)
        {
            check = check && false;
        }
        if (owningEntity != data.owningEntity)
        {
            check = check && false;
        }
        if (owningFaction != data.owningFaction)
        {
            check = check && false;
        }
        if (displayName != data.displayName)
        {
            check = check && false;
        }
        if (isKey != data.isKey)
        {
            check = check && false;
        }
        if (isKey)
        {
            if (keyID != data.keyID)
            {
                check = check && false;
            }
        }
        if (useEffect && data.useEffect)
        {
            if (!effect.Equals(data.effect))
            {
                check = check && false;
            }
        }
        return(check);
    }
コード例 #6
0
 public bool ContainsKeyID(string id)
 {
     foreach (Tapestry_ItemStack iStack in items)
     {
         Tapestry_ItemData i = iStack.item;
         if (i.isKey)
         {
             if (i.keyID == id)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
コード例 #7
0
    public virtual void Equip(Tapestry_ItemData item, Tapestry_EquipSlot slot)
    {
        if (ReferenceEquals(equipmentProfile, null))
        {
            equipmentProfile = (Tapestry_EquipmentProfile)ScriptableObject.CreateInstance("Tapestry_EquipmentProfile");
        }

        //foreach(Tapestry_ItemStack id in inventory.items)
        for (int i = inventory.items.Count - 1; i >= 0; i--)
        {
            if (inventory.items[i].item.Equals(item))
            {
                equipmentProfile.Equip(slot, item);
                inventory.RemoveItem(item, 1);
            }
        }
    }
コード例 #8
0
 public void SetData(Tapestry_ItemStack data)
 {
     this.data = data.item;
     if (data.item.size == Tapestry_ItemSize.Large)
     {
         size.text = "L";
     }
     else if (data.item.size == Tapestry_ItemSize.Small)
     {
         size.text = "S";
     }
     else if (data.item.size == Tapestry_ItemSize.Negligible)
     {
         size.text = "–";
     }
     quantity.text = data.quantity.ToString();
     title.text    = data.item.displayName;
 }
コード例 #9
0
    public void RemoveItem(Tapestry_ItemData id, int amount = 1)
    {
        if (amount >= 0)
        {
            foreach (Tapestry_ItemStack stack in items)
            {
                if (stack.item.Equals(id))
                {
                    if (amount > stack.quantity)
                    {
                        amount = stack.quantity;
                    }

                    stack.quantity -= amount;
                    if (stack.quantity == 0)
                    {
                        items.Remove(stack);
                    }
                    break;
                }
            }
        }
        //items.Sort();
    }
コード例 #10
0
 public Tapestry_ItemStack(Tapestry_ItemData item, int quantity)
 {
     this.item     = item;
     this.quantity = quantity;
 }
コード例 #11
0
    public void HandleInteract()
    {
        bool leftClick  = Input.GetMouseButton(0);
        bool rightClick = Input.GetMouseButton(1);
        bool activate   =
            Input.GetKey(Tapestry_Config.KeyboardInput_Activate) ||
            leftClick || rightClick;

        if (activateLastFrame && !activate)
        {
            Tapestry_UI_InventoryDisplayTextElement active = null;
            sbyte side = 0;
            foreach (Tapestry_UI_InventoryDisplayTextElement e in left.elements)
            {
                if (e.Active)
                {
                    active = e;
                    side   = -1;
                    break;
                }
            }
            if (side != -1)
            {
                foreach (Tapestry_UI_InventoryDisplayTextElement e in right.elements)
                {
                    if (e.Active)
                    {
                        active = e;
                        side   = 1;
                        break;
                    }
                }
            }
            if (active != null)
            {
                Debug.Log("Clicked on \"" + active.title.text + "\", side=" + side);

                if (side == 1)
                {
                    leftInv.AddItem(active.GetData(), 1);
                    rightInv.RemoveItem(active.GetData(), 1);
                    Open(leftInv, equipment, rightInv, leftName, rightName);
                }
                else if (side == -1)
                {
                    if (ReferenceEquals(rightInv, null))
                    {
                        if (active.GetData().isHoldable)
                        {
                            if (active.isEquipment)
                            {
                                if (active.equippedInSlot == Tapestry_EquipSlot.LeftHand)
                                {
                                    if (rightClickLastFrame)
                                    {
                                        Debug.Log("Right clicked item in left slot");
                                        if (equipment.GetInSlot(Tapestry_EquipSlot.RightHand) != null)
                                        {
                                            Debug.Log("Thar be a thingus");
                                            player.Unequip(Tapestry_EquipSlot.RightHand);
                                            player.Equip(equipment.GetInSlot(Tapestry_EquipSlot.LeftHand), Tapestry_EquipSlot.RightHand);
                                            player.Unequip(Tapestry_EquipSlot.LeftHand);
                                            Open(leftInv, equipment, rightInv, leftName, rightName);
                                        }
                                        else
                                        {
                                            Tapestry_ItemData swap = equipment.GetInSlot(Tapestry_EquipSlot.LeftHand);
                                            player.Unequip(Tapestry_EquipSlot.LeftHand);
                                            player.Equip(swap, Tapestry_EquipSlot.RightHand);
                                            Open(leftInv, equipment, rightInv, leftName, rightName);
                                        }
                                    }
                                    else if (activateLastFrame || leftClickLastFrame)
                                    {
                                        Debug.Log("Left clicked item in left slot");
                                        player.Unequip(Tapestry_EquipSlot.LeftHand);
                                        Open(leftInv, equipment, rightInv, leftName, rightName);
                                    }
                                }
                                else if (active.equippedInSlot == Tapestry_EquipSlot.RightHand)
                                {
                                    if (leftClickLastFrame)
                                    {
                                        if (equipment.GetInSlot(Tapestry_EquipSlot.LeftHand) != null)
                                        {
                                            player.Unequip(Tapestry_EquipSlot.LeftHand);
                                            player.Equip(equipment.GetInSlot(Tapestry_EquipSlot.RightHand), Tapestry_EquipSlot.LeftHand);
                                            player.Unequip(Tapestry_EquipSlot.RightHand);
                                            Open(leftInv, equipment, rightInv, leftName, rightName);
                                        }
                                        else
                                        {
                                            Tapestry_ItemData swap = equipment.GetInSlot(Tapestry_EquipSlot.RightHand);
                                            player.Unequip(Tapestry_EquipSlot.RightHand);
                                            player.Equip(swap, Tapestry_EquipSlot.LeftHand);
                                            Open(leftInv, equipment, rightInv, leftName, rightName);
                                        }
                                    }
                                    else if (activateLastFrame || rightClickLastFrame)
                                    {
                                        player.Unequip(Tapestry_EquipSlot.RightHand);
                                        Open(leftInv, equipment, rightInv, leftName, rightName);
                                    }
                                }
                            }
                            else
                            {
                                if (active.GetData().slot == Tapestry_EquipSlot.EitherHand && leftClickLastFrame)
                                {
                                    player.Equip(active.GetData(), Tapestry_EquipSlot.LeftHand);
                                    active.SetEquippedState(1);
                                    active.equippedInSlot = Tapestry_EquipSlot.LeftHand;
                                    Open(leftInv, equipment, rightInv, leftName, rightName);
                                }
                                else if (active.GetData().slot == Tapestry_EquipSlot.EitherHand && rightClickLastFrame)
                                {
                                    player.Equip(active.GetData(), Tapestry_EquipSlot.RightHand);
                                    active.SetEquippedState(2);
                                    active.equippedInSlot = Tapestry_EquipSlot.RightHand;
                                    Open(leftInv, equipment, rightInv, leftName, rightName);
                                }
                                else if (active.GetData().slot == Tapestry_EquipSlot.BothHands && (leftClickLastFrame || rightClickLastFrame))
                                {
                                    player.Equip(active.GetData(), Tapestry_EquipSlot.BothHands);
                                    active.SetEquippedState(3);
                                    active.equippedInSlot = Tapestry_EquipSlot.BothHands;
                                    Open(leftInv, equipment, rightInv, leftName, rightName);
                                }
                                //foreach(Tapestry_UI_InventoryDisplayTextElement te in left.elements)
                                //{
                                //    if(te.GetData() != player.equippedLeft && te.GetData() != player.equippedRight)
                                //        te.SetEquippedState(0);
                                //}
                            }
                        }
                        else
                        {
                            if (active.GetData().useEffect)
                            {
                                player.AddEffect(active.GetData().effect);
                                leftInv.RemoveItem(active.GetData(), 1);
                                Open(leftInv, equipment, rightInv, leftName, rightName);
                            }
                        }
                    }
                    else
                    {
                        rightInv.AddItem(active.GetData(), 1);
                        leftInv.RemoveItem(active.GetData(), 1);
                        Open(leftInv, null, rightInv, leftName, rightName);
                    }
                }
            }
        }

        //End of frame
        activateLastFrame   = activate;
        leftClickLastFrame  = leftClick;
        rightClickLastFrame = rightClick;
    }