예제 #1
0
        public void RangeIsInRangeThrowsOnOutOfRangeTest()
        {
            var innerRange  = new Range <EntityID>(0, 10);
            var outterRange = new Range <EntityID>(1, 9);

            Assert.Throws <ArgumentOutOfRangeException>(() => { Precondition.IsInRange(innerRange, outterRange); });
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GameObjectCollection{T}"/> class.
        /// </summary>
        /// <param name="in_bounds">The bounds within which the collected <see cref="GameObjectID"/>s are defined.</param>
        /// <param name="in_entities">The <see cref="GameObject"/>s to collect.  Cannot be null.</param>
        public GameObjectCollection(List <Range <GameObjectID> > in_bounds, IEnumerable <GameObject> in_entities)
        {
            Precondition.IsNotNull(in_entities, nameof(in_entities));

            var baseDictionary = new Dictionary <GameObjectID, GameObject> {
                { GameObjectID.None, null }
            };

            foreach (var entity in in_entities)
            {
                Precondition.IsInRange(entity.ID, in_bounds, nameof(in_entities));

                if (!baseDictionary.ContainsKey(entity.ID))
                {
                    baseDictionary[entity.ID] = entity;
                }
                else
                {
                    throw new InvalidOperationException($"Tried to duplicate entity ID {entity.ID}.");
                }
            }

            Bounds   = in_bounds;
            Entities = baseDictionary;
        }
예제 #3
0
        public void EntityIsInRangeThrowsOnOutOfRangeTest()
        {
            var testID    = (EntityID)12;
            var testRange = new Range <EntityID>(0, 10);

            Assert.Throws <ArgumentOutOfRangeException>(() => { Precondition.IsInRange(testID, testRange); });
        }
예제 #4
0
파일: Critter.cs 프로젝트: v-karpov/Parquet
 /// <summary>
 /// Initializes a new instance of the <see cref="Critter"/> class.
 /// </summary>
 /// <param name="in_id">
 /// Unique identifier for the <see cref="Critter"/>.  Cannot be null.
 /// Must be a <see cref="All.CritterIDs"/>.
 /// </param>
 /// <param name="in_name">Player-friendly name of the <see cref="Critter"/>.  Cannot be null or empty.</param>
 /// <param name="in_description">Player-friendly description of the <see cref="Critter"/>.</param>
 /// <param name="in_comment">Comment of, on, or by the <see cref="Critter"/>.</param>
 /// <param name="in_nativeBiome">The <see cref="Biome"/> in which this <see cref="Critter"/> is most comfortable.</param>
 /// <param name="in_primaryBehavior">The rules that govern how this <see cref="Critter"/> acts.  Cannot be null.</param>
 /// <param name="in_avoids">Any parquets this <see cref="Critter"/> avoids.</param>
 /// <param name="in_seeks">Any parquets this <see cref="Critter"/> seeks.</param>
 public Critter(GameObjectID in_id, string in_name, string in_description, string in_comment,
                GameObjectID in_nativeBiome, Behavior in_primaryBehavior,
                List <GameObjectID> in_avoids = null, List <GameObjectID> in_seeks = null)
     : base(All.CritterIDs, in_id, in_name, in_description, in_comment, in_nativeBiome, in_primaryBehavior, in_avoids, in_seeks)
 {
     Precondition.IsInRange(in_id, All.CritterIDs, nameof(in_id));
 }
예제 #5
0
        public void EntityIsInRangeTest()
        {
            var testID    = (EntityID)6;
            var testRange = new Range <EntityID>(0, 10);

            var exception = Record.Exception(() => Precondition.IsInRange(testID, testRange));

            Assert.Null(exception);
        }
예제 #6
0
        public void RangeIsInRangeTest()
        {
            var innerRange  = new Range <EntityID>(1, 9);
            var outterRange = new Range <EntityID>(0, 10);

            var exception = Record.Exception(() => Precondition.IsInRange(innerRange, outterRange));

            Assert.Null(exception);
        }
예제 #7
0
        public void EntityIsInRangeCollectionThrowsOnOutOfRangeTest()
        {
            var testID         = (EntityID)12;
            var testCollection = new List <Range <EntityID> > {
                new Range <EntityID>(0, 5), new Range <EntityID>(6, 10)
            };

            Assert.Throws <ArgumentOutOfRangeException>(() => { Precondition.IsInRange(testID, testCollection); });
        }
예제 #8
0
        public void RangeIsInRangeCollectionThrowsOnOutOfRangeTest()
        {
            var innerRange     = new Range <EntityID>(0, 10);
            var testCollection = new List <Range <EntityID> > {
                new Range <EntityID>(1, 5), new Range <EntityID>(6, 9)
            };

            Assert.Throws <ArgumentOutOfRangeException>(() => { Precondition.IsInRange(innerRange, testCollection); });
        }
예제 #9
0
        protected ParquetParent(Range <GameObjectID> in_bounds, GameObjectID in_id, string in_name, string in_description,
                                string in_comment, GameObjectID in_itemID, GameObjectTag in_addsToBiome, GameObjectTag in_addsToRoom)
            : base(in_bounds, in_id, in_name, in_description, in_comment)
        {
            Precondition.IsInRange(in_itemID, All.ItemIDs, nameof(in_itemID));

            ItemID      = in_itemID;
            AddsToBiome = string.IsNullOrEmpty(in_addsToBiome) ? GameObjectTag.None : in_addsToBiome;
            AddsToRoom  = string.IsNullOrEmpty(in_addsToRoom) ? GameObjectTag.None : in_addsToRoom;
        }
예제 #10
0
        protected GameObject(Range <GameObjectID> in_bounds, GameObjectID in_id, string in_name, string in_description, string in_comment)
        {
            Precondition.IsInRange(in_id, in_bounds, nameof(in_id));
            Precondition.IsNotEmpty(in_name, nameof(in_name));

            ID          = in_id;
            Name        = in_name;
            Description = in_description ?? "";
            Comment     = in_comment ?? "";
        }
예제 #11
0
        public void RangeIsInRangeCollectionTest()
        {
            var innerRange     = new Range <EntityID>(1, 4);
            var testCollection = new List <Range <EntityID> > {
                new Range <EntityID>(0, 5), new Range <EntityID>(6, 10)
            };

            var exception = Record.Exception(() => Precondition.IsInRange(innerRange, testCollection));

            Assert.Null(exception);
        }
예제 #12
0
        public void EntityIsInRangeCollectionTest()
        {
            var testID         = (EntityID)7;
            var testCollection = new List <Range <EntityID> > {
                new Range <EntityID>(0, 5), new Range <EntityID>(6, 10)
            };

            var exception = Record.Exception(() => Precondition.IsInRange(testID, testCollection));

            Assert.Null(exception);
        }
예제 #13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ParquetStack"/> struct.
        /// </summary>
        /// <param name="in_floor">The floor-layer parquet.</param>
        /// <param name="in_block">The The floor-layer parquet-layer parquet.</param>
        /// <param name="in_furnishing">The furnishing-layer parquet.</param>
        /// <param name="in_collectible">The collectible-layer parquet.</param>
        public ParquetStack(GameObjectID in_floor, GameObjectID in_block, GameObjectID in_furnishing, GameObjectID in_collectible)
        {
            Precondition.IsInRange(in_floor, All.FloorIDs, nameof(in_floor));
            Precondition.IsInRange(in_block, All.BlockIDs, nameof(in_block));
            Precondition.IsInRange(in_furnishing, All.FurnishingIDs, nameof(in_furnishing));
            Precondition.IsInRange(in_collectible, All.CollectibleIDs, nameof(in_collectible));

            Floor       = in_floor;
            Block       = in_block;
            Furnishing  = in_furnishing;
            Collectible = in_collectible;
        }
예제 #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NPC"/> class.
 /// </summary>
 /// <param name="in_id">
 /// Unique identifier for the <see cref="NPC"/>.  Cannot be null.
 /// Must be a valid <see cref="All.NpcIDs"/>.
 /// </param>
 /// <param name="in_personalName">Personal name of the <see cref="NPC"/>.  Cannot be null or empty.</param>
 /// <param name="in_familyName">Family name of the <see cref="NPC"/>.  Cannot be null or empty.</param>
 /// <param name="in_description">Player-friendly description of the <see cref="NPC"/>.</param>
 /// <param name="in_comment">Comment of, on, or by the <see cref="NPC"/>.</param>
 /// <param name="in_nativeBiome">The <see cref="GameObjectID"/> of the <see cref="Biome"/> in which this <see cref="NPC"/> is most comfortable.</param>
 /// <param name="in_currentBehavior">The rules that govern how this <see cref="NPC"/> acts.  Cannot be null.</param>
 /// <param name="in_avoids">Any parquets this <see cref="NPC"/> avoids.</param>
 /// <param name="in_seeks">Any parquets this <see cref="NPC"/> seeks.</param>
 /// <param name="in_pronoun">How to refer to this <see cref="NPC"/>.</param>
 /// <param name="in_storyCharacterID">A means of identifying this <see cref="PlayerCharacter"/> across multiple shipped game titles.</param>
 /// <param name="in_quests">Any quests this <see cref="NPC"/> has to offer.</param>
 /// <param name="in_dialogue">All dialogue this <see cref="NPC"/> may say.</param>
 /// <param name="in_inventory">Any items this <see cref="NPC"/> owns.</param>
 public NPC(GameObjectID in_id, string in_personalName, string in_familyName,
            string in_description, string in_comment,
            GameObjectID in_nativeBiome, Behavior in_currentBehavior,
            List <GameObjectID> in_avoids    = null, List <GameObjectID> in_seeks         = null,
            string in_pronoun                = DefaultPronoun, string in_storyCharacterID = "",
            List <GameObjectID> in_quests    = null, List <string> in_dialogue            = null,
            List <GameObjectID> in_inventory = null)
     : base(All.NpcIDs, in_id, in_personalName, in_familyName, in_description,
            in_comment, in_nativeBiome, in_currentBehavior, in_avoids, in_seeks,
            in_pronoun, in_storyCharacterID, in_quests, in_dialogue, in_inventory)
 {
     Precondition.IsInRange(in_id, All.NpcIDs, nameof(in_id));
 }
예제 #15
0
        public Collectible(GameObjectID in_id, string in_name, string in_description, string in_comment,
                           GameObjectID?in_itemID      = null, GameObjectTag?in_addsToBiome = null,
                           GameObjectTag?in_addsToRoom = null, CollectionEffect in_effect   = CollectionEffect.None,
                           int in_effectAmount         = 0)
            : base(Bounds, in_id, in_name, in_description, in_comment, in_itemID ?? GameObjectID.None,
                   in_addsToBiome ?? GameObjectTag.None, in_addsToRoom ?? GameObjectTag.None)
        {
            var nonNullItemID = in_itemID ?? GameObjectID.None;

            Precondition.IsInRange(nonNullItemID, All.ItemIDs, nameof(in_itemID));

            Effect       = in_effect;
            EffectAmount = in_effectAmount;
        }
예제 #16
0
        /// <summary>
        /// Used by <see cref="Being"/> subtypes.
        /// </summary>
        /// <param name="in_bounds">
        /// The bounds within which the <see cref="Being"/>'s <see cref="GameObjectID"/> is defined.
        /// Must be one of <see cref="All.BeingIDs"/>.
        /// </param>
        /// <param name="in_id">Unique identifier for the <see cref="Being"/>.  Cannot be null.</param>
        /// <param name="in_name">Player-friendly name of the <see cref="Being"/>.  Cannot be null or empty.</param>
        /// <param name="in_description">Player-friendly description of the <see cref="Being"/>.</param>
        /// <param name="in_comment">Comment of, on, or by the <see cref="Being"/>.</param>
        /// <param name="in_nativeBiome">The <see cref="GameObjectID"/> for the <see cref="Biome"/> in which this <see cref="Being"/> is most comfortable.</param>
        /// <param name="in_primaryBehavior">The rules that govern how this <see cref="Being"/> acts.  Cannot be null.</param>
        /// <param name="in_avoids">Any parquets this <see cref="Being"/> avoids.</param>
        /// <param name="in_seeks">Any parquets this <see cref="Being"/> seeks.</param>
        protected Being(Range <GameObjectID> in_bounds, GameObjectID in_id, string in_name, string in_description,
                        string in_comment, GameObjectID in_nativeBiome, Behavior in_primaryBehavior,
                        List <GameObjectID> in_avoids = null, List <GameObjectID> in_seeks = null)
            : base(in_bounds, in_id, in_name, in_description, in_comment)
        {
            Precondition.IsInRange(in_bounds, All.BeingIDs, nameof(in_bounds));
            Precondition.IsInRange(in_nativeBiome, All.BiomeIDs, nameof(in_nativeBiome));
            Precondition.AreInRange(in_avoids, All.ParquetIDs, nameof(in_avoids));
            Precondition.AreInRange(in_seeks, All.ParquetIDs, nameof(in_seeks));

            NativeBiome     = in_nativeBiome;
            PrimaryBehavior = in_primaryBehavior;
            Avoids          = (in_avoids ?? Enumerable.Empty <GameObjectID>()).ToList();
            Seeks           = (in_seeks ?? Enumerable.Empty <GameObjectID>()).ToList();
        }
예제 #17
0
        public Furnishing(GameObjectID in_id, string in_name, string in_description, string in_comment,
                          GameObjectID?in_itemID      = null, GameObjectTag?in_addsToBiome = null,
                          GameObjectTag?in_addsToRoom = null, bool in_isWalkable           = false,
                          bool in_isEntry             = false, bool in_isEnclosing = false, GameObjectID?in_swapID = null)
            : base(Bounds, in_id, in_name, in_description, in_comment, in_itemID ?? GameObjectID.None,
                   in_addsToBiome ?? GameObjectTag.None, in_addsToRoom ?? GameObjectTag.None)
        {
            var nonNullSwapID = in_swapID ?? GameObjectID.None;

            Precondition.IsInRange(nonNullSwapID, Bounds, nameof(in_swapID));

            IsWalkable  = in_isWalkable;
            IsEntry     = in_isEntry;
            IsEnclosing = in_isEnclosing;
            SwapID      = nonNullSwapID;
        }
예제 #18
0
파일: Item.cs 프로젝트: v-karpov/Parquet
        public Item(GameObjectID in_id, ItemType in_subtype, string in_name, string in_description, string in_comment,
                    int in_price, int in_rarity, int in_stackMax, int in_effectWhileHeld,
                    int in_effectWhenUsed, GameObjectID in_asParquet,
                    List <GameObjectTag> in_itemTags = null, GameObjectID?in_recipeID = null)
            : base(All.ItemIDs, in_id, in_name, in_description, in_comment)
        {
            Precondition.IsInRange(in_asParquet, All.ParquetIDs, nameof(in_asParquet));
            Precondition.MustBePositive(in_stackMax, nameof(in_stackMax));

            // TODO Do we need to bounds-check in_effectWhileHeld?  If so, add a unit test.
            // TODO Do we need to bounds-check in_effectWhenUsed?  If so, add a unit test.

            /* TODO This check is a good idea but it is improper to get a specific entity from All
             * during initialization of an entity.  If we are to include this functionality another
             * means of implementing it must be found.
             * if (nonNullCraftingRecipeID != CraftingRecipe.NotCraftable.ID)
             * {
             *  var craftingRecipe = All.CraftingRecipes.Get<CraftingRecipe>(nonNullCraftingRecipeID);
             *  var givenRecipeProducesGivenItem = false;
             *  foreach (var product in craftingRecipe.Products)
             *  {
             *      if (product.ItemID == in_id)
             *      {
             *          givenRecipeProducesGivenItem = true;
             *          break;
             *      }
             *  }
             *  if (!givenRecipeProducesGivenItem)
             *  {
             *      throw new ArgumentException($"The crafting recipe for {in_name} include {in_name} among its products.");
             *  }
             * }
             */

            var nonNullItemTags         = in_itemTags ?? Enumerable.Empty <GameObjectTag>().ToList();
            var nonNullCraftingRecipeID = in_recipeID ?? CraftingRecipe.NotCraftable.ID;

            Subtype         = in_subtype;
            Price           = in_price;
            Rarity          = in_rarity;
            StackMax        = in_stackMax;
            EffectWhileHeld = in_effectWhileHeld;
            EffectWhenUsed  = in_effectWhenUsed;
            AsParquet       = in_asParquet;
            ItemTags        = nonNullItemTags;
            Recipe          = nonNullCraftingRecipeID;
        }
예제 #19
0
        public Block(GameObjectID in_id, string in_name, string in_description, string in_comment,
                     GameObjectID?in_itemID          = null, GameObjectTag?in_addsToBiome = null,
                     GameObjectTag?in_addsToRoom     = null,
                     GatheringTools in_gatherTool    = GatheringTools.None,
                     GatheringEffect in_gatherEffect = GatheringEffect.None,
                     GameObjectID?in_collectibleID   = null, bool in_isFlammable = false,
                     bool in_isLiquid = false, int in_maxToughness               = DefaultMaxToughness)
            : base(Bounds, in_id, in_name, in_description, in_comment, in_itemID ?? GameObjectID.None,
                   in_addsToBiome ?? GameObjectTag.None, in_addsToRoom ?? GameObjectTag.None)
        {
            var nonNullCollectibleID = in_collectibleID ?? GameObjectID.None;

            Precondition.IsInRange(nonNullCollectibleID, All.CollectibleIDs, nameof(in_collectibleID));

            GatherTool    = in_gatherTool;
            GatherEffect  = in_gatherEffect;
            CollectibleID = nonNullCollectibleID;
            IsFlammable   = in_isFlammable;
            IsLiquid      = in_isLiquid;
            MaxToughness  = in_maxToughness;
        }
예제 #20
0
        /// <summary>
        /// Returns the specified <typeparamref name="T"/>.
        /// </summary>
        /// <param name="in_id">A valid, defined <typeparamref name="T"/> identifier.</param>
        /// <typeparam name="T">
        /// The type of <typeparamref name="ParentType"/> sought.  Must correspond to the given <paramref name="in_id"/>.
        /// </typeparam>
        /// <returns>The specified <typeparamref name="T"/>.</returns>
        public T Get <T>(GameObjectID in_id) where T : ParentType
        {
            Precondition.IsInRange(in_id, Bounds, nameof(in_id));

            return((T)Entities[in_id]);
        }
예제 #21
0
        /// <summary>
        /// Determines whether the <see cref="GameObjectCollection{T}"/> contains the specified <see cref="GameObject"/>.
        /// </summary>
        /// <param name="in_id">The <see cref="GameObjectID"/> of the <see cref="GameObject"/> to find.</param>
        /// <returns><c>true</c> if the <see cref="GameObjectID"/> was found; <c>false</c> otherwise.</returns>
        /// <remarks>This method is equivalent to <see cref="Dictionary{EntityID, Entity}.ContainsKey"/>.</remarks>
        public bool Contains(GameObjectID in_id)
        {
            Precondition.IsInRange(in_id, Bounds, nameof(in_id));

            return(Entities.ContainsKey(in_id));
        }