/// <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 void RemoveTrainedUnit(LogicCombatItemData data) { int idx = -1; for (int i = 0; i < this.m_slots.Size(); i++) { if (this.m_slots[i].GetData() == data) { if (this.m_slots[i].IsTerminate()) { idx = i; break; } } } if (idx != -1) { LogicUnitProductionSlot slot = this.m_slots[idx]; if (slot.GetCount() > 1) { slot.SetCount(slot.GetCount() - 1); } else { this.m_slots.Remove(idx); slot.Destruct(); slot = null; } this.MergeSlots(); if (this.GetWaitingForSpaceUnit() != null) { this.ProductionCompleted(false); } } }
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; } }