Skip to content

Commit

Permalink
Merge branch 'master' of github.com:phorcys/Taiwu_mods into taiwu
Browse files Browse the repository at this point in the history
  • Loading branch information
sth4nothing committed Nov 25, 2018
2 parents 5e7fa3c + b46fdbf commit fe5ed87
Show file tree
Hide file tree
Showing 6 changed files with 748 additions and 48 deletions.
1 change: 1 addition & 0 deletions Majordomo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.psd
47 changes: 13 additions & 34 deletions Majordomo/AutoHarvest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@

namespace Majordomo
{
class AutoHarvest
public class AutoHarvest
{
// 自动收获过月事件 ID
public const int TURN_EVENT_ID = 1001;

// 收获物类型
public const int BOOTY_TYPE_RESOURCE = 0;
public const int BOOTY_TYPE_ITEM = 1;
Expand Down Expand Up @@ -81,17 +78,14 @@ public static void RecordBooty(int[] booty)

public static string GetBootiesSummary()
{
if (AutoHarvest.harvestedResources.Count == 0 &&
AutoHarvest.harvestedItems.Count == 0 &&
AutoHarvest.harvestedActors.Count == 0)
return "您的管家禀告:本月尚无收获。\n";

string summary = "您的管家禀告了如下收获:\n";

string summary = "";
summary += GetHarvestedResourcesSummary();
summary += GetHarvestedItemsSummary();
summary += GetHarvestedActorsSummary();

if (string.IsNullOrEmpty(summary)) summary = "本月尚无收获。\n";
else summary = "本月收获" + summary;

return summary;
}

Expand Down Expand Up @@ -237,6 +231,8 @@ private static bool GetBooty(int partId, int placeId, int buildingIndex, int[] b
DateFile.instance.FamilyActorLeave(bootyId, 16);
DateFile.instance.MoveToPlace(int.Parse(DateFile.instance.GetGangDate(16, 3)), int.Parse(DateFile.instance.GetGangDate(16, 4)), bootyId, fromPart: false);
UIDate.instance.UpdateManpower();

AutoHarvest.LogNewVillagerMerchantType(bootyId);
break;
}
default:
Expand All @@ -260,30 +256,13 @@ private static bool GetBooty(int partId, int placeId, int buildingIndex, int[] b
}


// 注册月初事件
// changTrunEvent format: [turnEventId, param1, param2, ...]
// current changTrunEvent: [AutoHarvest.TURN_EVENT_ID]
// current GameObject.name: "TrunEventIcon,{AutoHarvest.TURN_EVENT_ID}"
public static void RegisterEvent(ref UIDate __instance)
{
__instance.changTrunEvents.Add(new int[] { AutoHarvest.TURN_EVENT_ID });
}


// 设置月初事件文字
public static void SetEventText(WindowManage __instance, bool on, GameObject tips)
// 在 log 中输出新村民的潜在商队
private static void LogNewVillagerMerchantType(int actorId)
{
if (tips == null || !on) return;
if (tips.tag != "TrunEventIcon") return;

string[] eventParams = tips.name.Split(',');
int eventId = (eventParams.Length > 1) ? int.Parse(eventParams[1]) : 0;

if (eventId != AutoHarvest.TURN_EVENT_ID) return;

__instance.informationName.text = DateFile.instance.trunEventDate[eventId][0];

__instance.informationMassage.text = AutoHarvest.GetBootiesSummary();
int gangType = int.Parse(DateFile.instance.GetActorDate(actorId, 9, addValue: false));
int merchantType = int.Parse(DateFile.instance.GetGangDate(gangType, 16));
string merchantTypeName = DateFile.instance.storyShopDate[merchantType][0];
Main.Logger.Log($"新村民:{DateFile.instance.GetActorName(actorId)},潜在商队:{merchantTypeName}");
}
}
}
2 changes: 1 addition & 1 deletion Majordomo/Info.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"Id": "Majordomo",
"DisplayName": "太吾管家",
"Author": "fenghou",
"Version": "0.0.2",
"Version": "0.5.0",
"AssemblyName": "Majordomo.dll",
"EntryMethod": "Majordomo.Main.Load",
"Requirements": ["BaseResourceMod-1.0.7"]
Expand Down
141 changes: 130 additions & 11 deletions Majordomo/Majordomo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@ namespace Majordomo
{
public class Settings : UnityModManager.ModSettings
{

public bool autoHarvestItems = true; // 自动收获物品
public bool autoHarvestActors = true; // 自动接纳新村民
// 自动收获
public bool autoHarvestItems = true; // 自动收获物品
public bool autoHarvestActors = true; // 自动接纳新村民

// 资源维护
public int resMinHolding = 3; // 资源保有量警戒值(每月消耗量的倍数)
public int[] resIdealHolding = null; // 期望资源保有量
public float resInitIdealHoldingRatio = 0.8f; // 期望资源保有量的初始值(占当前最大值的比例)
public int moneyMinHolding = 10000; // 银钱最低保有量(高于此值管家可花费银钱进行采购)

public override void Save(UnityModManager.ModEntry modEntry)
{
Expand Down Expand Up @@ -72,11 +77,36 @@ public static bool OnToggle(UnityModManager.ModEntry modEntry, bool value)
static void OnGUI(UnityModManager.ModEntry modEntry)
{
GUILayout.BeginHorizontal();
GUILayout.Label("自动收获");
GUILayout.Label("<color=#87CEEB>自动收获</color>");
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
Main.settings.autoHarvestItems = GUILayout.Toggle(Main.settings.autoHarvestItems, "自动收获物品");
Main.settings.autoHarvestActors = GUILayout.Toggle(Main.settings.autoHarvestActors, "自动接纳新村民");
Main.settings.autoHarvestItems = GUILayout.Toggle(Main.settings.autoHarvestItems, "自动收获物品", GUILayout.Width(120));
Main.settings.autoHarvestActors = GUILayout.Toggle(Main.settings.autoHarvestActors, "自动接纳新村民", GUILayout.Width(120));
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();

GUILayout.BeginHorizontal();
GUILayout.Label("\n<color=#87CEEB>资源维护</color>");
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.Label("资源保有量警戒值:每月消耗量的");
var resMinHolding = GUILayout.TextField(Main.settings.resMinHolding.ToString(), 4, GUILayout.Width(45));
if (GUI.changed && !int.TryParse(resMinHolding, out Main.settings.resMinHolding))
{
Main.settings.resMinHolding = 3;
}
GUILayout.Label("倍,低于此值管家会进行提醒");
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.Label("银钱最低保有量:");
var moneyMinHolding = GUILayout.TextField(Main.settings.moneyMinHolding.ToString(), 9, GUILayout.Width(85));
if (GUI.changed && !int.TryParse(moneyMinHolding, out Main.settings.moneyMinHolding))
{
Main.settings.moneyMinHolding = 10000;
}
GUILayout.Label(",高于此值管家可花费银钱进行采购");
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
}

Expand All @@ -88,32 +118,121 @@ static void OnSaveGUI(UnityModManager.ModEntry modEntry)
}


// 月初自动工作入口
public class TurnEvent
{
// 太吾管家过月事件 ID
public const int EVENT_ID = 1001;


// 注册过月事件
// changTrunEvent format: [turnEventId, param1, param2, ...]
// current changTrunEvent: [TurnEvent.EVENT_ID]
// current GameObject.name: "TrunEventIcon,{TurnEvent.EVENT_ID}"
public static void RegisterEvent(UIDate __instance)
{
__instance.changTrunEvents.Add(new int[] { TurnEvent.EVENT_ID });
}


// 设置过月事件文字
public static void SetEventText(WindowManage __instance, bool on, GameObject tips)
{
if (tips == null || !on) return;
if (tips.tag != "TrunEventIcon") return;

string[] eventParams = tips.name.Split(',');
int eventId = (eventParams.Length > 1) ? int.Parse(eventParams[1]) : 0;

if (eventId != TurnEvent.EVENT_ID) return;

__instance.informationName.text = DateFile.instance.trunEventDate[eventId][0];

__instance.informationMassage.text = "您的管家向您禀报:\n" + AutoHarvest.GetBootiesSummary();

if (!string.IsNullOrEmpty(ResourceMaintainer.shoppingRecord))
{
__instance.informationMassage.text += "\n" + ResourceMaintainer.shoppingRecord;
}

if (!string.IsNullOrEmpty(ResourceMaintainer.resourceWarning))
{
__instance.informationMassage.text += "\n" + ResourceMaintainer.resourceWarning;
}
}
}


// Patch: 展示过月事件
[HarmonyPatch(typeof(UIDate), "SetTrunChangeWindow")]
public static class UIDate_SetTrunChangeWindow_Patch
{
private static bool Prefix(ref UIDate __instance)
private static bool Prefix(UIDate __instance)
{
if (!Main.enabled) return true;

AutoHarvest.GetAllBooties();

AutoHarvest.RegisterEvent(ref __instance);
ResourceMaintainer.TryBuyingResources();

ResourceMaintainer.UpdateResourceWarning();

TurnEvent.RegisterEvent(__instance);

return true;
}
}


// 月初事件图标文字
// Patch: 设置浮窗文字
[HarmonyPatch(typeof(WindowManage), "WindowSwitch")]
public static class WindowManage_WindowSwitch_Patch
{
static void Postfix(WindowManage __instance, bool on, GameObject tips)
{
if (!Main.enabled) return;

AutoHarvest.SetEventText(__instance, on, tips);
TurnEvent.SetEventText(__instance, on, tips);
}
}


// Patch: 创建 UI
[HarmonyPatch(typeof(UIDate), "Start")]
public static class UIDate_Start_Patch
{
static void Postfix()
{
if (!Main.enabled) return;

ResourceMaintainer.InitialzeResourcesIdealHolding();
}
}


// Patch: 更新 UI
[HarmonyPatch(typeof(UIDate), "Update")]
public static class UIDate_Update_Patch
{
static void Postfix()
{
if (!Main.enabled) return;

ResourceMaintainer.ShowResourceIdealHoldingText();
}
}


// Patch: 显示浮窗
[HarmonyPatch(typeof(WindowManage), "LateUpdate")]
public static class WindowManage_LateUpdate_Patch
{
static bool Prefix(WindowManage __instance)
{
if (!Main.enabled) return true;

ResourceMaintainer.InterfereFloatWindow(__instance);

return true;
}
}
}
41 changes: 39 additions & 2 deletions Majordomo/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,46 @@
# 简介
帮助太吾传人收获太吾村的产出,并在月初事件列表中展示当月数据统计。
后续还将加入自动购入资源、自动安排工作人员、提出改善经营状况的建议等功能。
此 mod 作用为帮助太吾传人管理太吾村,目前实现的功能有:

- 收获太吾村的产出
- 在过月事件列表中展示统计信息
- 资源量未达到预期时自行购入
- 资源不足时进行提醒

后续还将加入自动安排工作人员、提出改善经营状况的建议等功能。


# 功能说明
## 收获太吾村的产出
- 在过月时自动进行产出品(资源、物品、村民)的收获。
- 可配置不自动收获物品、不自动接纳新村民。

## 在过月事件列表中展示统计数据
目前展示的统计信息有:

- 上月自动收获统计
- 上月资源购买情况
- 资源严重不足提醒

## 资源量未达到预期时自行购入
- 主界面的资源栏上,当前资源的下方,会显示灰色的资源期望保有量。当资源低于期望值时,管家会尝试自行购买资源。
- 在资源栏上点击左键会增加资源期望保有量,点击右键会减少资源期望保有量,可按住鼠标左/右键快速调整该值。
- 当鼠标移动到屏幕顶部时,才会显示资源期望保有量。
- 如果当前银钱大于配置项“银钱最低保有量”,且高于配置项“资源保有量警戒值”,则换季时会用多出的银钱按照期望值购买资源。每次可购买量和服牛帮行商保持一致。

## 资源不足时进行提醒
- 配置项:资源保有量警戒值(为每月资源消耗量的倍数),如果当前资源低于警戒值,则管家会在过月事件中进行提醒。


# 注意事项
在安装 0.0.2 及后续版本的时候,必须先卸载 0.0.1 版再安装,否则新旧版本的文件混合,就会导致在读档界面卡死。
如果想手动确认旧版是否已卸载,可以看游戏根目录的 Mods 目录下,是否有 Majordomo 文件夹,没有就是卸载了。


# 历史
## 0.5.0
- 增加功能:资源量未达到预期时自行购入。
- 增加功能:资源不足时进行提醒。

## 0.0.2
- 可选择不自动收获物品(也同时不显示在统计中)。
- 更改月初事件图标。
Expand Down
Loading

0 comments on commit fe5ed87

Please sign in to comment.