星露谷物语 Mod 制作 01
0x01 环境准备 1.1 硬件环境:
Windows 11 专业版 64bit 操作系统
可以胜任的 CPU 和 还算够用的内存
有可用的网络连接
1.2 软件环境: 因为不喜欢 VS 并且有 JetBrains 大礼包的授权,所以直接使用 Rider 进行开发。
1. 安装 JetBrains Rider 官网下载安装包,根据提示进行安装即可。
2. 安装 .NET 环境 需要准备 .NET 开发环境,推荐使用的版本是 .NET Framework 4.6.2,与其相匹配的 SDK 版本为 .NET 6.0,。
获取 .NET SDK 6.0 及 .NET Framework 4.6.2
获取地址
下载完成后按引导进行安装。
构建 Mod 创建项目 使用 Rider 创建解决方案,类型选择 .NET FrameWork,若没有找到或者无法继续,可能是 .NET 环境未就绪或环境变量配置错误导致,自行查阅文档工具进行排查。
为项目设置一个好记的名字和方便寻找的位置,即可点击创建。
通过 NuGet 获取 StardewModdingAPI 在解决方案上右键,选择 Manage NuGet Packages 或通过菜单、快捷键等方式打开管理器,搜索 Pathoschild.Stardew.ModBuildConfig
, 进行安装。
搜索结果:
如果报错The type or namespace name “StardewModdingAPI” could not be found,可能是您的游戏未安装或游戏路径未能被识别。
编写 Mod 脚本 Mod 脚本自行进行编写,具体实现参考 Wiki。
此处以增加每日问候和钓鱼成功后的提示为例进行说明。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 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 ]; } } }
构筑dll 直接点击 Build 进行构筑,忽略警告直接继续。
测试运行 从项目目录下可获得 Mod 相关文件,将其放入游戏目录下即可运行,通过 Rider 直接点击运行也可进行调试。