//******************************************************************** // 文件名: FellowContainer.cs // 描述: 伙伴容器 // 作者: TangYi // 创建时间: 2014-2-18 // // 修改历史: //******************************************************************** using System.Collections.Generic; using Games.GlobeDefine; namespace Games.Fellow { public class FellowContainer { /// /// 伙伴容器默认容量 /// private const int SIZE_FELLOWCONTAINER = 4; private readonly List m_Fellows = new List(); ////////////////////////////////////////////////////////////////////////// // 伙伴相关 ////////////////////////////////////////////////////////////////////////// //当前召出伙伴服务器objid private int m_nCurFellowObjId = -1; /// /// 构造函数 /// public FellowContainer() { ContainerSize = 0; //m_ContainerSize = SIZE_FELLOWCONTAINER; for (var i = 0; i < ContainerSize; ++i) m_Fellows.Add(new Fellow()); } public int CurFellowObjId { get { return m_nCurFellowObjId; } set { m_nCurFellowObjId = value; } } /// /// 容器大小 /// public int ContainerSize { get; private set; } /// /// 清空 /// public void CleanUp() { for (var i = 0; i < m_Fellows.Count; ++i) m_Fellows[i].CleanUp(); } public void AddContainerSize(int nAdd) { ContainerSize += nAdd; for (var i = 0; i < nAdd; ++i) m_Fellows.Add(new Fellow()); } public void RemoveFellow(ulong guid) { for (var i = 0; i < m_Fellows.Count; ++i) if (m_Fellows[i].Guid == guid) { m_Fellows[i].CleanUp(); return; } } public void UpdateHelpPet(ulong uid) { for (var i = 0; i < m_Fellows.Count; ++i) { m_Fellows[i].Helped = false; if (m_Fellows[i].Guid == uid) m_Fellows[i].Helped = true; } } public void RealFightPet(ulong uid) { for (var i = 0; i < m_Fellows.Count; ++i) { m_Fellows[i].RealFight = false; if (m_Fellows[i].Guid == uid) m_Fellows[i].RealFight = true; } } public void UpdateCallPet(ulong uid) { for (var i = 0; i < m_Fellows.Count; ++i) { m_Fellows[i].Called = false; if (m_Fellows[i].Guid == uid) m_Fellows[i].Called = true; } } /// /// 根据索引取得Fellow /// /// /// public Fellow GetFellowByIndex(int slot) { if (slot >= 0 && slot < m_Fellows.Count) return m_Fellows[slot]; return null; } public Fellow GetHelpedFellow() { for (var i = 0; i < m_Fellows.Count; i++) if (m_Fellows[i].Helped) return m_Fellows[i]; return null; } public ulong GetHelpedPet() { for (var i = 0; i < m_Fellows.Count; i++) if (m_Fellows[i].Helped) return m_Fellows[i].Guid; return GlobeVar.INVALID_GUID; } public Fellow GetCalledFellow() { for (var i = 0; i < m_Fellows.Count; i++) if (m_Fellows[i].Called) return m_Fellows[i]; return null; } public ulong GetCalledPet() { for (var i = 0; i < m_Fellows.Count; i++) if (m_Fellows[i].Called) return m_Fellows[i].Guid; return GlobeVar.INVALID_GUID; } public Fellow GetRealFightPet() { for (var i = 0; i < m_Fellows.Count; i++) if (m_Fellows[i].RealFight) return m_Fellows[i]; return null; } public Fellow GetFellowByAttachId(int attachId) { for (var i = 0; i < m_Fellows.Count; i++) if (m_Fellows[i].attachId == attachId) return m_Fellows[i]; return null; } public void UpdateSkillCD() { for (var i = 0; i < m_Fellows.Count; i++) m_Fellows[i].UpdateSkillCD(); } /// /// 根据Guid取得Fellow /// /// /// public Fellow GetFellowByGuid(ulong guid) { for (var i = 0; i < m_Fellows.Count; ++i) if (m_Fellows[i].Guid == guid) return m_Fellows[i]; return null; } //更新宠物技能CD public void UpdateSkillCD(int skillID, float CD) { for (var i = 0; i < m_Fellows.Count; ++i) m_Fellows[i].SkillCD(skillID, CD); } /// /// 更新伙伴 /// /// /// /// public bool UpdateFellow(int slot, Fellow fellow) { var bRet = false; if (slot >= 0 && slot < m_Fellows.Count) { m_Fellows[slot] = fellow; bRet = true; } return bRet; } /// /// 取得伙伴数量 /// /// public int GetFellowCount() { var count = 0; for (var i = 0; i < m_Fellows.Count; ++i) { var fellow = m_Fellows[i]; if (fellow.IsValid()) ++count; } return count; } /// /// 空槽位数量 /// /// public int GetEmptySlotCount() { return ContainerSize - GetFellowCount(); } // // useless // /// // /// 是否有人形伙伴 // /// // /// // public bool IsHaveHumanFellow() // { // for (int i = 0; i < m_Fellows.Count; ++i) // { // Fellow fellow = m_Fellows[i]; // if (fellow.IsValid()) // { // if (fellow.GetClassId() == (int)FELLOWCLASS.HUNMAN) // { // return true; // } // } // } // return false; // } // // useless // /// // /// 是否有动物形伙伴 // /// // /// // public bool IsHaveAnimalFellow() // { // for (int i = 0; i < m_Fellows.Count; ++i) // { // Fellow fellow = m_Fellows[i]; // if (fellow.IsValid()) // { // if (fellow.GetClassId() == (int)FELLOWCLASS.ANIMAL) // { // return true; // } // } // } // return false; // } } public class FellowTool { public static List FellowSort(FellowContainer container) { var resultList = new List(); for (var i = 0; i < container.ContainerSize; i++) if (container.GetFellowByIndex(i) != null) resultList.Add(container.GetFellowByIndex(i)); for (var i = 0; i < resultList.Count; i++) { var flag = 0; for (var j = 0; j < resultList.Count - i - 1; j++) //当前召出伙伴排前面 if (resultList[j + 1].Called) { var tempFellow = resultList[j + 1]; resultList[j + 1] = resultList[j]; resultList[j] = tempFellow; flag = 1; } else if (resultList[j].Called == false) { //星级高的伙伴排前面 if (resultList[j + 1].StarLevel > resultList[j].StarLevel) { var tempFellow = resultList[j + 1]; resultList[j + 1] = resultList[j]; resultList[j] = tempFellow; flag = 1; } else if (resultList[j + 1].StarLevel == resultList[j].StarLevel) { //品质高的排前面 if (resultList[j + 1].Quality > resultList[j].Quality) { var tempFellow = resultList[j + 1]; resultList[j + 1] = resultList[j]; resultList[j] = tempFellow; flag = 1; } else if (resultList[j + 1].Quality == resultList[j].Quality) { //等级高的排前面 if (resultList[j + 1].Level > resultList[j].Level) { var tempFellow = resultList[j + 1]; resultList[j + 1] = resultList[j]; resultList[j] = tempFellow; flag = 1; } else if (resultList[j + 1].Level == resultList[j].Level) { //DataId大的排前面 if (resultList[j + 1].DataId > resultList[j].DataId) { var tempFellow = resultList[j + 1]; resultList[j + 1] = resultList[j]; resultList[j] = tempFellow; flag = 1; } else if (resultList[j + 1].DataId == resultList[j].DataId) { //Guid大的排前面 if (resultList[j + 1].Guid > resultList[j].Guid) { var tempFellow = resultList[j + 1]; resultList[j + 1] = resultList[j]; resultList[j] = tempFellow; flag = 1; } } } } } } if (flag == 0) break; } return resultList; } public static string GetFellowSkillQualityFrame(int quality) { switch (quality) { case (int) FELLOWQUALITY.WHITE: return "QualityGrey"; case (int) FELLOWQUALITY.GREEN: return "QualityGreen"; case (int) FELLOWQUALITY.BLUE: return "QualityBlue"; case (int) FELLOWQUALITY.PURPLE: return "QualityPurple"; case (int) FELLOWQUALITY.ORANGE: return "QualityYellow"; default: return "QualityGrey"; } } } }