public void AddItemToInventory(InventoryObject objectBeingAdded)
    {
        GameObject    clone = Instantiate(togglePrefab, inventoryContent);
        InventoryItem item  = clone.GetComponent <InventoryItem>();

        item.InventoryObjectInSlot = objectBeingAdded;
    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.CompareTag("Player") && buildableObject != null)
        {
            buildScreen = CanvasReference.instance.buildSignScreen;


            buildScreen.GetComponentInChildren <Button>().onClick.AddListener(delegate { Build(); });

            inRange   = true;
            inventory = collision.gameObject.GetComponent <Player>().inventory;
            foreach (Transform child in buildScreen.transform.GetChild(0).transform)
            {
                Destroy(child.gameObject);
            }

            for (int i = 0; i < buildableObject.Materials.Count; i++)
            {
                GameObject mat = Instantiate(materialPrefab);
                mat.GetComponentsInChildren <Image>()[1].sprite     = buildableObject.Materials[i].item.uiDisplay;
                mat.GetComponentInChildren <TextMeshProUGUI>().text = currentAmounts[i] + "/" + buildableObject.Materials[i].amount.ToString();


                mat.transform.SetParent(buildScreen.transform.GetChild(0).transform, false);
            }

            buildScreen.SetActive(true);
        }
    }
Example #3
0
        /// <summary>
        /// Handles a new player enters room
        /// </summary>
        /// <param name="Message"></param>
        protected override void HandleCreateMessage(CreateMessage Message)
        {
            base.HandleCreateMessage(Message);

            RoomObject roomObject = Message.NewRoomObject;

            // tell offers to new roomobject
            if (roomObject.Flags.Drawing != ObjectFlags.DrawingType.Invisible &&
                roomObject.Flags.IsPlayer &&
                !roomObject.IsAvatar &&
                Config.TellOnEnter)
            {
                TellAdvertisement(roomObject);
            }

            // check if is bot admin who entered our room
            if (Config.IsAdmin(roomObject.Name))
            {
                // get our shillings from inventory
                InventoryObject shillings = Data.InventoryObjects.GetItemByName(NAME_SHILLING, false);

                uint count = 0;

                // tell master shillingscount
                if (shillings != null)
                {
                    count = shillings.Count;
                }

                SendSayGroupMessage(
                    roomObject.ID,
                    Config.ChatPrefixString + "Master " + roomObject.Name + ", I have " + count + " shillings");
            }
        }
Example #4
0
    // Start is called before the first frame update
    void Start()
    {
        inventory      = InventoryController.Instance.Inventory;
        itemSlotsInv   = InvSlotsObject.GetComponentsInChildren <SlotUI>();
        itemSlotsChest = ChestSlotsObject.GetComponentsInChildren <SlotUI>();

        rt = gameObject.GetComponent <RectTransform>();

        //Each slot is an observable. Subscribe to each observerable to check for a right click event on a slot
        for (int i = 0; i < inventory.totalSlots; i++)
        {
            itemSlotsInv[i].SlotID               = i;
            itemSlotsInv[i].OnLeftClickEvent    += OnLeftClickItemEventWrapper_Inventory;
            itemSlotsInv[i].OnPointerEnterEvent += CursorEnterItem;
            itemSlotsInv[i].OnPointerExitEvent  += CursorExitItem;
        }

        for (int i = 0; i < 30; i++)
        {
            itemSlotsChest[i].SlotID               = i;
            itemSlotsChest[i].OnLeftClickEvent    += OnLeftClickItemEventWrapper_Chest;
            itemSlotsChest[i].OnPointerEnterEvent += CursorEnterItem;
            itemSlotsChest[i].OnPointerExitEvent  += CursorExitItem;
        }
        Refresh();
    }
Example #5
0
        private void btnEdit_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Media.Effects.BlurEffect objBlur = new System.Windows.Media.Effects.BlurEffect();
            ((MainWindow)App.Current.MainWindow).Opacity = 0.5;
            ((MainWindow)App.Current.MainWindow).Effect  = objBlur;
            InventoryObject row = (InventoryObject)dataGridMaterial.SelectedItem;

            if (row != null)
            {
                Window window = new Window
                {
                    ResizeMode            = ResizeMode.NoResize,
                    WindowStyle           = WindowStyle.None,
                    Title                 = "Sửa vật liệu",
                    Content               = new PopupEditMaterial(row.Name, row.Unit),
                    Width                 = 460,
                    Height                = 300,
                    WindowStartupLocation = WindowStartupLocation.CenterScreen
                };
                window.ShowDialog();
                LoadData();
            }
            ((MainWindow)App.Current.MainWindow).Opacity = 1;
            ((MainWindow)App.Current.MainWindow).Effect  = null;
        }
    public void StartFishing(Vector3 position, FishPool fishPool, Player player)
    {
        FishSize    newFishSize = fishPool.RandomFishSize;
        Fish        fish        = fishFactory.CreateFish(newFishSize, GetFishTemplate(newFishSize));
        PlayerStats stats       = player.GetPlayerStats();
        Inventory   inventory   = player.GetPlayerInventory();

        GameObject    fishingTargetPrefab = GameObject.Instantiate(_fishingTargetPrefab, position, Quaternion.identity);
        FishingTarget fishingTarget       = fishingTargetPrefab.GetComponent <FishingTarget>();

        if (fishingTarget != null)
        {
        }

        bool canPlayerCatchFish = CanPlayerCatchFish(fish, stats);

        Debug.Log("Start Fishing :: FishName: " + fish.Size + ", CaughtFish: " + canPlayerCatchFish);
        if (canPlayerCatchFish)
        {
            stats.AddExperience(FishingHelper.calculateFishExperience(fishPool, fish, stats));
            InventoryObject fishInventoryObject  = new InventoryObject(fish);
            bool            collectedCollectable = inventory.AddItem(fishInventoryObject);
            Debug.Log(collectedCollectable ? "Success for inventoryplacement" : "Failure for inventoryplacement");
        }
    }
Example #7
0
        public async Task <bool> UpdateInventoryObjectAsync(InventoryObject newModel)
        {
            _appDbContext.Update(newModel);
            await _appDbContext.SaveChangesAsync();

            return(true);
        }
 protected virtual void Awake()
 {
     inventoryObject             = new InventoryObject();
     inventoryBuildingController = Instantiate(inventoryBuildingController.gameObject.transform.parent, Vector3.zero, Quaternion.identity, canvas).GetComponentInChildren <InventoryController>();
     player.UIElements1.Add(inventoryBuildingController.gameObject.transform.parent.gameObject);
     // inventoryBuildingController.gameObject.transform.parent.SetParent(canvas);
 }
 private void Door_OnKeyDestroy(InventoryObject obj)
 {
     if (this.AssociatedInventoryObject == obj)
     {
         Destroy(this.gameObject);
     }
 }
    private void LoadPrefs()
    {
        int pageAmount = EditorPrefs.GetInt(pageCountKey);

        if (pageAmount == 0)
        {
            Debug.Log("Prefs Empty. Loaded new empty page.");
            AddPage();
        }
        else
        {
            for (int pageId = 0; pageId < pageAmount; pageId++)
            {
                InventoryObject[] objectArray = new InventoryObject[width * height];

                for (int i = 0; i < width * height; i++)
                {
                    string objPath;
                    if ((objPath = EditorPrefs.GetString("" + pageId + "." + i)) != "")
                    {
                        int stackSize = 0;
                        if (stackingEnabled)
                        {
                            stackSize = EditorPrefs.GetInt("Stack" + pageId + "." + i);
                        }
                        objectArray[i] = new InventoryObject(AssetDatabase.LoadAssetAtPath(objPath, typeof(UnityEngine.Object)), stackSize);
                    }
                }
                LoadPage(new InventoryPage(EditorPrefs.GetString("pageName" + pageId), objectArray));
            }
        }
        activePageId = 0;
    }
Example #11
0
    public void AddItemToMenu(InventoryObject inventoryObjectToAdd)
    {
        GameObject menuItem            = Instantiate(inventoryMenuItemTogglePrefab, inventoryContentTransform);
        InventoryMenuItemToggle toggle = menuItem.GetComponent <InventoryMenuItemToggle>();

        toggle.AssociatedInventoryObject = inventoryObjectToAdd;
    }
Example #12
0
        /// <summary>
        /// Executes a Task 'use'
        /// </summary>
        /// <param name="Task"></param>
        protected void DoUse(BotTaskUse Task)
        {
            // try to get the item from the inventory
            InventoryObject inventoryObject =
                Data.InventoryObjects.GetItemByName(Task.Name, false);

            // item not found
            if (inventoryObject == null)
            {
                // log
                Log("WARN", "Cant execute task 'use'. Item " + Task.Name + " not found.");

                return;
            }

            // send requse
            if (!inventoryObject.IsInUse)
            {
                SendReqUseMessage(inventoryObject.ID);
            }

            // send requnuse
            else
            {
                SendReqUnuseMessage(inventoryObject.ID);
            }

            // log
            Log("BOT", "Executed task 'use' " + inventoryObject.Name);
        }
Example #13
0
    public void AddItemToMenu(InventoryObject inventoryItemToAdd)
    {
        GameObject clone = Instantiate(inventoryMenuItemToglePrefab, toggleScrollList.transform);
        InventoryMenuItemToggle toggle = clone.GetComponent <InventoryMenuItemToggle>();

        toggle.LinkedObject = inventoryItemToAdd;
    }
Example #14
0
    /// <summary>
    /// Comprueba si al añadir un objeto este se puede combinar con otro del inventario
    /// </summary>
    /// <param name="objAdd"> Objeto nuevo que se ha añadido al inventario</param>
    /// <returns></returns>

    public IEnumerator CheckCompositions(InventoryObject objAdd)
    {
        //comprueba que no se este buscando otra composicion en el momento, si es asi, espera
        while (IsCheckingCompositions)
        {
            yield return(new WaitForSeconds(0.2f));
        }

        IsCheckingCompositions = true;
        objAddId = objAdd.IDObject;

        for (int i = 0; i < numSlotsInv; i++)
        {
            objInvId = inventoryObjs[i].IDObject;
            if (objInvId != -1 && objInvId != objAddId)
            {
                hasFoundComposition = CheckTwoIngredientsComposition();
                if (hasFoundComposition)
                {
                    StartCoroutine(CreateCompoundObj(objAdd, inventoryObjs[i]));
                    break;
                }
            }
        }

        if (!hasFoundComposition)
        {
            IsCheckingCompositions = false;
        }
    }
 /// <summary>
 /// Gives the location amount number of type objects.
 /// </summary>
 /// <param name="location">What to give the items to</param>
 /// <param name="amount">Number of items to give</param>
 /// <param name="type">Type of object to give to player</param>
 public void Give(InventoryObject location, int amount, int type)
 {
     if (type == NRG)
     {
         location.NRGAmount += amount;
     }
     else if (type == Battery)
     {
         location.BatteriesAmount += amount;
     }
     else if (type == CarbonDioxideFilter)
     {
         location.C02FilterAmount += amount;
     }
     else if (type == Plant)
     {
         location.PlantAmount += amount;
     }
     else if (type == Water)
     {
         location.WaterAmount += amount;
     }
     else if (type == BoosterFood)
     {
         location.BoosterFoodAmount += amount;
     }
     else
     {
         return;
     }
 }
Example #16
0
 // When the player isn't triggered with the object anymore we set it's boolean value to false
 void OnTriggerExit2D(Collider2D collision)
 {
     if (collision.gameObject.name.Contains("Chest"))
     {
         ChestObject = null;
     }
     else if (collision.gameObject.name.Contains("TrashKings"))
     {
         isTrashKingsTriggered = false;
     }
     else if (collision.gameObject.name.Contains("AlienStore"))
     {
         isAlienStoreTriggered = false;
     }
     else if (collision.gameObject.name.Contains("CodePuzzle"))
     {
         isCodePuzzleTriggered = false;
     }
     else if (collision.gameObject.name.Contains("HackingPanelPuzzle"))
     {
         isHackPanelPuzzleTriggered = false;
     }
     else if (collision.gameObject.name.Contains("ButtonPuzzle"))
     {
         isButtonPuzzleTriggered = false;
     }
 }
Example #17
0
 /// <summary>
 /// The event handler for InventoryMenuItemSelected
 /// </summary>
 private void OnInventoryMenuItemSelected(InventoryObject inventoryObjectThatWasSelected)
 {
     itemLabelText.text           = inventoryObjectThatWasSelected.ObjectName;
     descriptionAreaText.text     = inventoryObjectThatWasSelected.Decription;
     itemImageButton.image.sprite = inventoryObjectThatWasSelected.Icon;
     itemEnlargedImage.sprite     = inventoryObjectThatWasSelected.LargeImage;
 }
Example #18
0
        public override MetadataWrapper generateMetadataWrapper()
        {
            MetadataWrapper metaMessage = base.generateMetadataWrapper();

            metaMessage.lastAction        = lastAction;
            metaMessage.lastActionSuccess = lastActionSuccess;
            metaMessage.errorMessage      = errorMessage;

            if (errorCode != ServerActionErrorCode.Undefined)
            {
                metaMessage.errorCode = Enum.GetName(typeof(ServerActionErrorCode), errorCode);
            }

            List <InventoryObject> ios = new List <InventoryObject>();

            foreach (string objectId in inventory.Keys)
            {
                SimObj          so = inventory [objectId];
                InventoryObject io = new InventoryObject();
                io.objectId   = so.UniqueID;
                io.objectType = Enum.GetName(typeof(SimObjType), so.Type);
                ios.Add(io);
            }

            metaMessage.inventoryObjects = ios.ToArray();

            return(metaMessage);
        }
Example #19
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.gameObject.CompareTag("Player"))
     {
         inventory = collision.gameObject.GetComponent <Player>().inventory;
     }
 }
Example #20
0
    // Battle will take place in a separate scene, the code below
    // will cause the player to be in battle upon scene entry
    void Start()
    {
        state = BattleState.START;

        prevWill = PlayerStats.Instance.totalWill;

        //these are temporary so the player has some moves to look through
        PlayerStats.attacks.Learn("stick", 1, -2, -3);
        PlayerStats.attacks.Learn("stone", 2, -3, -4);
        PlayerStats.skills.Learn("cry", 1, -3, 0);
        PlayerStats.skills.Learn("yell", -3, -1, 0);
        PlayerStats.skills.Learn("aa", 2, 3, 2);
        PlayerStats.skills.Learn("h", 0, 0, 0);

        //Finds the inventory in the scene
        player = GameObject.FindWithTag("Player");
        InventoryManager inventoryManager = player.GetComponent <InventoryManager>();

        inventory = inventoryManager.inventory;
        if (inventory != null)
        {
            Debug.Log("Inventory get");
        }
        StartCoroutine(SetupBattle());
    }
Example #21
0
    /// <summary>
    /// Instantiates a new inventory menu item toggle prefab and adds it to the menu.
    /// </summary>
    /// <param name="inventoryObjectToAdd"></param>
    public void AddItemToMenu(InventoryObject inventoryObjectToAdd)
    {
        GameObject clone = Instantiate(inventoryMenuItemTogglePrefab, inventoryListContentArea);
        InventoryMenuItemToggle toggle = clone.GetComponent <InventoryMenuItemToggle>();

        toggle.AssociatedInventoryObject = inventoryObjectToAdd;
    }
    public void OnTriggerEnter(Collider other)
    {
        // Check if this object has an inventory, if it doesn't: return.
        ShipController ship = other.transform.GetComponent <ShipController>();

        if (ship != null)
        {
            inventory = ship.inventory;
        }
        else if (other.transform.parent != null)
        {
            ship = other.transform.parent.gameObject.GetComponent <ShipController>();
        }
        if (ship != null)
        {
            inventory = ship.inventory;
        }
        else
        {
            return;    // if not even parent has a shipcontroller
        }
        if (inventory == null)
        {
            return;
        }

        closeObjectTransform = other.transform;
    }
Example #23
0
        private void dataGridView_equipamientos_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex < 5)
            {
                return;
            }

            InventoryObject objeto = cuenta.game.character.inventario.equipamiento.ElementAt(e.RowIndex);

            string accion = dataGridView_equipamientos.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();

            switch (accion)
            {
            case "Equipar":
                cuenta.game.character.inventario.equipar_Objeto(objeto);
                break;

            case "Desequipar":
                cuenta.game.character.inventario.desequipar_Objeto(objeto);
                break;

            case "Eliminar":
                if (MessageBox.Show("Realmente deseas eliminar " + objeto.nombre + "?", "Eliminar un objeto", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    cuenta.game.character.inventario.eliminar_Objeto(objeto, 1, true);
                }
                break;
            }
        }
Example #24
0
    public void additemtomenu(InventoryObject inventoryobjectoadd)
    {
        GameObject clone = Instantiate(inventorymenuitemtoggleprefab, inventorylistcontentarea);
        InventoryMenuItemToggle toggle = clone.GetComponent <InventoryMenuItemToggle>();

        toggle.associatedInventoryobject = inventoryobjectoadd;
    }
Example #25
0
 public void Remove(InventoryObject target)
 {
     if (this.Objects.Contains(target))
     {
         this.Objects.Remove(target);
     }
 }
    public void BuyItem(int id)
    {
        if (currentWares != null && id >= 0 && id < currentWares.ownedGear.Count)
        {
            GearSlot gearSlot = currentWares.ownedGear[id];

            InventoryObject.TradeItem(gearSlot, playerInventory, currentWares);

            //Update UI:
            EmptySlot(id);
            GenerateIcons();

            /*
             * //Exchange money
             * InventoryObject.ExchangeMainCurrency(currentWares.ownedGear[id].gear.BuyPrice, playerInventory, currentWares);
             *
             * //Give item to player:
             * playerInventory.AddGear(currentWares.ownedGear[id].gear);
             * Debug.Log("You bought item of id: " + id);
             * Debug.Log(currentWares.ownedGear[id].gear);
             *
             * //Remove item from current wares:
             * currentWares.RemoveGear(id);
             */
        }
        else
        {
            Debug.Log("It's an empty slot dumbass...");
        }
        //GenerateIcons();
    }
Example #27
0
 // When player comes in contact with trigger it checks the name and changes the boolean of the
 // object we triggered with to true
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.gameObject.name.Contains("Chest"))
     {
         ChestObject = collision.gameObject.GetComponent <InventoryObject>();
         uI_Chest.inventoryObject = ChestObject;
     }
     else if (collision.gameObject.name.Contains("TrashKings"))
     {
         isTrashKingsTriggered = true;
     }
     else if (collision.gameObject.name.Contains("AlienStore"))
     {
         isAlienStoreTriggered = true;
     }
     else if (collision.gameObject.name.Contains("CodePuzzle"))
     {
         isCodePuzzleTriggered = true;
     }
     else if (collision.gameObject.name.Contains("HackingPanel"))
     {
         isHackPanelPuzzleTriggered = true;
     }
     else if (collision.gameObject.name.Contains("ButtonPuzzle"))
     {
         isButtonPuzzleTriggered = true;
     }
 }
Example #28
0
    void ViewSlot <T>(int index, InventoryObject invObj, List <T> inventory) where T : InventoryObject
    {
        itemName.text        = invObj.GetName();
        itemDescription.text = invObj.GetDescription();
        ((Text)drop.GetComponentInChildren(typeof(Text))).text = "Drop";
        drop.onClick.AddListener(delegate() {
            ((Text)drop.GetComponentInChildren(typeof(Text))).text = "Confirm";
            drop.onClick.AddListener(delegate() {
                inventory.RemoveAt(index);
                CancelViewSlot();
                PopulateSlots(inventory);
            });
        });

        use.onClick.AddListener(delegate() {
            Use(invObj, delegate() {
                inventory.RemoveAt(index);
                Deactivate();
            });
        });

        cancel.onClick.AddListener(CancelViewSlot);

        itemOptions.SetActive(true);
    }
    // Returns true if successful
    public bool AddObject(InventoryObject objectToStore, int objNumber)
    {
        // Check that there is room for the object
        if (CurrentSize + (objectToStore.Size * objNumber) > MaxSize)
        {
            Debug.Log("Not enough room!");
            return(false);
        }

        // Check if there is already an instance of this object in the inventory
        var item = ItemList.Find(w => w.Object.Name == objectToStore.Name);

        // If not, create a new entry
        if (item == null)
        {
            ItemList.Add(new StoredObject(objectToStore, objNumber));
            Debug.Log("New Object Added!");
        }
        // Otherwise, just increase the entry by the amount given
        else
        {
            item.AddNumber(objNumber);
            // DebugConsole.Log("Object Added!");
        }

        // Track the total size
        CurrentSize += objectToStore.Size * objNumber;

        return(true);
    }
Example #30
0
        /// <summary>
        /// Processed an received botadmin command to give shillings
        /// </summary>
        /// <param name="AdminID"></param>
        protected void ProcessCommandGiveCash(uint AdminID, string[] Words)
        {
            // try to get player from who list since it's a whisper
            RoomObject roomObject = Data.RoomObjects.GetItemByID(AdminID);

            // if it's a bot admin
            if (Config.IsAdmin(roomObject.Name))
            {
                // need to read amount
                if (Words.Length < 2)
                {
                    return;
                }

                // try to get shills amount he want
                uint wantCash = 0;
                if (!UInt32.TryParse(Words[1], out wantCash))
                {
                    return;
                }

                if (roomObject == null)
                {
                    return;
                }

                // save this as our tradepartner (required for we offer first)
                Data.Trade.TradePartner = roomObject;

                // get our shillings from inventory
                InventoryObject shillings = Data.InventoryObjects.GetItemByName(NAME_SHILLING, false);

                // get how much cash we have
                uint haveCash = 0;
                if (shillings != null)
                {
                    haveCash = shillings.Count;
                }

                // tell we don't have that many
                uint offerCash = wantCash;
                if (haveCash < wantCash)
                {
                    offerCash = haveCash;

                    // tell admin
                    SendSayGroupMessage(
                        AdminID, Config.ChatPrefixString + "Master " + roomObject.Name + ", I don't have that many shillings. I give you all I have.");
                }

                // the shillings we offer him
                ObjectID[] offer = new ObjectID[] { new ObjectID(shillings.ID, offerCash) };

                // send offer
                SendReqOffer(new ObjectID(AdminID), offer);

                isGiveCashOffer = true;
            }
        }
Example #31
0
    /// <summary>
    /// Añade un objeto al inventario si aún no está lleno
    /// </summary>
    /// <param name="obj">Objeto a añadir</param>
    /// <returns></returns>
    public bool AddObject(InventoryObject obj) {
        bool res = (objects.Count < size);
        if (res) {
            objects.Add(obj);
            if (ObjectAddedEvent != null) {
                ObjectAddedEvent(obj.objectName);
            }
        }

        return res;
    }