Exemple #1
0
 public void RemoveBonus(DAttributeBonus dBonus)
 {
     if (dBonus.d_bIsRatio)
     {
         m_Properties[(int)dBonus.d_nType].d_fRatio -= dBonus.d_fValue;
     }
     else
     {
         m_Properties[(int)dBonus.d_nType].d_fFixed -= dBonus.d_fValue;
     }
 }
Exemple #2
0
    public void InitFromLuaFile()
    {
        SLua.LuaTable _table;
        //Script prefix path: Assets/Scripts/Lua/
        //read file
        _table = (SLua.LuaTable)SLua.LuaSvr.getInstance().doFile("Items/" + m_LuaScript);

        //onuse function
        SLua.LuaFunction _func = (SLua.LuaFunction)SLua.LuaSvr.mainState["OnUse"];
        if (_func != null)
        {
            m_UsageDelegate += _func.cast <ItemUsage>();
        }

        //load all the properties
        _table = (SLua.LuaTable)SLua.LuaSvr.mainState["properties"];

        //load mesh
        m_Prefab = (string)_table["Mesh"];
        //GameObject _tmp = Resources.Load<GameObject>("Prefabs/"+m_Prefab);
        GameObject _tmp = Resources.Load <GameObject>("Meshes/" + m_Prefab);

        _tmp = Instantiate(_tmp);
        gameObject.AddComponent <MeshFilter>();
        gameObject.AddComponent <MeshRenderer>();
        gameObject.GetComponent <MeshFilter>().mesh   = _tmp.GetComponent <MeshFilter>().mesh;
        gameObject.GetComponent <Renderer>().material = _tmp.GetComponent <Renderer>().material;
        gameObject.transform.localScale = _tmp.transform.localScale;
        GameObject.Destroy(_tmp);

        //attributes
        m_ItemName    = (string)_table["Name"];
        m_Description = (string)_table["Description"];

        m_Type = (ItemType)System.Convert.ToInt32(_table["Type"]);
        switch (m_Type)
        {
        case ItemType.ITEM_PRIMARY:
            m_ShotType    = (ShotType)System.Convert.ToInt32(_table["ShotType"]);
            m_AttackSpeed = System.Convert.ToSingle(_table["AttackSpeed"]);
            m_EnergyCost  = System.Convert.ToSingle(_table["EnergyCost"]);
            m_Damage      = System.Convert.ToSingle(_table["FirePower"]);
            break;

        case ItemType.ITEM_MELEE:
            m_Damage      = System.Convert.ToSingle(_table["Damage"]);
            m_AttackSpeed = System.Convert.ToSingle(_table["AttackSpeed"]);
            break;

        case ItemType.ITEM_PARTS:
            m_Damage     = System.Convert.ToSingle(_table["Damage"]);
            m_Projectile = (string)_table["Ammo"];
            break;

        case ItemType.ITEM_ARMOR:
            m_Armor = System.Convert.ToSingle(_table["Armor"]);
            break;

        default:
            break;
        }
        m_Weight = System.Convert.ToSingle(_table["Weight"]);

        SLua.LuaTable _bonus = (SLua.LuaTable)_table["Bonus"];
        m_BonusList = new DAttributeBonus[_bonus.length()];
        for (int i = 1; i <= _bonus.length(); i++)
        {
            SLua.LuaTable _oneBonus = (SLua.LuaTable)_bonus[i];
            m_BonusList[i - 1] = new DAttributeBonus(
                (AttrType)System.Convert.ToInt32(_oneBonus[1]),
                System.Convert.ToSingle(_oneBonus[3]),
                System.Convert.ToBoolean(_oneBonus[2])
                );
        }

        m_bIfLoaded = true;
    }