373 lines
12 KiB
C#
373 lines
12 KiB
C#
//********************************************************************
|
|
// 文件名: FellowContainer.cs
|
|
// 描述: 伙伴容器
|
|
// 作者: TangYi
|
|
// 创建时间: 2014-2-18
|
|
//
|
|
// 修改历史:
|
|
//********************************************************************
|
|
|
|
using System.Collections.Generic;
|
|
using Games.GlobeDefine;
|
|
|
|
namespace Games.Fellow
|
|
{
|
|
public class FellowContainer
|
|
{
|
|
/// <summary>
|
|
/// 伙伴容器默认容量
|
|
/// </summary>
|
|
private const int SIZE_FELLOWCONTAINER = 4;
|
|
|
|
private readonly List<Fellow> m_Fellows = new List<Fellow>();
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
// 伙伴相关
|
|
//////////////////////////////////////////////////////////////////////////
|
|
//当前召出伙伴服务器objid
|
|
private int m_nCurFellowObjId = -1;
|
|
|
|
/// <summary>
|
|
/// 构造函数
|
|
/// </summary>
|
|
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; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// 容器大小
|
|
/// </summary>
|
|
public int ContainerSize { get; private set; }
|
|
|
|
/// <summary>
|
|
/// 清空
|
|
/// </summary>
|
|
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;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据索引取得Fellow
|
|
/// </summary>
|
|
/// <param name="Slot"></param>
|
|
/// <returns></returns>
|
|
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();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据Guid取得Fellow
|
|
/// </summary>
|
|
/// <param name="guid"></param>
|
|
/// <returns></returns>
|
|
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);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新伙伴
|
|
/// </summary>
|
|
/// <param name="slot"></param>
|
|
/// <param name="fellow"></param>
|
|
/// <returns></returns>
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 取得伙伴数量
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 空槽位数量
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public int GetEmptySlotCount()
|
|
{
|
|
return ContainerSize - GetFellowCount();
|
|
}
|
|
|
|
// // useless
|
|
// /// <summary>
|
|
// /// 是否有人形伙伴
|
|
// /// </summary>
|
|
// /// <returns></returns>
|
|
// 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
|
|
// /// <summary>
|
|
// /// 是否有动物形伙伴
|
|
// /// </summary>
|
|
// /// <returns></returns>
|
|
// 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<Fellow> FellowSort(FellowContainer container)
|
|
{
|
|
var resultList = new List<Fellow>();
|
|
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";
|
|
}
|
|
}
|
|
}
|
|
} |