internal override void Decode()
 {
     this.X    = this.Reader.ReadInt32();
     this.Y    = this.Reader.ReadInt32();
     this.Unit = (Combat_Item)CSV.Tables.GetWithGlobalID(this.Reader.ReadInt32());
     this.Tick = this.Reader.ReadUInt32();
 }
Esempio n. 2
0
 internal void StartUpgrading(Combat_Item cid)
 {
     if (CanStartUpgrading(cid))
     {
         Unit  = cid;
         Timer = new Timer();
         Timer.StartTimer(Parent.Level.Avatar.LastTick, GetTotalSeconds());
     }
 }
Esempio n. 3
0
 internal void FinishUpgrading()
 {
     if (Unit != null)
     {
         var ca    = Parent.Level.Avatar;
         var level = ca.GetUnitUpgradeLevel(Unit);
         ca.SetUnitUpgradeLevel(Unit, level + 1);
     }
     Timer = null;
     Unit  = null;
 }
Esempio n. 4
0
        internal int Get_Unit_Count_V2(Combat_Item cd)
        {
            var result = 0;
            var index  = GetDataIndex(this.Units2, cd);

            if (index != -1)
            {
                result = this.Units2[index].Count;
            }
            return(result);
        }
Esempio n. 5
0
        internal void Set_Unit_Count_V2(Combat_Item cd, int count)
        {
            var index = GetDataIndex(this.Units2, cd);

            if (index != -1)
            {
                this.Units2[index].Count = count;
            }
            else
            {
                var ds = new Slot(cd.GetGlobalID(), count);
                this.Units2.Add(ds);
            }
        }
        internal int GetUnitTypeIndex(Combat_Item cd)
        {
            var index = -1;

            for (var i = 0; i < this.Units.Count; i++)
            {
                if (this.Units[i].Data == cd)
                {
                    index = i;
                    break;
                }
            }
            return(index);
        }
Esempio n. 7
0
        public void SetUnitUpgradeLevel(Combat_Item cd, int level)
        {
            switch (cd.GetCombatItemType())
            {
            case 2:
            {
                int index = GetDataIndex(this.Heroes_Upgrades, cd);
                if (index != -1)
                {
                    this.Heroes_Upgrades[index].Count = level;
                }
                else
                {
                    Slot ds = new Slot(cd.GetGlobalID(), level);
                    this.Heroes_Upgrades.Add(ds);
                }
                break;
            }

            case 1:
            {
                int index = GetDataIndex(this.Spell_Upgrades, cd);
                if (index != -1)
                {
                    this.Spell_Upgrades[index].Count = level;
                }
                else
                {
                    Slot ds = new Slot(cd.GetGlobalID(), level);
                    this.Spell_Upgrades.Add(ds);
                }
                break;
            }

            default:
            {
                int index = GetDataIndex(this.Unit_Upgrades, cd);
                if (index != -1)
                {
                    this.Unit_Upgrades[index].Count = level;
                }
                else
                {
                    Slot ds = new Slot(cd.GetGlobalID(), level);
                    this.Unit_Upgrades.Add(ds);
                }
                break;
            }
            }
        }
        internal bool CanAddUnit(Combat_Item cd)
        {
            var result = false;

            if (cd != null)
            {
                var cm           = GetParent.Level.GetComponentManager;
                var maxCapacity  = cm.GetTotalMaxHousingV2();
                var usedCapacity = cm.GetTotalUsedHousing();
                var housingSpace = cd.GetHousingSpace();
                if (GetUsedCapacity() < this.MaxCapacity)
                {
                    result = maxCapacity >= usedCapacity + housingSpace;
                }
            }
            return(result);
        }
Esempio n. 9
0
        internal bool CanStartUpgrading(Combat_Item data)
        {
            var result = false;

            if (Unit == null)
            {
                if (Parent.ClassId == 0)
                {
                    var b  = (Building)Parent;
                    var ca = Parent.Level.Avatar;
                    var cm = Parent.Level.GetComponentManager();
                    var maxProductionBuildingLevel = data.GetCombatItemType() == 1
                        ? cm.GetMaxSpellForgeLevel()
                        : cm.GetMaxBarrackLevel();
                    if (ca.GetUnitUpgradeLevel(data) < data.GetUpgradeLevelCount() - 1)
                    {
                        if (maxProductionBuildingLevel >= data.GetRequiredProductionHouseLevel() - 1)
                        {
                            result = b.GetUpgradeLevel >=
                                     data.GetRequiredLaboratoryLevel(ca.GetUnitUpgradeLevel(data) + 1) - 1;
                        }
                    }
                }
                else if (Parent.ClassId == 7)
                {
                    var b  = (Builder_Building)Parent;
                    var ca = Parent.Level.Avatar;
                    var cm = Parent.Level.GetComponentManager();
                    var maxProductionBuildingLevel = data.GetCombatItemType() == 1
                        ? cm.GetMaxSpellForgeLevel()
                        : cm.GetMaxBarrackLevel();
                    if (ca.GetUnitUpgradeLevel(data) < data.GetUpgradeLevelCount() - 1)
                    {
                        if (maxProductionBuildingLevel >= data.GetRequiredProductionHouseLevel() - 1)
                        {
                            result = b.GetUpgradeLevel >=
                                     data.GetRequiredLaboratoryLevel(ca.GetUnitUpgradeLevel(data) + 1) - 1;
                        }
                    }
                }
            }
            return(result);
        }
 internal void AddUnitImpl(Combat_Item cd)
 {
     //if (CanAddUnit(cd))
     {
         var ca         = GetParent.Level.Avatar;
         var UnitInCamp = ((Characters)cd).UnitsInCamp[ca.GetUnitUpgradeLevel(cd)];
         var unitIndex  = GetUnitTypeIndex(cd);
         if (unitIndex == -1)
         {
             var us = new DataSlot(cd, UnitInCamp);
             this.Units.Add(us);
         }
         else
         {
             this.Units[unitIndex].Value += UnitInCamp;
         }
         var unitCount = ca.Get_Unit_Count_V2(cd);
         ca.Set_Unit_Count_V2(cd, unitCount + UnitInCamp);
     }
 }
        public void RemoveUnitsImpl(Combat_Item cd, int count)
        {
            var unitIndex = GetUnitTypeIndex(cd);

            if (unitIndex != -1)
            {
                var us = this.Units[unitIndex];
                if (us.Value <= count)
                {
                    this.Units.Remove(us);
                }
                else
                {
                    us.Value -= count;
                }
                var ca        = GetParent.Level.Avatar;
                var unitCount = ca.Get_Unit_Count_V2(cd);
                ca.Set_Unit_Count_V2(cd, unitCount - count);
            }
        }
Esempio n. 12
0
        public int GetUnitUpgradeLevel(Combat_Item cd)
        {
            int result = 0;

            switch (cd.GetCombatItemType())
            {
            case 2:
            {
                int index = GetDataIndex(this.Heroes_Upgrades, cd);
                if (index != -1)
                {
                    result = this.Heroes_Upgrades[index].Count;
                }
                break;
            }

            case 1:
            {
                int index = GetDataIndex(this.Spell_Upgrades, cd);
                if (index != -1)
                {
                    result = this.Spell_Upgrades[index].Count;
                }
                break;
            }

            default:
            {
                int index = GetDataIndex(this.Unit_Upgrades, cd);
                if (index != -1)
                {
                    result = this.Unit_Upgrades[index].Count;
                }
                break;
            }
            }
            return(result);
        }
Esempio n. 13
0
        public override void Load(JObject jsonObject)
        {
            var unitUpgradeObject = (JObject)jsonObject["unit_upg"];

            if (unitUpgradeObject != null)
            {
                Timer = new Timer();
                var remainingTime    = unitUpgradeObject["t"].ToObject <int>();
                var remainingEndTime = unitUpgradeObject["t_end"].ToObject <int>();

                var startTime = (int)TimeUtils.ToUnixTimestamp(Parent.Level.Avatar.LastTick);
                var duration  = remainingEndTime - startTime;

                if (duration < 0)
                {
                    duration = 0;
                }

                Timer.StartTimer(Parent.Level.Avatar.LastTick, duration);

                var id = unitUpgradeObject["id"].ToObject <int>();
                Unit = (Combat_Item)CSV.Tables.GetWithGlobalID(id);
            }
        }
 public int GetUnitCountByData(Combat_Item cd)
 {
     return(this.Units.Where(t => t.Data == cd).Sum(t => t.Value));
 }
Esempio n. 15
0
 public Unit_Upgrade_Component(Game_Object go) : base(go)
 {
     Timer = null;
     Unit  = null;
 }
 public Unit_Upgrade_Component(GameObject go) : base(go)
 {
     this.Timer = null;
     this.Unit  = null;
 }
 public void RemoveUnits(Combat_Item cd, int count)
 {
     RemoveUnitsImpl(cd, count);
 }
 internal void AddUnit(Combat_Item cd)
 {
     AddUnitImpl(cd);
 }