Ejemplo n.º 1
0
        public IEnumerator SetUp()
        {
            player = MonoBehaviour.Instantiate(Resources.Load <GameObject>("Tests/Player"));
            yield return(null); // Wait for prefab to load

            character = player.GetComponent <Character>();
            worldItem = WorldItem.Create(Resources.Load <Item>("Items/item"), 1);
            yield return(null); // Wait for prefab to load

            character.Inventory.Give(worldItem);
            itemScript = character.HandItemContainer.gameObject.GetComponentInChildren <ItemScript>();
        }
Ejemplo n.º 2
0
    private void Start()
    {
        var table = new List <string>();

        for (int i = 0; i < loottable.Count; i++)
        {
            table.Add(loottable[UnityEngine.Random.Range(0, loottable.Count)]);
        }
        foreach (var item in table)
        {
            WorldItem.Create(Database.GetItemByID(item), transform.Find("spawnpoint").position, -1, atPoint: true);
        }
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Create a item in the world that can be picked up.
    /// </summary>
    /// <param name="item">The item that can be droped</param>
    /// <param name="position">The position where to drop the item</param>
    /// <param name="amount">The amout of the item to be dropped</param>
    /// <param name="despawn">How long it will take to despan the item</param>
    /// <param name="atPoint">Indicate to spane item at the position or a radious aroun the position</param>
    internal static void Create(Item item = null, Vector3 position = default, int amount = 1, float despawn = 300, bool atPoint = false)
    {
        if (item == null)
        {
            return;
        }
        var wip = Resources.Load("Prefabs/World_Item") as GameObject;

        if (!item.loottable)
        {
            for (int i = 0; i < amount; i++)
            {
                var x = position.x + (atPoint ? UnityEngine.Random.Range(-.5f, .5f) : UnityEngine.Random.Range(-3, 3));
                var z = position.z + (atPoint ? UnityEngine.Random.Range(-.5f, .5f) : UnityEngine.Random.Range(-3, 3));

                var wi = Instantiate(wip, new Vector3(x, position.y, z), Quaternion.identity).GetComponent <WorldItem>();
                wi.name   = $"[WORLD ITEM]: {item.Get<string>(pname.name)}";
                wi.item   = item;
                wi.despan = despawn;
                wi.transform.SetAsLastSibling();
            }
        }
        else
        {
            Dictionary <int, Item> tabledata = new Dictionary <int, Item>();
            var curentry = item.data.Keys.ToList().FindAll(x => x.StartsWith("loot_entry"));
            for (int i = 0; i < curentry.Count; i++)
            {
                var entry = curentry[i];

                var e = item.Get <string>(entry).Split(',')[0];
                var d = item.Get <string>(entry).Split(',')[1];
                tabledata.Add(int.Parse(d), Database.GetItemByID(e));
            }

            foreach (var key in tabledata.Keys)
            {
                var roll = UnityEngine.Random.Range(0, 100);
                if (roll <= key)
                {
                    WorldItem.Create(tabledata[key], position, atPoint: true);
                }
            }
        }
    }
Ejemplo n.º 4
0
    public void OnDrop(PointerEventData eventData)
    {
        var player = FindObjectOfType <Player>();

        Debug.Log("OnDrop");
        if (eventData.pointerDrag != null)
        {
            if (eventData.pointerDrag.GetComponent <InventorySlot>())
            {
                WorldItem.Create(eventData.pointerDrag.GetComponent <InventorySlot>().item, player.transform.position);
                eventData.pointerDrag.GetComponent <InventorySlot>().Set();
            }
            else if (eventData.pointerDrag.GetComponent <ActionbarSlot>())
            {
                WorldItem.Create(eventData.pointerDrag.GetComponent <ActionbarSlot>().item, player.transform.position);
                eventData.pointerDrag.GetComponent <ActionbarSlot>().Set();
            }
            else if (eventData.pointerDrag.GetComponent <CharacterSlot>())
            {
                WorldItem.Create(eventData.pointerDrag.GetComponent <CharacterSlot>().item, player.transform.position);
                eventData.pointerDrag.GetComponent <CharacterSlot>().Set();
            }
        }
    }
Ejemplo n.º 5
0
 // Start is called before the first frame update
 void Start()
 {
     WorldItem.Create(Database.GetLootTableByID("gina:basic_chest"), atPoint: true);
 }