private bool LoadFromXML(XmlNode info) { bool success = true; string reason = ""; amount_ = new IntNull(); percent_ = new IntNull(); if (success) { success = XMLHelper.SetUniqueStringFromAttribute(info, ref itemType_, "value"); } if (success) { success = XMLHelper.SetUniqueIntFromAttribute(info, ref amount_, "amount"); } if (success) { success = XMLHelper.SetUniqueIntFromAttribute(info, ref percent_, "percent"); } if (!success) { Debug.LogError("Error loading result XML: " + reason + " " + info.OuterXml); } return(success); }
private bool LoadFromXML(XmlNode info) { bool success = true; string reason = ""; level_ = new IntNull(); minFailPercent_ = new IntNull(); if (success) { success = XMLHelper.SetUniqueStringFromAttribute(info, ref type_, "type"); } if (success) { success = XMLHelper.SetUniqueIntFromAttribute(info, ref level_, "level"); } if (success) { success = XMLHelper.SetUniqueIntFromAttribute(info, ref minFailPercent_, "min_fail_percent"); } if (!success) { Debug.LogError("Error loading result XML: " + reason); } return(success); }
// gets the actual weight of an event in preparation for spawn, and also increments weight values private int GetEventWeightForSpawn(GameEvent gameEvent) { Debug.Log ("GetEventWeightForSpawn: " + gameEvent.Id); int actualWeight = gameEvent.Weight.Value; IntNull weightPerTurn = gameEvent.WeightPerTurn; int maxWeight = int.MaxValue; int minWeight = int.MinValue; // if we're already keeping track of the weight, update it if (eventWeights_.ContainsKey (gameEvent.Id)) { actualWeight = eventWeights_ [gameEvent.Id]; if (weightPerTurn.Defined) { actualWeight += weightPerTurn.Value; } if (gameEvent.MaxWeight.Defined) { maxWeight = gameEvent.MaxWeight.Value; } if (gameEvent.MinWeight.Defined) { minWeight = gameEvent.MinWeight.Value; } actualWeight = Mathf.Clamp (actualWeight, minWeight, maxWeight); eventWeights_ [gameEvent.Id] = actualWeight; } else { // otherwise, just put it in the storage eventWeights_.Add (gameEvent.Id, actualWeight); } return actualWeight; }
public Item(string id) { id_ = id; amount_ = 0; turnCounter_ = 0; cap_ = new IntNull(); producePer_ = new IntNull(); turnsToProduce_ = new IntNull(); }
public static bool SetUniqueIntFromAttribute(XmlNode info, ref IntNull uniqueInt, string attributeName) { XmlAttribute xmlAttr = info.Attributes [attributeName]; if (xmlAttr == null) { return(true); } return(XMLHelper.SetUniqueInt(xmlAttr, ref uniqueInt, attributeName)); }
public IntNull GetItemCap(string itemName) { IntNull cap = new IntNull(); if (inventory_.ContainsKey(itemName)) { cap = inventory_ [itemName].Cap; } return(cap); }
public bool LoadFromXML(XmlNode info) { bool success = true; string reason = ""; amount_ = new IntNull(); percent_ = new IntNull(); XmlAttribute xmlAttr = info.Attributes ["type"]; if (xmlAttr != null) { string tempString = XMLHelper.FetchString(xmlAttr); if (tempString == "change") { type_ = WeightChangeType.Change; } else if (tempString == "set") { type_ = WeightChangeType.Set; } else { success = false; reason = "invalid type tag: '" + tempString + "', was looking for (change, set)"; } } else { success = false; reason = "did not specify type tag, was looking for (change, set)"; } if (success) { success = XMLHelper.SetUniqueIntFromAttribute(info, ref amount_, "amount"); } if (success) { success = XMLHelper.SetUniqueIntFromAttribute(info, ref percent_, "percent"); } if (!success) { Debug.LogError("Error loading weight change XML: " + reason + " " + info.OuterXml); } return(success); }
public static bool SetUniqueInt(XmlAttribute xmlAttr, ref IntNull uniqueInt, string name) { if (uniqueInt == null) { uniqueInt = new IntNull(Int32.Parse(xmlAttr.Value)); return(true); } else if (!uniqueInt.Defined) { uniqueInt.Value = Int32.Parse(xmlAttr.Value); return(true); } else { Debug.LogError("found multiple instances of <" + name + ">" + xmlAttr.OuterXml); return(false); } }
public void PerformChallengeSetResult() { lastResult_ = null; lastChallengeString_ = ""; bool success = true; bool crit = true; if (challenges_ != null) { string challengeString = ""; if (challenges_.Count > 0) { challengeString = "["; } bool first = true; foreach (Challenge challenge in challenges_) { string type = challenge.Type; IntNull level = challenge.Level; int levelVal = 0; if (level.Defined) { levelVal = level.Value; } // TODO: implement min fail percent IntNull minFail = challenge.MinFailPercent; int itemAmount = ItemManager.Instance.GetItemAmount(type); int diceResult = UnityEngine.Random.Range(1, 6) + UnityEngine.Random.Range(1, 6) + itemAmount - levelVal; if (diceResult <= 2) { success = false; crit = true && crit; } else if (diceResult <= 6) { success = false; crit = false; } else if (diceResult <= 9) { success = true && success; crit = false; } else { success = true && success; crit = true && crit; } if (!first) { challengeString += ", "; } challengeString += type; first = false; } //crit = true; if (challenges_.Count > 0) { challengeString += "]"; } if (challenges_.Count > 0) { if (crit) { if ((success && resultSuccessCrit_ != null) || (!success && resultFailureCrit_ != null)) { lastChallengeString_ = "Critical "; } } if (success) { lastChallengeString_ += "Success"; } else { lastChallengeString_ += "Miss"; } lastChallengeString_ += " " + challengeString; } } if (success) { if (crit && resultSuccessCrit_ != null) { lastResult_ = resultSuccessCrit_; } else if (resultSuccess_ != null) { lastResult_ = resultSuccess_; } else { lastResult_ = resultAny_; } } else { if (crit && resultFailureCrit_ != null) { lastResult_ = resultFailureCrit_; } else if (resultFailure_ != null) { lastResult_ = resultFailure_; } else { lastResult_ = resultAny_; } } }
private void LoadFromXML(XmlNode eventInfo) { bool success = true; string reason = ""; weight_ = new IntNull(); weightPerTurn_ = new IntNull(); weightPerTurnPercent_ = new IntNull(); minWeight_ = new IntNull(); maxWeight_ = new IntNull(); // grab the id for the event if it exists XmlAttribute xmlAttr = eventInfo.Attributes ["id"]; if (xmlAttr != null) { id_ = xmlAttr.Value; } XmlNodeList content = eventInfo.ChildNodes; foreach (XmlNode xmlItem in content) { // load the basic info of an event if (xmlItem.Name == "name") { success = XMLHelper.SetUniqueString(xmlItem, ref name_, "name"); } else if (xmlItem.Name == "desc") { success = XMLHelper.SetUniqueString(xmlItem, ref desc_, "desc"); } else if (xmlItem.Name == "image") { success = XMLHelper.SetUniqueString(xmlItem, ref imageName_, "image"); } else if (xmlItem.Name == "triggers") { success = XMLHelper.LoadXmlList(xmlItem, ref triggers_, "triggers", "trigger", id_); } else if (xmlItem.Name == "only_once") { occurOnlyOnce_ = XMLHelper.FetchBool(xmlItem); } else if (xmlItem.Name == "mandatory") { mandatory_ = XMLHelper.FetchBool(xmlItem); } else if (xmlItem.Name == "weight") { weight_ = XMLHelper.FetchIntNull(xmlItem); } else if (xmlItem.Name == "min_weight") { minWeight_ = XMLHelper.FetchIntNull(xmlItem); } else if (xmlItem.Name == "max_weight") { maxWeight_ = XMLHelper.FetchIntNull(xmlItem); } else if (xmlItem.Name == "listeners") { success = XMLHelper.LoadXmlList(xmlItem, ref listeners_, "listeners", "listener", id_); } else if (xmlItem.Name == "weight_per_turn") { weightPerTurn_ = XMLHelper.FetchIntNull(xmlItem); } else if (xmlItem.Name == "weight_per_turn_percent") { weightPerTurn_ = XMLHelper.FetchIntNull(xmlItem); } else if (xmlItem.Name == "choices") { success = LoadChoicesFromXML(xmlItem); } if (!success) { break; } } if (!success) { Debug.LogError("Error loading XML for " + id_ + ": " + reason); } }
public bool LoadGame(string filename) { Debug.Log("Loading game: " + filename); if (!File.Exists(filename)) { Debug.LogError("File to load not found: " + filename); return(false); } FileStream file = File.Open(filename, FileMode.Open, FileAccess.Read); StreamReader reader = new StreamReader(file); string line = ""; bool readingNumTurns = false; bool readingFlags = false; bool readingNames = false; bool readingCompletedEvents = false; bool readingNeverSpawnEvents = false; bool readingInventory = false; bool readingSleepingEvents = false; bool readingEventWeights = false; GameEventManager.Instance.ResetSave(); ItemManager.Instance.ResetSave(); // TODO, this is the WORST. Make it better. while ((line = reader.ReadLine()) != null) { if (line.Equals("[numturns]")) { readingNumTurns = true; readingFlags = false; readingNames = false; readingCompletedEvents = false; readingNeverSpawnEvents = false; readingInventory = false; readingSleepingEvents = false; readingEventWeights = false; } else if (line.Equals("[flags]")) { readingNumTurns = false; readingFlags = true; readingNames = false; readingCompletedEvents = false; readingNeverSpawnEvents = false; readingInventory = false; readingSleepingEvents = false; readingEventWeights = false; } else if (line.Equals("[namebank]")) { readingNumTurns = false; readingFlags = false; readingNames = true; readingCompletedEvents = false; readingNeverSpawnEvents = false; readingInventory = false; readingSleepingEvents = false; readingEventWeights = false; } else if (line.Equals("[completedEventIDs]")) { readingNumTurns = false; readingFlags = false; readingNames = false; readingCompletedEvents = true; readingNeverSpawnEvents = false; readingInventory = false; readingSleepingEvents = false; readingEventWeights = false; } else if (line.Equals("[neverSpawnEventIDs]")) { readingNumTurns = false; readingFlags = false; readingNames = false; readingCompletedEvents = false; readingNeverSpawnEvents = true; readingInventory = false; readingSleepingEvents = false; readingEventWeights = false; } else if (line.Equals("[sleepingEventIDs]")) { readingNumTurns = false; readingFlags = false; readingNames = false; readingCompletedEvents = false; readingNeverSpawnEvents = false; readingInventory = false; readingSleepingEvents = true; readingEventWeights = false; } else if (line.Equals("[inventory]")) { readingNumTurns = false; readingFlags = false; readingNames = false; readingCompletedEvents = false; readingNeverSpawnEvents = false; readingInventory = true; readingSleepingEvents = false; readingEventWeights = false; } else if (line.Equals("[eventWeights]")) { readingNumTurns = false; readingFlags = false; readingNames = false; readingCompletedEvents = false; readingNeverSpawnEvents = false; readingInventory = false; readingSleepingEvents = false; readingEventWeights = true; } else { if (readingNumTurns) { GameEventManager.Instance.SetNumTurns(int.Parse(line)); } else if (readingFlags) { GameEventManager.Instance.SetFlag(line); } else if (readingNames) { string name = reader.ReadLine(); GameEventManager.Instance.SetName(line, name); } else if (readingCompletedEvents) { GameEventManager.Instance.SetEventIDCompleted(line); } else if (readingNeverSpawnEvents) { GameEventManager.Instance.NeverSpawnEventID(line); } else if (readingSleepingEvents) { string temp = reader.ReadLine(); //Debug.LogError ("SLEEP EVENTTTTTTTTTTTTTTTTTTTT: " + temp); int amount = int.Parse(temp); GameEventManager.Instance.SleepEventID(line, amount); } else if (readingEventWeights) { int weight = int.Parse(reader.ReadLine()); GameEventManager.Instance.SetEventWeight(line, weight); } else if (readingInventory) { //Debug.LogWarning ("READING INVENTORYYUUUUUUUUUUUUUUUUUUUUU"); Item temp = new Item(line); string itemType = line; int amount = int.Parse(reader.ReadLine()); //Debug.LogWarning (itemType + " : " + amount); bool defined = reader.ReadLine() == "True"; int value = int.Parse(reader.ReadLine()); IntNull cap = new IntNull(value, defined); defined = reader.ReadLine() == "True"; value = int.Parse(reader.ReadLine()); IntNull producePer = new IntNull(value, defined); defined = reader.ReadLine() == "True"; value = int.Parse(reader.ReadLine()); IntNull turnsToProduce = new IntNull(value, defined); int turnCounter = int.Parse(reader.ReadLine()); temp.Cap = cap; temp.ProducePer = producePer; temp.TurnsToProduce = turnsToProduce; temp.TurnCounter = turnCounter; temp.Amount = amount; ItemManager.Instance.SetInventoryItem(itemType, temp); } } } reader.Close(); GameController.Instance.GameLoaded(); return(true); }
private void LoadFromXML(XmlNode info) { bool success = true; string reason = ""; sleepFor_ = new IntNull(); effects_ = new List <ResultEffect> (); XmlAttribute xmlAttr = info.Attributes ["type"]; if (xmlAttr != null) { string tempString = XMLHelper.FetchString(xmlAttr); if (tempString == "success") { type_ = ResultType.Success; } else if (tempString == "failure") { type_ = ResultType.Failure; } else if (tempString == "success_crit") { type_ = ResultType.SuccessCrit; } else if (tempString == "failure_crit") { type_ = ResultType.FailureCrit; } else if (tempString == "any") { type_ = ResultType.Any; } else { success = false; reason = "invalid type tag: '" + tempString + "', was looking for (success, failure, failure_crit, success_crit, any, or blank)"; } } else { type_ = ResultType.Any; } xmlAttr = info.Attributes ["id"]; if (xmlAttr != null) { id_ = XMLHelper.FetchString(xmlAttr); } if (success) { XmlNodeList content = info.ChildNodes; foreach (XmlNode xmlItem in content) { if (xmlItem.Name == "desc") { if (desc_ == null) { desc_ = xmlItem.InnerText; } else { success = false; reason = "found multiple instances of <desc>"; } } else if (xmlItem.Name == "weight") { weightChange_ = new WeightChange(xmlItem); } else if (xmlItem.Name == "never_again") { neverAgain_ = XMLHelper.FetchBool(xmlItem); } else if (xmlItem.Name == "sleep_for") { IntNull temp = XMLHelper.FetchIntNull(xmlItem); if (temp.Value < 0) { success = false; reason = "invalid value for sleep_for. negative numbers not valid"; } else { sleepFor_ = temp; } } else if (xmlItem.Name == "effect") { effects_.Add(new ResultEffect(xmlItem)); } else { success = false; reason = "invalid tag found for result: " + xmlItem.Name + ", was expecting desc, weight_inc, weight_set, never_again, effect"; } if (!success) { break; } } } if (!success) { Debug.LogError("Error loading result XML: " + reason); } }
private void LoadFromXML(XmlNode info) { bool success = true; string reason = ""; amount_ = new IntNull(); lessThan_ = new IntNull(); XmlAttribute xmlAttr = info.Attributes ["logic"]; if (xmlAttr != null) { string tempString = XMLHelper.FetchString(xmlAttr); if (tempString == "and") { logic_ = TriggerLogic.AND; } else if (tempString == "or") { logic_ = TriggerLogic.OR; } else if (tempString == "not") { logic_ = TriggerLogic.NOT; } else if (tempString == "notand") { logic_ = TriggerLogic.NOTAND; } else if (tempString == "notor") { logic_ = TriggerLogic.NOTOR; } else { success = false; reason = "invalid logic tag: '" + tempString + "', was looking for (and, or, not)"; } } else { logic_ = TriggerLogic.AND; } if (success) { xmlAttr = info.Attributes ["type"]; if (xmlAttr != null) { string tempString = XMLHelper.FetchString(xmlAttr); if (tempString == "flag") { type_ = TriggerType.Flag; } else if (tempString == "artifact") { type_ = TriggerType.Artifact; } else if (tempString == "item") { type_ = TriggerType.Item; } else if (tempString == "event") { type_ = TriggerType.Item; } else if (tempString == "itemcap") { type_ = TriggerType.ItemCap; } else if (tempString == "turns") { type_ = TriggerType.Turns; } else if (tempString == "produceamount") { type_ = TriggerType.ProduceAmount; } else { success = false; reason = "invalid type tag found in trigger: '" + tempString + "'"; } } else { type_ = TriggerType.Event; } } if (success) { success = XMLHelper.SetUniqueStringFromAttribute(info, ref value_, "value"); } if (success) { success = XMLHelper.SetUniqueIntFromAttribute(info, ref amount_, "amount"); } if (success) { success = XMLHelper.SetUniqueIntFromAttribute(info, ref lessThan_, "less_than"); } if (success) { success = XMLHelper.SetUniqueIntFromAttribute(info, ref amount_, "greater_than"); } if (!success) { Debug.LogError("Error loading trigger XML: " + reason + " " + info.OuterXml); } }
public bool Triggered() { //Debug.LogError ("Checking triggered for : " + type_); switch (type_) { case TriggerType.Artifact: // TODO break; case TriggerType.Event: //Debug.LogError ("Checking if " + value_ + " is triggered"); //Debug.LogError (GameEventManager.Instance.IsEventCompleted (value_)); if (value_ != null) { return(GameEventManager.Instance.IsEventCompleted(value_)); } else { //Debug.LogError ("Tried to check event trigger, but no event id defined"); } break; case TriggerType.Flag: //Debug.LogError ("Checking flag: " + value_); return(GameEventManager.Instance.IsFlagSet(value_)); case TriggerType.Item: //Debug.LogError ("Checking item: " + value_); int inventoryAmount = ItemManager.Instance.GetItemAmount(value_); if (amount_.Defined) { //Debug.LogError (inventoryAmount + " >= " + amount_.Value); return(inventoryAmount >= amount_.Value); } else if (lessThan_.Defined) { //Debug.LogError (inventoryAmount + " < " + lessThan_.Value); return(inventoryAmount < lessThan_.Value); } break; case TriggerType.ItemCap: IntNull inventoryCap = ItemManager.Instance.GetItemCap(value_); if (inventoryCap.Defined && amount_.Defined) { return(inventoryCap.Value >= amount_.Value); } else if (inventoryCap.Defined && lessThan_.Defined) { return(inventoryCap.Value < lessThan_.Value); } break; case TriggerType.ProduceAmount: //Debug.LogError ("Checking Produce Amount"); Item item = ItemManager.Instance.GetItem(value_); int produceAmount = 0; if (item != null) { //Debug.LogError ("Found item"); IntNull producer = item.ProducePer; if (producer.Defined) { produceAmount = producer.Value; //Debug.LogError ("Found producer: " + produceAmount); } } if (amount_.Defined) { //Debug.LogError ("amount: " + produceAmount + " >= " + amount_.Value); return(produceAmount >= amount_.Value); } else if (lessThan_.Defined) { //Debug.LogError ("lessThan: " + produceAmount + " < " + lessThan_.Value); return(produceAmount < lessThan_.Value); } break; case TriggerType.Turns: int turns = GameEventManager.Instance.NumTurns(); if (amount_.Defined) { return(turns >= amount_.Value); } else if (lessThan_.Defined) { return(turns < amount_.Value); } break; } return(true); }