private bool CanBuyItem(IInventoryItem item)
        {
            if (item == null)
                return false;

            return (item.Quantity > 0);
        }
Exemplo n.º 2
0
		private void onSaveGameLoaded()
		{
			_panel = _game.Find<IPanel>(_panel.ID);
			_inventoryItemIcon = _game.Find<IObject>(_inventoryItemIcon.ID);
			_player = _game.State.Player;
			_lastInventoryItem = null;
		}
Exemplo n.º 3
0
		public async Task LoadAsync(IGameFactory factory)
		{
            AGSLoadImageConfig loadConfig = new AGSLoadImageConfig(new AGS.API.Point(0, 0));
			Bottle = await factory.Inventory.GetInventoryItemAsync("Bottle", "../../Assets/Rooms/EmptyStreet/bottle.bmp", null, loadConfig);
			VoodooDoll = await factory.Inventory.GetInventoryItemAsync("Voodoo Doll", _baseFolder + "voodooDoll.bmp", null, loadConfig, true);
			Poster = await factory.Inventory.GetInventoryItemAsync("Poster", _baseFolder + "poster.bmp", playerStartsWithItem: true);
			Manual = await factory.Inventory.GetInventoryItemAsync("Manual", _baseFolder + "manual.bmp", null, loadConfig, true);
		}
    public MarrowInventoryEnumerator(IInventoryItem[] items)
    {
        _items = items;

        for (int i = 0; i < _items.Length; i++) {
            if (_items[i] != null)
                count++;
        }
    }
Exemplo n.º 5
0
        public IInventoryItem Add(IInventoryItem item)
        {
            if (_data.ContainsKey(item.Label))
            {
                throw new InventoryException();
            }

            _data.Add(item.Label, item);
            return _data[item.Label];
        }
Exemplo n.º 6
0
 public void SetRepairItem(IInventoryItem item)
 {
     if (item == null || !item.datablock.isRepairable)
     {
         this.ClearRepairItem();
         return;
     }
     this._benchItem = item;
     this.UpdateGUIAmounts();
 }
        public bool BuyItem(IInventoryItem item)
        {
            var isSuccess = false;

            if (!CanBuyItem(item)) return isSuccess;
            item.Quantity--;
            isSuccess = true;

            return isSuccess;
        }
Exemplo n.º 8
0
		public IEvent<InventoryCombinationEventArgs> OnCombination(IInventoryItem item1, IInventoryItem item2)
		{
			var tuple1 = new Tuple<IInventoryItem, IInventoryItem> (item1, item2);
			var tuple2 = new Tuple<IInventoryItem, IInventoryItem> (item2, item1);

			var combinationEvent = _eventsMap.GetOrAdd(tuple1, _ => new AGSInteractionEvent<InventoryCombinationEventArgs>
                                   (new List<IEvent<InventoryCombinationEventArgs>> { OnDefaultCombination }, 
                                    AGSInteractions.INTERACT, null, null));
			_eventsMap[tuple2] = combinationEvent;

			return combinationEvent;
		}
Exemplo n.º 9
0
 void addItem(IInventoryItem item)
 {
     for (int i = 0; i < amount; i++) {
         try {
             inventory.Add(item);
         }
         catch (InventoryFullException ex) {
             Debug.Log(ex);
             objectWithInventory.SendMessage("OnFullInventory");
         }
     }
 }
Exemplo n.º 10
0
        /// <summary>
        /// Removes an item from storage.
        /// </summary>
        /// <param name="storage">The storage to remove from.</param>
        /// <param name="amount">Amount to be removed, -1 for all.</param>
        /// <param name="predicate">The predicate to be used, can be null for none</param>
        /// <returns>true if something was removed and false if nothing was removed.</returns>
        public static bool DeleteInventoryItem <T>(IStorage storage, int amount = -1, Func <T, bool> predicate = null)
        {
            var item = typeof(T);

            if (storage.Inventory == null)
            {
                storage.Inventory = new List <IInventoryItem>();
            }
            if (amount == -1)
            {
                IInventoryItem[] items = predicate != null?storage.Inventory.FindAll(x => x.GetType() == item).Cast <T>().Where(predicate).Cast <IInventoryItem>().ToArray() : storage.Inventory.FindAll(x => x.GetType() == item).ToArray();

                foreach (var i in items)
                {
                    storage.Inventory.Remove(i);
                    OnStorageLoseItem?.Invoke(storage, new OnLoseItemEventArgs(i, amount));
                }
                OnStorageItemUpdateAmount?.Invoke(storage, new OnItemAmountUpdatedEventArgs(item, 0));

                if (GetInventoryFilledSlots(storage) <= storage.MaxInvStorage && storage.GetType() == typeof(Character) && ((Character)storage).Player.HasSharedData("OVERWEIGHT"))
                {
                    API.Shared.ResetEntitySharedData(((Character)storage).Player,
                                                     "OVERWEIGHT");
                }
                return(true);
            }

            IInventoryItem itm = predicate != null ? (IInventoryItem)storage.Inventory.Where(x => x.GetType() == item).Cast <T>().SingleOrDefault(predicate) : storage.Inventory.SingleOrDefault(x => x.GetType() == item);

            if (itm == null)
            {
                return(false);
            }

            itm.Amount -= amount;
            if (itm.Amount <= 0)
            {
                storage.Inventory.Remove(itm);
            }

            OnStorageLoseItem?.Invoke(storage, new OnLoseItemEventArgs(itm, amount));
            OnStorageItemUpdateAmount?.Invoke(storage, new OnItemAmountUpdatedEventArgs(item, itm.Amount));

            if (GetInventoryFilledSlots(storage) <= storage.MaxInvStorage && storage.GetType() == typeof(Character) && ((Character)storage).Player.HasSharedData("OVERWEIGHT"))
            {
                API.Shared.ResetEntitySharedData(((Character)storage).Player,
                                                 "OVERWEIGHT");
            }
            return(true);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Add given item to the inventory
        /// </summary>
        /// <param name="item">Item to add</param>
        public void Add(IInventoryItem item)
        {
            if (!CanAdd(item))
            {
                return;
            }
            var freePoint = GetFirstPointThatFitsItem(item);

            if (freePoint.x == -1)
            {
                return;
            }
            AddAt(item, freePoint);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Removes an item from storage.
        /// </summary>
        /// <param name="storage">The storage to remove from.</param>
        /// <param name="item">The item to remove.</param>
        /// <param name="amount">Amount to be removed, -1 for all.</param>
        /// <param name="predicate">The predicate to be used, can be null for none</param>
        /// <returns>true if something was removed and false if nothing was removed.</returns>
        public static bool DeleteInventoryItem(IStorage storage, Type item, int amount = -1, Func <IInventoryItem, bool> predicate = null)
        {
            if (storage.Inventory == null)
            {
                storage.Inventory = new List <IInventoryItem>();
            }
            if (amount == -1)
            {
                IInventoryItem[] items = predicate != null?storage.Inventory.FindAll(x => x.GetType() == item).Where(predicate).ToArray() : storage.Inventory.FindAll(x => x.GetType() == item).ToArray();

                foreach (var i in items)
                {
                    storage.Inventory.Remove(i);
                    OnStorageLoseItem?.Invoke(storage, new OnLoseItemEventArgs(i, amount));
                }
                OnStorageItemUpdateAmount?.Invoke(storage, new OnItemAmountUpdatedEventArgs(item, 0));
                LogManager.Log(LogManager.LogTypes.Storage, $"[{GetStorageInfo(storage)}] Removed Item '{ItemTypeToNewObject(item).LongName}', Amount: '{amount}'");

                if (GetInventoryFilledSlots(storage) <= storage.MaxInvStorage && storage.GetType() == typeof(Character) && ((Character)storage).Client.HasSharedData("OVERWEIGHT"))
                {
                    API.Shared.ResetEntitySharedData(((Character)storage).Client,
                                                     "OVERWEIGHT");
                }
                return(true);
            }

            IInventoryItem itm = predicate != null?storage.Inventory.Where(x => x.GetType() == item).SingleOrDefault(predicate) : storage.Inventory.SingleOrDefault(x => x.GetType() == item);

            if (itm == null)
            {
                return(false);
            }

            itm.Amount -= amount;
            if (itm.Amount <= 0)
            {
                storage.Inventory.Remove(itm);
            }

            OnStorageLoseItem?.Invoke(storage, new OnLoseItemEventArgs(itm, amount));
            OnStorageItemUpdateAmount?.Invoke(storage, new OnItemAmountUpdatedEventArgs(item, itm.Amount));
            LogManager.Log(LogManager.LogTypes.Storage, $"[{GetStorageInfo(storage)}] Removed Item '{ItemTypeToNewObject(item).LongName}', Amount: '{amount}'");

            if (GetInventoryFilledSlots(storage) <= storage.MaxInvStorage && storage.GetType() == typeof(Character) && ((Character)storage).Client.HasSharedData("OVERWEIGHT"))
            {
                API.Shared.ResetEntitySharedData(((Character)storage).Client,
                                                 "OVERWEIGHT");
            }
            return(true);
        }
    public void OnItemClicked()
    {
        NewItemDragHandler dragHandler =
            gameObject.transform.Find("ItemImage").GetComponent <NewItemDragHandler>();

        IInventoryItem item = dragHandler.Item;

        Debug.Log(item.Name);

        _Inventory.UseItem(item);


        item.OnUse();
    }
Exemplo n.º 14
0
 public void RemoveItem(IInventoryItem item)
 {
     foreach (InventorySlot Slot in mSlots)
     {
         if (Slot.Remove(item))
         {
             if (ItemRemoved != null)
             {
                 ItemRemoved(this, new InventoryEventArgs(item));
             }
             break;
         }
     }
 }
Exemplo n.º 15
0
    private void OnTriggerEnter(Collider other)
    {
        IInventoryItem item = other.GetComponent <IInventoryItem>();

        if (item != null)
        {
            itemToPickup = item;
        }

        else if (other.gameObject.tag == "Terminal")
        {
            terminalInRange = other.gameObject.GetComponent <Terminal>();
        }
    }
Exemplo n.º 16
0
 public void RemoveItem(IInventoryItem item)
 {
     foreach (InventorySlot slot in iSlots)
     {
         if (slot.Remove(item))
         {
             if (ItemRemoved != null)
             {
                 ItemRemoved(instance, new InventoryEventArgs(item));
             }
             break;
         }
     }
 }
Exemplo n.º 17
0
 /// <inheritdoc />
 public bool TryRemove(IInventoryItem item)
 {
     if (!CanRemove(item))
     {
         return(false);
     }
     if (!_provider.RemoveInventoryItem(item))
     {
         return(false);
     }
     Rebuild(true);
     onItemRemoved?.Invoke(item);
     return(true);
 }
Exemplo n.º 18
0
        public int IndexOf(IInventoryItem item)
        {
            int index = -1;

            foreach (Record ir in _inventory)
            {
                if (ir.ID == item.ID)
                {
                    index = ir.Slot;
                }
            }

            return(index);
        }
Exemplo n.º 19
0
    /// <summary>
    /// Pick up an object, only if the collider (the object) has an IInventoryItem interface.
    /// </summary>
    /// <param name="collider">Object to pick up.</param>
    private void PickUpItem(Collider collider)
    {
        IInventoryItem item = collider.GetComponent <IInventoryItem>();

        if (item != null)
        {
            bool itemAddedCorrectly = inventory.AddItem(item, selectedSlot, rightHand.transform);
            if (itemAddedCorrectly)
            {
                hud.OnItemAdded(item, selectedSlot);
                itemOnHand = item;
            }
        }
    }
Exemplo n.º 20
0
 public IInventoryItem AddItem(string itemName)
 {
     foreach (ThoughtItem item in _definitions)
     {
         if (item.Name == itemName)
         {
             IInventoryItem newItem = item.CreateInstance();
             inventory.Add(newItem);
             return(newItem);
         }
     }
     Debug.Log("Did not find " + itemName);
     return(null);
 }
Exemplo n.º 21
0
    private void Match_OnActionEnd(IGameAction action)
    {
        if (action is TargetAction)
        {
            TargetAction   targetAction = (TargetAction)action;
            IInventoryItem item         = _creaturesInventory[targetAction.Source].ItemList.FirstOrDefault(x => x.GameAction == action);

            if (item != null)
            {
                RemoveItemFromInventory(targetAction.Source, item);
                OnRemoveInventoryItem?.Invoke(targetAction.Source, item);
            }
        }
    }
Exemplo n.º 22
0
 public void RemoveItem(IInventoryItem item)
 {
     if (mItems.Contains(item))
     {
         mItems.Remove(item);
         item.OnDrop();
         Collider collider = (item as MonoBehaviour).GetComponent <Collider>();
         if (collider != null)
         {
             collider.enabled = true;
         }
         ItemRemoved?.Invoke(this, new InventoryEventArgs(item));
     }
 }
Exemplo n.º 23
0
        object OnResearchItem(InventoryItem resourceitem, IInventoryItem otherItem)
        {
            if (!blockedResearch.Contains(otherItem.datablock.name))
            {
                return(null);
            }
            NetUser netuser = (resourceitem.inventory.idMain as Character).netUser;

            if (netuser != null)
            {
                ConsoleNetworker.SendClientCommand(netuser.networkPlayer, "notice.popup 10 q " + Facepunch.Utility.String.QuoteSafe(blockResearchMessage));
            }
            return(InventoryItem.MergeResult.Failed);
        }
Exemplo n.º 24
0
    public GameObject AddItemTitle(ItemDataBlock itemdb, IInventoryItem itemInstance = null, float aboveSpace = 0)
    {
        float      contentHeight = this.GetContentHeight();
        GameObject obj2          = NGUITools.AddChild(this.addParent, this.itemTitlePrefab);

        obj2.GetComponentInChildren <UILabel>().text = (itemInstance == null) ? itemdb.name : itemInstance.toolTip;
        UITexture componentInChildren = obj2.GetComponentInChildren <UITexture>();

        componentInChildren.material = componentInChildren.material.Clone();
        componentInChildren.material.Set("_MainTex", itemdb.GetIconTexture());
        componentInChildren.color = ((itemInstance == null) || !itemInstance.IsBroken()) ? Color.white : Color.red;
        obj2.transform.SetLocalPositionY(-(contentHeight + aboveSpace));
        return(obj2);
    }
        public void Add(UUID key, IInventoryItem value)
        {
            m_publicInventory.Add(key, value);
            var invtValue = InventoryItem.FromInterface(value);      // this could retuen null if unable to convert

            if (invtValue != null)
            {
                m_privateInventory [key] = invtValue.ToTaskInventoryItem();
            }
            else
            {
                m_privateInventory [key] = null;
            }
        }
Exemplo n.º 26
0
        public async Task LoadAsync(IGameFactory factory)
        {
            AGSLoadImageConfig loadConfig = new AGSLoadImageConfig(new AGS.API.Point(0, 0));

            Bottle = await factory.Inventory.GetInventoryItemAsync("Bottle", "../../Assets/Rooms/EmptyStreet/bottle.bmp", null, loadConfig);

            VoodooDoll = await factory.Inventory.GetInventoryItemAsync("Voodoo Doll", _baseFolder + "voodooDoll.bmp", null, loadConfig, true);

            Poster = await factory.Inventory.GetInventoryItemAsync("Poster", _baseFolder + "poster.bmp", playerStartsWithItem : true);

            Manual = await factory.Inventory.GetInventoryItemAsync("Manual", _baseFolder + "manual.bmp", null, loadConfig, true);

            Poster.OnCombination(Manual).SubscribeToAsync(onPutPosterInManual);
        }
Exemplo n.º 27
0
    private bool Contains(IInventoryItem comp) // FIXME compare isnt working for items - switch compare to geno ID?
    {
        bool result = false;

        foreach (IInventoryItem i in items)
        {
            if (i == comp)
            {
                result = true;
                break;
            }
        }
        return(result);
    }
Exemplo n.º 28
0
        public async Task <IActionResult> Get(int id, string session)
        {
            LoadSession(Guid.Parse(session));

            IInventoryItem item = inventory.Find(x => x.Id == id);

            if (item == null)
            {
                SetSession(Guid.Parse(session));
                return(new JsonResult(new List <int>()));
            }

            return(new OkObjectResult(item));
        }
Exemplo n.º 29
0
    //使用武器
    private void Inventory_ItemUsed(object sender, InventoryEventArgs e)
    {
        print("使用武器");
        IInventoryItem item = e.Item;

        //Do some with the object
        GameObject goItem = (item as MonoBehaviour).gameObject;

        goItem.SetActive(true);

        goItem.transform.parent   = Hand.transform;
        goItem.transform.position = Hand.transform.position;
        goItem.transform.rotation = Hand.transform.rotation;
    }
Exemplo n.º 30
0
    /// <summary>
    /// Sets up the display properly based on item data
    /// </summary>
    /// <param name="item">The item to display</param>
    public void SetItem(IInventoryItem item)
    {
        if (_item != null)
        {
            _item.PropertyChanged -= Item_PropertyChanged;
        }

        _item = item;
        if (item != null)
        {
            _item.PropertyChanged += Item_PropertyChanged;
        }

        SetImage();
    }
Exemplo n.º 31
0
 public void Internal_SetToolTip(ItemDataBlock itemdb, IInventoryItem item)
 {
     this.ClearContents();
     if (itemdb == null)
     {
         this.SetVisible(false);
     }
     else
     {
         this.RepositionAtCursor();
         itemdb.PopulateInfoWindow(this, item);
         this._background.transform.localScale = new Vector3(250f, this.GetContentHeight() + Mathf.Abs((float)(this.addParent.transform.localPosition.y * 2f)), 1f);
         this.SetVisible(true);
     }
 }
Exemplo n.º 32
0
    public void AddItem(IInventoryItem item)
    {
        if (_items.Count < SLOTS)
        {
            Collider2D col = (item as MonoBehaviour)?.GetComponent <Collider2D>();

            if (col != null && col.enabled)
            {
                col.enabled = false;
                _items.Add(item);
                item.OnPickup();
                ItemAdded?.Invoke(this, new InventoryEventArgs(item));
            }
        }
    }
Exemplo n.º 33
0
        public IEvent <InventoryCombinationEventArgs> Subscribe(IInventoryItem item1, IInventoryItem item2)
        {
            var tuple1 = (item1, item2);
            var tuple2 = (item2, item1);

            var combinationEvent = _subscriptions.GetOrAdd(tuple1, _ => new AGSInteractionEvent <InventoryCombinationEventArgs>
                                                               (new List <IEvent <InventoryCombinationEventArgs> > {
                _defaultInteractions.OnInventoryCombination
            },
                                                               AGSInteractions.INTERACT, null, null));

            _subscriptions[tuple2] = combinationEvent;

            return(combinationEvent);
        }
Exemplo n.º 34
0
        public async Task <IActionResult> Delete(int id, string session)
        {
            LoadSession(Guid.Parse(session));

            IInventoryItem item = inventory.Find(x => x.Id == id);

            if (item == null)
            {
                return(new NotFoundResult());
            }

            inventory.Remove(item);
            SetSession(Guid.Parse(session));
            return(new OkObjectResult(inventory));
        }
Exemplo n.º 35
0
    public void OnDrop(PointerEventData eventData)
    {
        RectTransform invPanel = transform as RectTransform;

        if (!RectTransformUtility.RectangleContainsScreenPoint(invPanel,
                                                               Input.mousePosition))
        {
            IInventoryItem item = eventData.pointerDrag.gameObject.GetComponent <ItemDragHandler>().Item;
            if (item != null)
            {
                _Inventory.RemoveItem(item);
                item.OnDrop();
            }
        }
    }
Exemplo n.º 36
0
        public void Put(IInventoryItem inventoryItem)
        {
            if (inventoryItem == null)
            {
                Debug.LogWarning("Trying to add to inventory null.");

                return;
            }

            _inventoryItems.Add(inventoryItem);

            Debug.Log(string.Format("Inventory item({0}) was putted in to inventory.", (inventoryItem.GetType().Name)));

            InventoryItemAmountChanged.Invoke(inventoryItem.GetType(), _inventoryItems.Count(x => x.GetType() == inventoryItem.GetType()));
        }
Exemplo n.º 37
0
    public void RemoveItem(IInventoryItem item)
    {
        if (_items.Contains(item))
        {
            _items.Remove(item);

            Collider2D col = (item as MonoBehaviour).GetComponent <Collider2D>();
            if (col != null)
            {
                col.enabled = true;
            }

            ItemRemoved?.Invoke(this, new InventoryEventArgs(item));
        }
    }
Exemplo n.º 38
0
        /// <summary>
        /// Add given item to the inventory
        /// </summary>
        /// <param name="item">Item to add</param>
        public bool Add(IInventoryItem item)
        {
            if (!CanAdd(item))
            {
                return(false);
            }
            var freePoint = GetFirstPointThatFitsItem(item);

            if (freePoint.x == -1)
            {
                return(false);
            }
            AddAt(item, freePoint);
            return(true);
        }
Exemplo n.º 39
0
 /*
  * Get first free point that will fit the given item
  */
 private Vector2Int GetFirstPointThatFitsItem(IInventoryItem item)
 {
     for (var x = 0; x < Width - (item.Shape.Width - 1); x++)
     {
         for (var y = 0; y < Height - (item.Shape.Height - 1); y++)
         {
             var p = new Vector2Int(x, y);
             if (CanAddAt(item, p))
             {
                 return(p);
             }
         }
     }
     return(new Vector2Int(-1, -1));
 }
Exemplo n.º 40
0
 public bool AddItem(IInventoryItem item, int amount)
 {
     lock (storedItems)
     {
         if (storedItems.ContainsKey(item.Name))
         {
             storedItems[item.Name].second += amount;
             return true;
         }
         else if (storedItems.Count < capacity)
         {
             storedItems.Add(item.Name, new Pair<IInventoryItem, int>(item, amount));
             return true;
         }
         return false;
     }
 }
Exemplo n.º 41
0
 private void MakeEmpty()
 {
     this._myDisplayItem = null;
     this._icon.enabled = false;
     this._stackLabel.text = string.Empty;
     this._usesLabel.text = string.Empty;
     if (this._amountBackground)
     {
         this._amountBackground.enabled = false;
     }
     if ((int)this.modSprites.Length > 0)
     {
         for (int i = 0; i < (int)this.modSprites.Length; i++)
         {
             this.modSprites[i].enabled = false;
         }
     }
 }
Exemplo n.º 42
0
 public GameObject AddConditionInfo(IInventoryItem item)
 {
     if (item == null || !item.datablock.DoesLoseCondition())
     {
         return null;
     }
     Color color = Color.green;
     if (item.condition <= 0.6f)
     {
         color = Color.yellow;
     }
     else if (item.IsBroken())
     {
         color = Color.red;
     }
     float single = 100f * item.condition;
     float single1 = 100f * item.maxcondition;
     GameObject gameObject = this.AddBasicLabel(string.Concat("Condition : ", single.ToString("0"), "/", single1.ToString("0")), 15f, color);
     return gameObject;
 }
Exemplo n.º 43
0
 public void Edit(IInventoryItem item)
 {
     if (item == null)
     {
         throw new ArgumentNullException("item");
     }
     _logger.InfoFormat("InventoryController.Edit(IInventoryItem) {0}", item.Id);
     ResolveAndActivateItemsEditView(item);
 }
Exemplo n.º 44
0
 public static InventoryItem.MergeResult ResearchItemKit(IInventoryItem otherItem, IResearchToolItem researchItem)
 {
     BlueprintDataBlock block2;
     PlayerInventory inventory = researchItem.inventory as PlayerInventory;
     if ((inventory == null) || (otherItem.inventory != inventory))
     {
         return InventoryItem.MergeResult.Failed;
     }
     PlayerClient playerClient = Array.Find(AllPlayerClients.ToArray(), (PlayerClient pc) => pc.netPlayer == inventory.networkView.owner);
     ItemDataBlock datablock = otherItem.datablock;
     if ((datablock == null) || !datablock.isResearchable || restrictResearch.Contains(otherItem.datablock.name))
     {
         if (datablock == null)
             return InventoryItem.MergeResult.Failed;
         if (!datablock.isResearchable || restrictResearch.Contains(otherItem.datablock.name))
         {
             if (!permitResearch.Contains(otherItem.datablock.name) && !craftList.Contains(playerClient.userID.ToString()))
             {
                 Rust.Notice.Popup(inventory.networkView.owner, "", "You cannot research this item!", 4f);
                 return InventoryItem.MergeResult.Failed;
             }
         }
     }
     if (!inventory.AtWorkBench() && researchAtBench && !craftList.Contains(playerClient.userID.ToString()))
     {
         Rust.Notice.Popup(inventory.networkView.owner, "", "You must be at a workbench to research.", 4f);
         return InventoryItem.MergeResult.Failed;
     }
     if (!BlueprintDataBlock.FindBlueprintForItem<BlueprintDataBlock>(otherItem.datablock, out block2))
     {
         Rust.Notice.Popup(inventory.networkView.owner, "", "There is no crafting recipe for this.", 4f);
         return InventoryItem.MergeResult.Failed;
     }
     if (inventory.KnowsBP(block2))
     {
         Rust.Notice.Popup(inventory.networkView.owner, "", "You already researched this.", 4f);
         return InventoryItem.MergeResult.Failed;
     }
     IInventoryItem paper;
     int numPaper = 1;
     if (researchPaper && !craftList.Contains(playerClient.userID.ToString()))
     {
         if (hasItem(playerClient, "Paper", out paper))
         {
             if (paper.Consume(ref numPaper))
                 paper.inventory.RemoveItem(paper.slot);
         }
         else
         {
             Rust.Notice.Popup(inventory.networkView.owner, "", "Researching requires paper.", 4f);
             return InventoryItem.MergeResult.Failed;
         }
     }
     inventory.BindBlueprint(block2);
     Rust.Notice.Popup(inventory.networkView.owner, "", "You can now craft: " + otherItem.datablock.name, 4f);
     int numWant = 1;
     if (!infiniteResearch)
     {
         if (researchItem.Consume(ref numWant))
             researchItem.inventory.RemoveItem(researchItem.slot);
     }
     return InventoryItem.MergeResult.Combined;
 }
Exemplo n.º 45
0
 public static void removeItem(PlayerClient playerClient, IInventoryItem item)
 {
     Inventory inventory = playerClient.controllable.GetComponent<Inventory>();
     inventory.RemoveItem(item.slot);
 }
 public bool Save(IInventoryItem item)
 {
     return _inventoryService.SaveInventoryItem(item.ToDao());
 }
Exemplo n.º 47
0
        public static ItemPermissionBlock FromOther(IInventoryItem other)
        {
            ItemPermissionBlock newBlock = new ItemPermissionBlock();
            newBlock.BasePermissions = other.BasePermissions;
            newBlock.NextPermissions = other.NextPermissions;
            newBlock.EveryOnePermissions = other.EveryOnePermissions;
            newBlock.GroupPermissions = other.GroupPermissions;
            newBlock.CurrentPermissions = other.CurrentPermissions;

            return newBlock;
        }
Exemplo n.º 48
0
 public InventoryEventArgs(IInventoryItem item)
 {
     InventoryItem = item;
 }
Exemplo n.º 49
0
        public void Delete(IInventoryItem item)
        {
            _logger.InfoFormat("InventoryController.Delete(IInventoryItem) Id {0}.", item.Id);
            _inventoryService.DeleteInventoryItem(item.Id);

            OnActivateItemsViewRequested();


        }
Exemplo n.º 50
0
 public InventorySoldMessage(IInventoryItem inventory)
 {
     this.InventorySold = inventory;
 }
Exemplo n.º 51
0
        private void ResolveAndActivateItemsEditView(IInventoryItem inventoryItem)
        {
            var editModel = _container.Resolve<IItemEditViewModel>();


            if (editModel == null || editModel.View == null)
            {
                return;
            }

            editModel.InventoryItem = inventoryItem;

            //Set data source for list entries in view
            editModel.Categories = _inventoryService.GetCategories();
            editModel.Locations = _inventoryService.GetLocations();
            editModel.Suppliers = _inventoryService.GetSuppliers();

            var region = _regionManager.Regions[RegionNames.MainRegion];

            if (region == null)
            {
                return;
            }

            region.Activate(editModel.View);
        }
Exemplo n.º 52
0
        private SceneObjectGroup RezSingleObjectToWorld(IClientAPI remoteClient, UUID itemID, 
            SceneObjectGroup group, Vector3 RayEnd, Vector3 RayStart,
            UUID RayTargetID, byte BypassRayCast, byte bRayEndIsIntersection,
            bool RezSelected, bool attachment, Vector3 pos, string name,
            string description, IInventoryItem item, ItemPermissionBlock itemPermissions,
            int? startParam, UUID? newAvatarGroupId, UUID? rezzedByObjectUUID)
        {
            bool ownerChanged = false;  // record this for the CHANGED_OWNER changed event

            if (IsBadUserLoad(group))
            {
                if (remoteClient != null)
                    remoteClient.SendAgentAlertMessage("You are currently not allowed to rez objects in this region.", false);
                return null;   // already reported above
            }
            if (IsBlacklistedLoad(group))
            {
                if (remoteClient != null)
                    remoteClient.SendAgentAlertMessage("Cannot rez blacklisted object '" + group.Name + "'.", false);
                return null;   // already reported above
            }

            //set the group here so that positioning in world will enable/disable the
            //script correctly based on the group the use is currently in

            // Initialize the server weight (LI)
            group.RecalcPrimWeights();

            group.RezzedFromFolderId = item.Folder;
            //group.FromAssetId = item.AssetID; //not needed yet

            if (newAvatarGroupId.HasValue)
            {
                //set the object's land group
                group.SetGroup(newAvatarGroupId.Value, null);
            }

            if (attachment)
            {
                group.SetFromItemID(itemID);
            }
            else
            {
                group.RootPart.SetGroupPositionDirect(pos);

                if (RezSelected)
                {
                    //also tell the client there is a new object being rezzed
                    foreach (SceneObjectPart part in group.GetParts())
                    {
                        part.AddFlag(PrimFlags.CreateSelected);
                    }
                }
            }

            SceneObjectPart rootPart = group.GetChildPart(group.UUID);
            if (rootPart == null) {
                string what = "object ";
                if (attachment)
                    what = " attachment ";
                m_log.Error("[AGENT INVENTORY]: Error rezzing ItemID: " + itemID + what + " root part not found.");
                return null;
            }

            // Since renaming the item in the inventory does not affect the name stored
            // in the serialization, transfer the correct name from the inventory to the
            // object itself before we rez.
            rootPart.Name = name;
            rootPart.Description = description;

            var partList = group.GetParts();

            foreach (SceneObjectPart part in partList)
            {
                /// This fixes inconsistencies between this part and the root part.
                /// In the past, there was a bug in Link operations that did not force 
                /// these permissions on child prims when linking.
                part.SyncChildPermsWithRoot();
            }

            if (rootPart.OwnerID != item.Owner)
            {
                if (Permissions.PropagatePermissions())
                {
                    if ((itemPermissions.CurrentPermissions & ScenePermBits.SLAM) != 0)
                    {    // enforce slam bit, apply item perms to the group parts
                        foreach (SceneObjectPart part in partList)
                        {
                            part.EveryoneMask = item.EveryOnePermissions;
                            part.NextOwnerMask = item.NextPermissions;
                            part.GroupMask = 0; // DO NOT propagate here
                        }
                    }
                    group.ApplyNextOwnerPermissions();
                }
            }

            ownerChanged |= group.Rationalize(item.Owner, false);

            foreach (SceneObjectPart part in partList)
            {
                if (part.OwnerID != item.Owner)
                {
                    part.LastOwnerID = part.OwnerID;
                    part.OwnerID = item.Owner;
                    part.Inventory.ChangeInventoryOwner(item.Owner);
                    ownerChanged = true;
                }
                else if (((itemPermissions.CurrentPermissions & ScenePermBits.SLAM) != 0) && (!attachment)) // Slam!
                {
                    part.EveryoneMask = itemPermissions.EveryOnePermissions;
                    part.NextOwnerMask = itemPermissions.NextPermissions;

                    part.GroupMask = 0; // DO NOT propagate here
                }
            }

            rootPart.TrimPermissions();

            if (!attachment)
            {
                if (group.RootPart.IsPrim)
                {
                    group.ClearPartAttachmentData();
                }
            }

            if (this.AddObjectToSceneIfPermitted(group, remoteClient, pos, attachment, rezzedByObjectUUID))
            {
                if (ownerChanged)
                {
                    foreach (SceneObjectPart part in partList)
                        part.TriggerScriptChangedEvent(Changed.OWNER);
                }

                if (!attachment)
                {
                    // Fire on_rez
                    group.CreateScriptInstances(startParam, ScriptStartFlags.PostOnRez, DefaultScriptEngine, (int)ScriptStateSource.PrimData, null);

                    rootPart.ScheduleFullUpdate(PrimUpdateFlags.ForcedFullUpdate);
                }

            } 
            else 
            {
                // The viewer automatically removes no-copy items from inventory on a rez attempt.
                // Since this one did not rez, it's still in inventory so let's "put it back".
                if (remoteClient != null)
                {
                    InventoryItemBase ib = item as InventoryItemBase;

                    if (item != null)
                    {
                        //this is a folder item, not a task item. update the user
                        remoteClient.SendInventoryItemCreateUpdate(ib, 0);
                    }
                }
                return null;
            }

            return rootPart.ParentGroup;
        }
Exemplo n.º 53
0
        private bool RezCoalescedObject(IClientAPI remoteClient, UUID itemID, 
            CoalescedObject obj, Vector3 RayEnd, Vector3 RayStart, UUID RayTargetID, 
            byte BypassRayCast, byte bRayEndIsIntersection, 
            bool RezSelected, bool rezAtRoot, Vector3 pos, 
            IInventoryItem item, int? startParam, UUID? newAvatarGroupId,
            UUID? rezzedByObjectUUID)
        {
            //determine the bounding box of the entire set
            Box coBoundingBox = obj.GetBoundingBox();
            Vector3 rezAtRootOffset = Vector3.Zero;

            pos = GetNewRezLocation(
                  RayStart, RayEnd, RayTargetID, Quaternion.Identity,
                  BypassRayCast, bRayEndIsIntersection, true, coBoundingBox.Size, false, 
                  remoteClient != null ? remoteClient.AgentId : UUID.Zero);

            Vector3 newPos = coBoundingBox.Center;
            if (rezAtRoot)
            {
                // Use the root prim position of the last object (matches SL).
                SceneObjectGroup lastGroup = null;
                foreach (SceneObjectGroup group in obj.Groups)
                    lastGroup = group;

                if (lastGroup != null)
                    rezAtRootOffset = (coBoundingBox.Center - lastGroup.RootPart.AbsolutePosition);
            }

            //reset the positions of all parts to be an offset from 0
            SceneObjectGroup.TranslateToNewCenterPosition(coBoundingBox.Center, pos, obj.Groups);
            
            //rez each group
            bool success = true;
            foreach (SceneObjectGroup group in obj.Groups)
            {
                group.ResetInstance(true, false, UUID.Zero);
                success = success &&
                (this.RezSingleObjectToWorld(remoteClient, itemID, group, RayEnd, RayStart, RayTargetID,
                    BypassRayCast, bRayEndIsIntersection, RezSelected, false, group.AbsolutePosition+rezAtRootOffset,
                    group.RootPart.Name, group.RootPart.Description, item, obj.FindPermissions(group.UUID),
                    startParam, newAvatarGroupId, rezzedByObjectUUID)) != null;
            }

            return success;
        }
Exemplo n.º 54
0
		private void onRepeatedlyExecute(object sender, AGSEventArgs args)
		{
            if (_player == null) return;
			if (_lastInventoryItem == _player.Inventory.ActiveItem) return;

			_lastInventoryItem = _player.Inventory.ActiveItem;

			if (_lastInventoryItem != null)
			{
				_inventoryItemIcon.Image = _lastInventoryItem.CursorGraphics.Image;
				_inventoryItemIcon.Animation.Sprite.Anchor = new AGS.API.PointF (0.5f, 0.5f);
				_inventoryItemIcon.ScaleTo(15f, 15f);
			}
			_inventoryItemIcon.Visible = (_lastInventoryItem != null);
		}
Exemplo n.º 55
0
 public bool SetHeldItem(IInventoryItem item)
 {
     if (item == null)
     {
         this.MakeEmpty();
         if (!this.fadingOut)
         {
             this.Opaque();
         }
         return false;
     }
     this.hasItem = true;
     Texture texture = item.datablock.iconTex;
     ItemDataBlock.LoadIconOrUnknown<Texture>(item.datablock.icon, ref texture);
     this._icon.enabled = true;
     this._myMaterial.Set("_MainTex", texture);
     this._itemHolding = item;
     Vector3 vector3 = new Vector2();
     Vector3 vector31 = vector3;
     this.offsetPoint = vector3;
     this.offsetVelocity = vector31;
     this.Opaque();
     return true;
 }
Exemplo n.º 56
0
 private void MakeEmpty()
 {
     if (this._icon)
     {
         this._icon.enabled = false;
     }
     this._itemHolding = null;
     this.hasItem = false;
 }
Exemplo n.º 57
0
 private void OnItemRemoved(Inventory inventory, int slot, IInventoryItem item)
 {
     HookCalled("OnItemRemoved");
     // Print item removed
     var netUser = inventory.GetComponent<Character>()?.netUser;
     if (netUser == null) return;
     Puts(item.datablock.name + " was removed from inventory slot " + slot.ToString() + " owned by " + netUser.displayName);
 }
Exemplo n.º 58
0
 private void OnResearchItem(ResearchToolItem<ResearchToolDataBlock> tool, IInventoryItem item)
 {
     HookCalled("OnResearchItem");
     // TODO: Complete parameters
     //var netUser = item.inventory.GetComponent<Character>()?.netUser;
     var netUser = item.inventory.GetComponent<Character>()?.netUser;
     if (netUser == null) return;
     Puts(netUser.displayName + " used " + tool.datablock.name + " on the item " + item.datablock.name);
 }
		public InventoryCombinationEventArgs (IInventoryItem activeItem, IInventoryItem passiveItem)
		{
			ActiveItem = activeItem;
			PassiveItem = passiveItem;
		}
Exemplo n.º 60
0
        public void Save(IInventoryItem item)
        {
            _inventoryService.Save(item.ToDao());

            OnActivateItemsViewRequested();
        }