mirror of
https://github.com/rafi1212122/PemukulPaku
synced 2025-12-12 22:24:34 +01:00
chat cmd & hopefully proper avatar level up
This commit is contained in:
@@ -71,5 +71,14 @@ namespace Common.Database
|
|||||||
{
|
{
|
||||||
Avatar.collection.ReplaceOne(Builders<AvatarScheme>.Filter.Eq(avatar => avatar.Id, Id), this);
|
Avatar.collection.ReplaceOne(Builders<AvatarScheme>.Filter.Eq(avatar => avatar.Id, Id), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PlayerLevelData.LevelData AddExp(uint exp)
|
||||||
|
{
|
||||||
|
PlayerLevelData.LevelData levelData = AvatarLevelData.GetInstance().CalculateLevel((int)(exp + Exp));
|
||||||
|
Level = (uint)levelData.Level;
|
||||||
|
Exp = (uint)levelData.Exp;
|
||||||
|
|
||||||
|
return levelData;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
64
Common/Utils/ExcelReader/AvatarLevelData.cs
Normal file
64
Common/Utils/ExcelReader/AvatarLevelData.cs
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace Common.Utils.ExcelReader
|
||||||
|
{
|
||||||
|
public class AvatarLevelData : BaseExcelReader<AvatarLevelData, AvatarLevelDataExcel>
|
||||||
|
{
|
||||||
|
public override string FileName { get { return "AvatarLevelData.json"; } }
|
||||||
|
|
||||||
|
public PlayerLevelData.LevelData CalculateLevel(int exp)
|
||||||
|
{
|
||||||
|
int level = 1;
|
||||||
|
int expRemain = exp;
|
||||||
|
|
||||||
|
foreach (AvatarLevelDataExcel levelData in All)
|
||||||
|
{
|
||||||
|
if (expRemain < 1)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (expRemain >= levelData.Exp)
|
||||||
|
{
|
||||||
|
if (level == All.OrderByDescending(level => level.Level).First().Level)
|
||||||
|
{
|
||||||
|
expRemain = All.OrderByDescending(level => level.Level).First().Exp;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
level++;
|
||||||
|
expRemain -= levelData.Exp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new PlayerLevelData.LevelData(level, expRemain);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int CalculateCost(int startLevel, int endLevel)
|
||||||
|
{
|
||||||
|
int[] costs = All.Where(level => level.Level > startLevel && level.Level < endLevel).Select(level => level.Cost).ToArray();
|
||||||
|
return costs.Sum();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
|
||||||
|
public partial class AvatarLevelDataExcel
|
||||||
|
{
|
||||||
|
[JsonProperty("exp")]
|
||||||
|
public int Exp { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("cost")]
|
||||||
|
public int Cost { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("avatarAssistConf")]
|
||||||
|
public double AvatarAssistConf { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("subSkillScoin")]
|
||||||
|
public int SubSkillScoin { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("DataImpl")]
|
||||||
|
public object DataImpl { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("level")]
|
||||||
|
public int Level { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,11 @@ namespace Common.Utils.ExcelReader
|
|||||||
public class MaterialData : BaseExcelReader<MaterialData, MaterialDataExcel>
|
public class MaterialData : BaseExcelReader<MaterialData, MaterialDataExcel>
|
||||||
{
|
{
|
||||||
public override string FileName { get { return "MaterialData.json"; } }
|
public override string FileName { get { return "MaterialData.json"; } }
|
||||||
|
|
||||||
|
public MaterialDataExcel? FromId(uint id)
|
||||||
|
{
|
||||||
|
return All.Where(material => material.Id == id).FirstOrDefault();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
|
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
|
||||||
|
|||||||
@@ -25,13 +25,33 @@ namespace PemukulPaku.GameServer.Game.Chatrooms
|
|||||||
{
|
{
|
||||||
string? StringMsg = chatMsg.Content.Items.Where(item => item.MsgStr != null).FirstOrDefault()?.MsgStr;
|
string? StringMsg = chatMsg.Content.Items.Where(item => item.MsgStr != null).FirstOrDefault()?.MsgStr;
|
||||||
|
|
||||||
if (StringMsg != null)
|
if (StringMsg != null)
|
||||||
{
|
{
|
||||||
// do we need cmds?
|
// do we need cmds?
|
||||||
Command? Cmd = CommandFactory.Commands.Find(cmd => StringMsg.Split(' ').ToList()[0] == cmd.Name.ToLower());
|
List<string> args = StringMsg.Split(' ').ToList();
|
||||||
|
Command? Cmd = CommandFactory.Commands.Find(cmd => args[0] == cmd.Name.ToLower());
|
||||||
if (Cmd != null)
|
if (Cmd != null)
|
||||||
{
|
{
|
||||||
|
args.RemoveAt(0);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (Cmd.CmdType == CommandType.All || Cmd.CmdType == CommandType.Player)
|
||||||
|
{
|
||||||
|
Cmd.Run(session, args.ToArray());
|
||||||
|
if (Cmd.CmdType == CommandType.Player)
|
||||||
|
SendAiMsg("Command executed", session);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SendAiMsg("Invalid usage", session);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
SendAiMsg(ex.Message, session);
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
chatMsg.CheckResult = new()
|
chatMsg.CheckResult = new()
|
||||||
@@ -67,6 +87,40 @@ namespace PemukulPaku.GameServer.Game.Chatrooms
|
|||||||
session.Send(Packet.FromProto(notify, CmdId.RecvChatMsgNotify));
|
session.Send(Packet.FromProto(notify, CmdId.RecvChatMsgNotify));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SendAiMsg(string msg, Session? session)
|
||||||
|
{
|
||||||
|
if(session == null)
|
||||||
|
{
|
||||||
|
foreach (Session valSession in Members)
|
||||||
|
{
|
||||||
|
SendAiMsg(msg, valSession);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
RecvChatMsgNotify notify = new() { };
|
||||||
|
ChatMsg AiMsg = new()
|
||||||
|
{
|
||||||
|
Uid = 0,
|
||||||
|
Nickname = "Ai-chan",
|
||||||
|
Time = (uint)Global.GetUnixInSeconds(),
|
||||||
|
Msg = msg,
|
||||||
|
Content = new() { },
|
||||||
|
Channel = ChatMsg.MsgChannel.World,
|
||||||
|
AvatarId = 3201,
|
||||||
|
DressId = 593201,
|
||||||
|
FrameId = 200001,
|
||||||
|
CustomHeadId = 161080,
|
||||||
|
CheckResult = new() { NumberCheck = 0, ShieldType = 0, RewriteText = msg }
|
||||||
|
};
|
||||||
|
AiMsg.Content.Items.Add(new() { MsgStr = msg });
|
||||||
|
|
||||||
|
notify.ChatMsgLists.Add(AiMsg);
|
||||||
|
|
||||||
|
session.Send(Packet.FromProto(notify, CmdId.RecvChatMsgNotify));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class BaseChatroom<TSelf> where TSelf : BaseChatroom<TSelf>
|
public abstract class BaseChatroom<TSelf> where TSelf : BaseChatroom<TSelf>
|
||||||
|
|||||||
41
GameServer/Handlers/AddAvatarExpByMaterialReqHandler.cs
Normal file
41
GameServer/Handlers/AddAvatarExpByMaterialReqHandler.cs
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
using Common.Database;
|
||||||
|
using Common.Resources.Proto;
|
||||||
|
using Common.Utils.ExcelReader;
|
||||||
|
|
||||||
|
namespace PemukulPaku.GameServer.Handlers
|
||||||
|
{
|
||||||
|
[PacketCmdId(CmdId.AddAvatarExpByMaterialReq)]
|
||||||
|
internal class AddAvatarExpByMaterialReqHandler : IPacketHandler
|
||||||
|
{
|
||||||
|
public void Handle(Session session, Packet packet)
|
||||||
|
{
|
||||||
|
AddAvatarExpByMaterialReq Data = packet.GetDecodedBody<AddAvatarExpByMaterialReq>();
|
||||||
|
MaterialDataExcel? materialData = MaterialData.GetInstance().FromId(Data.MaterialId);
|
||||||
|
AvatarScheme? avatar = session.Player.AvatarList.FirstOrDefault(avatar => avatar.AvatarId == Data.AvatarId);
|
||||||
|
|
||||||
|
AddAvatarExpByMaterialRsp Rsp = new() { retcode = AddAvatarExpByMaterialRsp.Retcode.Succ };
|
||||||
|
|
||||||
|
if (avatar is not null && materialData is not null)
|
||||||
|
{
|
||||||
|
session.Player.Equipment.AddMaterial(materialData.Id, -(int)Data.MaterialNum);
|
||||||
|
GetEquipmentDataRsp EquipmentRsp = new()
|
||||||
|
{
|
||||||
|
retcode = GetEquipmentDataRsp.Retcode.Succ,
|
||||||
|
VitalityValue = 0,
|
||||||
|
IsAll = true
|
||||||
|
};
|
||||||
|
EquipmentRsp.MaterialLists.Add(session.Player.Equipment.MaterialList.First(mat => mat.Id == materialData.Id));
|
||||||
|
|
||||||
|
avatar.AddExp((uint)materialData.CharacterExpProvide * Data.MaterialNum);
|
||||||
|
|
||||||
|
session.Send(Packet.FromProto(EquipmentRsp, CmdId.GetEquipmentDataRsp));
|
||||||
|
session.ProcessPacket(Packet.FromProto(new GetAvatarDataReq() { AvatarIdLists = new uint[] { avatar.AvatarId } }, CmdId.GetAvatarDataReq));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Rsp.retcode = AddAvatarExpByMaterialRsp.Retcode.AvatarNotExist;
|
||||||
|
}
|
||||||
|
session.Send(Packet.FromProto(Rsp, CmdId.AddAvatarExpByMaterialRsp));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user