コード例 #1
0
ファイル: XmlTool.cs プロジェクト: AlayaElla/sangharama
    public ArrayList loadItemXmlToArray()
    {
        //保存路径
        string filepath = "Config/Materiral/Item";

        string _result = Resources.Load(filepath).ToString();

        ArrayList itemList = new ArrayList();

        XmlDocument xmlDoc = new XmlDocument();

        xmlDoc.LoadXml(_result);

        XmlNodeList nodeList = xmlDoc.SelectSingleNode("ItemList").ChildNodes;

        foreach (XmlElement item in nodeList)
        {
            Materiral.Items _items = new Materiral.Items();

            //读取node内属性,把string转化为对应的属性
            if (item.GetAttribute("ID") != "")
            {
                _items.ID = int.Parse(item.GetAttribute("ID"));
            }
            if (item.GetAttribute("Name") != "")
            {
                _items.Name = item.GetAttribute("Name");
            }
            if (item.GetAttribute("Image") != "")
            {
                _items.IMG = item.GetAttribute("Image");
            }
            if (item.GetAttribute("Type") != "")
            {
                _items.Type = int.Parse(item.GetAttribute("Type"));
            }
            if (item.GetAttribute("Price") != "")
            {
                _items.Price = int.Parse(item.GetAttribute("Price"));
            }
            if (item.GetAttribute("Property") != "")
            {
                string[] _proStr = item.GetAttribute("Property").Split(',');
                _items.Property = new int[_proStr.Length];
                for (int i = 0; i < _proStr.Length; i++)
                {
                    _items.Property[i] = int.Parse(_proStr[i]);
                }
            }
            if (item.GetAttribute("des") != "")
            {
                _items.Des = item.GetAttribute("des");
            }

            //添加进itemList中
            itemList.Add(_items);
        }
        return(itemList);
    }
コード例 #2
0
    static public int AddGoodsByID(int materialType, int ID)
    {
        Goods newgoods = new Goods();

        newgoods.ID       = ID;
        newgoods.Number   = 1;
        newgoods.Property = Materiral.GetMaterialProperty(materialType, ID);
        newgoods.Quality  = 80;

        if (materialType == 0)
        {
            Materiral.Items _item = Materiral.FindItemByID(ID);
            newgoods.Name  = _item.Name;
            newgoods.Price = _item.Price;
            newgoods.Type  = _item.Type;
        }   //item
        else if (materialType == 1)
        {
            Materiral.Minds _mind = Materiral.FindMindByID(ID);
            newgoods.Name          = _mind.Name;
            newgoods.Price         = _mind.Price;
            newgoods.Type          = _mind.Type;
            newgoods.MateriralType = 1;
        }   //mind
        else if (materialType == 2)
        {
            Materiral.SpecialItem _sepcial = Materiral.FindSpecialItemByID(ID);
            newgoods.Name          = _sepcial.Name;
            newgoods.Price         = _sepcial.Price;
            newgoods.Type          = _sepcial.Type;
            newgoods.MateriralType = 2;
        }   //specail

        //添加物品
        int uid = AddGoods(newgoods);

        return(uid);
    }
コード例 #3
0
    //设置合成界面槽的信息和位置
    void SetSlot(Recipe.RecipeMap map)
    {
        int num = map.Slots.Length;

        //TODO:游戏道具的名称和ID,以及按钮的表现效果
        Vector3 base_point  = new Vector3(0, -100, 0);
        int     targetAngel = 0;

        SlotList = new Dictionary <int, SlotBox>();

        for (int i = 0; i < num; i++)
        {
            GameObject recipeSlot = Instantiate(btn_recipeSlot);
            recipeSlot.transform.SetParent(recipeSlotsList.transform, false);

            //设置按钮位置
            targetAngel = 360 / num * i;

            Vector3 target_pos = Quaternion.Euler(0, 0, targetAngel) * base_point;
            recipeSlot.transform.localPosition = target_pos;

            //判断slot中材料的类型,0为固定材料,1为材料种类
            if (map.Slots[i].SlotType == Recipe.SlotTypeList.Material)
            {
                //固定材料
                if (map.Slots[i].MatType == 0)  //Item
                {
                    Materiral.Items _item = Materiral.FindItemByID(map.Slots[i].MatId);

                    recipeSlot.name = i.ToString();
                    recipeSlot.transform.Find("Text").GetComponent <Text>().text            = "[" + _item.Name + "]";
                    recipeSlot.transform.Find("Bottom/Image").GetComponent <Image>().sprite = Materiral.GetIconByName(_item.IMG);
                    recipeSlot.transform.Find("Bottom/Image").GetComponent <Image>().color  = new Color(1, 1, 1, 0.5f);
                }
                else if (map.Slots[i].MatType == 1)  //Mind
                {
                    Materiral.Minds _mind = Materiral.FindMindByID(map.Slots[i].MatId);
                    recipeSlot.name = i.ToString();
                    recipeSlot.transform.Find("Text").GetComponent <Text>().text            = "[" + _mind.Name + "]";
                    recipeSlot.transform.Find("Bottom/Image").GetComponent <Image>().sprite = Materiral.GetIconByName(_mind.IMG);
                    recipeSlot.transform.Find("Bottom/Image").GetComponent <Image>().color  = new Color(1, 1, 1, 0.5f);
                }
            }
            else if (map.Slots[i].SlotType == Recipe.SlotTypeList.MaterialType)
            {
                //材料类型
                recipeSlot.name = i.ToString();

                int typeID = map.Slots[i].MatType;
                Materiral.MaterialType type = Materiral.FindTypeNameByID(typeID);
                recipeSlot.transform.Find("Text").GetComponent <Text>().text            = "<color=red>[" + type.Name + "]\n(类型)</color>";
                recipeSlot.transform.Find("Bottom/Image").GetComponent <Image>().sprite = Materiral.GetIconByName(type.IMG);
                recipeSlot.transform.Find("Bottom/Image").GetComponent <Image>().color  = new Color(1, 1, 1, 0.5f);
            }
            else
            {
                Debug.Log("Can't find recipe slots!");
            }

            //设置参数容器中的参数
            Parameter.Box parameter = new Parameter.Box();
            parameter.ID       = i; //ID为slot的序号
            parameter.callback = ClickInBag;
            parameter.obj      = map.Slots[i];
            parameter.subobj   = SlotList;

            //添加记录到合成系统用容器中
            SlotBox slot = new SlotBox();
            slot.button = recipeSlot;
            SlotList.Add(i, slot);

            //设置点击事件
            GameObject _slot = recipeSlot.transform.Find("Bottom/Image").gameObject;
            EventTriggerListener.Get(_slot).parameter          = parameter;
            EventTriggerListener.Get(_slot).onClickByParameter = OpenBag;
        }
    }
コード例 #4
0
    //通过进入地图的id筛选出道具,然后通过权重选出拾取的东西。
    //如果以后会有专门进入地图的设定的话,则可以吧判断地图id筛选道具列表的方法单独移出。
    public void CollectionAction(int ap, RectTransform rect)
    {
        Debug.Log("mine:" + ap);

        //筛选出可以掉落的道具
        int       mapid = ap;
        ArrayList List  = new ArrayList();

        int max = 0;

        foreach (CollectionMap materiral in CollectionList)
        {
            if (materiral.Map == mapid)
            {
                List.Add(materiral);
                //获取随机范围
                max += materiral.Weight;
            }
        }

        //随机权重,选出拾取哪个道具
        CharBag.Goods dropMa = new CharBag.Goods();
        dropMa.Property = new int[4];

        int point = Random.Range(1, max);
        int check = 0;

        foreach (CollectionMap materiral in List)
        {
            check += materiral.Weight;

            if (check >= point)
            {
                //指定掉落的材料
                dropMa.MateriralType = materiral.MateriralType;

                dropMa.ID = materiral.ID;
                //指定数量,后期会修改为需要指定数量
                dropMa.Number = 1;

                //随机品质
                dropMa.Quality = Random.Range(materiral.RandomQuality[0], materiral.RandomQuality[1]);

                //随机属性;随机4个属性
                int random_max = 0;
                int propcount  = 0;
                for (int i = 0; i < materiral.RandomProperty.Length / 2; i++)
                {
                    random_max += materiral.RandomProperty[i, 1];
                }

                for (int index = 0; index < 4; index++)
                {
                    if (materiral.PropertyProbability < Random.Range(1, 100))
                    {
                        continue;
                    }

                    int _point = Random.Range(1, random_max);
                    int _check = 0;
                    //指定随机属性
                    for (int i = 0; i < materiral.RandomProperty.Length / 2; i++)
                    {
                        _check += materiral.RandomProperty[i, 1];
                        if (_check >= _point)
                        {
                            dropMa.Property[propcount] = materiral.RandomProperty[i, 0];
                            propcount++;
                            break;
                        }
                    }
                }
                break;
            } //endif
        }     //endforech

        //获取名称
        if (dropMa.MateriralType == 0)
        {
            Materiral.Items dorp_item = Materiral.FindItemByID(dropMa.ID);
            dropMa.Name = dorp_item.Name;
            //设定基础价格,之后还需要计算
            dropMa.Price = dorp_item.Price;

            //获取type
            dropMa.Type = Materiral.GetTypeByMaterialID(dropMa.MateriralType, dropMa.ID);
        }   //item
        else if (dropMa.MateriralType == 1)
        {
            Materiral.Minds drop_mind = Materiral.FindMindByID(dropMa.ID);
            dropMa.Name = drop_mind.Name;
            //设定基础价格,之后还需要计算
            dropMa.Price = drop_mind.Price;

            //获取type
            dropMa.Type = Materiral.GetTypeByMaterialID(dropMa.MateriralType, dropMa.ID);
        }   //mind

        //计算价格
        dropMa = CharBag.SetPrice(dropMa);
        //添加物品
        dropMa.UID = CharBag.AddGoods(dropMa);

        questManager.CheckQuestListWithGoods(QuestManager.QuestTypeList.CollectGoods, dropMa, ap);
        //更新物品信息
        PlayerInfo.AddGoodsInfo(dropMa.MateriralType, dropMa.ID, PlayerInfo.GoodsInfoType.CollectCount);
        eventmanager.PreCheckEventList(1);
        ShowMaterialIcon(dropMa, rect);
    }