Esempio n. 1
0
    /// <summary>
    /// 获取随机词条
    /// </summary>
    public static GongfaAttrData GetRandomExAttr(GongfaType gongfa_typ)
    {
        List <GongfaAttrData> list = new List <GongfaAttrData>();

        foreach (KeyValuePair <GongfaType, GongfaAttrData[]> item in typeList)
        {
            if ((item.Key & gongfa_typ) == item.Key)
            {
                list.AddRange(item.Value);
            }
        }

#if UNITY_EDITOR
        List <GongfaType> typs = new List <GongfaType>();
        for (int i = 1; i != 1 << 31; i = i << 1)
        {
            if (((int)gongfa_typ & i) == i)
            {
                typs.Add((GongfaType)i);
            }
        }
        if (list.Count < 1)
        {
            Debug.LogError("ex_attr can't find : " + string.Join(", ", typs));
        }
#endif
        GongfaAttrData congfa_attr_data = list[Random.Range(0, list.Count)];
        return(congfa_attr_data);
    }
Esempio n. 2
0
    public SkillGongfaStaticData(int lv, GongfaType gongfa_typ, int color, int create_id) : base(lv, gongfa_typ, color, create_id)
    {
        // 主属性
        GongfaAttrData main_attr_data = GongfaAttrConfig.GetRandomExAttr(gongfa_typ | GongfaType.main);

        cool = main_attr_data.cool;
        cost = main_attr_data.cost;
    }
Esempio n. 3
0
    /// <summary>
    /// 获取主词条
    /// </summary>
    public static GongfaAttrData[] GetMainAttr(GongfaType gongfa_typ)
    {
        List <GongfaAttrData> list = new List <GongfaAttrData>();

        foreach (KeyValuePair <GongfaType, GongfaAttrData[]> item in typeList)
        {
            if ((gongfa_typ & item.Key) == item.Key)
            {
                if ((item.Key & GongfaType.main) == GongfaType.main)
                {
                    list.AddRange(item.Value);
                }
            }
        }

#if UNITY_EDITOR
        List <GongfaType> typs = new List <GongfaType>();
        for (int i = 1; i != 1 << 31; i = i << 1)
        {
            if (((int)gongfa_typ & i) == i)
            {
                typs.Add((GongfaType)i);
            }
        }
        if (list.Count < 1)
        {
            Debug.LogError("ex_attr can't find : " + string.Join(", ", typs));
        }
#endif
        List <GongfaAttrData> result = new List <GongfaAttrData>();
        for (int i = list.Count - 1; i >= 0; i--)
        {
            GongfaAttrData item = list[i];
            if (item.isSkill)
            {
                result.Add(item);
                list.RemoveAt(i);
            }
        }
        if (result.Count > 0)
        {
            // 如果有技能属性,排到第一,多条只随机取一条
            var main_attr = result[Random.Range(0, result.Count - 1)]; // 随机一条技能主属性
            result = new List <GongfaAttrData>();
            result.Add(main_attr);
            result.AddRange(list);
        }
        else
        {
            result = list;
        }
        return(result.ToArray());
    }
Esempio n. 4
0
    public GongfaStaticData(int lv, GongfaType gongfa_typ, int color, int create_id)
    {
        id         = create_id;
        level      = lv;
        this.color = color;
        price      = 20 * (lv + 1) * (color + 1);
        type       = gongfa_typ;

        // 主属性
        GongfaAttrData[] main_attr_data = GongfaAttrConfig.GetMainAttr(gongfa_typ | GongfaType.main);
        int attr_count = main_attr_data.Length;

        attr_id    = new int[attr_count];
        attr_value = new int[attr_count][];
        for (int i = 0; i < attr_count; i++)
        {
            attr_id[i]    = main_attr_data[i].id;
            attr_value[i] = main_attr_data[i].GetRandomAttr(lv, color);
        }

        string name = "";
        // 随机功法词条
        int ex_count = lv + color;

        ex_id     = new int[ex_count];
        ex_values = new int[ex_count][];
        ex_color  = new int[ex_count];
        for (int i = 0; i < ex_count; i++)
        {
            ex_color[i] = UnityEngine.Random.Range(0, GameConst.max_color + 1);
            GongfaAttrData congfa_attr_data = GongfaAttrConfig.GetRandomExAttr(gongfa_typ);
            ex_id[i]     = congfa_attr_data.id;
            ex_values[i] = congfa_attr_data.GetRandomAttr(lv, color);
            if (i < 2)
            {
                name += congfa_attr_data.name;
            }
        }
        this.name = name + main_attr_data[0].name;

        difficult = lv * lv + color;

        SetGongfaCondition();
    }
Esempio n. 5
0
    public static void CreateGongfaItem(GongfaStaticData gongfa, List <ItemStaticData> item_list, ItemSubType sub_type)
    {
        StringBuilder des = new StringBuilder();

        if (gongfa is HeartGongfaStaticData)
        {
            HeartGongfaStaticData gf = (HeartGongfaStaticData)gongfa;
            des.AppendFormat("道点消耗:{0}", gf.need_daodian);
        }
        else if (gongfa is SkillGongfaStaticData)
        {
            SkillGongfaStaticData gf = (SkillGongfaStaticData)gongfa;
            des.AppendFormat("技能冷却:{0}", gf.cool);
            des.AppendLine();
            des.AppendFormat("施法消耗:{0}", gf.cost);
        }
        des.AppendLine();
        des.AppendLine("——————————————————");

        bool isSkill = true;

        for (int i = 0; i < gongfa.attr_id.Length; i++)
        {
            var            attr_id        = gongfa.attr_id[i];
            GongfaAttrData main_attr_data = GongfaAttrConfig.GetAttrConfig(attr_id);
            if (!main_attr_data.isSkill && isSkill)
            {
                isSkill = false;
                des.AppendLine("<color=#E28225FF>装备后可获得以下属性</color>");
            }
            if (isSkill)
            {
                des.AppendLine(DesFormat(main_attr_data.des, gongfa.attr_value[i]));
            }
            else
            {
                des.AppendLine(" " + DesFormat(main_attr_data.des, gongfa.attr_value[i]));
            }
        }
        des.AppendLine("——————————————————");
        for (int i = 0; i < gongfa.ex_id.Length; i++)
        {
            GongfaAttrData congfa_attr_data = GongfaAttrConfig.GetAttrConfig(gongfa.ex_id[i]);
            des.AppendFormat(" <size=10>{1}</size>:<color=#{0}>", GameConst.item_color_str[gongfa.ex_color[i]], GameConst.attr_level_name[i]);
            des.Append(DesFormat(congfa_attr_data.des, gongfa.ex_values[i]));
            des.AppendLine("</color>");
        }
        des.AppendLine("——————————————————");
        if (gongfa.attr_condition[0].Length == 1)
        {
            RoleAttrConfig[] attribute_config = RoleAttrConfigData.GetAttrConfig();
            des.AppendFormat("学习条件:{0}达到{1}", attribute_config[(int)gongfa.attr_condition[0][0]].name, gongfa.value_condition[0]);
        }
        else
        {
            des.AppendFormat("任意一项战斗资质达到{0}", gongfa.value_condition[0]);
        }



        int item_static_id = item_list.Count;
        var item           = new ItemStaticData()
        {
            id       = item_static_id,
            type     = ItemType.Gongfa,
            sub_ype  = sub_type,
            price    = gongfa.price,
            maxcount = 1,
            param    = new int[] { gongfa.id },

            name  = gongfa.name,
            icon  = ItemSubType.Magic - sub_type,
            color = gongfa.color,
            level = gongfa.level,

            des         = des.ToString(),
            attributes  = null,
            attr_values = null,
        };

        item_list.Add(item);
    }
Esempio n. 6
0
    /// <summary>
    /// 更新属性 重新计算装备增加的属性
    /// </summary>
    public void UpdateAttr()
    {
        int count = attribute.Length;

        if (definitive_attribute == null || definitive_max_attribute == null)
        {
            definitive_attribute     = new int[count];
            definitive_max_attribute = new int[count];
            for (int i = 0; i < count; i++)
            {
                definitive_attribute[i]     = attribute[i];
                definitive_max_attribute[i] = max_attribute[i];
            }
        }

        int old_ride = GetAttr(RoleAttribute.ride_id);
        int new_ride = -1;

        // 记录更新属性
        int[] max_value = new int[count];
        for (int i = 0; i < count; i++)
        {
            max_value[i] = max_attribute[i];
        }

        // 计算装备增加的属性
        for (int i = 0; i < equip_items.Length; i++)
        {
            int item_id = equip_items[i];
            if (item_id == -1)
            {
                continue;
            }
            ItemData       item        = GameData.instance.all_item[item_id];
            ItemStaticData static_data = GameData.instance.item_static_data[item.static_id];
            for (int j = 0; j < static_data.attributes.Length; j++)
            {
                int attr = (int)static_data.attributes[j];
                max_value[attr] += static_data.attr_values[j];
            }
            if (static_data.sub_ype == ItemSubType.Ride)
            {
                new_ride = static_data.param[0];
            }
        }
        // 计算功法加的属性
        int daodian = 0; // 记录功法使用的道点
        List <GongfaData> gongfas = new List <GongfaData>(heart_gongfa);

        gongfas.Add(attack_gongfa);
        gongfas.Add(skill_gongfa);
        gongfas.Add(body_gongfa);
        gongfas.Add(magic_gongfa);
        for (int i = 0; i < gongfas.Count; i++)
        {
            GongfaData gongfa = gongfas[i];
            if (gongfa != null)
            {
                GongfaStaticData static_gongfa = GetGongfaStaticData(gongfa);
                for (int j = 0; j < static_gongfa.attr_id.Length; j++)
                {
                    GongfaAttrData attr_data = GongfaAttrConfig.GetAttrConfig(static_gongfa.attr_id[j]);
                    if (!attr_data.isSkill)
                    {
                        int value = gongfa.attr_value[j][0];
                        max_value[(int)attr_data.attr] += value;
                    }
                }
                for (int j = 0; j < static_gongfa.ex_id.Length; j++)
                {
                    GongfaAttrData attr_data = GongfaAttrConfig.GetAttrConfig(static_gongfa.ex_id[j]);
                    if (!attr_data.isSkill)
                    {
                        int value = gongfa.ex_values[j][0];
                        max_value[(int)attr_data.attr] += value;
                    }
                }
                if (static_gongfa is HeartGongfaStaticData)
                {
                    daodian += ((HeartGongfaStaticData)static_gongfa).need_daodian;
                }
            }
        }

        RoleAttrConfig[] attribute_config = RoleAttrConfigData.GetAttrConfig();
        for (int i = 0; i < count; i++)
        {
            float rate = definitive_attribute[i] == definitive_attribute[i] ? 1 : definitive_attribute[i] * 1f / definitive_max_attribute[i];
            if (attribute_config[i].type == RoleAttrShowType.FixedMinMax)
            {
                definitive_max_attribute[i] = max_value[i];
                continue;
            }
            else if (attribute_config[i].type != RoleAttrShowType.MinMax)
            {
                rate = 1;
            }
            definitive_max_attribute[i] = max_value[i];
            definitive_attribute[i]     = (int)(max_value[i] * rate);
        }
        definitive_attribute[(int)RoleAttribute.daodian] = daodian; // 修改当前使用的道点

        EventManager.SendEvent(EventTyp.AttrChange, this);          // 通知属性变更

        if (old_ride != new_ride)
        {
            SetAttrebuteValue(RoleAttribute.ride_id, new_ride);
            EventManager.SendEvent(EventTyp.ChangeRide, this); // 通知坐骑变更
        }
    }
Esempio n. 7
0
    public static Dictionary <GongfaType, GongfaAttrData[]> typeList; // 键是功法类型 值是该类型对应可以有哪些词条
    static GongfaAttrConfig()
    {
        Dictionary <GongfaType, List <GongfaAttrData> > all = new Dictionary <GongfaType, List <GongfaAttrData> >();

        dataList = new Dictionary <int, GongfaAttrData>();
        string[] data = Tools.ReadAllText("Config/gongfaAttrConfig.txt").Split('\n');
        foreach (string line in data)
        {
            if (string.IsNullOrWhiteSpace(line))
            {
                break;
            }
            if (line.StartsWith("#"))
            {
                continue;
            }

#if UNITY_EDITOR
            Debug.Log(line);
#endif

            string[] configs = line.Split('\t');
            int      id      = int.Parse(configs[0]);

            // 计算词条对应的功法
            GongfaType type  = GongfaType.none;
            string[]   types = configs[1].Split('|');
            foreach (string typ_str in types)
            {
                type |= (GongfaType)Enum.Parse(typeof(GongfaType), typ_str);
            }

            string des  = configs[3];
            string name = configs[4];
            float  cool = float.Parse(configs[5]);
            int    cost = int.Parse(configs[6]);

            bool isSkill = false;
            // 词条赋予的属性
            RoleAttribute attr;
            GongfaSkill   skill = GongfaSkill.None;
            if (!Enum.TryParse(configs[7], out attr))
            {
                isSkill = true;
                skill   = (GongfaSkill)Enum.Parse(typeof(GongfaSkill), configs[7]);
            }

            // 第一个索引是保存不同境界的最小随机范围 第二个索引是有些词条会有多个属性变量
            int[][] min_attr;
            int[][] max_attr;
            string  attr_str = configs[8];
            if (!(string.IsNullOrWhiteSpace(attr_str) || attr_str == "-"))
            {
                List <int[]> all_min_attr = new List <int[]>();
                List <int[]> all_max_attr = new List <int[]>();
                string[]     allattr      = attr_str.Split(';');
                for (int attr_idx = 0; attr_idx < allattr.Length; attr_idx++)
                {
                    int[]    minAttr = new int[GameConst.max_item_level];
                    int[]    maxAttr = new int[GameConst.max_item_level];
                    string[] attrs   = allattr[attr_idx].Split('|');
                    for (int lv = 0; lv < attrs.Length; lv++)
                    {
                        string[] minmax = attrs[lv].Split('-');
                        minAttr[lv] = (int.Parse(minmax[0]));
                        maxAttr[lv] = (int.Parse(minmax[1]));
                    }
                    all_min_attr.Add(minAttr);
                    all_max_attr.Add(maxAttr);
                }
                min_attr = all_min_attr.ToArray();
                max_attr = all_max_attr.ToArray();
            }
            else
            {
                min_attr = new int[0][];
                max_attr = new int[0][];
            }

            if (!all.ContainsKey(type))
            {
                all.Add(type, new List <GongfaAttrData>());
            }
            GongfaAttrData attr_data = new GongfaAttrData()
            {
                id       = id, type = type, name = name, des = des, isSkill = isSkill, attr = attr, skill = skill,
                min_attr = min_attr, max_attr = max_attr, cost = cost, cool = cool,
            };

            all[type].Add(attr_data);
            dataList.Add(id, attr_data);
        }

        typeList = new Dictionary <GongfaType, GongfaAttrData[]>();
        foreach (KeyValuePair <GongfaType, List <GongfaAttrData> > item in all)
        {
            typeList.Add(item.Key, item.Value.ToArray());
        }
    }