Skip to content

Commit

Permalink
添加与完善经验系统 (#17)
Browse files Browse the repository at this point in the history
* 忘改版本号力
* EX依赖更新
* 完善等级系统并进行代码清理
* 内嵌增加经验指令
* U README.md
* 属性调成公开
* 添加AddExp方便调用
* 虚!
  • Loading branch information
YongAn404 authored Oct 13, 2024
1 parent 1e8d87a commit a3f536d
Show file tree
Hide file tree
Showing 23 changed files with 182 additions and 102 deletions.
39 changes: 39 additions & 0 deletions Commands/ExpCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using CommandSystem;
using Exiled.API.Features;
using Exiled.Permissions.Extensions;
using System;
using YongAnFrame;
using YongAnFrame.Commands;

namespace BAPlugin.Command
{
[CommandHandler(typeof(RemoteAdminCommandHandler))]
public class ExpCommand : ICommand
{
public string Command => "experience";

public string[] Aliases => ["pexp"];

public string Description => "用于经验的设置";

public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
response = "NO";
if (sender.CheckPermission("yongan404.level.add"))
{
if (arguments.Array.Length > 2)
{
Player.Get(arguments.Array[1]).ToFPlayer().Level += ulong.Parse(arguments.Array[2]);
response = "OK";
return true;
}
}
else
{
response = "请保证你有yongan404.level.add权限";
}

return false;
}
}
}
10 changes: 5 additions & 5 deletions Commands/MessageCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ namespace YongAnFrame.Commands
/// 发送消息指令
/// </summary>
[CommandHandler(typeof(RemoteAdminCommandHandler))]
public sealed class MessageCommand : CommandPlus
public sealed class MessageCommand : ICommand
{
public override string Command => "message";
public string Command => "message";

public override string[] Aliases => ["mes", "msg"];
public string[] Aliases => ["mes", "msg"];

public override string Description => "用于发送消息";
public string Description => "用于发送消息";

public override bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
List<FramePlayer> choicePlayer = [];
if (arguments.Count < 3)
Expand Down
11 changes: 2 additions & 9 deletions Commands/PlayerCommand.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
using CommandSystem;
using Exiled.API.Features;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YongAnFrame.Players;

namespace YongAnFrame.Commands
Expand All @@ -30,14 +26,11 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
{
FramePlayer fPlayer = FramePlayer.Get(player);
fPlayer.HintManager.Clean();
string[] text = new string[36];

fPlayer.ExPlayer.ShowHint($"<size=20>{string.Join("\n", text)}\n\n\n\n\n\n\n\n\n\n\n\n\n\n</size>", 10000f);
fPlayer.ExPlayer.ShowHint($"<size=20>{YongAnFramePlugin.Instance.Config.BypassDoNotTrackText.Split('\n')}</size>", 10000f);
}

return true;
}

}
return false;
}
Expand Down
10 changes: 5 additions & 5 deletions Commands/SkillCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ namespace YongAnFrame.Commands
/// 未完成请勿乱用
/// </summary>
[CommandHandler(typeof(ClientCommandHandler))]
public sealed class SkillsCommand : CommandPlus
public sealed class SkillsCommand : ICommand
{
public override string Command => "skills";
public string Command => "skills";

public override string[] Aliases => ["sk"];
public string[] Aliases => ["sk"];

public override string Description => "skills";
public string Description => "skills";

public override bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
response = "NO";

Expand Down
14 changes: 4 additions & 10 deletions Components/CapacityList.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using Exiled.API.Features;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;

namespace YongAnFrame.Components
{
Expand All @@ -16,9 +10,9 @@ public class CapacityList<T>(int capacity)

public int Count => list.Count;

public T this[int index]
{
get
public T this[int index]
{
get
{
if (Count > index)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,8 @@ namespace YongAnFrame.Events.EventArgs.FramePlayer
/// <summary>
/// FramePlayer被无效时的事件数据
/// </summary>
public sealed class FramePlayerInvalidatingEventArgs : IExiledEvent
public sealed class FramePlayerInvalidatingEventArgs(Players.FramePlayer fPlayer) : IExiledEvent
{
public Players.FramePlayer FPlayer { get; }

public FramePlayerInvalidatingEventArgs(Players.FramePlayer fPlayer)
{
FPlayer = fPlayer;
}
public Players.FramePlayer FPlayer { get; } = fPlayer;
}
}
8 changes: 8 additions & 0 deletions Events/Handlers/FramePlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,19 @@ public sealed class FramePlayer
/// FramePlayer被无效时的事件
/// </summary>
public static Event<FramePlayerInvalidatingEventArgs> FramePlayerInvalidating { get; set; } = new Event<FramePlayerInvalidatingEventArgs>();
/// <summary>
/// FramePlayer提示刷新前的事件
/// </summary>
public static Event FramePlayerHintUpdate { get; set; } = new Event();

public static void OnFramePlayerCreated(FramePlayerCreatedEventArgs args)
{
FramePlayerCreated.InvokeSafely(args);
}
public static void OnFramerHintUpdate()
{
FramePlayerHintUpdate.InvokeSafely();
}
public static void OnFramePlayerInvalidating(FramePlayerInvalidatingEventArgs args)
{
FramePlayerInvalidating.InvokeSafely(args);
Expand Down
7 changes: 7 additions & 0 deletions Players/CustomPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@ public abstract class CustomPlayer(FramePlayer player)
{
public FramePlayer FramePlayer { get; private set; } = player;
public bool IsInvalid => FramePlayer == null;
public float ExpMultiplier { get { return FramePlayer.ExpMultiplier; } set { FramePlayer.ExpMultiplier = value; } }
public ulong Exp { get { return FramePlayer.Exp; } set { FramePlayer.Exp = value; } }
public ulong Level { get { return FramePlayer.Level; } set { FramePlayer.Level = value; } }
public HintManager HintManager => FramePlayer.HintManager;
public PlayerTitle UsingTitles { get { return FramePlayer.UsingTitles; } set { FramePlayer.UsingTitles = value; } }
public PlayerTitle UsingRankTitles { get { return FramePlayer.UsingRankTitles; } set { FramePlayer.UsingRankTitles = value; } }

public void AddExp(ulong exp, string name = "未知原因")
{
FramePlayer.AddExp(exp, name);
}

public virtual void Invalid()
{
FramePlayer = null;
Expand Down
54 changes: 51 additions & 3 deletions Players/FramePlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
using Exiled.Events.EventArgs.Player;
using Exiled.Events.Features;
using MEC;
using System;
using System.Collections.Generic;
using System.Linq;
using YongAnFrame.Events.EventArgs.FramePlayer;
using YongAnFrame.Roles;
using static YongAnFrame.Players.HintManager;

namespace YongAnFrame.Players
{
public sealed class FramePlayer
public sealed class FramePlayer : ICustomAlgorithm
{
private PlayerTitle usingTitles = null;
private PlayerTitle usingRankTitles = null;
Expand All @@ -31,7 +32,8 @@ public sealed class FramePlayer
/// <summary>
/// 实例拥有的自定义角色
/// </summary>
public CustomRolePlus CustomRolePlus {
public CustomRolePlus CustomRolePlus
{
get
{
if (ExPlayer.GetCustomRoles().Count != 0)
Expand All @@ -45,11 +47,25 @@ public CustomRolePlus CustomRolePlus {
/// 提示系统管理器
/// </summary>
public HintManager HintManager { get; private set; }

/// <summary>
/// 正在使用的主要自定义算法
/// </summary>
public ICustomAlgorithm CustomAlgorithm { get; set; }

/// <summary>
/// 玩家等级
/// </summary>
public ulong Level { get; set; }
/// <summary>
/// 玩家经验
/// </summary>
public ulong Exp { get; set; }
/// <summary>
/// 玩家经验倍率
/// </summary>
public float ExpMultiplier { get; set; }
/// <summary>
/// 玩家批准绕过DNT
/// </summary>
public bool IsBDNT { get; set; }
Expand Down Expand Up @@ -104,9 +120,36 @@ internal FramePlayer(Player player)
ExPlayer = player;
HintManager = new HintManager(this);
dictionary.Add(ExPlayer.Id, this);
CustomAlgorithm = this;
Events.Handlers.FramePlayer.OnFramePlayerCreated(new FramePlayerCreatedEventArgs(this));
}

public void AddExp(ulong exp, string name = "未知原因")
{
float globalExpMultiplier = YongAnFramePlugin.Instance.Config.GlobalExpMultiplier;
float expMultiplier = ExpMultiplier * globalExpMultiplier;
ulong addExp = (ulong)(exp * expMultiplier);

Exp += addExp;
HintManager.MessageTexts.Add(new Text($"{name},获得{exp}+{addExp - exp}经验({expMultiplier}倍经验)", 5));

ulong needExp = CustomAlgorithm.GetNeedUpLevel(Level);
ulong oldLevel = Level;
while (Exp >= needExp)
{
Log.Debug($"{Exp}/{needExp}");
Level++;
Exp -= needExp;
needExp = CustomAlgorithm.GetNeedUpLevel(Level);
}
if (oldLevel < Level)
{
UpdateShowInfoList();
HintManager.MessageTexts.Add(new Text($"恭喜你从{oldLevel}级到达{Level}级,距离下一级需要{Exp}/{needExp}经验", 8));
}
}


#region ShowRank

private readonly CoroutineHandle[] coroutines = new CoroutineHandle[2];
Expand Down Expand Up @@ -236,6 +279,11 @@ private IEnumerator<float> DynamicTitlesShow()
}
#endregion

public ulong GetNeedUpLevel(ulong level)
{
return (ulong)(100 + Math.Floor(level / 10f) * 100);
}

/// <summary>
/// 获取框架玩家
/// </summary>
Expand Down
23 changes: 8 additions & 15 deletions Players/HintManager.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using Exiled.API.Features;
using MEC;
using MEC;
using System.Collections.Generic;
using System.Reflection;
using YongAnFrame.Components;

namespace YongAnFrame.Players
Expand Down Expand Up @@ -31,23 +29,24 @@ public IEnumerator<float> Update()
{
while (true)
{
Events.Handlers.FramePlayer.OnFramerHintUpdate();
string[] text = new string[36];

int used = 0;
text[used] = $"YongAnFrame 1.0.0-alpha7";
text[used] = $"YongAnFrame 1.0.0-Beta1";

if (fPlayer.ExPlayer.DoNotTrack && !fPlayer.IsBDNT)
{
text[used] = "[注意]已开启DoNotTrack(DNT),游戏数据不会被保存,想保存数据请控制台输入pl BDNT查看详情";
}

used = 1;
text[used] = "<align=left>";

for (int i = 0; i < ChatTexts.Capacity; i++)
{
Text chatText = ChatTexts[i];
if(chatText != null)
if (chatText != null)
{
text[used] += chatText;
chatText.Duration--;
Expand Down Expand Up @@ -109,16 +108,10 @@ public void Clean()
Timing.KillCoroutines(coroutine);
}

public class Text
public class Text(string text, float duration, int size = 0)

Check warning on line 111 in Players/HintManager.cs

View workflow job for this annotation

GitHub Actions / build

Parameter 'size' is unread.

Check warning on line 111 in Players/HintManager.cs

View workflow job for this annotation

GitHub Actions / build

Parameter 'size' is unread.

Check warning on line 111 in Players/HintManager.cs

View workflow job for this annotation

GitHub Actions / build

Parameter 'size' is unread.

Check warning on line 111 in Players/HintManager.cs

View workflow job for this annotation

GitHub Actions / build

Parameter 'size' is unread.
{
public string Content { get; private set; }
public float Duration { get; internal set; }

public Text(string text, float duration, int size = 0)
{
Content = text;
Duration = duration;
}
public string Content { get; private set; } = text;
public float Duration { get; internal set; } = duration;

public override string ToString()
{
Expand Down
7 changes: 7 additions & 0 deletions Players/ICustomAlgorithm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace YongAnFrame.Players
{
public interface ICustomAlgorithm
{
public ulong GetNeedUpLevel(ulong level);
}
}
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.7")]
[assembly: AssemblyFileVersion("1.0.0.7")]
[assembly: AssemblyVersion("1.0.0.9")]
[assembly: AssemblyFileVersion("1.0.0.9")]
Loading

0 comments on commit a3f536d

Please sign in to comment.