示例#1
0
    public void updateWeapon(WeaponInfo newWeapon)
    {
        Dictionary <string, int[]> prevWeaponLevels = weaponManager.GetUpgrades();

        weaponName = newWeapon.name;
        bool alreadyUpgraded = weaponManager.alreadyUpgraded(weaponName);

        weaponDescription = newWeapon.description;
        imagePath         = newWeapon.imgpath;
        updateImage();
        skills = new List <WeaponSkill>();

        // construct the weapon object
        for (int i = 0; i < 3; i++)
        {
            SkillInfo         skillInfo   = newWeapon.skills[i];
            List <SkillLevel> levels      = new List <SkillLevel>();
            int[]             savedLevels = new int[3];
            if (alreadyUpgraded)
            {
                savedLevels = prevWeaponLevels[weaponName];
            }

            foreach (LevelInfo levelInfo in skillInfo.levels)
            {
                levels.Add(new SkillLevel(levelInfo.power, levelInfo.speed, levelInfo.range));
            }

            WeaponSkill newSkill = new WeaponSkill(skillInfo.name, skillInfo.description, skillInfo.imgpath, levels);
            if (alreadyUpgraded)
            {
                Debug.Log("setting skill " + i + "'s level to " + savedLevels[i]);
                newSkill.setLevel(savedLevels[i]);
            }
            skills.Add(newSkill);
        }
    }