Esempio n. 1
0
        public int GetTotalSeconds()
        {
            LogicUnitProductionSlot slot = null;

            for (int i = 0; i < this.m_slots.Size(); i++)
            {
                LogicUnitProductionSlot tmp = this.m_slots[i];

                if (!tmp.IsTerminate())
                {
                    slot = tmp;
                    break;
                }
            }

            if (slot != null)
            {
                LogicAvatar         homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar();
                LogicCombatItemData data            = (LogicCombatItemData)slot.GetData();

                return(data.GetTrainingTime(homeOwnerAvatar.GetUnitUpgradeLevel(data), this.m_level, 0));
            }

            return(0);
        }
Esempio n. 2
0
        public bool TrainingFinished()
        {
            bool success = false;

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

            if (this.m_slots.Size() > 0)
            {
                LogicUnitProductionSlot prodSlot = this.GetCurrentlyTrainedSlot();
                int prodIdx = this.GetCurrentlyTrainedIndex();

                if (prodSlot != null)
                {
                    if (prodSlot.GetCount() == 1)
                    {
                        prodSlot.SetTerminate(true);
                    }
                    else
                    {
                        prodSlot.SetCount(prodSlot.GetCount() - 1);

                        LogicUnitProductionSlot previousSlot = this.m_slots[LogicMath.Max(prodIdx - 1, 0)];

                        if (previousSlot != null &&
                            previousSlot.IsTerminate() &&
                            previousSlot.GetData().GetGlobalID() == prodSlot.GetData().GetGlobalID())
                        {
                            previousSlot.SetCount(previousSlot.GetCount() + 1);
                        }
                        else
                        {
                            this.m_slots.Add(prodIdx, new LogicUnitProductionSlot(prodSlot.GetData(), 1, true));
                        }
                    }
                }

                if (this.m_slots.Size() > 0)
                {
                    LogicCombatItemData nextProductionData = this.GetCurrentlyTrainedUnit();

                    if (nextProductionData != null && this.m_timer == null)
                    {
                        this.m_timer = new LogicTimer();
                        this.m_timer.StartTimer(nextProductionData.GetTrainingTime(this.m_level.GetHomeOwnerAvatar().GetUnitUpgradeLevel(nextProductionData), this.m_level, 0),
                                                this.m_level.GetLogicTime(), false, -1);
                        success = true;
                    }
                }
            }

            this.MergeSlots();

            return(success);
        }
Esempio n. 3
0
        public int AddUnitToQueue(LogicCombatItemData data)
        {
            if (data != null)
            {
                if (this.CanAddUnitToQueue(data, false))
                {
                    LogicAvatar homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar();

                    for (int i = this.m_slots.Size() - 1; i >= 0; i--)
                    {
                        LogicUnitProductionSlot tmp = this.m_slots[i];

                        if (tmp != null)
                        {
                            if (tmp.GetData() == data)
                            {
                                tmp.SetCount(tmp.GetCount() + 1);
                                this.MergeSlots();

                                return(i);
                            }

                            break;
                        }
                    }

                    this.m_slots.Add(new LogicUnitProductionSlot(data, 1, false));
                    this.MergeSlots();

                    if (this.m_slots.Size() > 0)
                    {
                        LogicCombatItemData productionData = this.GetCurrentlyTrainedUnit();

                        if (productionData != null && this.m_timer == null)
                        {
                            this.m_timer = new LogicTimer();
                            this.m_timer.StartTimer(productionData.GetTrainingTime(homeOwnerAvatar.GetUnitUpgradeLevel(productionData), this.m_level, 0),
                                                    this.m_level.GetLogicTime(), false, -1);
                        }
                    }
                }
            }
            else
            {
                Debugger.Error("LogicUnitProduction - Trying to add NULL character!");
            }

            return(-1);
        }
Esempio n. 4
0
        public bool DragSlot(int slotIdx, int dragIdx)
        {
            this.m_locked = false;

            if (slotIdx > -1 && slotIdx < this.m_slots.Size())
            {
                LogicCombatItemData     productionData = this.GetCurrentlyTrainedUnit();
                LogicUnitProductionSlot slot           = this.m_slots[slotIdx];

                this.m_slots.Remove(slotIdx);

                if (slot != null)
                {
                    if (slotIdx <= dragIdx)
                    {
                        dragIdx -= 1;
                    }

                    if (dragIdx >= 0 && dragIdx <= this.m_slots.Size())
                    {
                        this.m_slots.Add(dragIdx, slot);
                        this.MergeSlots();

                        LogicCombatItemData prodData = this.GetCurrentlyTrainedUnit();
                        int prodIdx = this.GetCurrentlyTrainedIndex();

                        if (productionData != prodData && (dragIdx >= prodIdx || prodIdx == slotIdx || prodIdx == dragIdx + 1))
                        {
                            if (this.m_timer != null)
                            {
                                this.m_timer.Destruct();
                                this.m_timer = null;
                            }

                            LogicAvatar homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar();

                            this.m_timer = new LogicTimer();
                            this.m_timer.StartTimer(prodData.GetTrainingTime(homeOwnerAvatar.GetUnitUpgradeLevel(prodData), this.m_level, 0),
                                                    this.m_level.GetLogicTime(), false, -1);
                        }
                    }

                    return(true);
                }
            }

            return(false);
        }
Esempio n. 5
0
        public int GetTotalRemainingSeconds()
        {
            LogicAvatar           homeOwnerAvatar  = this.m_level.GetHomeOwnerAvatar();
            LogicComponentManager componentManager = this.m_level.GetComponentManagerAt(this.m_villageType);

            int totalMaxHousing   = componentManager.GetTotalMaxHousing(this.m_unitProductionType != LogicDataType.CHARACTER ? 1 : 0);
            int totalUsedCapacity = this.m_unitProductionType == LogicDataType.CHARACTER ? homeOwnerAvatar.GetUnitsTotalCapacity() : homeOwnerAvatar.GetSpellsTotalCapacity();
            int freeCapacity      = totalMaxHousing - totalUsedCapacity;
            int remainingSecs     = 0;

            for (int i = 0; i < this.m_slots.Size(); i++)
            {
                LogicUnitProductionSlot slot = this.m_slots[i];
                LogicCombatItemData     data = (LogicCombatItemData)slot.GetData();
                int housingSpace             = data.GetHousingSpace();
                int count = slot.GetCount();

                if (count > 0)
                {
                    if (i == 0)
                    {
                        if (!slot.IsTerminate() && freeCapacity - housingSpace >= 0)
                        {
                            if (this.m_timer != null)
                            {
                                remainingSecs += this.m_timer.GetRemainingSeconds(this.m_level.GetLogicTime());
                            }
                        }

                        freeCapacity -= housingSpace;
                        count        -= 1;
                    }

                    for (int j = 0; j < count; j++)
                    {
                        if (!slot.IsTerminate() && freeCapacity - housingSpace >= 0)
                        {
                            remainingSecs += data.GetTrainingTime(homeOwnerAvatar.GetUnitUpgradeLevel(data), this.m_level, 0);
                        }

                        freeCapacity -= housingSpace;
                    }
                }
            }

            return(remainingSecs);
        }
Esempio n. 6
0
        public int AddUnitToQueue(LogicCombatItemData data, int index, bool ignoreCapacity)
        {
            if (data != null)
            {
                if (this.CanAddUnitToQueue(data, ignoreCapacity))
                {
                    LogicAvatar         homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar();
                    LogicCombatItemData productionData  = this.GetCurrentlyTrainedUnit();

                    this.m_slots.Add(index, new LogicUnitProductionSlot(data, 1, false));
                    this.MergeSlots();

                    if (productionData != null)
                    {
                        if (this.GetCurrentlyTrainedUnit() == data || this.GetCurrentlyTrainedIndex() != index)
                        {
                            return(index);
                        }
                    }
                    else
                    {
                        productionData = this.GetCurrentlyTrainedUnit();
                    }

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

                    this.m_timer = new LogicTimer();
                    this.m_timer.StartTimer(productionData.GetTrainingTime(homeOwnerAvatar.GetUnitUpgradeLevel(productionData), this.m_level, 0),
                                            this.m_level.GetLogicTime(), false, -1);

                    return(index);
                }
            }
            else
            {
                Debugger.Error("LogicUnitProduction - Trying to add NULL character!");
            }

            return(-1);
        }
        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");
                }
            }
        }
Esempio n. 8
0
        public bool RemoveUnit(LogicCombatItemData data, int index)
        {
            LogicUnitProductionSlot slot = null;
            bool removed = false;

            if (index > -1 &&
                this.m_slots.Size() > index &&
                this.m_slots[index].GetData() == data)
            {
                slot = this.m_slots[index];
            }
            else
            {
                index = -1;

                for (int i = 0; i < this.m_slots.Size(); i++)
                {
                    LogicUnitProductionSlot tmp = this.m_slots[i];

                    if (tmp.GetData() == data)
                    {
                        index = i;
                        break;
                    }
                }

                if (index == -1)
                {
                    return(false);
                }

                slot = this.m_slots[index];
            }

            int count = slot.GetCount();

            if (count > 0)
            {
                removed = true;
                slot.SetCount(count - 1);

                if (count == 1)
                {
                    int prodIdx = this.GetCurrentlyTrainedIndex();

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

                    this.m_slots[index].Destruct();
                    this.m_slots.Remove(index);
                }
            }

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

                if (productionSlot == null || this.m_timer != null)
                {
                    if (!removed)
                    {
                        return(false);
                    }

                    this.MergeSlots();
                }
                else
                {
                    LogicAvatar         homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar();
                    LogicCombatItemData productionData  = (LogicCombatItemData)productionSlot.GetData();

                    this.m_timer = new LogicTimer();
                    this.m_timer.StartTimer(productionData.GetTrainingTime(homeOwnerAvatar.GetUnitUpgradeLevel(productionData), this.m_level, 0), this.m_level.GetLogicTime(),
                                            false,
                                            -1);

                    if (removed)
                    {
                        this.MergeSlots();
                    }
                }
            }
            else
            {
                if (!removed)
                {
                    return(false);
                }

                this.MergeSlots();
            }

            return(true);
        }
Esempio n. 9
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");
            }
        }
Esempio n. 10
0
        public void FastForwardTime(int secs)
        {
            if (this.m_boostTimer != null && !this.m_boostPause)
            {
                int remainingSecs = this.m_boostTimer.GetRemainingSeconds(this.m_level.GetLogicTime());

                if (remainingSecs <= secs)
                {
                    this.m_boostTimer.Destruct();
                    this.m_boostTimer = null;
                }
                else
                {
                    this.m_boostTimer.StartTimer(remainingSecs - secs, this.m_level.GetLogicTime(), false, -1);
                }
            }

            if (this.GetRemainingBoostTimeSecs() > 0)
            {
                if (this.GetBoostMultiplier() >= 2 && !this.IsBoostPaused())
                {
                    secs = LogicMath.Min(secs, this.GetRemainingBoostTimeSecs()) * (this.GetBoostMultiplier() - 1) + secs;
                }

                if (this.m_timer != null)
                {
                    if (!this.IsBoostPaused())
                    {
                        this.m_timer.FastForwardSubticks(4 * this.GetBoostMultiplier() - 4);
                    }
                }
            }

            do
            {
                if (secs <= 0)
                {
                    break;
                }

                LogicUnitProductionSlot productionSlot = this.GetCurrentlyTrainedSlot();

                if (productionSlot == null)
                {
                    break;
                }

                if (this.m_timer == null)
                {
                    LogicCombatItemData productionData = (LogicCombatItemData)productionSlot.GetData();

                    this.m_timer = new LogicTimer();
                    this.m_timer.StartTimer(productionData.GetTrainingTime(this.m_level.GetHomeOwnerAvatar().GetUnitUpgradeLevel(productionData), this.m_level, 0),
                                            this.m_level.GetLogicTime(), false, -1);
                }

                int remainingSecs = this.m_timer.GetRemainingSeconds(this.m_level.GetLogicTime());

                if (secs < remainingSecs)
                {
                    this.m_timer.StartTimer(remainingSecs - secs, this.m_level.GetLogicTime(), false, -1);
                    break;
                }

                secs -= remainingSecs;
                this.m_timer.StartTimer(0, this.m_level.GetLogicTime(), false, -1);
            } while (this.ProductionCompleted(false));
        }
Esempio n. 11
0
 public int GetTrainingTime(LogicCombatItemData data)
 {
     return(data.GetTrainingTime(this.m_parent.GetLevel().GetHomeOwnerAvatar().GetUnitUpgradeLevel(data), this.m_parent.GetLevel(), 0));
 }