예제 #1
0
    /// <summary>
    /// 交换
    /// </summary>
    /// <param name="buttomObj"></param>
    private void Exchange(GameObject buttomObj)
    {
        //下面的装备
        HeroEquip buttomEquip = buttomObj.GetComponent <HeroEquip>();
        //获取下面装备的父物体
        EquipBox buttonEqupBox = buttomObj.transform.parent.GetComponent <EquipBox>();
        //当前格子的父对象
        EquipBox topEqupBox = parent.GetComponent <EquipBox>();

        //两个装备目前都在背包里
        if ((buttonEqupBox.equipType != EquipType.None ||
             topEqupBox.equipType != EquipType.None) &&
            (buttomEquip.equipType != equipType))
        {
            //回到原始位置
            BackToOrigin();
        }
        else
        {
            //下面的格子接收当前装备
            buttonEqupBox.SetEquip(this);
            //上面所在的格子接收下面的装备
            topEqupBox.SetEquip(buttomEquip);
        }
    }
예제 #2
0
 void Init()
 {
     if (m_Weapon == null)
     {
         m_Weapon = NGUITools.AddChild(m_WeaponIndicator, HeroEquipPrefab).GetComponent <HeroEquip>();
     }
     if (m_Armor == null)
     {
         m_Armor = NGUITools.AddChild(m_ArmorIndicator, HeroEquipPrefab).GetComponent <HeroEquip>();
     }
     m_Weapon.Init(m_Creature, m_Creature.Weapon, StuffItemPrefab, EquipEnchantCallback);
     m_Armor.Init(m_Creature, m_Creature.Armor, StuffItemPrefab, EquipEnchantCallback);
 }
예제 #3
0
 /// <summary>
 /// 设置装备到当前格子
 /// </summary>
 public void SetEquip(HeroEquip heroEquip)
 {
     //如果当前格子没有类型限制,或,当前格子的类型限制与装备类型匹配
     if (equipType == EquipType.None || equipType == heroEquip.equipType)
     {
         //设置进去
         heroEquip.SetToBox(transform);
     }
     else
     {
         //回调原始位置
         heroEquip.BackToOrigin();
     }
 }
예제 #4
0
        /// <summary>
        /// Method will create EquipHero BotTasks that will use resources needed
        /// </summary>
        /// <param name="acc">Account</param>
        /// <param name="vill">Village to use resources in</param>
        /// <param name="neededRes">Needed resources</param>
        /// <param name="heroRes">Hero resources</param
        /// <param name="task">Potential BuildingTask that requires the resources</param>
        private static HeroEquip UseHeroResources(Account acc, Village vill, ref long[] neededRes, long[] heroRes, BuildingTask task = null)
        {
            var useRes = new List <(Classificator.HeroItemEnum, int)>();

            for (int i = 0; i < 4; i++)
            {
                if (neededRes[i] == 0 || heroRes[i] == 0)
                {
                    continue;
                }

                long resToBeUsed = RoundUpTo100(neededRes[i]);
                if (heroRes[i] < resToBeUsed)
                {
                    resToBeUsed = heroRes[i];
                }
                neededRes[i] -= resToBeUsed;

                HeroItemEnum item = HeroItemEnum.Others_Wood_0;
                switch (i)
                {
                case 0:
                    item = HeroItemEnum.Others_Wood_0;
                    break;

                case 1:
                    item = HeroItemEnum.Others_Clay_0;
                    break;

                case 2:
                    item = HeroItemEnum.Others_Iron_0;
                    break;

                case 3:
                    item = HeroItemEnum.Others_Crop_0;
                    break;
                }
                useRes.Add((item, (int)resToBeUsed));
            }

            var heroEquip = new HeroEquip()
            {
                Items     = useRes,
                ExecuteAt = DateTime.Now.AddHours(-2), // -2 since sendRes is -1
                Vill      = vill
            };

            TaskExecutor.AddTask(acc, heroEquip);

            // A BuildTask needed the resources. If it was auto-build res fields task, make a new
            // general building task - so resources actually get used for intended building upgrade
            if (task != null && task.TaskType == Classificator.BuildingType.AutoUpgradeResFields)
            {
                var building = vill.Build.Buildings.FirstOrDefault(x => x.Id == task.BuildingId);
                var lvl      = building.Level;
                if (building.UnderConstruction)
                {
                    lvl++;
                }
                BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask()
                {
                    TaskType   = Classificator.BuildingType.General,
                    Building   = task.Building,
                    BuildingId = task.BuildingId,
                    Level      = ++lvl
                }, false);
            }

            return(heroEquip);
        }