Example #1
0
    public void PutItemToBody(BodySlot slot, Item item)
    {
        // unequip existing item on specified slot
        // if item count is too large
        if (item.Count > 1)
        {
            // put excessive items back to pack
            Item newitem = new Item(item, 1);
            item.Count--;
            ItemsPack.PutItem(ItemsPack.Count, item);
            item = newitem;
        }

        Item currentItem = GetItemFromBody(slot);

        if (currentItem != null)
        {
            ItemsPack.PutItem(ItemsPack.Count, ItemsBody.TakeItem(currentItem, 1));
        }

        if (item.Class.Option.TwoHanded == 2)
        {
            // unequip shield for 2-handed weapon
            Item shield = GetItemFromBody(BodySlot.Shield);
            if (shield != null)
            {
                ItemsPack.PutItem(ItemsPack.Count, ItemsBody.TakeItem(shield, 1));
            }
        }

        ItemsBody.PutItem(ItemsBody.Count, item);
        UpdateItems();
        DoUpdateInfo = true;
    }
Example #2
0
    private void PlaceItem(GridItem item)
    {
        if (item.Orientation == GridItemOrient.Landscape)
        {
            item.Sprite.pivot = UIWidget.Pivot.BottomLeft;
        }
        else
        {
            item.Sprite.pivot = UIWidget.Pivot.TopLeft;
        }

        item.Sprite.transform.parent = item.Boundary.transform.parent;
        item.Sprite.depth            = (int)InventoryItemDepth.Normal;

        item.transform.localPosition = item.Boundary.transform.localPosition;
        InventoryGrid grid = item.transform.parent.GetComponent <InventoryGrid>();

        grid.GetColumnRowFromLocalPos(item.transform.localPosition, out item.ColumnPos, out item.RowPos);

        item.Quantity.transform.parent        = item.Sprite.transform.parent;
        item.Quantity.transform.localPosition = item.Sprite.transform.localPosition + new Vector3(4, 4, 0);

        NGUITools.AddWidgetCollider(item.gameObject);
        NGUITools.MarkParentAsChanged(_windowPanel.gameObject);
        //item.State = GridItemState.None;
        item.Initialize(FocusedGrid);
        FocusedGrid.Items.Add(item);

        SelectedItem    = null;
        FocusedBodySlot = null;

        GameManager.Inst.SoundManager.UI.PlayOneShot(GameManager.Inst.SoundManager.GetClip("PlaceItemBackpack"), 0.2f);
    }
Example #3
0
    void PrepareBodyParts()
    {
        status = new PlayerStatus();

        headslot = new HeadSlot();
        bodyslot = new BodySlot();
        larmslot = new LeftArmSlot();
        rarmslot = new RightArmSlot();
        llegslot = new LeftLegSlot();
        rlegslot = new RightLegSlot();

        partslot = new Dictionary <string, BodypartSlot> {
            { "head", headslot },
            { "body", bodyslot },
            { "leftarm", larmslot },
            { "rightarm", rarmslot },
            { "leftleg", llegslot },
            { "rightleg", rlegslot }
        };

        headslot.ConnectPart(new Head());
        bodyslot.ConnectPart(new Body());
        larmslot.ConnectPart(new LeftArm());
        rarmslot.ConnectPart(new RightArm());
        llegslot.ConnectPart(new LeftLeg());
        rlegslot.ConnectPart(new RightLeg());
    }
Example #4
0
 private void PlaceItemInBodySlot(GridItem item)
 {
     AddItemToBodySlot(item, FocusedBodySlot);
     NGUITools.MarkParentAsChanged(_windowPanel.gameObject);
     SelectedItem    = null;
     FocusedBodySlot = null;
     if (item.Item.Type == ItemType.PrimaryWeapon || item.Item.Type == ItemType.SideArm)
     {
         if ((bool)item.Item.GetAttributeByName("_IsRanged").Value == true)
         {
             GameManager.Inst.SoundManager.UI.PlayOneShot(GameManager.Inst.SoundManager.GetClip("PlaceItemWeaponBody"), 0.1f);
         }
         else
         {
             GameManager.Inst.SoundManager.UI.PlayOneShot(GameManager.Inst.SoundManager.GetClip("PlaceItemMeleeBody"), 0.1f);
         }
     }
     else if (item.Item.Type == ItemType.Armor)
     {
         GameManager.Inst.SoundManager.UI.PlayOneShot(GameManager.Inst.SoundManager.GetClip("PlaceItemArmorBody"), 0.1f);
     }
     else
     {
         GameManager.Inst.SoundManager.UI.PlayOneShot(GameManager.Inst.SoundManager.GetClip("PlaceItemBody"), 0.1f);
     }
 }
Example #5
0
    public Item TakeItemFromBody(BodySlot slot)
    {
        Item item = ItemsBody.TakeItem(ItemsBody.FindItemBySlot(slot), 1);

        UpdateItems();
        DoUpdateInfo = true;
        return(item);
    }
Example #6
0
 public static GamePath Est(ObjectType type, EquipSlot equip, BodySlot slot)
 {
     return(type switch
     {
         ObjectType.Equipment => equip switch
         {
             EquipSlot.Body => GamePath.GenerateUnchecked("chara/xls/charadb/extra_top.est"),
             EquipSlot.Head => GamePath.GenerateUnchecked("chara/xls/charadb/extra_met.est"),
             _ => throw new NotImplementedException()
         },
Example #7
0
    public bool ChangeGear(string slotName, ItemData item)
    {
        BodySlot slot = GetSlot(slotName);

        if (slot == null)
        {
            Debug.Log("Slot Name does not exsist");
            return(false);
        }
        return(slot.TryChange(item));
    }
Example #8
0
 public static string ToSuffix(this BodySlot value)
 {
     return(value switch
     {
         BodySlot.Zear => "zear",
         BodySlot.Face => "face",
         BodySlot.Hair => "hair",
         BodySlot.Body => "body",
         BodySlot.Tail => "tail",
         _ => throw new InvalidEnumArgumentException()
     });
Example #9
0
    public ItemData GetItemInSlot(string slotName)
    {
        BodySlot bs = GetSlot(slotName);

        if (bs == null)
        {
            return(null);
        }
        else
        {
            return(bs.GetItem());
        }
    }
Example #10
0
        public BodyPart(string name, BodySlot type, int health, int attackPenalty)
        {
            Name = name;
            Type = type;

            if (health <= 0)
            {
                health = 1;
            }
            Health    = health;
            MaxHealth = health;

            TargettingPenalty = attackPenalty;
        }
Example #11
0
    public GameObject GetPickable(HorseItem.Type type, bool showName = false, bool destroyOnPick = true)
    {
        HorseItem item = Get(type);

        if (!item)
        {
            return(null);
        }

        GameObject go = Instantiate(pickablePrefab.gameObject);

        go.name                    = type.ToString();
        go.transform.parent        = null;
        go.transform.position      = Vector3.zero;
        go.transform.localRotation = Quaternion.identity;
        go.transform.localScale    = Vector3.one;
        go.AddComponent <InteractionType>().type = InteractionType.Type.pickableHorse;
        HorseItem.Copy(item, go.AddComponent <HorseItem>());
        go.SetActive(true);

        SkinnedMeshRenderer        skin     = item.gameObject.GetComponent <SkinnedMeshRenderer>();
        SpecialPickableShopArsenal pickable = go.GetComponent <SpecialPickableShopArsenal>();

        pickable.textmesh.text = go.name;
        if (go.name.Length >= 8)
        {
            pickable.textmesh.characterSize *= 0.5f;
        }
        pickable.itemMesh.gameObject.SetActive(false);
        pickable.body.gameObject.SetActive(false);

        pickable.horse.gameObject.SetActive(true);
        if (skin)
        {
            BodySlot.CopySkinnedMesh(skin, pickable.horse);
        }
        else
        {
            pickable.horse.gameObject.SetActive(false);
        }

        pickable.textmesh.gameObject.SetActive(showName);
        go.GetComponent <Item>().destroyOnPick = destroyOnPick;

        return(go);
    }
Example #12
0
    public void ApplyBodyData(BodySlot slot, SpriteMesh spriteMesh, ColorMask colors)
    {
        if (!slot)
        {
            return;
        }

        SpriteMeshRenderer renderer;

        if (_bodyRendererDict.TryGetValue(slot, out renderer) && renderer)
        {
            renderer.SetProperties(spriteMesh, colors);
        }
        else
        {
            Debug.LogError("Character does not have part for slot: " + slot, this);
        }
    }
Example #13
0
        private Transform getPlacement(BodySlot slot)
        {
            switch (slot)
            {
            case BodySlot.BACK:
                return(backPlace);

            case BodySlot.CHEST:
                return(chestPlace);

            case BodySlot.HEAD:
                return(hairPlace);

            case BodySlot.LEFT_FOREARM:
                return(leftForearmPlace);

            case BodySlot.LEFT_HAND:
                return(leftHandPlace);

            case BodySlot.LEFT_LEG:
                return(leftLegPlace);

            case BodySlot.LEFT_SHIN:
                return(leftShinPlace);

            case BodySlot.NOSE:
                return(eyesPlace);

            case BodySlot.RIGHT_FOREARM:
                return(rightForearmPlace);

            case BodySlot.RIGHT_HAND:
                return(rightHandPlace);

            case BodySlot.RIGHT_LEG:
                return(rightLegPlace);

            case BodySlot.RIGHT_SHIN:
                return(rightShinPlace);

            default:
                return(gameObject.transform);
            }
        }
Example #14
0
    private bool FindNearestBodySlot(out BodySlot fitSlot, Vector3 centerPos, List <BodySlot> bodySlots, ItemType itemType)
    {
        fitSlot = null;

        foreach (BodySlot slot in bodySlots)
        {
            if (centerPos.x >= slot.transform.localPosition.x - slot.Background.width / 2 && centerPos.x <= slot.transform.localPosition.x + slot.Background.width / 2 &&
                centerPos.y >= slot.transform.localPosition.y - slot.Background.height / 2 && centerPos.y <= slot.transform.localPosition.y + slot.Background.height / 2)
            {
                if (itemType == slot.AllowedItemType || (itemType == ItemType.Ammo && (slot.AllowedItemType == ItemType.PrimaryWeapon || slot.AllowedItemType == ItemType.SideArm)))
                {
                    fitSlot = slot;
                    return(true);
                }
            }
        }

        return(false);
    }
Example #15
0
    private void PickupItem(GridItem item)
    {
        //find out who's the item's container
        GameObject container = item.transform.parent.gameObject;


        if (container.GetComponent <InventoryGrid>() != null)
        {
            _selectedItemLastList = container.GetComponent <InventoryGrid>().Items;

            //if it's not owned by player, don't let player pick up rubles
            if (!container.GetComponent <InventoryGrid>().IsPlayerOwned&& item.Item.ID == "rubles")
            {
                return;
            }
        }
        else if (container.GetComponent <BodySlot>() != null)
        {
            _selectedItemLastList = container.GetComponent <BodySlot>().Items;
        }
        else if (container.GetComponent <TempSlot>() != null)
        {
            _selectedItemLastList = container.GetComponent <TempSlot>().Items;
        }

        SelectedItem        = item;
        item.Boundary.alpha = 0;
        NormalizeItemSpriteSize(item);
        item.Sprite.pivot              = UIWidget.Pivot.Center;
        item.Sprite.transform.parent   = _windowPanel.SelectedItemPanel.transform;
        item.Sprite.depth              = (int)InventoryItemDepth.Selected;
        item.Quantity.depth            = item.Sprite.depth + 1;
        item.Quantity.transform.parent = item.Sprite.transform.parent;
        //item.Sprite.panel = GameManager.Inst.UIManager.WindowPanel.SelectedItemPanel;
        NGUITools.MarkParentAsChanged(_windowPanel.gameObject);
        NGUITools.AddWidgetCollider(item.gameObject);
        item.State      = GridItemState.Selected;
        FocusedBodySlot = null;

        GameManager.Inst.SoundManager.UI.PlayOneShot(GameManager.Inst.SoundManager.GetClip("SelectItem"), 0.1f);
    }
Example #16
0
    public void AddItemToBodySlot(GridItem item, BodySlot slot)
    {
        item.Sprite.pivot = UIWidget.Pivot.Center;

        item.Sprite.transform.parent = item.Boundary.transform.parent;

        if (item.IsRotatable)
        {
            if (item.Item.Type == ItemType.PrimaryWeapon || item.Item.Type == ItemType.SideArm)
            {
                if (item.Orientation == GridItemOrient.Landscape)
                {
                    int temp = item.ColumnSize;
                    item.ColumnSize = item.RowSize;
                    item.RowSize    = temp;

                    item.Orientation = GridItemOrient.Portrait;
                    item.transform.localEulerAngles = new Vector3(0, 0, 90);
                }

                if (((float)item.ColumnSize) / ((float)item.RowSize) < 0.4f)
                {
                    item.Sprite.width  = slot.Background.height;
                    item.Sprite.height = Mathf.FloorToInt(item.Sprite.width * ((item.ColumnSize * 1f) / item.RowSize));
                }
                else
                {
                    item.Sprite.width  = slot.Background.width;
                    item.Sprite.height = Mathf.FloorToInt(item.Sprite.width * ((item.ColumnSize * 1f) / item.RowSize));
                }
            }
            else if (item.Item.Type == ItemType.Armor)
            {
                if (item.Orientation == GridItemOrient.Portrait)
                {
                    int temp = item.ColumnSize;
                    item.ColumnSize = item.RowSize;
                    item.RowSize    = temp;

                    item.Orientation = GridItemOrient.Landscape;
                    item.transform.localEulerAngles = new Vector3(0, 0, 0);
                }

                item.Sprite.width  = slot.Background.width;
                item.Sprite.height = Mathf.FloorToInt(item.Sprite.width * ((item.RowSize * 1f) / item.ColumnSize));
            }
            else if (item.Item.Type == ItemType.Thrown || item.Item.Type == ItemType.Tool)
            {
                if (item.Orientation == GridItemOrient.Portrait)
                {
                    int temp = item.ColumnSize;
                    item.ColumnSize = item.RowSize;
                    item.RowSize    = temp;

                    item.Orientation = GridItemOrient.Landscape;
                    item.transform.localEulerAngles = new Vector3(0, 0, 0);
                }

                item.Sprite.height = slot.Background.height;
                item.Sprite.width  = Mathf.FloorToInt(item.Sprite.height * ((item.ColumnSize * 1f) / item.RowSize));
            }
        }
        else
        {
            item.Sprite.width  = slot.Background.width;
            item.Sprite.height = item.Sprite.width;
        }

        item.Boundary.width  = slot.Background.width - 10;
        item.Boundary.height = slot.Background.height - 10;

        item.Sprite.depth            = (int)InventoryItemDepth.Normal;
        item.transform.localPosition = item.Boundary.transform.localPosition;
        NGUITools.AddWidgetCollider(item.gameObject);
        item.State = GridItemState.None;

        slot.Items.Add(item);
        item.IsPlayerOwned = true;
        item.ClearParentGrid();
    }
Example #17
0
	private void PlaceItem(GridItem item)
	{
		if(item.Orientation == GridItemOrient.Landscape)
		{
			item.Sprite.pivot = UIWidget.Pivot.BottomLeft;
		}
		else
		{
			item.Sprite.pivot = UIWidget.Pivot.TopLeft;
		}

		item.Sprite.transform.parent = item.Boundary.transform.parent;
		item.Sprite.depth = (int)InventoryItemDepth.Normal;

		item.transform.localPosition = item.Boundary.transform.localPosition;
		InventoryGrid grid = item.transform.parent.GetComponent<InventoryGrid>();
		grid.GetColumnRowFromLocalPos(item.transform.localPosition, out item.ColumnPos, out item.RowPos);

		item.Quantity.transform.parent = item.Sprite.transform.parent;
		item.Quantity.transform.localPosition = item.Sprite.transform.localPosition + new Vector3(4, 4, 0);

		NGUITools.AddWidgetCollider(item.gameObject);
		NGUITools.MarkParentAsChanged(_windowPanel.gameObject);
		item.State = GridItemState.None;

		FocusedGrid.Items.Add(item);

		SelectedItem = null;
		FocusedBodySlot = null;
	}
Example #18
0
    public void OnPlaceItem(GridItem item)
    {
        if (SelectedItem == item && item.Boundary.alpha == 1)
        {
            if (FocusedTempSlot != null)
            {
                //place in temp slot
                GridItem existingItem = null;
                TempSlot temp         = FocusedTempSlot;
                if (FocusedTempSlot.Items.Count > 0)
                {
                    existingItem = FocusedTempSlot.Items[0];
                }
                FocusedTempSlot.Items.Clear();

                PlaceItemInTempSlot(item);

                if (_selectedItemLastList != null && _selectedItemLastList != temp.Items)
                {
                    _selectedItemLastList.Remove(item);
                    _selectedItemLastList = null;
                }

                if (existingItem != null && existingItem != item)
                {
                    PickupItem(existingItem);
                }
            }
            else if (FocusedBodySlot != null)
            {
                //place in body slot
                GridItem existingItem = null;
                BodySlot temp         = FocusedBodySlot;
                if (FocusedBodySlot.Items.Count > 0)
                {
                    existingItem = FocusedBodySlot.Items[0];
                }


                if (item.Item.Type == ItemType.Ammo && (FocusedBodySlot.AllowedItemType == ItemType.PrimaryWeapon || FocusedBodySlot.AllowedItemType == ItemType.SideArm))
                {
                    if (existingItem != null && (int)existingItem.Item.GetAttributeByName("_LoadedAmmos").Value <= 0 &&
                        (string)item.Item.GetAttributeByName("_Caliber").Value == (string)existingItem.Item.GetAttributeByName("_Caliber").Value)
                    {
                        existingItem.Item.SetAttribute("_LoadedAmmoID", item.Item.ID);
                        GameManager.Inst.UIManager.SetConsoleText("The weapon is now loading " + item.Item.Name);
                        GameManager.Inst.SoundManager.UI.PlayOneShot(GameManager.Inst.SoundManager.GetClip("LoadAmmo"), 0.05f);
                    }
                    else if ((int)existingItem.Item.GetAttributeByName("_LoadedAmmos").Value > 0)
                    {
                        GameManager.Inst.UIManager.SetConsoleText("Weapon is still loaded, unload ammo first.");
                        GameManager.Inst.SoundManager.UI.PlayOneShot(GameManager.Inst.SoundManager.GetClip("Error1"), 0.05f);
                    }
                    else if ((string)item.Item.GetAttributeByName("_Caliber").Value != (string)existingItem.Item.GetAttributeByName("_Caliber").Value)
                    {
                        GameManager.Inst.UIManager.SetConsoleText("Caliber doesn't match!");
                        GameManager.Inst.SoundManager.UI.PlayOneShot(GameManager.Inst.SoundManager.GetClip("Error1"), 0.05f);
                    }
                }
                else
                {
                    FocusedBodySlot.Items.Clear();
                    PlaceItemInBodySlot(item);

                    if (_selectedItemLastList != null && _selectedItemLastList != temp.Items)
                    {
                        _selectedItemLastList.Remove(item);
                        _selectedItemLastList = null;
                    }


                    if (existingItem != null && existingItem != item)
                    {
                        PickupItem(existingItem);
                    }
                }
            }
            else if (FocusedGrid != null)
            {
                PlaceItem(item);

                if (_selectedItemLastList != null)
                {
                    _selectedItemLastList.Remove(item);
                    _selectedItemLastList = null;
                }

                if (ReplaceItem != null)
                {
                    Debug.Log("Replace item is not null");
                    //if replace item is same as item then try to combine the two
                    if (ReplaceItem.Item.ID == item.Item.ID && item.Item.MaxStackSize > 1)
                    {
                        int fill = item.Item.MaxStackSize - item.GetQuantity();
                        if (fill < ReplaceItem.GetQuantity())
                        {
                            item.SetQuantity(item.Item.MaxStackSize);
                            ReplaceItem.SetQuantity(ReplaceItem.GetQuantity() - fill);

                            PickupItem(ReplaceItem);
                            ReplaceItem.Sprite.alpha = 1;
                            ReplaceItem = null;
                        }
                        else
                        {
                            item.SetQuantity(item.GetQuantity() + ReplaceItem.GetQuantity());
                            FocusedGrid.Items.Remove(ReplaceItem);
                            DestroyItem(ReplaceItem);
                        }

                        RefreshItemTotals();

                        return;
                    }

                    //if replace item is not the same, but selected item is ammo and replace item is an empty gun that can use the ammo
                    //then load the gun with ammo
                    if (item.Item.Type == ItemType.Ammo && (ReplaceItem.Item.Type == ItemType.PrimaryWeapon || ReplaceItem.Item.Type == ItemType.SideArm))
                    {
                        if ((bool)ReplaceItem.Item.GetAttributeByName("_IsRanged").Value == true)
                        {
                            if ((int)ReplaceItem.Item.GetAttributeByName("_LoadedAmmos").Value <= 0 &&
                                (string)item.Item.GetAttributeByName("_Caliber").Value == (string)ReplaceItem.Item.GetAttributeByName("_Caliber").Value)
                            {
                                ReplaceItem.Item.SetAttribute("_LoadedAmmoID", item.Item.ID);
                                GameManager.Inst.UIManager.SetConsoleText("The weapon is now loading " + item.Item.Name);
                                GameManager.Inst.SoundManager.UI.PlayOneShot(GameManager.Inst.SoundManager.GetClip("LoadAmmo"), 0.05f);
                            }
                            else if ((int)ReplaceItem.Item.GetAttributeByName("_LoadedAmmos").Value > 0)
                            {
                                GameManager.Inst.UIManager.SetConsoleText("Weapon is still loaded, unload ammo first.");
                                GameManager.Inst.SoundManager.UI.PlayOneShot(GameManager.Inst.SoundManager.GetClip("Error1"), 0.05f);
                            }
                            else if ((string)item.Item.GetAttributeByName("_Caliber").Value != (string)ReplaceItem.Item.GetAttributeByName("_Caliber").Value)
                            {
                                GameManager.Inst.UIManager.SetConsoleText("Caliber doesn't match!");
                                GameManager.Inst.SoundManager.UI.PlayOneShot(GameManager.Inst.SoundManager.GetClip("Error1"), 0.05f);
                            }

                            PickupItem(item);
                            RefreshItemTotals();
                            return;
                        }
                    }


                    PickupItem(ReplaceItem);
                    ReplaceItem.Sprite.alpha = 1;
                    ReplaceItem = null;
                }
            }
        }

        RefreshItemTotals();
    }
Example #19
0
    public override void PerFrameUpdate()
    {
        //make item sprite follow cursor
        if (SelectedItem != null)
        {
            Vector3 pos = Input.mousePosition;
            pos.x = Mathf.Clamp01(pos.x / Screen.width);
            pos.y = Mathf.Clamp01(pos.y / Screen.height);
            SelectedItem.Sprite.transform.position        = GameManager.Inst.UIManager.UICamera.ViewportToWorldPoint(pos);
            SelectedItem.Quantity.transform.localPosition = SelectedItem.Sprite.transform.localPosition
                                                            - new Vector3(SelectedItem.ColumnSize * BackpackGrid.BlockSize / 2f - 4, SelectedItem.RowSize * BackpackGrid.BlockSize / 2f - 4);
            Vector3 centerPos = SelectedItem.Sprite.transform.localPosition;

            //find nearest fitting slot for selected item and move the boundary there
            int fitColumn = 0;
            int fitRow    = 0;


            List <InventoryGrid> grids = _windowPanel.FindInventoryGrids();
            if (FindNearestGridSlot(grids, out fitColumn, out fitRow, SelectedItem.IsPlayerOwned))
            {
                SelectedItem.Boundary.transform.parent = FocusedGrid.transform;
                if (SelectedItem.Orientation == GridItemOrient.Landscape)
                {
                    SelectedItem.Boundary.pivot = UIWidget.Pivot.BottomLeft;
                }
                else
                {
                    SelectedItem.Boundary.pivot = UIWidget.Pivot.TopLeft;
                }

                SelectedItem.Boundary.transform.localEulerAngles = SelectedItem.Sprite.transform.localEulerAngles;

                SelectedItem.Boundary.width  = SelectedItem.Sprite.width;
                SelectedItem.Boundary.height = SelectedItem.Sprite.height;
                SelectedItem.Boundary.transform.localPosition = new Vector3(fitColumn * BackpackGrid.BlockSize, fitRow * BackpackGrid.BlockSize, 0);
                SelectedItem.Boundary.alpha = 1;
                SelectedItem.ColumnPos      = fitColumn;
                SelectedItem.RowPos         = fitRow;

                FocusedBodySlot = null;
            }
            else
            {
                SelectedItem.Boundary.alpha = 0;
                FocusedBodySlot             = null;
                if (ReplaceItem != null)
                {
                    ReplaceItem.Sprite.alpha = 1;
                }
            }

            List <BodySlot> bodySlots = _windowPanel.FindBodySlots();
            BodySlot        fitSlot;
            if (bodySlots.Count > 0)
            {
                if (FindNearestBodySlot(out fitSlot, centerPos, bodySlots, SelectedItem.Item.Type))
                {
                    FocusedBodySlot = fitSlot;
                    SelectedItem.Boundary.transform.parent           = FocusedBodySlot.transform;
                    SelectedItem.Boundary.pivot                      = UIWidget.Pivot.Center;
                    SelectedItem.Boundary.transform.localEulerAngles = Vector3.zero;

                    SelectedItem.Boundary.width  = FocusedBodySlot.Background.width - 10;
                    SelectedItem.Boundary.height = FocusedBodySlot.Background.height - 10;
                    SelectedItem.Boundary.transform.localPosition = Vector3.zero;


                    SelectedItem.Boundary.alpha = 1;
                }
                else
                {
                    FocusedBodySlot = null;
                }
            }

            List <TempSlot> tempSlots = _windowPanel.FindTempSlots();
            TempSlot        tempSlot;
            if (tempSlots.Count > 0)
            {
                if (FindNearestTempSlot(out tempSlot, centerPos, tempSlots))
                {
                    FocusedTempSlot = tempSlot;
                    SelectedItem.Boundary.transform.parent           = FocusedTempSlot.transform;
                    SelectedItem.Boundary.pivot                      = UIWidget.Pivot.Center;
                    SelectedItem.Boundary.transform.localEulerAngles = Vector3.zero;

                    SelectedItem.Boundary.width  = FocusedTempSlot.Background.width - 10;
                    SelectedItem.Boundary.height = FocusedTempSlot.Background.height - 10;
                    SelectedItem.Boundary.transform.localPosition = Vector3.zero;


                    SelectedItem.Boundary.alpha = 1;
                }
                else
                {
                    FocusedTempSlot = null;
                }
            }
        }
    }
Example #20
0
 public static GameObjectInfo Customization(FileType type, CustomizationType customizationType, ushort id = 0
                                            , GenderRace gr = GenderRace.Unknown, BodySlot bodySlot = BodySlot.Unknown, byte variant = 0)
 => new()
Example #21
0
 public RPGItem GetBodyItem(BodySlot slot)
 {
     return(GetBodyItem((int)slot));
 }
Example #22
0
	private bool FindNearestBodySlot(out BodySlot fitSlot, Vector3 centerPos, List<BodySlot> bodySlots, ItemType itemType)
	{

		fitSlot = null;

		foreach(BodySlot slot in bodySlots)
		{
			if(centerPos.x >= slot.transform.localPosition.x - slot.Background.width/2 && centerPos.x <= slot.transform.localPosition.x + slot.Background.width/2 &&
				centerPos.y >= slot.transform.localPosition.y - slot.Background.height/2 && centerPos.y <= slot.transform.localPosition.y + slot.Background.height/2)
			{
				if(itemType == slot.AllowedItemType || (itemType == ItemType.Ammo && (slot.AllowedItemType == ItemType.PrimaryWeapon || slot.AllowedItemType == ItemType.SideArm)))
				{
					fitSlot = slot;
					return true;
				}
			}
		}

		return false;
	}
Example #23
0
    private void InstanciateShop()
    {
        GameObject shopContainer = new GameObject("shopContainer");

        shopContainer.transform.parent        = transform;
        shopContainer.transform.localPosition = Vector3.zero;
        shopContainer.transform.localRotation = Quaternion.identity;
        shopContainer.transform.localScale    = Vector3.one;
        shopContainer.SetActive(true);

        if (export_csv)
        {
            file_csv += "Arsenal items\n" +
                        "Name;Load;Dammage;Armor;Capacity;Wood;Wheat;Stone;Iron;Gold;Crystal\n";
        }

        // backpack
        Vector3 position = Vector3.zero;

        {
            GameObject go = Instantiate(pickablePrefab.gameObject);
            go.name                    = BackpackItem.Type.None.ToString();
            go.transform.parent        = shopContainer.transform;
            go.transform.localRotation = Quaternion.identity;
            go.transform.localScale    = Vector3.one;
            go.transform.localPosition = new Vector3(-2 * gap, position.y, position.z);
            go.AddComponent <InteractionType>().type = InteractionType.Type.pickableBackpack;
            go.AddComponent <BackpackItem>();
            go.SetActive(true);
            SpecialPickableShopArsenal pickable = go.GetComponent <SpecialPickableShopArsenal>();
            pickable.textmesh.text = go.name;
            if (go.name.Length >= 8)
            {
                pickable.textmesh.characterSize *= 0.5f;
            }
            pickable.body.gameObject.SetActive(false);

            if (export_csv)
            {
                file_csv += "\nbackpack items\n";
            }
        }
        foreach (KeyValuePair <BackpackItem.Type, BackpackItem> item in backpackDictionary)
        {
            GameObject go = Instantiate(pickablePrefab.gameObject);
            go.name                    = item.Key.ToString();
            go.transform.parent        = shopContainer.transform;
            go.transform.localRotation = Quaternion.identity;
            go.transform.localScale    = Vector3.one;
            go.transform.localPosition = position;
            go.AddComponent <InteractionType>().type = InteractionType.Type.pickableBackpack;
            BackpackItem.Copy(item.Value, go.AddComponent <BackpackItem>());
            go.SetActive(true);

            MeshFilter mf = item.Value.gameObject.GetComponent <MeshFilter>();
            SpecialPickableShopArsenal pickable = go.GetComponent <SpecialPickableShopArsenal>();
            pickable.textmesh.text = go.name;
            if (go.name.Length >= 8)
            {
                pickable.textmesh.characterSize *= 0.5f;
            }
            if (mf)
            {
                pickable.itemMesh.mesh = mf.mesh;
            }
            else
            {
                pickable.itemMesh.gameObject.SetActive(false);
            }
            pickable.body.gameObject.SetActive(false);

            if (createIcons)
            {
                pickable.textmesh.gameObject.SetActive(false);
                pickable.transform.localEulerAngles = new Vector3(0, 15, 0);
                cameraPivot.position = go.transform.position + new Vector3(-0.13f, 0.6f, 1.1f);

                if (item.Key == BackpackItem.Type.AdventureBackpack)
                {
                    pickable.transform.localEulerAngles = new Vector3(0, 90, 0);
                    cameraPivot.position = go.transform.position + new Vector3(0f, 0.7f, 0.9f);
                }

                CreateIcon(iconFolderPath + "/Backpacks/" + go.name + ".png");
            }
            if (export_csv)
            {
                ItemCost cost = GetCost(item.Value.crafting);
                file_csv += item.Key.ToString() + ";" +
                            item.Value.load.ToString() + ";0;0;" + item.Value.capacity.ToString() + ";" +
                            cost.wood.ToString() + ";" + cost.wheat.ToString() + ";" + cost.stone.ToString() + ";" + cost.iron.ToString() + ";" + cost.gold.ToString() + ";" + cost.crystal.ToString() + "\n";
            }
            position.x += gap;
        }

        // shields
        position.x = 0; position.z -= gap; position.y += gapY;
        {
            GameObject go = Instantiate(pickablePrefab.gameObject);
            go.name                    = ShieldItem.Type.None.ToString();
            go.transform.parent        = shopContainer.transform;
            go.transform.localRotation = Quaternion.identity;
            go.transform.localScale    = Vector3.one;
            go.transform.localPosition = new Vector3(-2 * gap, position.y, position.z);
            go.AddComponent <InteractionType>().type = InteractionType.Type.pickableShield;
            go.AddComponent <ShieldItem>();
            go.SetActive(true);
            SpecialPickableShopArsenal pickable = go.GetComponent <SpecialPickableShopArsenal>();
            pickable.textmesh.text = go.name;
            if (go.name.Length >= 8)
            {
                pickable.textmesh.characterSize *= 0.5f;
            }
            pickable.body.gameObject.SetActive(false);

            if (export_csv)
            {
                file_csv += "\nshield items\n";
            }
        }
        foreach (KeyValuePair <ShieldItem.Type, ShieldItem> item in shieldDictionary)
        {
            GameObject go = Instantiate(pickablePrefab.gameObject);
            go.name                    = item.Key.ToString();
            go.transform.parent        = shopContainer.transform;
            go.transform.localRotation = Quaternion.identity;
            go.transform.localScale    = Vector3.one;
            go.transform.localPosition = position;
            go.AddComponent <InteractionType>().type = InteractionType.Type.pickableShield;
            ShieldItem.Copy(item.Value, go.AddComponent <ShieldItem>());
            go.SetActive(true);

            MeshFilter mf = item.Value.gameObject.GetComponent <MeshFilter>();
            SpecialPickableShopArsenal pickable = go.GetComponent <SpecialPickableShopArsenal>();
            pickable.textmesh.text = go.name;
            if (go.name.Length >= 8)
            {
                pickable.textmesh.characterSize *= 0.5f;
            }
            if (mf)
            {
                pickable.itemMesh.mesh = mf.mesh;
            }
            else
            {
                pickable.itemMesh.gameObject.SetActive(false);
            }
            pickable.body.gameObject.SetActive(false);

            if (createIcons)
            {
                pickable.textmesh.gameObject.SetActive(false);
                pickable.transform.localEulerAngles = new Vector3(0, 30, 0);
                cameraPivot.position = go.transform.position + new Vector3(0f, 0.6f, 1.3f);
                CreateIcon(iconFolderPath + "/Shields/" + go.name + ".png");
            }
            if (export_csv)
            {
                ItemCost cost = GetCost(item.Value.crafting);
                file_csv += item.Key.ToString() + ";" +
                            item.Value.load.ToString() + ";0;" + item.Value.armor.ToString() + ";0;" +
                            cost.wood.ToString() + ";" + cost.wheat.ToString() + ";" + cost.stone.ToString() + ";" + cost.iron.ToString() + ";" + cost.gold.ToString() + ";" + cost.crystal.ToString() + "\n";
            }
            position.x += gap;
        }

        // second hand
        position.x = 0; position.z -= gap; position.y += gapY;
        {
            GameObject go = Instantiate(pickablePrefab.gameObject);
            go.name                    = SecondItem.Type.None.ToString();
            go.transform.parent        = shopContainer.transform;
            go.transform.localRotation = Quaternion.identity;
            go.transform.localScale    = Vector3.one;
            go.transform.localPosition = new Vector3(-2 * gap, position.y, position.z);
            go.AddComponent <InteractionType>().type = InteractionType.Type.pickableSecond;
            go.AddComponent <SecondItem>();
            go.SetActive(true);
            SpecialPickableShopArsenal pickable = go.GetComponent <SpecialPickableShopArsenal>();
            pickable.textmesh.text = go.name;
            if (go.name.Length >= 8)
            {
                pickable.textmesh.characterSize *= 0.5f;
            }
            pickable.body.gameObject.SetActive(false);

            if (export_csv)
            {
                file_csv += "\nsecond hand items\n";
            }
        }
        foreach (KeyValuePair <SecondItem.Type, SecondItem> item in secondDictionary)
        {
            GameObject go = Instantiate(pickablePrefab.gameObject);
            go.name                    = item.Key.ToString();
            go.transform.parent        = shopContainer.transform;
            go.transform.localRotation = Quaternion.identity;
            go.transform.localScale    = Vector3.one;
            go.transform.localPosition = position;
            go.AddComponent <InteractionType>().type = InteractionType.Type.pickableSecond;
            SecondItem.Copy(item.Value, go.AddComponent <SecondItem>());
            go.SetActive(true);

            MeshFilter mf = item.Value.gameObject.GetComponent <MeshFilter>();
            SpecialPickableShopArsenal pickable = go.GetComponent <SpecialPickableShopArsenal>();
            pickable.textmesh.text = go.name;
            if (go.name.Length >= 8)
            {
                pickable.textmesh.characterSize *= 0.5f;
            }
            if (mf)
            {
                pickable.itemMesh.mesh = mf.mesh;
            }
            else
            {
                pickable.itemMesh.gameObject.SetActive(false);
            }
            pickable.body.gameObject.SetActive(false);

            if (createIcons)
            {
                pickable.textmesh.gameObject.SetActive(false);
                pickable.transform.localEulerAngles = new Vector3(0, 0, -42);
                cameraPivot.position = go.transform.position + new Vector3(0.3f, 0.45f, 1.5f);
                CreateIcon(iconFolderPath + "/SecondHands/" + go.name + ".png");
            }
            if (export_csv)
            {
                ItemCost cost = GetCost(item.Value.crafting);
                file_csv += item.Key.ToString() + ";" +
                            item.Value.load.ToString() + ";" + item.Value.dammage.ToString() + ";0;0;" +
                            cost.wood.ToString() + ";" + cost.wheat.ToString() + ";" + cost.stone.ToString() + ";" + cost.iron.ToString() + ";" + cost.gold.ToString() + ";" + cost.crystal.ToString() + "\n";
            }
            position.x += gap;
        }

        // weapons
        position.x = 0; position.z -= gap; position.y += gapY;
        {
            GameObject go = Instantiate(pickablePrefab.gameObject);
            go.name                    = WeaponItem.Type.None.ToString();
            go.transform.parent        = shopContainer.transform;
            go.transform.localRotation = Quaternion.identity;
            go.transform.localScale    = Vector3.one;
            go.transform.localPosition = new Vector3(-2 * gap, position.y, position.z);
            go.AddComponent <InteractionType>().type = InteractionType.Type.pickableWeapon;
            go.AddComponent <WeaponItem>();
            go.SetActive(true);
            SpecialPickableShopArsenal pickable = go.GetComponent <SpecialPickableShopArsenal>();
            pickable.textmesh.text = go.name;
            if (go.name.Length >= 8)
            {
                pickable.textmesh.characterSize *= 0.5f;
            }
            pickable.body.gameObject.SetActive(false);
            if (export_csv)
            {
                file_csv += "\nweapon items\n";
            }
        }
        foreach (KeyValuePair <WeaponItem.Type, WeaponItem> item in weaponDictionary)
        {
            GameObject go = Instantiate(pickablePrefab.gameObject);
            go.name                    = item.Key.ToString();
            go.transform.parent        = shopContainer.transform;
            go.transform.localRotation = Quaternion.identity;
            go.transform.localScale    = Vector3.one;
            go.transform.localPosition = position;
            go.AddComponent <InteractionType>().type = InteractionType.Type.pickableWeapon;
            WeaponItem.Copy(item.Value, go.AddComponent <WeaponItem>());
            go.SetActive(true);

            MeshFilter mf = item.Value.gameObject.GetComponent <MeshFilter>();
            SpecialPickableShopArsenal pickable = go.GetComponent <SpecialPickableShopArsenal>();
            pickable.textmesh.text = go.name;
            if (go.name.Length >= 8)
            {
                pickable.textmesh.characterSize *= 0.5f;
            }
            if (mf)
            {
                pickable.itemMesh.mesh = mf.mesh;
            }
            else
            {
                pickable.itemMesh.gameObject.SetActive(false);
            }
            pickable.body.gameObject.SetActive(false);

            if (createIcons)
            {
                pickable.textmesh.gameObject.SetActive(false);
                pickable.transform.localEulerAngles = new Vector3(0, 0, -42);
                cameraPivot.position = go.transform.position + new Vector3(0.3f, 0.6f, 1.5f);

                if (item.Key == WeaponItem.Type.FireSword)
                {
                    pickable.itemMesh.gameObject.transform.Find("swordFireEffect").gameObject.SetActive(true);
                }
                else if (item.Key == WeaponItem.Type.ElectricSword)
                {
                    pickable.itemMesh.gameObject.transform.Find("swordElectricEffect").gameObject.SetActive(true);
                }

                CreateIcon(iconFolderPath + "/Weapons/" + go.name + ".png");
            }
            if (export_csv)
            {
                ItemCost cost = GetCost(item.Value.crafting);
                file_csv += item.Key.ToString() + ";" +
                            item.Value.load.ToString() + ";" + item.Value.dammage.ToString() + ";0;0;" +
                            cost.wood.ToString() + ";" + cost.wheat.ToString() + ";" + cost.stone.ToString() + ";" + cost.iron.ToString() + ";" + cost.gold.ToString() + ";" + cost.crystal.ToString() + "\n";
            }
            position.x += gap;
        }

        // heads
        position.x = 0; position.z -= gap; position.y += gapY;

        if (export_csv)
        {
            file_csv += "\nhead items\n";
        }
        foreach (KeyValuePair <HeadItem.Type, HeadItem> item in headDictionary)
        {
            GameObject go = Instantiate(pickablePrefab.gameObject);
            go.name                    = item.Key.ToString();
            go.transform.parent        = shopContainer.transform;
            go.transform.localRotation = Quaternion.identity;
            go.transform.localScale    = Vector3.one;
            go.transform.localPosition = position;
            go.AddComponent <InteractionType>().type = InteractionType.Type.pickableHead;
            HeadItem.Copy(item.Value, go.AddComponent <HeadItem>());
            go.SetActive(true);

            MeshFilter mf = item.Value.gameObject.GetComponent <MeshFilter>();
            SpecialPickableShopArsenal pickable = go.GetComponent <SpecialPickableShopArsenal>();
            pickable.textmesh.text = go.name;
            if (go.name.Length >= 8)
            {
                pickable.textmesh.characterSize *= 0.5f;
            }
            if (mf)
            {
                pickable.itemMesh.mesh = mf.mesh;
            }
            else
            {
                pickable.itemMesh.gameObject.SetActive(false);
            }
            pickable.body.gameObject.SetActive(false);

            if (createIcons)
            {
                pickable.textmesh.gameObject.SetActive(false);
                pickable.transform.localEulerAngles = new Vector3(0, 15, 0);
                cameraPivot.position = go.transform.position + new Vector3(0, 0.6f, 1f);
                CreateIcon(iconFolderPath + "/Heads/" + go.name + ".png");
            }
            if (export_csv)
            {
                ItemCost cost = GetCost(item.Value.crafting);
                file_csv += item.Key.ToString() + ";" +
                            item.Value.load.ToString() + ";0;" + item.Value.armor.ToString() + ";0;" +
                            cost.wood.ToString() + ";" + cost.wheat.ToString() + ";" + cost.stone.ToString() + ";" + cost.iron.ToString() + ";" + cost.gold.ToString() + ";" + cost.crystal.ToString() + "\n";
            }
            position.x += gap;
        }

        // bodies
        position.x = 0; position.z -= gap; position.y += gapY;

        if (export_csv)
        {
            file_csv += "\nbody items\n";
        }
        foreach (KeyValuePair <BodyItem.Type, BodyItem> item in bodyDictionary)
        {
            GameObject go = Instantiate(pickablePrefab.gameObject);
            go.name                    = item.Key.ToString();
            go.transform.parent        = shopContainer.transform;
            go.transform.localRotation = Quaternion.identity;
            go.transform.localScale    = Vector3.one;
            go.transform.localPosition = position;
            go.AddComponent <InteractionType>().type = InteractionType.Type.pickableBody;
            BodyItem.Copy(item.Value, go.AddComponent <BodyItem>());
            go.SetActive(true);

            SkinnedMeshRenderer        skin     = item.Value.gameObject.GetComponent <SkinnedMeshRenderer>();
            SpecialPickableShopArsenal pickable = go.GetComponent <SpecialPickableShopArsenal>();
            pickable.textmesh.text = go.name;
            if (go.name.Length >= 8)
            {
                pickable.textmesh.characterSize *= 0.5f;
            }
            pickable.itemMesh.gameObject.SetActive(false);

            if (skin)
            {
                BodySlot.CopySkinnedMesh(skin, pickable.body);
            }
            else
            {
                pickable.body.gameObject.SetActive(false);
            }

            if (createIcons)
            {
                pickable.textmesh.gameObject.SetActive(false);
                pickable.transform.localEulerAngles = new Vector3(0, 15, 0);
                cameraPivot.position = go.transform.position + new Vector3(0, 0.5f, 1.5f);
                CreateIcon(iconFolderPath + "/Bodies/" + go.name + ".png");
            }
            if (export_csv)
            {
                ItemCost cost = GetCost(item.Value.crafting);
                file_csv += item.Key.ToString() + ";" +
                            item.Value.load.ToString() + ";0;" + item.Value.armor.ToString() + ";0;" +
                            cost.wood.ToString() + ";" + cost.wheat.ToString() + ";" + cost.stone.ToString() + ";" + cost.iron.ToString() + ";" + cost.gold.ToString() + ";" + cost.crystal.ToString() + "\n";
            }
            position.x += gap;
        }

        // horses
        position.x = 0; position.z -= 2 * gap; position.y += gapY;
        {
            GameObject go = Instantiate(pickablePrefab.gameObject);
            go.name                    = HorseItem.Type.None.ToString();
            go.transform.parent        = shopContainer.transform;
            go.transform.localRotation = Quaternion.identity;
            go.transform.localScale    = Vector3.one;
            go.transform.localPosition = new Vector3(-2 * gap, position.y, position.z);
            go.AddComponent <InteractionType>().type = InteractionType.Type.pickableHorse;
            go.AddComponent <HorseItem>();
            go.SetActive(true);
            SpecialPickableShopArsenal pickable = go.GetComponent <SpecialPickableShopArsenal>();
            pickable.textmesh.text = go.name;
            if (go.name.Length >= 8)
            {
                pickable.textmesh.characterSize *= 0.5f;
            }
            pickable.body.gameObject.SetActive(false);

            if (export_csv)
            {
                file_csv += "\nhorse items\n";
            }
        }
        foreach (KeyValuePair <HorseItem.Type, HorseItem> item in horseDictionary)
        {
            GameObject go = Instantiate(pickablePrefab.gameObject);
            go.name                    = item.Key.ToString();
            go.transform.parent        = shopContainer.transform;
            go.transform.localRotation = Quaternion.identity;
            go.transform.localScale    = Vector3.one;
            go.transform.localPosition = position;
            go.AddComponent <InteractionType>().type = InteractionType.Type.pickableHorse;
            HorseItem.Copy(item.Value, go.AddComponent <HorseItem>());
            go.SetActive(true);

            SkinnedMeshRenderer        skin     = item.Value.gameObject.GetComponent <SkinnedMeshRenderer>();
            SpecialPickableShopArsenal pickable = go.GetComponent <SpecialPickableShopArsenal>();
            pickable.textmesh.text = go.name;
            if (go.name.Length >= 8)
            {
                pickable.textmesh.characterSize *= 0.5f;
            }
            pickable.itemMesh.gameObject.SetActive(false);

            if (skin)
            {
                BodySlot.CopySkinnedMesh(skin, pickable.horse);
            }
            else
            {
                pickable.horse.gameObject.SetActive(false);
            }
            pickable.horse.gameObject.SetActive(true);
            pickable.body.gameObject.SetActive(false);

            if (createIcons)
            {
                pickable.textmesh.gameObject.SetActive(false);
                pickable.transform.localEulerAngles = new Vector3(0, 90, 0);
                cameraPivot.position = go.transform.position + new Vector3(0, 1, 3f);
                CreateIcon(iconFolderPath + "/Horses/" + go.name + ".png");
            }
            if (export_csv)
            {
                file_csv += item.Key.ToString() + ";" + item.Value.load.ToString() + ";0;" + item.Value.armor.ToString() + ";0;0;0;0;0;0;0\n";
            }
            position.x += gap;
        }



        if (export_csv)
        {
            StreamWriter writer = new StreamWriter("Assets/Resources/arsenal.csv", false);
            writer.WriteLine(file_csv);
            writer.Close();
        }
    }
Example #24
0
 public Item GetItemFromBody(BodySlot slot)
 {
     return(ItemsBody.FindItemBySlot(slot));
 }
Example #25
0
	private void PickupItem(GridItem item)
	{
		//find out who's the item's container
		GameObject container = item.transform.parent.gameObject;


		if(container.GetComponent<InventoryGrid>() != null)
		{
			_selectedItemLastList = container.GetComponent<InventoryGrid>().Items;
		}
		else if(container.GetComponent<BodySlot>() != null)
		{
			_selectedItemLastList = container.GetComponent<BodySlot>().Items;
		}
		else if(container.GetComponent<TempSlot>() != null)
		{
			_selectedItemLastList = container.GetComponent<TempSlot>().Items;
		}

		SelectedItem = item;
		item.Boundary.alpha = 0;
		NormalizeItemSpriteSize(item);
		item.Sprite.pivot = UIWidget.Pivot.Center;
		item.Sprite.transform.parent = _windowPanel.SelectedItemPanel.transform;
		item.Sprite.depth = (int)InventoryItemDepth.Selected;
		item.Quantity.depth = item.Sprite.depth + 1;
		item.Quantity.transform.parent = item.Sprite.transform.parent;
		//item.Sprite.panel = GameManager.Inst.UIManager.WindowPanel.SelectedItemPanel;
		NGUITools.MarkParentAsChanged(_windowPanel.gameObject);
		NGUITools.AddWidgetCollider(item.gameObject);
		item.State = GridItemState.Selected;
		FocusedBodySlot = null;
	}
Example #26
0
 public RPGItem RemoveBodyItem(BodySlot slot)
 {
     return(RemoveBodyItem((int)slot));
 }
Example #27
0
	public override void PerFrameUpdate ()
	{
		//make item sprite follow cursor
		if(SelectedItem != null)
		{
			Vector3 pos = Input.mousePosition;
			pos.x = Mathf.Clamp01(pos.x / Screen.width);
			pos.y = Mathf.Clamp01(pos.y / Screen.height);
			SelectedItem.Sprite.transform.position = GameManager.Inst.UIManager.UICamera.ViewportToWorldPoint(pos);
			SelectedItem.Quantity.transform.localPosition = SelectedItem.Sprite.transform.localPosition 
				- new Vector3(SelectedItem.ColumnSize * BackpackGrid.BlockSize / 2f - 4, SelectedItem.RowSize * BackpackGrid.BlockSize / 2f - 4);
			Vector3 centerPos = SelectedItem.Sprite.transform.localPosition;

			//find nearest fitting slot for selected item and move the boundary there
			int fitColumn = 0;
			int fitRow = 0;


			List<InventoryGrid> grids = _windowPanel.FindInventoryGrids();
			if(FindNearestGridSlot(grids, out fitColumn, out fitRow))
			{
				SelectedItem.Boundary.transform.parent = FocusedGrid.transform;
				if(SelectedItem.Orientation == GridItemOrient.Landscape)
				{
					SelectedItem.Boundary.pivot = UIWidget.Pivot.BottomLeft;
				}
				else
				{
					SelectedItem.Boundary.pivot = UIWidget.Pivot.TopLeft;
				}

				SelectedItem.Boundary.transform.localEulerAngles = SelectedItem.Sprite.transform.localEulerAngles;

				SelectedItem.Boundary.width = SelectedItem.Sprite.width;
				SelectedItem.Boundary.height = SelectedItem.Sprite.height;
				SelectedItem.Boundary.transform.localPosition = new Vector3(fitColumn * BackpackGrid.BlockSize, fitRow * BackpackGrid.BlockSize, 0);
				SelectedItem.Boundary.alpha = 1;
				SelectedItem.ColumnPos = fitColumn;
				SelectedItem.RowPos = fitRow;

				FocusedBodySlot = null;
			}
			else
			{
				SelectedItem.Boundary.alpha = 0;
				FocusedBodySlot = null;
				if(ReplaceItem != null)
				{
					ReplaceItem.Sprite.alpha = 1;
				}
			}

			List<BodySlot> bodySlots = _windowPanel.FindBodySlots();
			BodySlot fitSlot;
			if(bodySlots.Count > 0)
			{

				if(FindNearestBodySlot(out fitSlot, centerPos, bodySlots, SelectedItem.Item.Type))
				{
					FocusedBodySlot = fitSlot;
					SelectedItem.Boundary.transform.parent = FocusedBodySlot.transform;
					SelectedItem.Boundary.pivot = UIWidget.Pivot.Center;
					SelectedItem.Boundary.transform.localEulerAngles = Vector3.zero;

					SelectedItem.Boundary.width = FocusedBodySlot.Background.width - 10;
					SelectedItem.Boundary.height = FocusedBodySlot.Background.height - 10;
					SelectedItem.Boundary.transform.localPosition = Vector3.zero;


					SelectedItem.Boundary.alpha = 1;
				}
				else
				{
					FocusedBodySlot = null;
				}
			}

			List<TempSlot> tempSlots = _windowPanel.FindTempSlots();
			TempSlot tempSlot;
			if(tempSlots.Count > 0)
			{

				if(FindNearestTempSlot(out tempSlot, centerPos, tempSlots))
				{
					FocusedTempSlot = tempSlot;
					SelectedItem.Boundary.transform.parent = FocusedTempSlot.transform;
					SelectedItem.Boundary.pivot = UIWidget.Pivot.Center;
					SelectedItem.Boundary.transform.localEulerAngles = Vector3.zero;

					SelectedItem.Boundary.width = FocusedTempSlot.Background.width - 10;
					SelectedItem.Boundary.height = FocusedTempSlot.Background.height - 10;
					SelectedItem.Boundary.transform.localPosition = Vector3.zero;


					SelectedItem.Boundary.alpha = 1;
				}
				else
				{
					FocusedTempSlot = null;
				}
			}

		}


	}
Example #28
0
	private void PlaceItemInBodySlot(GridItem item)
	{
		AddItemToBodySlot(item, FocusedBodySlot);
		NGUITools.MarkParentAsChanged(_windowPanel.gameObject);
		SelectedItem = null;
		FocusedBodySlot = null;
	}
Example #29
0
 public BodyPart GetBodyPart(BodySlot bp)
 {
     return(bodyParts[bp]);
 }
Example #30
0
	public void AddItemToBodySlot(GridItem item, BodySlot slot)
	{
		item.Sprite.pivot = UIWidget.Pivot.Center;

		item.Sprite.transform.parent = item.Boundary.transform.parent;

		if(item.IsRotatable)
		{
			if(item.Item.Type == ItemType.PrimaryWeapon || item.Item.Type == ItemType.SideArm)
			{
				if(item.Orientation == GridItemOrient.Landscape)
				{
					int temp = item.ColumnSize;
					item.ColumnSize = item.RowSize;
					item.RowSize = temp;

					item.Orientation = GridItemOrient.Portrait;
					item.transform.localEulerAngles = new Vector3(0, 0, 90);
				}

				item.Sprite.width = slot.Background.height;
				item.Sprite.height = Mathf.FloorToInt(item.Sprite.width * ((item.ColumnSize * 1f) / item.RowSize));
			}
			else if(item.Item.Type == ItemType.Armor)
			{
				if(item.Orientation == GridItemOrient.Portrait)
				{
					int temp = item.ColumnSize;
					item.ColumnSize = item.RowSize;
					item.RowSize = temp;

					item.Orientation = GridItemOrient.Landscape;
					item.transform.localEulerAngles = new Vector3(0, 0, 0);
				}

				item.Sprite.width = slot.Background.width;
				item.Sprite.height = Mathf.FloorToInt(item.Sprite.width * ((item.RowSize * 1f) / item.ColumnSize));
			}
			else if(item.Item.Type == ItemType.Thrown || item.Item.Type == ItemType.Tool)
			{
				if(item.Orientation == GridItemOrient.Portrait)
				{
					int temp = item.ColumnSize;
					item.ColumnSize = item.RowSize;
					item.RowSize = temp;

					item.Orientation = GridItemOrient.Landscape;
					item.transform.localEulerAngles = new Vector3(0, 0, 0);
				}

				item.Sprite.height = slot.Background.height;
				item.Sprite.width = Mathf.FloorToInt(item.Sprite.height * ((item.ColumnSize * 1f) / item.RowSize));
			}
		}
		else
		{
			item.Sprite.width = slot.Background.width;
			item.Sprite.height = item.Sprite.width;
		}

		item.Boundary.width = slot.Background.width - 10;
		item.Boundary.height = slot.Background.height - 10;

		item.Sprite.depth = (int)InventoryItemDepth.Normal;
		item.transform.localPosition = item.Boundary.transform.localPosition;
		NGUITools.AddWidgetCollider(item.gameObject);
		item.State = GridItemState.None;

		slot.Items.Add(item);

	}