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.
328 lines
13 KiB
328 lines
13 KiB
using ProtoCSStruct;
|
|
using Sog;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Game
|
|
{
|
|
public static class PlayerPresetSvc
|
|
{
|
|
public static void PlayerBorn(PlayerOnGame player)
|
|
{
|
|
for(int i = 0; i < player.RoleData.Preset.Sets.GetMaxCount(); i++)
|
|
{
|
|
player.RoleData.Preset.Sets.Add(new DBPresetOne() {Saved=false });
|
|
}
|
|
}
|
|
public static void PresetSave(PlayerOnGame player, StructPacket packet)
|
|
{
|
|
ref var req = ref packet.GetMessage<CSPresetSaveReq>();
|
|
int index = req.PresetIndex;
|
|
if(index < 0 || index >= player.RoleData.Preset.Sets.Count)
|
|
{
|
|
return;
|
|
}
|
|
ref var setOne = ref player.RoleData.Preset.Sets[index];
|
|
//旧预设的装备和宝石要清除预设索引
|
|
//for (int i = 0; i < setOne.WearEquip.Count; i++)
|
|
//{
|
|
// int serialNum = setOne.WearEquip[i].Id;
|
|
// //遍历全部预设,判断是否存在
|
|
// bool exist = false;
|
|
// for(int j = 0; j < player.RoleData.Preset.Sets.Count; j++)
|
|
// {
|
|
// if(j != index)
|
|
// {
|
|
// for(int k = 0; k < player.RoleData.Preset.Sets[j].WearEquip.Count; k++)
|
|
// {
|
|
// if (player.RoleData.Preset.Sets[j].WearEquip[k].Id == serialNum)
|
|
// {
|
|
// exist = true;
|
|
// break;
|
|
// }
|
|
// }
|
|
// if (exist) break;
|
|
// }
|
|
// }
|
|
// if (!exist)
|
|
// {
|
|
// exist = false;
|
|
// for (int j = 0; j < player.RoleData.PandoraBag.EquipList.Count; j++)
|
|
// {
|
|
// ref var eq = ref player.RoleData.PandoraBag.EquipList[j];
|
|
// if (eq.SerialNum == serialNum)
|
|
// {
|
|
// eq.PreSetIndex = 0;
|
|
// exist = true;
|
|
// break;
|
|
// }
|
|
// }
|
|
// if (!exist)
|
|
// {
|
|
// for (int j = 0; j < player.RoleData.PandoraBag.EquipDepot.Count; j++)
|
|
// {
|
|
// ref var eq = ref player.RoleData.PandoraBag.EquipDepot[j];
|
|
// if (eq.SerialNum == serialNum)
|
|
// {
|
|
// eq.PreSetIndex = 0;
|
|
// break;
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
//}
|
|
setOne.WearEquip.Clear();
|
|
for (int i = 0; i < player.RoleData.Knight.DbHero.WearEquip.Count; i++)
|
|
{
|
|
setOne.WearEquip.Add(
|
|
new IDValue32() { Id = player.RoleData.Knight.DbHero.WearEquip[i].SerialNum,
|
|
Value = player.RoleData.Knight.DbHero.WearEquip[i].Pos
|
|
}
|
|
);
|
|
}
|
|
////旧预设的装备和宝石要清除预设索引
|
|
//for (int i = 0; i < setOne.WearGem.Count; i++)
|
|
//{
|
|
// int serialNum = setOne.WearGem[i].Id;
|
|
// //遍历全部预设,判断是否存在
|
|
// bool exist = false;
|
|
// for (int j = 0; j < player.RoleData.Preset.Sets.Count; j++)
|
|
// {
|
|
// if (j != index)
|
|
// {
|
|
// for (int k = 0; k < player.RoleData.Preset.Sets[j].WearGem.Count; k++)
|
|
// {
|
|
// if (player.RoleData.Preset.Sets[j].WearGem[k].Id == serialNum)
|
|
// {
|
|
// exist = true;
|
|
// break;
|
|
// }
|
|
// }
|
|
// if (exist) break;
|
|
// }
|
|
// }
|
|
// if (!exist)
|
|
// {
|
|
// for (int j = 0; j < player.RoleData.PandoraBag.GemList.Count; j++)
|
|
// {
|
|
// ref var eq = ref player.RoleData.PandoraBag.GemList[j];
|
|
// if (eq.ConfId == serialNum)
|
|
// {
|
|
// eq.PreSetIndex = 0;
|
|
// break;
|
|
// }
|
|
// }
|
|
// }
|
|
//}
|
|
setOne.WearGem.Clear();
|
|
for (int i = 0; i < player.RoleData.Knight.DbHero.WearGem.Count; i++)
|
|
{
|
|
setOne.WearGem.Add(new IDValue32 { Id = player.RoleData.Knight.DbHero.WearGem[i].ConfId,
|
|
Value = player.RoleData.Knight.DbHero.WearGem[i].Pos
|
|
});
|
|
}
|
|
setOne.Talents.CopyFrom(ref player.RoleData.Talent);
|
|
setOne.WingskinId = player.RoleData.WingData.Wing.SkinId;
|
|
setOne.WingrefitId = player.RoleData.WingData.Wing.RefitId;
|
|
setOne.WingwearId = player.RoleData.WingData.Wing.WearId;
|
|
setOne.PropView.CopyFrom(ref player.RoleData.Knight.PropView);
|
|
|
|
setOne.Saved = true;
|
|
|
|
var res = new CSPresetSaveRes();
|
|
res.PresetIndex = index;
|
|
res.Ret = CSErrCode.None;
|
|
res.Preset.CopyFrom(ref player.RoleData.Preset);
|
|
player.SendToClient<CSPresetSaveRes>((int)CSGameMsgID.PresetSaveRes, ref res);
|
|
|
|
}
|
|
public static void PresetApplyReq(PlayerOnGame player, StructPacket packet)
|
|
{
|
|
ref var req = ref packet.GetMessage<CSPresetApplyReq>();
|
|
int index = req.PresetIndex;
|
|
if (index < 0 || index >= player.RoleData.Preset.Sets.Count)
|
|
{
|
|
return;
|
|
}
|
|
ref var setOne = ref player.RoleData.Preset.Sets[index];
|
|
if(!setOne.Saved)
|
|
{
|
|
return;
|
|
}
|
|
//先卸下所有的装备
|
|
for (var i = EquipmentPos.Helmet; i < EquipmentPos.Max; i++ )
|
|
{
|
|
if (!(i == EquipmentPos.LeftGun
|
|
|| i == EquipmentPos.RightGun))
|
|
{
|
|
EquipmentSvc.UnWearEquip(player, (int)i);
|
|
}
|
|
}
|
|
for (int i = 0; i < setOne.WearEquip.Count; i++)
|
|
{
|
|
var equipId = setOne.WearEquip[i];
|
|
//不存在的装备要卸下当前的,武器不卸下
|
|
int idx = -1;
|
|
for (int j = 0; j < player.RoleData.PandoraBag.EquipList.Count; j++)
|
|
{
|
|
ref var eq = ref player.RoleData.PandoraBag.EquipList[j];
|
|
if (eq.SerialNum == equipId.Id)
|
|
{
|
|
idx = i;
|
|
break;
|
|
}
|
|
}
|
|
if (idx == -1)
|
|
{
|
|
}
|
|
else
|
|
{
|
|
EquipmentSvc.WearEquip(player, equipId.Id, -1, false, false);
|
|
}
|
|
|
|
}
|
|
//宝石先全部卸下
|
|
var gemList = new List<int>();
|
|
for (int j = 0; j < player.RoleData.Knight.DbHero.WearGem.Count; j++)
|
|
{
|
|
ref var gem = ref player.RoleData.Knight.DbHero.WearGem[j];
|
|
gemList.Add(gem.ConfId);
|
|
}
|
|
foreach (var gemId in gemList)
|
|
{
|
|
GemSvc.GemUnWear(player, gemId, false);
|
|
}
|
|
for (int i = 0; i < setOne.WearGem.Count; i++)
|
|
{
|
|
var gemId = setOne.WearGem[i];
|
|
|
|
//不存在的宝石要卸下当前的
|
|
int idx = -1;
|
|
for (int j = 0; j < player.RoleData.PandoraBag.GemList.Count; j++)
|
|
{
|
|
ref var gem = ref player.RoleData.PandoraBag.GemList[j];
|
|
if (gem.ConfId == gemId.Id)
|
|
{
|
|
idx = i;
|
|
break;
|
|
}
|
|
}
|
|
if (idx == -1)
|
|
{
|
|
}
|
|
else
|
|
{
|
|
GemSvc.GemWearOn(player, gemId.Id, gemId.Value, false, false);
|
|
}
|
|
|
|
}
|
|
|
|
player.RoleData.Talent.TalentPage.Items.CopyFrom(ref setOne.Talents.TalentPage.Items);
|
|
player.RoleData.Talent.PeakData.Items.CopyFrom(ref setOne.Talents.PeakData.Items);
|
|
|
|
player.RoleData.WingData.Wing.SkinId = setOne.WingskinId;
|
|
player.RoleData.WingData.Wing.RefitId = setOne.WingrefitId;
|
|
player.RoleData.WingData.Wing.WearId = setOne.WingwearId;
|
|
|
|
WingSvc.SyncData(player);
|
|
RolePropUtil.RecalRoleProp(player);
|
|
PlayerDataSvc.SendHeroInfoSync(player);
|
|
PlayerDataSvc.SendBagInfoSync(player);
|
|
TalentSvc.SyncData(player);
|
|
|
|
var res = new CSPresetApplyRes();
|
|
res.Ret = CSErrCode.None;
|
|
res.PresetIndex = index;
|
|
player.SendToClient<CSPresetApplyRes>((int)CSGameMsgID.PresetApplyRes, ref res);
|
|
}
|
|
public static void PresetBuyOneReq(PlayerOnGame player, StructPacket packet)
|
|
{
|
|
var req = packet.GetMessage<CSPresetBuyOneReq>();
|
|
int buyCount = player.RoleData.Preset.BuyCount;
|
|
int free = 0;
|
|
int maxBuy = 0;
|
|
for(int i = 0; i < CommParamDescMgr.Instance.SchemeCostNum.int_list.Length; i++)
|
|
{
|
|
if (CommParamDescMgr.Instance.SchemeCostNum.int_list[i] == 0)
|
|
{
|
|
free++;
|
|
}
|
|
else
|
|
{
|
|
maxBuy++;
|
|
}
|
|
}
|
|
if(buyCount >= maxBuy)
|
|
{
|
|
return;
|
|
}
|
|
int cost = CommParamDescMgr.Instance.SchemeCostNum.int_list[free + buyCount];
|
|
UnifyOp bagOp = new UnifyOp(player, BillChangeItemReason.Preset, "PresetBuyOneReq");
|
|
bagOp.CostItem(CommParamDescMgr.Instance.SchemeCostId.str_val, cost);
|
|
var ret = bagOp.DoOp();
|
|
var res = new CSPresetBuyOneRes();
|
|
if (ret == CSErrCode.None)
|
|
{
|
|
player.RoleData.Preset.BuyCount++;
|
|
res.Ret = CSErrCode.None;
|
|
}
|
|
else
|
|
{
|
|
res.Ret = ret;
|
|
}
|
|
res.Preset.CopyFrom(ref player.RoleData.Preset);
|
|
player.SendToClient((int)CSGameMsgID.PresetBuyOneRes, ref res);
|
|
}
|
|
public static void PresetRenameReq(PlayerOnGame player, StructPacket packet)
|
|
{
|
|
var req = packet.GetMessage<CSPresetRenameReq>();
|
|
int index = req.PresetIndex;
|
|
if (index < 0 || index >= player.RoleData.Preset.Sets.Count)
|
|
{
|
|
return;
|
|
}
|
|
int iRet = PlayerUtils.CheckRenameValid(req.Name.GetString());
|
|
if (iRet != 0)
|
|
{
|
|
var res = new CSPresetRenameRes();
|
|
res.Ret = CSErrCode.IncludeIllegalWord;
|
|
player.SendToClient((int)CSGameMsgID.PresetRenameRes, ref res);
|
|
return;
|
|
}
|
|
DirtyStringSvc.DealDirtyStringCheck(player, DirtyStringCheckType.CSPresetRenameReq, ref req, req.Name.GetString());
|
|
}
|
|
public static void DealCSPresetRenameReq(PlayerOnGame player, DirtyStringCheckObj checkObj, ref SSCheckDirtyStringRes checkRes)
|
|
{
|
|
CSPresetRenameReq req = (CSPresetRenameReq)checkObj.obj;
|
|
CSErrCode ret = 0;
|
|
if (checkRes.Result == 0)
|
|
{
|
|
player.RoleData.Preset.Sets[req.PresetIndex].Name.SetString(req.Name.GetString());
|
|
CSPresetRenameRes res = new CSPresetRenameRes();
|
|
res.Ret = ret;
|
|
res.PresetIndex = req.PresetIndex;
|
|
res.Preset.CopyFrom(ref player.RoleData.Preset);
|
|
player.SendToClient((int)CSGameMsgID.PresetRenameRes, ref res);
|
|
return;
|
|
}
|
|
else if (checkRes.Result == 1)
|
|
{
|
|
ret = CSErrCode.IncludeIllegalWord;
|
|
}
|
|
else
|
|
{
|
|
ret = CSErrCode.SysFailure;
|
|
}
|
|
|
|
if (ret != 0)
|
|
{
|
|
CSPresetRenameRes res = new CSPresetRenameRes();
|
|
res.Ret = ret;
|
|
player.SendToClient((int)CSGameMsgID.PresetRenameRes, ref res);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|