暂存
This commit is contained in:
Binary file not shown.
@@ -10,6 +10,7 @@ namespace WulaFallenEmpire
|
|||||||
{
|
{
|
||||||
private const TargetIndex TableIndex = TargetIndex.A;
|
private const TargetIndex TableIndex = TargetIndex.A;
|
||||||
private const TargetIndex IngredientIndex = TargetIndex.B;
|
private const TargetIndex IngredientIndex = TargetIndex.B;
|
||||||
|
private const TargetIndex IngredientPlaceCellIndex = TargetIndex.C;
|
||||||
|
|
||||||
protected Building_GlobalWorkTable Table => (Building_GlobalWorkTable)job.GetTarget(TableIndex).Thing;
|
protected Building_GlobalWorkTable Table => (Building_GlobalWorkTable)job.GetTarget(TableIndex).Thing;
|
||||||
|
|
||||||
@@ -18,68 +19,26 @@ namespace WulaFallenEmpire
|
|||||||
if (!pawn.Reserve(Table, job, 1, -1, null, errorOnFailed))
|
if (!pawn.Reserve(Table, job, 1, -1, null, errorOnFailed))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// 预约所有材料
|
pawn.ReserveAsManyAsPossible(job.GetTargetQueue(IngredientIndex), job);
|
||||||
if (job.targetQueueB != null)
|
|
||||||
{
|
|
||||||
foreach (var target in job.targetQueueB)
|
|
||||||
{
|
|
||||||
if (!pawn.Reserve(target, job, 1, -1, null, errorOnFailed))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override IEnumerable<Toil> MakeNewToils()
|
protected override IEnumerable<Toil> MakeNewToils()
|
||||||
{
|
{
|
||||||
// 1. 收集材料
|
this.FailOnDestroyedOrNull(TableIndex);
|
||||||
Toil collect = Toils_General.DoAtomic(delegate
|
this.FailOnForbidden(TableIndex);
|
||||||
{
|
|
||||||
// 这是一个占位符,实际收集逻辑由下面的循环生成
|
// 1. 前往工作台
|
||||||
});
|
yield return Toils_Goto.GotoThing(TableIndex, PathEndMode.InteractionCell);
|
||||||
|
|
||||||
foreach (var toil in CollectIngredientsToils())
|
// 2. 收集材料 (使用原版 JobDriver_DoBill 的逻辑)
|
||||||
|
// 参数: ingredientInd, billGiverInd, ingredientPlaceCellInd, subtractNumTakenFromJobCount, failIfStackCountLessThanJobCount, placeInBillGiver
|
||||||
|
foreach (Toil toil in JobDriver_DoBill.CollectIngredientsToils(IngredientIndex, TableIndex, IngredientPlaceCellIndex, false, true, true))
|
||||||
{
|
{
|
||||||
yield return toil;
|
yield return toil;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. 运送到工作台
|
// 3. 检查并触发上传
|
||||||
yield return Toils_Goto.GotoThing(TableIndex, PathEndMode.Touch);
|
|
||||||
|
|
||||||
// 3. 放入材料
|
|
||||||
yield return new Toil
|
|
||||||
{
|
|
||||||
initAction = delegate
|
|
||||||
{
|
|
||||||
Pawn actor = GetActor();
|
|
||||||
Building_GlobalWorkTable table = Table;
|
|
||||||
|
|
||||||
// 将携带的所有相关材料放入工作台
|
|
||||||
// 注意:这里假设小人携带的都是为了这个任务
|
|
||||||
// 实际可能需要更精确的筛选
|
|
||||||
List<Thing> carriedThings = actor.inventory.innerContainer.ToList(); // 复制列表
|
|
||||||
|
|
||||||
foreach (var thing in carriedThings)
|
|
||||||
{
|
|
||||||
// 检查这个物品是否是订单需要的(简单检查Def)
|
|
||||||
// 这里简化处理:直接全部放入,多余的之后再处理或留在容器中
|
|
||||||
if (actor.inventory.innerContainer.TryTransferToContainer(thing, table.innerContainer, thing.stackCount) > 0)
|
|
||||||
{
|
|
||||||
// 成功放入
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 同时也处理手上拿着的(如果有)
|
|
||||||
if (actor.carryTracker.CarriedThing != null)
|
|
||||||
{
|
|
||||||
actor.carryTracker.innerContainer.TryTransferToContainer(actor.carryTracker.CarriedThing, table.innerContainer);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
defaultCompleteMode = ToilCompleteMode.Instant
|
|
||||||
};
|
|
||||||
|
|
||||||
// 4. 检查并触发上传
|
|
||||||
yield return new Toil
|
yield return new Toil
|
||||||
{
|
{
|
||||||
initAction = delegate
|
initAction = delegate
|
||||||
@@ -90,25 +49,6 @@ namespace WulaFallenEmpire
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<Toil> CollectIngredientsToils()
|
|
||||||
{
|
|
||||||
// 遍历队列中的所有材料
|
|
||||||
// 注意:RimWorld的原版 JobDriver_DoBill 的收集逻辑非常复杂
|
|
||||||
// 这里使用简化版:走到目标 -> 拿起 -> 下一个
|
|
||||||
|
|
||||||
Toil extract = Toils_JobTransforms.ExtractNextTargetFromQueue(IngredientIndex);
|
|
||||||
yield return extract;
|
|
||||||
|
|
||||||
Toil gotoThing = Toils_Goto.GotoThing(IngredientIndex, PathEndMode.ClosestTouch);
|
|
||||||
yield return gotoThing;
|
|
||||||
|
|
||||||
Toil takeThing = Toils_Haul.StartCarryThing(IngredientIndex, false, true);
|
|
||||||
yield return takeThing;
|
|
||||||
|
|
||||||
// 循环直到队列为空
|
|
||||||
yield return Toils_Jump.JumpIfHaveTargetInQueue(IngredientIndex, extract);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CheckAndUpload()
|
private void CheckAndUpload()
|
||||||
{
|
{
|
||||||
var table = Table;
|
var table = Table;
|
||||||
@@ -119,9 +59,6 @@ namespace WulaFallenEmpire
|
|||||||
if (order == null) return;
|
if (order == null) return;
|
||||||
|
|
||||||
// 检查是否满足需求
|
// 检查是否满足需求
|
||||||
// 这里的逻辑需要结合云端库存和本地容器库存
|
|
||||||
// 如果 (云端 + 容器) >= 需求,则触发上传
|
|
||||||
|
|
||||||
var costList = order.GetProductCostList();
|
var costList = order.GetProductCostList();
|
||||||
bool allSatisfied = true;
|
bool allSatisfied = true;
|
||||||
|
|
||||||
@@ -149,16 +86,11 @@ namespace WulaFallenEmpire
|
|||||||
|
|
||||||
if (missingInCloud > 0)
|
if (missingInCloud > 0)
|
||||||
{
|
{
|
||||||
// 从容器中移除并添加到云端
|
|
||||||
int taken = table.innerContainer.TryTransferToContainer(null, table.innerContainer, missingInCloud);
|
|
||||||
// 注意:上面的 TryTransferToContainer 用法不对,因为目标是云端(虚拟)
|
|
||||||
// 正确做法:
|
|
||||||
|
|
||||||
int toTake = missingInCloud;
|
int toTake = missingInCloud;
|
||||||
while (toTake > 0)
|
while (toTake > 0)
|
||||||
{
|
{
|
||||||
Thing t = table.innerContainer.FirstOrDefault(x => x.def == kvp.Key);
|
Thing t = table.innerContainer.FirstOrDefault(x => x.def == kvp.Key);
|
||||||
if (t == null) break; // 理论上不应该发生,因为前面检查过了
|
if (t == null) break;
|
||||||
|
|
||||||
int num = UnityEngine.Mathf.Min(t.stackCount, toTake);
|
int num = UnityEngine.Mathf.Min(t.stackCount, toTake);
|
||||||
t.SplitOff(num).Destroy(); // 销毁实体
|
t.SplitOff(num).Destroy(); // 销毁实体
|
||||||
|
|||||||
@@ -15,13 +15,13 @@ namespace WulaFallenEmpire
|
|||||||
{
|
{
|
||||||
if (!(t is Building_GlobalWorkTable table) || !table.Spawned || table.IsForbidden(pawn))
|
if (!(t is Building_GlobalWorkTable table) || !table.Spawned || table.IsForbidden(pawn))
|
||||||
{
|
{
|
||||||
// Log.Message($"[WULA_DEBUG] HasJobOnThing: Target invalid or forbidden. {t}");
|
if (forced) Log.Message($"[WULA_DEBUG] HasJobOnThing: Target invalid or forbidden. {t}");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pawn.CanReserve(table, 1, -1, null, forced))
|
if (!pawn.CanReserve(table, 1, -1, null, forced))
|
||||||
{
|
{
|
||||||
// Log.Message($"[WULA_DEBUG] HasJobOnThing: Cannot reserve table.");
|
if (forced) Log.Message($"[WULA_DEBUG] HasJobOnThing: Cannot reserve table.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,14 +29,21 @@ namespace WulaFallenEmpire
|
|||||||
var order = table.globalOrderStack.orders.FirstOrDefault(o => o.state == GlobalProductionOrder.ProductionState.Gathering && !o.paused);
|
var order = table.globalOrderStack.orders.FirstOrDefault(o => o.state == GlobalProductionOrder.ProductionState.Gathering && !o.paused);
|
||||||
if (order == null)
|
if (order == null)
|
||||||
{
|
{
|
||||||
// Log.Message($"[WULA_DEBUG] HasJobOnThing: No gathering order found.");
|
if (forced)
|
||||||
|
{
|
||||||
|
Log.Message($"[WULA_DEBUG] HasJobOnThing: No gathering order found. Total orders: {table.globalOrderStack.orders.Count}");
|
||||||
|
foreach (var o in table.globalOrderStack.orders)
|
||||||
|
{
|
||||||
|
Log.Message($" - Order: {o.Label}, State: {o.state}, Paused: {o.paused}");
|
||||||
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查是否已经有足够的材料在容器中或云端
|
// 检查是否已经有足够的材料在容器中或云端
|
||||||
if (order.HasEnoughResources())
|
if (order.HasEnoughResources())
|
||||||
{
|
{
|
||||||
// Log.Message($"[WULA_DEBUG] HasJobOnThing: Order has enough resources.");
|
if (forced) Log.Message($"[WULA_DEBUG] HasJobOnThing: Order has enough resources.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,7 +85,7 @@ namespace WulaFallenEmpire
|
|||||||
// 获取所需材料清单
|
// 获取所需材料清单
|
||||||
var neededMaterials = GetNeededMaterials(order, table, globalStorage);
|
var neededMaterials = GetNeededMaterials(order, table, globalStorage);
|
||||||
|
|
||||||
// Log.Message($"[WULA_DEBUG] Needed materials for {order.Label}: {string.Join(", ", neededMaterials.Select(k => $"{k.Key.defName} x{k.Value}"))}");
|
Log.Message($"[WULA_DEBUG] Needed materials for {order.Label}: {string.Join(", ", neededMaterials.Select(k => $"{k.Key.defName} x{k.Value}"))}");
|
||||||
|
|
||||||
foreach (var kvp in neededMaterials)
|
foreach (var kvp in neededMaterials)
|
||||||
{
|
{
|
||||||
@@ -105,7 +112,7 @@ namespace WulaFallenEmpire
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log.Message($"[WULA_DEBUG] Found {currentCount}/{countNeeded} of {def.defName}");
|
Log.Message($"[WULA_DEBUG] Found {currentCount}/{countNeeded} of {def.defName}");
|
||||||
}
|
}
|
||||||
|
|
||||||
return result.Count > 0 ? result : null;
|
return result.Count > 0 ? result : null;
|
||||||
|
|||||||
Reference in New Issue
Block a user