diff --git a/Economics.NPC/Config.cs b/Economics.NPC/Config.cs new file mode 100644 index 00000000..db155dad --- /dev/null +++ b/Economics.NPC/Config.cs @@ -0,0 +1,18 @@ +using Newtonsoft.Json; + +namespace Economics.NPC; + +public class Config +{ + [JsonProperty("开启提示")] + public bool Prompt = true; + + [JsonProperty("提示内容")] + public string PromptText = "你因击杀{0},获得额外奖励{1}{2}个"; + + [JsonProperty("额外奖励列表")] + public List NPCS = new(); + + [JsonProperty("转换率更改")] + public Dictionary AllocationRatio = new(); +} diff --git a/Economics.NPC/Economics.NPC.csproj b/Economics.NPC/Economics.NPC.csproj new file mode 100644 index 00000000..2baf035b --- /dev/null +++ b/Economics.NPC/Economics.NPC.csproj @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/Economics.NPC/NpcOption.cs b/Economics.NPC/NpcOption.cs new file mode 100644 index 00000000..7e0fd3ce --- /dev/null +++ b/Economics.NPC/NpcOption.cs @@ -0,0 +1,19 @@ +using Newtonsoft.Json; + +namespace Economics.NPC; + +public class NpcOption +{ + [JsonProperty("怪物ID")] + public int ID { get; set; } + + [JsonProperty("怪物名称")] + public string Name { get; set; } = string.Empty; + + [JsonProperty("奖励货币")] + public long ExtraReward { get; set; } + + [JsonProperty("按输出瓜分")] + public bool DynamicPartition { get; set; } = true; + +} \ No newline at end of file diff --git a/Economics.NPC/Plugin.cs b/Economics.NPC/Plugin.cs new file mode 100644 index 00000000..f6aef177 --- /dev/null +++ b/Economics.NPC/Plugin.cs @@ -0,0 +1,78 @@ +using EconomicsAPI.Configured; +using EconomicsAPI.Extensions; +using Microsoft.Xna.Framework; +using System.Reflection; +using Terraria; +using TerrariaApi.Server; +using TShockAPI.Hooks; + +namespace Economics.NPC; + +[ApiVersion(2, 1)] +public class Plugin : TerrariaPlugin +{ + public override string Author => "少司命"; + + public override string Description => Assembly.GetExecutingAssembly().GetName().Name!; + + public override string Name => Assembly.GetExecutingAssembly().GetName().Name!; + + public override Version Version => Assembly.GetExecutingAssembly().GetName().Version!; + + internal static string PATH = Path.Combine(EconomicsAPI.Economics.SaveDirPath, "NPC.json"); + + private static Config Config = new(); + + public Plugin(Main game) : base(game) + { + } + + public override void Initialize() + { + LoadConfig(); + EconomicsAPI.Events.PlayerHandler.OnPlayerKillNpc += OnPlayerKillNpc; + GeneralHooks.ReloadEvent += (_) => LoadConfig(); + } + + private void LoadConfig() + { + if(!File.Exists(PATH)) + { + Config.NPCS.Add(new()); + } + Config = ConfigHelper.LoadConfig(PATH, Config); + } + + private void OnPlayerKillNpc(EconomicsAPI.EventArgs.PlayerEventArgs.PlayerKillNpcArgs args) + { + if (args.Npc == null || args.Player == null) return; + if (Config.AllocationRatio.TryGetValue(args.Npc.netID, out double ra)) + { + double rw = args.Damage / args.Npc.lifeMax; + long Curr = Convert.ToInt64(rw * ra); + EconomicsAPI.Economics.CurrencyManager.AddUserCurrency(args.Player.Name, Curr); + args.Player.SendCombatMsg($"+{Curr}$", Color.AliceBlue); + args.Handler = true; + return; + } + + var cfg = Config.NPCS.Find(f => f.ID == args.Npc.netID); + if (cfg != null) + { + if (cfg.DynamicPartition) + { + double rw = args.Damage / args.Npc.lifeMax; + long Curr = Convert.ToInt64(Math.Round(rw * cfg.ExtraReward)); + EconomicsAPI.Economics.CurrencyManager.AddUserCurrency(args.Player.Name, Curr); + if (Config.Prompt) + args.Player.SendInfoMessage(Config.PromptText, args.Npc.GetFullNetName(), EconomicsAPI.Economics.Setting.CurrencyName, Curr); + } + else + { + EconomicsAPI.Economics.CurrencyManager.AddUserCurrency(args.Player.Name, cfg.ExtraReward); + if (Config.Prompt) + args.Player.SendInfoMessage(Config.PromptText, args.Npc.GetFullNetName(), EconomicsAPI.Economics.Setting.CurrencyName, cfg.ExtraReward); + } + } + } +} diff --git a/Economics.NPC/README.md b/Economics.NPC/README.md new file mode 100644 index 00000000..e3cfc333 --- /dev/null +++ b/Economics.NPC/README.md @@ -0,0 +1,40 @@ +# Economics.NPC 插件 自定义怪物奖励 + +- 作者: 少司命 +- 出处: 无 +- 配置 NPC 专属奖励 + +## 更新日志 + +``` +无 +``` + +## 指令 + +无 + +## 配置 + +```json +{ + "开启提示": true, + "提示内容": "你因击杀{0},获得额外奖励{1}{2}个", + "额外奖励列表": [ + { + "怪物ID": 390, + "怪物名称": "猪鲨", + "奖励货币": 100000, + "按输出瓜分": true // false 时每个人发10000奖励 + } + ], + "转换率更改": { + "50": 1.3 //id 和 转换率 + } +} +``` + +## 反馈 + +- 共同维护的插件库:https://github.com/Controllerdestiny/TShockPlugin +- 国内社区 trhub.cn 或 TShock 官方群等 diff --git a/Plugin.sln b/Plugin.sln index f79e29f9..cfe2116f 100644 --- a/Plugin.sln +++ b/Plugin.sln @@ -156,6 +156,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WeaponPlus", "WeaponPlusCos EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Economics.Projectile", "Economics.Projectile\Economics.Projectile.csproj", "{1F11D206-B4CE-430B-A8BD-6D7C93BC4C8F}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Economics.NPC", "Economics.NPC\Economics.NPC.csproj", "{40542E99-97E7-4A2F-A7FA-4405CAAF0967}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -756,6 +758,14 @@ Global {1F11D206-B4CE-430B-A8BD-6D7C93BC4C8F}.Release|Any CPU.Build.0 = Release|Any CPU {1F11D206-B4CE-430B-A8BD-6D7C93BC4C8F}.Release|x64.ActiveCfg = Release|Any CPU {1F11D206-B4CE-430B-A8BD-6D7C93BC4C8F}.Release|x64.Build.0 = Release|Any CPU + {40542E99-97E7-4A2F-A7FA-4405CAAF0967}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {40542E99-97E7-4A2F-A7FA-4405CAAF0967}.Debug|Any CPU.Build.0 = Debug|Any CPU + {40542E99-97E7-4A2F-A7FA-4405CAAF0967}.Debug|x64.ActiveCfg = Debug|Any CPU + {40542E99-97E7-4A2F-A7FA-4405CAAF0967}.Debug|x64.Build.0 = Debug|Any CPU + {40542E99-97E7-4A2F-A7FA-4405CAAF0967}.Release|Any CPU.ActiveCfg = Release|Any CPU + {40542E99-97E7-4A2F-A7FA-4405CAAF0967}.Release|Any CPU.Build.0 = Release|Any CPU + {40542E99-97E7-4A2F-A7FA-4405CAAF0967}.Release|x64.ActiveCfg = Release|Any CPU + {40542E99-97E7-4A2F-A7FA-4405CAAF0967}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/README.md b/README.md index 0c529ba6..fce3e76b 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,7 @@ | [Economics.Skill](Economics.Skill/README.md) | 技能插件(未完成) | EconomicsAPI
Economics.RPG | | [Economics.Regain](Economics.Regain/README.md) | 物品回收 | EconomicsAPI | | [Economics.Projectile](Economics.Projectile/README.md) | 自定义弹幕 | EconomicsAPI
Economics.RPG | +| [Economics.NPC](Economics.NPC/README.md) | 自定义怪物奖励 | EconomicsAPI | | [CreateSpawn](CreateSpawn/README.md) | 出生点建筑生成 | 无 | | [AutoBroadcast](AutoBroadcast/README.md) | 自动广播 | 无 | | [AutoTeam](AutoTeam/README.md) | 自动队伍 | 无 |