public void Init(ItemInstance itemInstance) { ItemInstance = itemInstance; }
public bool InstantiateIndividuals; // if true, it will instantiate 1 prefab instance per quantity public virtual bool CanMove(ItemInstance i) { return(true); }
public ItemInstance(ItemInstance i) { ItemType.Value = i.ItemType.Value; Quantity.Value = i.Quantity.Value; }
public virtual bool Set(ItemInstance item) { Quantity.Value = item.Quantity.Value; ItemType.Value = item.ItemType.Value; return(true); }
private void Lift(int amount) { var amountLeft = _originalLiftedItem.Item.Quantity.Value - amount; _originalLiftedItem.Item.Set(amountLeft); _clonedLiftedItem.Item.Set(amount); OnCancel = () => { _originalLiftedItem.Item.ItemType.Value = _clonedLiftedItem.Item.ItemType.Value; _originalLiftedItem.Item.Quantity.Value = _originalLiftedItem.Item.Quantity.Value + _clonedLiftedItem.Item.Quantity.Value; CancelLift(); }; Action <ItemInstance> move = (target) => { // merging if (target.ItemType.Value == _clonedLiftedItem.Item.ItemType.Value) { var overflow = target.Add(_clonedLiftedItem.Item.Quantity.Value); if (overflow > 0) { _originalLiftedItem.SetItem(new ItemInstance(_clonedLiftedItem.Item.ItemType.Value, overflow)); } FinishLift(); } // there is still something in the original stack, cloned stack and target stack. We are lifting a portion, you can't put that in the target stack then else if (!_originalLiftedItem.IsEmpty && !_clonedLiftedItem.IsEmpty && !target.IsEmpty) { OnCancel(); } // most common case, lifting a full stack onto another item else { var targetBefore = new ItemInstance(target); bool success = target.CanMove(_clonedLiftedItem.Item) && _originalLiftedItem.CanMove(targetBefore); if (success) { target.Set(_clonedLiftedItem.Item); if (_originalLiftedItem.IsEmpty) { _originalLiftedItem.Item.Set(targetBefore); } FinishLift(); } else { OnCancel(); } } }; OnTryLiftEnd = (targetView) => { var canMove = targetView.CanMove(_clonedLiftedItem.Item); if (canMove) { move(targetView.Item); } else { OnCancel(); } }; OnComplete = (item) => { move(item); }; }