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); }
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"); } }