mirror of
https://git.muiegratis.online/suikoakari/Campofinale
synced 2025-12-12 17:44:37 +01:00
working conveyors and implemented furnace build
This commit is contained in:
@@ -9,7 +9,7 @@ namespace Campofinale.Game.Factory
|
||||
{
|
||||
public class BlockCalculator
|
||||
{
|
||||
public static int CalculateTotalBlocks(List<Vector3f> points)
|
||||
public static float CalculateTotalBlocks(List<Vector3f> points)
|
||||
{
|
||||
if (points == null || points.Count < 2)
|
||||
return 0;
|
||||
|
||||
@@ -9,6 +9,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Campofinale.Resource;
|
||||
using static Campofinale.Resource.ResourceManager;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Campofinale.Game.Factory.BuildingsBehaviour
|
||||
{
|
||||
@@ -30,9 +31,21 @@ namespace Campofinale.Game.Factory.BuildingsBehaviour
|
||||
inputCacheId = cache1.compId;
|
||||
outputCacheId = cache2.compId;
|
||||
producerId = producer.compId;
|
||||
node.components.Add(new FComponentPortManager(chapter.nextCompV(), 3,cache1).Init());
|
||||
node.components.Add(new FComponentPortManager(chapter.nextCompV(), 3, cache1).Init());
|
||||
node.components.Add(new FComponentPortManager(chapter.nextCompV(), 3, cache2).Init());
|
||||
}
|
||||
public string GetFormulaGroupId(string templateId)
|
||||
{
|
||||
FactoryMachineCraftTable table = factoryMachineCraftTable.Values.ToList().Find(r => r.machineId == templateId);
|
||||
if (table != null)
|
||||
{
|
||||
return table.formulaGroupId;
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
public override void Update(FactoryChapter chapter, FactoryNode node)
|
||||
{
|
||||
|
||||
@@ -41,8 +54,12 @@ namespace Campofinale.Game.Factory.BuildingsBehaviour
|
||||
FComponentProducer producer = node.GetComponent<FComponentProducer>(producerId);
|
||||
FComponentCache inCache = node.GetComponent<FComponentCache>(inputCacheId);
|
||||
FComponentCache outCache = node.GetComponent<FComponentCache>(outputCacheId);
|
||||
FComponentFormulaMan formulaManager = node.GetComponent<FComponentFormulaMan>();
|
||||
|
||||
if (formulaManager == null) return;
|
||||
formulaManager.currentGroup = GetFormulaGroupId(node.templateId);
|
||||
FactoryMachineCraftTable craftingRecipe = null;
|
||||
string recipe = ResourceManager.FindFactoryMachineCraftIdUsingCacheItems(inCache.items);
|
||||
string recipe = ResourceManager.FindFactoryMachineCraftIdUsingCacheItems(inCache.items,formulaManager.currentGroup);
|
||||
producer.formulaId = recipe;
|
||||
ResourceManager.factoryMachineCraftTable.TryGetValue(producer.formulaId, out craftingRecipe);
|
||||
|
||||
@@ -73,7 +90,6 @@ namespace Campofinale.Game.Factory.BuildingsBehaviour
|
||||
}
|
||||
else
|
||||
{
|
||||
producer.inBlock = false;
|
||||
producer.inProduce = false;
|
||||
producer.progress = 0;
|
||||
}
|
||||
@@ -85,18 +101,7 @@ namespace Campofinale.Game.Factory.BuildingsBehaviour
|
||||
producer.progress = 0;
|
||||
}
|
||||
}
|
||||
/* ScFactoryModifyChapterComponents update = new()
|
||||
{
|
||||
ChapterId = chapter.chapterId,
|
||||
Tms = DateTime.UtcNow.ToUnixTimestampMilliseconds()/1000,
|
||||
|
||||
};
|
||||
|
||||
foreach (var comp in node.components)
|
||||
{
|
||||
update.Components.Add(comp.ToProto());
|
||||
}
|
||||
chapter.GetOwner().Send(ScMsgId.ScFactoryModifyChapterComponents, update);*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
using Campofinale.Game.Factory.Components;
|
||||
using Campofinale.Protocol;
|
||||
using Campofinale.Resource;
|
||||
using Campofinale.Resource.Table;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Campofinale.Resource;
|
||||
using static Campofinale.Resource.ResourceManager;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Campofinale.Game.Factory.BuildingsBehaviour
|
||||
{
|
||||
public class NodeBuilding_ProducerFurnace : NodeBuildingBehaviour
|
||||
{
|
||||
public uint inputCacheId = 0;
|
||||
public uint outputCacheId = 0;
|
||||
public uint inputCacheIdFluid = 0;
|
||||
public uint outputCacheIdFluid = 0;
|
||||
public uint producerId = 0;
|
||||
public int currentProgress = 0;
|
||||
public override void Init(FactoryChapter chapter, FactoryNode node)
|
||||
{
|
||||
FComponentCache cache1 = (FComponentCache)new FComponentCache(chapter.nextCompV(), FCComponentPos.CacheIn1).Init();
|
||||
FComponentCache cache2 = (FComponentCache)new FComponentCache(chapter.nextCompV(), FCComponentPos.CacheOut1).Init();
|
||||
FComponentCache cache3 = (FComponentCache)new FComponentCache(chapter.nextCompV(), FCComponentPos.CacheFluidIn1).Init();
|
||||
FComponentCache cache4 = (FComponentCache)new FComponentCache(chapter.nextCompV(), FCComponentPos.CacheFluidOut1).Init();
|
||||
FComponentProducer producer = (FComponentProducer)new FComponentProducer(chapter.nextCompV()).Init();
|
||||
node.components.Add(producer);
|
||||
node.components.Add(new FComponentFormulaMan(chapter.nextCompV()).Init());
|
||||
node.components.Add(cache1);
|
||||
node.components.Add(cache2);
|
||||
node.components.Add(cache3);
|
||||
node.components.Add(cache4);
|
||||
inputCacheId = cache1.compId;
|
||||
outputCacheId = cache2.compId;
|
||||
inputCacheIdFluid = cache3.compId;
|
||||
outputCacheIdFluid = cache4.compId;
|
||||
producerId = producer.compId;
|
||||
node.components.Add(new FComponentPortManager(chapter.nextCompV(), 4, cache1).Init());
|
||||
node.components.Add(new FComponentPortManager(chapter.nextCompV(), 4, cache2).Init());
|
||||
}
|
||||
public string GetFormulaGroupId(string templateId)
|
||||
{
|
||||
FactoryMachineCraftTable table = factoryMachineCraftTable.Values.ToList().Find(r => r.machineId == templateId);
|
||||
if (table != null)
|
||||
{
|
||||
return table.formulaGroupId;
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
public override void Update(FactoryChapter chapter, FactoryNode node)
|
||||
{
|
||||
|
||||
if (node.powered)
|
||||
{
|
||||
FComponentProducer producer = node.GetComponent<FComponentProducer>(producerId);
|
||||
FComponentCache inCache = node.GetComponent<FComponentCache>(inputCacheId);
|
||||
FComponentCache outCache = node.GetComponent<FComponentCache>(outputCacheId);
|
||||
FComponentFormulaMan formulaManager = node.GetComponent<FComponentFormulaMan>();
|
||||
|
||||
if (formulaManager == null) return;
|
||||
formulaManager.currentGroup = GetFormulaGroupId(node.templateId);
|
||||
FactoryMachineCraftTable craftingRecipe = null;
|
||||
string recipe = ResourceManager.FindFactoryMachineCraftIdUsingCacheItems(inCache.items,formulaManager.currentGroup);
|
||||
producer.formulaId = recipe;
|
||||
ResourceManager.factoryMachineCraftTable.TryGetValue(producer.formulaId, out craftingRecipe);
|
||||
|
||||
if (craftingRecipe != null)
|
||||
{
|
||||
producer.inBlock = outCache.IsFull();
|
||||
if (craftingRecipe.CacheHaveItems(inCache) && !outCache.IsFull())
|
||||
{
|
||||
producer.inProduce = true;
|
||||
|
||||
producer.lastFormulaId = recipe;
|
||||
producer.progress += craftingRecipe.totalProgress/craftingRecipe.progressRound;
|
||||
currentProgress++;
|
||||
if (currentProgress >= craftingRecipe.progressRound)
|
||||
{
|
||||
currentProgress = 0;
|
||||
List<ItemCount> toConsume = craftingRecipe.GetIngredients();
|
||||
inCache.ConsumeItems(toConsume);
|
||||
craftingRecipe.outcomes.ForEach(e =>
|
||||
{
|
||||
e.group.ForEach(i =>
|
||||
{
|
||||
outCache.AddItem(i.id, i.count);
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
producer.inProduce = false;
|
||||
producer.progress = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
producer.inBlock = false;
|
||||
producer.inProduce = false;
|
||||
producer.progress = 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,14 +10,17 @@ namespace Campofinale.Game.Factory.Components
|
||||
public List<ItemCount> items = new();
|
||||
public FComponentBoxConveyor(uint id) : base(id, FCComponentType.BoxConveyor,FCComponentPos.BoxConveyor)
|
||||
{
|
||||
lastPopTms=DateTime.UtcNow.ToUnixTimestampMilliseconds();
|
||||
}
|
||||
|
||||
|
||||
public override void SetComponentInfo(ScdFacCom proto)
|
||||
{
|
||||
if (items == null)
|
||||
{
|
||||
items = new List<ItemCount>();
|
||||
}
|
||||
|
||||
proto.BoxConveyor = new()
|
||||
{
|
||||
LastPopTms = lastPopTms,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Campofinale.Resource;
|
||||
using static Campofinale.Game.Factory.FactoryNode;
|
||||
|
||||
|
||||
namespace Campofinale.Game.Factory.Components
|
||||
{
|
||||
@@ -7,28 +7,24 @@ namespace Campofinale.Game.Factory.Components
|
||||
{
|
||||
public string currentGroup = "group_grinder_normal";
|
||||
public string currentMode = "normal";
|
||||
public List<string> formulaIds = new();
|
||||
public FComponentFormulaMan(uint id) : base(id, FCComponentType.FormulaMan)
|
||||
{
|
||||
}
|
||||
|
||||
public List<string> GetFormulaIds()
|
||||
{
|
||||
List<string> ids = ResourceManager.factoryMachineCraftTable.Where(i => i.Value.formulaGroupId == currentGroup).Select(i => i.Value.id).ToList();
|
||||
return ids;
|
||||
}
|
||||
public override void SetComponentInfo(ScdFacCom proto)
|
||||
{
|
||||
formulaIds = GetFormulaIds();
|
||||
proto.FormulaMan = new()
|
||||
{
|
||||
CurrentGroup = currentGroup,
|
||||
CurrentMode = currentMode,
|
||||
FormulaIds = {
|
||||
"grinder_iron_powder_1",
|
||||
"grinder_quartz_powder_1",
|
||||
"grinder_originium_powder_1",
|
||||
"grinder_carbon_powder_1",
|
||||
"grinder_crystal_powder_1",
|
||||
"grinder_plant_moss_powder_1_1",
|
||||
"grinder_plant_moss_powder_2_1",
|
||||
"grinder_plant_moss_powder_3_1",
|
||||
"grinder_plant_bbflower_powder_1_1",
|
||||
"grinder_plant_grass_powder_1_1",
|
||||
"grinder_plant_grass_powder_2_1"
|
||||
formulaIds
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ using Campofinale.Game.Factory.BuildingsBehaviour;
|
||||
using static Campofinale.Resource.ResourceManager.FactoryBuildingTable;
|
||||
using Newtonsoft.Json;
|
||||
using System.Drawing;
|
||||
using Campofinale.Game.Inventory;
|
||||
|
||||
namespace Campofinale.Game.Factory
|
||||
{
|
||||
@@ -55,15 +56,28 @@ namespace Campofinale.Game.Factory
|
||||
lastPowered = powered;
|
||||
chapter.GetOwner().Send(new PacketScFactoryModifyChapterNodes(chapter.GetOwner(), chapter.chapterId, this));
|
||||
}
|
||||
if (nodeBehaviour != null)
|
||||
if (nodeBehaviour != null && !deactive)
|
||||
{
|
||||
nodeBehaviour.Update(chapter,this);
|
||||
}
|
||||
foreach(var comp in components.FindAll(c=> c is FComponentPortManager))
|
||||
foreach (var comp in components.FindAll(c => c is FComponentPortManager))
|
||||
{
|
||||
UpdatePortManager(chapter, (FComponentPortManager)comp);
|
||||
var portmanager = (FComponentPortManager)comp;
|
||||
if (portmanager.customPos != FCComponentPos.PortOutManager)
|
||||
{
|
||||
UpdatePortManager(chapter, portmanager);
|
||||
}
|
||||
}
|
||||
foreach (var comp in components.FindAll(c => c is FComponentPortManager))
|
||||
{
|
||||
var portmanager = (FComponentPortManager)comp;
|
||||
if (portmanager.customPos == FCComponentPos.PortOutManager)
|
||||
{
|
||||
UpdatePortManager(chapter, portmanager);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public void UpdatePortManager(FactoryChapter chapter,FComponentPortManager manager)
|
||||
{
|
||||
if (ResourceManager.factoryBuildingTable.TryGetValue(templateId, out FactoryBuildingTable table))
|
||||
@@ -99,7 +113,7 @@ namespace Campofinale.Game.Factory
|
||||
FComponentBoxConveyor output = chapter.GetCompById<FComponentBoxConveyor>(port.touchComId);
|
||||
FComponentCache outputCache = chapter.GetCompById<FComponentCache>(port.ownerComId);
|
||||
FactoryNode conveyorNode = chapter.GetNodeByCompId(port.touchComId);
|
||||
if(outputCache!=null && output != null && conveyorNode != null)
|
||||
if (outputCache != null && output != null && conveyorNode != null)
|
||||
{
|
||||
bool did = false;
|
||||
outputCache.items.ForEach(i =>
|
||||
@@ -109,12 +123,10 @@ namespace Campofinale.Game.Factory
|
||||
ItemCount add = new ItemCount()
|
||||
{
|
||||
id = i.id,
|
||||
count = 1,
|
||||
|
||||
count = 1
|
||||
};
|
||||
|
||||
|
||||
if (conveyorNode.AddConveyorItem(i))
|
||||
if (conveyorNode.AddConveyorItem(add))
|
||||
{
|
||||
did = true;
|
||||
outputCache.ConsumeItems(new List<ItemCount>() { add });
|
||||
@@ -151,25 +163,66 @@ namespace Campofinale.Game.Factory
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Input items
|
||||
foreach (var port in manager.ports)
|
||||
{
|
||||
FComponentBoxConveyor input = chapter.GetCompById<FComponentBoxConveyor>(port.touchComId);
|
||||
FComponentCache inputCache = chapter.GetCompById<FComponentCache>(port.ownerComId);
|
||||
FactoryNode conveyorNode = chapter.GetNodeByCompId(port.touchComId);
|
||||
if (inputCache != null && input != null && conveyorNode != null)
|
||||
{
|
||||
bool did = false;
|
||||
ItemCount toRemove = null;
|
||||
foreach (var item in input.items)
|
||||
{
|
||||
if (!did && item.count > 0 && item.IsItemAtConveyorEnd(BlockCalculator.CalculateTotalBlocks(conveyorNode.points)))
|
||||
{
|
||||
|
||||
if (!inputCache.IsFull())
|
||||
{
|
||||
did = true;
|
||||
toRemove = item;
|
||||
inputCache.AddItem(item.id, item.count);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if(toRemove!=null)
|
||||
input.items.Remove(toRemove);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private bool AddConveyorItem(ItemCount i)
|
||||
{
|
||||
int length=BlockCalculator.CalculateTotalBlocks(points);
|
||||
float length=BlockCalculator.CalculateTotalBlocks(points);
|
||||
FComponentBoxConveyor conveyorComp = GetComponent<FComponentBoxConveyor>();
|
||||
if (conveyorComp != null)
|
||||
{
|
||||
if(conveyorComp.items.Count < length)
|
||||
if(conveyorComp.items.Count < (int)length)
|
||||
{
|
||||
long timestamp = i.tms - conveyorComp.lastPopTms;
|
||||
if(timestamp >= 2000)
|
||||
{
|
||||
conveyorComp.items.Add(i);
|
||||
int size = BlockCalculator.CalculateTotalBlocks(points) - 1;
|
||||
i.tms = DateTime.UtcNow.ToUnixTimestampMilliseconds();
|
||||
conveyorComp.lastPopTms = i.tms;
|
||||
Logger.Print("Spawning item in conveyor: " + conveyorComp.lastPopTms);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -413,7 +466,14 @@ namespace Campofinale.Game.Factory
|
||||
components.Add(new FComponentBattle(chapter.nextCompV()).Init());
|
||||
break;
|
||||
case FCNodeType.Producer:
|
||||
nodeBehaviour=new NodeBuilding_Producer();
|
||||
if (templateId == "grinder_1")
|
||||
{
|
||||
nodeBehaviour = new NodeBuilding_Producer();
|
||||
}else if (templateId == "furnance_1")
|
||||
{
|
||||
nodeBehaviour = new NodeBuilding_ProducerFurnace();
|
||||
}
|
||||
if(nodeBehaviour!=null)
|
||||
nodeBehaviour.Init(chapter, this);
|
||||
break;
|
||||
case FCNodeType.BoxConveyor:
|
||||
|
||||
@@ -89,7 +89,8 @@ namespace Campofinale.Packets.Cs
|
||||
IsFirstLogin = false,
|
||||
IsReconnect=false,
|
||||
LastRecvUpSeqid = packet.csHead.UpSeqid,
|
||||
|
||||
ServerTimeZone=2,
|
||||
ServerTime=DateTime.UtcNow.ToUnixTimestampMilliseconds(),
|
||||
};
|
||||
byte[] encKey = GenerateRandomBytes(32);
|
||||
string serverPublicKeyPem = req.ClientPublicKey.ToStringUtf8();
|
||||
|
||||
@@ -341,12 +341,12 @@ namespace Campofinale.Resource
|
||||
return strIdNumTable.item_id.dic[item_id];
|
||||
}
|
||||
|
||||
public static string FindFactoryMachineCraftIdUsingCacheItems(List<ItemCount> items)
|
||||
public static string FindFactoryMachineCraftIdUsingCacheItems(List<ItemCount> items, string group)
|
||||
{
|
||||
// Estrae solo gli ID degli items in input e li ordina
|
||||
var inputItemIds = items.Select(item => item.id).OrderBy(id => id).ToList();
|
||||
|
||||
foreach (var recipe in factoryMachineCraftTable.Values.ToList())
|
||||
foreach (var recipe in factoryMachineCraftTable.Values.ToList().FindAll(r=>r.formulaGroupId==group))
|
||||
{
|
||||
// Raccoglie tutti gli ID degli ingredienti della ricetta
|
||||
var recipeItemIds = new List<string>();
|
||||
@@ -386,8 +386,16 @@ namespace Campofinale.Resource
|
||||
{
|
||||
Count = count,
|
||||
Id = id,
|
||||
Tms = tms
|
||||
};
|
||||
}
|
||||
public bool IsItemAtConveyorEnd(float conveyorSize)
|
||||
{
|
||||
long spawnTms = tms;
|
||||
long endTms = spawnTms + (long)(2000 * conveyorSize);
|
||||
long cur = DateTime.UtcNow.ToUnixTimestampMilliseconds();
|
||||
return cur > endTms;
|
||||
}
|
||||
}
|
||||
public class FactoryBuildingTable
|
||||
{
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace Campofinale.Resource.Table
|
||||
public int progressRound;
|
||||
public long totalProgress;
|
||||
public int signal;
|
||||
public string formulaGroupId;
|
||||
public List<FactoryMachineCraftIngredient> ingredients = new();
|
||||
public List<FactoryMachineCraftIngredient> outcomes = new();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user