public void EndArray() { if (this.m_nodes != null) { LogicJSONNode prevNode = this.m_nodes[this.m_nodes.Size() - 1]; Debugger.DoAssert(prevNode.GetJSONNodeType() == LogicJSONNodeType.ARRAY, "ChecksumHelper::endArray() called but top is not an array"); Debugger.DoAssert(this.m_nodes.Size() > 1, "ChecksumHelper::endArray() - size is too small"); this.m_nodes.Remove(this.m_nodes.Size() - 1); } }
public void WriteValue(string name, int value) { this.m_checksum += value; if (this.m_nodes != null) { LogicJSONNode prevNode = this.m_nodes[this.m_nodes.Size() - 1]; if (prevNode.GetJSONNodeType() == LogicJSONNodeType.OBJECT) { ((LogicJSONObject)prevNode).Put(name, new LogicJSONNumber(value)); } else if (prevNode.GetJSONNodeType() == LogicJSONNodeType.ARRAY) { ((LogicJSONArray)prevNode).Add(new LogicJSONString(string.Format("{0} {1}", name, value))); } } }
public void StartArray(string name) { if (this.m_nodes != null) { LogicJSONNode prevNode = this.m_nodes[this.m_nodes.Size() - 1]; if (prevNode.GetJSONNodeType() == LogicJSONNodeType.OBJECT) { LogicJSONArray array = new LogicJSONArray(); ((LogicJSONObject)prevNode).Put(name, array); this.m_nodes.Add(array); } else if (prevNode.GetJSONNodeType() == LogicJSONNodeType.ARRAY) { Debugger.DoAssert(((LogicJSONArray)prevNode).Size() != 0, "ChecksumHelper::startArray can't handle the truth (array inside array)"); } } }
public void StartObject(string name) { if (this.m_nodes != null) { LogicJSONObject jsonObject = new LogicJSONObject(); LogicJSONNode prevNode = this.m_nodes[this.m_nodes.Size() - 1]; if (prevNode.GetJSONNodeType() == LogicJSONNodeType.OBJECT) { ((LogicJSONObject)prevNode).Put(name, jsonObject); } else if (prevNode.GetJSONNodeType() == LogicJSONNodeType.ARRAY) { ((LogicJSONArray)prevNode).Add(jsonObject); jsonObject.Put("name", new LogicJSONString(name)); } this.m_nodes.Add(jsonObject); } }
public LogicJSONObject LoadBattleLogFromJSON(LogicJSONObject root) { LogicJSONNumber villageTypeNumber = root.GetJSONNumber("villageType"); if (villageTypeNumber != null) { this.m_villageType = villageTypeNumber.GetIntValue(); } LogicJSONNode lootNode = root.Get("loot"); if (lootNode != null && lootNode.GetJSONNodeType() == LogicJSONNodeType.ARRAY) { LogicBattleLog.AddJSONDataSlotsToArray((LogicJSONArray)lootNode, this.m_lootCount); } else if (this.m_villageType != 1) { Debugger.Warning("LogicBattleLog has no loot."); } LogicJSONNode unitNode = root.Get("units"); if (unitNode != null && unitNode.GetJSONNodeType() == LogicJSONNodeType.ARRAY) { LogicBattleLog.AddJSONDataSlotsToArray((LogicJSONArray)unitNode, this.m_castedUnitCount); } else { Debugger.Warning("LogicBattleLog has no loot."); } LogicJSONNode allianceUnitNode = root.Get("cc_units"); if (allianceUnitNode != null && allianceUnitNode.GetJSONNodeType() == LogicJSONNodeType.ARRAY) { LogicBattleLog.AddJSONUnitSlotsToArray((LogicJSONArray)allianceUnitNode, this.m_castedAllianceUnitCount); } LogicJSONNode costNode = root.Get("costs"); if (costNode != null && costNode.GetJSONNodeType() == LogicJSONNodeType.ARRAY) { LogicBattleLog.AddJSONDataSlotsToArray((LogicJSONArray)costNode, this.m_costCount); } LogicJSONNode spellNode = root.Get("spells"); if (spellNode != null && spellNode.GetJSONNodeType() == LogicJSONNodeType.ARRAY) { LogicBattleLog.AddJSONDataSlotsToArray((LogicJSONArray)spellNode, this.m_costCount); } else if (this.m_villageType != 1) { Debugger.Warning("LogicBattleLog has no spells."); } LogicJSONNode levelNode = root.Get("levels"); if (levelNode != null && levelNode.GetJSONNodeType() == LogicJSONNodeType.ARRAY) { LogicBattleLog.AddJSONDataSlotsToArray((LogicJSONArray)levelNode, this.m_unitLevelCount); } else { Debugger.Warning("LogicBattleLog has no levels."); } LogicJSONNode statsNode = root.Get("stats"); if (statsNode != null && statsNode.GetJSONNodeType() == LogicJSONNodeType.OBJECT) { LogicJSONObject statsObject = (LogicJSONObject)statsNode; LogicJSONBoolean townhallDestroyedBoolean = statsObject.GetJSONBoolean("townhallDestroyed"); if (townhallDestroyedBoolean != null) { this.m_townhallDestroyed = townhallDestroyedBoolean.IsTrue(); } LogicJSONBoolean battleEndedBoolean = statsObject.GetJSONBoolean("battleEnded"); if (battleEndedBoolean != null) { this.m_battleEnded = battleEndedBoolean.IsTrue(); } LogicJSONBoolean allianceUsedBoolean = statsObject.GetJSONBoolean("allianceUsed"); if (allianceUsedBoolean != null) { this.m_allianceUsed = allianceUsedBoolean.IsTrue(); } LogicJSONNumber destructionPercentageNumber = statsObject.GetJSONNumber("destructionPercentage"); if (destructionPercentageNumber != null) { this.m_destructionPercentage = destructionPercentageNumber.GetIntValue(); } LogicJSONNumber battleTimeNumber = statsObject.GetJSONNumber("battleTime"); if (battleTimeNumber != null) { this.m_battleTime = battleTimeNumber.GetIntValue(); } LogicJSONNumber attackerScoreNumber = statsObject.GetJSONNumber("attackerScore"); if (attackerScoreNumber != null) { this.m_attackerScore = attackerScoreNumber.GetIntValue(); } LogicJSONNumber defenderScoreNumber = statsObject.GetJSONNumber("defenderScore"); if (defenderScoreNumber != null) { this.m_defenderScore = defenderScoreNumber.GetIntValue(); } LogicJSONNumber originalAttackerScoreNumber = statsObject.GetJSONNumber("originalAttackerScore"); if (originalAttackerScoreNumber != null) { this.m_originalAttackerScore = originalAttackerScoreNumber.GetIntValue(); } else { this.m_attackerScore = -1; } LogicJSONNumber originalDefenderScoreNumber = statsObject.GetJSONNumber("originalDefenderScore"); if (originalDefenderScoreNumber != null) { this.m_originalDefenderScore = originalDefenderScoreNumber.GetIntValue(); } else { this.m_originalDefenderScore = -1; } this.LoadAttackerNameFromJson(statsObject); this.LoadDefenderNameFromJson(statsObject); LogicJSONNumber lootMultiplierByTownHallDiffNumber = statsObject.GetJSONNumber("lootMultiplierByTownHallDiff"); if (lootMultiplierByTownHallDiffNumber != null) { this.m_lootMultiplierByTownHallDiff = lootMultiplierByTownHallDiffNumber.GetIntValue(); } else { this.m_lootMultiplierByTownHallDiff = -1; } LogicJSONNumber deployedHousingSpaceNumber = statsObject.GetJSONNumber("deployedHousingSpace"); if (deployedHousingSpaceNumber != null) { this.m_deployedHousingSpace = deployedHousingSpaceNumber.GetIntValue(); } LogicJSONNumber armyDeploymentPercentageNumber = statsObject.GetJSONNumber("armyDeploymentPercentage"); if (armyDeploymentPercentageNumber != null) { this.m_armyDeploymentPercentage = armyDeploymentPercentageNumber.GetIntValue(); } LogicJSONNumber attackerStarsNumber = statsObject.GetJSONNumber("attackerStars"); if (attackerStarsNumber != null) { this.m_attackerStars = attackerStarsNumber.GetIntValue(); } return(statsObject); } Debugger.Warning("LogicBattleLog has no stats."); return(null); }