public static XmlElement buildScoreDOM(Completable.Score score) { XmlElement progressNode = Writer.GetDoc().CreateElement("score"); progressNode.SetAttribute("type", score.getType().ToString()); progressNode.SetAttribute("method", score.getMethod().ToString()); if (score.getMethod() == Completable.Score.ScoreMethod.SINGLE) { progressNode.SetAttribute("id", score.getId()); } else { XmlElement subScores = Writer.GetDoc().CreateElement("sub-scores"); foreach (Completable.Score s in score.getSubScores()) { subScores.AppendChild(CompletableDOMWriter.buildScoreDOM(s)); } progressNode.AppendChild(subScores); } return(progressNode); }
private float CalculateScore(Completable.Score completableScore) { float score = 0; switch (completableScore.getMethod()) { // Base case (calculated based on target) case Completable.Score.ScoreMethod.SINGLE: var targetId = completableScore.getId(); switch (completableScore.getType()) { case Completable.Score.ScoreType.VARIABLE: // In case of variable type, the target id points to a variable var variableValue = Game.Instance.GameState.GetVariable(targetId); score = variableValue; break; case Completable.Score.ScoreType.COMPLETABLE: // In case of completable type, the target id points to a completable var referencedCompletable = CompletablesController.Instance.GetCompletable(targetId); score = referencedCompletable.Score; break; } break; // Recursive cases (calculated based on subscores) case Completable.Score.ScoreMethod.AVERAGE: score = completableScore.getSubScores().Average(s => CalculateScore(s)); break; case Completable.Score.ScoreMethod.SUM: score = completableScore.getSubScores().Sum(s => CalculateScore(s)); break; } return(score); }
public override bool canAddElement(int type) { return(score.getMethod() != Completable.Score.ScoreMethod.SINGLE && type == Controller.SCORE); }