Skip to content

Commit

Permalink
代码提交
Browse files Browse the repository at this point in the history
  • Loading branch information
FYJ95 committed Feb 8, 2021
1 parent be20714 commit cbcc1a8
Show file tree
Hide file tree
Showing 4 changed files with 626 additions and 4 deletions.
4 changes: 0 additions & 4 deletions .gitignore

This file was deleted.

136 changes: 136 additions & 0 deletions AssemblerVerticalConstruction/AssemblerComponentEx.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using BepInEx;

namespace AssemblerVerticalConstruction
{
public class AssemblerComponentEx
{

public int[][] assemblerNextIds = new int[64*6][];
public int assemblerCapacity = 64*6;
public void SetAssemblerCapacity(int newCapacity){
var array = this.assemblerNextIds;
this.assemblerNextIds = new int[newCapacity][];
if (array != null)
{
Array.Copy(array, this.assemblerNextIds, (newCapacity <= this.assemblerCapacity) ? newCapacity : assemblerCapacity);
}
this.assemblerCapacity = newCapacity;
}

public int GetNextId(int index, int assemblerId){

if(index >= assemblerNextIds.Length)
{
return 0;
}
if (this.assemblerNextIds[index] == null || assemblerId >= this.assemblerNextIds[index].Length)
{
return 0;
}
return this.assemblerNextIds[index][assemblerId];
}

public void SetAssemblerInsertTarget(PlanetFactory __instance, int assemblerId, int nextEntityId)
{

//MyLogSource.LogInfo(assemblerId+ " "+nextEntityId);
var index = __instance.factorySystem.factory.index;
if (index >= assemblerNextIds.Length)
{
this.SetAssemblerCapacity(this.assemblerCapacity * 2);
}

if (assemblerId != 0 && __instance.factorySystem.assemblerPool[assemblerId].id == assemblerId)
{
if (nextEntityId == 0)
{
this.assemblerNextIds[index][assemblerId] = 0;
}
else
{
this.assemblerNextIds[index][assemblerId] = __instance.entityPool[nextEntityId].assemblerId;
var nextAssemblerId = __instance.entityPool[nextEntityId].assemblerId;
if (nextAssemblerId != 0 && __instance.factorySystem.assemblerPool[assemblerId].recipeId != __instance.factorySystem.assemblerPool[nextAssemblerId].recipeId)
{
__instance.factorySystem.assemblerPool[nextAssemblerId].SetRecipe(__instance.factorySystem.assemblerPool[assemblerId].recipeId, __instance.factorySystem.factory.entitySignPool);
}
}
}
}

public void SetAssemblerNextId(int index, int assemblerId, int nextId)
{
if (index >= assemblerNextIds.Length)
{
this.SetAssemblerCapacity(this.assemblerCapacity * 2);
}

if (assemblerNextIds[index] == null || assemblerId >= assemblerNextIds[index].Length)
{
var array = this.assemblerNextIds[index];

var newCapacity = assemblerId * 2;
newCapacity = newCapacity > 256 ? newCapacity : 256;
this.assemblerNextIds[index] = new int[newCapacity];
if (array != null)
{
var len = array.Length;
Array.Copy(array, this.assemblerNextIds[index], (newCapacity <= len) ? newCapacity : len);
}
}
this.assemblerNextIds[index][assemblerId] = nextId;
}
public void UpdateOutputToNext(int planeIndex, int assemblerId, AssemblerComponent[] assemblerPool)
{
if(planeIndex >= assemblerNextIds.Length || assemblerNextIds[planeIndex] == null || assemblerId >= assemblerNextIds[planeIndex].Length || assemblerId >= assemblerPool.Length)
{
return;
}
var assemblerNextId = assemblerNextIds[planeIndex][assemblerId];
if (assemblerNextId >= assemblerPool.Length)
{
return;
}
var _this = assemblerPool[assemblerId];
if (assemblerPool[assemblerNextId].id == 0 || assemblerPool[assemblerNextId].id != assemblerNextId)
{
Assert.CannotBeReached();
this.assemblerNextIds[planeIndex][assemblerId] = 0;
}
if (assemblerPool[assemblerNextId].needs != null && _this.recipeId == assemblerPool[assemblerNextId].recipeId)
{
if (_this.served != null && assemblerPool[assemblerNextId].served != null)
{
int num = _this.served.Length;
for (int i = 0; i < num; i++)
{
if (_this.needs[i] == 0 && assemblerPool[assemblerNextId].needs[i] == _this.requires[i] && _this.served[i] >= _this.requireCounts[i] * 5)
{
_this.served[i]--;
assemblerPool[assemblerNextId].served[i]++;
}
}
}
if (_this.produced != null && assemblerPool[assemblerNextId].produced != null)
{
for (int l = 0; l < _this.productCounts.Length; l++)
{
var maxCount = _this.productCounts[l] * 9;
if (_this.produced[l] < maxCount && assemblerPool[assemblerNextId].produced[l] > 0 )
{
_this.produced[l]++;
assemblerPool[assemblerNextId].produced[l]--;
}
}
}
}
}

}
}
Loading

0 comments on commit cbcc1a8

Please sign in to comment.