矿架升级:给原版电子元件加上作用于矿架的判断,5 槽流程走通
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ed7d2bd088
commit
7d89ccfeac
2 files changed
+48
-5
No files matched your search
@@ -46,6 +46,7 @@ namespace Decentralized
|
||||
{
|
||||
dir.Add(Terminal, CreateTerminal);
|
||||
dir.Add(Rig, CreateRig);
|
||||
WrapElectronics(dir);
|
||||
dir.Add(Guide, CreateGuide);
|
||||
dir.Add(Web3Guide, CreateWeb3Guide);
|
||||
dir.Add(HwWallet, CreateHwWallet);
|
||||
@@ -475,6 +476,7 @@ namespace Decentralized
|
||||
var rig = ItemDirectory.CreateEmptyItem(Rig).SetContentWindow(window);
|
||||
rig.SetSpriteAndShapeFromMod(ModInfo.Id, "rig");
|
||||
RigStatus.Add(rig, new[] { stCount, stPower, stHash });
|
||||
RigInv.Remove(rig); RigInv.Add(rig, Tuple.Create(cards, (GameInventory)modules));
|
||||
rig.name = L.T("item.rig.name");
|
||||
rig.unitValue = Tuning.RigPrice;
|
||||
MachineHelper.SetupBatterySlot(battery, rig);
|
||||
@@ -486,10 +488,6 @@ namespace Decentralized
|
||||
cards.mayInventoryAddItemFunc = (item, _) => GeneralHelper.IsItemOwned(item) && IsGpu(item) && !item.IsTag(DeadTag);
|
||||
cards.onSlotAddItemEndFunc = (_, _, _) => UpdateRig(rig, modules, cards);
|
||||
cards.onSlotRemoveItemEndFunc = (_, _, _) => UpdateRig(rig, modules, cards);
|
||||
// 升级:把电子元件拖到矿架上就投入(和游戏里别的机器一样,用材料作用在机器上),攒够解锁一个显卡槽
|
||||
rig.mayItemTargetThisFunc = (Func<GameItem, GameItem, bool>)Delegate.Combine(rig.mayItemTargetThisFunc, (Func<GameItem, GameItem, bool>)((src, t) => CanUpgradeWith(t, src)));
|
||||
rig.canItemTargetThisFunc = (Func<GameItem, GameItem, bool>)Delegate.Combine(rig.canItemTargetThisFunc, (Func<GameItem, GameItem, bool>)((src, t) => CanUpgradeWith(t, src)));
|
||||
rig.onItemTargetThisFunc = (Action<GameItem, GameItem>)Delegate.Combine(rig.onItemTargetThisFunc, (Action<GameItem, GameItem>)((src, t) => Log.Guard("矿架升级槽位", () => TakeUpgrade(t, cards, modules, src))));
|
||||
rig.onLoaded = _ => { ApplySlots(rig, cards); UpdateRig(rig, modules, cards); };
|
||||
rig.onCycleEndEarlySlotItemFunc = (_, _, _) => Log.Guard("矿架扣电", () => NightDraw(rig, battery, modules, cards));
|
||||
ModHelper.SetSource(rig, ModInfo.Id, ModInfo.Name);
|
||||
@@ -505,14 +503,58 @@ namespace Decentralized
|
||||
rig.contentWindow?.Validate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 电子元件作用在矿架上:游戏按“材料作用于目标”判断,元件自己的判断函数对矿架一律为否(三方判断取与),
|
||||
/// 所以要在元件上加一个对矿架为真的判断。用原版目录里的工厂造元件,再补上这三个函数。
|
||||
/// </summary>
|
||||
private static void WrapElectronics(ModItemDirectory dir)
|
||||
{
|
||||
try
|
||||
{
|
||||
var directories = (System.Collections.IDictionary)typeof(DirectoryMaster).GetField("singletonInstance", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static)?.GetValue(null);
|
||||
var list = directories?[typeof(GameItem)] as System.Collections.IList;
|
||||
if (list == null) { Log.Warn("[Rig] 找不到原版物品目录,电子元件不能升级矿架"); return; }
|
||||
foreach (var id in new[] { "common_electronic", "rare_electronic" })
|
||||
{
|
||||
Func<GameItem> vanilla = null;
|
||||
foreach (var d in list)
|
||||
{
|
||||
if (d is ModItemDirectory) continue;
|
||||
var fd = d.GetType().GetProperty("factoryDictionary")?.GetValue(d) as Dictionary<string, Func<GameItem>>;
|
||||
if (fd != null && fd.TryGetValue(id, out var f)) { vanilla = f; break; }
|
||||
}
|
||||
if (vanilla == null) { Log.Warn($"[Rig] 找不到原版 {id}"); continue; }
|
||||
var make = vanilla;
|
||||
dir.Set(id, () =>
|
||||
{
|
||||
var it = make();
|
||||
Func<GameItem, GameItem, bool> can = (src, t) => t != null && t.identifier == Rig && CanUpgradeWith(t, src);
|
||||
it.mayThisTargetItemFunc = (Func<GameItem, GameItem, bool>)Delegate.Combine(it.mayThisTargetItemFunc, can);
|
||||
it.canThisTargetItemFunc = (Func<GameItem, GameItem, bool>)Delegate.Combine(it.canThisTargetItemFunc, can);
|
||||
it.onThisTargetItemFunc = (Action<GameItem, GameItem>)Delegate.Combine(it.onThisTargetItemFunc, (Action<GameItem, GameItem>)((src, t) =>
|
||||
{
|
||||
if (t != null && t.identifier == Rig && CanUpgradeWith(t, src)) Log.Guard("矿架升级槽位", () => TakeUpgrade(t, src));
|
||||
}));
|
||||
return it;
|
||||
});
|
||||
Log.Info($"[Rig] 已给 {id} 加上升级矿架的作用");
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { Log.Error("[Rig] 包装电子元件失败:" + ex); }
|
||||
}
|
||||
|
||||
private static readonly System.Runtime.CompilerServices.ConditionalWeakTable<GameItem, Tuple<GameGridInventory, GameInventory>> RigInv = new System.Runtime.CompilerServices.ConditionalWeakTable<GameItem, Tuple<GameGridInventory, GameInventory>>();
|
||||
|
||||
private static bool CanUpgradeWith(GameItem rig, GameItem src)
|
||||
{
|
||||
var need = RigSlots.Next(SlotsOf(rig));
|
||||
return src != null && rig.identifier == Rig && need != null && src.identifier == need.Value.Item && GeneralHelper.IsItemOwned(src);
|
||||
}
|
||||
|
||||
private static void TakeUpgrade(GameItem rig, GameGridInventory cards, GameInventory modules, GameItem item)
|
||||
private static void TakeUpgrade(GameItem rig, GameItem item)
|
||||
{
|
||||
if (!RigInv.TryGetValue(rig, out var inv)) return;
|
||||
var cards = inv.Item1; var modules = inv.Item2;
|
||||
int slots = SlotsOf(rig);
|
||||
int progress = rig.IsTag(ProgressTag) ? rig.GetTagReadonly(ProgressTag).GetInt() : 0;
|
||||
int before = slots;
|
||||
|
||||
Reference in new issue
Block a user