Skip to content

Commit

Permalink
more items
Browse files Browse the repository at this point in the history
  • Loading branch information
jossse69 committed Oct 7, 2023
1 parent d81cc98 commit 83ea292
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/Chest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ public static List<IItem> GenerateLoot(Map map)
var rng = new Random();
var loot = new List<IItem>();
var loottype = rng.Next(5);
if(loottype < 3)
if(loottype < 2)
{
for (var i = 0; i < rng.Next(1, 4); i++)
{
// 20% chance of a healing elixir, else its chance of a cooked beef.
if( rng.Next(100) <= 20)
{
//loot.Add(new IItem(new Info("healing elixir", "a healing elixir. smells sweetly."), ItemType.Consumable, ui, map, new Point(-1, -1)));
loot.Add(new items.consumables.healingelixir(ui, map));
} else
{
loot.Add(new items.consumables.cookedbeef(ui, map));
Expand Down Expand Up @@ -61,7 +61,7 @@ public static List<IItem> GenerateLoot(Map map)
}
else
{
//loot.Add(new IItem(new Info("sword", "a sword. a dagger, but longer."), ItemType.Mellee, ui, map, new Point(-1, -1)));
loot.Add(new items.Mellees.sword(ui, map));
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/Fighter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ public Fighter(int maxHP, int HP, int power, int defense, UI UI, monsterType typ
this.type = type;
}

public void takeDamage(int damage, int power)
public void takeDamage(int damage, int power, GameObject self, Map map)
{
var rng = new Random();
var dmg = Math.Max(rng.Next(damage - defense, damage * power), 0);

ui.SendMessage("did " + dmg + " physical damage.");
if (self.IsVisible(map)) ui.SendMessage("did " + dmg + " physical damage.");

if (dmg <= 0)
{
ui.SendMessage("It's very uneffective...");
if (self.IsVisible(map)) ui.SendMessage("It's very uneffective...");
}
else if (dmg > damage * 1.5)
{
ui.SendMessage("Critical Hit!");
if (self.IsVisible(map)) ui.SendMessage("Critical Hit!");
HP -= dmg;
}
else
Expand Down
6 changes: 4 additions & 2 deletions src/GameObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ public void MoveAndAttack(int dx, int dy, Map map, List<GameObject> objects)
// if the monster is not of same type, attack
if (obj.Fighter.type != Fighter.type)
{
if (IsVisible(map)){
UI.SendMessage(Info.name + " attacks!");
}
// see if its the player and what item he is holding
if (obj.Fighter.type != monsterType.player && Fighter.type == monsterType.player)
{
Expand All @@ -108,10 +110,10 @@ public void MoveAndAttack(int dx, int dy, Map map, List<GameObject> objects)
dmg = (int)item.GetType().GetMethod("WeaponAttack").Invoke(item, new object[] { obj });
}

obj.Fighter?.takeDamage(dmg, Fighter.power);
obj.Fighter?.takeDamage(dmg, Fighter.power, obj, map);
}
else{
obj.Fighter?.takeDamage(2, Fighter.power);
obj.Fighter?.takeDamage(2, Fighter.power, obj, map);
}

}
Expand Down
6 changes: 5 additions & 1 deletion src/ScreenContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ public ScreenContainer()

UI.playerinventory.Add(new items.Mellees.kitchenknife(UI, Instance.Map));
UI.playerinventory.Add(new items.consumables.bread(UI, Instance.Map));
UI.SendMessage("Welcome! this is a test message.");
UI.SendMessage("Welcome! climb up the tower to heaven!");
UI.SendMessage("But watch your step for evil things!");
UI.SendMessage("Get powerful weapons to defeat them.");
UI.SendMessage("Find friends to help you.");
UI.SendMessage("Get out of the void! heaven is waiting.");
UI.Draw(Player);

Children.Add(Map);
Expand Down
8 changes: 4 additions & 4 deletions src/items/consumables/healingelixir.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class healingelixir : IConsumableItem
{
public ItemType Type => ItemType.Consumable;

public Info Info => new Info("bread", "a loaf of bread, that's all.");
public Info Info => new Info("healing elixir", "a healing elixir, smells like stawberry.");

private GameObject ThisObject;
public GameObject? Object { get => ThisObject; set => ThisObject = value; }
Expand All @@ -19,10 +19,10 @@ public healingelixir(UI ui, IScreenSurface surface)

public void Use(UI ui, GameObject player)
{
ui.SendMessage("You eat the bread.");
ui.SendMessage("You drink the elixir. You feel better.");

// heal the player a little bit
player.Fighter.HP = Math.Min(player.Fighter.maxHP, player.Fighter.HP + 10);
// heal the player
player.Fighter.HP = player.Fighter.maxHP;

// destroy the object
ui.playerinventory.Remove(this);
Expand Down
33 changes: 33 additions & 0 deletions src/items/mellees/sword.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using MIST.AI;
using SadConsole;
using SadRogue.Primitives;

namespace MIST.items.Mellees
{
public class sword : IMelleeItem
{
public ItemType Type => ItemType.Mellee;

public Info Info => new Info("sword", "a dagger, but longer.");

private GameObject ThisObject;
public GameObject? Object { get => ThisObject; set => ThisObject = value; }

public int actioncost => 185;

public sword(UI ui, IScreenSurface surface)
{
ThisObject = new GameObject(new ColoredGlyph(Color.Orange, Color.Black, '/'), new Point(0, 0), surface, null, Info, null, ui);
}

public int CritWeaponAttack(GameObject target)
{
return 10;
}

public int WeaponAttack(GameObject target)
{
return 7;
}
}
}

0 comments on commit 83ea292

Please sign in to comment.