Esempio n. 1
0
        public override void LoadFromJSON(LogicJSONObject jsonRoot)
        {
            LogicJSONObject baseObject = jsonRoot.GetJSONObject("base");

            if (baseObject == null)
            {
                Debugger.Error("Replay LogicPlaceAttackerCommand load failed! Base missing!");
            }

            base.LoadFromJSON(baseObject);

            LogicJSONNumber dataNumber = jsonRoot.GetJSONNumber("d");

            if (dataNumber != null)
            {
                this.m_data = (LogicCharacterData)LogicDataTables.GetDataById(dataNumber.GetIntValue(), LogicDataType.CHARACTER);
            }

            if (this.m_data == null)
            {
                Debugger.Error("Replay LogicPlaceAttackerCommand load failed! Character is NULL!");
            }

            this.m_x = jsonRoot.GetJSONNumber("x").GetIntValue();
            this.m_y = jsonRoot.GetJSONNumber("y").GetIntValue();
        }
Esempio n. 2
0
        public override void LoadFromJSON(LogicJSONObject jsonRoot)
        {
            LogicJSONObject baseObject = jsonRoot.GetJSONObject("base");

            if (baseObject == null)
            {
                Debugger.Error("Replay LogicPlaceAlliancePortalCommand load failed! Base missing!");
            }

            base.LoadFromJSON(baseObject);

            LogicJSONNumber dataNumber = jsonRoot.GetJSONNumber("d");

            if (dataNumber != null)
            {
                this.m_data = (LogicAlliancePortalData)LogicDataTables.GetDataById(dataNumber.GetIntValue(), LogicDataType.ALLIANCE_PORTAL);
            }

            if (this.m_data == null)
            {
                Debugger.Error("Replay LogicPlaceAlliancePortalCommand load failed! Data is NULL!");
            }

            this.m_x = jsonRoot.GetJSONNumber("x").GetIntValue();
            this.m_y = jsonRoot.GetJSONNumber("y").GetIntValue();
        }
Esempio n. 3
0
        public override void LoadFromJSON(LogicJSONObject jsonRoot)
        {
            LogicJSONObject baseObject = jsonRoot.GetJSONObject("base");

            if (baseObject == null)
            {
                Debugger.Error("Replay LogicChangeUnitVillage2Command load failed! Base missing!");
            }

            base.LoadFromJSON(baseObject);

            LogicJSONNumber newDataNumber = jsonRoot.GetJSONNumber("n");

            if (newDataNumber != null)
            {
                this.m_newUnitData = (LogicCharacterData)LogicDataTables.GetDataById(newDataNumber.GetIntValue(), LogicDataType.CHARACTER);
            }

            LogicJSONNumber oldDataNumber = jsonRoot.GetJSONNumber("o");

            if (oldDataNumber != null)
            {
                this.m_oldUnitData = (LogicCharacterData)LogicDataTables.GetDataById(oldDataNumber.GetIntValue(), LogicDataType.CHARACTER);
            }
        }
Esempio n. 4
0
        public override void LoadFromJSON(LogicJSONObject jsonRoot)
        {
            LogicJSONObject baseObject = jsonRoot.GetJSONObject("base");

            if (baseObject == null)
            {
                Debugger.Error("Replay LogicCastSpellCommand load failed! Base missing!");
            }

            base.LoadFromJSON(baseObject);

            LogicJSONNumber dataNumber = jsonRoot.GetJSONNumber("d");

            if (dataNumber != null)
            {
                this.m_data = (LogicSpellData)LogicDataTables.GetDataById(dataNumber.GetIntValue(), LogicDataType.SPELL);
            }

            if (this.m_data == null)
            {
                Debugger.Error("Replay LogicCastSpellCommand load failed! Data is NULL!");
            }

            this.m_x = jsonRoot.GetJSONNumber("x").GetIntValue();
            this.m_y = jsonRoot.GetJSONNumber("y").GetIntValue();

            LogicJSONNumber dataLevelNumber = jsonRoot.GetJSONNumber("dl");

            if (dataLevelNumber != null)
            {
                this.m_allianceSpell = true;
                this.m_upgLevel      = dataLevelNumber.GetIntValue();
            }
        }
        public LogicData GetDataParameter(int idx, LogicDataType tableIdx)
        {
            if (this.IsValidParameter(idx))
            {
                int value = LogicStringUtil.ConvertToInt(this.m_parameters[idx]);

                if (value != 0)
                {
                    LogicData data = LogicDataTables.GetDataById(value, tableIdx);

                    if (data != null)
                    {
                        return(data);
                    }

                    this.m_errorHandler.WarningFunction(this.m_calendarEvent, this, this.m_functionData.GetParameterName(idx),
                                                        string.Format("Unable to find data by id {0} from tableId {1}.", value, tableIdx));
                }
                else
                {
                    this.m_errorHandler.WarningFunction(this.m_calendarEvent, this, this.m_functionData.GetParameterName(idx),
                                                        string.Format("Expected globalId got {0}.", value));
                }
            }

            return(null);
        }
        public void Load(LogicJSONObject jsonObject)
        {
            LogicJSONNumber avatarIdHighObject = jsonObject.GetJSONNumber("avatar_id_high");
            LogicJSONNumber avatarIdLowObject  = jsonObject.GetJSONNumber("avatar_id_low");

            if (avatarIdHighObject != null && avatarIdLowObject != null)
            {
                this.m_avatarId = new LogicLong(avatarIdHighObject.GetIntValue(), avatarIdLowObject.GetIntValue());
            }

            LogicJSONArray donationArray = jsonObject.GetJSONArray("donations");

            if (donationArray != null)
            {
                for (int i = 0; i < donationArray.Size(); i++)
                {
                    LogicJSONArray array = donationArray.GetJSONArray(i);

                    if (array != null && array.Size() == 2)
                    {
                        LogicData data = LogicDataTables.GetDataById(array.GetJSONNumber(0).GetIntValue());

                        if (data != null)
                        {
                            this.m_donationData.Add((LogicCombatItemData)data);
                            this.m_donationLevel.Add(array.GetJSONNumber(1).GetIntValue());
                        }
                    }
                }
            }
        }
Esempio n. 7
0
        public void Load(LogicJSONObject jsonObject)
        {
            this.m_allianceName           = jsonObject.GetJSONString("alliance_name").GetStringValue();
            this.m_allianceBadgeId        = jsonObject.GetJSONNumber("badge_id").GetIntValue();
            this.m_allianceType           = (AllianceType)jsonObject.GetJSONNumber("type").GetIntValue();
            this.m_memberCount            = jsonObject.GetJSONNumber("member_count").GetIntValue();
            this.m_score                  = jsonObject.GetJSONNumber("score").GetIntValue();
            this.m_duelScore              = jsonObject.GetJSONNumber("duel_score").GetIntValue();
            this.m_requiredScore          = jsonObject.GetJSONNumber("required_score").GetIntValue();
            this.m_requiredDuelScore      = jsonObject.GetJSONNumber("required_duel_score").GetIntValue();
            this.m_winWarCount            = jsonObject.GetJSONNumber("win_war_count").GetIntValue();
            this.m_lostWarCount           = jsonObject.GetJSONNumber("lost_war_count").GetIntValue();
            this.m_drawWarCount           = jsonObject.GetJSONNumber("draw_war_count").GetIntValue();
            this.m_warFrequency           = jsonObject.GetJSONNumber("war_freq").GetIntValue();
            this.m_expLevel               = jsonObject.GetJSONNumber("xp_level").GetIntValue();
            this.m_expPoints              = jsonObject.GetJSONNumber("xp_points").GetIntValue();
            this.m_consecutiveWinWarCount = jsonObject.GetJSONNumber("cons_win_war_count").GetIntValue();
            this.m_publicWarLog           = jsonObject.GetJSONBoolean("public_war_log").IsTrue();
            this.m_amicalWarEnabled       = jsonObject.GetJSONBoolean("amical_war_enabled").IsTrue();

            LogicJSONNumber localeObject = jsonObject.GetJSONNumber("locale");

            if (localeObject != null)
            {
                this.m_localeData = LogicDataTables.GetDataById(localeObject.GetIntValue());
            }

            LogicJSONNumber originObject = jsonObject.GetJSONNumber("origin");

            if (originObject != null)
            {
                this.m_originData = LogicDataTables.GetDataById(originObject.GetIntValue());
            }
        }
Esempio n. 8
0
        public override void Decode(ByteStream stream)
        {
            this.m_id   = stream.ReadVInt();
            this.m_data = (LogicGameObjectData)LogicDataTables.GetDataById(stream.ReadVInt());
            this.m_json = LogicJSONParser.ParseObject(stream.ReadString(900000) ?? string.Empty);

            base.Decode(stream);
        }
        public static LogicData ReadDataReference(ByteStream stream, LogicDataType tableIndex)
        {
            int globalId = stream.ReadInt();

            if (GlobalID.GetClassID(globalId) == (int)tableIndex + 1)
            {
                return(LogicDataTables.GetDataById(globalId));
            }
            return(null);
        }
Esempio n. 10
0
        /// <summary>
        ///     Reads this instance from json.
        /// </summary>
        public void ReadFromJSON(LogicJSONObject jsonObject)
        {
            LogicJSONNumber id = jsonObject.GetJSONNumber("id");

            if (id != null && id.GetIntValue() != 0)
            {
                this._data = LogicDataTables.GetDataById(id.GetIntValue());
            }

            this._count = LogicJSONHelper.GetJSONNumber(jsonObject, "cnt");
        }
        public static LogicData GetLogicData(LogicJSONObject jsonObject, string key)
        {
            LogicData data = LogicDataTables.GetDataById(LogicStringUtil.ConvertToInt(LogicJSONHelper.GetString(jsonObject, key, string.Empty, true)));

            if (data == null)
            {
                Debugger.Error("Unable to load data. key:" + key);
            }

            return(data);
        }
        public static void LoadDebugJSONArray(LogicLevel level, LogicJSONArray jsonArray, LogicGameObjectType gameObjectType, int villageType)
        {
            if (jsonArray != null)
            {
                LogicGameObjectManager           gameObjectManager = level.GetGameObjectManagerAt(villageType);
                LogicArrayList <LogicGameObject> prevGameObjects   = new LogicArrayList <LogicGameObject>();

                prevGameObjects.AddAll(gameObjectManager.GetGameObjects(gameObjectType));

                for (int i = 0; i < prevGameObjects.Size(); i++)
                {
                    gameObjectManager.RemoveGameObject(prevGameObjects[i]);
                }

                for (int i = 0; i < jsonArray.Size(); i++)
                {
                    LogicJSONObject  jsonObject    = jsonArray.GetJSONObject(i);
                    LogicJSONNumber  dataNumber    = jsonObject.GetJSONNumber("data");
                    LogicJSONNumber  lvlNumber     = jsonObject.GetJSONNumber("lvl");
                    LogicJSONBoolean lockedBoolean = jsonObject.GetJSONBoolean("locked");
                    LogicJSONNumber  xNumber       = jsonObject.GetJSONNumber("x");
                    LogicJSONNumber  yNumber       = jsonObject.GetJSONNumber("y");

                    if (dataNumber != null && xNumber != null && yNumber != null)
                    {
                        LogicGameObjectData data = (LogicGameObjectData)LogicDataTables.GetDataById(dataNumber.GetIntValue());

                        if (data != null)
                        {
                            LogicGameObject gameObject = LogicGameObjectFactory.CreateGameObject(data, level, villageType);

                            if (gameObjectType == LogicGameObjectType.BUILDING)
                            {
                                ((LogicBuilding)gameObject).StartConstructing(true);
                            }

                            if (lockedBoolean != null && lockedBoolean.IsTrue())
                            {
                                ((LogicBuilding)gameObject).Lock();
                            }

                            gameObject.Load(jsonObject);
                            gameObjectManager.AddGameObject(gameObject, -1);

                            if (lvlNumber != null)
                            {
                                LogicDebugUtil.SetBuildingUpgradeLevel(level, gameObject.GetGlobalID(), lvlNumber.GetIntValue(), villageType);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 13
0
        private async Task UpdateAllianceRankingList(int villageType)
        {
            Dictionary <long, AllianceRankingEntry> prevAllianceRankingDictionary = this.m_allianceRankingList[villageType];
            Dictionary <long, AllianceRankingEntry> allianceRankingDictionary     = new Dictionary <long, AllianceRankingEntry>(SeasonDocument.RANKING_LIST_SIZE);
            LogicArrayList <AllianceRankingEntry>   allianceRankingList           = this.AllianceRankingList[villageType];

            allianceRankingList.Clear();

            IViewResult <JObject> result =
                await ServerScoring.AllianceDatabase.ExecuteCommand <JObject>(new ViewQuery().From("alliances", "leaderboard_" + villageType).Desc().Limit(SeasonDocument.RANKING_LIST_SIZE));

            if (result.Success)
            {
                int orderCounter = 0;

                foreach (JObject value in result.Values)
                {
                    AllianceRankingEntry allianceRankingEntry = new AllianceRankingEntry();
                    LogicLong            id = new LogicLong((int)value["id_hi"], (int)value["id_lo"]);

                    allianceRankingEntry.SetId(id);
                    allianceRankingEntry.SetName((string)value["name"]);
                    allianceRankingEntry.SetScore((int)value["score"]);
                    allianceRankingEntry.SetAllianceBadgeId((int)value["badge_id"]);
                    allianceRankingEntry.SetAllianceLevel((int)value["xp_level"]);
                    allianceRankingEntry.SetMemberCount((int)value["member_count"]);

                    if (value.TryGetValue("origin", out JToken originToken))
                    {
                        allianceRankingEntry.SetOriginData(LogicDataTables.GetDataById((int)originToken));
                    }

                    allianceRankingEntry.SetOrder(++orderCounter);

                    if (prevAllianceRankingDictionary != null && prevAllianceRankingDictionary.TryGetValue(id, out AllianceRankingEntry prevEntry))
                    {
                        allianceRankingEntry.SetPreviousOrder(prevEntry.GetPreviousOrder());
                    }

                    allianceRankingDictionary.Add(id, allianceRankingEntry);
                    allianceRankingList.Add(allianceRankingEntry);
                }

                this.m_allianceRankingList[villageType] = allianceRankingDictionary;
            }
            else
            {
                Logging.Warning("ScoringSeason.updateAllianceRankingList: view error: " + result.Error);
            }
        }
Esempio n. 14
0
        public override void Load(LogicJSONObject root)
        {
            if (this.m_timer != null)
            {
                this.m_timer.Destruct();
                this.m_timer = null;
            }

            this.m_unit = null;

            LogicJSONObject jsonObject = root.GetJSONObject("unit_upg");

            if (jsonObject != null)
            {
                LogicJSONNumber unitTypeObject         = jsonObject.GetJSONNumber("unit_type");
                LogicJSONNumber idObject               = jsonObject.GetJSONNumber("id");
                LogicJSONNumber timerObject            = jsonObject.GetJSONNumber("t");
                LogicJSONNumber timerEndObject         = jsonObject.GetJSONNumber("t_end");
                LogicJSONNumber timerFastForwardObject = jsonObject.GetJSONNumber("t_ff");

                this.m_unitType = unitTypeObject != null?unitTypeObject.GetIntValue() : 0;

                if (idObject != null)
                {
                    if (timerObject != null)
                    {
                        LogicData data = LogicDataTables.GetDataById(idObject.GetIntValue(), this.m_unitType == 0 ? LogicDataType.CHARACTER : LogicDataType.SPELL);

                        if (data != null)
                        {
                            this.m_unit = (LogicCombatItemData)data;

                            this.m_timer = new LogicTimer();
                            this.m_timer.StartTimer(timerObject.GetIntValue(), this.m_parent.GetLevel().GetLogicTime(), false, -1);

                            if (timerEndObject != null)
                            {
                                this.m_timer.SetEndTimestamp(timerEndObject.GetIntValue());
                            }

                            if (timerFastForwardObject != null)
                            {
                                this.m_timer.SetFastForward(timerFastForwardObject.GetIntValue());
                            }
                        }
                    }
                }
            }
        }
Esempio n. 15
0
        public override void LoadFromJSON(LogicJSONObject jsonRoot)
        {
            LogicJSONObject baseObject = jsonRoot.GetJSONObject("base");

            if (baseObject == null)
            {
                Debugger.Error("Replay LogicTriggerComponentTriggeredCommand load failed! Base missing!");
            }

            base.LoadFromJSON(baseObject);

            this.m_id   = jsonRoot.GetJSONNumber("id").GetIntValue();
            this.m_data = (LogicGameObjectData)LogicDataTables.GetDataById(jsonRoot.GetJSONNumber("dataid").GetIntValue());
            this.m_json = jsonRoot.GetJSONObject("objs");
        }
Esempio n. 16
0
        public static void AddJSONDataSlotsToArray(LogicJSONArray jsonArray, LogicArrayList <LogicDataSlot> slot)
        {
            for (int i = 0; i < jsonArray.Size(); i++)
            {
                LogicJSONArray objectArray = jsonArray.GetJSONArray(i);

                if (objectArray != null && objectArray.Size() == 2)
                {
                    LogicData data  = LogicDataTables.GetDataById(jsonArray.GetJSONNumber(0).GetIntValue());
                    int       count = objectArray.GetJSONNumber(1).GetIntValue();

                    slot.Add(new LogicDataSlot(data, count));
                }
            }
        }
        public override void Load(LogicJSONObject jsonObject)
        {
            base.Load(jsonObject);

            this.m_badgeId     = jsonObject.GetJSONNumber(AllianceRankingEntry.JSON_ATTRIBUTE_BADGE_ID).GetIntValue();
            this.m_expLevel    = jsonObject.GetJSONNumber(AllianceRankingEntry.JSON_ATTRIBUTE_EXP_LEVEL).GetIntValue();
            this.m_memberCount = jsonObject.GetJSONNumber(AllianceRankingEntry.JSON_ATTRIBUTE_MEMBER_COUNT).GetIntValue();

            LogicJSONNumber originNumber = jsonObject.GetJSONNumber(AllianceRankingEntry.JSON_ATTRIBUTE_ORIGIN);

            if (originNumber != null)
            {
                this.m_originData = LogicDataTables.GetDataById(originNumber.GetIntValue());
            }
        }
        /// <summary>
        ///     Loads this instance from json.
        /// </summary>
        public override void Load(LogicJSONObject jsonObject)
        {
            LogicJSONObject unitProductionObject = jsonObject.GetJSONObject("up2");

            if (unitProductionObject != null)
            {
                LogicJSONNumber timerObject = jsonObject.GetJSONNumber("t");

                if (timerObject != null)
                {
                    int time = timerObject.GetIntValue();

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

                    this._trainingTimer = new LogicTimer();
                    this._trainingTimer.StartTimer(time, this._parent.GetLevel().GetLogicTime(), false, -1);
                }

                LogicJSONArray unitArray = jsonObject.GetJSONArray("unit");

                if (unitArray != null)
                {
                    LogicJSONNumber dataObject = unitArray.GetJSONNumber(0);
                    LogicJSONNumber cntObject  = unitArray.GetJSONNumber(0);

                    if (dataObject != null)
                    {
                        if (cntObject != null)
                        {
                            LogicData data = LogicDataTables.GetDataById(dataObject.GetIntValue(), this._productionType != 0 ? 25 : 3);

                            if (data != null)
                            {
                                this._unit = new LogicDataSlot(data, cntObject.GetIntValue());
                            }
                            else
                            {
                                Debugger.Error("LogicVillage2UnitComponent::load - Character data is NULL!");
                            }
                        }
                    }
                }
            }
        }
        /// <summary>
        ///     Loads this instance.
        /// </summary>
        public override void Load(LogicJSONObject jsonObject)
        {
            LogicJSONArray unitArray = jsonObject.GetJSONArray("units");

            if (unitArray != null)
            {
                if (this._slots.Count > 0)
                {
                    Debugger.Error("LogicUnitStorageComponent::load - Unit array size > 0!");
                }

                for (int i = 0, size = unitArray.Size(); i < size; i++)
                {
                    LogicJSONArray unitObject = unitArray.GetJSONArray(i);

                    if (unitObject != null)
                    {
                        LogicJSONNumber dataObject  = unitObject.GetJSONNumber(0);
                        LogicJSONNumber countObject = unitObject.GetJSONNumber(1);

                        if (dataObject != null)
                        {
                            if (countObject != null)
                            {
                                LogicData data = LogicDataTables.GetDataById(dataObject.GetIntValue(), this._storageType != 0 ? 25 : 3);

                                if (data != null)
                                {
                                    this._slots.Add(new LogicUnitSlot(data, -1, countObject.GetIntValue()));
                                }
                                else
                                {
                                    Debugger.Error("LogicUnitStorageComponent::load - Character data is NULL!");
                                }
                            }
                        }
                    }
                }
            }
        }
        public void LoadGameObjectsJsonArray(LogicLevel level, LogicJSONArray array, int villageType)
        {
            if (array != null)
            {
                for (int i = 0; i < array.Size(); i++)
                {
                    LogicJSONObject jsonObject = array.GetJSONObject(i);

                    if (jsonObject != null)
                    {
                        LogicGameObjectData data = (LogicGameObjectData)LogicDataTables.GetDataById(jsonObject.GetJSONNumber("data").GetIntValue());

                        if (data != null)
                        {
                            LogicGameObject gameObject = LogicGameObjectFactory.CreateGameObject(data, level, villageType);
                            gameObject.Load(jsonObject);
                            level.GetGameObjectManagerAt(1).AddGameObject(gameObject, -1);
                        }
                    }
                }
            }
        }
        public override void LoadFromJSON(LogicJSONObject jsonRoot)
        {
            LogicJSONObject baseObject = jsonRoot.GetJSONObject("base");

            if (baseObject == null)
            {
                Debugger.Error("Replay LogicTriggerHeroAbility load failed! Base missing!");
            }

            base.LoadFromJSON(baseObject);

            LogicJSONNumber dataNumber = jsonRoot.GetJSONNumber("d");

            if (dataNumber != null)
            {
                this.m_data = (LogicHeroData)LogicDataTables.GetDataById(dataNumber.GetIntValue(), LogicDataType.HERO);
            }

            if (this.m_data == null)
            {
                Debugger.Error("Replay LogicTriggerHeroAbility load failed! Hero is NULL!");
            }
        }
 public static LogicData ReadDataReference(ByteStream stream)
 {
     return(LogicDataTables.GetDataById(stream.ReadInt()));
 }
        /// <summary>
        ///     Executes this command.
        /// </summary>
        public override int Execute(LogicLevel level)
        {
            LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

            if (playerAvatar != null)
            {
                if (this._source == 1)
                {
                    // listener.
                }

                playerAvatar.SetDiamonds(playerAvatar.GetDiamonds() + this._diamondsCount);

                if (this._freeDiamonds)
                {
                    int freeDiamonds = playerAvatar.GetFreeDiamonds();

                    if (this._diamondsCount < 0)
                    {
                        if (freeDiamonds - this._diamondsCount >= 0 && playerAvatar.GetDiamonds() != freeDiamonds)
                        {
                            playerAvatar.SetFreeDiamonds(freeDiamonds + this._diamondsCount);
                        }
                    }
                    else
                    {
                        playerAvatar.SetFreeDiamonds(freeDiamonds + this._diamondsCount);
                    }
                }
                else
                {
                    if (this._billingPackageId > 0)
                    {
                        LogicBillingPackageData billingPackageData = (LogicBillingPackageData)LogicDataTables.GetDataById(this._billingPackageId, 21);

                        if (billingPackageData != null)
                        {
                            if (billingPackageData.RED && !this._bundlePackage)
                            {
                                int redPackageState    = playerAvatar.GetRedPackageState();
                                int newRedPackageState = redPackageState | 0x10;

                                if ((redPackageState & 3) != 3)
                                {
                                    newRedPackageState = (int)(newRedPackageState & 0xFFFFFFFC);
                                }

                                playerAvatar.SetRedPackageState(newRedPackageState);
                            }
                        }
                    }

                    level.GetGameListener().DiamondsBought();
                    playerAvatar.AddCumulativePurchasedDiamonds(this._diamondsCount);
                }

                return(0);
            }

            return(-1);
        }
Esempio n. 24
0
        public void Load(LogicJSONObject root)
        {
            if (this.m_timer != null)
            {
                this.m_timer.Destruct();
                this.m_timer = null;
            }

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

            for (int i = this.m_slots.Size() - 1; i >= 0; i--)
            {
                this.m_slots[i].Destruct();
                this.m_slots.Remove(i);
            }

            LogicJSONObject jsonObject = root.GetJSONObject("unit_prod");

            if (jsonObject != null)
            {
                LogicJSONArray slotArray = jsonObject.GetJSONArray("slots");

                if (slotArray != null)
                {
                    for (int i = 0; i < slotArray.Size(); i++)
                    {
                        LogicJSONObject slotObject = slotArray.GetJSONObject(i);

                        if (slotObject != null)
                        {
                            LogicJSONNumber dataObject = slotObject.GetJSONNumber("id");

                            if (dataObject != null)
                            {
                                LogicData data = LogicDataTables.GetDataById(dataObject.GetIntValue());

                                if (data != null)
                                {
                                    LogicJSONNumber  countObject   = slotObject.GetJSONNumber("cnt");
                                    LogicJSONBoolean termineObject = slotObject.GetJSONBoolean("t");

                                    if (countObject != null)
                                    {
                                        if (countObject.GetIntValue() > 0)
                                        {
                                            LogicUnitProductionSlot slot = new LogicUnitProductionSlot(data, countObject.GetIntValue(), false);

                                            if (termineObject != null)
                                            {
                                                slot.SetTerminate(termineObject.IsTrue());
                                            }

                                            this.m_slots.Add(slot);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                if (this.m_slots.Size() > 0)
                {
                    LogicUnitProductionSlot slot = this.GetCurrentlyTrainedSlot();

                    if (slot != null)
                    {
                        LogicJSONNumber timeObject = jsonObject.GetJSONNumber("t");

                        if (timeObject != null)
                        {
                            this.m_timer = new LogicTimer();
                            this.m_timer.StartTimer(timeObject.GetIntValue(), this.m_level.GetLogicTime(), false, -1);
                        }
                        else
                        {
                            LogicCombatItemData combatItemData = (LogicCombatItemData)slot.GetData();
                            LogicAvatar         avatar         = this.m_level.GetHomeOwnerAvatar();
                            int upgradeLevel = 0;

                            if (avatar != null)
                            {
                                upgradeLevel = avatar.GetUnitUpgradeLevel(combatItemData);
                            }

                            this.m_timer = new LogicTimer();
                            this.m_timer.StartTimer(combatItemData.GetTrainingTime(upgradeLevel, this.m_level, 0), this.m_level.GetLogicTime(), false, -1);

                            Debugger.Print("LogicUnitProduction::load null timer, restart: " + this.m_timer.GetRemainingSeconds(this.m_level.GetLogicTime()));
                        }
                    }
                }

                LogicJSONNumber boostTimeObject = jsonObject.GetJSONNumber("boost_t");

                if (boostTimeObject != null)
                {
                    this.m_boostTimer = new LogicTimer();
                    this.m_boostTimer.StartTimer(boostTimeObject.GetIntValue(), this.m_level.GetLogicTime(), false, -1);
                }

                LogicJSONBoolean boostPauseObject = jsonObject.GetJSONBoolean("boost_pause");

                if (boostPauseObject != null)
                {
                    this.m_boostPause = boostPauseObject.IsTrue();
                }
            }
            else
            {
                Debugger.Warning("LogicUnitProduction::load - Component wasn't found from the JSON");
            }
        }
        public override void Load(LogicJSONObject root)
        {
            if (this.m_timer != null)
            {
                this.m_timer.Destruct();
                this.m_timer = null;
            }

            for (int i = this.m_slots.Size() - 1; i >= 0; i--)
            {
                this.m_slots[i].Destruct();
                this.m_slots.Remove(i);
            }

            LogicJSONObject jsonObject = root.GetJSONObject("unit_prod");

            if (jsonObject != null)
            {
                LogicJSONNumber modeObject = jsonObject.GetJSONNumber("m");

                if (modeObject != null)
                {
                    this.m_mode = true;
                }

                LogicJSONNumber unitTypeObject = jsonObject.GetJSONNumber("unit_type");

                if (unitTypeObject != null)
                {
                    this.m_productionType = unitTypeObject.GetIntValue();
                }

                LogicJSONArray slotArray = jsonObject.GetJSONArray("slots");

                if (slotArray != null)
                {
                    for (int i = 0; i < slotArray.Size(); i++)
                    {
                        LogicJSONObject slotObject = slotArray.GetJSONObject(i);

                        if (slotObject != null)
                        {
                            LogicJSONNumber idObject = slotObject.GetJSONNumber("id");

                            if (idObject != null)
                            {
                                LogicData data = LogicDataTables.GetDataById(idObject.GetIntValue(),
                                                                             this.m_productionType == 0 ? LogicDataType.CHARACTER : LogicDataType.SPELL);

                                if (data != null)
                                {
                                    LogicJSONNumber countObject = slotObject.GetJSONNumber("cnt");

                                    if (countObject != null)
                                    {
                                        if (countObject.GetIntValue() > 0)
                                        {
                                            this.m_slots.Add(new LogicDataSlot(data, countObject.GetIntValue()));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                if (this.m_slots.Size() > 0)
                {
                    LogicJSONNumber timeObject = jsonObject.GetJSONNumber("t");

                    if (timeObject != null)
                    {
                        this.m_timer = new LogicTimer();
                        this.m_timer.StartTimer(timeObject.GetIntValue(), this.m_parent.GetLevel().GetLogicTime(), false, -1);
                    }
                    else
                    {
                        LogicCombatItemData data            = (LogicCombatItemData)this.m_slots[0].GetData();
                        LogicAvatar         homeOwnerAvatar = this.m_parent.GetLevel().GetHomeOwnerAvatar();
                        int upgLevel = homeOwnerAvatar != null?homeOwnerAvatar.GetUnitUpgradeLevel(data) : 0;

                        this.m_timer = new LogicTimer();
                        this.m_timer.StartTimer(data.GetTrainingTime(upgLevel, this.m_parent.GetLevel(), 0), this.m_parent.GetLevel().GetLogicTime(), false, -1);
                    }
                }
            }
            else
            {
                this.m_productionType = 0;

                if (this.m_parent.GetVillageType() == 0)
                {
                    Debugger.Warning("LogicUnitProductionComponent::load - Component wasn't found from the JSON");
                }
            }
        }
        private void OnSendGlobalChatLineMessageReceived(SendGlobalChatLineMessage message)
        {
            if (!this.CanSendGlobalChatMessage())
            {
                return;
            }

            string chatMessage = StringUtil.RemoveMultipleSpaces(message.RemoveMessage());

            if (chatMessage.Length > 0)
            {
                if (chatMessage.Length > 128)
                {
                    chatMessage = chatMessage.Substring(0, 128);
                }

                if (chatMessage.StartsWith("/op "))
                {
                    string[] args = chatMessage.Trim().Split(' ');

                    if (args.Length < 3)
                    {
                        return;
                    }

                    string commandType = args[1];
                    string commandName = args[2];

                    switch (commandType)
                    {
                    case "attack":
                    {
                        if (string.Equals(commandName, "me", StringComparison.InvariantCultureIgnoreCase))
                        {
                            this.m_session.SendMessage(new GameStartFakeAttackMessage
                                {
                                    AccountId = this.m_session.AccountId,
                                    ArgData   = null
                                }, 9);
                        }
                        else if (commandName.StartsWith("#"))
                        {
                            LogicLong accountId = HashTagCodeGenerator.m_instance.ToId(commandName.ToUpperInvariant());

                            if (accountId != null)
                            {
                                this.m_session.SendMessage(new GameStartFakeAttackMessage
                                    {
                                        AccountId = accountId,
                                        ArgData   = null
                                    }, 9);
                            }
                        }
                        else if (string.Equals(commandName, "generate", StringComparison.InvariantCultureIgnoreCase))
                        {
                            if (args.Length >= 4)
                            {
                                if (int.TryParse(args[3], out int id))
                                {
                                    LogicGameObjectData gameObjectData = null;

                                    switch (id / 100)
                                    {
                                    case 0:
                                        LogicBuildingData buildingData =
                                            (LogicBuildingData)LogicDataTables.GetDataById(GlobalID.CreateGlobalID((int)LogicDataType.BUILDING + 1, id), LogicDataType.BUILDING);

                                        if (buildingData.IsTownHall() || buildingData.IsTownHallVillage2())
                                        {
                                            return;
                                        }
                                        if (!buildingData.IsEnabledInVillageType(0))
                                        {
                                            return;
                                        }
                                        if (buildingData.IsLocked() && !buildingData.IsAllianceCastle())
                                        {
                                            return;
                                        }

                                        gameObjectData = buildingData;
                                        break;

                                    case 1:
                                        gameObjectData = (LogicGameObjectData)LogicDataTables.GetDataById(GlobalID.CreateGlobalID((int)LogicDataType.TRAP + 1, id), LogicDataType.TRAP);
                                        break;
                                    }

                                    if (gameObjectData != null)
                                    {
                                        this.m_session.SendMessage(new GameStartFakeAttackMessage
                                            {
                                                AccountId = null,
                                                ArgData   = gameObjectData
                                            }, 9);
                                    }
                                }
                            }
                            else
                            {
                                this.m_session.SendMessage(new GameStartFakeAttackMessage
                                    {
                                        AccountId = null,
                                        ArgData   = null
                                    }, 9);
                            }
                        }

                        break;
                    }

                    case "village":
                        switch (commandName)
                        {
                        case "upgrade":
                        {
                            AvailableServerCommandMessage availableServerCommandMessage = new AvailableServerCommandMessage();
                            availableServerCommandMessage.SetServerCommand(new LogicDebugCommand(LogicDebugActionType.UPGRADE_ALL_BUILDINGS));
                            this.m_session.SendPiranhaMessage(availableServerCommandMessage, 1);
                            break;
                        }

                        case "obstacle":
                        {
                            AvailableServerCommandMessage availableServerCommandMessage = new AvailableServerCommandMessage();
                            availableServerCommandMessage.SetServerCommand(new LogicDebugCommand(LogicDebugActionType.REMOVE_OBSTACLES));
                            this.m_session.SendPiranhaMessage(availableServerCommandMessage, 1);
                            break;
                        }

                        case "preset":
                            // TODO: Implement this.
                            break;
                        }

                        break;

                    case "hero":
                        switch (commandName)
                        {
                        case "max":
                        {
                            AvailableServerCommandMessage availableServerCommandMessage = new AvailableServerCommandMessage();
                            availableServerCommandMessage.SetServerCommand(new LogicDebugCommand(LogicDebugActionType.SET_MAX_HERO_LEVELS));
                            this.m_session.SendPiranhaMessage(availableServerCommandMessage, 1);
                            return;
                        }

                        case "reset":
                        {
                            AvailableServerCommandMessage availableServerCommandMessage = new AvailableServerCommandMessage();
                            availableServerCommandMessage.SetServerCommand(new LogicDebugCommand(LogicDebugActionType.RESET_HERO_LEVELS));
                            this.m_session.SendPiranhaMessage(availableServerCommandMessage, 1);
                            return;
                        }
                        }

                        break;

                    case "unit":
                        switch (commandName)
                        {
                        case "max":
                        {
                            AvailableServerCommandMessage availableServerCommandMessage = new AvailableServerCommandMessage();
                            availableServerCommandMessage.SetServerCommand(new LogicDebugCommand(LogicDebugActionType.SET_MAX_UNIT_SPELL_LEVELS));
                            this.m_session.SendPiranhaMessage(availableServerCommandMessage, 1);
                            return;
                        }
                        }

                        break;
                    }
                }
                else
                {
                    ServerRequestManager.Create(new AvatarRequestMessage
                    {
                        AccountId = this.m_session.AccountId
                    }, ServerManager.GetDocumentSocket(9, this.m_session.AccountId)).OnComplete = args =>
                    {
                        if (args.ErrorCode == ServerRequestError.Success && args.ResponseMessage.Success)
                        {
                            this.m_session.ChatInstance.PublishMessage(((AvatarResponseMessage)args.ResponseMessage).LogicClientAvatar, WordCensorUtil.FilterMessage(chatMessage));
                            this.m_previousGlobalChatMessageTime = DateTime.UtcNow;
                        }
                    };
                }
            }
        }