コード例 #1
0
        /// <summary>
        ///     Gets the used capacity.
        /// </summary>
        public int GetUsedCapacity()
        {
            int usedCapacity = 0;

            for (int i = 0; i < this._slots.Count; i++)
            {
                LogicUnitSlot       unitSlot       = this._slots[i];
                LogicCombatItemData combatItemData = (LogicCombatItemData)unitSlot.GetData();

                usedCapacity += combatItemData.GetHousingSpace() * unitSlot.GetCount();
            }

            return(usedCapacity);
        }
コード例 #2
0
        public override void Load(LogicJSONObject jsonObject)
        {
            LogicJSONObject baseObject = jsonObject.GetJSONObject("base");

            if (baseObject == null)
            {
                Debugger.Error("ChatStreamEntry::load base is NULL");
            }

            base.Load(baseObject);

            this.m_castleLevel              = LogicJSONHelper.GetInt(jsonObject, "castle_level");
            this.m_castleUsedCapacity       = LogicJSONHelper.GetInt(jsonObject, "castle_used");
            this.m_castleUsedSpellCapacity  = LogicJSONHelper.GetInt(jsonObject, "castle_sp_used");
            this.m_castleTotalCapacity      = LogicJSONHelper.GetInt(jsonObject, "castle_total");
            this.m_castleTotalSpellCapacity = LogicJSONHelper.GetInt(jsonObject, "castle_sp_total");

            LogicJSONString messageObject = jsonObject.GetJSONString("message");

            if (messageObject != null)
            {
                this.m_message = messageObject.GetStringValue();
            }

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

            if (donationArray != null)
            {
                for (int i = 0; i < donationArray.Size(); i++)
                {
                    DonationContainer donationContainer = new DonationContainer();
                    donationContainer.Load(donationArray.GetJSONObject(i));
                    this.m_donationContainerList.Add(donationContainer);
                }
            }

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

            if (unitArray != null)
            {
                this.m_unitCount = new LogicArrayList <LogicUnitSlot>();

                for (int i = 0; i < unitArray.Size(); i++)
                {
                    LogicUnitSlot unitSlot = new LogicUnitSlot(null, -1, 0);
                    unitSlot.ReadFromJSON(unitArray.GetJSONObject(i));
                    this.m_unitCount.Add(unitSlot);
                }
            }
        }
コード例 #3
0
        /// <summary>
        ///     Gets the unit count by data.
        /// </summary>
        public int GetUnitCountByData(LogicCombatItemData data)
        {
            int count = 0;

            for (int i = 0; i < this._slots.Count; i++)
            {
                LogicUnitSlot unitSlot = this._slots[i];

                if (unitSlot.GetData() == data)
                {
                    count += unitSlot.GetCount();
                }
            }

            return(count);
        }
コード例 #4
0
        public static LogicJSONArray UnitSlotArrayToJSONArray(LogicArrayList <LogicUnitSlot> dataSlotArray)
        {
            LogicJSONArray jsonArray = new LogicJSONArray(dataSlotArray.Size());

            for (int i = 0; i < dataSlotArray.Size(); i++)
            {
                LogicUnitSlot  unitSlot    = dataSlotArray[i];
                LogicJSONArray objectArray = new LogicJSONArray();

                objectArray.Add(new LogicJSONNumber(unitSlot.GetData().GetGlobalID()));
                objectArray.Add(new LogicJSONNumber(unitSlot.GetLevel()));
                objectArray.Add(new LogicJSONNumber(unitSlot.GetCount()));

                jsonArray.Add(objectArray);
            }

            return(jsonArray);
        }
コード例 #5
0
        /// <summary>
        ///     Implementation to remove units.
        /// </summary>
        private void RemoveUnitsImpl(LogicCombatItemData data, int upgLevel, int count)
        {
            if (data != null)
            {
                int index = -1;

                for (int i = 0; i < this._slots.Count; i++)
                {
                    LogicUnitSlot slot = this._slots[i];

                    if (slot.GetData() == data && slot.GetLevel() == upgLevel)
                    {
                        index = i;
                        break;
                    }
                }

                if (index != -1)
                {
                    LogicUnitSlot slot = this._slots[index];

                    if (slot.GetCount() - count <= 0)
                    {
                        this._slots[index].Destruct();
                        this._slots.Remove(index);
                    }
                    else
                    {
                        slot.SetCount(slot.GetCount() - count);
                    }

                    Debugger.Print("LogicUnitStorageComponent::removeUnitsImpl remove " + count + " units");
                }
                else
                {
                    Debugger.Error("LogicUnitStorageComponent::removeUnitsImpl No units with the given type found");
                }
            }
            else
            {
                Debugger.Error("LogicUnitStorageComponent::removeUnits called with CharacterData NULL");
            }
        }
コード例 #6
0
        public void AddAvatarAllianceUnitsToCastle()
        {
            LogicGameObjectManager gameObjectManager = this.m_level.GetGameObjectManagerAt(0);
            LogicBuilding          allianceCastle    = gameObjectManager.GetAllianceCastle();

            if (allianceCastle != null)
            {
                LogicBunkerComponent bunkerComponent = allianceCastle.GetBunkerComponent();

                if (bunkerComponent != null)
                {
                    bunkerComponent.RemoveAllUnits();

                    LogicArrayList <LogicUnitSlot> units = this.m_level.GetHomeOwnerAvatar().GetAllianceUnits();

                    for (int i = 0; i < units.Size(); i++)
                    {
                        LogicUnitSlot       unitSlot = units[i];
                        LogicCombatItemData data     = (LogicCombatItemData)unitSlot.GetData();
                        int count = unitSlot.GetCount();

                        if (data != null)
                        {
                            if (data.GetCombatItemType() == LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER)
                            {
                                for (int j = 0; j < count; j++)
                                {
                                    if (bunkerComponent.GetUnusedCapacity() >= data.GetHousingSpace())
                                    {
                                        bunkerComponent.AddUnitImpl(data, unitSlot.GetLevel());
                                    }
                                }
                            }
                        }
                        else
                        {
                            Debugger.Error("LogicComponentManager::addAvatarAllianceUnitsToCastle - NULL character");
                        }
                    }
                }
            }
        }
コード例 #7
0
        /// <summary>
        ///     Implementation to add unit.
        /// </summary>
        private void AddUnitImpl(LogicCombatItemData data, int upgLevel)
        {
            if (data != null)
            {
                if (this.CanAddUnit(data))
                {
                    int index = -1;

                    for (int i = 0; i < this._slots.Count; i++)
                    {
                        LogicUnitSlot slot = this._slots[i];

                        if (slot.GetData() == data && slot.GetLevel() == upgLevel)
                        {
                            index = i;
                            break;
                        }
                    }

                    if (index != -1)
                    {
                        this._slots[index].SetCount(this._slots[index].GetCount() + 1);
                    }
                    else
                    {
                        this._slots.Add(new LogicUnitSlot(data, upgLevel, 1));
                    }
                }
                else
                {
                    Debugger.Warning("LogicUnitStorageComponent::addUnitImpl called and storage is full");
                }
            }
            else
            {
                Debugger.Warning("LogicUnitStorageComponent::addUnitImpl called and storage is full");
            }
        }
コード例 #8
0
        /// <summary>
        ///     Saves this instance.
        /// </summary>
        public override void Save(LogicJSONObject jsonObject)
        {
            LogicJSONArray unitArray = new LogicJSONArray();

            for (int i = 0; i < this._slots.Count; i++)
            {
                LogicUnitSlot slot = this._slots[i];

                if (slot.GetData() != null && slot.GetCount() > 0)
                {
                    if (slot.GetLevel() != -1)
                    {
                        Debugger.Error("Invalid unit level.");
                    }

                    LogicJSONArray unitObject = new LogicJSONArray(2);
                    unitObject.Add(new LogicJSONNumber(slot.GetData().GetGlobalID()));
                    unitObject.Add(new LogicJSONNumber(slot.GetCount()));
                    unitArray.Add(unitObject);
                }
            }

            jsonObject.Put("units", unitArray);
        }
コード例 #9
0
        /// <summary>
        ///     Destructs this instance.
        /// </summary>
        public override void Destruct()
        {
            base.Destruct();

            if (this._slots != null)
            {
                if (this._slots.Count != 0)
                {
                    do
                    {
                        LogicUnitSlot unitSlot = this._slots[0];

                        if (unitSlot != null)
                        {
                            this._slots[0].Destruct();
                        }

                        this._slots.Remove(0);
                    } while (this._slots.Count != 0);
                }

                this._slots = null;
            }
        }
コード例 #10
0
        public override void Decode(ByteStream stream)
        {
            base.Decode(stream);

            this.m_castleLevel              = stream.ReadInt();
            this.m_castleTotalCapacity      = stream.ReadInt();
            this.m_castleTotalSpellCapacity = stream.ReadInt();
            this.m_castleUsedCapacity       = stream.ReadInt();
            this.m_castleUsedSpellCapacity  = stream.ReadInt();

            for (int i = 0, size = stream.ReadInt(); i < size; i++)
            {
                DonationContainer donationContainer = new DonationContainer();
                donationContainer.Decode(stream);
                this.m_donationContainerList.Add(donationContainer);
            }

            if (stream.ReadBoolean())
            {
                this.m_message = stream.ReadString(900000);
            }

            int count = stream.ReadInt();

            if (count > -1)
            {
                this.m_unitCount = new LogicArrayList <LogicUnitSlot>(count);

                for (int i = 0; i < count; i++)
                {
                    LogicUnitSlot unitSlot = new LogicUnitSlot(null, -1, 0);
                    unitSlot.Decode(stream);
                    this.m_unitCount.Add(unitSlot);
                }
            }
        }
コード例 #11
0
        public override int Execute(LogicLevel level)
        {
            if (level.IsReadyForAttack())
            {
                if (level.GetVillageType() == 0)
                {
                    if (LogicDataTables.GetGlobals().AllowClanCastleDeployOnObstacles())
                    {
                        if (!level.GetTileMap().IsValidAttackPos(this.m_x >> 9, this.m_y >> 9))
                        {
                            return(-2);
                        }
                    }
                    else
                    {
                        LogicTile tile = level.GetTileMap().GetTile(this.m_x >> 9, this.m_y >> 9);

                        if (tile == null)
                        {
                            return(-4);
                        }

                        if (tile.GetPassableFlag() == 0)
                        {
                            return(-3);
                        }
                    }

                    LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

                    if (playerAvatar != null)
                    {
                        if (this.m_data != null)
                        {
                            LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(0);

                            if (gameObjectManager.GetGameObjectCountByData(this.m_data) <= 0 && playerAvatar.GetAllianceCastleUsedCapacity() > 0)
                            {
                                LogicAlliancePortal  alliancePortal  = (LogicAlliancePortal)LogicGameObjectFactory.CreateGameObject(this.m_data, level, level.GetVillageType());
                                LogicBunkerComponent bunkerComponent = alliancePortal.GetBunkerComponent();

                                alliancePortal.SetInitialPosition(this.m_x, this.m_y);

                                if (bunkerComponent != null)
                                {
                                    bunkerComponent.SetMaxCapacity(playerAvatar.GetAllianceCastleTotalCapacity());

                                    if (level.GetBattleLog() != null)
                                    {
                                        if (!level.GetBattleLog().HasDeployedUnits() && level.GetTotalAttackerHeroPlaced() == 0)
                                        {
                                            level.UpdateLastUsedArmy();
                                        }
                                    }

                                    if (level.GetGameMode().IsInAttackPreparationMode())
                                    {
                                        level.GetGameMode().EndAttackPreparation();
                                    }

                                    bunkerComponent.RemoveAllUnits();

                                    LogicArrayList <LogicUnitSlot> allianceUnits = playerAvatar.GetAllianceUnits();

                                    for (int i = 0; i < allianceUnits.Size(); i++)
                                    {
                                        LogicUnitSlot       slot = allianceUnits[i];
                                        LogicCombatItemData data = (LogicCombatItemData)slot.GetData();

                                        if (data != null)
                                        {
                                            int count = slot.GetCount();

                                            if (data.GetCombatItemType() == LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER)
                                            {
                                                for (int j = 0; j < count; j++)
                                                {
                                                    if (bunkerComponent.GetUnusedCapacity() >= data.GetHousingSpace())
                                                    {
                                                        bunkerComponent.AddUnitImpl(data, slot.GetLevel());
                                                    }
                                                }
                                            }
                                        }
                                        else
                                        {
                                            Debugger.Error("LogicPlaceAlliancePortalCommand::execute - NULL alliance character");
                                        }
                                    }
                                }

                                gameObjectManager.AddGameObject(alliancePortal, -1);

                                return(0);
                            }
                        }
                    }

                    return(-5);
                }
            }

            return(-1);
        }