/// <summary> /// Drops one item from the slot with the specified _index. /// </summary> /// <param name="_index">Index.</param> public void Drop(int _index) { InventorySlotObject _slot = GetSlotByIndex(_index); if (_slot != null) { _slot.DropItem(); } }
/// <summary> /// Current amount of the specified item name /// </summary> /// <returns>The item amount.</returns> /// <param name="_name">Name.</param> public int SlotItemAmount(string _name) { InventorySlotObject _slot = GetSlotByItemName(_name); if (_slot != null) { return(_slot.Amount); } else { return(0); } }
public void Copy(InventorySlotObject _slot) { if (_slot == null) { return; } MountPointName = _slot.MountPointName; IsExclusive = _slot.IsExclusive; ItemName = _slot.ItemName; MaxAmount = _slot.MaxAmount; Amount = _slot.Amount; UseRandomAmount = _slot.UseRandomAmount; UseDetachOnDie = _slot.UseDetachOnDie; }
private InventorySlotObject ForceSlotByItem(GameObject _item, int _required_amount) { if (_item == null) { return(null); } InventorySlotObject _slot = ForceSlotByItemName(_item.name, _required_amount); if (_slot != null && _item.transform.IsChildOf(Owner.transform)) { _slot.MountPointName = _item.transform.parent.name; } return(_slot); }
private InventorySlotObject ForceSlotByItemName(string _name, int _required_amount) { InventorySlotObject _slot = GetSlotByItemName(_name, _required_amount); if (_slot == null) { _slot = GetEmptySlot(); } // if there is no slot and the inventory is not static create a new slot if (_slot == null && (!UseStaticSlots || !Application.isPlaying)) { _slot = new InventorySlotObject(OwnerComponent, _name, _required_amount); Slots.Add(_slot); } return(_slot); }
public bool Insert(GameObject _object) { if (_object == null || !_object.activeInHierarchy) { return(false); } InventorySlotObject _slot = ForceSlotByItem(_object, 1); if (_slot != null) { if (_slot.SetItemObject(_object)) { if (DebugLogIsEnabled) { PrintDebugLog(this, "Insert - '" + _object.name + "' inserted and attached to slot (new amount : " + _slot.Amount + "/" + _slot.MaxAmount + ")"); } } else if (_slot.FreeCapacity >= 1) { if (_slot.IsEmpty) { _slot.ItemName = _object.name; } _slot.Amount++; CreatureRegister.Remove(_object); if (DebugLogIsEnabled) { PrintDebugLog(this, "Insert - '" + _object.name + "' amount increased of slot (new amount : " + _slot.Amount + "/" + _slot.MaxAmount + ") and original object removed"); } } else { //if( DebugLogIsEnabled ) PrintDebugLog( this, "Insert - '" + _object.name + "' amount increased of slot (new amount : " + _slot.Amount + "/" + _slot.MaxAmount + ") and original object removed" ); return(false); } return(true); } return(false); }
public int Insert(string _name, int _amount) { int _rest = _amount; InventorySlotObject _named_slot = ForceSlotByItemName(_name, _amount); if (_named_slot != null) { _rest = _named_slot.TryUpdateAmount(_name, _rest); } if (_rest > 0) { foreach (InventorySlotObject _slot in Slots) { _rest = _slot.TryUpdateAmount(_name, _rest); } } return(_rest); }
public InventorySlotObject(ICEWorldBehaviour _component, InventorySlotObject _slot) : base(_component) { Copy(_slot); }
public void Action(InventoryActionDataObject _action) { if (_action == null || !_action.Enabled) { return; } if (_action.DropItemRequired()) { InventorySlotObject _slot = GetSlotByItemName(_action.ItemName); if (_slot != null && _slot.Amount > 0) { Transform _transform = ICE.World.Utilities.SystemTools.FindChildByName(_action.ParentName, Owner.transform); _transform = (_transform != null ? _transform : Owner.transform); Quaternion _rotation = Quaternion.Euler(0, UnityEngine.Random.Range(0, 360), 0); Vector3 _position = PositionTools.FixTransformPoint(_transform, _action.Offset); GameObject _item = _slot.GiveItem(_position, _rotation); if (_item == null) { _item = CreatureRegister.Spawn(_slot.ItemReferenceObject, _position, _rotation); _slot.Amount--; } } } else if (_action.ParentUpdateRequired()) { InventorySlotObject _slot = GetSlotByItemName(_action.ItemName); if (_slot != null && _slot.Amount > 0) { if (_slot.ItemObject != null) { _slot.MountPointName = _action.ParentName; } } } else if (_action.CollectActiveItemRequired()) { ICECreatureControl _control = OwnerComponent as ICECreatureControl; TargetObject _target = _control.Creature.ActiveTarget; if (_control != null && _target != null && _target.Selectors.TotalCheckIsValid) //&& LastCollectedObjectID != _target.TargetID ) { GameObject _item = _target.TargetGameObject; //LastCollectedObjectID = _target.TargetID; if (_target.EntityComponent != null && _target.EntityComponent.IsChildEntity) { ICEWorldEntity _parent = _target.EntityComponent.RootEntity; if (_parent != null) { if (DebugLogIsEnabled) { PrintDebugLog(this, "CollectActiveItem : take '" + _target.Name + "' from " + _parent.name + " (" + _parent.ObjectInstanceID + ")"); } InventorySlotObject _slot = GetInventorySlot(_parent.gameObject, _target.TargetName); if (_slot != null) { _item = _slot.GiveItem(); } } } if (Insert(_item)) { //Debug.Log( _control.Creature.ActiveTarget.TargetGameObject.name + " - " + _control.Creature.ActiveTarget.TargetGameObject.GetInstanceID() ); //_target.ResetTargetGameObject(); _control.Creature.ResetActiveTarget(); // } } } }