public bool CanAddUnitToQueue(CombatItemData cd)
 {
     //Console.WriteLine(GetMaxTrainCount());
     //Console.WriteLine(GetTotalCount());
     //Console.WriteLine(cd.GetHousingSpace());
     return (GetMaxTrainCount() >= GetTotalCount() + cd.GetHousingSpace());
 }
 public void FinishUpgrading()
 {
     if(m_vCurrentlyUpgradedUnit != null)
     {
         ClientAvatar ca = GetParent().GetLevel().GetHomeOwnerAvatar();
         int level = ca.GetUnitUpgradeLevel(m_vCurrentlyUpgradedUnit);
         ca.SetUnitUpgradeLevel(m_vCurrentlyUpgradedUnit, level + 1);
     }
     m_vTimer = null;
     m_vCurrentlyUpgradedUnit = null;
 }
 public void AddUnitImpl(CombatItemData cd, int level)
 {
     if(CanAddUnit(cd))
     {
         int unitIndex = GetUnitTypeIndex(cd, level);
         if(unitIndex == -1)
         {
             UnitSlot us = new UnitSlot(cd, level, 1);
             m_vUnits.Add(us);
         }
         else
         {
             m_vUnits[unitIndex].Count++;
         }
         ClientAvatar ca = GetParent().GetLevel().GetPlayerAvatar();
         int unitCount = ca.GetUnitCount(cd);
         ca.SetUnitCount(cd, unitCount + 1);
     }
 }
 public bool CanAddUnit(CombatItemData cd)
 {
     bool result = false;
     if(cd != null)
     {
         if(IsSpellForge)
         {
             result = (GetMaxCapacity() >= GetUsedCapacity() + cd.GetHousingSpace());
         }
         else
         {
             var cm = GetParent().GetLevel().GetComponentManager();
             int maxCapacity = cm.GetTotalMaxHousing();//GetMaxCapacity();
             int usedCapacity = cm.GetTotalUsedHousing();//GetUsedCapacity();
             int housingSpace = cd.GetHousingSpace();
             if (GetUsedCapacity() < GetMaxCapacity())
                 result = (maxCapacity >= usedCapacity + housingSpace);
         } 
     }   
     return result;
 }
 public bool CanStartUpgrading(CombatItemData cid)
 {
     bool result = false;
     if (m_vCurrentlyUpgradedUnit == null)
     {
         Building b = (Building)GetParent();
         ClientAvatar ca = GetParent().GetLevel().GetHomeOwnerAvatar();
         ComponentManager cm = GetParent().GetLevel().GetComponentManager();
         int maxProductionBuildingLevel;
         if(cid.GetCombatItemType() == 1)
             maxProductionBuildingLevel = cm.GetMaxSpellForgeLevel();
         else
             maxProductionBuildingLevel = cm.GetMaxBarrackLevel();
         if (ca.GetUnitUpgradeLevel(cid) < cid.GetUpgradeLevelCount() - 1)
         {
             if(maxProductionBuildingLevel >= cid.GetRequiredProductionHouseLevel() - 1)
             {
                 result = (b.GetUpgradeLevel() >= (cid.GetRequiredLaboratoryLevel(ca.GetUnitUpgradeLevel(cid) + 1)) - 1);
             }
         }
     }
     return result;
 }
 public void AddUnitToProductionQueue(CombatItemData cd)
 {
     if(CanAddUnitToQueue(cd))
     {
         for(int i=0;i<GetSlotCount();i++)
         {
             if ((CombatItemData)m_vUnits[i].Data == cd)
             {
                 m_vUnits[i].Value++;
                 return;
             }
         }
         DataSlot ds = new DataSlot(cd, 1);
         m_vUnits.Add(ds);
         if(m_vTimer == null)
         {
             ClientAvatar ca = GetParent().GetLevel().GetHomeOwnerAvatar();
             m_vTimer = new Timer();
             int trainingTime = cd.GetTrainingTime(ca.GetUnitUpgradeLevel(cd));
             m_vTimer.StartTimer(trainingTime, GetParent().GetLevel().GetTime());
         }
     }
 }
 public void RemoveUnit(CombatItemData cd)
 {
     int index = -1;
     if(GetSlotCount() >= 1)
     {
         for(int i=0;i<GetSlotCount();i++)
         {
             if (m_vUnits[i].Data == cd)
                 index = i;
         }
     }
     if(index != -1)
     {
         if (m_vUnits[index].Value >= 1)
         {
             m_vUnits[index].Value--;
             if (m_vUnits[index].Value == 0)
             {
                 m_vUnits.RemoveAt(index);
                 if(GetSlotCount() >= 1)
                 {
                     DataSlot ds = m_vUnits[0];
                     CombatItemData newcd = (CombatItemData)m_vUnits[0].Data;
                     ClientAvatar ca = GetParent().GetLevel().GetHomeOwnerAvatar();
                     m_vTimer = new Timer();
                     int trainingTime = newcd.GetTrainingTime(ca.GetUnitUpgradeLevel(newcd));
                     m_vTimer.StartTimer(trainingTime, GetParent().GetLevel().GetTime());
                 }
             }
         }
     }    
 }
Example #8
0
 public void SetUnitUpgradeLevel(CombatItemData cd, int level)
 {
     switch(cd.GetCombatItemType())
     {
         case 2:
             {
                 int index = GetDataIndex(m_vHeroUpgradeLevel, cd);
                 if (index != -1)
                     m_vHeroUpgradeLevel[index].Value = level;
                 else
                 {
                     DataSlot ds = new DataSlot(cd, level);
                     m_vHeroUpgradeLevel.Add(ds);
                 }
                 break;
             }
         case 1:
             {
                 int index = GetDataIndex(m_vSpellUpgradeLevel, cd);
                 if (index != -1)
                     m_vSpellUpgradeLevel[index].Value = level;
                 else
                 {
                     DataSlot ds = new DataSlot(cd, level);
                     m_vSpellUpgradeLevel.Add(ds);
                 }
                 break;
             }
         default:
             {
                 int index = GetDataIndex(m_vUnitUpgradeLevel, cd);
                 if (index != -1)
                     m_vUnitUpgradeLevel[index].Value = level;
                 else
                 {
                     DataSlot ds = new DataSlot(cd, level);
                     m_vUnitUpgradeLevel.Add(ds);
                 }
                 break;
             }
     }
 }
Example #9
0
 public void SetUnitCount(CombatItemData cd, int count)
 {
     switch (cd.GetCombatItemType())
     {
         case 1:
             {
                 int index = GetDataIndex(m_vSpellCount, cd);
                 if (index != -1)
                     m_vSpellCount[index].Value = count;
                 else
                 {
                     DataSlot ds = new DataSlot(cd, count);
                     m_vSpellCount.Add(ds);
                 }
                 break;
             }
         default:
             {
                 int index = GetDataIndex(m_vUnitCount, cd);
                 if (index != -1)
                     m_vUnitCount[index].Value = count;
                 else
                 {
                     DataSlot ds = new DataSlot(cd, count);
                     m_vUnitCount.Add(ds);
                 }
                 break;
             }
     }
 }
Example #10
0
        public int GetUnitUpgradeLevel(CombatItemData cd)
        {
            int result = 0;
            switch(cd.GetCombatItemType())
            {
                case 2:
                    {
                        int index = GetDataIndex(m_vHeroUpgradeLevel, cd);
                        if (index != -1)
                            result = m_vHeroUpgradeLevel[index].Value;
                        break;
                    }
                case 1:
                    {
                        int index = GetDataIndex(m_vSpellUpgradeLevel, cd);
                        if (index != -1)
                            result = m_vSpellUpgradeLevel[index].Value;
                        break;
                    }

                default:
                    {
                        int index = GetDataIndex(m_vUnitUpgradeLevel, cd);
                        if (index != -1)
                            result = m_vUnitUpgradeLevel[index].Value;
                        break;
                    }
            }
            return result;
        }
Example #11
0
 public int GetUnitCount(CombatItemData cd)
 {
     int result = 0;
     if(cd.GetCombatItemType() == 1)
     {
         int index = GetDataIndex(m_vSpellCount, cd);
         if (index != -1)
             result = m_vSpellCount[index].Value;
     }
     else
     {
         int index = GetDataIndex(m_vUnitCount, cd);
         if (index != -1)
             result = m_vUnitCount[index].Value;
     }
     return result;
 }
 public int GetUnitCountByData(CombatItemData cd)
 {
     int count = 0;
     for (int i = 0; i < m_vUnits.Count; i++)
     {
         if (m_vUnits[i].UnitData == cd)
             count += m_vUnits[i].Count;
     }
     return count;
 }
        private CombatItemData m_vCurrentlyUpgradedUnit;//a1 + 16
        //a1 + 20 -- Listener?

        public UnitUpgradeComponent(GameObject go) : base(go)
        {
            m_vTimer = null;
            m_vCurrentlyUpgradedUnit = null;
        }
        public int Count;//a1 + 12

        public UnitSlot(CombatItemData cd, int level, int count)
        {
            UnitData = cd;
            Level = level;
            Count = count;
        }
        public void AddUnit(CombatItemData cd)

        {
            AddUnitImpl(cd, -1);
        }
 public void RemoveUnitsImpl(CombatItemData cd, int level, int count)
 {
     int unitIndex = GetUnitTypeIndex(cd, level);
     if (unitIndex == -1)
     {
         //Do nothing, should be empty yet
     }
     else
     {
         UnitSlot us = m_vUnits[unitIndex];
         if(us.Count <= count)
         {
             m_vUnits.Remove(us);
         }
         else
         {
             us.Count -= count;
         }
         ClientAvatar ca = GetParent().GetLevel().GetPlayerAvatar();
         int unitCount = ca.GetUnitCount(cd);
         ca.SetUnitCount(cd, unitCount - count);
     }
 }
 public void RemoveUnits(CombatItemData cd, int count)
 {
     RemoveUnitsImpl(cd,-1,count);
 }
 public int GetUnitTypeIndex(CombatItemData cd, int level)
 {
     int index = -1;
     for (int i = 0; i < m_vUnits.Count; i++)
     {
         if (m_vUnits[i].UnitData == cd)
         {
             if(m_vUnits[i].Level == level)
             {
                 index = i;
                 break;
             } 
         }
     }
     return index;
 }
        public override void Load(JObject jsonObject)
        {
            JObject unitUpgradeObject = (JObject)jsonObject["unit_upg"];
            if (unitUpgradeObject != null)
            {
                m_vTimer = new Timer();
                int remainingTime = unitUpgradeObject["t"].ToObject<int>();
                m_vTimer.StartTimer(remainingTime, GetParent().GetLevel().GetTime());

                int id = unitUpgradeObject["id"].ToObject<int>();
                m_vCurrentlyUpgradedUnit = (CombatItemData)ObjectManager.DataTables.GetDataById(id);
            }
        }
 public void Decode(BinaryReader br)
 {
     UnitData = (CombatItemData)br.ReadDataReference();
     Level = br.ReadInt32WithEndian();
     Count = br.ReadInt32WithEndian();
 }
 public void StartUpgrading(CombatItemData cid)
 {
     if(CanStartUpgrading(cid))
     {
         m_vCurrentlyUpgradedUnit = cid;
         m_vTimer = new Timer();
         m_vTimer.StartTimer(GetTotalSeconds(), GetParent().GetLevel().GetTime());
     }
 }