Esempio n. 1
0
        private AddChildEvent RequestAdd(Thing thingToAdd)
        {
            // Prepare an add event request, and ensure both the new parent (this) and the
            // thing itself both get a chance to cancel this request before committing.
            var addChildEvent = new AddChildEvent(thingToAdd, this);

            this.Eventing.OnMovementRequest(addChildEvent, EventScope.SelfDown);
            thingToAdd.Eventing.OnMovementRequest(addChildEvent, EventScope.SelfDown);
            return(addChildEvent);
        }
Esempio n. 2
0
        private bool PerformAdd(Thing thingToAdd, AddChildEvent addEvent, MultipleParentsBehavior multipleParentsBehavior)
        {
            if (addEvent.IsCancelled)
            {
                return(false);
            }

            // If an existing thing is stackable with the added thing, combine the new
            // thing into the existing thing instead of simply adding it.
            foreach (Thing currentThing in this.Children)
            {
                if (thingToAdd.CanStack(currentThing))
                {
                    currentThing.Combine(thingToAdd);
                    return(true);
                }
            }

            // The item cannot be stacked so add the item to the specified parent.
            if (!this.Children.Contains(thingToAdd))
            {
                this.Children.Add(thingToAdd);
            }

            // If we don't have a MultipleParentsBehavior, directly set the one-allowed
            // parent ourselves, else use the behavior's logic for setting parents.
            if (multipleParentsBehavior == null)
            {
                thingToAdd.Parent = this;
            }
            else
            {
                multipleParentsBehavior.AddParent(this);
            }

            this.Eventing.OnMovementEvent(addEvent, EventScope.SelfDown);
            return(true);
        }