You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

101 lines
3.2 KiB

using System;
using System.Collections.Generic;
using Sog;
using ProtoCSStruct;
using System.Linq;
using Sog.IO;
using ProtoCSClass;
namespace World
{
//机器人相关
public class RobotUtils
{
public static SimpleRobotPool robotPool;
public const string robotFile = "../cfg/data/robot.bin"; //机器人文件路径
public static void InitRobotPool()
{
TraceLog.Trace("RobotUtils.InitRobotPool : {0}", robotFile);
robotPool.Pool.Clear();
bool successRobot = FileDBSave.ReadFromFile(ref robotPool, robotFile);
if (!successRobot)
{
TraceLog.Error("RobotUtils.InitRobotPool robot Data {0} fail", robotFile);
}
else
{
TraceLog.Trace("RobotUtils.InitRobotPool load robot num {0}", robotPool.Pool.Count);
}
}
public static bool IsRobotByUid(long Uid)
{
return Uid < 100000;
}
public static void GetRobotInfo(long uid, ref SimpleRobot robotInfo)
{
for (int i = 0; i < robotPool.Pool.Count; i++)
{
ref SimpleRobotList poolList = ref robotPool.Pool[i];
for (int j = 0; j < poolList.List.Count; j++)
{
if (poolList.List[j].RoleBase.Uid == uid)
{
robotInfo.CopyFrom(ref poolList.List[j]);
return;
}
}
}
}
public static string GetRobotLastNameByIdx(int idx)
{
string name = "";
var desc = RandNameDescMgr.Instance.GetConfig(idx);
if (desc != null)
{
int randNameRow = 0;
string strRandNameRow = WorldServerUtils.GetApp().GetCluster().GetAppParamByKey("randNameRow"); //读第几列,从0开始
if (!string.IsNullOrEmpty(strRandNameRow))
{
int.TryParse(strRandNameRow, out randNameRow);
}
if (randNameRow + 1 <= desc.name.Length)
{
if (!string.IsNullOrEmpty(desc.name[randNameRow].LastName))
{
name = desc.name[randNameRow].LastName;
}
}
}
return name;
}
public static void FillRobotInfo(long uid, ref QueryRoleShowInfo showInfo)
{
SimpleRobot robotInfo = new SimpleRobot();
GetRobotInfo(uid, ref robotInfo);
string robotNick = GetRobotLastNameByIdx(robotInfo.RandNameIdx);//取真正的机器人名字
if (robotNick != "")
robotInfo.RoleBase.Nick.SetString(robotNick);
else
robotInfo.RoleBase.Nick.SetString(robotInfo.RoleBase.Nick.GetPtr());//那就取默认列的
DBRoleData roleData = new DBRoleData();
QueryRoleInfoSvc.FillRoleBaseInfo(ref robotInfo.RoleBase, ref roleData, ref showInfo.RoleBaseInfo);
showInfo.RoleBaseInfo.Integral = 1000; //机器人固定1000积分
showInfo.HeroInfo.CopyFrom(ref robotInfo.HeroInfo);
}
}
}