private ActionChain CreateMoveToChain(WorldObject target, out int thisMoveToChainNumber) { thisMoveToChainNumber = GetNextMoveToChainNumber(); ActionChain moveToChain = new ActionChain(); moveToChain.AddAction(this, () => { if (target.Location == null) { log.Error("Player_Use CreateMoveToChain targetObject.Location null"); return; } if (target.WeenieType == WeenieType.Portal) { OnAutonomousMove(target.Location, Sequences, MovementTypes.MoveToPosition, target.Guid, (target.UseRadius ?? 0)); } else { OnAutonomousMove(target.Location, Sequences, MovementTypes.MoveToObject, target.Guid, (target.UseRadius ?? 0)); } }); // poll for arrival every .1 seconds ActionChain moveToBody = new ActionChain(); moveToBody.AddDelaySeconds(.1); var thisMoveToChainNumberCopy = thisMoveToChainNumber; moveToChain.AddLoop(this, () => { if (thisMoveToChainNumberCopy != moveToChainCounter) { return(false); } // Break loop if CurrentLandblock == null (we portaled or logged out) if (CurrentLandblock == null) { return(false); } // Are we within use radius? var valid = false; bool ret = CurrentLandblock != null ? !CurrentLandblock.WithinUseRadius(this, target.Guid, out valid) : false; // If one of the items isn't on a landblock if (!valid) { ret = false; } return(ret); }, moveToBody); return(moveToChain); }
private ActionChain CreateMoveToChain(ObjectGuid target, out int thisMoveToChainNumber) { thisMoveToChainNumber = GetNextMoveToChainNumber(); ActionChain moveToChain = new ActionChain(); moveToChain.AddAction(this, () => { var targetObject = CurrentLandblock?.GetObject(target); if (targetObject == null) { // Is the item we're trying to move to in the container we have open? var lastUsedContainer = CurrentLandblock?.GetObject(lastUsedContainerId) as Container; if (lastUsedContainer != null) { if (lastUsedContainer.Inventory.ContainsKey(target)) { targetObject = lastUsedContainer; } else { // could be a child container of this container log.Error("Player_Use CreateMoveToChain container inception not finished"); return; } } } if (targetObject == null) { log.Error("Player_Use CreateMoveToChain targetObject null"); return; } if (targetObject.Location == null) { log.Error("Player_Use CreateMoveToChain targetObject.Location null"); return; } if (targetObject.WeenieType == WeenieType.Portal) { OnAutonomousMove(targetObject.Location, Sequences, MovementTypes.MoveToPosition, target, (targetObject.UseRadius ?? 0)); } else { OnAutonomousMove(targetObject.Location, Sequences, MovementTypes.MoveToObject, target, (targetObject.UseRadius ?? 0)); } }); // poll for arrival every .1 seconds ActionChain moveToBody = new ActionChain(); moveToBody.AddDelaySeconds(.1); var thisMoveToChainNumberCopy = thisMoveToChainNumber; moveToChain.AddLoop(this, () => { if (thisMoveToChainNumberCopy != moveToChainCounter) { return(false); } // Break loop if CurrentLandblock == null (we portaled or logged out) if (CurrentLandblock == null) { return(false); } // Are we within use radius? var valid = false; bool ret = CurrentLandblock != null ? !CurrentLandblock.WithinUseRadius(this, target, out valid) : false; // If one of the items isn't on a landblock if (!valid) { ret = false; } return(ret); }, moveToBody); return(moveToChain); }
public ActionChain CreateMoveToChain(WorldObject target, out int thisMoveToChainNumber) { thisMoveToChainNumber = GetNextMoveToChainNumber(); ActionChain moveToChain = new ActionChain(); moveToChain.AddAction(this, () => { if (target.Location == null) { log.Error($"{Name}.CreateMoveToChain({target.Name}): target.Location is null"); return; } if (target.WeenieType == WeenieType.Portal) { MoveToPosition(target.Location); } else { MoveToObject(target); } }); // poll for arrival every .1 seconds // Ideally, this should be switched away from using the DelayManager, and instead be checked on every Player Tick() ActionChain moveToBody = new ActionChain(); moveToBody.AddDelaySeconds(.1); var thisMoveToChainNumberCopy = thisMoveToChainNumber; moveToChainStartTime = DateTime.UtcNow; moveToChain.AddLoop(this, () => { if (thisMoveToChainNumberCopy != moveToChainCounter) { return(false); } // Break loop if CurrentLandblock == null (we portaled or logged out) if (CurrentLandblock == null) { StopExistingMoveToChains(); // This increments our moveToChainCounter and thus, should stop any additional actions in this chain return(false); } // Have we timed out? if (moveToChainStartTime + defaultMoveToTimeout <= DateTime.UtcNow) { StopExistingMoveToChains(); // This increments our moveToChainCounter and thus, should stop any additional actions in this chain return(false); } // Are we within use radius? bool ret = !CurrentLandblock.WithinUseRadius(this, target.Guid, out var valid); // If one of the items isn't on a landblock if (!valid) { ret = false; StopExistingMoveToChains(); // This increments our moveToChainCounter and thus, should stop any additional actions in this chain } return(ret); }, moveToBody); return(moveToChain); }