CTT/Server/Hotfix/Game/Helper/GMTool.cs

794 lines
35 KiB
C#
Raw Normal View History

2021-04-08 20:09:59 +08:00
using System;
using System.Collections.Generic;
2021-04-24 17:39:11 +08:00
using System.IO;
2021-04-08 20:09:59 +08:00
using System.Linq;
2021-05-05 13:36:19 +08:00
using System.Text;
2021-05-13 20:14:23 +08:00
using Cal.DataTable;
2021-04-08 20:09:59 +08:00
namespace ET
{
public static class GMTool
{
public static async ETTask<string> Execute(Unit unit, string chatContent)
{
if (chatContent.StartsWith("cmd", StringComparison.OrdinalIgnoreCase))
{
string[] arr = chatContent.Trim().Split('/');
int paramsCount = 0;
if (arr.Length == 3)
paramsCount = 1;
else if (arr.Length == 4)
paramsCount = 2;
if (paramsCount == 0)
return "参数至少1个";
string cmdType = arr[1];
string cmdValue = arr[2];
long count = 1;
if (paramsCount == 2)
{
long.TryParse(arr[3], out count);
}
if (cmdType.Equals("sys", StringComparison.OrdinalIgnoreCase))
{
Chat.Instance.SendSystemCaht(cmdValue);
return "成功";
}
2021-05-13 20:14:23 +08:00
else if (cmdType.Equals("updateDay", StringComparison.OrdinalIgnoreCase))
2021-04-08 20:09:59 +08:00
{
2021-09-07 16:20:46 +08:00
Game.EventSystem.Publish(new ET.EventType.UpdatePer1DayOfMonth {zone = unit.DomainZone(),now = TimeHelper.ClientNow() }).Coroutine();
2021-04-24 17:39:11 +08:00
return "成功";
2022-05-29 23:02:28 +08:00
}
else if (cmdType.Equals("test1", StringComparison.OrdinalIgnoreCase))
{
await FamilyComponent.Instance.GetFamilyBossReward(unit,1,new List<ItemInfo>());
return "成功";
}
else if (cmdType.Equals("settleFimalyBoss", StringComparison.OrdinalIgnoreCase))
{
List<FamilyBoss> list = await DBComponent.Instance.QueryJson<FamilyBoss>("{}");
if (list == null || list.Count == 0)
{
return "没有FamilyBoss";
}
IEnumerable<FamilyBossConfig> bossList = DataTableHelper.GetAll<FamilyBossConfig>();
foreach (FamilyBoss familyBoss in list)
{
try
{
foreach (FamilyBossConfig config in bossList)
{
await FamilyBossComponent.instance.SettleReword(familyBoss, config);
await FamilyBossComponent.instance.SettleReword(familyBoss, config);
}
}
catch (Exception e)
{
Log.Error(e);
}
}
return "成功";
2021-04-24 17:39:11 +08:00
}
2021-05-13 20:14:23 +08:00
else if (cmdType.Equals("clearPvpCount", StringComparison.OrdinalIgnoreCase))
2021-04-08 20:09:59 +08:00
{
2021-04-11 19:50:39 +08:00
List<PlayerData> list = await DBComponent.Instance.QueryJson<PlayerData>("{}");
foreach (PlayerData data in list)
2021-04-08 20:09:59 +08:00
{
try
{
data.personalPvpCount = 0;
Unit _unit = MapUnitComponent.Instance.Get(data.Id);
if (_unit)
{
_unit.RemoveComponent<PlayerData>();
_unit.AddComponent(data);
}
2021-05-13 20:14:23 +08:00
2021-06-29 11:28:15 +08:00
UnitHelper.SaveComponenet(data);
2021-04-08 20:09:59 +08:00
}
catch (Exception e)
{
Log.Error(e);
}
}
2021-05-13 20:14:23 +08:00
2021-04-08 20:09:59 +08:00
return "成功";
}
2021-05-13 20:14:23 +08:00
else if (cmdType.Equals("settlePvp", StringComparison.OrdinalIgnoreCase))
2021-04-08 20:09:59 +08:00
{
await PvpMap.inatance.SettlePvp();
return "成功";
}
2021-05-13 20:14:23 +08:00
else if (cmdType.Equals("requireStore", StringComparison.OrdinalIgnoreCase))
2021-04-08 20:09:59 +08:00
{
2021-04-11 19:50:39 +08:00
List<Store> list = await DBComponent.Instance.QueryJson<Store>("{}");
foreach (Store store in list)
2021-04-08 20:09:59 +08:00
{
try
{
bool isRequired = false;
List<Item> itemList = new();
int index = -1;
2021-04-11 19:50:39 +08:00
foreach (KeyValuePair<KeyValuePair<int, int>, Item> kv in store.StoreDic)
2021-04-08 20:09:59 +08:00
{
++index;
if (!isRequired)
isRequired = (kv.Key.Key != index);
itemList.Add(kv.Value);
}
2021-05-13 20:14:23 +08:00
2021-04-08 20:09:59 +08:00
store.StoreDic.Clear();
index = -1;
2021-04-11 19:50:39 +08:00
foreach (Item item in itemList)
2021-04-08 20:09:59 +08:00
{
++index;
if (item.IsEmpty)
{
store.StoreDic.Add(index, 0, item);
}
else
store.StoreDic.Add(index, item.ItemId, item);
}
2021-05-13 20:14:23 +08:00
2021-04-08 20:09:59 +08:00
if (isRequired)
{
2021-04-11 19:50:39 +08:00
Store _store = await StoreComponent.Instance.Query(store.Id);
2021-04-08 20:09:59 +08:00
if (_store != null)
{
_store = store;
}
2021-05-13 20:14:23 +08:00
2021-04-08 20:09:59 +08:00
await DBComponent.Instance.Save(store);
}
}
catch (Exception e)
{
Log.Error(e);
}
}
2021-05-13 20:14:23 +08:00
2021-04-08 20:09:59 +08:00
return "成功";
}
2021-05-13 20:14:23 +08:00
else if (cmdType.Equals("removeInvalidIdMail", StringComparison.OrdinalIgnoreCase))
2021-04-08 20:09:59 +08:00
{
2021-04-11 19:50:39 +08:00
List<MailLib> list = await DBComponent.Instance.QueryJson<MailLib>("{}");
foreach (MailLib mailLib in list)
2021-04-08 20:09:59 +08:00
{
try
{
2021-04-11 19:50:39 +08:00
using ListComponent<long> listComponent = ListComponent<long>.Create();
foreach (Mail mail in mailLib.Dic.Values)
2021-04-08 20:09:59 +08:00
{
try
{
2021-04-11 19:50:39 +08:00
foreach (MailItem mailItem in mail.RewordArr)
2021-04-08 20:09:59 +08:00
{
try
{
2021-04-11 19:50:39 +08:00
IConfig _item = BagHelper.GetItemBase(mailItem.ItemId);
2021-04-08 20:09:59 +08:00
}
catch (Exception e)
{
2021-05-13 20:14:23 +08:00
Log.Error(e);
2021-04-08 20:09:59 +08:00
}
finally
{
listComponent.List.Add(mail.Id);
User user = await UserComponent.Instance.Query(mailLib.Id);
Log.Info($"{user?.NickName}{mailLib.Id} 清理了邮件");
}
}
}
catch (Exception e)
{
2021-05-13 20:14:23 +08:00
Log.Error(e);
2021-04-08 20:09:59 +08:00
}
}
2021-05-13 20:14:23 +08:00
2021-04-11 19:50:39 +08:00
foreach (long item in listComponent.List)
2021-04-08 20:09:59 +08:00
{
mailLib.Dic.Remove(item);
}
2021-05-13 20:14:23 +08:00
2021-04-08 20:09:59 +08:00
DBComponent.Instance.Save(mailLib).Coroutine();
}
catch (Exception e)
{
2021-05-13 20:14:23 +08:00
Log.Error(e);
2021-04-08 20:09:59 +08:00
}
}
2021-05-13 20:14:23 +08:00
2021-04-08 20:09:59 +08:00
return "成功";
}
2021-05-13 20:14:23 +08:00
else if (cmdType.Equals("requireBag", StringComparison.OrdinalIgnoreCase))
2021-04-08 20:09:59 +08:00
{
2021-04-11 19:50:39 +08:00
List<Bag> list = await DBComponent.Instance.QueryJson<Bag>("{}");
foreach (Bag bag in list)
2021-04-08 20:09:59 +08:00
{
try
{
int itemCount = bag.ItemDic.Count(t => t.Key.Value != 0);
if (itemCount == bag.ItemCount) continue;
bag.ItemCount = 0;
for (int i = 0; i < bag.MaxItemCount; i++)
{
2021-04-11 19:50:39 +08:00
if (bag.ItemDic.TryGetValueByKey1(i, out Item item))
2021-04-08 20:09:59 +08:00
{
if (item.ItemId != 0)
bag.ItemCount++;
}
}
2021-05-13 20:14:23 +08:00
2021-04-11 19:50:39 +08:00
Unit unitInServer = MapUnitComponent.Instance.Get(bag.Id);
2021-04-08 20:09:59 +08:00
if (unitInServer != null)
{
unitInServer.RemoveComponent<Bag>();
unitInServer.AddComponent(bag);
}
2021-06-29 11:28:15 +08:00
UnitHelper.SaveComponenet(bag);
2021-04-08 20:09:59 +08:00
}
catch (Exception e)
{
Log.Error(e);
}
}
2021-05-13 20:14:23 +08:00
2021-04-08 20:09:59 +08:00
return "成功";
}
2021-05-13 20:14:23 +08:00
else if (int.TryParse(cmdValue, out int value))
2021-04-08 20:09:59 +08:00
{
if (cmdType.Equals("addItem", StringComparison.OrdinalIgnoreCase))
{
2021-05-13 20:14:23 +08:00
await MailHelper.AddItem(unit.Id, value, count, true, getSource: "GM发放", "GM邮件", "GM发放的物品。", "GM");
2021-04-08 20:09:59 +08:00
await DBComponent.Instance.Save(new AccountLog
{
Id = Game.IdGenerater.GenerateId(),
cmd = chatContent,
time = DateTime.Now,
count = count,
uid = unit.Id,
itemId = value
});
}
2021-09-07 16:20:46 +08:00
if (cmdType.Equals("dropItem", StringComparison.OrdinalIgnoreCase))
{
for (int i = 0; i < 100; i++)
{
DropHelper.Drop(unit,unit.GetComponent<PlayerData>(), BattleType.Boss,value
,null,1,"test",false,null);
}
}
2021-05-13 20:14:23 +08:00
else if (cmdType.Equals("addStarSoulItem", StringComparison.OrdinalIgnoreCase))
2021-05-02 01:19:35 +08:00
{
if (!AppConfig.inst.isTest)
return "测试服专用";
foreach (Unit u in MapUnitComponent.Instance.GetAll())
{
try
{
if (u.UnitType == UnitType.Player)
{
2021-05-05 13:36:19 +08:00
for (int i = 0; i < 100; i++)
2021-05-02 23:18:14 +08:00
{
if (value == 0)
{
value = RandomHelper.RandomNumber(1, 5);
}
2021-05-13 20:14:23 +08:00
var item = ItemHelper.GenerateStarSoulItem(RandomHelper.RandomNumber(1001, 1011), (Quality) value);
2021-05-02 23:18:14 +08:00
StarSoulBag bag = u.GetComponent<StarSoulBag>();
bag.Add(item);
}
2021-05-02 01:19:35 +08:00
}
}
catch (Exception e)
{
Log.Error($"unit id is {u.Id}");
Log.Error(e);
}
}
2021-05-13 20:14:23 +08:00
2021-05-02 01:19:35 +08:00
return "成功";
}
2021-05-13 20:14:23 +08:00
else if (cmdType.Equals("addPetExp", StringComparison.OrdinalIgnoreCase))
2021-04-08 20:09:59 +08:00
{
Pet pet = unit.GetComponent<Pet>();
pet.AddExp(value);
return "成功";
}
2021-05-13 20:14:23 +08:00
else if (cmdType.Equals("exportUser", StringComparison.OrdinalIgnoreCase))
2021-05-05 13:36:19 +08:00
{
long uid = value;
try
{
User user = await DBComponent.Instance.Query<User>(uid);
2021-05-13 20:14:23 +08:00
if (user == null)
2021-05-05 13:36:19 +08:00
{
return $"user is null where id = {uid}";
}
Character character = await DBComponent.Instance.Query<Character>(uid);
Bag bag = await DBComponent.Instance.Query<Bag>(uid);
UnitSkillComponent skill = await DBComponent.Instance.Query<UnitSkillComponent>(uid);
UserSetting userSetting = await DBComponent.Instance.Query<UserSetting>(uid);
NumericComponent num = await DBComponent.Instance.Query<NumericComponent>(uid);
Pet pet = await DBComponent.Instance.Query<Pet>(uid);
2021-05-07 23:50:22 +08:00
string dirPath = "../Export";
if (!File.Exists(dirPath))
2021-05-05 13:36:19 +08:00
{
2021-05-07 23:50:22 +08:00
Directory.CreateDirectory(dirPath);
2021-05-05 13:36:19 +08:00
}
StringBuilder sb = new StringBuilder();
sb
2022-07-31 10:15:47 +08:00
.Append(MongoHelper.ToJson(user)).Append("#gan#")
.Append(MongoHelper.ToJson(character)).Append("#gan#")
.Append(MongoHelper.ToJson(bag)).Append("#gan#")
.Append(MongoHelper.ToJson(skill)).Append("#gan#")
.Append(MongoHelper.ToJson(userSetting)).Append("#gan#")
.Append(MongoHelper.ToJson(num)).Append("#gan#")
2021-05-13 20:14:23 +08:00
.Append(MongoHelper.ToJson(pet))
2021-05-05 13:36:19 +08:00
;
2021-05-13 20:14:23 +08:00
string path = dirPath + $"/{uid}.json";
if (File.Exists(path))
2021-05-05 13:36:19 +08:00
File.Delete(path);
await File.WriteAllTextAsync(path, sb.ToString());
2021-05-07 23:50:22 +08:00
path = dirPath;
DirectoryInfo info = new DirectoryInfo(path);
2021-05-13 20:14:23 +08:00
FileInfo[] fileInfos = info.GetFiles("*.json");
2021-05-07 23:50:22 +08:00
string __str = null;
foreach (FileInfo fileInfo in fileInfos)
{
2021-05-13 20:14:23 +08:00
long.TryParse(fileInfo.Name.Replace(fileInfo.Extension, string.Empty), out long existId);
2021-05-07 23:50:22 +08:00
if (existId == 0) continue;
User __user = await DBComponent.Instance.Query<User>(existId);
__str += $"{__user.NickName} {existId}\r\n";
}
2021-05-13 20:14:23 +08:00
2021-05-07 23:50:22 +08:00
path = dirPath + $"/name.json";
await File.WriteAllTextAsync(path, __str);
2021-05-05 13:36:19 +08:00
}
catch (Exception e)
{
Log.Error(e);
}
2021-05-13 20:14:23 +08:00
2021-05-05 13:36:19 +08:00
return "成功";
}
2021-05-13 20:14:23 +08:00
else if (cmdType.Equals("inportUser", StringComparison.OrdinalIgnoreCase))
2021-05-05 13:36:19 +08:00
{
if (!AppConfig.inst.isTest)
return "测试服专用";
long olsId = value;
long uid = count;
try
{
User user = await UserComponent.Instance.Query(uid);
2021-05-13 20:14:23 +08:00
if (user == null)
2021-05-05 13:36:19 +08:00
{
return $"user is null where id = {uid}";
}
string path = $"../Export/{olsId}.json";
string str = await File.ReadAllTextAsync(path);
2022-07-31 10:15:47 +08:00
string[] arrStr = str.Replace($"\"_id\" : NumberLong({olsId})", $"\"_id\" : NumberLong({uid})").Split("#gan#");
2021-05-05 13:36:19 +08:00
int index = 0;
User user_ = MongoHelper.FromJson<User>(arrStr[index++]);
user.JobId = user_.JobId;
2021-05-07 23:50:22 +08:00
user.Level = user_.Level;
2021-05-05 13:36:19 +08:00
Character character = MongoHelper.FromJson<Character>(arrStr[index++]);
Bag bag = MongoHelper.FromJson<Bag>(arrStr[index++]);
2021-05-13 20:14:23 +08:00
UnitSkillComponent skill = MongoHelper.FromJson<UnitSkillComponent>(arrStr[index++]);
2021-05-05 13:36:19 +08:00
UserSetting userSetting = MongoHelper.FromJson<UserSetting>(arrStr[index++]);
NumericComponent num = MongoHelper.FromJson<NumericComponent>(arrStr[index++]);
Pet pet = MongoHelper.FromJson<Pet>(arrStr[index++]);
Unit unit_ = MapUnitComponent.Instance.Get(uid);
if (unit_)
{
unit_.RemoveComponent<Character>();
unit_.AddComponent(character);
unit_.RemoveComponent<Bag>();
unit_.AddComponent(bag);
unit_.RemoveComponent<UnitSkillComponent>();
unit_.AddComponent(skill);
unit_.RemoveComponent<UserSetting>();
unit_.AddComponent(userSetting);
unit_.RemoveComponent<NumericComponent>();
unit_.AddComponent(num);
unit_.RemoveComponent<Pet>();
unit_.AddComponent(pet);
CharacterHelper.SyncNumeric(unit_);
}
else
{
2021-06-29 11:28:15 +08:00
UserComponent.Instance.Save(user);
UnitHelper.SaveComponenet(character);
UnitHelper.SaveComponenet(bag);
UnitHelper.SaveComponenet(skill);
UnitHelper.SaveComponenet(userSetting);
UnitHelper.SaveComponenet(num);
UnitHelper.SaveComponenet(pet);
2021-05-05 13:36:19 +08:00
}
}
catch (Exception e)
{
Log.Error(e);
}
2021-05-13 20:14:23 +08:00
2021-05-05 13:36:19 +08:00
return "成功";
}
2021-05-13 20:14:23 +08:00
else if (cmdType.Equals("addAllAITime", StringComparison.OrdinalIgnoreCase))
2021-04-08 20:09:59 +08:00
{
2021-04-11 19:50:39 +08:00
List<PlayerData> list = await DBComponent.Instance.QueryJson<PlayerData>("{}");
foreach (PlayerData data in list)
2021-04-08 20:09:59 +08:00
{
try
{
2021-05-13 20:14:23 +08:00
data.mainstoryAITime += value * 60 * 1000;
2021-04-08 20:09:59 +08:00
Unit _unit = MapUnitComponent.Instance.Get(data.Id);
if (_unit)
{
_unit.RemoveComponent<PlayerData>();
_unit.AddComponent(data);
}
2021-05-13 20:14:23 +08:00
2021-06-29 11:28:15 +08:00
UnitHelper.SaveComponenet(data);
2021-04-08 20:09:59 +08:00
}
catch (Exception e)
{
Log.Error(e);
}
}
2021-05-13 20:14:23 +08:00
2021-04-08 20:09:59 +08:00
return "成功";
}
2021-05-13 20:14:23 +08:00
else if (cmdType.Equals("addLevel", StringComparison.OrdinalIgnoreCase))
2021-04-08 20:09:59 +08:00
{
CharacterHelper.AddLevel(unit, value);
await DBComponent.Instance.Save(new AccountLog
{
Id = Game.IdGenerater.GenerateId(),
cmd = chatContent,
time = DateTime.Now,
count = value,
uid = unit.Id,
});
}
2021-05-13 20:14:23 +08:00
else if (cmdType.Equals("addAllItem", StringComparison.OrdinalIgnoreCase))
2021-04-08 20:09:59 +08:00
{
if (!AppConfig.inst.isTest)
return "测试服专用";
2021-04-11 19:50:39 +08:00
foreach (Unit u in MapUnitComponent.Instance.GetAll())
2021-04-08 20:09:59 +08:00
{
try
{
if (u.UnitType == UnitType.Player)
await MailHelper.AddItem(u.Id, value, count, true, getSource: "GM发放", "GM邮件", "GM发放的物品。", "GM");
}
catch (Exception e)
{
Log.Error($"unit id is {u.Id}");
Log.Error(e);
}
}
2021-05-13 20:14:23 +08:00
2021-04-08 20:09:59 +08:00
await DBComponent.Instance.Save(new AccountLog
{
Id = Game.IdGenerater.GenerateId(),
cmd = chatContent,
time = DateTime.Now,
count = count,
uid = unit.Id,
itemId = value
});
}
2021-05-13 20:14:23 +08:00
2021-04-08 20:09:59 +08:00
return "成功";
}
}
else if (chatContent.StartsWith("othercmd", StringComparison.OrdinalIgnoreCase))
{
string[] arr = chatContent.Trim().Split('/');
int paramsCount = 0;
if (arr.Length == 4)
paramsCount = 1;
else if (arr.Length == 5)
paramsCount = 2;
if (paramsCount == 0)
return "参数至少1个";
string idStr = arr[1];
if (!long.TryParse(idStr, out long id))
{
return "请输入id";
}
2021-05-13 20:14:23 +08:00
2021-04-08 20:09:59 +08:00
Unit unitInLib = await MapUnitComponent.Instance.Query(id);
if (unitInLib == null)
{
return "玩家不存在";
}
2021-05-13 20:14:23 +08:00
2021-04-08 20:09:59 +08:00
string cmdType = arr[2];
string cmdValue = arr[3];
long count = 1;
if (paramsCount == 2)
{
long.TryParse(arr[4], out count);
}
2021-05-13 20:14:23 +08:00
2021-04-08 20:09:59 +08:00
if (cmdType.Equals("modifyPwd", StringComparison.OrdinalIgnoreCase))
{
if (paramsCount != 2)
{
return "旧密码/新密码";
}
2021-05-13 20:14:23 +08:00
2021-04-08 20:09:59 +08:00
string old = arr[3];
string newPwd = arr[4];
if (string.IsNullOrWhiteSpace(newPwd))
{
return "请输入新密码";
}
2021-05-13 20:14:23 +08:00
2021-04-11 19:50:39 +08:00
List<Account> list = await DBComponent.Instance.Query<Account>(t => t.UserId == id);
2021-04-08 20:09:59 +08:00
if (list == null || list.Count == 0)
{
return "用户没找到";
}
2021-05-13 20:14:23 +08:00
2021-04-08 20:09:59 +08:00
Account account = list[0];
if (!account.Pwd.Equals(old))
{
return "密码错误";
}
2021-05-13 20:14:23 +08:00
2021-04-08 20:09:59 +08:00
account.Pwd = newPwd;
await DBComponent.Instance.Save(account);
await DBComponent.Instance.Save(new AccountLog
{
Id = Game.IdGenerater.GenerateId(),
cmd = chatContent,
time = DateTime.Now,
count = 0,
uid = id,
});
return "成功";
}
2021-05-13 20:14:23 +08:00
else if (cmdType.Equals("TransLevel", StringComparison.OrdinalIgnoreCase))
2021-04-08 20:09:59 +08:00
{
//othercmd/10001/TransLevel/XXX/5685
Log.Info($"{id} 旧等级:{count}");
string nickName = arr[3];
2021-05-13 20:14:23 +08:00
2021-04-08 20:09:59 +08:00
User user = await UserComponent.Instance.Query(unitInLib.Id);
if (user == null) return "用户不存在";
if (!user.IsOnline())
{
return "不在线";
}
2021-05-13 20:14:23 +08:00
if (user.NickName.Trim() != nickName.Trim())
2021-04-08 20:09:59 +08:00
{
return user.NickName;
}
2021-05-13 20:14:23 +08:00
2021-04-08 20:09:59 +08:00
if (count > user.Level)
{
return $"{user.Level}";
}
2021-05-13 20:14:23 +08:00
2021-04-08 20:09:59 +08:00
await CharacterHelper.ReSetCharacter(unitInLib);
CharacterHelper.AddLevel(unitInLib, 6000);
await TimerComponent.Instance.WaitAsync(1000);
2021-05-13 20:14:23 +08:00
string ret = await CharacterHelper.Transmigration(unitInLib);
2021-04-08 20:09:59 +08:00
if (ret != null)
{
return ret;
}
2021-05-13 20:14:23 +08:00
2021-04-08 20:09:59 +08:00
long exp = 0;
for (int i = 1; i < count; i++)
{
long exp_ = CharacterHelper.GetUpgradeLevelExp(0, i);
if (exp_ > 0)
{
exp += exp_;
}
}
2021-05-13 20:14:23 +08:00
2021-04-08 20:09:59 +08:00
Log.Info($"{id} 经验:{exp}");
2021-05-13 20:14:23 +08:00
await MailHelper.AddItem(id, BagHelper.ExpId, exp, false, "", "经验补偿", "", "");
2021-04-08 20:09:59 +08:00
return "成功";
}
2021-05-13 20:14:23 +08:00
else if (cmdType.Equals("winBattle", StringComparison.OrdinalIgnoreCase))
2021-04-08 20:09:59 +08:00
{
if (!unitInLib) return "不在线";
2021-05-15 14:29:48 +08:00
CopyBattle battle = BattleMgrCompnent.Instance.GetBattle(unitInLib);
battle.Victory().Coroutine();
2021-04-08 20:09:59 +08:00
return "成功";
}
2021-05-13 20:14:23 +08:00
else if (cmdType.Equals("queryAccount", StringComparison.OrdinalIgnoreCase))
2021-04-08 20:09:59 +08:00
{
User user = await UserComponent.Instance.Query(id);
if (user == null)
return "用户不存在";
if (!cmdValue.Equals(user.NickName, StringComparison.OrdinalIgnoreCase))
return $"昵称错误:目标昵称为{user.NickName}";
2021-05-13 20:14:23 +08:00
List<Account> list = await DBComponent.Instance.Query<Account>(t => t.UserId == id);
2021-04-08 20:09:59 +08:00
if (list.Count < 1) return "未找到";
2021-09-07 16:20:46 +08:00
Account account = list[0];
return $"【{account.Username}】【{account.Pwd}】";
2021-04-08 20:09:59 +08:00
}
2021-05-13 20:14:23 +08:00
2021-04-11 19:50:39 +08:00
if (int.TryParse(cmdValue, out int value))
2021-04-08 20:09:59 +08:00
{
if (cmdType.Equals("addItem", StringComparison.OrdinalIgnoreCase))
{
//if (!AppConfig.inst.isTest)
// return "测试服专用";
try
{
2021-04-11 19:50:39 +08:00
IConfig item = BagHelper.GetItemBase(value);
2021-04-08 20:09:59 +08:00
}
catch (Exception e)
{
Log.Error(e);
return "你在写几把呢";
}
2021-05-13 20:14:23 +08:00
2021-04-08 20:09:59 +08:00
await MailHelper.AddItem(unitInLib.Id, value, count, true, getSource: "GM发放", "GM邮件", "GM发放的物品。", "GM");
await DBComponent.Instance.Save(new AccountLog
{
Id = Game.IdGenerater.GenerateId(),
cmd = chatContent,
time = DateTime.Now,
count = count,
uid = id,
itemId = value
});
}
2021-05-13 20:14:23 +08:00
else if (cmdType.Equals("updateDayPerson", StringComparison.OrdinalIgnoreCase))
{
2021-05-13 20:14:23 +08:00
PlayerData data = unitInLib.GetComponent<PlayerData>();
data.InitData();
return "成功";
}
2021-05-13 20:14:23 +08:00
else if (cmdType.Equals("changePetId", StringComparison.OrdinalIgnoreCase))
{
Pet pet = unitInLib.GetComponent<Pet>();
var petConfig = PetConfigCategory.Instance.Get(value, false);
if (petConfig == null)
{
return "petId 错误";
}
pet.petId = value;
Game.EventSystem.Change(pet);
return "成功";
}
else if (cmdType.Equals("passLevel", StringComparison.OrdinalIgnoreCase))
2021-04-08 20:09:59 +08:00
{
PlayerData data = unitInLib.GetComponent<PlayerData>();
data.MainStoryRecordId = 10026;
2021-05-13 20:14:23 +08:00
Game.EventSystem.Publish(new ET.EventType.ChangeMap { unit = unitInLib, mapId = value }).Coroutine();
2021-04-08 20:09:59 +08:00
return "成功";
}
2021-05-13 20:14:23 +08:00
else if (cmdType.Equals("transJob", StringComparison.OrdinalIgnoreCase))
2021-04-08 20:09:59 +08:00
{
CharacterHelper.TransferJob(unitInLib, value, true).Coroutine();
await DBComponent.Instance.Save(new AccountLog
{
Id = Game.IdGenerater.GenerateId(),
cmd = chatContent,
time = DateTime.Now,
count = count,
uid = id,
itemId = value
});
}
2021-05-13 20:14:23 +08:00
else if (cmdType.Equals("addLevel", StringComparison.OrdinalIgnoreCase))
2021-04-08 20:09:59 +08:00
{
CharacterHelper.AddLevel(unitInLib, value);
await DBComponent.Instance.Save(new AccountLog
{
Id = Game.IdGenerater.GenerateId(),
cmd = chatContent,
time = DateTime.Now,
count = value,
uid = id,
});
}
2021-05-13 20:14:23 +08:00
else if (cmdType.Equals("requireStore", StringComparison.OrdinalIgnoreCase))
2021-04-08 20:09:59 +08:00
{
2021-04-11 19:50:39 +08:00
Store store = await StoreComponent.Instance.Query(unitInLib.Id);
2021-04-08 20:09:59 +08:00
try
{
bool isRequired = false;
List<Item> itemList = new();
int index = -1;
2021-04-11 19:50:39 +08:00
foreach (KeyValuePair<KeyValuePair<int, int>, Item> kv in store.StoreDic)
2021-04-08 20:09:59 +08:00
{
++index;
if (!isRequired)
isRequired = (kv.Key.Key != index);
itemList.Add(kv.Value);
}
2021-05-13 20:14:23 +08:00
2021-04-08 20:09:59 +08:00
store.StoreDic.Clear();
index = -1;
2021-04-11 19:50:39 +08:00
foreach (Item item in itemList)
2021-04-08 20:09:59 +08:00
{
++index;
if (item.IsEmpty)
{
store.StoreDic.Add(index, 0, item);
}
else
store.StoreDic.Add(index, item.ItemId, item);
}
2021-05-13 20:14:23 +08:00
2021-04-08 20:09:59 +08:00
if (isRequired)
{
await DBComponent.Instance.Save(store);
}
}
catch (Exception e)
{
Log.Error(e);
}
}
2021-05-13 20:14:23 +08:00
else if (cmdType.Equals("resetCharacter", StringComparison.OrdinalIgnoreCase))
2021-04-08 20:09:59 +08:00
{
await CharacterHelper.ReSetCharacter(unitInLib);
await DBComponent.Instance.Save(new AccountLog
{
Id = Game.IdGenerater.GenerateId(),
cmd = chatContent,
time = DateTime.Now,
count = value,
uid = id,
});
}
2021-05-13 20:14:23 +08:00
else if (cmdType.Equals("resetTeamState", StringComparison.OrdinalIgnoreCase))
2021-04-08 20:09:59 +08:00
{
Team team = TeamComponent.Instance.Get(unitInLib.TeamLeaderId);
team.ChangeState(TeamState.None);
}
2021-05-13 20:14:23 +08:00
else if (cmdType.Equals("resetBag", StringComparison.OrdinalIgnoreCase))
2021-04-08 20:09:59 +08:00
{
2021-04-11 19:50:39 +08:00
Bag bag = unitInLib.GetComponent<Bag>();
2021-04-08 20:09:59 +08:00
List<(KeyValuePair<int, int>, Item)> keyList = new List<(KeyValuePair<int, int>, Item)>();
2021-04-11 19:50:39 +08:00
foreach (KeyValuePair<KeyValuePair<int, int>, Item> kv in bag.ItemDic)
2021-04-08 20:09:59 +08:00
{
if (kv.Value?.Count == 0)
{
keyList.Add((kv.Key, kv.Value));
}
}
2021-05-13 20:14:23 +08:00
2021-04-11 19:50:39 +08:00
foreach ((KeyValuePair<int, int>, Item) item in keyList)
2021-04-08 20:09:59 +08:00
{
bag.ItemDic.Remove(item.Item1.Key, item.Item1.Value, item.Item2);
bag.ItemCount--;
}
}
2021-05-13 20:14:23 +08:00
2021-06-29 11:28:15 +08:00
UnitHelper.Save<Bag>(unitInLib);
UnitHelper.Save<NumericComponent>(unitInLib);
UnitHelper.Save<Character>(unitInLib);
2021-04-08 20:09:59 +08:00
return "成功";
}
}
2021-05-13 20:14:23 +08:00
2021-04-08 20:09:59 +08:00
return "cmd/othercmd";
}
}
2021-05-13 20:14:23 +08:00
}