public IEnumerator ConvertDataToLaws(uint id) { string data; //r.Data.TryGetValue(id, out data); // Add some laws for debugging - ToDo: Store in an extra file. //data = "4:10|2,5:6|1?spawnenemy;1:0|0?spawnenemy"; // Who: Player, Destroyed_Asteroids > 0 => Spawnasteroids();" // Law: All players destroyed data = "100:0|0?gameover"; // Law: All strange folks destroyed data += ";105:0|0?gamewon"; // Law: All rebels destroyed data += ";106:0|0?gamewon"; // Law: Player attacks player data += ";0:0|0,10:0|2?stopattackingyourfriends"; Debug.Log("Law Collection contains already " + LawManager.collection.Count + " laws."); string[] laws = data.Split(';'); // For each law found in the string foreach (string law in laws) { Law l = new Law(); string[] criteriaResponse = law.Split('?'); if (criteriaResponse[1] != "null") l.response = criteriaResponse[1]; string[] criteria = criteriaResponse[0].Split(','); // And each criteria found that way foreach (string c in criteria) { string[] keyValue = c.Split(':'); string[] valueCompare = keyValue[1].Split('|'); uint key = uint.MaxValue, compareType = uint.MaxValue; int value = int.MaxValue; // Convert the values key = Convert.ToUInt32(keyValue[0]); value = Convert.ToInt32(valueCompare[0]); compareType = Convert.ToUInt32(valueCompare[1]); if ((key == uint.MaxValue) || (value == int.MaxValue) || (compareType == uint.MaxValue)) Console.WriteLine("ERROR (Law): Input string is not a sequence of digits."); // And add them as criteria l.AddCriteria(key, value, compareType); } yield return null; //LawManager.collection.Add(l); } Debug.Log(LawManager.collection.Count + " new Laws added!"); yield break; }
public static void RemoveLaw(Law law) { collection.Remove(law); DeleteFromDatabase(); }
public static bool ContainsLaw(Law law) { return collection.Contains(law); }
public static void LoadAllFromDatabase() { //try //{ /*Dictionary<string, string> param = new Dictionary<string, string>(); uint freeID = r.LastRequestID + 1; r.POST(param, freeID, ConvertDataToLaws(freeID));*/ // ... Law dummy = new Law(true); //StartCoroutine(dummy.ConvertDataToLaws(0)); //freeID Coroutiner.StartCoroutine(dummy.ConvertDataToLaws(0)); //} //catch (Exception e) //{ // Debug.LogError ("Exception: " + e.ToString()); //} }