Project Zomboid

Project Zomboid

[BROKEN] Improved Generator Longevity
kERHUS 4 Feb, 2023 @ 11:30am
I think i knew what broken
It's IsoGenerator.class
< >
Showing 1-5 of 5 comments
kERHUS 4 Feb, 2023 @ 11:33am 
part 1
package zombie.iso.objects; import java.io.IOException; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.HashMap; import zombie.GameTime; import zombie.SandboxOptions; import zombie.WorldSoundManager; import zombie.core.Rand; import zombie.core.Translator; import zombie.core.logger.ExceptionLogger; import zombie.core.network.ByteBufferWriter; import zombie.core.properties.PropertyContainer; import zombie.core.raknet.UdpConnection; import zombie.inventory.InventoryItem; import zombie.inventory.ItemContainer; import zombie.inventory.types.Food; import zombie.iso.IsoCell; import zombie.iso.IsoChunk; import zombie.iso.IsoGridSquare; import zombie.iso.IsoObject; import zombie.iso.IsoUtils; import zombie.iso.IsoWorld; import zombie.iso.SpriteDetails.IsoFlagType; import zombie.iso.objects.IsoClothingDryer; import zombie.iso.objects.IsoClothingWasher; import zombie.iso.objects.IsoCombinationWasherDryer; import zombie.iso.objects.IsoFireManager; import zombie.iso.objects.IsoLightSwitch; import zombie.iso.objects.IsoRadio; import zombie.iso.objects.IsoStackedWasherDryer; import zombie.iso.objects.IsoStove; import zombie.iso.objects.IsoTelevision; import zombie.iso.objects.IsoWorldInventoryObject; import zombie.iso.sprite.IsoSpriteManager; import zombie.network.GameClient; import zombie.network.GameServer; import zombie.network.PacketTypes; import zombie.network.ServerMap; public class IsoGenerator extends IsoObject { public float fuel = 0.0f; public boolean activated = false; public int condition = 0; private int lastHour = -1; public boolean connected = false; private int numberOfElectricalItems = 0; private boolean updateSurrounding = false; private final HashMap<String, String> itemsPowered = new HashMap(); private float totalPowerUsing = 0.0f; private static final ArrayList<IsoGenerator> AllGenerators = new ArrayList(); private static final int GENERATOR_RADIUS = 20; public IsoGenerator(IsoCell isoCell) { super(isoCell); } public IsoGenerator(InventoryItem inventoryItem, IsoCell isoCell, IsoGridSquare isoGridSquare) { super(isoCell, isoGridSquare, IsoSpriteManager.instance.getSprite("appliances_misc_01_0")); if (inventoryItem != null) { this.setInfoFromItem(inventoryItem); } this.sprite = IsoSpriteManager.instance.getSprite("appliances_misc_01_0"); this.square = isoGridSquare; isoGridSquare.AddSpecialObject(this); if (GameClient.bClient) { this.transmitCompleteItemToServer(); } } public IsoGenerator(InventoryItem inventoryItem, IsoCell isoCell, IsoGridSquare isoGridSquare, boolean bl) { super(isoCell, isoGridSquare, IsoSpriteManager.instance.getSprite("appliances_misc_01_0")); if (inventoryItem != null) { this.setInfoFromItem(inventoryItem); } this.sprite = IsoSpriteManager.instance.getSprite("appliances_misc_01_0"); this.square = isoGridSquare; isoGridSquare.AddSpecialObject(this); if (GameClient.bClient && !bl) { this.transmitCompleteItemToServer(); } } public void setInfoFromItem(InventoryItem inventoryItem) { this.condition = inventoryItem.getCondition(); if (inventoryItem.getModData().rawget("fuel") instanceof Double) { this.fuel = ((Double)inventoryItem.getModData().rawget("fuel")).floatValue(); } }
kERHUS 4 Feb, 2023 @ 11:34am 
part 2 (what need to us):
public void update() { if (this.updateSurrounding && this.getSquare() != null) { this.setSurroundingElectricity(); this.updateSurrounding = false; } if (this.isActivated()) { if (!(GameServer.bServer || this.emitter != null && this.emitter.isPlaying("GeneratorLoop"))) { if (this.emitter == null) { this.emitter = IsoWorld.instance.getFreeEmitter(this.getX() + 0.5f, this.getY() + 0.5f, (int)this.getZ()); IsoWorld.instance.takeOwnershipOfEmitter(this.emitter); } this.emitter.playSoundLoopedImpl("GeneratorLoop"); } if (GameClient.bClient) { this.emitter.tick(); return; } WorldSoundManager.instance.addSoundRepeating(this, (int)this.getX(), (int)this.getY(), (int)this.getZ(), 20, 1, false); if ((int)GameTime.getInstance().getWorldAgeHours() != this.lastHour) { if (!this.getSquare().getProperties().Is(IsoFlagType.exterior) && this.getSquare().getBuilding() != null) { this.getSquare().getBuilding().setToxic(false); this.getSquare().getBuilding().setToxic(this.isActivated()); } int n = (int)GameTime.getInstance().getWorldAgeHours() - this.lastHour; float f = 0.0f; int n2 = 0; for (int i = 0; i < n; ++i) { float f2 = this.totalPowerUsing; f2 = (float)((double)f2 * SandboxOptions.instance.GeneratorFuelConsumption.getValue()); f += f2; if (Rand.Next(30) == 0) { n2 += Rand.Next(2) + 1; } if (this.fuel - f <= 0.0f || this.condition - n2 <= 0) break; } this.fuel -= f; if (this.fuel <= 0.0f) { this.setActivated(false); this.fuel = 0.0f; } this.condition -= n2; if (this.condition <= 0) { this.setActivated(false); this.condition = 0; } if (this.condition <= 20) { if (Rand.Next(10) == 0) { IsoFireManager.StartFire(this.getCell(), this.square, true, 1000); this.condition = 0; this.setActivated(false); } else if (Rand.Next(20) == 0) { this.square.explode(); this.condition = 0; this.setActivated(false); } } this.lastHour = (int)GameTime.getInstance().getWorldAgeHours(); if (GameServer.bServer) { this.syncIsoObject(false, (byte)0, null, null); } } } if (this.emitter != null) { this.emitter.tick(); } }
kERHUS 4 Feb, 2023 @ 11:36am 
we can recall public function.
something stuff like:
GeneratorConditionRemod.lua
IsoGenerator.update() { if (this.updateSurrounding && this.getSquare() != null) { this.setSurroundingElectricity(); this.updateSurrounding = false; } if (this.isActivated()) { if (!(GameServer.bServer || this.emitter != null && this.emitter.isPlaying("GeneratorLoop"))) { if (this.emitter == null) { this.emitter = IsoWorld.instance.getFreeEmitter(this.getX() + 0.5f, this.getY() + 0.5f, (int)this.getZ()); IsoWorld.instance.takeOwnershipOfEmitter(this.emitter); } this.emitter.playSoundLoopedImpl("GeneratorLoop"); } if (GameClient.bClient) { this.emitter.tick(); return; } WorldSoundManager.instance.addSoundRepeating(this, (int)this.getX(), (int)this.getY(), (int)this.getZ(), 20, 1, false); if ((int)GameTime.getInstance().getWorldAgeHours() != this.lastHour) { if (!this.getSquare().getProperties().Is(IsoFlagType.exterior) && this.getSquare().getBuilding() != null) { this.getSquare().getBuilding().setToxic(false); this.getSquare().getBuilding().setToxic(this.isActivated()); } int n = (int)GameTime.getInstance().getWorldAgeHours() - this.lastHour; float f = 0.0f; int n2 = 0; for (int i = 0; i < n; ++i) { float f2 = this.totalPowerUsing; f2 = (float)((double)f2 * SandboxOptions.instance.GeneratorFuelConsumption.getValue()); f += f2; if (Rand.Next(30) == 0) { n2 += Rand.Next(2) + 1; } if (this.fuel - f <= 0.0f || this.condition - n2 <= 0) break; } this.fuel -= f; if (this.fuel <= 0.0f) { this.setActivated(false); this.fuel = 0.0f; } this.condition -= n2; if (this.condition <= 0) { this.setActivated(false); this.condition = 0; } if (this.condition <= 20) { if (Rand.Next(10) == 0) { IsoFireManager.StartFire(this.getCell(), this.square, true, 1000); this.condition = 0; this.setActivated(false); } else if (Rand.Next(20) == 0) { this.square.explode(); this.condition = 0; this.setActivated(false); } } this.lastHour = (int)GameTime.getInstance().getWorldAgeHours(); if (GameServer.bServer) { this.syncIsoObject(false, (byte)0, null, null); } } } if (this.emitter != null) { this.emitter.tick(); } }
kERHUS 4 Feb, 2023 @ 11:38am 
I use Recaf to see a .class file
GenChadT  [developer] 4 Feb, 2023 @ 6:16pm 
@kERHUS Thanks but this is a bit out of my depth.. Feel free to use my code as it is fully open source/unlicensed.
< >
Showing 1-5 of 5 comments
Per page: 1530 50