Fix Pet System

This commit is contained in:
letheriver2007
2024-10-02 13:50:33 +08:00
parent 11e549d4d7
commit f873da6975
16 changed files with 195 additions and 0 deletions

View File

@@ -138,6 +138,36 @@ public class CommandGiveall : ICommand
I18NManager.Translate("Word.Material"), amount.ToString()));
}
[CommandMethod("0 pet")]
public async ValueTask GiveAllPet(CommandArg arg)
{
var player = arg.Target?.Player;
if (player == null)
{
await arg.SendMsg(I18NManager.Translate("Game.Command.Notice.PlayerNotFound"));
return;
}
arg.CharacterArgs.TryGetValue("x", out var amountStr);
amountStr ??= "1";
if (!int.TryParse(amountStr, out var amount))
{
await arg.SendMsg(I18NManager.Translate("Game.Command.Notice.InvalidArguments"));
return;
}
var petList = GameData.ItemConfigData.Values;
var items = new List<ItemData>();
foreach (var pet in petList)
if (pet.ItemMainType == ItemMainTypeEnum.Pet)
items.Add(new ItemData
{
ItemId = pet.ID,
Count = amount
});
await player.InventoryManager!.AddItems(items, true);
await arg.SendMsg(I18NManager.Translate("Game.Command.GiveAll.GiveAllItems",
I18NManager.Translate("Word.Pet"), "1"));
}
[CommandMethod("0 relic")]
public async ValueTask GiveAllRelic(CommandArg arg)
{

View File

@@ -0,0 +1,17 @@
namespace EggLink.DanhengServer.Data.Excel;
[ResourceEntity("PetConfig.json")]
public class PetExcel : ExcelResource
{
public int PetID { get; set; }
public int PetItemID { get; set; }
public int SummonUnitID { get; set; }
public override int GetId()
{
return PetID;
}
public override void Loaded()
{
GameData.PetData.Add(PetID, this);
}
}

View File

@@ -131,6 +131,7 @@ public static class GameData
public static Dictionary<int, RelicConfigExcel> RelicConfigData { get; private set; } = [];
public static Dictionary<int, RelicExpItemExcel> RelicExpItemData { get; private set; } = [];
public static Dictionary<int, RelicExpTypeExcel> RelicExpTypeData { get; private set; } = [];
public static Dictionary<int, PetExcel> PetData { get; private set; } = [];
#endregion

View File

@@ -27,6 +27,8 @@ public class PlayerData : BaseDatabaseDataHelper
public int Mcoin { get; set; } = 0; // Crystals
public int TalentPoints { get; set; } = 0; // Rogue talent points
public int Pet { get; set; } = 0;
public int Stamina { get; set; } = 240;
public double StaminaReserve { get; set; } = 0;
public long NextStaminaRecover { get; set; } = 0;

View File

@@ -38,6 +38,7 @@ public class WordTextCHS
public string Rank => "星魂";
public string Avatar => "角色";
public string Material => "材料";
public string Pet => "宠物";
public string Relic => "遗器";
public string Equipment => "光锥";
public string Talent => "行迹";

View File

@@ -38,6 +38,7 @@ public class WordTextCHT
public string Rank => "星魂";
public string Avatar => "角色";
public string Material => "材料";
public string Pet => "寵物";
public string Relic => "遺器";
public string Equipment => "光錐";
public string Talent => "行跡";

View File

@@ -38,6 +38,7 @@ public class WordTextEN
public string Rank => "Rank";
public string Avatar => "Avatar";
public string Material => "Material";
public string Pet => "Pet";
public string Relic => "Relic";
public string Equipment => "Light Cone";
public string Talent => "Talent";

View File

@@ -203,6 +203,7 @@ public class InventoryManager(PlayerInstance player) : BasePlayerManager(player)
switch (GameData.ItemConfigData[itemId].ItemMainType)
{
case ItemMainTypeEnum.Material:
case ItemMainTypeEnum.Pet:
case ItemMainTypeEnum.Virtual:
case ItemMainTypeEnum.Usable:
case ItemMainTypeEnum.Mission:
@@ -263,6 +264,7 @@ public class InventoryManager(PlayerInstance player) : BasePlayerManager(player)
switch (itemConfig.ItemMainType)
{
case ItemMainTypeEnum.Material:
case ItemMainTypeEnum.Pet:
case ItemMainTypeEnum.Mission:
case ItemMainTypeEnum.Usable:
var item = Data.MaterialItems.Find(x => x.ItemId == itemId);
@@ -341,6 +343,7 @@ public class InventoryManager(PlayerInstance player) : BasePlayerManager(player)
switch (mainType)
{
case ItemMainTypeEnum.Material:
case ItemMainTypeEnum.Pet:
return Data.MaterialItems.Find(x => x.ItemId == itemId);
case ItemMainTypeEnum.Equipment:
return uniqueId > 0

View File

@@ -0,0 +1,15 @@
using EggLink.DanhengServer.GameServer.Server.Packet.Send.Pet;
using EggLink.DanhengServer.Kcp;
namespace EggLink.DanhengServer.GameServer.Server.Packet.Recv.Pet;
[Opcode(CmdIds.GetPetDataCsReq)]
public class HandlerGetPetDataCsReq : Handler
{
public override async Task OnHandle(Connection connection, byte[] header, byte[] data)
{
var player = connection.Player!;
await connection.SendPacket(new PacketGetPetDataScRsp(player));
}
}

View File

@@ -0,0 +1,18 @@
using EggLink.DanhengServer.GameServer.Server.Packet.Send.Pet;
using EggLink.DanhengServer.Kcp;
using EggLink.DanhengServer.Proto;
namespace EggLink.DanhengServer.GameServer.Server.Packet.Recv.Pet;
[Opcode(CmdIds.RecallPetCsReq)]
public class HandlerRecallPetCsReq : Handler
{
public override async Task OnHandle(Connection connection, byte[] header, byte[] data)
{
var req = RecallPetCsReq.Parser.ParseFrom(data);
connection.Player!.Data.Pet = 0;
await connection.SendPacket(new PacketRecallPetScRsp(req.SummonedPetId));
}
}

View File

@@ -0,0 +1,23 @@
using EggLink.DanhengServer.GameServer.Server.Packet.Send.Pet;
using EggLink.DanhengServer.Kcp;
using EggLink.DanhengServer.Proto;
namespace EggLink.DanhengServer.GameServer.Server.Packet.Recv.Pet;
[Opcode(CmdIds.SummonPetCsReq)]
public class HandlerSummonPetCsReq : Handler
{
public override async Task OnHandle(Connection connection, byte[] header, byte[] data)
{
var req = SummonPetCsReq.Parser.ParseFrom(data);
int curPetId = connection.Player!.Data.Pet;
if (curPetId != req.SummonedPetId && curPetId != 0) {
await connection.SendPacket(new PacketCurPetChangedScNotify(req.SummonedPetId));
}
connection.Player!.Data.Pet = (int)req.SummonedPetId;
await connection.SendPacket(new PacketSummonPetScRsp(curPetId, req.SummonedPetId));
}
}

View File

@@ -0,0 +1,18 @@
using EggLink.DanhengServer.Kcp;
using EggLink.DanhengServer.Proto;
namespace EggLink.DanhengServer.GameServer.Server.Packet.Send.Pet;
public class PacketCurPetChangedScNotify : BasePacket
{
public PacketCurPetChangedScNotify(uint newPetId) : base(CmdIds.CurPetChangedScNotify)
{
var proto = new CurPetChangedScNotify
{
CurPetId = newPetId,
};
SetData(proto);
}
}

View File

@@ -0,0 +1,26 @@
using EggLink.DanhengServer.Data;
using EggLink.DanhengServer.GameServer.Game.Player;
using EggLink.DanhengServer.Kcp;
using EggLink.DanhengServer.Proto;
namespace EggLink.DanhengServer.GameServer.Server.Packet.Send.Pet;
public class PacketGetPetDataScRsp : BasePacket
{
public PacketGetPetDataScRsp(PlayerInstance player) : base(CmdIds.GetPetDataScRsp)
{
var proto = new GetPetDataScRsp
{
CurPetId = (uint)player.Data.Pet,
};
foreach (var pet in GameData.PetData.Values)
{
proto.PetIdList.Add((uint)pet.PetID);
}
SetData(proto);
}
}

View File

@@ -0,0 +1,19 @@
using EggLink.DanhengServer.Kcp;
using EggLink.DanhengServer.Proto;
namespace EggLink.DanhengServer.GameServer.Server.Packet.Send.Pet;
public class PacketRecallPetScRsp : BasePacket
{
public PacketRecallPetScRsp(uint newPetId) : base(CmdIds.RecallPetScRsp)
{
var proto = new RecallPetScRsp
{
CurPetId = newPetId,
NewPetId = 0
};
SetData(proto);
}
}

View File

@@ -0,0 +1,19 @@
using EggLink.DanhengServer.Kcp;
using EggLink.DanhengServer.Proto;
namespace EggLink.DanhengServer.GameServer.Server.Packet.Send.Pet;
public class PacketSummonPetScRsp : BasePacket
{
public PacketSummonPetScRsp(int curPetId, uint newPetId) : base(CmdIds.SummonPetScRsp)
{
var proto = new SummonPetScRsp
{
CurPetId = (uint)curPetId,
NewPetId = newPetId
};
SetData(proto);
}
}

View File

@@ -160,6 +160,7 @@ public class PacketPlayerSyncScNotify : BasePacket
break;
case ItemMainTypeEnum.Mission:
case ItemMainTypeEnum.Material:
case ItemMainTypeEnum.Pet:
case ItemMainTypeEnum.Usable:
notify.MaterialList.Add(item.ToMaterialProto());
break;