private void FinishActionItem(IActionItem actionItem, NWPlayer user, NWItem item, NWObject target, Location targetLocation, Vector userStartPosition, CustomData customData) { user.IsBusy = false; Vector userPosition = user.Position; if (userPosition.m_X != userStartPosition.m_X || userPosition.m_Y != userStartPosition.m_Y || userPosition.m_Z != userStartPosition.m_Z) { user.SendMessage("You move and interrupt your action."); return; } if (actionItem.MaxDistance() > 0.0f) { if (_.GetDistanceBetween(user.Object, target.Object) > actionItem.MaxDistance() || user.Area.Resref != target.Area.Resref) { user.SendMessage("Your target is too far away."); return; } } if (!target.IsValid && !actionItem.AllowLocationTarget()) { user.SendMessage("Unable to locate target."); return; } string invalidTargetMessage = actionItem.IsValidTarget(user, item, target, targetLocation); if (!string.IsNullOrWhiteSpace(invalidTargetMessage)) { user.SendMessage(invalidTargetMessage); return; } actionItem.ApplyEffects(user, item, target, targetLocation, customData); if (actionItem.ReducesItemCharge(user, item, target, targetLocation, customData)) { if (item.Charges > 0) { item.ReduceCharges(); } else { item.Destroy(); } } }
private void OnFinishActionItem(OnFinishActionItem data) { using (new Profiler(nameof(FinishActionItem))) { IActionItem actionItem = ItemService.GetActionItemHandler(data.ClassName); data.Player.IsBusy = false; Vector userPosition = data.Player.Position; if (userPosition.X != data.UserPosition.X || userPosition.Y != data.UserPosition.Y || userPosition.Z != data.UserPosition.Z) { data.Player.SendMessage("You move and interrupt your action."); return; } float maxDistance = actionItem.MaxDistance(data.Player, data.Item, data.Target, data.TargetLocation); if (maxDistance > 0.0f) { NWObject owner = GetItemPossessor(data.Target); if (data.Target.IsValid && owner.IsValid) { // We are okay - we have targeted an item in our inventory (we can't target someone // else's inventory, so no need to actually check distance). } else if (data.Target.Object == _.OBJECT_SELF) { // Also okay. } else if (data.Target.IsValid && (_.GetDistanceBetween(data.Player, data.Target) > maxDistance || data.Player.Area.Resref != data.Target.Area.Resref)) { data.Player.SendMessage("Your target is too far away."); return; } else if (!data.Target.IsValid && (_.GetDistanceBetweenLocations(data.Player.Location, data.TargetLocation) > maxDistance || data.Player.Area.Resref != ((NWArea)_.GetAreaFromLocation(data.TargetLocation)).Resref)) { data.Player.SendMessage("That location is too far away."); return; } } if (!data.Target.IsValid && !actionItem.AllowLocationTarget()) { data.Player.SendMessage("Unable to locate target."); return; } string invalidTargetMessage = actionItem.IsValidTarget(data.Player, data.Item, data.Target, data.TargetLocation); if (!string.IsNullOrWhiteSpace(invalidTargetMessage)) { data.Player.SendMessage(invalidTargetMessage); return; } actionItem.ApplyEffects(data.Player, data.Item, data.Target, data.TargetLocation, data.CustomData); if (actionItem.ReducesItemCharge(data.Player, data.Item, data.Target, data.TargetLocation, data.CustomData)) { if (data.Item.Charges > 0) { data.Item.ReduceCharges(); } if (data.Item.Charges <= 0) { data.Item.Destroy(); } } } }
private void OnFinishActionItem(OnFinishActionItem data) { using (new Profiler(nameof(FinishActionItem))) { IActionItem actionItem = ItemService.GetActionItemHandler(data.ClassName); data.Player.IsBusy = false; Vector userPosition = data.Player.Position; if (userPosition.m_X != data.UserPosition.m_X || userPosition.m_Y != data.UserPosition.m_Y || userPosition.m_Z != data.UserPosition.m_Z) { data.Player.SendMessage("You move and interrupt your action."); return; } float maxDistance = actionItem.MaxDistance(data.Player, data.Item, data.Target, data.TargetLocation); if (maxDistance > 0.0f) { if (data.Target.IsValid && (_.GetDistanceBetween(data.Player, data.Target) > maxDistance || data.Player.Area.Resref != data.Target.Area.Resref)) { data.Player.SendMessage("Your target is too far away."); return; } else if (!data.Target.IsValid && (_.GetDistanceBetweenLocations(data.Player.Location, data.TargetLocation) > maxDistance || data.Player.Area.Resref != ((NWArea)_.GetAreaFromLocation(data.TargetLocation)).Resref)) { data.Player.SendMessage("That location is too far away."); return; } } if (!data.Target.IsValid && !actionItem.AllowLocationTarget()) { data.Player.SendMessage("Unable to locate target."); return; } string invalidTargetMessage = actionItem.IsValidTarget(data.Player, data.Item, data.Target, data.TargetLocation); if (!string.IsNullOrWhiteSpace(invalidTargetMessage)) { data.Player.SendMessage(invalidTargetMessage); return; } actionItem.ApplyEffects(data.Player, data.Item, data.Target, data.TargetLocation, data.CustomData); if (actionItem.ReducesItemCharge(data.Player, data.Item, data.Target, data.TargetLocation, data.CustomData)) { if (data.Item.Charges > 0) { data.Item.ReduceCharges(); } else { data.Item.Destroy(); } } } }