예제 #1
0
        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);
        }
예제 #2
0
        public LogicJSONObject GenerateBattleLogJSON(LogicLong homeId, LogicLong allianceId, int allianceBadgeId, string allianceName, int allianceBadgeId2, int allianceExpLevel,
                                                     int allianceExpLevel2)
        {
            LogicJSONObject jsonObject = new LogicJSONObject();

            jsonObject.Put("villageType", new LogicJSONNumber(this.m_villageType));

            bool village2Match = true;

            if ((this.m_level.GetMatchType() & 0xFFFFFFFE) != 8)
            {
                jsonObject.Put("loot", LogicBattleLog.DataSlotArrayToJSONArray(this.m_lootCount));
                jsonObject.Put("availableLoot", LogicBattleLog.DataSlotArrayToJSONArray(this.m_availableLootCount));

                village2Match = false;
            }

            jsonObject.Put("units", LogicBattleLog.DataSlotArrayToJSONArray(this.m_castedUnitCount));

            if (!village2Match)
            {
                if (this.m_castedAllianceUnitCount != null && this.m_castedAllianceUnitCount.Size() > 0)
                {
                    jsonObject.Put("cc_units", LogicBattleLog.UnitSlotArrayToJSONArray(this.m_castedAllianceUnitCount));
                }
            }

            if (this.m_costCount != null && this.m_costCount.Size() > 0)
            {
                jsonObject.Put("costs", LogicBattleLog.DataSlotArrayToJSONArray(this.m_costCount));
            }

            if (!village2Match)
            {
                jsonObject.Put("spells", LogicBattleLog.DataSlotArrayToJSONArray(this.m_castedSpellCount));
            }

            jsonObject.Put("levels", LogicBattleLog.DataSlotArrayToJSONArray(this.m_unitLevelCount));

            LogicJSONObject statObject = new LogicJSONObject();

            statObject.Put("townhallDestroyed", new LogicJSONBoolean(this.m_townhallDestroyed));
            statObject.Put("battleEnded", new LogicJSONBoolean(this.m_battleEnded));

            if (!village2Match)
            {
                statObject.Put("allianceUsed", new LogicJSONBoolean(this.m_allianceUsed));
            }

            statObject.Put("destructionPercentage", new LogicJSONNumber(this.m_destructionPercentage));
            statObject.Put("battleTime", new LogicJSONNumber(this.m_battleTime));

            if (!village2Match)
            {
                statObject.Put("originalAttackerScore", new LogicJSONNumber(this.m_originalAttackerScore));
                statObject.Put("attackerScore", new LogicJSONNumber(this.m_attackerScore));
                statObject.Put("originalDefenderScore", new LogicJSONNumber(this.m_originalDefenderScore));
                statObject.Put("defenderScore", new LogicJSONNumber(this.m_defenderScore));
            }

            statObject.Put("allianceName", new LogicJSONString(allianceName));

            if (!village2Match)
            {
                statObject.Put("attackerStars", new LogicJSONNumber(this.m_attackerStars));
            }

            if (this.m_level.GetMatchType() <= 7)
            {
                statObject.Put("attackerName", new LogicJSONString(this.m_attackerName));
                statObject.Put("defenderName", new LogicJSONString(this.m_defenderName));

                int lootMultiplierByTownHallDiff = 100;

                if (LogicDataTables.GetGlobals().UseTownHallLootPenaltyInWar())
                {
                    lootMultiplierByTownHallDiff = LogicDataTables.GetGlobals().GetLootMultiplierByTownHallDiff(this.m_level.GetVisitorAvatar().GetTownHallLevel(),
                                                                                                                this.m_level.GetHomeOwnerAvatar().GetTownHallLevel());
                }

                statObject.Put("lootMultiplierByTownHallDiff", new LogicJSONNumber(lootMultiplierByTownHallDiff));
            }

            LogicJSONArray homeIdArray = new LogicJSONArray(2);

            homeIdArray.Add(new LogicJSONNumber(homeId.GetHigherInt()));
            homeIdArray.Add(new LogicJSONNumber(homeId.GetLowerInt()));

            statObject.Put("homeID", homeIdArray);

            if (allianceBadgeId != -2)
            {
                statObject.Put("allianceBadge", new LogicJSONNumber(allianceBadgeId));
            }

            if (allianceBadgeId2 != -2)
            {
                statObject.Put("allianceBadge2", new LogicJSONNumber(allianceBadgeId2));
            }

            if (allianceId != null)
            {
                LogicJSONArray allianceIdArray = new LogicJSONArray(2);

                allianceIdArray.Add(new LogicJSONNumber(allianceId.GetHigherInt()));
                allianceIdArray.Add(new LogicJSONNumber(allianceId.GetLowerInt()));

                statObject.Put("allianceID", allianceIdArray);
            }

            if (!village2Match)
            {
                statObject.Put("deployedHousingSpace", new LogicJSONNumber(this.m_deployedHousingSpace));
                statObject.Put("armyDeploymentPercentage", new LogicJSONNumber(this.m_armyDeploymentPercentage));
            }

            if (allianceExpLevel != 0)
            {
                statObject.Put("allianceExp", new LogicJSONNumber(allianceExpLevel));
            }

            if (allianceExpLevel2 != 0)
            {
                statObject.Put("allianceExp2", new LogicJSONNumber(allianceExpLevel2));
            }

            jsonObject.Put("stats", statObject);

            return(jsonObject);
        }