Ejemplo n.º 1
0
 public static IReward[] XMLStringToActiveRewards(string xml)
 {
     FastList<IReward> rewards = new FastList<IReward> ();
     XmlDocument doc = new XmlDocument ();
     doc.LoadXml (xml);
     foreach (XmlNode rewardNode in doc.SelectNodes("boost")) {
         XmlAttributeCollection atts = rewardNode.Attributes;
         Boost b = new Boost();
         b.ValueID = Data.StringToValueID(atts ["name"].Value);
         b.Value = float.Parse(atts ["value"].Value);
         if (atts ["endDate"] != null) {
             b.EndDate = DateTime.Parse (atts ["endDate"].Value);
         }
         b.Activate ();
         rewards.Add (b);
     }
     return rewards.ToArray ();
 }
Ejemplo n.º 2
0
 public static XmlElement BoostToXmlElement(Boost boost, XmlDocument doc)
 {
     XmlElement boostElem = doc.CreateElement("boost");
     boostElem.SetAttribute ("name", boost.ValueID.ToString());
     boostElem.SetAttribute ("value", boost.Value.ToString());
     if (!boost.isForever) {
         boostElem.SetAttribute ("years", boost.Years.ToString());
         boostElem.SetAttribute ("months", boost.Months.ToString());
     }
     return boostElem;
 }
Ejemplo n.º 3
0
        public static Challenge ChallengeNodeToChallenge(XmlNode challengeNode, bool loadStates)
        {
            XmlAttributeCollection challengeAtts = challengeNode.Attributes;
            FastList<IGoal> goalsToAdd = new FastList<IGoal> ();
            FastList<IReward> rewardsToAdd = new FastList<IReward> ();
            FastList<IReward> penaltiesToAdd = new FastList<IReward> ();

            int years = -1, months = -1;
            foreach (XmlNode node in challengeNode.ChildNodes) {
                //Debug.PrintMessage(node.Name);
                if (node.Name == "goal") {
                    string name = node.Attributes ["name"].Value;
                    float passValue = float.Parse (node.Attributes ["passValue"].Value);
                    float failValue = float.Parse (node.Attributes ["failValue"].Value);
                    NumericalGoal goal = new NumericalGoal (StringToValueID (name), GoalTypeExtension.FromComparison (failValue, passValue), failValue, passValue);
                    if (node.Attributes ["passOnce"] != null) {
                        goal.PassOnce = bool.Parse (node.Attributes ["passOnce"].Value);
                    }
                    if (node.Attributes ["failOnce"] != null) {
                        goal.FailOnce = bool.Parse (node.Attributes ["failOnce"].Value);
                    }
                    if (loadStates && node.Attributes["hasAlreadyFailed"] != null) {
                        goal.HasAlreadyFailed = bool.Parse(node.Attributes ["hasAlreadyFailed"].Value);
                    }
                    if (loadStates && node.Attributes["hasAlreadyPassed"] != null) {
                        goal.HasAlreadyPassed = bool.Parse(node.Attributes ["hasAlreadyPassed"].Value);
                    }
                    goalsToAdd.Add (goal);
                } else if (node.Name == "deadline") {
                    if (node.Attributes ["years"] != null)
                        years = int.Parse (node.Attributes ["years"].Value);
                    if (node.Attributes ["months"] != null)
                        months = int.Parse (node.Attributes ["months"].Value);

                } else if (node.Name == "reward") {
                    foreach (XmlNode rewardNode in node.ChildNodes) {
                        if (rewardNode.Name == "boost") {
                            Boost newBoost = new Boost ();
                            newBoost.ValueID = Data.StringToValueID(rewardNode.Attributes ["name"].Value);
                            newBoost.Value = float.Parse (rewardNode.Attributes ["value"].Value);

                            if (rewardNode.Attributes ["years"] != null){
                                newBoost.Years = int.Parse (rewardNode.Attributes ["years"].Value);
                            }
                            if (rewardNode.Attributes ["months"] != null){
                                newBoost.Months = int.Parse (rewardNode.Attributes ["months"].Value);
                            }
                            rewardsToAdd.Add (newBoost);
                        } else if (rewardNode.Name == "payment") {
                            rewardsToAdd.Add(new Payment (int.Parse (rewardNode.Attributes ["amount"].Value)));
                        }
                    }
                } else if (node.Name == "penalty") {
                    foreach (XmlNode rewardNode in node.ChildNodes) {
                        if (rewardNode.Name == "payment") {
                            penaltiesToAdd.Add(new Payment (int.Parse(rewardNode.Attributes ["amount"].Value)));
                        }
                    }
                }
            }
            Challenge newChallenge = new Challenge (challengeAtts ["name"].Value, challengeAtts ["desc"].Value, goalsToAdd.ToArray (), rewardsToAdd.ToArray(), penaltiesToAdd.ToArray());
            //Debug.PrintMessage(challengeNode.OuterXml);
            if (challengeAtts ["requires"] != null) {
                newChallenge.PassTolerance = int.Parse (challengeAtts ["requires"].Value);
            }
            if (challengeAtts ["failTolerance"] != null) {
                newChallenge.FailTolerance = int.Parse (challengeAtts ["failTolerance"].Value);
            }
            if (loadStates && challengeAtts ["startDate"] != null) {
                newChallenge.MapStartTime = DateTime.Parse (challengeAtts ["startDate"].Value);
            }
            if (years >= 0) {
                newChallenge.Years = years;
            }
            if (months >= 0) {
                newChallenge.Months = months;
            }
            return newChallenge;
        }