因为不喜欢 VS 并且有 JetBrains 大礼包的授权,所以直接使用 Rider 进行开发。
官网下载安装包,根据提示进行安装即可。
需要准备 .NET 开发环境,推荐使用的版本是 .NET Framework 4.6.2,与其相匹配的 SDK 版本为 .NET 6.0,。
获取 .NET SDK 6.0 及 .NET Framework 4.6.2
下载完成后按引导进行安装。
使用 Rider 创建解决方案,类型选择 .NET FrameWork,若没有找到或者无法继续,可能是 .NET 环境未就绪或环境变量配置错误导致,自行查阅文档工具进行排查。
为项目设置一个好记的名字和方便寻找的位置,即可点击创建。
在解决方案上右键,选择 Manage NuGet Packages 或通过菜单、快捷键等方式打开管理器,搜索 Pathoschild.Stardew.ModBuildConfig
, 进行安装。
搜索结果:
如果报错The type or namespace name "StardewModdingAPI" could not be found,可能是您的游戏未安装或游戏路径未能被识别。
Mod 脚本自行进行编写,具体实现参考 Wiki。
此处以增加每日问候和钓鱼成功后的提示为例进行说明。
using System;
using System.Collections.Generic;
using System.Runtime.Remoting.Metadata.W3cXsd2001;
using Microsoft.Xna.Framework;
using StardewModdingAPI;
using StardewModdingAPI.Events;
using StardewValley;
internal sealed class FishMod : Mod
{
private bool _gameRuning = false;
private bool _hasPlayerInfo = false;
private Dictionary<string, int> _playerInfo = new Dictionary<string, int>();
private IModHelper _helper;
public override void Entry(IModHelper helper)
{
_helper = helper;
helper.Events.GameLoop.UpdateTicked += OnUpdateTicked;
helper.Events.GameLoop.DayStarted += OnDayStarted;
helper.Events.GameLoop.ReturnedToTitle += OnReturnedToTitle;
}
private void OnDayStarted(object sender, DayStartedEventArgs e)
{
_gameRuning = true;
string message = "";
if (_hasPlayerInfo) {
if (_playerInfo["farmingExp"] == Game1.player.experiencePoints[0] &&
_playerInfo["fishingExp"] == Game1.player.experiencePoints[1] &&
_playerInfo["foragingExp"] == Game1.player.experiencePoints[2] &&
_playerInfo["miningExp"] == Game1.player.experiencePoints[3] &&
_playerInfo["combatExp"] == Game1.player.experiencePoints[4]) {
message += "今天似乎也和昨天一样呢。";
} else {
message += "昨天获得了:";
if (_playerInfo["farmingExp"] != Game1.player.experiencePoints[0])
{
message += (Game1.player.experiencePoints[0] - _playerInfo["farmingExp"]) + "种植经验,";
}
if (_playerInfo["fishingExp"] != Game1.player.experiencePoints[1])
{
message += (Game1.player.experiencePoints[1] - _playerInfo["fishingExp"]) + "钓鱼经验,";
}
if (_playerInfo["foragingExp"] != Game1.player.experiencePoints[2])
{
message += (Game1.player.experiencePoints[2] - _playerInfo["foragingExp"]) + "觅食经验,";
}
if (_playerInfo["miningExp"] != Game1.player.experiencePoints[3])
{
message += (Game1.player.experiencePoints[3] - _playerInfo["miningExp"]) + "挖掘经验,";
}
if (_playerInfo["combatExp"] != Game1.player.experiencePoints[4])
{
message += (Game1.player.experiencePoints[4] - _playerInfo["combatExp"]) + "战斗经验,";
}
}
}else
{
message += "你回来了。";
_hasPlayerInfo = true;
}
_playerInfo["farmingExp"] = Game1.player.experiencePoints[0];
_playerInfo["fishingExp"] = Game1.player.experiencePoints[1];
_playerInfo["foragingExp"] = Game1.player.experiencePoints[2];
_playerInfo["miningExp"] = Game1.player.experiencePoints[3];
_playerInfo["combatExp"] = Game1.player.experiencePoints[4];
double luck = Game1.player.DailyLuck * 1000f;
message += "今日好运指数:" + luck + "。";
message += "这平凡的每一天都是连续发生中的奇迹。";
Game1.showGlobalMessage(message);
Game1.chatBox.addMessage(message,Color.Green);
}
private void OnReturnedToTitle(object sender, ReturnedToTitleEventArgs e)
{
_gameRuning = false;
_hasPlayerInfo = false;
}
private uint lastfish = 0;
private int lastfishexp = 0;
private void OnUpdateTicked(object sender, EventArgs e)
{
if (lastfish!=Game1.stats.fishCaught)
{
Game1.addHUDMessage(new HUDMessage($"这是你钓到的第 {Game1.stats.fishCaught} 个东西,获得了钓鱼经验 {Game1.player.experiencePoints[1]-lastfishexp} ",6));
lastfish = Game1.stats.fishCaught;
lastfishexp = Game1.player.experiencePoints[1];
}
}
}
直接点击 Build 进行构筑,忽略警告直接继续。
从项目目录下可获得 Mod 相关文件,将其放入游戏目录下即可运行,通过 Rider 直接点击运行也可进行调试。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。