private ActionChain CreateMoveToChain(WorldObject target, float distance, 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); } else { OnAutonomousMove(target.Location, Sequences, MovementTypes.MoveToObject, target.Guid); } }); // 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? bool ret = !CurrentLandblock.WithinUseRadius(this, target.Guid, out var valid); // If one of the items isn't on a landblock if (!valid) { ret = false; } return(ret); }, moveToBody); return(moveToChain); }
public void MoveToChain(WorldObject target, int thisMoveToChainNumber, Action <bool> callback, float?useRadius = null) { if (thisMoveToChainNumber != moveToChainCounter) { if (thisMoveToChainNumber > lastCompletedMove) { lastCompletedMove = thisMoveToChainNumber; } callback(false); return; } // 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 callback(false); return; } // Have we timed out? if (moveToChainStartTime + defaultMoveToTimeout <= DateTime.UtcNow) { StopExistingMoveToChains(); // This increments our moveToChainCounter and thus, should stop any additional actions in this chain callback(false); return; } // Are we within use radius? var success = CurrentLandblock.WithinUseRadius(this, target.Guid, out var targetValid, useRadius); // If one of the items isn't on a landblock if (!targetValid) { StopExistingMoveToChains(); // This increments our moveToChainCounter and thus, should stop any additional actions in this chain callback(false); return; } if (!success) { // target not reached yet var actionChain = new ActionChain(); actionChain.AddDelaySeconds(0.1f); actionChain.AddAction(this, () => MoveToChain(target, thisMoveToChainNumber, callback, useRadius)); actionChain.EnqueueChain(); } else { if (thisMoveToChainNumber > lastCompletedMove) { lastCompletedMove = thisMoveToChainNumber; } callback(true); } }
public void CreateMoveToChain(WorldObject target, Action <bool> callback, float?useRadius = null) { var thisMoveToChainNumber = GetNextMoveToChainNumber(); if (target.Location == null) { StopExistingMoveToChains(); log.Error($"{Name}.CreateMoveToChain({target.Name}): target.Location is null"); callback(false); return; } // fix bug in magic combat mode after walking to target, // crouch animation steps out of range if (useRadius == null) { useRadius = target.UseRadius ?? 0.6f; } if (CombatMode == CombatMode.Magic) { useRadius = Math.Max(0.0f, useRadius.Value - 0.2f); } // already within use distance? var withinUseRadius = CurrentLandblock.WithinUseRadius(this, target.Guid, out var targetValid, useRadius); if (withinUseRadius) { // send TurnTo motion var rotateTime = Rotate(target); var actionChain = new ActionChain(); actionChain.AddDelaySeconds(rotateTime); actionChain.AddAction(this, () => { lastCompletedMove = thisMoveToChainNumber; callback(true); }); actionChain.EnqueueChain(); return; } if (target.WeenieType == WeenieType.Portal) { MoveToPosition(target.Location); } else { MoveToObject(target, useRadius); } moveToChainStartTime = DateTime.UtcNow; MoveToChain(target, thisMoveToChainNumber, callback, useRadius); }
public bool HandleActionOpenTradeNegotiations(Session session, ObjectGuid tradePartner, bool initiator = false) { session.Player.TradePartner = tradePartner; var targetsession = WorldManager.Find(session.Player.TradePartner); var target = CurrentLandblock?.GetObject(tradePartner); //Check to see if partner is not allowing trades if ((initiator) && (targetsession.Player.GetCharacterOption(CharacterOption.IgnoreAllTradeRequests))) { session.Network.EnqueueSend(new GameEventWeenieError(session, WeenieError.TradeIgnoringRequests)); return(false); } //Check to see if either party is already part of an in process trade session if ((session.Player.IsTrading) || (targetsession.Player.IsTrading)) { session.Network.EnqueueSend(new GameEventWeenieError(session, WeenieError.TradeAlreadyTrading)); return(false); } //Check to see if either party is in combat mode if ((session.Player.CombatMode != CombatMode.NonCombat) || (targetsession.Player.CombatMode != CombatMode.NonCombat)) { session.Network.EnqueueSend(new GameEventWeenieError(session, WeenieError.TradeNonCombatMode)); return(false); } //Check to see if trade partner is in range, if so, rotate and move to var valid = false; bool ret = CurrentLandblock != null ? !CurrentLandblock.WithinUseRadius(session.Player, tradePartner, out valid) : false; if (valid) { session.Player.ItemsInTradeWindow.Clear(); session.Player.Rotate(target); session.Player.MoveTo(target); session.Network.EnqueueSend(new GameEventRegisterTrade(session, session.Player.Guid, tradePartner)); if (!initiator) { session.Player.IsTrading = true; targetsession.Player.IsTrading = true; } return(true); } else { session.Network.EnqueueSend(new GameEventWeenieError(session, WeenieError.TradeMaxDistanceExceeded)); return(false); } }
public void HandleMoveToCallback() { var isFacing = IsFacing(MoveToParams.Target); var withinUseRadius = MoveToParams.UseRadius == null || CurrentLandblock.WithinUseRadius(this, MoveToParams.Target.Guid, out _, MoveToParams.UseRadius); var success = isFacing && withinUseRadius; MoveToParams.Callback(success); MoveToParams = null; }
public void CreateMoveToChain2(WorldObject target, Action <bool> callback, float?useRadius = null, bool rotate = true) { if (IsPlayerMovingTo2) { StopExistingMoveToChains2(); } if (target.Location == null) { log.Error($"{Name}.MoveTo({target.Name}): target.Location is null"); callback(false); return; } var withinUseRadius = CurrentLandblock.WithinUseRadius(this, target.Guid, out var targetValid, useRadius); if (withinUseRadius) { if (rotate) { CreateTurnToChain2(target, callback); } else { callback(true); } return; } // send command to client MoveToObject(target); // start on server // forward this to PhysicsObj.MoveManager.MoveToManager var mvp = GetMoveToParams(target, useRadius); if (!PhysicsObj.IsMovingOrAnimating) { //PhysicsObj.UpdateTime = PhysicsTimer.CurrentTime - PhysicsGlobals.MinQuantum; PhysicsObj.UpdateTime = PhysicsTimer.CurrentTime; } IsPlayerMovingTo2 = true; MoveToCallback = callback; PhysicsObj.MoveToObject(target.PhysicsObj, mvp); //PhysicsObj.LastMoveWasAutonomous = false; PhysicsObj.update_object(); }
public void CreateMoveToChain(WorldObject target, Action <bool> callback, float?useRadius = null) { var thisMoveToChainNumber = GetNextMoveToChainNumber(); if (target.Location == null) { StopExistingMoveToChains(); log.Error($"{Name}.CreateMoveToChain({target.Name}): target.Location is null"); callback(false); return; } // already within use distance? var withinUseRadius = CurrentLandblock.WithinUseRadius(this, target.Guid, out var targetValid, useRadius); if (withinUseRadius) { // send TurnTo motion var rotateTime = Rotate(target); var actionChain = new ActionChain(); actionChain.AddDelaySeconds(rotateTime); actionChain.AddAction(this, () => { lastCompletedMove = thisMoveToChainNumber; callback(true); }); actionChain.EnqueueChain(); return; } if (target.WeenieType == WeenieType.Portal) { MoveToPosition(target.Location); } else { MoveToObject(target); } moveToChainStartTime = DateTime.UtcNow; MoveToChain(target, thisMoveToChainNumber, callback, useRadius); }
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); }