all repos — RPG @ 47a62e6ce978749f6f26f705791d7168abdd28ed

Fully functional 3D turn based role playing game coded in C# and base Unity.

better party management
Marco Andronaco andronacomarco@gmail.com
Wed, 15 Apr 2020 16:58:07 +0200
commit

47a62e6ce978749f6f26f705791d7168abdd28ed

parent

52fdf8201f67d07e007b532c35ef7d502843d4d5

1 files changed, 27 insertions(+), 24 deletions(-)

jump to
M Assets/Scripts/Utility/GameMaster.csAssets/Scripts/Utility/GameMaster.cs

@@ -1,14 +1,11 @@

using System; -using System.Collections; using System.Collections.Generic; -using System.IO; -using System.Runtime.Serialization.Formatters.Binary; using UnityEngine; using UnityEngine.SceneManagement; public class GameMaster : Singleton<GameMaster> { - #region Pubblica + #region Public private Dictionary<string, Stats> party; public List<Stats> Party {

@@ -26,7 +23,9 @@

[Header("Inventory")] public int gold = 0; public Inventory inventory; + public bool loaded = false; + public int currentLevel = 0; #endregion #region Private private float timer;

@@ -37,9 +36,6 @@ private string fighting = "";

private string enemyType; private Vector3 lastPosition; private Quaternion lastRotation; - public bool loaded = false; - - public int currentLevel = 0; private string[] partyNames = { "Paladin", "Archer", "Boxer", "Mage" }; private List<string> bossNames = new List<string>{ "Brady", "Ganfaul" };

@@ -51,14 +47,7 @@ {

//start timer timer = 0; - //create party - party = new Dictionary<string, Stats>(); - - //add members - foreach(string st in partyNames) - { - addToParty(st); - } + initParty(partyNames); //create inventory inventory = new Inventory();

@@ -131,6 +120,7 @@ #region Inizio battaglia

case "Battle": break; #endregion + #region Battaglia vinta o ritorno all'overworld case "Level0": case "Level1":

@@ -155,6 +145,7 @@ }

player.transform.SetPositionAndRotation(lastPosition, lastRotation); break; #endregion + #region Battaglia persa case "Menu":

@@ -163,6 +154,7 @@ case "GameOver":

break; #endregion + #region Altro default: break;

@@ -179,13 +171,28 @@ }

#endregion #region Party Management - public void addToParty(string name) + private void initParty(string[] names){ + party = new Dictionary<string, Stats>(); + foreach(string s in names) + { + addToParty(s); + } + } + public bool addToParty(string name) { - party.Add(name, new Stats(name)); + if(!party.ContainsKey(name)){ + party.Add(name, new Stats(name)); + return true; + } + return false; } - public void removeFromParty(string name) + public bool removeFromParty(string name) { - party.Remove(name); + if(party.ContainsKey(name)){ + party.Remove(name); + return true; + } + return false; } #endregion

@@ -233,11 +240,7 @@ loaded = false;

currentLevel = 0; killedEnemies = new List<string>(); gold = 0; - party = new Dictionary<string, Stats>(); - foreach(string s in partyNames) - { - party.Add(s, new Stats(s)); - } + initParty(partyNames); inventory = new Inventory(); fighting = ""; timer = 0;