这段代码定义了 CW_Asset_Element 类的两个构造函数,用于创建游戏中的元素属性对象。

第一个构造函数:

internal CW_Asset_Element(string id, int[] base_elements, float promot = 1.0f, float rarity = 1.0f, CW_BaseStats bonus_stats = null)
{
    if (base_elements == null || base_elements.Length != Others.CW_Constants.base_element_types || promot < 0.01f || rarity < 0.99f) throw new Exception(String.Format('Init arguments error: {0},{1},{2}', base_elements==null?-1:base_elements.Length, promot, rarity));
    this.promot = promot;
    this.rarity = rarity;
    this.base_elements = base_elements;
    for(int i = 0; i < Others.CW_Constants.base_element_types; i++)
    {
        if (base_elements[i] < 0 || base_elements[i] > 100) throw new Exception(String.Format('Error Base Elements at {0}, value {1}', i, base_elements[i]));
    }
    this.id = id;
    this.bonus_stats = (bonus_stats==null?new CW_BaseStats():bonus_stats);
}

该构造函数接受以下参数:

  • id: 元素属性的唯一标识符字符串。
  • base_elements: 包含五个整数的数组,分别表示元素属性的五个基本元素值(例如,水、火、木、金、土)。
  • promot: 元素属性的提升率,默认值为 1.0f。
  • rarity: 元素属性的稀有度,默认值为 1.0f。
  • bonus_stats: 可选参数,表示元素属性的额外属性,默认值为 null。

构造函数首先检查参数的有效性,如果参数不满足要求,则抛出异常。然后,将参数赋值给对象的属性。如果 bonus_stats 参数为 null,则创建一个新的 CW_BaseStats 对象作为 bonus_stats 属性的值。

第二个构造函数:

internal CW_Asset_Element(string id, int water, int fire, int wood, int iron, int ground, float promot = 1.0f, float rarity = 1.0f, CW_BaseStats bonus_stats = null, float mod_culti_velo = 0)
{
    if (promot < 0.5f || rarity < 0.99f) throw new Exception(String.Format('Init arguments error: {0},{1}', promot, rarity));
    this.promot = promot;
    this.rarity = rarity;
    this.base_elements = new int[Others.CW_Constants.base_element_types] { water, fire, wood, iron, ground};
    for (int i = 0; i < Others.CW_Constants.base_element_types; i++)
    {
        if (base_elements[i] < 0 || base_elements[i] > 100) throw new Exception(String.Format('Error Base Elements at {0}, value {1}', i, base_elements[i]));
    }
    this.id = id;
    this.bonus_stats = (bonus_stats == null ? new CW_BaseStats() : bonus_stats);
    this.bonus_stats.mod_cultivation = mod_culti_velo;
}

该构造函数接受以下参数:

  • id: 元素属性的唯一标识符字符串。
  • water: 元素属性的“水”属性值。
  • fire: 元素属性的“火”属性值。
  • wood: 元素属性的“木”属性值。
  • iron: 元素属性的“金”属性值。
  • ground: 元素属性的“土”属性值。
  • promot: 元素属性的提升率,默认值为 1.0f。
  • rarity: 元素属性的稀有度,默认值为 1.0f。
  • bonus_stats: 可选参数,表示元素属性的额外属性,默认值为 null。
  • mod_culti_velo: 可选参数,表示元素属性的培养速度修改值,默认值为 0。

构造函数首先检查参数的有效性,如果参数不满足要求,则抛出异常。然后,将参数赋值给对象的属性。如果 bonus_stats 参数为 null,则创建一个新的 CW_BaseStats 对象作为 bonus_stats 属性的值。最后,将 mod_culti_velo 参数赋值给 bonus_stats 属性的 mod_cultivation 属性。

总结:

这两个构造函数用于创建 CW_Asset_Element 对象,并根据传入的参数初始化对象的属性。开发者可以选择适合的构造函数根据需要创建不同类型的元素属性对象。

CW_Asset_Element 类构造函数详解

原文地址: https://www.cveoy.top/t/topic/peLX 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录