diff options
| author | Syndamia <kamen.d.mladenov@protonmail.com> | 2020-04-28 17:53:52 +0300 |
|---|---|---|
| committer | Syndamia <kamen.d.mladenov@protonmail.com> | 2020-04-28 17:53:52 +0300 |
| commit | 95e3f7d2406beba2f120ecddd3f98e0ae5883443 (patch) | |
| tree | 4647c255e2afdcd7c6dfff566f659c654bad5499 | |
| parent | 4fa98228dbb89fd3590edb4e933c284ee34a1ef9 (diff) | |
| download | Mundus-95e3f7d2406beba2f120ecddd3f98e0ae5883443.tar Mundus-95e3f7d2406beba2f120ecddd3f98e0ae5883443.tar.gz Mundus-95e3f7d2406beba2f120ecddd3f98e0ae5883443.zip | |
Did documentation for Crafting, Mobs, Superlayers and Tiles services
| -rw-r--r-- | Mundus/Data/SuperLayers/Mobs/MI.cs | 2 | ||||
| -rw-r--r-- | Mundus/Mundus.csproj | 1 | ||||
| -rw-r--r-- | Mundus/Service/Crafting/CraftingController.cs | 44 | ||||
| -rw-r--r-- | Mundus/Service/Crafting/CraftingRecipe.cs | 71 | ||||
| -rw-r--r-- | Mundus/Service/Mobs/Controllers/MobMovement.cs | 67 | ||||
| -rw-r--r-- | Mundus/Service/Mobs/Controllers/MobStatsController.cs | 17 | ||||
| -rw-r--r-- | Mundus/Service/Mobs/Controllers/MobTerraforming.cs | 25 | ||||
| -rw-r--r-- | Mundus/Service/Mobs/LandMobs/Player.cs | 9 | ||||
| -rw-r--r-- | Mundus/Service/Mobs/MobTile.cs | 18 | ||||
| -rw-r--r-- | Mundus/Service/SuperLayers/HeightController.cs | 6 | ||||
| -rw-r--r-- | Mundus/Service/SuperLayers/ImageController.cs | 56 | ||||
| -rw-r--r-- | Mundus/Views/Windows/CraftingWindow.cs | 5 | ||||
| -rw-r--r-- | Mundus/Views/Windows/MediumGameWindow.cs | 12 | ||||
| -rw-r--r-- | Mundus/Views/Windows/SmallGameWindow.cs | 12 |
14 files changed, 236 insertions, 109 deletions
diff --git a/Mundus/Data/SuperLayers/Mobs/MI.cs b/Mundus/Data/SuperLayers/Mobs/MI.cs index 98f85e0..1faf580 100644 --- a/Mundus/Data/SuperLayers/Mobs/MI.cs +++ b/Mundus/Data/SuperLayers/Mobs/MI.cs @@ -7,7 +7,7 @@ namespace Mundus.Data.Superlayers.Mobs { public static Player Player { get; private set; } public static void CreateInstances(int inventorySize) { - Player = new Player("player", 20, inventorySize, LI.Land); + Player = new Player("player", 20, LI.Land, inventorySize); } public static void CreateInventories(int screenInvSize) { diff --git a/Mundus/Mundus.csproj b/Mundus/Mundus.csproj index 4f4c787..c186234 100644 --- a/Mundus/Mundus.csproj +++ b/Mundus/Mundus.csproj @@ -46,6 +46,7 @@ <Reference Include="atk-sharp, Version=2.4.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f">
<SpecificVersion>False</SpecificVersion>
</Reference>
+ <Reference Include="Mono.Posix" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="gtk-gui\gui.stetic">
diff --git a/Mundus/Service/Crafting/CraftingController.cs b/Mundus/Service/Crafting/CraftingController.cs index 3b9fb79..a9aee09 100644 --- a/Mundus/Service/Crafting/CraftingController.cs +++ b/Mundus/Service/Crafting/CraftingController.cs @@ -1,8 +1,8 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using Mundus.Data.Crafting; using Mundus.Data.Superlayers.Mobs; +using Mundus.Service.Tiles; using Mundus.Service.Tiles.Items; namespace Mundus.Service.Crafting { @@ -10,19 +10,12 @@ namespace Mundus.Service.Crafting { private static Dictionary<ItemTile, int> avalableItems; /// <summary> - /// Gets all different items and their quantaties in the inventory. Stores that in memory. + /// Returns all recipes that can be executed with the current items in the player inventory (Inventory.Items) /// </summary> - public static void FindAvalableItems() { - avalableItems = MI.Player.Inventory.Items.Where(x => x != null) - //Can't use distinct on non primative types, beause they also hold their memory location info (I think). - //This is my way of getting only the "unique" item tiles. - .Select(x => x.stock_id).Distinct().Select(x => MI.Player.Inventory.Items.Where(y => y != null).First(y => y.stock_id == x)) - //For each "unique" item tile (key), get how many there are of it in the player inventory (value) - .Select(x => new KeyValuePair<ItemTile, int>(x, MI.Player.Inventory.Items.Where(y => y != null).Count(i => i.stock_id == x.stock_id))) - .ToDictionary(kvp => kvp.Key, kvp => kvp.Value); - } + /// <returns>All avalable recipies.</returns> + public static CraftingRecipe[] GetAvalableRecipes() { + FindAvalableItems(); - public static CraftingRecipe[] GetAvalableRecipies() { List<CraftingRecipe> recipes = new List<CraftingRecipe>(); foreach (var recipe in RI.AllRecipies) { @@ -34,14 +27,25 @@ namespace Mundus.Service.Crafting { return recipes.ToArray(); } + // Sets avalableItems to all items in the player inventory (Inventory.Items) + private static void FindAvalableItems() { + avalableItems = MI.Player.Inventory.Items.Where(x => x != null) + //Can't use distinct on non primative types, beause they also hold their memory location info (I think). + //This is my way of getting only the "unique" item tiles. + .Select(x => x.stock_id).Distinct().Select(x => MI.Player.Inventory.Items.Where(y => y != null).First(y => y.stock_id == x)) + //For each "unique" item tile (key), get how many there are of it in the player inventory (value) + .Select(x => new KeyValuePair<ItemTile, int>(x, MI.Player.Inventory.Items.Where(y => y != null).Count(i => i.stock_id == x.stock_id))) + .ToDictionary(kvp => kvp.Key, kvp => kvp.Value); + } + /// <summary> /// Removes items, used for crafting and adds the result item to the inventory /// </summary> /// <param name="itemRecipe">CraftingRecipie of the item that will be crafted</param> - public static void CraftItem(CraftingRecipe itemRecipe) { + public static void CraftItem(CraftingRecipe itemRecipe, MobTile mob) { // Removes all items that are used to craft the result item foreach (var itemAndCount in itemRecipe.GetRequiredItemsAndCounts()) { - for(int i = 0, removedItems = 0; i < MI.Player.Inventory.Items.Length && removedItems < itemAndCount.Value; i++) { + for(int i = 0, removedItems = 0; i < mob.Inventory.Items.Length && removedItems < itemAndCount.Value; i++) { if (MI.Player.Inventory.Items[i] != null) { if (MI.Player.Inventory.Items[i].stock_id == itemAndCount.Key.stock_id) { MI.Player.Inventory.Items[i] = null; @@ -52,7 +56,7 @@ namespace Mundus.Service.Crafting { } ItemTile tmp = null; - // Adds the result item to the inventory (in the correct type) + // Adds the result item to the inventory (in the correct data type) if (itemRecipe.ResultItem.GetType() == typeof(Material)) { tmp = new Material((Material)itemRecipe.ResultItem); } @@ -69,5 +73,13 @@ namespace Mundus.Service.Crafting { Data.Windows.WI.SelWin.PrintInventory(); } + + /// <summary> + /// Does CraftItem method for the player + /// </summary> + /// <param name="itemRecipe">CraftingRecipie of the item that will be crafted</param> + public static void CraftItemPlayer(CraftingRecipe itemRecipe) { + CraftItem(itemRecipe, MI.Player); + } } }
\ No newline at end of file diff --git a/Mundus/Service/Crafting/CraftingRecipe.cs b/Mundus/Service/Crafting/CraftingRecipe.cs index 34092ee..d3829d0 100644 --- a/Mundus/Service/Crafting/CraftingRecipe.cs +++ b/Mundus/Service/Crafting/CraftingRecipe.cs @@ -3,22 +3,56 @@ using System.Linq; using Mundus.Service.Tiles.Items; namespace Mundus.Service.Crafting { - public class CraftingRecipe { + public class CraftingRecipe {
+ /// <summary>
+ /// Item that will be added to the inventory after crafting
+ /// </summary>
+ /// <value>The result item.</value> public ItemTile ResultItem { get; private set; } - - public int Count1 { get; private set; } +
+ /// <summary>
+ /// Required amount of the first item
+ /// </summary> + public int Count1 { get; private set; }
+ /// <summary>
+ /// Required first item
+ /// </summary> public ItemTile ReqItem1 { get; private set; } - - public int Count2 { get; private set; } +
+ /// <summary>
+ /// Required amount of the second item
+ /// </summary> + public int Count2 { get; private set; }
+ /// <summary>
+ /// Required second item
+ /// </summary> public ItemTile ReqItem2 { get; private set; } - - public int Count3 { get; private set; } +
+ /// <summary>
+ /// Required amount of the third item
+ /// </summary> + public int Count3 { get; private set; }
+ /// <summary>
+ /// Required third item
+ /// </summary> public ItemTile ReqItem3 { get; private set; } - - public int Count4 { get; private set; } +
+ /// <summary>
+ /// Required amount of the fourth item
+ /// </summary> + public int Count4 { get; private set; }
+ /// <summary>
+ /// Required fourth item
+ /// </summary> public ItemTile ReqItem4 { get; private set; } - - public int Count5 { get; private set; } +
+ /// <summary>
+ /// Required amount of the fifth item
+ /// </summary> + public int Count5 { get; private set; }
+ /// <summary>
+ /// Required fifth item
+ /// </summary> public ItemTile ReqItem5 { get; private set; } public CraftingRecipe(ItemTile resultItem, int count1, ItemTile reqItem1) :this(resultItem, count1, reqItem1, 0, null, 0, null, 0, null, 0, null) @@ -53,6 +87,11 @@ namespace Mundus.Service.Crafting { } //ugly af, but will rewrite when I imntegrade data bases
+ /// <summary>
+ /// Checks if the parameter has enough of every requried item
+ /// </summary>
+ /// <returns><c>true</c>If has enough<c>false</c>otherwise</returns>
+ /// <param name="itemsAndCounts">Dictionary that has the items and their respective amounts (that will be checked)</param>
public bool HasEnoughItems(Dictionary<ItemTile, int> itemsAndCounts) { bool hasEnough = true;
@@ -93,7 +132,10 @@ namespace Mundus.Service.Crafting { return hasEnough; }
- +
+ /// <summary>
+ /// Checks if the given item (and amount) is enough for the recipe
+ /// </summary> public bool HasEnoughOfItem(ItemTile item, int count) { if (ReqItem1.stock_id == item.stock_id) return count >= Count1; if (ReqItem2.stock_id == item.stock_id) return count >= Count2; @@ -102,7 +144,10 @@ namespace Mundus.Service.Crafting { if (ReqItem5.stock_id == item.stock_id) return count >= Count5; return false; } - +
+ /// <summary>
+ /// Returns a dictionary of every required item and their respective amount
+ /// </summary> public Dictionary<ItemTile, int> GetRequiredItemsAndCounts() { Dictionary<ItemTile, int> req = new Dictionary<ItemTile, int>();
diff --git a/Mundus/Service/Mobs/Controllers/MobMovement.cs b/Mundus/Service/Mobs/Controllers/MobMovement.cs index dcec506..20082b9 100644 --- a/Mundus/Service/Mobs/Controllers/MobMovement.cs +++ b/Mundus/Service/Mobs/Controllers/MobMovement.cs @@ -9,23 +9,27 @@ namespace Mundus.Service.Mobs.Controllers { public static class MobMovement {
private static Random rnd = new Random();
- public static void MovePlayer(int yPos, int xPos, int size) { - ChangePosition(MI.Player, yPos, xPos, size); - }
-
+ /// <summary>
+ /// Moves all mobs that have a RndMovementRate of more than one on a random tile
+ /// in a 3x3 radius (including the tile they are currently on)
+ /// </summary>
public static void MoveRandomlyAllMobs() { - foreach(var superLayer in LI.AllSuperLayers()) { - for (int y = 0; y < MapSizes.CurrSize; y++) { - for (int x = 0; x < MapSizes.CurrSize; x++) { - MobTile mob = MI.Player.CurrSuperLayer.GetMobLayerTile(y, x); + foreach(var superLayer in LI.AllSuperLayers())
+ { + for (int y = 0; y < MapSizes.CurrSize; y++)
+ { + for (int x = 0; x < MapSizes.CurrSize; x++)
+ { + MobTile mob = superLayer.GetMobLayerTile(y, x); - if (mob != null) { - if (mob != MI.Player && - rnd.Next(0, mob.RndMovementRate) == 1) { + if (mob != null) {
+ // Checks validity of RndMovementRate and descides if a mob will move to another tile + if (mob.RndMovementRate > 0 && rnd.Next(0, mob.RndMovementRate) == 1)
+ { int newYPos = rnd.Next(mob.YPos - 1, mob.YPos + 2); int newXPos = rnd.Next(mob.XPos - 1, mob.XPos + 2); - ChangePosition(mob, newYPos, newXPos, MapSizes.CurrSize); + ChangeMobPosition(mob, newYPos, newXPos, MapSizes.CurrSize); } } } @@ -33,33 +37,47 @@ namespace Mundus.Service.Mobs.Controllers { } }
- public static void ChangePosition(MobTile mob, int yPos, int xPos, int size) { + public static void ChangeMobPosition(MobTile mob, int yPos, int xPos, int mapSize) { if (InBoundaries(yPos, xPos)) { if (CanWalkAt(mob, yPos, xPos)) { - ChangePosition(mob, yPos, xPos); + ChangeMobPosition(mob, yPos, xPos); } } } - public static void ChangePosition(MobTile mob, int yPos, int xPos) { - mob.CurrSuperLayer.RemoveMobFromPosition(mob.YPos, mob.XPos); + public static void MovePlayer(int yPos, int xPos, int mapSize) {
+ ChangeMobPosition(MI.Player, yPos, xPos, mapSize);
+ }
+ private static void ChangeMobPosition(MobTile mob, int yPos, int xPos) {
+ // Mob is removed from his current superlayer and in the end is added to the new one
+ // Note: mob could not move, but will still be removed and readded to the superlayer + mob.CurrSuperLayer.RemoveMobFromPosition(mob.YPos, mob.XPos); +
+ // If mob can go down a layer from a hole if (mob.CurrSuperLayer.GetGroundLayerTile(yPos, xPos) == null &&
- HeightController.GetLayerUnderneathMob(mob) != null) {
- if (HeightController.GetLayerUnderneathMob(mob).GetMobLayerTile(yPos, xPos) == null) { + HeightController.GetLayerUnderneathMob(mob) != null)
+ {
+ if (HeightController.GetLayerUnderneathMob(mob).GetMobLayerTile(yPos, xPos) == null)
+ { mob.CurrSuperLayer = HeightController.GetLayerUnderneathMob(mob); } }
+ // If mob can go down a layer from non-solid ground
else if (!mob.CurrSuperLayer.GetGroundLayerTile(yPos, xPos).Solid &&
- HeightController.GetLayerUnderneathMob(mob) != null) {
- if (HeightController.GetLayerUnderneathMob(mob).GetMobLayerTile(yPos, xPos) == null) { + HeightController.GetLayerUnderneathMob(mob) != null)
+ {
+ if (HeightController.GetLayerUnderneathMob(mob).GetMobLayerTile(yPos, xPos) == null)
+ { mob.CurrSuperLayer = HeightController.GetLayerUnderneathMob(mob); } - } + }
+ // If mob can climb up else if (mob.CurrSuperLayer.GetStructureLayerTile(yPos, xPos) != null &&
- HeightController.GetLayerAboveMob(mob).GetMobLayerTile(yPos, xPos) == null) { - //Mobs can only climb to the superlayer on top of them, if there is a climable structure - //and there is a "hole" on top of the climable structure + HeightController.GetLayerAboveMob(mob).GetMobLayerTile(yPos, xPos) == null)
+ { + // Mobs can only climb to the superlayer on top of them, if
+ // there is a climable structure and there is a "hole" on top of the climable structure if (mob.CurrSuperLayer.GetStructureLayerTile(yPos, xPos).IsClimable && HeightController.GetLayerAboveMob(mob) != null)
{
@@ -88,6 +106,7 @@ namespace Mundus.Service.Mobs.Controllers { mob.CurrSuperLayer.GetMobLayerTile(yPos, xPos) == mob); }
+ // Returns if the chosen new location is inside the map
private static bool InBoundaries(int yPos, int xPos) { return yPos >= 0 && xPos >= 0 && yPos < MapSizes.CurrSize && xPos < MapSizes.CurrSize; } diff --git a/Mundus/Service/Mobs/Controllers/MobStatsController.cs b/Mundus/Service/Mobs/Controllers/MobStatsController.cs index df09d4b..d02d65a 100644 --- a/Mundus/Service/Mobs/Controllers/MobStatsController.cs +++ b/Mundus/Service/Mobs/Controllers/MobStatsController.cs @@ -9,6 +9,11 @@ namespace Mundus.Service.Mob.Controllers { return MI.Player.Health; } + /// <summary> + /// Returns the stock_id of the hearth icon that must be used on the given position of the health bar + /// </summary> + /// <returns>stock_id of hearth icon</returns> + /// <param name="index">Health bar index</param> public static string GetPlayerHearth(int index) { string stock_id = "empty"; @@ -29,6 +34,10 @@ namespace Mundus.Service.Mob.Controllers { } } + /// <summary> + /// Heals the player (unless/until he has full health) + /// </summary> + /// <param name="healthPoints">Health points to heal with</param> public static void TryHealPlayer(int healthPoints) { MI.Player.Health += healthPoints; @@ -37,6 +46,9 @@ namespace Mundus.Service.Mob.Controllers { } } + /// <summary> + /// Returns the name of the superlayer the player is curently on + /// </summary> public static string GetPlayerSuperLayerName() { return MI.Player.CurrSuperLayer.ToString(); } @@ -57,8 +69,11 @@ namespace Mundus.Service.Mob.Controllers { return MI.Player.YPos; } + /// <summary> + /// Checks if the player has an an empty/non-solid tile directly on the superlayer above him + /// </summary> public static bool ExistsHoleOnTopOfPlayer() { - //There can't be a hole if there is nothing above layer + //There can't be a hole if there isn't a layer above the player if (HeightController.GetLayerAboveMob(MI.Player) == null) { return false; } diff --git a/Mundus/Service/Mobs/Controllers/MobTerraforming.cs b/Mundus/Service/Mobs/Controllers/MobTerraforming.cs index e83ca36..41ae9cf 100644 --- a/Mundus/Service/Mobs/Controllers/MobTerraforming.cs +++ b/Mundus/Service/Mobs/Controllers/MobTerraforming.cs @@ -7,23 +7,31 @@ using Mundus.Service.Tiles.Items; namespace Mundus.Service.Mobs.Controllers { public static class MobTerraforming {
+ /// <summary>
+ /// Tries to place a selected structure/ground tile or to mine/dig (destroy) at the selected location
+ /// </summary>
+ /// <param name="inventoryPlace">Place where the selected item is located ("hotbar", "items", ...)</param>
+ /// <param name="inventoryIndex">Index of the place where the item is located</param>
public static void PlayerTerraformAt(int mapYPos, int mapXPos, string inventoryPlace, int inventoryIndex) { var selectedItemType = Inventory.GetPlayerItem(inventoryPlace, inventoryIndex).GetType(); - +
+ // If player can place strucure if (selectedItemType == typeof(Structure) && PlayerCanBuildStructureAt(mapYPos, mapXPos)) { PlayerBuildStructureAt(mapYPos, mapXPos, inventoryPlace, inventoryIndex); MI.Player.Inventory.DeleteItemTile(inventoryPlace, inventoryIndex); }
+ // If Player can place ground
else if (selectedItemType == typeof(GroundTile) && PlayerCanPlaceGroundAt(mapYPos, mapXPos)) { PlayerPlaceGroundAt(mapYPos, mapXPos, inventoryPlace, inventoryIndex); MI.Player.Inventory.DeleteItemTile(inventoryPlace, inventoryIndex); - } + }
+ // If player can mine/dig else if (selectedItemType == typeof(Tool) && PlayerCanDestroyAt(mapYPos, mapXPos)) { PlayerDestroyAt(mapYPos, mapXPos, inventoryPlace, inventoryIndex); } }
-
+ // Player can't destory structures/ground tiles if there are none
private static bool PlayerCanDestroyAt(int yPos, int xPos) {
return MI.Player.CurrSuperLayer.GetStructureLayerTile(yPos, xPos) != null ||
MI.Player.CurrSuperLayer.GetGroundLayerTile(yPos, xPos) != null;
@@ -32,10 +40,11 @@ namespace Mundus.Service.Mobs.Controllers { private static void PlayerDestroyAt(int mapYPos, int mapXPos, string place, int index) {
var selectedTool = (Tool)MI.Player.Inventory.GetItemTile(place, index); - //Only shovels can destroy ground layer tiles, but not when there is something over the ground tile + // Only shovels can destroy ground layer tiles, but not when there is something over the ground tile if (selectedTool.Type == ToolTypes.Shovel && MI.Player.CurrSuperLayer.GetStructureLayerTile(mapYPos, mapXPos) == null) { PlayerTryDestroyGroundAt(mapYPos, mapXPos, selectedTool); - } + }
+ // Don't try to destroy structure if there is no structure else if (MI.Player.CurrSuperLayer.GetStructureLayerTile(mapYPos, mapXPos) != null) { PlayerTryDestroyStructureAt(mapYPos, mapXPos, selectedTool); } @@ -44,12 +53,12 @@ namespace Mundus.Service.Mobs.Controllers { private static void PlayerTryDestroyGroundAt(int mapYPos, int mapXPos, Tool shovel) { var selectedGround = MI.Player.CurrSuperLayer.GetGroundLayerTile(mapYPos, mapXPos); - // Grdound tiles that shoud be unbreakable have negative required shovel class + // Grdound tiles that should be unbreakable have a negative required shovel class if (selectedGround.ReqShovelClass <= shovel.Class && selectedGround.ReqShovelClass >= 0) { MI.Player.CurrSuperLayer.SetGroundAtPosition(null, mapYPos, mapXPos); - //When a shovel destroys ground tile, it destroys the structure below (if it is not walkable) ISuperLayer under = HeightController.GetLayerUnderneathMob(MI.Player); + // When a shovel destroys ground tile, it destroys the structure below it (but only if it is not walkable) if (under != null && under.GetStructureLayerTile(mapYPos, mapXPos) != null) { if (!under.GetStructureLayerTile(mapYPos, mapXPos).IsWalkable) { under.RemoveStructureFromPosition(mapYPos, mapXPos); @@ -88,7 +97,7 @@ namespace Mundus.Service.Mobs.Controllers { } }
-
+ // Ground can be placed if there isnt a structure on an empty ground layer spot
private static bool PlayerCanPlaceGroundAt(int yPos, int xPos) { return MI.Player.CurrSuperLayer.GetGroundLayerTile(yPos, xPos) == null &&
MI.Player.CurrSuperLayer.GetStructureLayerTile(yPos, xPos) == null; diff --git a/Mundus/Service/Mobs/LandMobs/Player.cs b/Mundus/Service/Mobs/LandMobs/Player.cs index c590332..fb4859d 100644 --- a/Mundus/Service/Mobs/LandMobs/Player.cs +++ b/Mundus/Service/Mobs/LandMobs/Player.cs @@ -4,11 +4,10 @@ using Mundus.Service.Tiles.Items; namespace Mundus.Service.Mobs.LandMobs { public class Player : MobTile { - public Inventory Inventory { get; set; }
- - public Player(string stock_id, int health, int inventorySize, ISuperLayer currentSuperLayer) : base(stock_id, health, currentSuperLayer) - {
- this.Inventory = new Inventory(inventorySize); + public Player(string stock_id, int health, ISuperLayer currentSuperLayer, int inventorySize)
+ : base(stock_id, health, currentSuperLayer, inventorySize, -1, null)
+ { + base.DroppedUponDeath = (Material)Inventory.Hotbar[0]; } } } diff --git a/Mundus/Service/Mobs/MobTile.cs b/Mundus/Service/Mobs/MobTile.cs index 7384a85..1c0c56b 100644 --- a/Mundus/Service/Mobs/MobTile.cs +++ b/Mundus/Service/Mobs/MobTile.cs @@ -14,21 +14,23 @@ namespace Mundus.Service.Tiles { public int YPos { get; set; } public int XPos { get; set; } public int Health { get; set; } - public Material DroppedUponDeath { get; private set; }
-
+ public Material DroppedUponDeath { get; protected set; }
+ public Inventory Inventory { get; set; } + /// <summary>
- /// Specifies how big the chance of a mob moving (randomly) is. lower value means higher chance for movement.
+ /// Specifies how big the chance of a mob moving (randomly) is. Lower the value, higher the chance for movement.
+ /// Note: negative values (or 0) means the mob won't move randomly
/// </summary>
- /// <value>The random movement limiter.</value>
- public int RndMovementRate { get; private set; } + public int RndMovementRate { get; protected set; } - public MobTile(string stock_id, int health, ISuperLayer currentSuperLayer, int rndMovementQualifier = 3, Material droppedUponDeath = null) { + public MobTile(string stock_id, int health, ISuperLayer currentSuperLayer, int inventorySize = 5, int rndMovementQualifier = 3, Material droppedUponDeath = null) { this.stock_id = stock_id; this.Texture = new Image(stock_id, IconSize.Dnd); this.Health = health;
this.CurrSuperLayer = currentSuperLayer;
this.RndMovementRate = rndMovementQualifier; - this.DroppedUponDeath = droppedUponDeath; + this.DroppedUponDeath = droppedUponDeath;
+ this.Inventory = new Inventory(inventorySize); } } -} +}
\ No newline at end of file diff --git a/Mundus/Service/SuperLayers/HeightController.cs b/Mundus/Service/SuperLayers/HeightController.cs index 5788654..b6d33ba 100644 --- a/Mundus/Service/SuperLayers/HeightController.cs +++ b/Mundus/Service/SuperLayers/HeightController.cs @@ -1,10 +1,10 @@ -using System; -using Mundus.Data.SuperLayers; -using Mundus.Service.Mobs; +using Mundus.Data.SuperLayers; using Mundus.Service.Tiles; namespace Mundus.Service.SuperLayers { public static class HeightController { + // Order of layers (top to bottom): sky, land, underground + private static ISuperLayer sky = LI.Sky; private static ISuperLayer land = LI.Land; private static ISuperLayer underground = LI.Underground; diff --git a/Mundus/Service/SuperLayers/ImageController.cs b/Mundus/Service/SuperLayers/ImageController.cs index 30c4ac6..74ec3f8 100644 --- a/Mundus/Service/SuperLayers/ImageController.cs +++ b/Mundus/Service/SuperLayers/ImageController.cs @@ -6,8 +6,12 @@ using Mundus.Service.Tiles.Items; namespace Mundus.Service.SuperLayers { public static class ImageController { - //Set the image to be either the ground layer tile, "blank" icon, item layer tile, mob layer tile or don't set it to anything - //Note: first the ground and the blank icons are printed, then over them are printed the item tiles and over them are mob tiles + + /// <summary> + /// Returns the image of the selected layer in the superlayer + /// Note: Layer 0 is GroundLayer, 1 is ItemLayer and 2 is Moblayer + /// Note: null structure tiles and null mob tiles are skipped (returns null) + /// </summary> public static Image GetScreenImage(int row, int col, int layer) { ISuperLayer superLayer = MI.Player.CurrSuperLayer; Image img = null; @@ -15,23 +19,24 @@ namespace Mundus.Service.SuperLayers { //Layer 0 is GroundLayer, 1 is ItemLayer and 2 is Moblayer if (layer == 0) { - img = new Image(GetGroundImage(row, col).Stock, IconSize.Dnd); + img = new Image(GetPlayerGroundImage(row, col).Stock, IconSize.Dnd); } - else if (layer == 1 && - superLayer.GetStructureLayerTile( row, col ) != null) + else if (layer == 1 && superLayer.GetStructureLayerTile( row, col ) != null) { - img = new Image(GetStructureImage(row, col).Stock, IconSize.Dnd ); + img = new Image(GetPlayerStructureImage(row, col).Stock, IconSize.Dnd ); } - else if (layer == 2 && - superLayer.GetMobLayerTile(row, col) != null) + else if (layer == 2 && superLayer.GetMobLayerTile(row, col) != null) { img = new Image(superLayer.GetMobLayerTile(row, col).stock_id, IconSize.Dnd); } return img; } - - public static Image GetGroundImage(int row, int col) { + /// <summary> + /// Returns the Image on the given position of the ground layer the player is currently in + /// Note: null values (holes) get the "L_hole" image + /// </summary> + public static Image GetPlayerGroundImage(int row, int col) { ISuperLayer superLayer = MI.Player.CurrSuperLayer; Image img = new Image("L_hole", IconSize.Dnd); @@ -42,7 +47,11 @@ namespace Mundus.Service.SuperLayers { return img; } - public static Image GetStructureImage(int row, int col) { + /// <summary> + /// Returns the Image on the given position of the structure layer the player is currently in + /// Note: null values get the "blank" image ; GetScreenImage skips if the value is null + /// </summary> + public static Image GetPlayerStructureImage(int row, int col) { ISuperLayer superLayer = MI.Player.CurrSuperLayer; Image img = new Image("blank", IconSize.Dnd ); @@ -54,11 +63,16 @@ namespace Mundus.Service.SuperLayers { return img; } + // Checks if the position is inside the map private static bool IsInsideBoundaries(int row, int col) { return row >= 0 && col >= 0 && col < MapSizes.CurrSize && row < MapSizes.CurrSize; } - public static Image GetHotbarImage(int index) { + /// <summary> + /// Returns the Image on the given position of the player's hotbar (Incentory.Hotbar) + /// Note: null values get the "blank" image + /// </summary> + public static Image GetPlayerHotbarImage(int index) { Image img = new Image("blank", IconSize.Dnd); if (index < MI.Player.Inventory.Hotbar.Length) { @@ -77,7 +91,11 @@ namespace Mundus.Service.SuperLayers { return img; } - public static Image GetInventoryItemImage(int index) { + /// <summary> + /// Returns the Image on the given position of the player's items inventory (Inventory.Items) + /// Note: null values get the "blank" image + /// </summary> + public static Image GetPlayerInventoryItemImage(int index) { Image img = new Image("blank", IconSize.Dnd); if (index < MI.Player.Inventory.Items.Length) { @@ -96,7 +114,11 @@ namespace Mundus.Service.SuperLayers { return img; } - public static Image GetAccessoryImage(int index) { + /// <summary> + /// Returns the Image on the given position of the player's accessories (Inventory.Accessories) + /// Note: null values get the "blank" image + /// </summary> + public static Image GetPlayerAccessoryImage(int index) { Image img = new Image("blank_gear", IconSize.Dnd); if (index < MI.Player.Inventory.Accessories.Length) { @@ -107,7 +129,11 @@ namespace Mundus.Service.SuperLayers { return img; } - public static Image GetGearImage(int index) { + /// <summary> + /// Returns the Image on the given position of the player's gear (Inventory.Gear) + /// Note: null values get the "blank" image + /// </summary> + public static Image GetPlayerGearImage(int index) { Image img = new Image("blank_gear", IconSize.Dnd); if (index < MI.Player.Inventory.Gear.Length) { diff --git a/Mundus/Views/Windows/CraftingWindow.cs b/Mundus/Views/Windows/CraftingWindow.cs index 6ee95c3..adf61f6 100644 --- a/Mundus/Views/Windows/CraftingWindow.cs +++ b/Mundus/Views/Windows/CraftingWindow.cs @@ -22,8 +22,7 @@ namespace Mundus.Views.Windows { /// </summary> public void Initialize() { Reset(); - CraftingController.FindAvalableItems(); - this.Recipes = CraftingController.GetAvalableRecipies(); + this.Recipes = CraftingController.GetAvalableRecipes(); recipeIndex = 0; PrintRecipe(); UpdateNextPrevBtns(); @@ -113,7 +112,7 @@ namespace Mundus.Views.Windows { protected void OnBtnCraftClicked(object sender, EventArgs e) { - CraftingController.CraftItem(Recipes[recipeIndex]); + CraftingController.CraftItemPlayer(Recipes[recipeIndex]); this.Hide(); } } diff --git a/Mundus/Views/Windows/MediumGameWindow.cs b/Mundus/Views/Windows/MediumGameWindow.cs index ef7dc13..a4c6321 100644 --- a/Mundus/Views/Windows/MediumGameWindow.cs +++ b/Mundus/Views/Windows/MediumGameWindow.cs @@ -189,7 +189,7 @@ namespace Mundus.Views.Windows { //Prints hotbar for (int i = 0; i < Size; i++) { - Image img = ImageController.GetHotbarImage(i); + Image img = ImageController.GetPlayerHotbarImage(i); switch (i) { case 0: btnH1.Image = img; break; @@ -209,7 +209,7 @@ namespace Mundus.Views.Windows { //Prints the "Ground layer" in map menu for (int row = Calculate.CalculateStartY(Size), maxY = Calculate.CalculateMaxY(Size), img = 1; row <= maxY; row++) { for (int col = Calculate.CalculateStartX(Size), maxX = Calculate.CalculateMaxX(Size); col <= maxX; col++, img++) { - string sName = ImageController.GetGroundImage(row, col).Stock; + string sName = ImageController.GetPlayerGroundImage(row, col).Stock; switch (img) { case 1: imgG1.SetFromStock(sName, IconSize.Dnd); break; @@ -272,7 +272,7 @@ namespace Mundus.Views.Windows { //Prints the "Item layer" in map menu for (int row = Calculate.CalculateStartY(Size), maxY = Calculate.CalculateMaxY(Size), img = 1; row <= maxY; row++) { for (int col = Calculate.CalculateStartX(Size), maxX = Calculate.CalculateMaxX(Size); col <= maxX; col++, img++) { - string sName = ImageController.GetStructureImage(row, col).Stock; + string sName = ImageController.GetPlayerStructureImage(row, col).Stock; switch (img) { case 1: imgI1.SetFromStock(sName, IconSize.Dnd); break; @@ -335,7 +335,7 @@ namespace Mundus.Views.Windows { //Prints the actual inventory (items) for (int row = 0; row < Size; row++) { for (int col = 0; col < Size; col++) { - Image img = ImageController.GetInventoryItemImage(row * Size + col); + Image img = ImageController.GetPlayerInventoryItemImage(row * Size + col); switch (row * Size + col + 1) { case 1: btnI1.Image = img; break; @@ -394,7 +394,7 @@ namespace Mundus.Views.Windows { //Prints accessories for (int row = 0; row < 2; row++) { for (int col = 0; col < Size; col++) { - Image img = ImageController.GetAccessoryImage(row * Size + col); + Image img = ImageController.GetPlayerAccessoryImage(row * Size + col); switch (row * Size + col + 1) { case 1: btnA1.Image = img; break; @@ -417,7 +417,7 @@ namespace Mundus.Views.Windows { //Prints gear for (int i = 0; i < Size; i++) { - Image img = ImageController.GetGearImage(i); + Image img = ImageController.GetPlayerGearImage(i); switch (i + 1) { case 1: btnG1.Image = img; break; diff --git a/Mundus/Views/Windows/SmallGameWindow.cs b/Mundus/Views/Windows/SmallGameWindow.cs index 5119600..41c7bdd 100644 --- a/Mundus/Views/Windows/SmallGameWindow.cs +++ b/Mundus/Views/Windows/SmallGameWindow.cs @@ -184,7 +184,7 @@ namespace Mundus.Views.Windows { //Prints hotbar for (int i = 0; i < Size; i++) { - Image img = ImageController.GetHotbarImage(i); + Image img = ImageController.GetPlayerHotbarImage(i); switch (i + 1) { case 1: btnH1.Image = img; break; @@ -202,7 +202,7 @@ namespace Mundus.Views.Windows { //Prints the "Ground layer" in map menu for (int row = Calculate.CalculateStartY(Size), maxY = Calculate.CalculateMaxY(Size), img = 1; row <= maxY; row++) { for (int col = Calculate.CalculateStartX(Size), maxX = Calculate.CalculateMaxX(Size); col <= maxX; col++, img++) { - string sName = ImageController.GetGroundImage(row, col).Stock; + string sName = ImageController.GetPlayerGroundImage(row, col).Stock; switch (img) { case 1: imgG1.SetFromStock(sName, IconSize.Dnd); break; @@ -241,7 +241,7 @@ namespace Mundus.Views.Windows { //Prints the "Item layer" in map menu for (int row = Calculate.CalculateStartY(Size), maxY = Calculate.CalculateMaxY(Size), img = 1; row <= maxY; row++) { for (int col = Calculate.CalculateStartX(Size), maxX = Calculate.CalculateMaxX(Size); col <= maxX; col++, img++) { - string sName = ImageController.GetStructureImage(row, col).Stock; + string sName = ImageController.GetPlayerStructureImage(row, col).Stock; switch (img) { case 1: imgI1.SetFromStock(sName, IconSize.Dnd); break; @@ -280,7 +280,7 @@ namespace Mundus.Views.Windows { //Prints the actual inventory (items) for (int row = 0; row < Size; row++) { for (int col = 0; col < Size; col++) { - Image img = ImageController.GetInventoryItemImage(row * Size + col); + Image img = ImageController.GetPlayerInventoryItemImage(row * Size + col); switch (row * Size + col + 1) { case 1: btnI1.Image = img; break; @@ -315,7 +315,7 @@ namespace Mundus.Views.Windows { //Prints accessories for (int row = 0; row < 2; row++) { for (int col = 0; col < Size; col++) { - Image img = ImageController.GetAccessoryImage(row * Size + col); + Image img = ImageController.GetPlayerAccessoryImage(row * Size + col); switch (row * Size + col + 1) { case 1: btnA1.Image = img; break; @@ -334,7 +334,7 @@ namespace Mundus.Views.Windows { //Prints gear for (int i = 0; i < Size; i++) { - Image img = ImageController.GetGearImage(i); + Image img = ImageController.GetPlayerGearImage(i); switch (i + 1) { case 1: btnG1.Image = img; break; |
