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); }
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); }
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); }
/// <summary> /// Tries to merge slots. /// </summary> public void MergeSlots() { LogicAvatar homeOwnerAvatar = this._level.GetHomeOwnerAvatar(); if (this._slots.Count > 0) { if (this._slots.Count > 1) { for (int i = 1; i < this._slots.Count; i++) { LogicUnitProductionSlot slot1 = this._slots[i]; LogicUnitProductionSlot slot2 = this._slots[i - 1]; if (slot1.GetData() == slot2.GetData()) { if (slot1.IsTerminate() == slot2.IsTerminate()) { this._slots.Remove(i--); slot2.SetCount(slot2.GetCount() + slot1.GetCount()); slot1.Destruct(); slot1 = null; } } } } } LogicComponentManager componentManager = this._level.GetComponentManagerAt(this._villageType); Int32 totalCapcity = componentManager.GetTotalMaxHousing(this._unitProductionType != 3 ? 1 : 0); Int32 usedCapacity = this._unitProductionType == 25 ? homeOwnerAvatar.GetSpellsTotalCapacity() : homeOwnerAvatar.GetUnitsTotalCapacity(); Int32 freeCapacity = totalCapcity - usedCapacity; for (int i = 0; i < this._slots.Count; i++) { LogicUnitProductionSlot slot = this._slots[i]; LogicCombatItemData data = (LogicCombatItemData)slot.GetData(); int housingSpace = data.GetHousingSpace() * slot.GetCount(); if (freeCapacity < housingSpace) { if (slot.GetCount() > 0 && housingSpace / data.GetHousingSpace() > 0) { if (slot.GetCount() > housingSpace / data.GetHousingSpace()) { this._slots.Add(i + 1, new LogicUnitProductionSlot(data, slot.GetCount() - housingSpace / data.GetHousingSpace(), slot.IsTerminate())); } } break; } freeCapacity -= housingSpace; } }
public LogicCombatItemData GetWaitingForSpaceUnit() { if (this.m_slots.Size() > 0) { LogicUnitProductionSlot slot = this.m_slots[0]; if (slot.IsTerminate() || this.m_timer != null && this.m_timer.GetRemainingSeconds(this.m_level.GetLogicTime()) == 0) { return((LogicCombatItemData)slot.GetData()); } } return(null); }
public void Save(LogicJSONObject root) { LogicJSONObject jsonObject = new LogicJSONObject(); if (this.m_timer != null) { jsonObject.Put("t", new LogicJSONNumber(this.m_timer.GetRemainingSeconds(this.m_level.GetLogicTime()))); } if (this.m_slots.Size() > 0) { LogicJSONArray slotArray = new LogicJSONArray(); for (int i = 0; i < this.m_slots.Size(); i++) { LogicUnitProductionSlot slot = this.m_slots[i]; if (slot != null) { LogicJSONObject slotObject = new LogicJSONObject(); slotObject.Put("id", new LogicJSONNumber(slot.GetData().GetGlobalID())); slotObject.Put("cnt", new LogicJSONNumber(slot.GetCount())); if (slot.IsTerminate()) { slotObject.Put("t", new LogicJSONBoolean(true)); } slotArray.Add(slotObject); } } jsonObject.Put("slots", slotArray); } if (this.m_boostTimer != null) { jsonObject.Put("boost_t", new LogicJSONNumber(this.m_boostTimer.GetRemainingSeconds(this.m_level.GetLogicTime()))); } if (this.m_boostPause) { jsonObject.Put("boost_pause", new LogicJSONBoolean(true)); } root.Put("unit_prod", jsonObject); }
public int GetWaitingForSpaceUnitCount(LogicCombatItemData data) { int count = 0; for (int i = 0; i < this.m_slots.Size(); i++) { LogicUnitProductionSlot slot = this.m_slots[i]; if (slot.GetData() == data) { if (slot.IsTerminate()) { count += slot.GetCount(); } } } return(count); }
public void MergeSlots() { LogicAvatar homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar(); if (this.m_slots.Size() > 0) { if (this.m_slots.Size() > 1) { for (int i = 1; i < this.m_slots.Size(); i++) { LogicUnitProductionSlot slot1 = this.m_slots[i]; LogicUnitProductionSlot slot2 = this.m_slots[i - 1]; if (slot1.GetData() == slot2.GetData()) { if (slot1.IsTerminate() == slot2.IsTerminate()) { this.m_slots.Remove(i--); slot2.SetCount(slot2.GetCount() + slot1.GetCount()); slot1.Destruct(); slot1 = null; } } } } } LogicComponentManager componentManager = this.m_level.GetComponentManagerAt(this.m_villageType); int usedCapacity = this.m_unitProductionType == LogicDataType.SPELL ? homeOwnerAvatar.GetSpellsTotalCapacity() : homeOwnerAvatar.GetUnitsTotalCapacity(); int totalCapacity = componentManager.GetTotalMaxHousing(this.m_unitProductionType != LogicDataType.CHARACTER ? 1 : 0); int freeCapacity = totalCapacity - usedCapacity; for (int i = 0, j = freeCapacity; i < this.m_slots.Size(); i++) { LogicUnitProductionSlot slot = this.m_slots[i]; LogicCombatItemData data = (LogicCombatItemData)slot.GetData(); int count = slot.GetCount(); int housingSpace = data.GetHousingSpace() * count; if (j < housingSpace) { if (count > 1) { int maxInProduction = j / data.GetHousingSpace(); if (maxInProduction > 0) { int inQueue = count - maxInProduction; if (inQueue > 0) { slot.SetCount(maxInProduction); this.m_slots.Add(i + 1, new LogicUnitProductionSlot(data, inQueue, slot.IsTerminate())); } } } break; } j -= housingSpace; } }