Skip to content

Commit

Permalink
item system done
Browse files Browse the repository at this point in the history
  • Loading branch information
jossse69 committed Sep 26, 2023
1 parent 5c6bbf4 commit 63f3aa8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
8 changes: 5 additions & 3 deletions src/Chest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ namespace MIST;

public class Chest : GameObject
{
private static UI ui;
public List<Item> loot= new List<Item>();

public bool open = false;
public Chest(Point position, IScreenSurface surface, Info info, UI ui, Map map) : base(new ColoredGlyph(Color.Brown, Color.Black, 234), position, surface, null, info, null, ui)
public Chest(Point position, IScreenSurface surface, Info info, UI UI) : base(new ColoredGlyph(Color.Brown, Color.Black, 234), position, surface, null, info, null, ui)
{
loot = GenerateLoot(ui, map);
loot = new List<Item>();
ui = UI;
}

public List<Item> GenerateLoot(UI ui, Map map)
public static List<Item> GenerateLoot(Map map)
{
// fill with 3-4 Consumables, 1-2 Ranged, 1-2 Melee, 1-2 Books
var rng = new Random();
Expand Down
5 changes: 3 additions & 2 deletions src/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,11 @@ public static Map GenerateMap(int width, int height, List<GameObject> objects, U
{
map.CreateMonster(map, room, ui);

// small change to swant a chest with loot
// small chance to swant a chest with loot
if (random.Next(2) == 0)
{
var chest = new Chest(new Point(room.X + room.Width / 2, room.Y + room.Height / 2), map, new Info("Chest", "A brown wooden chest, has loot!"), ScreenContainer.Instance.UI, map);
var chest = new Chest(new Point(room.X + room.Width / 2, room.Y + room.Height / 2), map, new Info("Chest", "A brown wooden chest, has loot!"), ui);
chest.loot = Chest.GenerateLoot(map);
chests.Add(chest);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/UI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,15 @@ public void ReciveDirection(int x, int y, GameObject player)
{
SendMessage("'" + item.Object?.Info.name +"'");
playerinventory.Add(item);
chest.open = true;
break;
}
}
else
{
SendMessage("oops... nothing here...");
}

chest.open = true;
chest.Appearance = new ColoredGlyph(Color.SaddleBrown, Color.Black, 251);
inaction = "none";
state = "none";
ingame = true;
Expand Down
2 changes: 1 addition & 1 deletion src/items/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public class Item
public ItemType type;

public Info info;

public UI UI;
private static ColoredGlyph itemappearance = new ColoredGlyph(Color.Orange, Color.Black, '*');

Expand All @@ -18,6 +17,7 @@ public Item(Info Info, ItemType Type, UI ui, IScreenSurface map, Point position)
{
type = Type;
info = Info;
UI = ui;

if (type == ItemType.Consumable)
{
Expand Down

0 comments on commit 63f3aa8

Please sign in to comment.