Files
JJBB/Assets/Project/Script/Player/Fellow/Fellow.cs
2024-08-23 15:49:34 +08:00

732 lines
22 KiB
C#

//********************************************************************
// 文件名: Fellow.cs
// 描述: 伙伴
// 作者: TangYi
// 创建时间: 2014-2-18
//
// 修改历史:
//********************************************************************
using UnityEngine;
using System.Collections.Generic;
using System;
using GCGame.Table;
using Games.GlobeDefine;
using Games.SkillModle;
using UnityEngine.UI;
namespace Games.Fellow
{
public enum FELLOWCLASS
{
ANIMAL = 1, //动物型
HUNMAN = 2, //人型
}
enum FELLOWATTACK
{
PHYSCIS = 1, //物理攻击
MAGIC = 2, //魔法攻击
}
public enum FELLOWQUALITY
{
WHITE = 1, //白色品质
GREEN = 2, //绿色品质
BLUE = 3, //蓝色品质
PURPLE = 4, //紫色品质
RED = 5, //红色品质
ORANGE = 6, //金色品质
}
public partial class Fellow
{
public Dictionary<int, string> PropType = new Dictionary<int, string>()
{
{ 0, "#{20125}" },
{ 1, "#{20126}" },
{ 2, "#{20127}" },
{ 3, "#{20128}" },
};
public Dictionary<int, string> CharacterType = new Dictionary<int, string>()
{
{ 1, "#{20134}" },
{ 2, "#{20135}" },
{ 3, "#{20136}" },
{ 4, "#{20137}" },
{ 5, "#{20138}" },
};
/// <summary>
/// 构造函数
/// </summary>
/// <returns></returns>
public Fellow()
{
CleanUp();
}
/// <summary>
/// 清空
/// </summary>
public void CleanUp()
{
m_nGuid = GlobeVar.INVALID_GUID;
m_nDataId = -1;
m_szName = "";
m_nExp = -1;
m_nLevel = -1;
m_nStarLevel = -1;
m_nZzPoint = -1;
m_bLocked = false;
m_bCalled = false;
m_OwnSkillId.Clear();
m_bHelped = false;
m_GY_skillid = -1;
m_MW_skillid = -1;
LockSkillIds.Clear();
m_CombatAttr_Critical = 0;
m_CombatAttr_Guard = 0;
ownSkillDatas = new OwnSkillData[(int)SKILLDEFINE.MAX_PET_SKILLNUM];
for (int i = 0; i < (int)SKILLDEFINE.MAX_PET_SKILLNUM; i++)
{
ownSkillDatas[i] = new OwnSkillData();
ownSkillDatas[i].CleanUp();
}
}
public void SetGodPetSign(Image Sign)
{
if (m_nDataId >= 0)
{
Tab_FellowBase fellowBase = TableManager.GetFellowBaseByID(m_nDataId, 0);
if (fellowBase != null)
{
string iconPath = "";
switch (fellowBase.Type)
{
case 1: iconPath = "fellowType1"; break;
case 2: iconPath = "fellowType2"; break;
case 3: iconPath = "fellowType3"; break;
}
if (string.IsNullOrEmpty(iconPath))
Sign.gameObject.SetActive(false);
else
{
Sign.gameObject.SetActive(true);
LoadAssetBundle.Instance.SetImageSprite(Sign, iconPath, null);
}
}
}
}
/// <summary>
/// IsValid
/// </summary>
/// <returns></returns>
public bool IsValid()
{
if (m_nDataId >= 0)
{
Tab_FellowBase fellowBase = TableManager.GetFellowBaseByID(m_nDataId, 0);
if (fellowBase != null)
{
return true;
}
}
return false;
}
/// <summary>
/// 伙伴Guid
/// </summary>
/// <returns></returns>
private UInt64 m_nGuid;
public System.UInt64 Guid
{
get { return m_nGuid; }
set { m_nGuid = value; }
}
/// <summary>
/// 伙伴ID 对应FellowAttr.txt里面的ID
/// -1 为非法,-2为用于待解锁槽
/// </summary>
/// <returns></returns>
private int m_nDataId;
public int DataId
{
get { return m_nDataId; }
set { m_nDataId = value; }
}
/// <summary>
/// 名称
/// </summary>
/// <returns></returns>
private string m_szName;
public string Name
{
get { return m_szName; }
set { m_szName = value; }
}
/// <summary>
/// 经验值
/// </summary>
/// <returns></returns>
private long m_nExp;
public long Exp
{
get { return m_nExp; }
set { m_nExp = value; }
}
/// <summary>
/// 级别
/// </summary>
/// <returns></returns>
private int m_nLevel;
public int Level
{
get { return m_nLevel; }
set { m_nLevel = value; }
}
/// <summary>
/// 星级
/// </summary>
/// <returns></returns>
private int m_nStarLevel;
public int StarLevel
{
get { return m_nStarLevel; }
set { m_nStarLevel = value; }
}
/// <summary>
/// 资质点
/// </summary>
private int m_nZzPoint;
public int ZzPoint
{
get { return m_nZzPoint; }
set { m_nZzPoint = value; }
}
public float CalculateAptitude(float atitude1, float atitude2, float atitude3, float atitude4, float atitude5)
{
float rateBone = 0.0f;
float rateForce = 0.0f;
float ratePower = 0.0f;
float rateSmart = 0.0f;
float rateAgile = 0.0f;
Tab_FellowBase fellowBase = TableManager.GetFellowBaseByID(m_nDataId, 0);
if (fellowBase == null)
return 0;
Tab_FellowApitute tabApitute = null;
var apitutes = TableManager.GetFellowApitute().Values;
foreach(var apitute in apitutes)
{
if(apitute.Type == fellowBase.Type && apitute.PropType == fellowBase.PropType)
{
tabApitute = apitute;
break;
}
}
if (tabApitute == null)
return 0;
rateBone = (atitude1 - tabApitute.ConstituMin) / (tabApitute.ConstituMax - tabApitute.ConstituMin);
rateForce = (atitude2 - tabApitute.MorfibMin) / (tabApitute.MorfibMax - tabApitute.MorfibMin);
ratePower = (atitude3 - tabApitute.StrengthMin) / (tabApitute.StrengthMax - tabApitute.StrengthMin);
rateSmart = (atitude4 - tabApitute.IntellengMin) / (tabApitute.IntellengMax - tabApitute.IntellengMin);
rateAgile = (atitude5 - tabApitute.AgileMin) / (tabApitute.AgilenMax - tabApitute.AgileMin);
float rate = (rateBone + rateForce + ratePower + rateSmart + rateAgile) / 5;
if (rate <= 0)
return 0;
return rate;
}
public void CalculateAptitudeTotle()
{
//AptitudeTotle = CalculateAptitude(Boneatitude,Forceatitude,Poweratitude,Smartatitude,Agileatitude);
//NewAptitudeTotle = CalculateAptitude(newConstituAptitude, newMorfiAptitude, newStrengthAptitude, newIntellengAptitude, newAgileAptitude);
}
/// <summary>
/// 品质
/// </summary>
public int Quality;
/// <summary>
/// 加锁
/// </summary>
private bool m_bLocked;
public bool Locked
{
get { return m_bLocked; }
set { m_bLocked = value; }
}
/// <summary>
/// 实际出战宠物
/// </summary>
private bool m_bRealFight;
public bool RealFight
{
get { return m_bRealFight; }
set { m_bRealFight = value; }
}
/// <summary>
/// 出战
/// </summary>
private bool m_bCalled;
public bool Called
{
get { return m_bCalled; }
set { m_bCalled = value; }
}
//附加
public bool Attached
{
get
{
Tab_FellowAttached attachTab = TableManager.GetFellowAttachedByID(attachId, 0);
return attachTab != null;
}
}
/// <summary>
/// 助战
/// </summary>
private bool m_bHelped;
public bool Helped
{
get { return m_bHelped; }
set { m_bHelped = value; }
}
/// <summary>
/// 暴击
/// </summary>
private int m_CombatAttr_Critical;
public int CombatAttr_Critical
{
get { return m_CombatAttr_Critical; }
set { m_CombatAttr_Critical = value; }
}
/// <summary>
/// 守护
/// </summary>
private int m_CombatAttr_Guard;
public int CombatAttr_Guard
{
get { return m_CombatAttr_Guard; }
set { m_CombatAttr_Guard = value; }
}
/// <summary>
/// 加持
/// </summary>
private int m_CombatAttr_Bless;
public int CombatAttr_Bless
{
get { return m_CombatAttr_Bless; }
set { m_CombatAttr_Bless = value; }
}
//锁住的技能
private List<int> LockSkillIds = new List<int>();
public void AddLockSkill(List<int> ids)
{
LockSkillIds.Clear();
LockSkillIds.AddRange(ids);
}
public string GetCharacterStr //性格描述
{
get
{
if(CharacterType.ContainsKey(character))
return CharacterType[character];
return "";
}
}
public string GetNature
{
get
{
Tab_FellowBase fellowBase = TableManager.GetFellowBaseByID(m_nDataId, 0);
if (fellowBase == null)
return "";
if (CharacterType.ContainsKey(character)==false)
return "";
return StrDictionary.GetClientDictionaryString(CharacterType[character]);
}
}
public string GetStyle
{
get
{
Tab_FellowBase fellowBase = TableManager.GetFellowBaseByID(m_nDataId, 0);
if (fellowBase == null)
return "";
return StrDictionary.GetClientDictionaryString(PropType[fellowBase.PropType]) + StrDictionary.GetClientDictionaryString("#{20130}");
}
}
public string Summ //总评语
{
get
{
Tab_FellowBase fellowBase = TableManager.GetFellowBaseByID(m_nDataId, 0);
if (fellowBase == null)
return "";
//return StrDictionary.GetClientDictionaryString(GetCharacterStr) +" "+ StrDictionary.GetClientDictionaryString(PropType[fellowBase.PropType]) + StrDictionary.GetClientDictionaryString("#{20130}");
return StrDictionary.GetClientDictionaryString(PropType[fellowBase.PropType]) + StrDictionary.GetClientDictionaryString("#{20130}");
}
}
public int GetlockNum()
{
return LockSkillIds.Count;
}
public bool isSkillLocked(int id)
{
for(int i=0;i<LockSkillIds.Count;i++)
{
if (LockSkillIds[i] == id)
return true;
}
return false;
}
/// <summary>
/// 伙伴拥有的技能
/// </summary>
public const int FELLOW_MAXOWNSKILL = 8; //伙伴最大拥有技能数量
private List<int> m_OwnSkillId = new List<int>();
private OwnSkillData[] ownSkillDatas;
private int m_GY_skillid = -1;
public int GY_skillid
{
get { return m_GY_skillid; }
}
private int m_MW_skillid = -1;
public int MW_skillid
{
get { return m_MW_skillid; }
}
public int GetOwnSkillId(int index)
{
if (index >= 0 && index < m_OwnSkillId.Count)
{
return m_OwnSkillId[index];
}
return -1;
}
public int GetOwnTotleCount()
{
int count = GetOwnSkillCount();
Tab_FellowSkill skill = TableManager.GetFellowSkillByID(m_MW_skillid, 0);
if (skill != null)
count++;
Tab_FellowSkill skill1 = TableManager.GetFellowSkillByID(m_GY_skillid, 0);
if (skill1 != null)
count++;
return count;
}
public int GetOwnSkillCount()
{
int count = 0;
for(int i=0;i<m_OwnSkillId.Count;i++)
{
Tab_FellowSkill skill = TableManager.GetFellowSkillByID(m_OwnSkillId[i], 0);
if (skill == null)
continue;
count++;
}
return count;
}
public void SetOwnSkillId(int skillId, int oldID)
{
Tab_FellowSkill skill = TableManager.GetFellowSkillByID(skillId, 0);
if (skill == null)
return;
if(skill.Type == 1)
{
if(oldID!=-1 && IsHaveSkillId(oldID))
{
for (int i = 0; i < m_OwnSkillId.Count; i++)
{
if (m_OwnSkillId[i] == oldID)
{
m_OwnSkillId[i] = skillId;
}
}
}
else
{
if(IsHaveSkillId(skillId) == false)
m_OwnSkillId.Add(skillId);
}
}
if (skill.Type == 2)
m_MW_skillid = skillId;
if (skill.Type == 3)
m_GY_skillid = skillId;
AddSkillData(m_MW_skillid, 0);
AddSkillData(m_GY_skillid, 1);
if ((skill.Type == 2 || skill.Type == 3) && RealFight && SkillBarLogic.Instance()!=null)
{
SkillBarLogic.Instance().FightPetSkill();
}
}
//index=0 MW技能 index=1 GY技能
public void AddSkillData(int skillID ,int index)
{
Tab_SkillEx tab_SkillEx = TableManager.GetSkillExByID(skillID, 0);
if (tab_SkillEx == null)
return;
var cdTable = TableManager.GetCoolDownTimeByID(tab_SkillEx.CDTimeId, 0);
if (cdTable == null)
return;
Tab_FellowSkill tab_FellowSkill = TableManager.GetFellowSkillByID(skillID, 0);
if (tab_FellowSkill == null)
return;
OwnSkillData ownSkill = ownSkillDatas[index];
Tab_FellowSkill tabCur_FellowSkill = TableManager.GetFellowSkillByID(ownSkill.SkillId, 0);
if (tabCur_FellowSkill == null || tabCur_FellowSkill.BaseSkillId!= tab_FellowSkill.BaseSkillId)
{
ownSkill.SetCooldown(0);
}
ownSkill.SetSkillId(skillID, tab_SkillEx.Level);
}
public OwnSkillData GetSkillData(int index)
{
OwnSkillData ownSkill = null;
if (ownSkillDatas.Length > index)
ownSkill = ownSkillDatas[index];
return ownSkill;
}
public void UpdateSkillCD()
{
for (int i = 0; i < (int)SKILLDEFINE.MAX_PET_SKILLNUM; i++)
{
ownSkillDatas[i].UpdateCooldown();
}
}
public bool SkillCD(int skillID,float CD)
{
if (m_MW_skillid == skillID)
{
if (CD < 0)
ownSkillDatas[0].ResetCooldown();
else
ownSkillDatas[0].SetCooldown(CD);
return true;
}
if(m_GY_skillid == skillID)
{
if(CD < 0)
ownSkillDatas[1].ResetCooldown();
else
ownSkillDatas[1].SetCooldown(CD);
return true;
}
return false;
}
public bool IsHaveSkillId(int skillId)
{
for (int index = 0; index < m_OwnSkillId.Count; index++)
{
if (m_OwnSkillId[index] == skillId)
{
return true;
}
}
if (skillId == MW_skillid)
return true;
if (skillId == GY_skillid)
return true;
return false;
}
public bool IsSkillMax(int skillId)
{
Tab_FellowSkill skillinfo = TableManager.GetFellowSkillByID(skillId + 1, 0);
return skillinfo == null;
}
public int IsSkillBookUsed(int skillID)
{
Tab_FellowSkill skillinfo = TableManager.GetFellowSkillByID(MW_skillid, 0);
if (skillinfo != null)
{
if (skillinfo.BaseSkillId == skillID)
return MW_skillid;
}
skillinfo = TableManager.GetFellowSkillByID(GY_skillid, 0);
if (skillinfo != null)
{
if (skillinfo.BaseSkillId == skillID)
return GY_skillid;
}
for (int index = 0; index < m_OwnSkillId.Count; index++)
{
skillinfo = TableManager.GetFellowSkillByID(m_OwnSkillId[index],0);
if(skillinfo!=null)
{
if (skillinfo.BaseSkillId == skillID)
return skillinfo.Id;
}
}
return 0;
}
public void ConstPay(int skillBaseID,out Tab_CommonItem commonItem,out int needCount)
{
commonItem = null;
needCount = 0;
int skillID = IsSkillBookUsed(skillBaseID);
if (skillID > 0)
{
Tab_FellowSkill skillInfo = TableManager.GetFellowSkillByID(skillID, 0);
if (skillInfo == null || skillInfo.Type == -1)
{
return;
}
for (int i = 0; i < skillInfo.getLevelupConsumeTypeCount(); i++)
{
if (skillInfo.GetLevelupConsumeTypebyIndex(i) == (int)CONSUM_TYPE.ITEM)
{
commonItem = TableManager.GetCommonItemByID(skillInfo.GetLevelupConsumeSubTypebyIndex(i), 0);
if (commonItem != null)
{
needCount = skillInfo.GetLevelupConsumeNumbyIndex(i);
return;
}
}
}
}
else
{
skillID = skillBaseID;
Tab_FellowLearnSkillCost skillBookInfo = TableManager.GetFellowLearnSkillCostByID(skillID, 0);
if (skillBookInfo == null)
{
return;
}
for (int i = 0; i < skillBookInfo.getConsumeTypeCount(); i++)
{
if (skillBookInfo.GetConsumeTypebyIndex(i) == (int)CONSUM_TYPE.ITEM)
{
commonItem = TableManager.GetCommonItemByID(skillBookInfo.GetConsumeSubTypebyIndex(i), 0);
if (commonItem != null)
{
needCount = skillBookInfo.GetConsumeNumbyIndex(i);
}
}
}
}
}
public Tab_CharModel CharModel(int dataID = -1)
{
Tab_FellowBase line = TableManager.GetFellowBaseByID(dataID == -1 ? m_nDataId : dataID, 0);
if (line != null)
{
Tab_CharModel charModel = TableManager.GetCharModelByID(line.ModelId, 0);
if(charModel!=null)
{
return charModel;
}
}
return null;
}
/// <summary>
/// 头像
/// </summary>
/// <returns></returns>
public string GetIcon()
{
Tab_FellowBase line = TableManager.GetFellowBaseByID(m_nDataId, 0);
if (line != null)
{
return line.Icon;
}
return null;
}
//static public string GetTypeString(int DataId)
//{
// string retString = "";
// Tab_FellowAttr line = TableManager.GetFellowAttrByID(DataId, 0);
// if (line != null)
// {
// if (line.ClassId == (int)FELLOWCLASS.ANIMAL)
// {
// retString += StrDictionary.GetClientDictionaryString("#{2902}");
// }
// else if (line.ClassId == (int)FELLOWCLASS.HUNMAN)
// {
// retString += StrDictionary.GetClientDictionaryString("#{2903}");
// }
// retString += "-";
// if (line.AttackType == (int)FELLOWATTACK.PHYSCIS)
// {
// retString += StrDictionary.GetClientDictionaryString("#{2904}");
// }
// else if (line.AttackType == (int)FELLOWATTACK.MAGIC)
// {
// retString += StrDictionary.GetClientDictionaryString("#{2905}");
// }
// }
// return retString;
//}
///// <summary>
///// 伙伴分类ID 1动物 2人形
///// </summary>
///// <returns></returns>
//public int GetClassId()
//{
// Tab_FellowAttr line = TableManager.GetFellowAttrByID(m_nDataId, 0);
// if (line != null)
// {
// return line.ClassId;
// }
// return 0;
//}
private double m_CombatValue = 0;
public double CombatValue
{
get { return m_CombatValue; }
set { m_CombatValue = value; }
}
}
}