-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #142 from Controllerdestiny/main
添加插件: Economics.NPC
- Loading branch information
Showing
7 changed files
with
175 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<NpcOption> NPCS = new(); | ||
|
||
[JsonProperty("转换率更改")] | ||
public Dictionary<int, double> AllocationRatio = new(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<Import Project="..\template.targets"/> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\EconomicsAPI\EconomicsAPI.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 官方群等 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters