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.
 
 
 
 
 
 

463 lines
14 KiB

/*
Sog 游戏基础库
2016 by zouwei
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Sog;
using Sog.IO;
using ProtoCSStruct;
namespace Battle
{
public class GmCmdSvc : BaseReloadableService
{
public override int GetServiceType()
{
return BattleServiceType.GmCmdSvc;
}
//销毁的时候清空指令注册
public override void Dispose()
{
GmCommandMgr.Instance.ClearAll();
}
//构造的时候注册所有指令
public GmCmdSvc()
{
RegisterAllGmCmd();
}
private void RegisterAllGmCmd()
{
GmCommandMgr.Instance.Register("CheckTestUid", "CheckTestUid uid, check uid 20 times", CheckTestUid);
GmCommandMgr.Instance.Register("CheckFromFile", "CheckFromFile file", CheckFromFile);
GmCommandMgr.Instance.Register("ClearAllBattleInfo", "ClearAllBattleInfo", ClearAllBattleInfo);
GmCommandMgr.Instance.Register("TestProp", "TestProp", TestProp);
}
public static long checkTestUid;
public int CheckTestUid(long userid, string[] cmdParams)
{
if (cmdParams.Length != 1)
{
TraceLog.Error("GmCmdSvc.CheckTestUid invalid param, need deskId");
return -1;
}
long uid;
if (long.TryParse(cmdParams[0], out uid) == false)
{
TraceLog.Error("GmCmdSvc.CheckTestUid invalid uid {0}", cmdParams[0]);
return -1;
}
checkTestUid = uid;
TraceLog.Debug("GmCmdSvc.CheckTestUid uid {0}", uid);
return 0;
}
public static bool IsIntArrayKey(string key)
{
if(key == "ViewMatrix"
|| key == "BuffIdsA"
|| key == "BuffIdsB"
|| key == "CarrySpellId"
|| key == "ArtifactOwners"
|| key == "HeroSerialNum"
|| key == "PropId"
|| key == "Treasures"
|| key == "StarIndexs"
|| key == "KillEnemy"
|| key == "KillObjID"
|| key == "ViewMatrix"
|| key == "Params")
{
return true;
}
return false;
}
public static bool IsArrayKey(string key)
{
if(key == "List"
|| key == "Equipment"
|| key == "Artifact"
|| key == "SpellLv"
|| key == "RenownPosLv"
|| key == "Equipment"
|| key == "TalentSpell"
|| key == "HeroFetterInfo"
|| key == "EquipmentSuit"
|| key == "Artifact"
|| key == "Institute"
|| key == "DampingInfo"
|| key == "AppendTypeValue"
|| key == "OneGroupList"
|| key == "HeroAtlasIndex"
|| key == "Employees"
|| key == "DungeonHeroInfo"
|| key == "Relics"
|| key == "EnemyRelics"
|| key == "Enemys"
|| key == "HerosInfo"
|| key == "SpecialList"
|| key == "SpellStat"
|| key == "BattleInput")
{
return true;
}
return false;
}
public static string ReadAndConvertValidJsonFile(string filepath)
{
StringBuilder sb = new StringBuilder();
string[] alllines = File.ReadAllLines(filepath);
Stack<int> arrayBeginSpaceNumStack = new Stack<int>();
int arrayBeginSpaceNum = 0;
foreach (var line in alllines)
{
string[] jsonKeyValue = line.Split(':');
if(jsonKeyValue.Length == 0)
{
continue;
}
string key = jsonKeyValue[0];
int spaceCount = 0;
foreach (var ch in key)
{
if(ch != ' ')
{
break;
}
if (ch == ' ')
{
spaceCount++;
}
}
key = key.Trim();
if (jsonKeyValue.Length == 1 && arrayBeginSpaceNum > 0)
{
if(spaceCount == arrayBeginSpaceNum && key.Contains('}'))
{
char[] ca = key.ToCharArray();
for(int i = 0; i< ca.Length; i++)
{
if(ca[i] == '}')
{
ca[i] = ']';
break;
}
}
key = new string(ca);
if (key.Length > 1 && key[key.Length - 1] == '}')
{
key += ',';
}
arrayBeginSpaceNumStack.Pop();
if(arrayBeginSpaceNumStack.Count > 0)
arrayBeginSpaceNum = arrayBeginSpaceNumStack.Peek();
}
}
if (jsonKeyValue.Length == 1)
{
sb.AppendLine(key);
continue;
}
string value = jsonKeyValue[1];
value = value.Trim();
if (key == "Type" && value.Contains("Mainland("))
{
value = value.Substring(9, 1) + ",";
}
if(IsIntArrayKey(key))
{
value = value.Replace('{', '[');
char[] ca = value.ToCharArray();
for (int i = 0; i < ca.Length; i++)
{
if (ca[i] == '}')
{
ca[i] = ']';
break;
}
}
value = new string(ca);
if (value.Length > 1 && value[value.Length - 1] == '}')
{
value += ',';
}
}
else if(IsArrayKey(key) && value.Contains('{'))
{
value = value.Replace('{', '[');
arrayBeginSpaceNumStack.Push(spaceCount);
arrayBeginSpaceNum = spaceCount;
}
else
{
if(value.Length > 1 && value[value.Length - 1] == '}')
{
value += ',';
}
}
string newLine;
if (key.Contains('[') && key.Contains(']'))
{
newLine = value;
}
else
{
newLine = string.Format("\"{0}\":{1}", key, value);
}
sb.AppendLine(newLine);
}
return sb.ToString();
}
public int CheckFromFile(long userid, string[] cmdParams)
{
//if (cmdParams.Length != 2)
//{
// TraceLog.Error("GmCmdSvc.CheckFromFile invalid param, need deskId");
// return -1;
//}
//string battleInfoFile = cmdParams[0];
//string finishReqFile = cmdParams[1];
//string battleInfoContent = File.ReadAllText(battleInfoFile);
//string finishReqContent = File.ReadAllText(finishReqFile);
//try
// {
// ProtoCSClass.BattleInfoAll battleInfoAllCS = JsonConfig.parse<ProtoCSClass.BattleInfoAll>(battleInfoContent);
// ProtoCSClass.CSMainlandFinishReq finishReqCS = JsonConfig.parse<ProtoCSClass.CSMainlandFinishReq>(finishReqContent);
// ProtoCSStruct.CSMainlandFinishReq req = new ProtoCSStruct.CSMainlandFinishReq();
// MakeFromCSToCCReq(ref req, finishReqCS);
// //还原站位
// //站位数据会被改 需要还原回来
// int[] transPosArr = { 1, 1, 2, 3, 3, 4, 5, 5, 6 };
// foreach (var one in battleInfoAllCS.HerosA.List)
// {
// one.LineupPos = transPosArr[one.LineupPos - 1];
// }
// foreach (var one in battleInfoAllCS.HerosB.List)
// {
// one.LineupPos = transPosArr[one.LineupPos - 1];
// }
// foreach (var one in battleInfoAllCS.DungeonInfo.Employees)
// {
// one.LineupPos = transPosArr[one.LineupPos - 1];
// }
// req.BattleCheckRet = BattleMatchHandler.CheckBattle(battleInfoAllCS.RoleA.RoleBase.Uid, battleInfoAllCS, req.BattleID, req.MainlandID,
// ref req.BattleStats, ref req.BriefStats, ref req.BattleInput);
// TraceLog.Debug("GmCmdSvc.CheckFromFile BattleCheckRet {0}", req.BattleCheckRet);
//}
//catch(Exception ex)
// {
// }
return 0;
}
public int ClearAllBattleInfo(long userid, string[] cmdParams)
{
//TraceLog.Error("GmCmdSvc.ClearAllBattleInfo battle count {0}", BattleServerUtils.GetBattleTableOp().GetBattleCount());
//BattleServerUtils.GetBattleTableOp().Table.m_battleTable.Clear();
return 0;
}
public int TestProp(long userid, string[] cmdParams)
{
// uint instId = ServerIDUtils.GetInstanceID(BattleServerUtils.GetAppID());
// if (instId != 1)
// {
// return 0;
// }
//if (cmdParams.Length != 1)
// {
// TraceLog.Error("GmCmdSvc.TestProp invalid param, need testId");
// return -1;
// }
// if (! int.TryParse(cmdParams[0], out var testId))
// {
// return -1;
// }
//var battleInfo = new BattleInfoAll();
// battleInfo.BattleId = (ulong)BattleServerUtils.GetTimeSecond();
// battleInfo.MainlandId = 1001001;
// battleInfo.MainlandType = (int)MainlandType.Adventure;
//battleInfo.RoleA.RoleBase.Uid = 1001;
// battleInfo.RoleA.RoleBase.Nick.SetString("test_prop");
//var battle = new BattleObj(ref battleInfo);
// BattleInitSvc.InitTestBattle(battle, testId);
//BattleControl.BattleBegin(battle);
// var res = new SSBattleBeginRes {BattleInfo = battle.battleInfo, IsGM = 1};
//BattleServerUtils.GetPacketSender().Broadcast((int)ServerType.Game, (int)SSGameMsgID.BattleBeginRes, ref res, userid, 0);
return 0;
}
/*
public int TestParse(long userid, string[] cmdParams)
{
Dictionary<string, object> allDynamicparams = new Dictionary<string, object>();
allDynamicparams.Add("caster",null);
allDynamicparams.Add("target", null);
if (cmdParams.Length == 3)
{
int key1 = 0;
if (int.TryParse(cmdParams[0], out key1) == false)
{
TraceLog.Error("GmCmdSvc.TestParse invalid skillID {0}", cmdParams[0]);
return -1;
}
int key2 = 0;
if (int.TryParse(cmdParams[1], out key2) == false)
{
TraceLog.Error("GmCmdSvc.TestParse invalid StartFrame {0}", cmdParams[1]);
return -1;
}
SkillEffectDesc skillEffect = SkillEffectDescMgr.Instance.GetConfig(key1, key2);
if (skillEffect == null)
{
TraceLog.Error("GmCmdSvc.TestParse cannot find skilldesc skillID {0} StartFrame {1}", cmdParams[0],cmdParams[1]);
return -1;
}
string lowparam = cmdParams[2].ToLower();
switch (lowparam)
{
case "condition":
ParseStringOrCallResult.Instance.GetFinalResult(skillEffect.Condition, allDynamicparams);
break;
case "targeteffect":
ParseStringOrCallResult.Instance.GetFinalResult(skillEffect.TargetEffect, allDynamicparams);
break;
case "endeffect":
ParseStringOrCallResult.Instance.GetFinalResult(skillEffect.EndEffect, allDynamicparams);
break;
case "damage":
ParseStringOrCallResult.Instance.GetFinalResult(skillEffect.Damage, allDynamicparams);
break;
default:
return -1;
}
}
else if (cmdParams.Length == 1)
{
ParseStringOrCallResult.Instance.GetFinalResult(cmdParams[0], allDynamicparams);
}
return 0;
}
public int TestExcelOnColumn(long userid, string[] cmdParams)
{
Dictionary<string, object> allDynamicparams = new Dictionary<string, object>
{
{ "caster", null },
{ "target", null }
};
if (cmdParams.Length != 2)
{
TraceLog.Error("GmCmdSvc.TestExcelOnColumn cmdParams length {0} invalid ", cmdParams.Length);
return -1;
}
string ExcelName = cmdParams[0].ToLower();
string ColumnName = cmdParams[1].ToLower();
if (string.IsNullOrEmpty(ExcelName) || string.IsNullOrEmpty(ColumnName))
{
TraceLog.Error("GmCmdSvc.TestExcelOnColumn invalid ExcelName {0} or ColumnName {1}", cmdParams[0], cmdParams[1]);
return -1;
}
//目前只有一个表
switch (ExcelName)
{
case "skilleffect":
switch (ColumnName)
{
case "condition":
foreach (var skilllist in SkillEffectDescMgr.Instance.ItemTable.Values)
foreach (var skillEffect in skilllist.Values)
ParseStringOrCallResult.Instance.GetFinalResult(skillEffect.Condition, allDynamicparams);
break;
case "targeteffect":
foreach (var skilllist in SkillEffectDescMgr.Instance.ItemTable.Values)
foreach (var skillEffect in skilllist.Values)
ParseStringOrCallResult.Instance.GetFinalResult(skillEffect.TargetEffect, allDynamicparams);
break;
case "endeffect":
foreach (var skilllist in SkillEffectDescMgr.Instance.ItemTable.Values)
foreach (var skillEffect in skilllist.Values)
ParseStringOrCallResult.Instance.GetFinalResult(skillEffect.EndEffect, allDynamicparams);
break;
case "damage":
foreach (var skilllist in SkillEffectDescMgr.Instance.ItemTable.Values)
foreach (var skillEffect in skilllist.Values)
ParseStringOrCallResult.Instance.GetFinalResult(skillEffect.Damage, allDynamicparams);
break;
default:
TraceLog.Error("GmCmdSvc.TestExcelOnColumn invalid ColumnName {0} ", cmdParams[1]);
return -1;
}
break;
default:
TraceLog.Error("GmCmdSvc.TestExcelOnColumn invalid ExcelName {0} ", cmdParams[0]);
return -1;
}
return 0;
}
*/
}
}