add call item

This commit is contained in:
Naruse
2026-04-29 16:00:10 +08:00
parent 50121d619b
commit fcf0bf0843
7 changed files with 91 additions and 3 deletions

View File

@@ -186,4 +186,40 @@ public class CommandGiveAll : ICommands
await arg.SendMsg(I18NManager.Translate("Game.Command.GiveAll.GiveAllItems",
I18NManager.Translate("Word.SkinPart"), skinPartItems.Count.ToString()));
}
[CommandMethod("call")]
public async ValueTask GiveAllCallItem(CommandArg arg)
{
if (!await arg.CheckOnlineTarget()) return;
if (await arg.GetOption('p') is not int particular) return;
if (await arg.GetOption('l') is not int level) return;
if (await arg.GetOption('g') is not int genre) return;
var detail = arg.GetInt(0);
var player = arg.Target!.Player!;
List<BaseGameItemInfo> callItems = [];
if (detail == -1)
{
// add all
foreach (var config in GameData.CallItemData.Values)
{
var callItem = await player.InventoryManager!
.AddCallItem((ItemTypeEnum)config.Genre, config.Detail, config.Particular, config.Level, false);
if (callItem != null) callItems.Add(callItem);
}
}
else
{
var callItem = await player.InventoryManager!.AddCallItem((ItemTypeEnum)genre, (uint)detail, (uint)particular, (uint)level, false);
if (callItem == null)
{
await arg.SendMsg(I18NManager.Translate("Game.Command.GiveAll.NotFound", I18NManager.Translate("Word.CallItem")));
return;
}
callItems.Add(callItem);
}
if (callItems.Count > 0) await player.SendPacket(new PacketNtfCallScript(callItems));
await arg.SendMsg(I18NManager.Translate("Game.Command.GiveAll.GiveAllItems",
I18NManager.Translate("Word.CallItem"), callItems.Count.ToString()));
}
}

View File

@@ -291,4 +291,25 @@ public class InventoryManager(PlayerInstance player) : BasePlayerManager(player)
return skinPartInfo;
}
public async ValueTask<BaseGameItemInfo?> AddCallItem(ItemTypeEnum genre, uint detail, uint particular, uint level = 1, bool sendPacket = true)
{
if (genre != ItemTypeEnum.TYPE_CALL) return null;
var callData = GameData.CallItemData.Values.FirstOrDefault(x => x.Genre == (int)genre && x.Detail == detail && x.Particular == particular && x.Level == level);
if (callData == null) return null;
var templateId = GameResourceTemplateId.FromGdpl((uint)genre, detail, particular, level);
if (InventoryData.Items.Values.Any(x => x.TemplateId == templateId)) return null;
var callInfo = new BaseGameItemInfo
{
TemplateId = templateId,
UniqueId = InventoryData.NextUniqueUid++,
ItemType = genre,
ItemCount = 1
};
InventoryData.Items[callInfo.UniqueId] = callInfo;
if (sendPacket) await Player.SendPacket(new PacketNtfCallScript([callInfo]));
return callInfo;
}
}