public static bool Prefix(UIProductionStatWindow __instance, FactoryProductionStat factoryStat) { int[] itemIds = ItemProto.itemIds; int length = itemIds.Length; var displayEntries = Traverse.Create(__instance).Field("displayEntries").GetValue <List <int[]> >(); int[] productIndices = factoryStat.productIndices; for (int index1 = 0; index1 < length; ++index1) { int c1 = __instance.statTimeLevel + 1; int c2 = c1 + 7; int id = itemIds[index1]; switch (id) { case 11901: case 11902: case 11903: continue; default: int favoriteId = __instance.production.favoriteIds[id]; if (productIndices[id] > 0 && ((favoriteId & __instance.favoriteMask) != 0 || __instance.favoriteMask == 0)) { int count = displayEntries.Count; bool flag = false; for (int index2 = 0; index2 < count; ++index2) { if (displayEntries[index2][0] == id) { ProductStat productStat = factoryStat.productPool[productIndices[id]]; displayEntries[index2][1] += productStat.total[c1]; displayEntries[index2][3] += productStat.total[c2]; displayEntries[index2][4] = GetScore(displayEntries[index2][1], displayEntries[index2][3]); flag = true; } } if (!flag) { ProductStat productStat = factoryStat.productPool[productIndices[id]]; displayEntries.Add(new int[5] { id, productStat.total[c1], LDB.items.Select(id).index, productStat.total[c2], GetScore(productStat.total[c1], productStat.total[c2]) }); continue; } continue; } continue; } } return(false); }
public void ProcessPacket(StatisticUpdateDataPacket packet, NebulaConnection conn) { StatisticalSnapShot snapshot; using (StatisticsManager.IsIncomingRequest.On()) { using (BinaryUtils.Reader reader = new BinaryUtils.Reader(packet.StatisticsBinaryData)) { ref FactoryProductionStat[] productionStats = ref GameMain.statistics.production.factoryStatPool; int numOfSnapshots = reader.BinaryReader.ReadInt32(); for (int i = 0; i < numOfSnapshots; i++) { //Clear all current statistical data for (int a = 0; a < GameMain.statistics.production.factoryStatPool.Length; a++) { GameMain.statistics.production.factoryStatPool[a]?.ClearRegisters(); } //Load new snapshot snapshot = new StatisticalSnapShot(reader.BinaryReader); for (int factoryId = 0; factoryId < snapshot.ProductionChangesPerFactory.Length; factoryId++) { if (productionStats[factoryId] == null) { productionStats[factoryId] = new FactoryProductionStat(); productionStats[factoryId].Init(); } for (int changeId = 0; changeId < snapshot.ProductionChangesPerFactory[factoryId].Count; changeId++) { if (snapshot.ProductionChangesPerFactory[factoryId][changeId].IsProduction) { productionStats[factoryId].productRegister[snapshot.ProductionChangesPerFactory[factoryId][changeId].ProductId] += snapshot.ProductionChangesPerFactory[factoryId][changeId].Amount; } else { productionStats[factoryId].consumeRegister[snapshot.ProductionChangesPerFactory[factoryId][changeId].ProductId] += snapshot.ProductionChangesPerFactory[factoryId][changeId].Amount; } } //Import power system statistics productionStats[factoryId].powerGenRegister = snapshot.PowerGenerationRegister[factoryId]; productionStats[factoryId].powerConRegister = snapshot.PowerConsumptionRegister[factoryId]; productionStats[factoryId].powerChaRegister = snapshot.PowerChargingRegister[factoryId]; productionStats[factoryId].powerDisRegister = snapshot.PowerDischargingRegister[factoryId]; //Import fake energy stored values StatisticsManager.PowerEnergyStoredData = snapshot.EnergyStored; //Import Research statistics productionStats[factoryId].hashRegister = snapshot.HashRegister[factoryId]; } GameMain.statistics.production.GameTick(snapshot.CapturedGameTick); } } }
public static bool GameTick_Prefix(FactoryProductionStat __instance) { //Do not run in single player for host if (!SimulatedWorld.Initialized || LocalPlayer.IsMasterClient) { return(true); } //Multiplayer clients should not include their own calculated statistics if (!StatisticsManager.IsIncomingRequest) { __instance.ClearRegisters(); return(false); } return(true); }
public static bool GameTick_Prefix(FactoryProductionStat __instance) { //Do not run in single player for host if (!Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost) { return(true); } //Multiplayer clients should not include their own calculated statistics if (!Multiplayer.Session.Statistics.IsIncomingRequest) { __instance.ClearRegisters(); return(false); } return(true); }
public void factorySystemStatUpdate(long time, FactorySystem factorySystem) { var factory = factorySystem.factory; FactoryProductionStat factoryProductionStat = GameMain.statistics.production.factoryStatPool[factory.index]; int[] productRegister = factoryProductionStat.productRegister; for (int i = 1; i < factorySystem.minerCursor; i++) { if (factorySystem.minerPool[i].id == i) { var minerComponent = factorySystem.minerPool[i]; var networkId = factory.powerSystem.consumerPool[minerComponent.pcId].networkId; if (MinerComponent_InternalUpdate( factory, factory.veinPool, factory.powerSystem.netPool[networkId], factory.powerSystem.networkServes[networkId], GameMain.history.miningCostRate, GameMain.history.miningSpeedScale, productRegister, minerComponent)) { // Update notificationTimes used to trigger notifications if (notificationTimes.ContainsKey(minerComponent.entityId)) { notificationTimes[minerComponent.entityId].lastUpdated = time; } else { // We want to trigger almost immediately, but leave notificationWindowLow for cases where you are actively building and haven't wired up things. notificationTimes[minerComponent.entityId] = new NotificationTiming() { lastNotification = time - notificationWindowHigh + notificationWindowLow, lastUpdated = time }; } } } } }
static void Geothermal(PlanetFactory __instance) { var factory = __instance; if (frame % 3 != 0) { return; } if (factory.planet.type != EPlanetType.Vocano || factory.planet.waterItemId != -1) { return; } GameStatData statistics = GameMain.statistics; FactoryProductionStat factoryProductionStat = statistics.production.factoryStatPool[factory.factorySystem.factory.index]; int[] productRegister = factoryProductionStat.productRegister; int[] consumeRegister = factoryProductionStat.consumeRegister; for (int i = 0; i < factory.transport.stationCursor; i++) { var sc = factory.transport.stationPool[i]; if (sc != null && sc.storage != null) { int item1 = -1; int item2 = -1; int item3 = -1; int item4 = -1; int item5 = -1; for (int j = 0; j < sc.storage.Length; j++) { var st = sc.storage[j]; if (st.itemId > 0) { if (st.itemId == ice) { item1 = j; } else if (st.itemId == waterId) { item2 = j; } else if (st.itemId == cmx) { item3 = j; } else if (st.itemId == emtryB) { item4 = j; } else if (st.itemId == fullB) { item5 = j; } } } if (item1 > -1) { if (item3 > -1 && sc.storage[item1].count > 0) { if (sc.storage[item3].count < sc.storage[item3].max) { if (sc.energy < sc.energyMax - 100000) { sc.energy += 100000; } sc.storage[item1].count--; consumeRegister[item1]++; sc.storage[item3].count++; productRegister[item1]++; if (item4 > -1 && item5 > -1 && sc.storage[item4].count > 0 && sc.storage[item5].max > sc.storage[item5].count) { if (frame % 20 == 0) { sc.storage[item4].count--; consumeRegister[item4]++; productRegister[item5]++; sc.storage[item5].count++; } } } } } if (item2 > -1) { if (sc.storage[item2].count > 0 && item4 > -1 && item5 > -1 && sc.storage[item4].count > 0 && sc.storage[item5].max > sc.storage[item5].count) { if (sc.energy < sc.energyMax - 100000) { sc.energy += 100000; } sc.storage[item2].count--; consumeRegister[item2]++; if (frame % 20 == 0) { sc.storage[item4].count--; consumeRegister[item4]++; productRegister[item5]++; sc.storage[item5].count++; } } } } } }
static void Miner(FactorySystem __instance) { GameHistoryData history = GameMain.history; float miningSpeedScale = history.miningSpeedScale; if (miningSpeedScale <= 0) { return; } int baseSpeed = (int)(120 / (miningSpeedScale)); if (baseSpeed <= 0) { baseSpeed = 1; } if (frame % baseSpeed != 0) { return; } var veinPool = __instance.factory.veinPool; Dictionary <int, List <int> > veins = new Dictionary <int, List <int> >(); if (__instance.minerPool[0].seed == 0) { var rondom = new System.Random(); __instance.minerPool[0].seed = (uint)(__instance.planet.id * 100000 + rondom.Next(1, 9999)); } else { seed = __instance.minerPool[0].seed; } for (int i = 0; i < veinPool.Length; i++) { var d = veinPool[i]; if (d.amount > 0 && d.productId > 0) { AddVeinData(veins, d.productId, i); } } float miningCostRate = 0; PlanetTransport transport = null; int[] productRegister = null; miningCostRate = history.miningCostRate; transport = __instance.planet.factory.transport; FactoryProductionStat factoryProductionStat = GameMain.statistics.production.factoryStatPool[__instance.factory.index]; bool h = false; if (factoryProductionStat != null) { productRegister = factoryProductionStat.productRegister; h = true; } for (int i = 1; i < transport.stationCursor; i++) { var sc = transport.stationPool[i]; if (sc != null && sc.storage != null) { for (int j = 0; j < sc.storage.Length; j++) { var da = sc.storage[j]; if (da.localLogic == ELogisticStorage.Demand && da.max > da.count) { if (veins.ContainsKey(da.itemId) || da.itemId == __instance.planet.waterItemId) { //当能量不足一半时 if (sc.energyMax / 2 > sc.energy) { //获取倒数第二个物品栏 var lastup = sc.storage[sc.storage.Length - 2]; //如果物品数量大于0 if (lastup.count > 0) { //获取物品的能量值 long en = LDB.items.Select(lastup.itemId).HeatValue; //如果物品的能量大于0 if (en > 0) { //获取需要充电的能量 long needen = sc.energyMax - sc.energy; //计算需要的数量 int needcount = (int)(needen / en); //如果需要是数量大于有的数量 if (needcount > lastup.count) { //将需求数量改为当前数量 needcount = sc.storage[sc.storage.Length - 2].count; } //消耗物品 sc.storage[sc.storage.Length - 2].count -= needcount; //充能 sc.energy += needcount * en; } } } } if (veins.ContainsKey(da.itemId)) { if (sc.energy >= uesEnergy) { var vein = veins[da.itemId].First(); if (veinPool[vein].type == EVeinType.Oil) { float count = 0; foreach (int index in veins[da.itemId]) { if (veinPool.Length > index && veinPool[index].productId > 0) { count += veinPool[index].amount / 6000f; } } sc.storage[j].count += (int)count; if (h) { productRegister[da.itemId] += (int)count; } sc.energy -= uesEnergy; } else { int count = 0; foreach (int index in veins[da.itemId]) { if (GetMine(veinPool, index, miningCostRate, __instance.planet.factory)) { count++; } } sc.storage[j].count += count; if (h) { productRegister[da.itemId] += count; } sc.energy -= uesEnergy; } } } else if (da.itemId == __instance.planet.waterItemId) { sc.storage[j].count += waterSpeed; if (h) { productRegister[da.itemId] += waterSpeed; } sc.energy -= uesEnergy; } } } } } }
public override void ProcessPacket(StatisticUpdateDataPacket packet, NebulaConnection conn) { StatisticalSnapShot snapshot; using (Multiplayer.Session.Statistics.IsIncomingRequest.On()) { using (BinaryUtils.Reader reader = new BinaryUtils.Reader(packet.StatisticsBinaryData)) { bool itemChanged = false; ref FactoryProductionStat[] productionStats = ref GameMain.statistics.production.factoryStatPool; int numOfSnapshots = reader.BinaryReader.ReadInt32(); for (int i = 0; i < numOfSnapshots; i++) { //Load new snapshot snapshot = new StatisticalSnapShot(reader.BinaryReader); for (int factoryId = 0; factoryId < snapshot.ProductionChangesPerFactory.Length; factoryId++) { if (productionStats[factoryId] == null) { productionStats[factoryId] = new FactoryProductionStat(); productionStats[factoryId].Init(); } //Clear current statistical data productionStats[factoryId].PrepareTick(); for (int changeId = 0; changeId < snapshot.ProductionChangesPerFactory[factoryId].Count; changeId++) { StatisticalSnapShot.ProductionChangeStruct productionChange = snapshot.ProductionChangesPerFactory[factoryId][changeId]; if (productionChange.IsProduction) { productionStats[factoryId].productRegister[productionChange.ProductId] += productionChange.Amount; } else { productionStats[factoryId].consumeRegister[productionChange.ProductId] += productionChange.Amount; } } //Import power system statistics productionStats[factoryId].powerGenRegister = snapshot.PowerGenerationRegister[factoryId]; productionStats[factoryId].powerConRegister = snapshot.PowerConsumptionRegister[factoryId]; productionStats[factoryId].powerChaRegister = snapshot.PowerChargingRegister[factoryId]; productionStats[factoryId].powerDisRegister = snapshot.PowerDischargingRegister[factoryId]; //Import fake energy stored values Multiplayer.Session.Statistics.PowerEnergyStoredData = snapshot.EnergyStored; //Import Research statistics productionStats[factoryId].hashRegister = snapshot.HashRegister[factoryId]; //Processs changed registers. FactoryProductionStat.AfterTick() is empty currently so we ignore it. productionStats[factoryId].GameTick(snapshot.CapturedGameTick); itemChanged |= productionStats[factoryId].itemChanged; } } //Trigger GameMain.statistics.production.onItemChange() event when itemChanged is true if (itemChanged) { UIRoot.instance.uiGame.statWindow.OnItemChange(); NebulaModel.Logger.Log.Debug("StatisticsUpdateProcessor: itemChanged"); } } }