/// <summary> /// Attempts to get the tile's top <see cref="IThing"/> depending on the given position. /// </summary> /// <param name="creatureFinder">A reference to the creature finder.</param> /// <param name="stackPos">The zero-based position in the full stack to return.</param> /// <returns>A reference to the <see cref="IThing"/>, or null if nothing corresponds to that position.</returns> public IThing GetTopThingByOrder(ICreatureFinder creatureFinder, byte stackPos) { creatureFinder.ThrowIfNull(nameof(creatureFinder)); var i = this.Ground == null ? 0 : 1; if (this.stayOnTopItems.Any() && stackPos < i + this.stayOnTopItems.Count) { return(this.stayOnTopItems.ElementAt(Math.Max(0, stackPos - i))); } i += this.stayOnTopItems.Count; if (this.stayOnBottomItems.Any() && stackPos < i + this.stayOnBottomItems.Count) { return(this.stayOnBottomItems.ElementAt(Math.Max(0, stackPos - i))); } i += this.stayOnBottomItems.Count; if (this.creatureIdsOnTile.Any() && stackPos < i + this.creatureIdsOnTile.Count) { return(creatureFinder.FindCreatureById(this.creatureIdsOnTile.ElementAt(Math.Max(0, stackPos - i)))); } i += this.creatureIdsOnTile.Count; if (this.itemsOnTile.Any() && stackPos < i + this.itemsOnTile.Count) { return(this.itemsOnTile.ElementAt(Math.Max(0, stackPos - i))); } // when nothing else works, return the ground (if any). return(this.Ground); }
/// <summary> /// Initializes a new instance of the <see cref="StopAllActionsHandler"/> class. /// </summary> /// <param name="creatureFinder">A reference to the creature finder.</param> /// <param name="gameInstance">A reference to the game instance.</param> public StopAllActionsHandler( ICreatureFinder creatureFinder, IGame gameInstance) : base(gameInstance) { this.CreatureFinder = creatureFinder; }
/// <summary> /// Initializes a new instance of the <see cref="AutoMoveCancelHandler"/> class. /// </summary> /// <param name="creatureFinder">A reference to the creature finder.</param> /// <param name="gameInstance">A reference to the game instance.</param> public AutoMoveCancelHandler( ICreatureFinder creatureFinder, IGame gameInstance) : base(gameInstance) { this.CreatureFinder = creatureFinder; }
/// <summary> /// Initializes a new instance of the <see cref="SectorMapLoader"/> class. /// </summary> /// <param name="logger">A reference to the logger instance in use.</param> /// <param name="creatureFinder">A reference to the creature finder.</param> /// <param name="itemFactory">A reference to the item factory.</param> /// <param name="sectorMapLoaderOptions">The options for this map loader.</param> public SectorMapLoader( ILogger logger, ICreatureFinder creatureFinder, IItemFactory itemFactory, IOptions <SectorMapLoaderOptions> sectorMapLoaderOptions) { logger.ThrowIfNull(nameof(logger)); creatureFinder.ThrowIfNull(nameof(creatureFinder)); itemFactory.ThrowIfNull(nameof(itemFactory)); sectorMapLoaderOptions.ThrowIfNull(nameof(sectorMapLoaderOptions)); DataAnnotationsValidator.ValidateObjectRecursive(sectorMapLoaderOptions.Value); this.mapDirInfo = new DirectoryInfo(sectorMapLoaderOptions.Value.LiveMapDirectory); if (!this.mapDirInfo.Exists) { throw new ApplicationException($"The map directory '{sectorMapLoaderOptions.Value.LiveMapDirectory}' could not be found."); } this.Logger = logger.ForContext <SectorMapLoader>(); this.CreatureFinder = creatureFinder; this.ItemFactory = itemFactory; this.totalTileCount = 1; this.totalLoadedCount = default; this.loadLock = new object(); this.sectorsLengthX = 1 + SectorXMax - SectorXMin; this.sectorsLengthY = 1 + SectorYMax - SectorYMin; this.sectorsLengthZ = 1 + SectorZMax - SectorZMin; this.sectorsLoaded = new bool[this.sectorsLengthX, this.sectorsLengthY, this.sectorsLengthZ]; }
/// <summary> /// Initializes a new instance of the <see cref="ThingIsTakeableEventCondition"/> class. /// </summary> /// <param name="creatureFinder">A reference to the creature finder in use.</param> /// <param name="grabberId">The id of the grabber creature.</param> /// <param name="thingMoving">The thing being checked.</param> public ThingIsTakeableEventCondition(ICreatureFinder creatureFinder, uint grabberId, IThing thingMoving) { creatureFinder.ThrowIfNull(nameof(creatureFinder)); this.CreatureFinder = creatureFinder; this.GrabberId = grabberId; this.Thing = thingMoving; }
/// <summary> /// Initializes a new instance of the <see cref="ContainerManager"/> class. /// </summary> /// <param name="logger">A reference to the logger in use.</param> /// <param name="creatureFinder">A reference to the creature finder in use.</param> public ContainerManager(ILogger <ContainerManager> logger, ICreatureFinder creatureFinder) { this.logger = logger; this.creatureFinder = creatureFinder; this.internalDictionariesLock = new object(); this.creaturesToContainers = new Dictionary <uint, IContainerItem[]>(); this.containersToCreatureIds = new Dictionary <Guid, IDictionary <byte, uint> >(); }
/// <summary> /// Initializes a new instance of the <see cref="ContainerToMapMovementEvent"/> class. /// </summary> /// <param name="logger">A reference to the logger in use.</param> /// <param name="game">A reference to the game instance.</param> /// <param name="connectionManager">A reference to the connection manager in use.</param> /// <param name="tileAccessor">A reference to the tile accessor in use.</param> /// <param name="creatureFinder">A reference to the creture finder in use.</param> /// <param name="creatureRequestingId">The id of the creature requesting the movement.</param> /// <param name="thingMoving">The thing being moved.</param> /// <param name="fromCreatureId">The id of the creature in which the movement is happening.</param> /// <param name="fromCreatureContainerId">The id of the container from which the movement is happening.</param> /// <param name="fromCreatureContainerIndex">The index in the container from which the movement is happening.</param> /// <param name="toLocation">The location in the map to which the movement is happening.</param> /// <param name="amount">Optional. The amount of the thing to move. Must be positive. Defaults to 1.</param> /// <param name="evaluationTime">Optional. The evaluation time policy for this event. Defaults to <see cref="EvaluationTime.OnBoth"/>.</param> public ContainerToMapMovementEvent( ILogger logger, IGame game, IConnectionManager connectionManager, ITileAccessor tileAccessor, ICreatureFinder creatureFinder, uint creatureRequestingId, IThing thingMoving, uint fromCreatureId, byte fromCreatureContainerId, byte fromCreatureContainerIndex, Location toLocation, byte amount = 1, EvaluationTime evaluationTime = EvaluationTime.OnBoth) : base(logger, game, connectionManager, creatureFinder, creatureRequestingId, evaluationTime) { tileAccessor.ThrowIfNull(nameof(tileAccessor)); if (amount == 0) { throw new ArgumentException("Invalid count zero.", nameof(amount)); } this.Conditions.Add(new LocationNotObstructedEventCondition(tileAccessor, this.Requestor, () => thingMoving, () => toLocation)); this.Conditions.Add(new LocationHasTileWithGroundEventCondition(tileAccessor, () => toLocation)); this.Conditions.Add(new ContainerIsOpenEventCondition(() => creatureFinder.FindCreatureById(fromCreatureId), fromCreatureContainerId)); var onPassAction = new GenericEventAction(() => { bool moveSuccessful = thingMoving is IItem item && creatureFinder.FindCreatureById(fromCreatureId) is IPlayer targetPlayer && tileAccessor.GetTileAt(toLocation, out ITile toTile) && this.Game.PerformItemMovement(item, targetPlayer.GetContainerById(fromCreatureContainerId), toTile, fromIndex: fromCreatureContainerIndex, amountToMove: amount); if (!moveSuccessful) { // handles check for isPlayer. this.NotifyOfFailure(); return; } if (this.Requestor is IPlayer player && toLocation != player.Location && player != thingMoving) { var directionToDestination = player.Location.DirectionTo(toLocation); this.Game.PlayerRequest_TurnToDirection(player, directionToDestination); } this.Game.EvaluateCollisionEventRules(toLocation, thingMoving, this.Requestor); this.Game.EvaluateMovementEventRules(thingMoving, this.Requestor); }); this.ActionsOnPass.Add(onPassAction); }
/// <summary> /// Initializes a new instance of the <see cref="SlotContainsItemAndAmountEventCondition"/> class. /// </summary> /// <param name="creatureFinder">A reference to the creature finder in use.</param> /// <param name="requestorId">The id of the requesting creature.</param> /// <param name="movingItem">The item to check.</param> /// <param name="slot">The slot to check.</param> /// <param name="amount">The amount to check for.</param> public SlotContainsItemAndAmountEventCondition(ICreatureFinder creatureFinder, uint requestorId, IItem movingItem, byte slot, byte amount = 1) { creatureFinder.ThrowIfNull(nameof(creatureFinder)); this.CreatureFinder = creatureFinder; this.RequestorId = requestorId; this.ItemMoving = movingItem; this.Slot = (Slot)slot; this.Amount = amount; }
/// <summary> /// Initializes a new instance of the <see cref="TileUpdatedNotification"/> class. /// </summary> /// <param name="logger">A reference to the logger in use.</param> /// <param name="creatureFinder">A reference to the creature finder instance.</param> /// <param name="determineTargetConnectionsFunction">A function to determine the target connections of this notification.</param> /// <param name="arguments">The arguments for this notification.</param> public TileUpdatedNotification(ILogger logger, ICreatureFinder creatureFinder, Func <IEnumerable <IConnection> > determineTargetConnectionsFunction, TileUpdatedNotificationArguments arguments) : base(logger) { determineTargetConnectionsFunction.ThrowIfNull(nameof(determineTargetConnectionsFunction)); arguments.ThrowIfNull(nameof(arguments)); this.CreatureFinder = creatureFinder; this.TargetConnectionsFunction = determineTargetConnectionsFunction; this.Arguments = arguments; }
/// <summary> /// Gets the creature that is requesting the event, if known. /// </summary> /// <param name="creatureFinder">A reference to the creature finder in use.</param> /// <returns>The creature that requested the operation, or null if there wasn't any.</returns> public ICreature GetRequestor(ICreatureFinder creatureFinder) { creatureFinder.ThrowIfNull(nameof(creatureFinder)); if (this.requestor == null && this.RequestorId > 0) { this.requestor = creatureFinder.FindCreatureById(this.RequestorId); } return(this.requestor); }
/// <summary> /// Initializes a new instance of the <see cref="LookAtHandler"/> class. /// </summary> /// <param name="logger">A reference to the logger to use in this handler.</param> /// <param name="gameInstance">A reference to the game instance.</param> /// <param name="creatureFinder">A reference to the creature finder.</param> /// <param name="tileAccessor">A reference to the tile accessor.</param> public LookAtHandler( ILogger logger, IGame gameInstance, ICreatureFinder creatureFinder, ITileAccessor tileAccessor) : base(gameInstance) { this.CreatureFinder = creatureFinder; this.TileAccessor = tileAccessor; this.Logger = logger.ForContext <LookAtHandler>(); }
/// <summary> /// Initializes a new instance of the <see cref="UseItemHandler"/> class. /// </summary> /// <param name="logger">A reference to the logger to use in this handler.</param> /// <param name="creatureFinder">A reference to the creature finder.</param> /// <param name="gameInstance">A reference to the game instance.</param> public UseItemHandler( ILogger logger, ICreatureFinder creatureFinder, IGame gameInstance) : base(gameInstance) { creatureFinder.ThrowIfNull(nameof(creatureFinder)); this.Logger = logger.ForContext <UseItemHandler>(); this.CreatureFinder = creatureFinder; }
/// <summary> /// Initializes a new instance of the <see cref="Map"/> class. /// </summary> /// <param name="logger">A reference to the logger to use.</param> /// <param name="mapLoader">The map loader to use to load this map.</param> /// <param name="creatureFinder">A reference to the creature finder.</param> public Map(ILogger logger, IMapLoader mapLoader, ICreatureFinder creatureFinder) { logger.ThrowIfNull(nameof(logger)); mapLoader.ThrowIfNull(nameof(mapLoader)); creatureFinder.ThrowIfNull(nameof(creatureFinder)); this.Logger = logger.ForContext <Map>(); this.Loader = mapLoader; this.CreatureFinder = creatureFinder; this.tiles = new ConcurrentDictionary <Location, ITile>(); }
/// <summary> /// Initializes a new instance of the <see cref="NotificationContext"/> class. /// </summary> /// <param name="logger">A reference to the logger in use.</param> /// <param name="mapDescriptor">A reference to the map descriptor in use.</param> /// <param name="creatureFinder">A reference to the creature finder in use.</param> public NotificationContext( ILogger logger, IMapDescriptor mapDescriptor, ICreatureFinder creatureFinder) : base(logger, () => DateTimeOffset.UtcNow) { mapDescriptor.ThrowIfNull(nameof(mapDescriptor)); creatureFinder.ThrowIfNull(nameof(creatureFinder)); this.MapDescriptor = mapDescriptor; this.CreatureFinder = creatureFinder; }
/// <summary> /// Initializes a new instance of the <see cref="NotificationContext"/> class. /// </summary> /// <param name="logger">A reference to the logger in use.</param> /// <param name="mapDescriptor">A reference to the map descriptor in use.</param> /// <param name="creatureFinder">A reference to the creature finder in use.</param> public NotificationContext( ILogger logger, IMapDescriptor mapDescriptor, ICreatureFinder creatureFinder) { logger.ThrowIfNull(nameof(logger)); mapDescriptor.ThrowIfNull(nameof(mapDescriptor)); creatureFinder.ThrowIfNull(nameof(creatureFinder)); this.Logger = logger.ForContext <NotificationContext>(); this.MapDescriptor = mapDescriptor; this.CreatureFinder = creatureFinder; }
/// <summary> /// Initializes a new instance of the <see cref="MapToContainerMovementEvent"/> class. /// </summary> /// <param name="logger">A reference to the logger in use.</param> /// <param name="game">A reference to the game instance.</param> /// <param name="connectionManager">A reference to the connection manager in use.</param> /// <param name="tileAccessor">A reference to the tile accessor in use.</param> /// <param name="creatureFinder">A reference to the creture finder in use.</param> /// <param name="creatureRequestingId">The id of the creature requesting the movement.</param> /// <param name="thingMoving">The thing being moved.</param> /// <param name="fromLocation">The location from which the movement is happening.</param> /// <param name="toCreatureId">The id of the creature that should known the container to which the movement is happening.</param> /// <param name="toCreatureContainerId">The id of the container to which the movement is happening.</param> /// <param name="toCreatureContainerIndex">The index in the container to which the movement is happening.</param> /// <param name="amount">Optional. The amount of the thing to move. Must be positive. Defaults to 1.</param> /// <param name="evaluationTime">Optional. The evaluation time policy for this event. Defaults to <see cref="EvaluationTime.OnBoth"/>.</param> public MapToContainerMovementEvent( ILogger logger, IGame game, IConnectionManager connectionManager, ITileAccessor tileAccessor, ICreatureFinder creatureFinder, uint creatureRequestingId, IThing thingMoving, Location fromLocation, uint toCreatureId, byte toCreatureContainerId, byte toCreatureContainerIndex, byte amount = 1, EvaluationTime evaluationTime = EvaluationTime.OnBoth) : base(logger, game, connectionManager, creatureFinder, creatureRequestingId, evaluationTime) { tileAccessor.ThrowIfNull(nameof(tileAccessor)); if (amount == 0) { throw new ArgumentException("Invalid count zero.", nameof(amount)); } this.Conditions.Add(new TileContainsThingEventCondition(tileAccessor, thingMoving, fromLocation, amount)); this.Conditions.Add(new RequestorIsInRangeToMoveEventCondition(this.Requestor, () => fromLocation)); this.Conditions.Add(new LocationsMatchEventCondition(() => thingMoving?.Location ?? default, () => fromLocation)); this.Conditions.Add(new ContainerIsOpenEventCondition(() => creatureFinder.FindCreatureById(toCreatureId), toCreatureContainerId)); var onPassAction = new GenericEventAction(() => { bool moveSuccessful = thingMoving is IItem item && creatureFinder.FindCreatureById(toCreatureId) is IPlayer targetPlayer && tileAccessor.GetTileAt(fromLocation, out ITile fromTile) && this.Game.PerformItemMovement(item, fromTile, targetPlayer.GetContainerById(toCreatureContainerId), toIndex: toCreatureContainerIndex, amountToMove: amount); if (!moveSuccessful) { // handles check for isPlayer. this.NotifyOfFailure(); return; } this.Game.EvaluateSeparationEventRules(fromLocation, thingMoving, this.Requestor); this.Game.EvaluateMovementEventRules(thingMoving, this.Requestor); }); this.ActionsOnPass.Add(onPassAction); }
/// <summary> /// Initializes a new instance of the <see cref="ContainerToContainerMovementEvent"/> class. /// </summary> /// <param name="logger">A reference to the logger in use.</param> /// <param name="game">A reference to the game instance.</param> /// <param name="connectionManager">A reference to the connection manager in use.</param> /// <param name="tileAccessor">A reference to the tile accessor in use.</param> /// <param name="creatureFinder">A reference to the creture finder in use.</param> /// <param name="creatureRequestingId">The id of the creature requesting the movement.</param> /// <param name="thingMoving">The thing being moved.</param> /// <param name="targetCreatureId">The id of the creature in which the movement is happening.</param> /// <param name="fromCreatureContainerId">The id of the container from which the movement is happening.</param> /// <param name="fromCreatureContainerIndex">The index in the container from which the movement is happening.</param> /// <param name="toCreatureContainerId">The id of the container to which the movement is happening.</param> /// <param name="toCreatureContainerIndex">The index in the container to which the movement is happening.</param> /// <param name="amount">Optional. The amount of the thing to move. Must be positive. Defaults to 1.</param> /// <param name="evaluationTime">Optional. The evaluation time policy for this event. Defaults to <see cref="EvaluationTime.OnBoth"/>.</param> public ContainerToContainerMovementEvent( ILogger logger, IGame game, IConnectionManager connectionManager, ITileAccessor tileAccessor, ICreatureFinder creatureFinder, uint creatureRequestingId, IThing thingMoving, uint targetCreatureId, byte fromCreatureContainerId, byte fromCreatureContainerIndex, byte toCreatureContainerId, byte toCreatureContainerIndex, byte amount = 1, EvaluationTime evaluationTime = EvaluationTime.OnBoth) : base(logger, game, connectionManager, creatureFinder, creatureRequestingId, evaluationTime) { tileAccessor.ThrowIfNull(nameof(tileAccessor)); if (amount == 0) { throw new ArgumentException("Invalid count zero.", nameof(amount)); } this.Conditions.Add(new ContainerIsOpenEventCondition(() => creatureFinder.FindCreatureById(targetCreatureId), fromCreatureContainerId)); this.Conditions.Add(new ContainerIsOpenEventCondition(() => creatureFinder.FindCreatureById(targetCreatureId), toCreatureContainerId)); var onPassAction = new GenericEventAction(() => { bool moveSuccessful = thingMoving is IItem item && creatureFinder.FindCreatureById(targetCreatureId) is IPlayer targetPlayer && this.Game.PerformItemMovement(item, targetPlayer.GetContainerById(fromCreatureContainerId), targetPlayer.GetContainerById(toCreatureContainerId), fromCreatureContainerIndex, toCreatureContainerIndex, amount); if (!moveSuccessful) { // handles check for isPlayer. this.NotifyOfFailure(); return; } this.Game.EvaluateMovementEventRules(thingMoving, this.Requestor); }); this.ActionsOnPass.Add(onPassAction); }
/// <summary> /// Initializes a new instance of the <see cref="ChangeItemEvent"/> class. /// </summary> /// <param name="logger">A reference to the logger in use.</param> /// <param name="game">A reference to the game instance.</param> /// <param name="connectionManager">A reference to the connection manager in use.</param> /// <param name="tileAccessor">A reference to the tile accessor in use.</param> /// <param name="creatureFinder">A reference to the creature finder in use.</param> /// <param name="requestorId">The id of the creature requesting the use.</param> /// <param name="typeId">The type id of the item being used.</param> /// <param name="fromLocation">The location from which the item is being used.</param> /// <param name="toTypeId">The type id of the item to change to.</param> /// <param name="fromStackPos">The position in the stack from which the item is being used.</param> /// <param name="index">The index of the item being used.</param> /// <param name="evaluationTime">The time to evaluate the movement.</param> public ChangeItemEvent( ILogger logger, IGame game, IConnectionManager connectionManager, ITileAccessor tileAccessor, ICreatureFinder creatureFinder, uint requestorId, ushort typeId, Location fromLocation, ushort toTypeId, byte fromStackPos = byte.MaxValue, byte index = 1, EvaluationTime evaluationTime = EvaluationTime.OnBoth) : base(logger, requestorId, evaluationTime) { game.ThrowIfNull(nameof(game)); tileAccessor.ThrowIfNull(nameof(tileAccessor)); connectionManager.ThrowIfNull(nameof(connectionManager)); creatureFinder.ThrowIfNull(nameof(creatureFinder)); this.ConnectionManager = connectionManager; this.CreatureFinder = creatureFinder; this.Game = game; this.ActionsOnFail.Add(new GenericEventAction(this.NotifyOfFailure)); var onPassAction = new GenericEventAction(() => { var fromCylinder = this.Game.GetCyclinder(fromLocation, ref fromStackPos, ref index, this.Requestor); var item = this.Game.FindItemByIdAtLocation(typeId, fromLocation, this.Requestor); bool successfulUse = this.Game.PerformItemChange(item, toTypeId, fromCylinder, index, this.Requestor); if (!successfulUse) { // handles check for isPlayer. this.NotifyOfFailure(); return; } }); this.ActionsOnPass.Add(onPassAction); }
/// <summary> /// Initializes a new instance of the <see cref="DeleteItemEvent"/> class. /// </summary> /// <param name="logger">A reference to the logger in use.</param> /// <param name="game">A reference to the game instance.</param> /// <param name="connectionManager">A reference to the connection manager in use.</param> /// <param name="tileAccessor">A reference to the tile accessor in use.</param> /// <param name="creatureFinder">A reference to the creature finder in use.</param> /// <param name="requestorId">The id of the creature requesting the deletion.</param> /// <param name="typeId">The type id of the item being deleted.</param> /// <param name="atLocation">The location from which the item is being deleted.</param> /// <param name="evaluationTime">The time to evaluate the event.</param> public DeleteItemEvent( ILogger logger, IGame game, IConnectionManager connectionManager, ITileAccessor tileAccessor, ICreatureFinder creatureFinder, uint requestorId, ushort typeId, Location atLocation, EvaluationTime evaluationTime = EvaluationTime.OnBoth) : base(logger, requestorId, evaluationTime) { game.ThrowIfNull(nameof(game)); tileAccessor.ThrowIfNull(nameof(tileAccessor)); connectionManager.ThrowIfNull(nameof(connectionManager)); creatureFinder.ThrowIfNull(nameof(creatureFinder)); this.ConnectionManager = connectionManager; this.CreatureFinder = creatureFinder; this.Game = game; this.ActionsOnFail.Add(new GenericEventAction(this.NotifyOfFailure)); var onPassAction = new GenericEventAction(() => { byte index = 0, subIndex = 0; var fromCylinder = this.Game.GetCyclinder(atLocation, ref index, ref subIndex, this.Requestor); var item = this.Game.FindItemByIdAtLocation(typeId, atLocation, this.Requestor); bool successfulDeletion = this.Game.PerformItemDeletion(item, fromCylinder, subIndex, this.Requestor); if (!successfulDeletion) { // handles check for isPlayer. this.NotifyOfFailure(); return; } }); this.ActionsOnPass.Add(onPassAction); }
/// <summary> /// Initializes a new instance of the <see cref="ConditionContext"/> class. /// </summary> /// <param name="logger">A reference to the logger in use.</param> /// <param name="map">A reference to the map in use.</param> /// <param name="creatureFinder">A reference to the creature finder in use.</param> /// <param name="gameOperationsApi">A reference to the game operations api.</param> /// <param name="itemFactory">A reference to the item factory in use.</param> /// <param name="scheduler">A reference to the scheduler instance.</param> public ConditionContext( ILogger logger, IMap map, IGameOperationsApi gameOperationsApi, ICreatureFinder creatureFinder, IItemFactory itemFactory, IScheduler scheduler) : base(logger, () => scheduler.CurrentTime) { map.ThrowIfNull(nameof(map)); gameOperationsApi.ThrowIfNull(nameof(gameOperationsApi)); creatureFinder.ThrowIfNull(nameof(creatureFinder)); itemFactory.ThrowIfNull(nameof(itemFactory)); scheduler.ThrowIfNull(nameof(scheduler)); this.Map = map; this.GameApi = gameOperationsApi; this.CreatureFinder = creatureFinder; this.ItemFactory = itemFactory; this.Scheduler = scheduler; }
/// <summary> /// Initializes a new instance of the <see cref="ConditionContext"/> class. /// </summary> /// <param name="logger">A reference to the logger in use.</param> /// <param name="mapDescriptor">A reference to the map descriptor in use.</param> /// <param name="map">A reference to the map in use.</param> /// <param name="creatureFinder">A reference to the creature finder in use.</param> /// <param name="itemFactory">A reference to the item factory in use.</param> /// <param name="scheduler">A reference to the scheduler instance.</param> public ConditionContext( ILogger logger, IMapDescriptor mapDescriptor, IMap map, ICreatureFinder creatureFinder, IItemFactory itemFactory, IScheduler scheduler) : base(logger, () => scheduler.CurrentTime) { mapDescriptor.ThrowIfNull(nameof(mapDescriptor)); map.ThrowIfNull(nameof(map)); creatureFinder.ThrowIfNull(nameof(creatureFinder)); itemFactory.ThrowIfNull(nameof(itemFactory)); scheduler.ThrowIfNull(nameof(scheduler)); this.MapDescriptor = mapDescriptor; this.Map = map; this.CreatureFinder = creatureFinder; this.ItemFactory = itemFactory; this.Scheduler = scheduler; }
/// <summary> /// Initializes a new instance of the <see cref="SectorMapLoader"/> class. /// </summary> /// <param name="logger">A reference to the logger instance in use.</param> /// <param name="creatureFinder">A reference to the creature finder.</param> /// <param name="itemFactory">A reference to the item factory.</param> /// <param name="sectorMapLoaderOptions">The options for this map loader.</param> public SectorMapLoader(ILogger logger, ICreatureFinder creatureFinder, IItemFactory itemFactory, IOptions <SectorMapLoaderOptions> sectorMapLoaderOptions) { logger.ThrowIfNull(nameof(logger)); creatureFinder.ThrowIfNull(nameof(creatureFinder)); itemFactory.ThrowIfNull(nameof(itemFactory)); sectorMapLoaderOptions.ThrowIfNull(nameof(sectorMapLoaderOptions)); this.mapDirInfo = new DirectoryInfo(sectorMapLoaderOptions.Value.LiveMapDirectory); this.Logger = logger.ForContext <SectorMapLoader>(); this.CreatureFinder = creatureFinder; this.ItemFactory = itemFactory; this.totalTileCount = 1; this.totalLoadedCount = default; this.sectorsLengthX = 1 + SectorXMax - SectorXMin; this.sectorsLengthY = 1 + SectorYMax - SectorYMin; this.sectorsLengthZ = 1 + SectorZMax - SectorZMin; this.sectorsLoaded = new bool[this.sectorsLengthX, this.sectorsLengthY, this.sectorsLengthZ]; }
/// <summary> /// Initializes a new instance of the <see cref="OperationContext"/> class. /// </summary> /// <param name="logger">A reference to the logger in use.</param> /// <param name="mapDescriptor">A reference to the map descriptor in use.</param> /// <param name="map">A reference to the map in use.</param> /// <param name="creatureFinder">A reference to the creature finder in use.</param> /// <param name="itemFactory">A reference to the item factory in use.</param> /// <param name="creatureFactory">A reference to the creature factory in use.</param> /// <param name="containerManager">A reference to the container manager in use.</param> /// <param name="gameOperationsApi">A reference to the game operations api.</param> /// <param name="combatOperationsApi">A reference to the combat operations api.</param> /// <param name="pathFinderAlgo">A reference to the path finding algorithm in use.</param> /// <param name="predefinedItemSet">A reference to the predefined item set declared.</param> /// <param name="scheduler">A reference to the scheduler instance.</param> public OperationContext( ILogger logger, IMapDescriptor mapDescriptor, IMap map, ICreatureFinder creatureFinder, IItemFactory itemFactory, ICreatureFactory creatureFactory, IContainerManager containerManager, IGameOperationsApi gameOperationsApi, ICombatOperationsApi combatOperationsApi, IPathFinder pathFinderAlgo, IPredefinedItemSet predefinedItemSet, IScheduler scheduler) : base(logger, () => scheduler.CurrentTime) { mapDescriptor.ThrowIfNull(nameof(mapDescriptor)); map.ThrowIfNull(nameof(map)); creatureFinder.ThrowIfNull(nameof(creatureFinder)); itemFactory.ThrowIfNull(nameof(itemFactory)); creatureFactory.ThrowIfNull(nameof(creatureFactory)); containerManager.ThrowIfNull(nameof(containerManager)); gameOperationsApi.ThrowIfNull(nameof(gameOperationsApi)); combatOperationsApi.ThrowIfNull(nameof(combatOperationsApi)); pathFinderAlgo.ThrowIfNull(nameof(pathFinderAlgo)); predefinedItemSet.ThrowIfNull(nameof(predefinedItemSet)); scheduler.ThrowIfNull(nameof(scheduler)); this.MapDescriptor = mapDescriptor; this.Map = map; this.CreatureFinder = creatureFinder; this.ItemFactory = itemFactory; this.CreatureFactory = creatureFactory; this.ContainerManager = containerManager; this.GameApi = gameOperationsApi; this.CombatApi = combatOperationsApi; this.PathFinder = pathFinderAlgo; this.PredefinedItemSet = predefinedItemSet; this.Scheduler = scheduler; }
/// <summary> /// Initializes a new instance of the <see cref="OnMapCreatureMovementEvent"/> class. /// </summary> /// <param name="logger"></param> /// <param name="game"></param> /// <param name="connectionManager"></param> /// <param name="tileAccessor"></param> /// <param name="creatureFinder"></param> /// <param name="itemFactory"></param> /// <param name="requestorId"></param> /// <param name="creatureMoving"></param> /// <param name="fromLocation"></param> /// <param name="toLocation"></param> /// <param name="fromStackPos">Optional. The position in the stack of the tile from which the movement is being performed. Defaults to <see cref="byte.MaxValue"/> which signals to attempt to find the thing from the source location.</param> /// <param name="isTeleport"></param> /// <param name="deferEvaluation"></param> public OnMapCreatureMovementEvent( ILogger logger, IGame game, IConnectionManager connectionManager, ITileAccessor tileAccessor, ICreatureFinder creatureFinder, uint requestorId, ICreature creatureMoving, Location fromLocation, Location toLocation, byte fromStackPos = byte.MaxValue, bool isTeleport = false, bool deferEvaluation = false) : base(logger, game, connectionManager, tileAccessor, creatureFinder, requestorId, creatureMoving, fromLocation, toLocation, fromStackPos, 1, isTeleport, deferEvaluation ? EvaluationTime.OnExecute : EvaluationTime.OnBoth) { // Don't add any conditions if this wasn't a creature requesting, i.e. if the request comes from a script. if (!isTeleport && this.Requestor != null) { this.Conditions.Add(new LocationNotAvoidEventCondition(tileAccessor, this.Requestor, () => creatureMoving, () => toLocation)); this.Conditions.Add(new LocationsAreDistantByEventCondition(() => fromLocation, () => toLocation)); this.Conditions.Add(new CreatureThrowBetweenFloorsEventCondition(this.Requestor, () => creatureMoving, () => toLocation)); } }
/// <summary> /// Initializes a new instance of the <see cref="PlayerTurnWestHandler"/> class. /// </summary> /// <param name="gameInstance">A reference to the game instance.</param> /// <param name="creatureFinder">A reference to the creature finder.</param> public PlayerTurnWestHandler(IGame gameInstance, ICreatureFinder creatureFinder) : base(gameInstance, creatureFinder, Direction.West) { }
/// <summary> /// Initializes a new instance of the <see cref="ActionWithoutContentHandler"/> class. /// </summary> /// <param name="logger">A reference to the logger in use.</param> /// <param name="gameInstance">A reference to the game instance.</param> /// <param name="creatureFinder">A reference to the creature finder in use.</param> public ActionWithoutContentHandler(ILogger logger, IGame gameInstance, ICreatureFinder creatureFinder) : base(logger, gameInstance) { this.CreatureFinder = creatureFinder; }
/// <summary> /// Initializes a new instance of the <see cref="ContainerCloseHandler"/> class. /// </summary> /// <param name="gameInstance">A reference to the game instance.</param> /// <param name="creatureFinder">A reference to the creature finder.</param> public ContainerCloseHandler(IGame gameInstance, ICreatureFinder creatureFinder) : base(gameInstance) { this.CreatureFinder = creatureFinder; }
/// <summary> /// Initializes a new instance of the <see cref="PlayerWalkSoutheastHandler"/> class. /// </summary> /// <param name="gameInstance">A reference to the game instance.</param> /// <param name="creatureFinder">A reference to the creature finder.</param> public PlayerWalkSoutheastHandler(IGame gameInstance, ICreatureFinder creatureFinder) : base(gameInstance, creatureFinder, Direction.SouthEast) { }
/// <summary> /// Initializes a new instance of the <see cref="LookAtHandler"/> class. /// </summary> /// <param name="logger">A reference to the logger in use.</param> /// <param name="gameInstance">A reference to the game instance.</param> /// <param name="creatureFinder">A reference to the creature finder in use.</param> public LookAtHandler(ILogger <LookAtHandler> logger, IGame gameInstance, ICreatureFinder creatureFinder) : base(logger, gameInstance) { this.CreatureFinder = creatureFinder; }
/// <summary> /// Initializes a new instance of the <see cref="WalkOnDemandHandler"/> class. /// </summary> /// <param name="logger">A reference to the logger in use.</param> /// <param name="gameInstance">A reference to the game instance.</param> /// <param name="creatureFinder">A reference to the creature finder in use.</param> public WalkOnDemandHandler(ILogger logger, IGame gameInstance, ICreatureFinder creatureFinder) : base(logger, gameInstance) { this.CreatureFinder = creatureFinder; }