Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(game): legacy commands for stats #236

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f71cb82
feat(game): implement /set command
MeikelLP Nov 26, 2024
4773688
Merge branch 'refs/heads/master' into feature/set-command
MeikelLP Nov 26, 2024
a907113
feat(game): implement /set_maxhp command
MeikelLP Nov 26, 2024
fd3fc9d
refactor(game): rename SendAsync -> Send
MeikelLP Nov 26, 2024
0c0f34e
feat(game): implement /setskill command
MeikelLP Nov 26, 2024
c266b8a
feat(game): implement /con+
MeikelLP Nov 26, 2024
622836c
feat(game): implement /mspd command
MeikelLP Nov 26, 2024
475486f
feat(game): implement /stat_reset command
MeikelLP Nov 26, 2024
eefbedf
feat(game): implement /all_skills_master command
MeikelLP Nov 26, 2024
1d5d945
refactor(game): implement EPlayerClassGendered
MeikelLP Nov 26, 2024
7bd3760
fix(game): equip shields
MeikelLP Nov 26, 2024
fe45581
feat(game): implement /full_set command
MeikelLP Nov 26, 2024
1b8ee98
feat(game): Implement /m + /mob command
MeikelLP Nov 28, 2024
b60b16d
feat(game): Implement /mob_ld command
MeikelLP Nov 28, 2024
e9f6210
fix(game): /set [Name] exp [Value] causing a stack overflow
MeikelLP Nov 29, 2024
7493553
feat(game): Implement /mm command
MeikelLP Nov 29, 2024
56ca39e
feat(game): Implement /group command
MeikelLP Nov 29, 2024
40bb0f8
feat(game): Implement /grrandom command
MeikelLP Nov 29, 2024
b404fec
feat(game): Implement /state command
MeikelLP Nov 29, 2024
2f859ef
feat(game): Implement /gstate command
MeikelLP Nov 29, 2024
32fa285
Merge branch 'feature/monster-commands' into feature/set-command
MeikelLP Nov 29, 2024
a73eb4f
feat(game): Implement /purge command
MeikelLP Nov 29, 2024
b0f9997
refactor(game): improved command error messages
MeikelLP Nov 29, 2024
644305b
Merge branch 'master' into feature/set-command
MeikelLP Dec 13, 2024
d98ec45
Merge branch 'master' into feature/set-command
MeikelLP Dec 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/CorePluginAPI/Core/Models/IPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class PlayerData
public uint Id { get; set; }
public Guid AccountId { get; set; }
public string Name { get; set; } = "";
public byte PlayerClass { get; set; }
public EPlayerClassGendered PlayerClass { get; set; }
public byte SkillGroup { get; set; }
public ulong PlayTime { get; set; }
public byte Level { get; set; } = 1;
Expand Down
2 changes: 1 addition & 1 deletion src/CorePluginAPI/EPlayerClass.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace QuantumCore.API;

public enum EPlayerClass
public enum EPlayerClass : byte
{
Warrior = 0,
Ninja = 1,
Expand Down
13 changes: 13 additions & 0 deletions src/CorePluginAPI/EPlayerClassGendered.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace QuantumCore.API;

public enum EPlayerClassGendered : byte
{
WarriorMale = 0,
NinjaFemale = 1,
SuraMale = 2,
ShamanFemale = 3,
WarriorFemale = 4,
NinjaMale = 5,
SuraFemale = 6,
ShamanMale = 7,
}
19 changes: 19 additions & 0 deletions src/CorePluginAPI/EPlayerJob.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace QuantumCore.API;

public enum EPlayerJob : byte
{
WarriorBody = 0,
NinjaDagger = 1,
SuraWeapons = 2,
ShamanDragon = 3,
WarriorMind = 4,
NinjaBow = 5,
SuraMagic = 6,
ShamanLightning = 7
}

public enum EPlayerGender : byte
{
Male = 0,
Female = 1
}
4 changes: 3 additions & 1 deletion src/CorePluginAPI/EquipmentSlots.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace QuantumCore.API;

public enum EquipmentSlots
public enum EquipmentSlots : byte
{
Body = 0,
Head = 1,
Expand All @@ -11,6 +11,8 @@ public enum EquipmentSlots
Earring = 6,
Unique1 = 7,
Unique2 = 8,
Arrow = 9,
Shield = 10,
Costume = 19,
Hair = 20
}
36 changes: 36 additions & 0 deletions src/CorePluginAPI/Extensions/PlayerExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
namespace QuantumCore.API.Extensions;

public static class PlayerExtensions
{
public static EPlayerClass GetClass(this EPlayerClassGendered playerClass)
{
return playerClass switch
{
EPlayerClassGendered.WarriorMale => EPlayerClass.Warrior,
EPlayerClassGendered.NinjaFemale => EPlayerClass.Ninja,
EPlayerClassGendered.SuraMale => EPlayerClass.Sura,
EPlayerClassGendered.ShamanFemale => EPlayerClass.Shaman,
EPlayerClassGendered.WarriorFemale => EPlayerClass.Warrior,
EPlayerClassGendered.NinjaMale => EPlayerClass.Ninja,
EPlayerClassGendered.SuraFemale => EPlayerClass.Sura,
EPlayerClassGendered.ShamanMale => EPlayerClass.Shaman,
_ => throw new ArgumentOutOfRangeException(nameof(playerClass), playerClass, null)
};
}

public static EPlayerGender GetGender(this EPlayerClassGendered playerClass)
{
return playerClass switch
{
EPlayerClassGendered.WarriorMale => EPlayerGender.Male,
EPlayerClassGendered.NinjaFemale => EPlayerGender.Female,
EPlayerClassGendered.SuraMale => EPlayerGender.Male,
EPlayerClassGendered.ShamanFemale => EPlayerGender.Female,
EPlayerClassGendered.WarriorFemale => EPlayerGender.Female,
EPlayerClassGendered.NinjaMale => EPlayerGender.Male,
EPlayerClassGendered.SuraFemale => EPlayerGender.Female,
EPlayerClassGendered.ShamanMale => EPlayerGender.Male,
_ => throw new ArgumentOutOfRangeException(nameof(playerClass), playerClass, null)
};
}
}
4 changes: 2 additions & 2 deletions src/CorePluginAPI/Game/Guild/GuildMemberData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ public class GuildMemberData
public uint Id { get; set; }
public string Name { get; set; } = "";
public byte Level { get; set; }
public byte Class { get; set; }
public EPlayerClassGendered Class { get; set; }
public bool IsLeader { get; set; }
public byte Rank { get; set; }
public uint SpentExperience { get; set; }
}
}
11 changes: 8 additions & 3 deletions src/CorePluginAPI/Game/Skills/IPlayerSkills.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@ public interface IPlayerSkills
{
Task LoadAsync();
Task PersistAsync();

ISKill? this[ESkillIndexes skillId] { get; }

void SetSkillGroup(byte skillGroup);
void ClearSkills();
void ClearSubSkills();
void Reset(ESkillIndexes skillId);
void SetLevel(ESkillIndexes skillId, byte level);
void SkillUp(ESkillIndexes skillId, ESkillLevelMethod method = ESkillLevelMethod.Point);
bool CanUse(ESkillIndexes skillId);
void SendAsync();

/// <summary>
/// Send skill info to client
/// </summary>
void Send();

bool LearnSkillByBook(ESkillIndexes skillId);
void SetSkillNextReadTime(ESkillIndexes skillId, int time);
}
53 changes: 48 additions & 5 deletions src/CorePluginAPI/Game/Types/EPoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public enum EPoints
AttackGrade = 18,
MoveSpeed = 19,
Defence = 20,
MagicAttackGrade = 22,
MagicDefenceGrade = 23,
StatusPoints = 26,
SubSkill = 27,
Skill = 28,
Expand All @@ -27,17 +29,58 @@ public enum EPoints
PlayTime = 31,
CriticalPercentage = 40,
PenetratePercentage = 41,

AttackBonusHuman = 43,
AttackBonusAnimal = 44,
AttackBonusOrc = 45,
AttackBonusEsoterics = 46,
AttackBonusUndead = 47,
AttackBonusDevil = 48,
AttackBonusInsect = 49,
AttackBonusFire = 50,
AttackBonusIce = 51,
AttackBonusDesert = 52,
AttackBonusMonster = 53,
AttackBonusWarrior = 54,
AttackBonusAssassin = 55,
AttackBonusSura = 56,
AttackBonusShaman = 57,
AttackBonusTree = 58,
ResistWarrior = 59,
ResistAssassin = 60,
ResistSura = 61,
ResistShaman = 62,
Block = 67,
Dodge = 68,
ResistSword = 69,
ResistTwoHanded = 70,
ResistDagger = 71,
ResistBell = 72,
ResistFan = 73,
ResistBow = 74,
ResistFire = 75,
ResistElectric = 76,
ResistMagic = 77,
ResistWind = 78,
ItemDropBonus = 85,

AttackBonus = 93,
DefenceBonus = 94,

HorseSkill = 113,


MallAttBonus = 114,
MallDefBonus = 115,
MallExpBonus = 116,
MallItemBonus = 117,

MallGoldBonus = 118,
SkillDamageBonus = 121,
NormalHitDamageBonus = 122,
SkillDefendBonus = 123,
NormalHitDefendBonus = 124,
MagicAttackBonus = 132,
ResistIce = 133,
ResistEarth = 134,
ResistDark = 135,
ResistCritical = 136,
ResistPenetrate = 137,
MinWeaponDamage = 200,
Expand Down
2 changes: 2 additions & 0 deletions src/CorePluginAPI/Game/World/IEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public interface IEntity
public void ShowEntity(IConnection connection);
public void HideEntity(IConnection connection);
IReadOnlyCollection<IEntity> NearbyEntities { get; }
byte MovementSpeed { get; set; }
byte AttackSpeed { get; set; }

public uint GetPoint(EPoints point);
public int GetMinDamage();
Expand Down
1 change: 1 addition & 0 deletions src/CorePluginAPI/Game/World/IPlayerEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@ public interface IPlayerEntity : IEntity
int GetPremiumRemainSeconds(EPremiumTypes type);
bool IsUsableSkillMotion(int motion);
Task RefreshGuildAsync();
void RecalculateStatusPoints();
}
}
3 changes: 2 additions & 1 deletion src/CorePluginAPI/Game/World/IWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public interface IWorld : ILoadable
CoreHost GetMapHost(int x, int y);
#nullable enable
SpawnGroup? GetGroup(uint id);
SpawnGroup GetRandomGroup();
SpawnGroupCollection? GetGroupCollection(uint id);
#nullable restore
void SpawnEntity(IEntity e);
Expand All @@ -36,4 +37,4 @@ public interface IWorld : ILoadable
IList<IPlayerEntity> GetPlayers();
IPlayerEntity? GetPlayerById(uint playerId);
}
}
}
5 changes: 2 additions & 3 deletions src/CorePluginAPI/IJobManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@

public interface IJobManager
{
byte GetJobFromClass(byte playerClass);
Job? Get(byte playerClass);
}
Job? Get(EPlayerClassGendered playerClass);
}
4 changes: 2 additions & 2 deletions src/Data/Game.Persistence/DbPlayerRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public async Task CreateAsync(PlayerData player)
Id = player.Id,
AccountId = player.AccountId,
Name = player.Name,
PlayerClass = player.PlayerClass,
PlayerClass = (byte)player.PlayerClass,
SkillGroup = player.SkillGroup,
PlayTime = player.PlayTime,
Level = player.Level,
Expand Down Expand Up @@ -83,7 +83,7 @@ public async Task SetPlayerAsync(PlayerData data)
if (entity is null) return;

entity.Empire = data.Empire;
entity.PlayerClass = data.PlayerClass;
entity.PlayerClass = (byte)data.PlayerClass;
entity.SkillGroup = data.SkillGroup;
entity.PlayTime = data.PlayTime;
entity.Level = data.Level;
Expand Down
13 changes: 6 additions & 7 deletions src/Data/Game.Persistence/Extensions/QueryExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Immutable;
using QuantumCore.API;
using QuantumCore.API.Core.Models;
using QuantumCore.API.Game.Guild;
using QuantumCore.API.Game.Skills;
Expand All @@ -16,7 +17,7 @@ public static IQueryable<PlayerData> SelectPlayerData(this IQueryable<Player> qu
Id = x.Id,
AccountId = x.AccountId,
Name = x.Name,
PlayerClass = x.PlayerClass,
PlayerClass = (EPlayerClassGendered)x.PlayerClass,
SkillGroup = x.SkillGroup,
PlayTime = x.PlayTime,
Level = x.Level,
Expand Down Expand Up @@ -46,7 +47,7 @@ public static IQueryable<Skill> SelectPlayerSkill(this IQueryable<PlayerSkill> q
return query.Select(x => new Skill
{
PlayerId = x.PlayerId,
SkillId = (ESkillIndexes) x.SkillId,
SkillId = (ESkillIndexes)x.SkillId,
MasterType = x.MasterType,
Level = x.Level,
NextReadTime = x.NextReadTime,
Expand All @@ -70,16 +71,14 @@ public static IQueryable<GuildData> SelectData(this IQueryable<Guild> query)
Id = member.Player.Id,
Name = member.Player.Name,
Level = member.Player.Level,
Class = member.Player.PlayerClass,
Class = (EPlayerClassGendered)member.Player.PlayerClass,
SpentExperience = member.SpentExperience,
Rank = member.RankPosition,
IsLeader = member.IsLeader
}).ToImmutableArray(),
Ranks = x.Ranks.Select(rank => new GuildRankData
{
Position = rank.Position,
Name = rank.Name,
Permissions = rank.Permissions
Position = rank.Position, Name = rank.Name, Permissions = rank.Permissions
}).ToImmutableArray()
});
}
Expand All @@ -96,4 +95,4 @@ public static IQueryable<ItemInstance> SelectInstance(this IQueryable<Item> quer
Count = x.Count
});
}
}
}
7 changes: 5 additions & 2 deletions src/Game.Benchmarks/Benchmarks/WorldUpdateBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void GlobalSetup()
.Replace(new ServiceDescriptor(typeof(IJobManager), _ =>
{
var mock = Substitute.For<IJobManager>();
mock.Get(1).Returns(new Job());
mock.Get(EPlayerClassGendered.NinjaFemale).Returns(new Job());
return mock;
}, ServiceLifetime.Singleton))
.Replace(new ServiceDescriptor(typeof(IMonsterManager), _ =>
Expand All @@ -113,7 +113,10 @@ public void GlobalSetup()

foreach (var i in Enumerable.Range(0, PlayerAmount))
{
var player = new PlayerData {Name = i.ToString(), PlayerClass = 1, PositionX = 1, PositionY = 1};
var player = new PlayerData
{
Name = i.ToString(), PlayerClass = EPlayerClassGendered.NinjaFemale, PositionX = 1, PositionY = 1
};
var conn = Substitute.For<IGameConnection>();
var entity = ActivatorUtilities.CreateInstance<PlayerEntity>(services, _world, player, conn);
_world.SpawnEntity(entity);
Expand Down
28 changes: 26 additions & 2 deletions src/Libraries/Game.Commands/CommandManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Linq.Expressions;
using System.Reflection;
using CommandLine;
using CommandLine.Text;
using Microsoft.CodeAnalysis;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -225,8 +226,31 @@ public async Task Handle(IGameConnection connection, string chatline)
}
else
{
connection.Player.SendChatInfo(
$"Comannd validation failed: {string.Join(", ", errors.Select(x => x.GetType().Name))}");
Func<HelpText, HelpText> helpTextFunc = h =>
{
h.Copyright = "";
h.AutoVersion = false;
h.AutoHelp = false;
h.Heading = "";
return h;
};
Func<Example, Example> exampleFunc = example => example;
var verbsIndex = false;
var maxDisplayWidth = 80;
var helpTextMethod = typeof(HelpText)
.GetMethods(BindingFlags.Static | BindingFlags.Public)
.First(x => x.Name == nameof(HelpText.AutoBuild) && x.GetParameters().Length == 5)!
.MakeGenericMethod(commandCache.OptionsType);
var help = (HelpText)helpTextMethod.Invoke(null,
[parserResult, helpTextFunc, exampleFunc, verbsIndex, maxDisplayWidth])!;
var messages = help.ToString().Split(Environment.NewLine)
.Where(x => !string.IsNullOrWhiteSpace(x));
connection.Player.SendChatInfo("Comannd validation failed:");
foreach (var message in messages)
{
connection.Player.SendChatInfo(message);
}

return;
}
}
Expand Down
Loading
Loading