public void CannotDoubleSlot() { var small = this.SlottableRequiring(2); var ev = new GameEvent_Slot(this.slottedContainer, this.slottedContainer, small); this.slottedContainer.HandleEvent(ev); var slotEvent = new GameEvent_Slot(this.slottedContainer, this.slottedContainer, small); Assert.Throws <ArgumentException> (() => this.slottedContainer.HandleEvent(slotEvent)); }
private Entity SlotEntityWithStructure(Entity container, int structure, int slotsRequired = 1) { var en = new Entity(); en.AddComponent(new Component_Slottable(slotsRequired)); en.AddComponent(new Component_InternalStructure(structure)); var ev = new GameEvent_Slot(container, container, en); container.HandleEvent(ev); return(en); }
public void CanUnslot() { var small = this.SlottableRequiring(2); var ev = new GameEvent_Slot(this.slottedContainer, this.slottedContainer, small); this.slottedContainer.HandleEvent(ev); var unslot = new GameEvent_Unslot(this.slottedContainer, this.slottedContainer, small); this.slottedContainer.HandleEvent(unslot); Assert.IsTrue(unslot.Completed); Assert.AreEqual(this.containerSize, this.slottedContainer.GetComponentOfType <Component_SlottedContainer>().SlotsRemaining); }
public void CanSlot() { var small = this.SlottableRequiring(2); var ev = new GameEvent_Slot(this.slottedContainer, this.slottedContainer, small); this.slottedContainer.HandleEvent(ev); Assert.IsTrue(ev.Completed); Assert.AreEqual(3, this.slottedContainer.GetComponentOfType <Component_SlottedContainer>().SlotsRemaining); var perfect = this.SlottableRequiring(3); var ev1 = new GameEvent_Slot(this.slottedContainer, this.slottedContainer, perfect); this.slottedContainer.HandleEvent(ev1); Assert.IsTrue(ev1.Completed); Assert.AreEqual(0, this.slottedContainer.GetComponentOfType <Component_SlottedContainer>().SlotsRemaining); }
private void HandleSlot(GameEvent_Slot ev) { if (ev.ExecutorEntity == this.Parent) { if (this.CanAttach(ev.EntityToSlot)) { this.attachedEntity = ev.EntityToSlot; ev.EntityToSlot.GetComponentOfType <Component_Attachable>().Notify_Attached(this.Parent); ev.Completed = true; } else { throw new InvalidOperationException("Can't mount item " + ev.EntityToSlot + "!"); } } }
private void HandleSlot(GameEvent_Slot ev) { if (ev.ExecutorEntity == this.Parent) { if (this.storedEntities.Contains(ev.EntityToSlot)) { throw new ArgumentException("Cannot attach attached item " + ev.EntityToSlot.ToString()); } if (this.CanSlot(ev.EntityToSlot)) { this.storedEntities.Add(ev.EntityToSlot); ev.Completed = true; } else { throw new InvalidOperationException("Can't slot item " + ev.EntityToSlot + " in " + this.Parent); } } }