Пример #1
0
    private void ItemContainer_OnClick(ItemContainer container, UnityEngine.EventSystems.PointerEventData pointerEventData)
    {
        if (DebugConfigs.DEBUG_LOG)
        {
            Debug.Log("ItemController::ItemContainer_OnClick::PLANTED" + pointerEventData.position);
        }

        GameObject ItemGO = Instantiate(itemPrefab);

        ItemGO.transform.SetParent(ItemContainerToGO[container].transform, false);
        ItemGO.transform.Find("Image").GetComponent <Image>().sprite = Resources.Load <Sprite>("Images\\Animals\\" + selecteditem);
        ItemGO.GetComponentInChildren <TextMeshProUGUI>().text       = selecteditem;
        //ItemGO.GetComponent<RectTransform>().rect.Set(0, 0, 0, 0);
        if (DebugConfigs.DEBUG_LOG)
        {
            Debug.Log("Update event added to Item.");
        }

        ItemController ItemController = ItemGO.GetComponent <ItemController>();
        Item           item           = ItemPrototype.GetItemInfo(selecteditem).item.Clone() as Item;

        item.Planted     += itemPlanted;
        item.Planted     += UpgradeablePanelController.Instance.ItemPlanted;
        item.UpdateEvent += ItemUpdate;

        //planted eventları
        GameController.Instance.planteditemsToGOs[item]        = ItemGO;
        GameController.Instance.ItemContainerToitem[container] = item;
        container.hasItem   = true;
        ItemController.item = item as Item;
        ItemControllers.Add(ItemController);
        // After Item planted selected Item gets set to null so be carefull where you do this
        item.ItemPlanted();
    }
Пример #2
0
    public void ItemPlanted(Item item)
    {
        //find the copied Item in the upgradeable panel

        Button button = itemNameToUpgradeContainer[item.Name].GetComponentInChildren <Button>();

        button.transform.GetComponentInChildren <TextMeshProUGUI>().text = "Upgrade\n" + Extensions.Format(item.requiredMoneyForUpgrade);
        button.onClick.RemoveAllListeners();
        button.onClick.AddListener(() => { UpgradeItemButtonClicked(itemNameToUpgradeContainer[item.Name], item); });

        item.Upgraded += ItemUpgraded;

        GameController.Instance.money -= item.requiredMoneyForPlant;
        //for second time to plant an item we will set the price to 0 in the proto
        //ikinci kez aynı nesneyi plant etmek için bir ücret istemiyoruz(tartışmaya açık)
        ItemPrototype.GetItemInfo(item.Name).item.requiredMoneyForPlant = 0;

        //itemler startta isimleri ile ekleniyorlar
        if (itemNameToActiveItem.ContainsKey(item.Name))
        {
            //her seferinde burada referans değişmeli. Biz bir item ekledik ve sonra onu son seviye yaptık.
            //button tekrar plant olacak ve yeni bir item plant edeceğiz artık takip etmemiz gereken item o olacak
            itemNameToActiveItem[item.Name] = item;
        }
        else
        {
            Debug.LogError("How did this happen?? This item should not be exist!!!");
        }
    }
Пример #3
0
 public Item CreateInstance(ItemPrototype prototype)
 {
     if (prototype.name == "Empty")
     {
         return(null);
     }
     return(Item.CreateInstance(prototype));
 }
Пример #4
0
        public bool GetItemPrototype(int id, out ItemPrototype prototype)
        {
            if (itemsProto.TryGetValue(id, out prototype))
            {
                return(true);
            }

            return(false);
        }
Пример #5
0
    public void SpawnItem(ItemPrototype prototype, Vector2 position)
    {
        if (prototype.name == "Empty")
        {
            return;
        }
        Item item = CreateInstance(prototype);

        if (item == null)
        {
            return;
        }
        Spawn(item, position);
    }
    private void BlockController()
    {
        PlayerInventory playerInventory = player.GetComponent <PlayerInventory>();

        if (Physics.Raycast(mainCam.position, mainCam.forward, out var hitInfo, 10f, rayCastMask))
        {
            ChunkManager chunkManager = ChunkManager.Instance;
            Vector3      hitInfoPoint = hitInfo.point - hitInfo.normal / 2;
            hitInfoPoint = new Vector3(Mathf.CeilToInt(hitInfoPoint.x),
                                       Mathf.FloorToInt(hitInfoPoint.y), Mathf.FloorToInt(hitInfoPoint.z));
            hightBlock.SetActive(true);
            hightBlock.transform.position = hitInfoPoint;
            Block oldBlock = null;
            if (Input.GetMouseButtonDown(1))
            {
                hitInfoPoint = hitInfoPoint + hitInfo.normal;
                Vector3Int chunkSerial = ChunkManager.Instance.PositionToChunkSerial(hitInfoPoint);
                Chunk      chunk       = ChunkManager.Instance.GetChunk(chunkSerial);

                int        curSelectIndex = UIManager.Instance.toolBarPanel.CurSelectIndex;
                ItemEntity curSelEntity   =
                    playerInventory.toolBarItems.GetItemFromSlot(curSelectIndex);
                if (curSelEntity != null)
                {
                    oldBlock = chunk.SetBlock(hitInfoPoint - new Vector3(chunkSerial.x * chunkManager.length, 0, chunkSerial.z * chunkManager.width),
                                              BlockManager.Instance.GetBlock(curSelEntity.ItemPrototype.bindBlock));
                    ItemManager.Instance.RemoveItemFromPlayerToolbar(curSelectIndex);
                }
            }
            if (Input.GetMouseButtonDown(0))
            {
                Vector3Int chunkSerial = ChunkManager.Instance.PositionToChunkSerial(hitInfoPoint);
                //Debug.Log($"{hitInfoPoint} {hightBlock.transform.position} {ChunkManager.Instance.GetNoiseValue( hitInfoPoint.x,hitInfoPoint.y,hitInfoPoint.z)}");
                Chunk chunk = ChunkManager.Instance.GetChunk(chunkSerial);
                oldBlock = chunk.SetBlock(hitInfoPoint - new Vector3(chunkSerial.x * chunkManager.length, 0, chunkSerial.z * chunkManager.width), null);
            }

            if (oldBlock != null)
            {
                ItemPrototype itemPrototype = ItemManager.Instance.GetItemPrototype(oldBlock.blockID);
                if (itemPrototype != null)
                {
                    ItemManager.Instance.CreateDropEntity(itemPrototype.id, hitInfoPoint + new Vector3(-0.5f, 0.5f, 0.5f));
                }
            }
            //Debug.Log($"{hitInfo.point} {hitInfo.normal}");
            Debug.DrawLine(mainCam.position, hitInfo.point);
        }
Пример #7
0
 protected Item(ItemPrototype b)
 {
     this.name        = b.name;
     this.itemType    = b.itemType;
     this.stackCount  = b.stackCount;
     this.itemQuality = b.itemQuality;
     this.stats       = new Stat[b.stats.Length];
     for (int i = 0; i < this.stats.Length; i++)
     {
         this.stats[i] = new Stat(b.stats[i].statType, b.stats[i].minValue, b.stats[i].maxValue);
     }
     this.sprite       = Sprite_Manager.instance.GetSprite(b.sprite);
     this.itemUseType  = b.itemUseType;
     this.cost         = b.cost;
     this.timeToCreate = b.timeToCreate;
 }
Пример #8
0
 void Update()
 {
     if (targetInventory.Get(index) != null)
     {
         ItemPrototype proto = targetInventory.Get(index).Prototype();
         imgObj.GetComponent <Image>().sprite = root.itemIcons[proto.iconIndex];
         if (targetInventory.Get(index).Prototype().consumptionBehaviour != ConsumptionBehaviour.nonconsumable || targetInventory.Get(index).stackCount > 1)
         {
             textObj.GetComponent <Text>().text = targetInventory.Get(index).stackCount.ToString();
         }
     }
     else
     {
         imgObj.GetComponent <Image>().sprite = root.nullIcon;
         textObj.GetComponent <Text>().text   = "";
     }
 }
Пример #9
0
    // Start is called before the first frame update
    void Start()
    {
        if (Instance != null)
        {
            return;
        }
        //TODO:hghjgj
        Instance = this;
        itemNameToUpgradeContainer = new Dictionary <string, GameObject>();
        itemNameToActiveItem       = new Dictionary <string, Item>();

        GameController.Instance.LeveledUp += Player_LeveledUp;

        foreach (ItemInfo itemInfo in ItemPrototype.GetItemInfos())
        {
            Item proto = itemInfo.item;

            GameObject upgradeableGO = Instantiate(upgradeablePrefab);
            upgradeableGO.transform.SetParent(parentObjectTransform, false);
            upgradeableGO.transform.Find("Name").GetComponent <TextMeshProUGUI>().text = proto.Name;
            upgradeableGO.transform.Find("Image").GetComponent <Image>().sprite        = Resources.Load <Sprite>("Images\\Animals\\" + proto.Name);
            // Debug.Log(proto.Name);

            Button btn = upgradeableGO.GetComponentInChildren <Button>();
            btn.onClick.AddListener(() => { Plant(proto.Name); });
            if (proto.requiredLevel > GameController.Instance.level)
            {
                btn.interactable = false;
                btn.gameObject.GetComponentInChildren <TextMeshProUGUI>().text = "Required Level " + proto.requiredLevel;
            }

            itemNameToUpgradeContainer.Add(proto.Name, upgradeableGO);
            itemNameToActiveItem.Add(proto.Name, null);


            //we need to set behaviour of this upgradeable or plantable Item objects
            //for example is this object active?
            //is this upgradeable or plantable
            //yerleştirilmiş ve son seviyeye kadar geliştirilmiş objeler nasıl davranacak?
            //son seviyeye geldiği zaman yerleştirme aktif olacak yani artık buton başka bir obje için çalışacak diğeri ile olan bağı kopacak
            //bu durumda buttonlar hangi objeye bağlı olduğunu bilecek
            //plant yaparken bunu bildirebiliriz
            //bunun için mantıklı bir yöntem düşün
        }
    }
Пример #10
0
    public ItemPrototype GetPrototype(string itemName)
    {
        /* if (itemType == ItemType.Cargo)
         *      return GetCargoProto(itemName);
         * if (itemType == ItemType.Machine)
         *      return GetMachineProto(itemName); */
        foreach (ItemPrototype prototype in available_Items)
        {
            if (prototype.name == itemName)
            {
                return(prototype);
            }
        }
        ItemPrototype empty = new ItemPrototype();

        empty.name = "Empty";
        return(empty);
    }
Пример #11
0
        public ItemsManager()
        {
            lastItemId = DatabaseManager.GetLastInsertedId("items");

            DataTable itemsProtoTable = DatabaseManager.ReturnQuery("SELECT * FROM items_proto");

            for (int i = 0; i < itemsProtoTable.Rows.Count; i++)
            {
                DataRow row = itemsProtoTable.Rows[i];

                ItemPrototype data = new ItemPrototype()
                {
                    id     = (int)row["id"],
                    name   = (string)row["name"],
                    reqLvl = (sbyte)row["req_level"],
                    price  = (int)row["price"],
                };

                itemsProto.Add(data.id, data);
            }
        }
Пример #12
0
    private void OnEnable()
    {
        if (Instance != null)
        {
            return;
        }

        Instance = this;
        shelves  = new List <Item[]>();

        // instantiate planted Items to game object dictionary
        // this will store all Item models that planted and link them to the game objects in the game
        planteditemsToGOs   = new Dictionary <Item, GameObject>();
        ItemContainerToGO   = new Dictionary <ItemContainer, GameObject>();
        ItemContainerToitem = new Dictionary <ItemContainer, Item>();

        ItemControllers = new List <ItemController>();
        ItemPrototype.InitializeObjects();
        CleanShelf();
        CreateShelf();
        CreateShelf();
    }
Пример #13
0
 private void Update()
 {
     foreach (string itemName in itemNameToActiveItem.Keys)
     {
         Button button = itemNameToUpgradeContainer[itemName].GetComponentInChildren <Button>();
         if (ItemPrototype.GetItemInfo(itemName).item.requiredLevel > GameController.Instance.level)
         {
             button.interactable = false;
             return;
         }
         Item item = itemNameToActiveItem[itemName];
         //this means we can plant this but we did not do that yet
         if (item == null)
         {
             if (ItemPrototype.GetItemInfo(itemName).item.requiredMoneyForPlant > GameController.Instance.money)
             {
                 button.interactable = false;
             }
             else
             {
                 button.interactable = true;
             }
         }
         //this means we planted an item
         else
         {
             if (item.requiredMoneyForUpgrade > GameController.Instance.money)
             {
                 button.interactable = false;
             }
             else
             {
                 button.interactable = true;
             }
         }
     }
 }
Пример #14
0
 private void Player_LeveledUp(int level)
 {
     foreach (string itemName in itemNameToUpgradeContainer.Keys)
     {
         if (ItemPrototype.GetItemInfo(itemName).item.requiredLevel <= GameController.Instance.level)
         {
             Button button = itemNameToUpgradeContainer[itemName].GetComponentInChildren <Button>();
             if (itemNameToActiveItem[itemName] == null)
             {
                 int    reqMoney  = ItemPrototype.GetItemInfo(itemName).item.requiredMoneyForPlant;
                 string plantInfo = "Plant\n" + (reqMoney > 0 ? Extensions.Format(reqMoney) : "");
                 button.transform.GetComponentInChildren <TextMeshProUGUI>().text = plantInfo;
                 button.onClick.RemoveAllListeners();
                 button.onClick.AddListener(() => { Plant(itemName); });
             }
             else
             {
                 continue;
             }
             Debug.Log(itemName + ":" + (itemNameToActiveItem[itemName] == null));
             button.interactable = true;
         }
     }
 }
Пример #15
0
 public static Item CreateInstance(ItemPrototype prototype)
 {
     return(new Item(prototype));
 }
Пример #16
0
 public void Add(ItemPrototype item)
 {
     _Items[item.Name] = item;
 }
    void DefinePrototypes()
    {
        ItemPrototype bumbel;


        bumbel                      = new ItemPrototype();
        bumbel.name                 = "Oil";
        bumbel.iconIndex            = 0;
        bumbel.maxStackCount        = 10;
        bumbel.craftable            = true;
        bumbel.consumptionBehaviour = ConsumptionBehaviour.consumable;
        bumbel.Use                  = (Player p, Inventory container, int index) => {
            Debug.Log(p.backpack.maxSize);
        };
        prototypes.Add(bumbel);

        bumbel                      = new ItemPrototype();
        bumbel.name                 = "Wood";
        bumbel.iconIndex            = 1;
        bumbel.maxStackCount        = 10;
        bumbel.craftable            = true;
        bumbel.consumptionBehaviour = ConsumptionBehaviour.consumable;
        bumbel.Use                  = (Player p, Inventory container, int index) => {
            Debug.Log("USED WOOD");
        };
        prototypes.Add(bumbel);

        bumbel                      = new ItemPrototype();
        bumbel.name                 = "Campfire Schematic";
        bumbel.iconIndex            = 6;
        bumbel.maxStackCount        = 10;
        bumbel.craftable            = true;
        bumbel.consumptionBehaviour = ConsumptionBehaviour.consumable;
        bumbel.Use                  = (Player p, Inventory container, int index) => {
            UnderCursorDisplay underCursorDisplay = GameObject.FindGameObjectWithTag("UnderCursorDisplay").GetComponent <UnderCursorDisplay>();
            underCursorDisplay.itemUsedFromInventory = container;
            underCursorDisplay.itemUsedFromIndex     = index;
            underCursorDisplay.structure             = structurePrototypes[0];
            container.Get(index).inUse = true;
        };
        bumbel.Callback = (Player p, Inventory container, int index, bool successFlag) => {
            UnderCursorDisplay cursorHandler = GameObject.FindGameObjectWithTag("UnderCursorDisplay").GetComponent <UnderCursorDisplay>();
            container.Get(index).inUse          = false;
            cursorHandler.itemUsedFromInventory = null;
            cursorHandler.itemUsedFromIndex     = -1;
            if (successFlag)
            {
                GameObject construction     = Instantiate(Resources.Load <GameObject>("Prefabs/firepit"));
                Camera     mainCamera       = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <Camera>();
                Vector3    mouseCoordinates = mainCamera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, mainCamera.nearClipPlane));
                mouseCoordinates.x = Mathf.Round(mouseCoordinates.x * 2) / 2f;
                mouseCoordinates.y = Mathf.Round(mouseCoordinates.y * 2) / 2f;
                construction.transform.position = new Vector3(mouseCoordinates.x, mouseCoordinates.y, -0.5f);
                cursorHandler.structure         = null;

                container.Get(index).Decrement(container, index);
            }
            else
            {
                cursorHandler.structure = null;
            }
        };
        prototypes.Add(bumbel);



        StructurePrototype structurePrototype;

        structurePrototype        = new StructurePrototype();
        structurePrototype.sprite = Resources.Load <Sprite>("Sprites/firepit");
        structurePrototype.size   = 2;
        structurePrototype.name   = "firepit";
        structurePrototypes.Add(structurePrototype);
    }
Пример #18
0
 public ItemEntity(ItemEntity itemEntity, int count) : this()
 {
     itemPrototypeID = itemEntity.itemPrototypeID;
     itemPrototype   = itemEntity.itemPrototype;
     itemCount       = count;
 }
Пример #19
0
 public ItemEntity(ItemPrototype itemPrototypePrototype, int count) : this(itemPrototypePrototype)
 {
     itemCount = count;
 }
Пример #20
0
 public ItemEntity(ItemPrototype itemPrototypePrototype) : this()
 {
     itemPrototypeID = itemPrototypePrototype.id;
     itemPrototype   = itemPrototypePrototype;
 }
Пример #21
0
 public ItemEntity(string id) : this()
 {
     itemPrototypeID = id;
     itemPrototype   = ItemManager.Instance.GetItemPrototype(id);
 }
Пример #22
0
 public ItemEntity()
 {
     itemPrototypeID = "";
     itemPrototype   = null;
     itemCount       = 1;
 }