Exemplo n.º 1
0
    // Use this for initialization
    void Start()
    {
        m_MatItemList = new List <CSUI_MaterialGrid>();

        if (m_Entity == null)
        {
            return;
        }

        if (null != PeCreature.Instance && null != PeCreature.Instance.mainPlayer)
        {
            m_PlayerPackageCmpt = PeCreature.Instance.mainPlayer.GetCmpt <PlayerPackageCmpt>();
        }

        Tip = PELocalization.GetString(funcType == FuncType.Delete ? 82201081 : 82201082);

        //MergeSkill ms  = MergeSkill.s_tblMergeSkills.Find(
        //               delegate (MergeSkill hh)
        //                {
        //                    return hh.m_productItemId == m_Entity.ItemID;
        //                });

        Pathea.Replicator.Formula ms     = Pathea.Replicator.Formula.Mgr.Instance.FindByProductId(m_Entity.ItemID);
        List <MaterialItem>       miList = ItemProto.GetRepairMaterialList(m_Entity.ItemID);
        float percent = 0.0f;

        if (funcType == FuncType.Repair)
        {
            percent = (m_Entity.m_Info.m_Durability - m_Entity.BaseData.m_Durability) / m_Entity.m_Info.m_Durability;
        }
        else if (funcType == FuncType.Delete)
        {
            percent = m_Entity.BaseData.m_Durability / m_Entity.m_Info.m_Durability;
        }

        if (ms != null)
        {
            if (funcType == FuncType.Repair && miList != null && miList.Count > 0)
            {
                foreach (MaterialItem mi in miList)
                {
                    int count     = Mathf.CeilToInt(mi.count * percent);
                    int playerCnt = m_PlayerPackageCmpt.package.GetCount(mi.protoId);
                    CreateGrid(mi.protoId, playerCnt, count);
                    if (playerCnt < count && funcType == FuncType.Repair)
                    {
                        m_OkBtn.isEnabled = false;
                    }
                }
            }
            else
            {
                if (miList == null || miList.Count == 0)
                {
                    Debug.LogError("no ItemProto.repairMaterialList:" + m_Entity.ItemID);
                }
                List <Pathea.Replicator.Formula.Material> m_MSMIlist = ms.materials;

                foreach (Pathea.Replicator.Formula.Material msmi in m_MSMIlist)
                {
                    int count     = Mathf.CeilToInt(msmi.itemCount * percent);
                    int playerCnt = m_PlayerPackageCmpt.package.GetCount(msmi.itemId);
                    CreateGrid(msmi.itemId, playerCnt, count);
                    if (playerCnt < count && funcType == FuncType.Repair)
                    {
                        m_OkBtn.isEnabled = false;
                    }
                }

                m_MatGridRoot.repositionNow = true;
            }
        }
        else
        {
            for (int i = 0; i < m_DefItemCostsId.Length; i++)
            {
                int count     = Mathf.CeilToInt(m_DefItemCostsCnt[i] * percent);
                int playerCnt = m_PlayerPackageCmpt.package.GetCount(m_DefItemCostsId[i]);
                CreateGrid(m_DefItemCostsId[i], playerCnt, count);
                if (playerCnt < count && funcType == FuncType.Repair)
                {
                    m_OkBtn.isEnabled = false;
                }
            }

            m_MatGridRoot.repositionNow = true;
        }
    }