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.
 
 
 
 
 
 

180 lines
6.4 KiB

using ProtoCSStruct;
using Sog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static Google.Protobuf.WellKnownTypes.Field.Types;
namespace Game
{
public class SkinSvc
{
public static void OnPlayerBorn(PlayerOnGame player)
{
var list = CommParamDescMgr.Instance.DefaultSkin.int_list;
foreach (var skinId in list)
{
if (skinId > 0)
{
AddSkin(player, skinId, false);
}
}
}
public static void OnPlayerOnline(PlayerOnGame player)
{
CalcBenifits(player);
}
public static bool AddSkin(PlayerOnGame player, int skinId, bool sendMsg = true)
{
bool isExist = false;
for (var i = 0; i < player.RoleData.Skin.Skins.Count; i++)
{
if (player.RoleData.Skin.Skins[i].SkinId == skinId)
{
isExist = true;
break;
}
}
if (isExist)
{
return false;
}
//var desc = RoleModelDescMgr.Instance.GetConfig(skinId);
//player.RoleData.PowerPointData.ExtMopTimes += desc.condition1;
DBSkinOne skin = new DBSkinOne();
skin.SkinId = skinId;
skin.UnlockTime = AppTime.ServerAppTime.GetTime();
skin.NewGet = true;
player.RoleData.Skin.Skins.Add(ref skin);
if (player.RoleData.Skin.Skins.Count == 1)
{
player.RoleData.Skin.NowSkin = skinId;
player.RoleData.Knight.DbHero.Skin = skinId;
}
var omop = SkinSvc.GetBenifitValue(player, "addSweepTimes");
CalcBenifits(player);
var nmop = SkinSvc.GetBenifitValue(player, "addSweepTimes");
if(nmop > omop)
{
player.RoleData.PowerPointData.ExtMopTimes += nmop - omop;
}
if (sendMsg)
{
CSSkinSync sync = new CSSkinSync();
sync.Skins.CopyFrom(ref player.RoleData.Skin);
player.SendToClient<CSSkinSync>((int)CSGameMsgID.SkinSync, ref sync);
RolePropUtil.RecalRoleProp(player, true);
PlayerDataSvc.SyncPower(player);
}
return true;
}
public static void CalcBenifits(PlayerOnGame player)
{
player.RoleData.Skin.Benifits.Clear();
var bmap = new Dictionary<string, int>();
for (var i = 0; i < player.RoleData.Skin.Skins.Count; i++)
{
var skinId = player.RoleData.Skin.Skins[i].SkinId;
var desc = RoleModelDescMgr.Instance.GetConfig(skinId);
for (var j = 0; j < desc.benefitType.Length; j++)
{
var t = desc.benefitType[j];
var v = desc.benefitValue[j];
if(bmap.ContainsKey(t))
{
bmap[t] += v;
}
else
{
bmap[t] = v;
}
}
}
foreach (var item in bmap)
{
var idv = new TypeIDValueString { Value = item.Value };
idv.Id.SetString(item.Key);
player.RoleData.Skin.Benifits.Add(ref idv);
}
}
public static int GetBenifitValue(PlayerOnGame player, string type)
{
for (var i = 0; i < player.RoleData.Skin.Benifits.Count; i++)
{
if (player.RoleData.Skin.Benifits[i].Id.GetString() == type)
{
return player.RoleData.Skin.Benifits[i].Value;
}
}
return 0;
}
public static void CalcSkinProps(ref DBRoleData roleData, RoleProp roleProp)
{
for (var i = 0; i < roleData.Skin.Skins.Count; i++)
{
var skinId = roleData.Skin.Skins[i].SkinId;
var desc = RoleModelDescMgr.Instance.GetConfig(skinId);
for (var j = 0; j < desc.propType.Length; j++)
{
roleProp.AddProp(desc.propType[j], desc.propValue[j]);
}
}
}
public static void PutonOnSkin(PlayerOnGame player, StructPacket packet)
{
ref var req = ref packet.GetMessage<CSSkinPuton>();
var res = new CSSkinPutonRes();
res.SkinId = req.SkinId;
res.Ret = CSErrCode.Fail;
bool isExist = false;
for (var i = 0; i < player.RoleData.Skin.Skins.Count; i++)
{
if (player.RoleData.Skin.Skins[i].SkinId == req.SkinId)
{
isExist = true;
break;
}
}
if (!isExist)
{
player.SendToClient((int)CSGameMsgID.SkinPutonRes, ref res);
return;
}
player.RoleData.Skin.NowSkin = req.SkinId;
player.RoleData.Knight.DbHero.Skin = req.SkinId;
res.Ret = CSErrCode.None;
res.SkinData.CopyFrom(ref player.RoleData.Skin);
player.MakeDirty();
player.SendToClient((int)CSGameMsgID.SkinPutonRes, ref res);
PlayerNotify.NotifyPlayerShowInfoChange(player);
}
public static void SkinSetNewget(PlayerOnGame player, StructPacket packet)
{
ref var req = ref packet.GetMessage<CSSkinSetNewGet>();
var res = new CSSkinSetNewGetRes();
bool isExist = false;
for (var i = 0; i < player.RoleData.Skin.Skins.Count; i++)
{
if (player.RoleData.Skin.Skins[i].NewGet )
{
player.RoleData.Skin.Skins[i].NewGet = false;
isExist = true;
}
}
if (isExist)
{
player.MakeDirty();
CSSkinSync sync = new CSSkinSync();
sync.Skins.CopyFrom(ref player.RoleData.Skin);
player.SendToClient<CSSkinSync>((int)CSGameMsgID.SkinSync, ref sync);
}
player.SendToClient((int)CSGameMsgID.SkinSetNewgetRes, ref res);
}
}
}