/// <summary> /// Simpler function to call instead of ThreadManager.StartEvent. Return value works the same way. /// </summary> /// <param name="mob"></param> /// <returns></returns> public IDisposable StartEventFor(MOB mob, int timeout = 1000, bool?ignorePause = null) { restart: Body body = mob.Body; Room startingRoom = body.Position.ForRoom; IDisposable disposable; using (disposable = ThreadManager.StartEvent(startingRoom, this, timeout, ignorePause)) { if (disposable == null) { return(null); //Notify caller that event entirely failed. } if (mob.Body != body || body.Position.ForRoom != startingRoom) { // Race condition, need to try again with new body/get lock for new room. goto restart; //This is probably fine but might make something smarter later. } disposable = null; //Have the caller dispose this instead. return(this); } }
public override IDisposable StarttEventLocks() { IDisposable disposable, returnValue; using (disposable = ThreadManager.StartEvent(originalPosition.ForRoom, this)) { if (originalPosition.ForRoom != eventSource.Position.ForRoom) { AddItemLock(eventSource); } if (originalPosition.ForRoom != movementSource.Body.Position.ForRoom) { AddMOBLock(movementSource); } if (originalPosition.ForRoom != targetPosition.ForRoom) { AddRoomLock(targetPosition.ForRoom); } returnValue = disposable; disposable = null; return(returnValue); } }