From f210746859e22b9b3dbb769d64048645b2338711 Mon Sep 17 00:00:00 2001 From: AlessandroCH Date: Sat, 9 Aug 2025 17:41:24 +0200 Subject: [PATCH] improvements --- Campofinale/Campofinale.csproj | 4 - .../NodeBuilding_Producer.cs | 15 +- .../NodeBuilding_ProducerFurnace.cs | 15 +- .../Components/FComponentBoxConveyor.cs | 3 +- Campofinale/Game/Factory/FComponent.cs | 3 + Campofinale/Game/Factory/FactoryChapter.cs | 65 +++-- Campofinale/Game/Factory/FactoryManager.cs | 22 +- Campofinale/Game/Factory/FactoryNode.cs | 15 +- Campofinale/Game/Inventory/Item.cs | 1 - .../Packets/Sc/PacketScFactoryHsSync.cs | 31 +++ Campofinale/Server.cs | 2 +- Dotfuscator1.xml | 229 ------------------ 12 files changed, 123 insertions(+), 282 deletions(-) create mode 100644 Campofinale/Packets/Sc/PacketScFactoryHsSync.cs delete mode 100644 Dotfuscator1.xml diff --git a/Campofinale/Campofinale.csproj b/Campofinale/Campofinale.csproj index 5cc10f4..113136d 100644 --- a/Campofinale/Campofinale.csproj +++ b/Campofinale/Campofinale.csproj @@ -21,15 +21,11 @@ - - - - diff --git a/Campofinale/Game/Factory/BuildingsBehaviour/NodeBuilding_Producer.cs b/Campofinale/Game/Factory/BuildingsBehaviour/NodeBuilding_Producer.cs index f690108..333a907 100644 --- a/Campofinale/Game/Factory/BuildingsBehaviour/NodeBuilding_Producer.cs +++ b/Campofinale/Game/Factory/BuildingsBehaviour/NodeBuilding_Producer.cs @@ -18,7 +18,7 @@ namespace Campofinale.Game.Factory.BuildingsBehaviour public uint inputCacheId = 0; public uint outputCacheId = 0; public uint producerId = 0; - public int currentProgress = 0; + public long timestampFinish = 0; public override void Init(FactoryChapter chapter, FactoryNode node) { FComponentCache cache1 = (FComponentCache)new FComponentCache(chapter.nextCompV(), FCComponentPos.CacheIn1).Init(); @@ -71,11 +71,14 @@ namespace Campofinale.Game.Factory.BuildingsBehaviour producer.inProduce = true; producer.lastFormulaId = recipe; - producer.progress += craftingRecipe.totalProgress/craftingRecipe.progressRound; - currentProgress++; - if (currentProgress >= craftingRecipe.progressRound) + if (timestampFinish == 0) { - currentProgress = 0; + timestampFinish = DateTime.UtcNow.ToUnixTimestampMilliseconds() + 1000 * craftingRecipe.progressRound; + } + producer.progress = (DateTime.UtcNow.ToUnixTimestampMilliseconds()/timestampFinish)* craftingRecipe.totalProgress; + if (DateTime.UtcNow.ToUnixTimestampMilliseconds() >= timestampFinish) + { + timestampFinish= DateTime.UtcNow.ToUnixTimestampMilliseconds()+1000* craftingRecipe.progressRound; List toConsume = craftingRecipe.GetIngredients(); inCache.ConsumeItems(toConsume); craftingRecipe.outcomes.ForEach(e => @@ -92,6 +95,7 @@ namespace Campofinale.Game.Factory.BuildingsBehaviour { producer.inProduce = false; producer.progress = 0; + timestampFinish = 0; } } else @@ -99,6 +103,7 @@ namespace Campofinale.Game.Factory.BuildingsBehaviour producer.inBlock = false; producer.inProduce = false; producer.progress = 0; + timestampFinish = 0; } } diff --git a/Campofinale/Game/Factory/BuildingsBehaviour/NodeBuilding_ProducerFurnace.cs b/Campofinale/Game/Factory/BuildingsBehaviour/NodeBuilding_ProducerFurnace.cs index b9f82c0..a9bf040 100644 --- a/Campofinale/Game/Factory/BuildingsBehaviour/NodeBuilding_ProducerFurnace.cs +++ b/Campofinale/Game/Factory/BuildingsBehaviour/NodeBuilding_ProducerFurnace.cs @@ -20,7 +20,7 @@ namespace Campofinale.Game.Factory.BuildingsBehaviour public uint inputCacheIdFluid = 0; public uint outputCacheIdFluid = 0; public uint producerId = 0; - public int currentProgress = 0; + public long timestampFinish = 0; public override void Init(FactoryChapter chapter, FactoryNode node) { FComponentCache cache1 = (FComponentCache)new FComponentCache(chapter.nextCompV(), FCComponentPos.CacheIn1).Init(); @@ -79,11 +79,14 @@ namespace Campofinale.Game.Factory.BuildingsBehaviour producer.inProduce = true; producer.lastFormulaId = recipe; - producer.progress += craftingRecipe.totalProgress/craftingRecipe.progressRound; - currentProgress++; - if (currentProgress >= craftingRecipe.progressRound) + if (timestampFinish == 0) { - currentProgress = 0; + timestampFinish = DateTime.UtcNow.ToUnixTimestampMilliseconds() + 1000 * craftingRecipe.progressRound; + } + producer.progress = (DateTime.UtcNow.ToUnixTimestampMilliseconds() / timestampFinish) * craftingRecipe.totalProgress; + if (DateTime.UtcNow.ToUnixTimestampMilliseconds() >= timestampFinish) + { + timestampFinish = DateTime.UtcNow.ToUnixTimestampMilliseconds() + 1000 * craftingRecipe.progressRound; List toConsume = craftingRecipe.GetIngredients(); inCache.ConsumeItems(toConsume); craftingRecipe.outcomes.ForEach(e => @@ -100,6 +103,7 @@ namespace Campofinale.Game.Factory.BuildingsBehaviour { producer.inProduce = false; producer.progress = 0; + timestampFinish = 0; } } else @@ -107,6 +111,7 @@ namespace Campofinale.Game.Factory.BuildingsBehaviour producer.inBlock = false; producer.inProduce = false; producer.progress = 0; + timestampFinish = 0; } } diff --git a/Campofinale/Game/Factory/Components/FComponentBoxConveyor.cs b/Campofinale/Game/Factory/Components/FComponentBoxConveyor.cs index c204911..c63d964 100644 --- a/Campofinale/Game/Factory/Components/FComponentBoxConveyor.cs +++ b/Campofinale/Game/Factory/Components/FComponentBoxConveyor.cs @@ -13,7 +13,6 @@ namespace Campofinale.Game.Factory.Components lastPopTms=DateTime.UtcNow.ToUnixTimestampMilliseconds(); } - public override void SetComponentInfo(ScdFacCom proto) { if (items == null) @@ -26,8 +25,10 @@ namespace Campofinale.Game.Factory.Components LastPopTms = lastPopTms, }; + items.ForEach(item => { + if(item!=null) proto.BoxConveyor.Items.Add(item.ToFactoryItemProto()); }); diff --git a/Campofinale/Game/Factory/FComponent.cs b/Campofinale/Game/Factory/FComponent.cs index 4f5ffca..89058d3 100644 --- a/Campofinale/Game/Factory/FComponent.cs +++ b/Campofinale/Game/Factory/FComponent.cs @@ -1,6 +1,7 @@ using Campofinale.Game.Factory.Components; using Campofinale.Resource; using MongoDB.Bson.Serialization.Attributes; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; @@ -104,5 +105,7 @@ namespace Campofinale.Game.Factory } return this; } + + } } diff --git a/Campofinale/Game/Factory/FactoryChapter.cs b/Campofinale/Game/Factory/FactoryChapter.cs index 7ce8b26..7a461d3 100644 --- a/Campofinale/Game/Factory/FactoryChapter.cs +++ b/Campofinale/Game/Factory/FactoryChapter.cs @@ -18,24 +18,59 @@ namespace Campofinale.Game.Factory public uint v = 1; public uint compV = 0; public int bandwidth = 200; + public FactoryBlackboard blackboard = new(); + public class FactoryBlackboard + { + public uint inventoryNodeId=1; + public FacBbPower power = new(); + public class FacBbPower + { + public long powerGen; + public long powerSaveMax; + public long powerSaveCurrent; + public long powerCost; + public bool isStopByPower; + } + public ScdFactorySyncBlackboard ToProto() + { + return new ScdFactorySyncBlackboard() + { + InventoryNodeId = inventoryNodeId, + Power = new() + { + IsStopByPower=power.isStopByPower, + PowerCost=power.powerCost, + PowerGen=power.powerGen, + PowerSaveCurrent=power.powerSaveCurrent, + PowerSaveMax=power.powerSaveMax, + } + }; + } + + public ScdFactoryHsBb ToProtoHsBb() + { + return new ScdFactoryHsBb() + { + Power = new() + { + IsStopByPower = power.isStopByPower, + PowerSaveCurrent = power.powerSaveCurrent, + PowerSaveMax = power.powerSaveMax, + + }, + + }; + } + } public ScFactorySyncChapter ToProto() { + blackboard = new(); ScFactorySyncChapter chapter = new() { ChapterId = chapterId, Tms = DateTime.UtcNow.ToUnixTimestampMilliseconds(), - Blackboard = new() - { - Power = new() - { - PowerGen = 0, - PowerSaveMax = 0, - PowerSaveCurrent = 0, - PowerCost = 0 - }, - InventoryNodeId = 1 - }, + Blackboard = new(), Statistic = new() { LastDay = new() @@ -57,15 +92,15 @@ namespace Campofinale.Game.Factory }, }; - chapter.Blackboard.Power.PowerSaveCurrent = bandwidth; + blackboard.power.powerSaveCurrent = bandwidth; domainDataTable[chapterId].levelGroup.ForEach(levelGroup => { int grade = GetOwner().sceneManager.GetScene(GetSceneNumIdFromLevelData(levelGroup)).grade; LevelGradeInfo sceneGrade = ResourceManager.levelGradeTable[levelGroup].grades.Find(g => g.grade == grade); if (sceneGrade != null) { - chapter.Blackboard.Power.PowerGen += sceneGrade.bandwidth; - chapter.Blackboard.Power.PowerSaveMax += sceneGrade.bandwidth; + blackboard.power.powerGen += sceneGrade.bandwidth; + blackboard.power.powerSaveMax += sceneGrade.bandwidth; var scene = new ScdFactorySyncScene() { @@ -141,7 +176,7 @@ namespace Campofinale.Game.Factory { } - + chapter.Blackboard = blackboard.ToProto(); chapter.Maps.AddRange(GetMaps()); return chapter; } diff --git a/Campofinale/Game/Factory/FactoryManager.cs b/Campofinale/Game/Factory/FactoryManager.cs index 5d6eb69..dbaa245 100644 --- a/Campofinale/Game/Factory/FactoryManager.cs +++ b/Campofinale/Game/Factory/FactoryManager.cs @@ -73,33 +73,19 @@ namespace Campofinale.Game.Factory { if (!player.Initialized) return; if (player.GetCurrentChapter() == "") return; - long curtimestamp = DateTime.UtcNow.ToUnixTimestampMilliseconds(); - - ScFactoryHsSync hs = new() - { - Tms = curtimestamp, - CcList = - { - }, - Blackboard = GetChapter(player.GetCurrentChapter()).ToProto().Blackboard, - ChapterId = player.GetCurrentChapter(), - }; + List nodeUpdateList = new(); foreach (var node in GetChapter(player.GetCurrentChapter()).nodes) { if (node != null) { - if (node.position.DistanceXZ(player.position) < 150) + if (node.position.DistanceXZ(player.position) < 150 && node.nodeType != FCNodeType.BoxConveyor) { - node.components.ForEach(c => - { - hs.CcList.Add(c.ToProto()); - }); + nodeUpdateList.Add(node); } - } } - player.Send(ScMsgId.ScFactoryHsSync, hs); + player.Send(new PacketScFactoryHsSync(player,GetChapter(player.GetCurrentChapter()), nodeUpdateList)); } public void Update() { diff --git a/Campofinale/Game/Factory/FactoryNode.cs b/Campofinale/Game/Factory/FactoryNode.cs index 0b9c58e..d469806 100644 --- a/Campofinale/Game/Factory/FactoryNode.cs +++ b/Campofinale/Game/Factory/FactoryNode.cs @@ -11,6 +11,7 @@ using static Campofinale.Resource.ResourceManager.FactoryBuildingTable; using Newtonsoft.Json; using System.Drawing; using Campofinale.Game.Inventory; +using System.Numerics; namespace Campofinale.Game.Factory { @@ -135,7 +136,7 @@ namespace Campofinale.Game.Factory count = 1 }; - if (conveyorNode.AddConveyorItem(add)) + if (conveyorNode.AddConveyorItem(chapter,add)) { did = true; outputCache.ConsumeItems(new List() { add }); @@ -199,7 +200,7 @@ namespace Campofinale.Game.Factory } } if(toRemove!=null) - input.items.Remove(toRemove); + conveyorNode.RemoveConveyorItem(chapter,toRemove); } } @@ -208,7 +209,14 @@ namespace Campofinale.Game.Factory } - private bool AddConveyorItem(ItemCount i) + private void RemoveConveyorItem(FactoryChapter chapter,ItemCount toRemove) + { + FComponentBoxConveyor conveyorComp = GetComponent(); + conveyorComp.items.Remove(toRemove); + chapter.GetOwner().Send(new PacketScFactoryHsSync(chapter.GetOwner(), chapter, new List() { this})); + } + + private bool AddConveyorItem(FactoryChapter chapter,ItemCount i) { float length=BlockCalculator.CalculateTotalBlocks(points); FComponentBoxConveyor conveyorComp = GetComponent(); @@ -222,6 +230,7 @@ namespace Campofinale.Game.Factory conveyorComp.items.Add(i); i.tms = DateTime.UtcNow.ToUnixTimestampMilliseconds(); conveyorComp.lastPopTms = i.tms; + chapter.GetOwner().Send(new PacketScFactoryHsSync(chapter.GetOwner(), chapter, new List() { this })); return true; } else diff --git a/Campofinale/Game/Inventory/Item.cs b/Campofinale/Game/Inventory/Item.cs index a35230a..a219079 100644 --- a/Campofinale/Game/Inventory/Item.cs +++ b/Campofinale/Game/Inventory/Item.cs @@ -11,7 +11,6 @@ using static Campofinale.Resource.ResourceManager; using Google.Protobuf.Collections; using Campofinale.Packets.Sc; using Campofinale.Protocol; -using CsvHelper.Configuration.Attributes; namespace Campofinale.Game.Inventory { diff --git a/Campofinale/Packets/Sc/PacketScFactoryHsSync.cs b/Campofinale/Packets/Sc/PacketScFactoryHsSync.cs new file mode 100644 index 0000000..3d4286d --- /dev/null +++ b/Campofinale/Packets/Sc/PacketScFactoryHsSync.cs @@ -0,0 +1,31 @@ +using Campofinale.Game.Factory; +using Campofinale.Network; +using Campofinale.Protocol; +using System.Numerics; + +namespace Campofinale.Packets.Sc +{ + public class PacketScFactoryHsSync : Packet + { + + public PacketScFactoryHsSync(Player client, FactoryChapter chapter, List nodes) { + + long curtimestamp = DateTime.UtcNow.ToUnixTimestampMilliseconds(); + ScFactoryHsSync hs = new() + { + Tms = curtimestamp, + Blackboard = chapter.blackboard.ToProto(), + ChapterId = chapter.chapterId, + }; + nodes.ForEach(node => + { + node.components.ForEach(c => + { + hs.CcList.Add(c.ToProto()); + }); + }); + SetData(ScMsgId.ScFactoryHsSync, hs); + } + + } +} diff --git a/Campofinale/Server.cs b/Campofinale/Server.cs index 06b5c39..b5ea2ba 100644 --- a/Campofinale/Server.cs +++ b/Campofinale/Server.cs @@ -152,7 +152,7 @@ namespace Campofinale try { clients.ForEach(client => { if (client != null) client.Update(); }); - Thread.Sleep(1000); + Thread.Sleep(250); } catch (Exception ex) { diff --git a/Dotfuscator1.xml b/Dotfuscator1.xml deleted file mode 100644 index 44bfed3..0000000 --- a/Dotfuscator1.xml +++ /dev/null @@ -1,229 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file