Hello (sorry for the english)
I try to create an RPG game for fun.
I start a new project to begin with good roots.
For now I have an object the CharacteresModel, I will use this model to create Player(s) and Ennemies.
It contains 3 others objecct : Level, Health and Mana.
Each of this object contains their own methode to Get,Set,Increase,Decrease, …
Where I block now his to do event cross object.
For exemple a player level up I want his health and mana to level as well.
I kwon how use event and to do this is simple, but the probleme is all the other caracter will listen to the same event, and will react the same way, obviously I don’t want went an Player level up than the ennemies do tthe same.
Thee only way I find is went I intantiate my Level object I Give my CharacteresModel (this) as parameter and send him in the event as argument and in the listener I have a :
if (sender.Equals(this))
Where sender is the object send by the event (here the CharacteresModel I give to the level object)
It work but I find this I bit heavy and dirty (peraphs I am wrong).
By question his ; There is a better way ? can we get the object CharacteresModel directly from the Level ? Peraphs we there is an option in the event I dont kown about or an other solution witout the event ?
Here my class (I try on the Health not the level but it should work the same) :
public class CharacteresModel
{
public string charactereName;
public Level lvl;
public Health health;
public Mana mana;
public CharacteresModel()
{
lvl = new Level(1);
health = new Health(10, this);
mana = new Mana(10);
StatutSystemEvents.OnHealthChange += THealth;
StatutSystemEvents.OnTest += Test;
}
public void THealth()
{
Debug.Log("THealth " + charactereName + " " + health.HP);
}
public void Test(object sender)
{
if (sender.Equals(this))
{
Debug.Log("Test " + charactereName + " " + health.HP);
}
}
}