//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Wednesday, January 31, 2018
|
//--------------------------------------------------------
|
using UnityEngine;
|
using System.Collections;
|
using UnityEngine.UI;
|
using System.Collections.Generic;
|
|
|
//灵宠的技能
|
namespace Snxxz.UI
|
{
|
|
public class SkillButtonPet : CellView
|
{
|
|
[SerializeField] Button skillBtn;
|
[SerializeField] Image skillIcon;
|
[SerializeField] GameObject lockObj;
|
[SerializeField] Text lockLvText;
|
|
PetModel petModel { get { return ModelCenter.Instance.GetModel<PetModel>(); } }
|
MountModel mountModel { get { return ModelCenter.Instance.GetModel<MountModel>(); } }
|
|
public void SetModel(int skillId, int skillUnlock, bool isUnlock, int petId, SkillType skillType, bool isAll = false)
|
{
|
SkillConfig skillConfig = SkillConfig.Get(skillId);
|
if (skillConfig == null) return;
|
|
skillIcon.SetSprite(skillConfig.IconName);
|
if (isUnlock)
|
{
|
lockObj.SetActive(false);
|
lockLvText.gameObject.SetActive(false);
|
}
|
else
|
{
|
lockObj.SetActive(true);
|
if (!isAll)
|
{
|
lockLvText.gameObject.SetActive(true);
|
lockLvText.text = skillUnlock +Language.Get("Z1041");
|
|
}
|
else
|
{
|
lockLvText.gameObject.SetActive(false);
|
}
|
}
|
|
skillBtn.RemoveAllListeners();
|
skillBtn.AddListener(() =>
|
{
|
string[] str = new string[2];
|
|
int fightPower = 0;
|
|
switch (skillType)
|
{
|
case SkillType.PetSkill:
|
if (petModel.TryGetPetId(skillId, out petId))
|
{
|
PetInfoConfig petInfo = PetInfoConfig.Get(petId);
|
str[0] = skillConfig.Description;
|
str[1] = Language.Get("pet_SkillTipLv", petInfo.Name, petModel.GetSkillUnlockLevel(skillId));
|
fightPower = skillConfig.FightPower;
|
}
|
else
|
{
|
List<int> skills;
|
var effect = SkillConfig.GetSkillEffectValue(skillConfig);
|
var count = effect.GetHasValueCount();
|
var values = new int[count];
|
if (petModel.TryGetPetSkills(effect, out skills))
|
{
|
foreach (var id in skills)
|
{
|
if (petModel.IsSkillUnlock(id))
|
{
|
var skillEffectGroup = petModel.GetSkillEffectGroup(id);
|
for (int i = 0; i < count; i++)
|
{
|
values[i] += skillEffectGroup.GetEffectValue(i);
|
}
|
var config = SkillConfig.Get(id);
|
fightPower += config.FightPower;
|
}
|
}
|
}
|
str[0] = SkillConfig.GetSkillDescription(skillConfig.Description, values);
|
str[1] = string.Empty;
|
}
|
break;
|
case SkillType.MountSkill:
|
{
|
if (mountModel.GetMountSkillAndItem.ContainsKey(skillId))
|
{
|
var horseId = mountModel.GetMountSkillAndItem[skillId].HorseID;
|
var horseConfig = HorseConfig.Get(horseId);
|
if (horseConfig != null)
|
{
|
str[0] = skillConfig.Description;
|
str[1] = Language.Get("pet_SkillTipLv", horseConfig.Name, mountModel.GetSkillUnlockLevel(skillId));
|
}
|
fightPower = skillConfig.FightPower;
|
}
|
else
|
{
|
var effect = SkillConfig.GetSkillEffectValue(skillConfig);
|
List<int> skills;
|
var count = effect.GetHasValueCount();
|
var values = new int[count];
|
if (mountModel.TryGetHorseSkills(effect, out skills))
|
{
|
foreach (var id in skills)
|
{
|
if (mountModel.IsSkillUnlock(id))
|
{
|
var skillEffectGroup = mountModel.GetSkillEffectGroup(id);
|
for (int i = 0; i < count; i++)
|
{
|
values[i] += skillEffectGroup.GetEffectValue(i);
|
}
|
var config = SkillConfig.Get(id);
|
fightPower += config.FightPower;
|
}
|
}
|
}
|
str[0] = SkillConfig.GetSkillDescription(skillConfig.Description, values);
|
str[1] = string.Empty;
|
}
|
}
|
break;
|
}
|
SkillDetails.ShowSkillDetails(skillId, SkillDetails.SkillSourceType.PetSkill, fightPower, str);
|
});
|
}
|
|
}
|
|
public enum SkillType
|
{
|
PetSkill,
|
MountSkill,
|
}
|
}
|
|
|
|