Skip to content

Commit

Permalink
skills
Browse files Browse the repository at this point in the history
  • Loading branch information
Görkem Seven committed Jun 23, 2023
1 parent 03abf2e commit 73ecb88
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 128 deletions.
34 changes: 24 additions & 10 deletions Abilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
namespace Rpg
{
[Serializable]
public class SkillBook
public class AbilityCollection
{
HashSet<Ability> skills;

public SkillBook()
Character user;
public AbilityCollection(Character character)
{
skills = new HashSet<Ability>();
user = character;
}

public bool TryToLearn(Ability skill)
Expand All @@ -23,6 +24,7 @@ public bool TryToLearn(Ability skill)
}
if (!skills.Contains(skill) && skill != null)
{
skill.source = user;
skills.Add(skill);
return true;
}
Expand All @@ -45,6 +47,18 @@ public Ability Find(string name)
}
return null;
}

public void Discard(Ability skill)
{
if (skills.Contains(skill))
skills.Remove(skill);
}
public void Discard(string skillName)
{
var skill = Find(skillName);
if (skill != null)
Discard(skill);
}
}

[Serializable]
Expand Down Expand Up @@ -72,7 +86,7 @@ public bool Perform(object targets)
return false;
}

protected abstract bool CheckRequirements();
public abstract bool CheckRequirements();
protected abstract void UseResources();
protected abstract void Effect(object target);
}
Expand All @@ -95,7 +109,7 @@ public static Ability Shock { get
}
public static Ability HardHit { get
{
var fb = new Skill( 10f, 2f,2f);
var fb = new Skill( 10f, 1f,1.25f);
fb.name = "Hard Hit";
return fb;
}
Expand All @@ -119,11 +133,11 @@ public Skill(float cost, float damageBonus, float damageFactor)
factor = damageFactor;
staminaCost = cost;
}
protected override bool CheckRequirements()
public override bool CheckRequirements()
{
if(source is Character character)
{
if (character.stats.stamina.energy > staminaCost)
if (character.stats.stamina.energy >= staminaCost)
return true;
}
return false;
Expand All @@ -137,8 +151,8 @@ protected override void Effect(object target)
{
if(target is Character trg)
{
var str = (source as Character).stats.strenght.level;
trg.ReceiveDamage(new Damage((str+power.level) * bonus * factor, Damage.Type.physical, source));
var str = (source as Character).stats.strenght.level + bonus + power.level;
trg.ReceiveDamage(new Damage(str * factor, Damage.Type.physical, source));
}
}
}
Expand All @@ -151,7 +165,7 @@ public class Spell : Ability
public float manaCost;


protected override bool CheckRequirements()
public override bool CheckRequirements()
{
if (source is Character character)
{
Expand Down
16 changes: 10 additions & 6 deletions Character.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ public class Character : Village.Object
public Stats stats { get; protected set; }
public Inventory inventory { get; protected set; }
public Equipments equipments { get; protected set; }
public SkillBook skills { get; protected set; }
public AbilityCollection skills { get; protected set; }

protected Character target;

public Character()
{
stats = new Stats(10f, 10f, 0f, 2, 1, 1);
stats = new Stats(8f, 10f, 0f, 2, 0, 0);
inventory = new Inventory();
equipments = new Equipments(this);
skills = new SkillBook();
skills = new AbilityCollection(this);
}

protected override void ExperienceSecond()
Expand All @@ -35,7 +35,7 @@ protected override void ExperienceSecond()

if (target != null)
{
if (Program.random.NextDouble() > 0.33f || !TryRandomSkill())
if(!TryRandomSkill())
Hit();
}
}
Expand Down Expand Up @@ -71,10 +71,14 @@ bool TryRandomSkill()
if (skillsList.Count > 0)
{
var selectedSkill = skillsList[Program.random.Next(0, skillsList.Count)];
if(selectedSkill.Perform(target))
if(selectedSkill.CheckRequirements())
{
village.AddToLog(name + " used " + selectedSkill.name);
stats.wisdom.ChangeExp(1f);
selectedSkill.Perform(target);
if (selectedSkill is Skill)
stats.agility.ChangeExp(1f);
else if (selectedSkill is Spell)
stats.wisdom.ChangeExp(1f);

return true;
}
Expand Down
144 changes: 43 additions & 101 deletions Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public void Help(SocketMessage sMessage)
Console.WriteLine("Helping the user");
}

//Character
[Summary("Shows player's information")]
public void Profile(SocketMessage sMessage)
{
Expand All @@ -71,15 +72,6 @@ public void Profile(SocketMessage sMessage)

sMessage.Channel.SendMessageAsync(null, false, embed);
}

[Summary("Shows event logs ")]
public void Logs(SocketMessage sMessage)
{
var character = Operations.GetCharacter(sMessage);

character?.village.SendLogs();
}

[Summary("(!SetName Juan Rick) Set your character's name (limited usage)")]
public void SetName(SocketMessage sMessage,List<string> names)
{
Expand All @@ -89,7 +81,7 @@ public void SetName(SocketMessage sMessage,List<string> names)
}


#region Interactions
//Enviroment Interaction
[Summary("(!Attack Evil Monster) Attacks target character ")]
public void Attack(SocketMessage sMessage,List<string> names)
{
Expand Down Expand Up @@ -124,81 +116,16 @@ public void Enviroment(SocketMessage sMessage)
}
sMessage.Channel.SendMessageAsync(null, false, builder.Build());
}
/*[Summary("Cuts some tree from forest. ")]
public void Timber(SocketMessage sMessage)
{
var character = Operations.GetCharacter(sMessage);
var pool=character?.village.GetPool();
foreach (var item in pool)
{
if(item is Forest)
{
var forest = item as Forest;
var wood = forest.Cut();
if (wood != null)
{
character.inventory.Add(wood);
sMessage.Channel.SendMessageAsync("Wood added to your inventory");
return;
}
}
}
sMessage.Channel.SendMessageAsync("There were no trees left");
}
[Summary("Try to mine ores at mountan mine. ")]
public void Mine(SocketMessage sMessage)
[Summary("Shows event logs ")]
public void Logs(SocketMessage sMessage)
{
var character = Operations.GetCharacter(sMessage);

var pool=character?.village.GetPool();
foreach (var item in pool)
{
if(item is Mine)
{
var mine = item as Mine;
var ore = mine.Dig();
if (ore != null)
{
character.inventory.Add(ore);
sMessage.Channel.SendMessageAsync(ore.name +" added to your inventory");
return;
}
}
}
sMessage.Channel.SendMessageAsync("There were no mine nearby");
character?.village.SendLogs();
}
*/
[Summary("'!Ability Name' to use ability ")]
public void Ability(SocketMessage sMessage, List<string> names)
{
if (names.Count < 2)//1 ability name, rest is target name
return;

var abilityName = names[0];

names.RemoveAt(0);

var targetName = Operations.CombineWords(names);
Character crc = Operations.GetCharacter(sMessage);
var target = Operations.FindObect(targetName,crc.village);
var abilty = crc.skills.Find(abilityName);

if (target != null && abilty !=null)
{
sMessage.Channel.SendMessageAsync("Using " + abilty.name + " on " + targetName);
abilty.Perform(target);
}
}
#endregion

#region Inventory
//INVENTORY
[Summary("(Equip Black Sword) Equip named item and discard already equiped one")]
public void Equip(SocketMessage sMessage, List<string> names)
{
Expand Down Expand Up @@ -249,7 +176,6 @@ public void Collect(SocketMessage sMessage, List<string> names)
else
sMessage.Channel.SendMessageAsync("Could not find " + eqpm);
}

[Summary("See what you got. ")]
public void Inventory(SocketMessage sMessage)
{
Expand All @@ -270,26 +196,6 @@ public void Inventory(SocketMessage sMessage)
}
sMessage.Channel.SendMessageAsync(null, false, embedBuilder.Build());
}
[Summary("See what you got. ")]
public void Abilities(SocketMessage sMessage)
{
var character = Operations.GetCharacter(sMessage);
var items = character.skills.GiveVirtualList();
var embedBuilder = new EmbedBuilder();
embedBuilder.Title = "Abilities";
for (int i = 0; i < items.Count; i++)
{
if (i % 2 == 0)
{
embedBuilder.Description += "\n " + "- " + items[i].name + " (" + items[i].power.level + ")";
}
else
{
embedBuilder.Description += " " + "- " + items[i].name + " (" + items[i].power.level + ")";
}
}
sMessage.Channel.SendMessageAsync(null, false, embedBuilder.Build());
}
[Summary("See what you can craft. ")]
public void Craftables(SocketMessage sMessage)
{
Expand Down Expand Up @@ -330,8 +236,44 @@ public void Craft(SocketMessage sMessage, List<string> names)

sMessage.Channel.SendMessageAsync("Could not find recipe for " + targetItem+ ", please check your craftables");
}
#endregion

//ABİLİTİES
[Summary("See what you got. ")]
public void Abilities(SocketMessage sMessage)
{
var character = Operations.GetCharacter(sMessage);
var items = character.skills.GiveVirtualList();
var embedBuilder = new EmbedBuilder();
embedBuilder.Title = "Abilities";
for (int i = 0; i < items.Count; i++)
{
if (i % 2 == 0)
{
embedBuilder.Description += "\n " + "- " + items[i].name + " (" + items[i].power.level + " level ("+items[i].power.exp+" exp))";
}
else
{
embedBuilder.Description += " " + "- " + items[i].name + " (" + items[i].power.level + " level (" + items[i].power.exp + " exp))";
}
}
sMessage.Channel.SendMessageAsync(null, false, embedBuilder.Build());
}
[Summary("Removes ability ")]
public void DiscardAbility(SocketMessage sMessage, List<string> names)
{
if (names.Count < 2)//1 ability name, rest is target name
return;

var targetName = Operations.CombineWords(names);
Character crc = Operations.GetCharacter(sMessage);
var abilty = crc.skills.Find(targetName);
if (abilty != null)
{
crc.skills.Discard(abilty);
sMessage.Channel.SendMessageAsync(abilty.name + " removed");
}

}

static class Operations
{
Expand Down
10 changes: 10 additions & 0 deletions Hero.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,21 @@ public class Mob : Character
{
public float dropChance = 0.99f;
public List<Item> drops = new List<Item>();
int lifeTime = 0;
public Mob(float hp, float sta, float mna, int str, int agi, int wis)
{
stats = new Stats(hp, sta, mna, str, agi, wis);
}

protected override void ExperienceSecond()
{
base.ExperienceSecond();
if (++lifeTime > 3600)
{
village.SendMessage(name + " left");
Destroy();
}
}

protected override void OnDeath()
{
Expand Down
10 changes: 10 additions & 0 deletions ItemGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ public static Item stone
return w;
}
}
public static Item meat
{
get
{
var w = new Item();
w.name = "Meat";
w.maxQuantity = 10;
return w;
}
}
public static Item Bow
{
get
Expand Down
2 changes: 2 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ static void Main(string[] args)
* Minigames:-fishing
*
scienario:
-player try to set up their character with first spawning easier mobs. They'll collect pendant or sword or bow.
-than player waits for stronger opponents to show up.
village enviroment
-Forest(x trees) //grows in number over time, can be cut down for wood resource, some wood might be collected without cutting trees, from falling branches
Expand Down
Loading

0 comments on commit 73ecb88

Please sign in to comment.