public static LogicTimer GetLogicTimer(LogicJSONObject jsonObject, LogicTime time, string key, int maxTime)
        {
            LogicJSONNumber number = (LogicJSONNumber)jsonObject.Get(key);

            if (number != null)
            {
                LogicTimer timer = new LogicTimer();

                int remainingSeconds = LogicMath.Min(number.GetIntValue(), maxTime);
                int tick             = time.GetTick();

                timer.m_remainingTime = tick + LogicTime.GetSecondsInTicks(remainingSeconds);

                return(timer);
            }

            return(null);
        }
Beispiel #2
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);
        }
        public void Load(LogicJSONObject root)
        {
            LogicJSONObject jsonObject = root.GetJSONObject("offer");

            if (jsonObject != null)
            {
                this.m_offerObject = jsonObject;

                if (this.m_timer != null)
                {
                    this.m_timer.Destruct();
                    this.m_timer = null;
                }

                this.m_timer = LogicTimer.GetLogicTimer(jsonObject, this.m_level.GetLogicTime(), "pct", 604800);

                if (jsonObject.Get("t") != null)
                {
                    this.m_terminate = true;
                }

                LogicJSONArray offerArray = jsonObject.GetJSONArray("offers");

                if (offerArray != null)
                {
                    for (int i = 0; i < offerArray.Size(); i++)
                    {
                        LogicJSONObject obj = (LogicJSONObject)offerArray.Get(i);

                        if (obj != null)
                        {
                            int data = LogicJSONHelper.GetInt(obj, "data", -1);

                            if (data != -1)
                            {
                                LogicOffer offer = this.GetOfferById(data);

                                if (offer != null)
                                {
                                    offer.Load(obj);
                                }
                            }
                        }
                        else
                        {
                            Debugger.Error("LogicOfferManager::load - Offer is NULL!");
                        }
                    }
                }

                for (int i = 0; i < 2; i++)
                {
                    LogicJSONNumber number = (LogicJSONNumber)jsonObject.Get(i == 1 ? "top2" : "top");

                    if (number != null)
                    {
                        this.m_topOffer[i] = this.GetOfferById(number.GetIntValue());
                    }
                }
            }
        }