add item, setlevel, ship commands for fun

This commit is contained in:
raphaeIl
2024-04-02 23:40:43 -04:00
parent d6c07eb41d
commit 2d7f83bafc
4 changed files with 86389 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,54 @@
using BLHX.Server.Common.Data;
using BLHX.Server.Common.Database;
using BLHX.Server.Common.Proto.common;
using BLHX.Server.Game.Handlers;
using System.Numerics;
namespace BLHX.Server.Game.Commands {
[CommandHandler("item", "Unlock an item or all items", "item unlock=all amount=1")]
public class ItemCommand : Command {
[Argument("unlock")]
public string? Unlock { get; set; }
[Argument("amount")]
public string? Amount { get; set; }
public override void Execute(Dictionary<string, string> args, Connection connection) {
base.Execute(args);
uint amount = 1;
if (Amount is not null) {
uint.TryParse(Amount, out uint parsedAmount);
amount = parsedAmount;
}
if (Unlock is not null) {
if (Unlock.Equals("all", StringComparison.CurrentCultureIgnoreCase)) {
// ...
} else if (uint.TryParse(Unlock, out uint itemId)) {
//connection.player.DoResource(itemId, amount);
PlayerResource? item = DBManager.PlayerContext.Resources.Where(res => res.Id == itemId).FirstOrDefault();
if (item is null) {
DBManager.PlayerContext.Resources.Add(new PlayerResource() { Id = itemId, PlayerUid = connection.player.Uid, Num = 1 });
//connection.player.DoResource(itemId, 1);
//item = DBManager.PlayerContext.Resources.Where(res => res.Id == itemId).FirstOrDefault();
} else {
item.Num += amount;
connection.SendSystemMsg($"{amount} item of itemid: {itemId} added!");
}
} else {
connection.SendSystemMsg($"Invalid ItemId: {itemId}");
}
}
DBManager.PlayerContext.Save();
connection.NotifyPlayerData();
base.NotifySuccess(connection);
}
}
}

View File

@@ -0,0 +1,40 @@
using BLHX.Server.Common.Database;
using BLHX.Server.Common.Utils;
namespace BLHX.Server.Game.Commands;
[CommandHandler("setlevel", "set a player's level", "setlevel uid=1 level=20")]
public class SetLevelCommand : Command {
[Argument("uid")]
public string? UID { get; set; }
[Argument("level")]
public string? Level { get; set; }
public override void Execute(Dictionary<string, string> args) {
base.Execute(args);
if (UID is null || Level is null) {
Logger.c.Log($"Usage: /setlevel uid=1 level=20");
return;
}
if (!uint.TryParse(UID, out uint targetUID) || !uint.TryParse(Level, out uint targetLevel)) {
Logger.c.Log($"Invalid UID or Level");
return;
}
Player? player = DBManager.PlayerContext.Players.Where(p => p.Uid == targetUID).FirstOrDefault();
if (player == null) {
Logger.c.Log($"Can not find player with UID: ${targetUID}");
return;
}
player.Level = targetLevel;
DBManager.PlayerContext.Save();
Logger.c.Log($"Set Player with UID {targetUID}'s level to {targetLevel}");
}
}

View File

@@ -0,0 +1,75 @@
using BLHX.Server.Common.Data;
using BLHX.Server.Common.Database;
using BLHX.Server.Common.Proto.common;
using BLHX.Server.Common.Utils;
using BLHX.Server.Game.Handlers;
namespace BLHX.Server.Game.Commands {
[CommandHandler("ship", "Unlock a character or all characters", "ship unlock=all")]
public class ShipCommand : Command {
[Argument("unlock")]
public string? Unlock { get; set; }
public override void Execute(Dictionary<string, string> args, Connection connection) {
base.Execute(args);
if (Unlock is null) {
Logger.c.Log($"Usage: /ship unlock=<all|clear|shipId>");
return;
}
if (Unlock.Equals("all", StringComparison.CurrentCultureIgnoreCase)) {
int amount = 500; // not sure why but if you add more than this amount the client crashes
List<int> all_ship_ids = Data.ShipDataTemplate.Where(x => x.Value.Star == x.Value.StarMax && x.Value.Star >= 5).ToDictionary().Keys.ToList();
List<PlayerShip> all_ships = all_ship_ids.Select(ship_id => CreateShipFromId((uint)ship_id, connection.player.Uid)).Take(amount).ToList();
all_ships.AddRange(GetDefaultShips(connection.player.Ships)); // add the defaults
connection.player.Ships = all_ships;
connection.SendSystemMsg($"Added {amount} ships!");
} else if (Unlock.Equals("clear", StringComparison.CurrentCultureIgnoreCase)) {
connection.player.Ships = GetDefaultShips(connection.player.Ships);
connection.SendSystemMsg($"Cleared all ships!");
} else if (uint.TryParse(Unlock, out uint shipId)) {
connection.player.AddShip(shipId);
} else {
connection.SendSystemMsg($"Invalid Ship Id: {shipId}");
return;
}
DBManager.PlayerContext.Save();
connection.NotifyShipData();
base.NotifySuccess(connection);
}
public static PlayerShip CreateShipFromId(uint shipId, uint playerUid) {
if (!Data.ShipDataTemplate.TryGetValue((int)shipId, out var shipTemplate))
throw new InvalidDataException($"Ship template {shipId} not found!");
var ship = new PlayerShip() {
TemplateId = shipId,
Level = 1,
EquipInfoLists = [
new EquipskinInfo() { Id = shipTemplate.EquipId1 },
new EquipskinInfo() { Id = shipTemplate.EquipId2 },
new EquipskinInfo() { Id = shipTemplate.EquipId3 },
new EquipskinInfo(),
new EquipskinInfo(),
],
Energy = shipTemplate.Energy,
SkillIdLists = shipTemplate.BuffList.Select(x => new Shipskill() { SkillId = x, SkillLv = 1 }).ToList(),
Intimacy = 5000,
PlayerUid = playerUid
};
return ship;
}
public static ICollection<PlayerShip> GetDefaultShips(ICollection<PlayerShip> playerShips) {
return playerShips.Where(ship => ship.TemplateId == 106011 || ship.TemplateId == 101171).ToList();
}
}
}