Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package zombie.radio.devices;
- import java.io.IOException;
- import java.nio.ByteBuffer;
- import java.util.ArrayList;
- import java.util.Map;
- import zombie.GameTime;
- import zombie.GameWindow;
- import zombie.SandboxOptions;
- import zombie.WorldSoundManager;
- import zombie.audio.BaseSoundEmitter;
- import zombie.characters.IsoPlayer;
- import zombie.core.Rand;
- import zombie.core.network.ByteBufferWriter;
- import zombie.core.raknet.UdpConnection;
- import zombie.inventory.InventoryItem;
- import zombie.inventory.InventoryItemFactory;
- import zombie.inventory.ItemContainer;
- import zombie.inventory.types.DrainableComboItem;
- import zombie.inventory.types.Radio;
- import zombie.iso.IsoGridSquare;
- import zombie.iso.IsoObject;
- import zombie.iso.IsoWorld;
- import zombie.iso.objects.IsoWaveSignal;
- import zombie.network.GameClient;
- import zombie.network.GameServer;
- import zombie.network.PacketTypesShort;
- import zombie.radio.ZomboidRadio;
- import zombie.vehicles.BaseVehicle;
- import zombie.vehicles.VehiclePart;
- public class DeviceData
- implements Cloneable
- {
- private static final float deviceSpeakerSoundMod = 0.4F;
- private static final float deviceButtonSoundVol = 0.05F;
- protected String deviceName;
- protected boolean twoWay;
- protected int transmitRange;
- protected int micRange;
- protected boolean micIsMuted;
- protected float baseVolumeRange;
- protected float deviceVolume;
- protected boolean isPortable;
- protected boolean isTelevision;
- protected boolean isHighTier;
- protected boolean isTurnedOn;
- protected int channel;
- protected int minChannelRange;
- protected int maxChannelRange;
- protected DevicePresets presets;
- protected boolean isBatteryPowered;
- protected boolean hasBattery;
- protected float powerDelta;
- protected float useDelta;
- protected int lastRecordedDistance;
- protected int headphoneType;
- protected WaveSignalDevice parent;
- protected GameTime gameTime;
- protected boolean channelChangedRecently;
- protected BaseSoundEmitter emitter;
- protected ArrayList<Long> soundIDs;
- private float soundCounterStatic;
- protected long radioLoopSound;
- protected boolean doTriggerWorldSound;
- protected long lastMinuteStamp;
- protected int listenCnt;
- float nextStaticSound;
- protected float signalCounter;
- protected float soundCounter;
- public DeviceData() { this(null); }
- public void generatePresets() {
- if (this.presets == null) {
- this.presets = new DevicePresets();
- }
- this.presets.clearPresets();
- if (this.isTelevision) {
- Map map = ZomboidRadio.getInstance().GetChannelList("Television");
- if (map != null) {
- for (Map.Entry entry : map.entrySet()) {
- if (((Integer)entry.getKey()).intValue() >= this.minChannelRange && ((Integer)entry.getKey()).intValue() <= this.maxChannelRange) {
- this.presets.addPreset((String)entry.getValue(), ((Integer)entry.getKey()).intValue());
- }
- }
- }
- } else {
- byte b = this.twoWay ? 100 : 800;
- Map map = ZomboidRadio.getInstance().GetChannelList("Radio");
- if (map != null) {
- for (Map.Entry entry : map.entrySet()) {
- if (((Integer)entry.getKey()).intValue() >= this.minChannelRange && ((Integer)entry.getKey()).intValue() <= this.maxChannelRange && Rand.Next(1000) < b) {
- this.presets.addPreset((String)entry.getValue(), ((Integer)entry.getKey()).intValue());
- }
- }
- }
- if (this.twoWay) {
- map = ZomboidRadio.getInstance().GetChannelList("Amateur");
- if (map != null) {
- for (Map.Entry entry : map.entrySet()) {
- if (((Integer)entry.getKey()).intValue() >= this.minChannelRange && ((Integer)entry.getKey()).intValue() <= this.maxChannelRange && Rand.Next(1000) < b) {
- this.presets.addPreset((String)entry.getValue(), ((Integer)entry.getKey()).intValue());
- }
- }
- }
- }
- if (this.isHighTier) {
- map = ZomboidRadio.getInstance().GetChannelList("Military");
- if (map != null) {
- for (Map.Entry entry : map.entrySet()) {
- if (((Integer)entry.getKey()).intValue() >= this.minChannelRange && ((Integer)entry.getKey()).intValue() <= this.maxChannelRange && Rand.Next(1000) < 10) {
- this.presets.addPreset((String)entry.getValue(), ((Integer)entry.getKey()).intValue());
- }
- }
- }
- }
- }
- }
- protected Object clone() throws CloneNotSupportedException {
- DeviceData deviceData = (DeviceData)super.clone();
- deviceData.setDevicePresets((DevicePresets)this.presets.clone());
- deviceData.setParent(null);
- return deviceData;
- }
- public DeviceData getClone() {
- DeviceData deviceData;
- try {
- deviceData = (DeviceData)clone();
- } catch (Exception exception) {
- System.out.println(exception.getMessage());
- deviceData = new DeviceData();
- }
- return deviceData;
- }
- public WaveSignalDevice getParent() { return this.parent; }
- public void setParent(WaveSignalDevice paramWaveSignalDevice) { this.parent = paramWaveSignalDevice; }
- public DevicePresets getDevicePresets() { return this.presets; }
- public void setDevicePresets(DevicePresets paramDevicePresets) {
- if (paramDevicePresets == null) {
- paramDevicePresets = new DevicePresets();
- }
- this.presets = paramDevicePresets;
- }
- public int getMinChannelRange() { return this.minChannelRange; }
- public void setMinChannelRange(int paramInt) { this.minChannelRange = (paramInt >= 200 && paramInt <= 1000000) ? paramInt : 200; }
- public int getMaxChannelRange() { return this.maxChannelRange; }
- public void setMaxChannelRange(int paramInt) { this.maxChannelRange = (paramInt >= 200 && paramInt <= 1000000) ? paramInt : 1000000; }
- public boolean getIsHighTier() { return this.isHighTier; }
- public void setIsHighTier(boolean paramBoolean) { this.isHighTier = paramBoolean; }
- public boolean getIsBatteryPowered() { return this.isBatteryPowered; }
- public void setIsBatteryPowered(boolean paramBoolean) { this.isBatteryPowered = paramBoolean; }
- public boolean getHasBattery() { return this.hasBattery; }
- public void setHasBattery(boolean paramBoolean) { this.hasBattery = paramBoolean; }
- public void addBattery(DrainableComboItem paramDrainableComboItem) {
- if (!this.hasBattery && paramDrainableComboItem != null && paramDrainableComboItem.getFullType().equals("Base.Battery")) {
- ItemContainer itemContainer = paramDrainableComboItem.getContainer();
- if (itemContainer != null) {
- if (itemContainer.getType().equals("floor") && paramDrainableComboItem.getWorldItem() != null && paramDrainableComboItem.getWorldItem().getSquare() != null) {
- paramDrainableComboItem.getWorldItem().getSquare().transmitRemoveItemFromSquare(paramDrainableComboItem.getWorldItem());
- paramDrainableComboItem.getWorldItem().getSquare().getWorldObjects().remove(paramDrainableComboItem.getWorldItem());
- (paramDrainableComboItem.getWorldItem().getSquare()).chunk.recalcHashCodeObjects();
- paramDrainableComboItem.getWorldItem().getSquare().getObjects().remove(paramDrainableComboItem.getWorldItem());
- paramDrainableComboItem.setWorldItem(null);
- }
- this.powerDelta = paramDrainableComboItem.getDelta();
- itemContainer.DoRemoveItem(paramDrainableComboItem);
- this.hasBattery = true;
- transmitDeviceDataState((byte)2);
- }
- }
- }
- public InventoryItem getBattery(ItemContainer paramItemContainer) {
- if (this.hasBattery) {
- DrainableComboItem drainableComboItem = (DrainableComboItem)InventoryItemFactory.CreateItem("Base.Battery");
- drainableComboItem.setDelta(this.powerDelta);
- this.powerDelta = 0.0F;
- paramItemContainer.AddItem(drainableComboItem);
- this.hasBattery = false;
- transmitDeviceDataState((byte)2);
- return drainableComboItem;
- }
- return null;
- }
- public void transmitBattryChange() { transmitDeviceDataState((byte)2); }
- public void addHeadphones(InventoryItem paramInventoryItem) {
- if (this.headphoneType < 0 && (paramInventoryItem.getFullType().equals("Base.Headphones") || paramInventoryItem.getFullType().equals("Base.Earbuds"))) {
- ItemContainer itemContainer = paramInventoryItem.getContainer();
- if (itemContainer != null) {
- if (itemContainer.getType().equals("floor") && paramInventoryItem.getWorldItem() != null && paramInventoryItem.getWorldItem().getSquare() != null) {
- paramInventoryItem.getWorldItem().getSquare().transmitRemoveItemFromSquare(paramInventoryItem.getWorldItem());
- paramInventoryItem.getWorldItem().getSquare().getWorldObjects().remove(paramInventoryItem.getWorldItem());
- (paramInventoryItem.getWorldItem().getSquare()).chunk.recalcHashCodeObjects();
- paramInventoryItem.getWorldItem().getSquare().getObjects().remove(paramInventoryItem.getWorldItem());
- paramInventoryItem.setWorldItem(null);
- }
- byte b = paramInventoryItem.getFullType().equals("Base.Headphones") ? 0 : 1;
- itemContainer.DoRemoveItem(paramInventoryItem);
- setHeadphoneType(b);
- transmitDeviceDataState((byte)6);
- }
- }
- }
- public InventoryItem getHeadphones(ItemContainer paramItemContainer) {
- if (this.headphoneType >= 0) {
- InventoryItem inventoryItem = null;
- if (this.headphoneType == 0) {
- inventoryItem = InventoryItemFactory.CreateItem("Base.Headphones");
- } else if (this.headphoneType == 1) {
- inventoryItem = InventoryItemFactory.CreateItem("Base.Earbuds");
- }
- if (inventoryItem != null) {
- paramItemContainer.AddItem(inventoryItem);
- }
- setHeadphoneType(-1);
- transmitDeviceDataState((byte)6);
- }
- return null;
- }
- public int getMicRange() { return this.micRange; }
- public void setMicRange(int paramInt) { this.micRange = paramInt; }
- public boolean getMicIsMuted() { return this.micIsMuted; }
- public void setMicIsMuted(boolean paramBoolean) { this.micIsMuted = paramBoolean; }
- public DeviceData(WaveSignalDevice paramWaveSignalDevice) {
- this.deviceName = "WaveSignalDevice";
- this.twoWay = false;
- this.transmitRange = 1000;
- this.micRange = 5;
- this.micIsMuted = false;
- this.baseVolumeRange = 15.0F;
- this.deviceVolume = 1.0F;
- this.isPortable = false;
- this.isTelevision = false;
- this.isHighTier = false;
- this.isTurnedOn = false;
- this.channel = 88000;
- this.minChannelRange = 200;
- this.maxChannelRange = 1000000;
- this.presets = null;
- this.isBatteryPowered = true;
- this.hasBattery = true;
- this.powerDelta = 1.0F;
- this.useDelta = 0.001F;
- this.lastRecordedDistance = -1;
- this.headphoneType = -1;
- this.parent = null;
- this.gameTime = null;
- this.channelChangedRecently = false;
- this.emitter = null;
- this.soundIDs = new ArrayList();
- this.soundCounterStatic = 0.0F;
- this.radioLoopSound = 0L;
- this.doTriggerWorldSound = false;
- this.lastMinuteStamp = -1L;
- this.listenCnt = 0;
- this.nextStaticSound = 0.0F;
- this.signalCounter = 0.0F;
- this.soundCounter = 0.0F; this.parent = paramWaveSignalDevice; this.presets = new DevicePresets(); this.gameTime = GameTime.getInstance();
- } public int getHeadphoneType() { return this.headphoneType; } public void setHeadphoneType(int paramInt) { this.headphoneType = paramInt; } public float getBaseVolumeRange() { return this.baseVolumeRange; } public void setBaseVolumeRange(float paramFloat) { this.baseVolumeRange = paramFloat; } public float getDeviceVolume() { return this.deviceVolume; } public void setDeviceVolume(float paramFloat) { this.deviceVolume = (paramFloat < 0.0F) ? 0.0F : ((paramFloat > 1.0F) ? 1.0F : paramFloat);
- transmitDeviceDataState((byte)4); } public void setDeviceVolumeRaw(float paramFloat) { this.deviceVolume = (paramFloat < 0.0F) ? 0.0F : ((paramFloat > 1.0F) ? 1.0F : paramFloat); } public boolean getIsTelevision() { return this.isTelevision; } public void doReceiveSignal(int paramInt) { if (this.isTurnedOn)
- { this.lastRecordedDistance = paramInt;
- this.signalCounter = 300.0F;
- this.doTriggerWorldSound = true;
- setNextStaticSound(); } } public void setIsTelevision(boolean paramBoolean) { this.isTelevision = paramBoolean; } public String getDeviceName() { return this.deviceName; } public void setDeviceName(String paramString) { this.deviceName = paramString; } public boolean getIsTwoWay() { return this.twoWay; } public void setIsTwoWay(boolean paramBoolean) { this.twoWay = paramBoolean; } public int getTransmitRange() { return this.transmitRange; } public void setTransmitRange(int paramInt) { this.transmitRange = (paramInt > 0) ? paramInt : 0; } public boolean getIsPortable() { return this.isPortable; } public void setIsPortable(boolean paramBoolean) { this.isPortable = paramBoolean; } public boolean getIsTurnedOn() { return this.isTurnedOn; } public void setIsTurnedOn(boolean paramBoolean) { if (canBePoweredHere()) { if (!this.isBatteryPowered || this.powerDelta > 0.0F) { this.isTurnedOn = paramBoolean; } else { this.isTurnedOn = false; } playSoundSend("RadioButton", false); transmitDeviceDataState((byte)0); } else if (this.isTurnedOn) { this.isTurnedOn = false; playSoundSend("RadioButton", false); transmitDeviceDataState((byte)0); } } public void setTurnedOnRaw(boolean paramBoolean) { this.isTurnedOn = paramBoolean; } public boolean canBePoweredHere() { if (this.isBatteryPowered == true) return true; if (this.parent instanceof VehiclePart) { VehiclePart vehiclePart = (VehiclePart)this.parent; if (vehiclePart.getItemType() != null && !vehiclePart.getItemType().isEmpty() && vehiclePart.getInventoryItem() == null) return false; return vehiclePart.hasDevicePower(); } boolean bool = false; if (GameTime.getInstance().getNightsSurvived() < SandboxOptions.instance.getElecShutModifier()) bool = true; if (this.parent == null || this.parent.getSquare() == null) { bool = false; } else if (this.parent.getSquare().haveElectricity()) { bool = true; } else if (this.parent.getSquare().getRoom() == null) { bool = false; } return bool; } public void setRandomChannel() { if (this.presets != null && this.presets.getPresets().size() > 0) { int i = Rand.Next(0, this.presets.getPresets().size()); this.channel = ((PresetEntry)this.presets.getPresets().get(i)).getFrequency(); } else { this.channel = Rand.Next(this.minChannelRange, this.maxChannelRange); this.channel -= this.channel % 200; } }
- public int getChannel() { return this.channel; }
- public void setChannel(int paramInt) { setChannel(paramInt, true); }
- public void setChannel(int paramInt, boolean paramBoolean) { if (paramInt >= this.minChannelRange && paramInt <= this.maxChannelRange) { this.channel = paramInt; playSoundSend("RadioButton", false); if (this.isTelevision) { playSoundSend("TelevisionZap", true); } else { playSoundSend("RadioZap", true); } if (this.radioLoopSound > 0L) { this.emitter.stopSound(this.radioLoopSound); this.radioLoopSound = 0L; } transmitDeviceDataState((byte)1); if (paramBoolean)
- TriggerPlayerListening(true); } }
- public boolean isReceivingSignal() { return (this.signalCounter > 0.0F); }
- public void setChannelRaw(int paramInt) { this.channel = paramInt; }
- public float getUseDelta() { return this.useDelta; }
- public void setUseDelta(float paramFloat) { this.useDelta = paramFloat / 60.0F; }
- public float getPower() { return this.powerDelta; } public void setPower(float paramFloat) { if (paramFloat > 1.0F) paramFloat = 1.0F; if (paramFloat < 0.0F) paramFloat = 0.0F; this.powerDelta = paramFloat; } public void TriggerPlayerListening(boolean paramBoolean) { if (this.isTurnedOn) ZomboidRadio.getInstance().PlayerListensChannel(this.channel, true, this.isTelevision); } public void playSoundSend(String paramString, boolean paramBoolean) { playSound(paramString, paramBoolean ? (this.deviceVolume * 0.4F) : 0.05F, true); } public void playSoundLocal(String paramString, boolean paramBoolean) { playSound(paramString, paramBoolean ? (this.deviceVolume * 0.4F) : 0.05F, false); } public void playSound(String paramString, float paramFloat, boolean paramBoolean) { if (GameServer.bServer) return; setEmitterAndPos(); if (this.emitter != null) { long l = paramBoolean ? this.emitter.playSound(paramString) : this.emitter.playSoundImpl(paramString, false, null); this.emitter.setVolume(l, paramFloat); } } public void cleanSoundsAndEmitter() { if (this.emitter != null) { this.emitter.stopAll(); IsoWorld.instance.freeEmitters.add(this.emitter); this.emitter = null; this.radioLoopSound = 0L; } } protected void setEmitterAndPos() { IsoPlayer isoPlayer = null; if (this.parent != null && this.parent instanceof IsoObject) { isoPlayer = (IsoObject)this.parent; } else if (this.parent != null && this.parent instanceof Radio) { isoPlayer = IsoPlayer.getInstance(); } if (isoPlayer != null) { if (this.emitter == null) { this.emitter = IsoWorld.instance.getFreeEmitter(isoPlayer.getX() + 0.5F, isoPlayer.getY() + 0.5F, (int)isoPlayer.getZ()); IsoWorld.instance.currentEmitters.remove(this.emitter); } else { this.emitter.setPos(isoPlayer.getX() + 0.5F, isoPlayer.getY() + 0.5F, (int)isoPlayer.getZ()); } if (this.radioLoopSound != 0L) this.emitter.setVolume(this.radioLoopSound, this.deviceVolume * 0.4F); } } public int getLastRecordedDistance() { return this.lastRecordedDistance; }
- protected void updateEmitter() { if (GameServer.bServer) return; if (!this.isTurnedOn) { if (this.emitter != null && this.emitter.isPlaying("RadioButton")) { if (this.radioLoopSound > 0L) this.emitter.stopSound(this.radioLoopSound); setEmitterAndPos(); this.emitter.tick(); return; } cleanSoundsAndEmitter(); return; } setEmitterAndPos(); if (this.emitter != null) { if (this.signalCounter > 0.0F && !this.emitter.isPlaying("RadioTalk")) { if (this.radioLoopSound > 0L) this.emitter.stopSound(this.radioLoopSound); this.radioLoopSound = this.emitter.playSoundImpl("RadioTalk", false, null); this.emitter.setVolume(this.radioLoopSound, this.deviceVolume * 0.4F); } String str = !this.isTelevision ? "RadioStatic" : "TelevisionTestBeep"; if (this.radioLoopSound == 0L || (this.signalCounter <= 0.0F && !this.emitter.isPlaying(str))) { if (this.radioLoopSound > 0L) { this.emitter.stopSound(this.radioLoopSound); if (this.isTelevision) { playSoundLocal("TelevisionZap", true); } else { playSoundLocal("RadioZap", true); } } this.radioLoopSound = this.emitter.playSoundImpl(str, false, null); this.emitter.setVolume(this.radioLoopSound, this.deviceVolume * 0.4F); } this.emitter.tick(); } }
- public void update(boolean paramBoolean1, boolean paramBoolean2) { if (this.lastMinuteStamp == -1L) this.lastMinuteStamp = this.gameTime.getMinutesStamp(); if (this.gameTime.getMinutesStamp() > this.lastMinuteStamp) { long l = this.gameTime.getMinutesStamp() - this.lastMinuteStamp; this.lastMinuteStamp = this.gameTime.getMinutesStamp(); this.listenCnt = (int)(this.listenCnt + l); if (this.listenCnt >= 10)
- this.listenCnt = 0; if (!GameServer.bServer && this.isTurnedOn && paramBoolean2 && (this.listenCnt == 0 || this.listenCnt == 5))
- TriggerPlayerListening(true); if (this.isTurnedOn && this.isBatteryPowered && this.powerDelta > 0.0F) { float f = this.powerDelta - this.powerDelta % 0.01F; setPower(this.powerDelta - this.useDelta * (float)l); if (this.listenCnt == 0 || this.powerDelta == 0.0F || this.powerDelta < f)
- if (paramBoolean1 && GameServer.bServer) { transmitDeviceDataStateServer((byte)3, null); } else if (!paramBoolean1 && GameClient.bClient) { transmitDeviceDataState((byte)3); } } } if (this.isTurnedOn && ((this.isBatteryPowered && this.powerDelta <= 0.0F) || !canBePoweredHere())) { this.isTurnedOn = false; if (paramBoolean1 && GameServer.bServer) { transmitDeviceDataStateServer((byte)0, null); } else if (!paramBoolean1 && GameClient.bClient) { transmitDeviceDataState((byte)0); } } updateEmitter(); updateSimple(); } public boolean isIsoDevice() { return (getParent() != null && getParent() instanceof IsoWaveSignal); } public void updateSimple() { if (this.signalCounter >= 0.0F) this.signalCounter -= 1.25F * GameTime.getInstance().getMultiplier(); if (this.soundCounter >= 0.0F) this.soundCounter = (float)(this.soundCounter - 1.25D * GameTime.getInstance().getMultiplier()); if (this.signalCounter <= 0.0F && this.lastRecordedDistance >= 0) this.lastRecordedDistance = -1; updateStaticSounds(); if (GameClient.bClient) updateEmitter(); if (this.doTriggerWorldSound && this.soundCounter <= 0.0F) { if (this.isTurnedOn && this.deviceVolume > 0.0F && (!isInventoryDevice() || this.headphoneType < 0) && ((!GameClient.bClient && !GameServer.bServer) || (GameClient.bClient && isInventoryDevice()) || (GameServer.bServer && !isInventoryDevice()))) { BaseVehicle baseVehicle = null; if (this.parent != null && this.parent instanceof IsoObject) { baseVehicle = (IsoObject)this.parent; } else if (this.parent != null && this.parent instanceof Radio) { IsoPlayer isoPlayer = IsoPlayer.getInstance(); } else if (this.parent instanceof VehiclePart) { baseVehicle = ((VehiclePart)this.parent).getVehicle(); } if (baseVehicle != null) { int i = (int)(100.0F * this.deviceVolume); int j = getDeviceSoundVolumeRange(); WorldSoundManager.instance.addSound(baseVehicle, (int)baseVehicle.getX(), (int)baseVehicle.getY(), (int)baseVehicle.getZ(), j, i, (i > 50)); } } this.doTriggerWorldSound = false; this.soundCounter = (300 + Rand.Next(0, 300)); } } private void updateStaticSounds() { if (!this.isTurnedOn) return; float f = GameTime.getInstance().getMultiplier(); this.nextStaticSound -= f; if (this.nextStaticSound <= 0.0F) { if (this.parent != null) { this.parent.AddDeviceText(ZomboidRadio.getInstance().getRandomBzztFzzt(), 1.0F, 1.0F, 1.0F, null, -1); this.doTriggerWorldSound = true; } setNextStaticSound(); } } private void setNextStaticSound() { this.nextStaticSound = Rand.Next(250.0F, 1500.0F); }
- public int getDeviceVolumeRange() { return 5 + (int)(this.baseVolumeRange * this.deviceVolume); }
- public int getDeviceSoundVolumeRange() { if (isInventoryDevice()) { Radio radio = (Radio)getParent(); if (radio.getPlayer() != null && radio.getPlayer().getSquare() != null && radio.getPlayer().getSquare().getRoom() != null) return 3 + (int)(this.baseVolumeRange * 0.4F * this.deviceVolume); return 5 + (int)(this.baseVolumeRange * this.deviceVolume); } if (isIsoDevice()) { IsoWaveSignal isoWaveSignal = (IsoWaveSignal)getParent(); if (isoWaveSignal.getSquare() != null && isoWaveSignal.getSquare().getRoom() != null) return 3 + (int)(this.baseVolumeRange * 0.5F * this.deviceVolume); return 5 + (int)(this.baseVolumeRange * 0.75F * this.deviceVolume); } return 5 + (int)(this.baseVolumeRange / 2.0F * this.deviceVolume); }
- public boolean isInventoryDevice() { return (getParent() != null && getParent() instanceof Radio); }
- public boolean isVehicleDevice() { return getParent() instanceof VehiclePart; }
- public void transmitPresets() { transmitDeviceDataState((byte)5); }
- private void transmitDeviceDataState(byte paramByte) {
- if (GameClient.bClient) {
- try {
- sendDeviceDataStatePacket(GameClient.connection, paramByte);
- }
- catch (Exception exception) {
- System.out.print(exception.getMessage());
- }
- }
- }
- private void transmitDeviceDataStateServer(byte paramByte, UdpConnection paramUdpConnection) {
- if (GameServer.bServer) {
- try {
- for (byte b = 0; b < GameServer.udpEngine.connections.size(); b++) {
- UdpConnection udpConnection = (UdpConnection)GameServer.udpEngine.connections.get(b);
- if (paramUdpConnection == null || paramUdpConnection != udpConnection)
- {
- sendDeviceDataStatePacket(udpConnection, paramByte);
- }
- }
- } catch (Exception exception) {
- System.out.print(exception.getMessage());
- }
- }
- }
- private void sendDeviceDataStatePacket(UdpConnection paramUdpConnection, byte paramByte) throws IOException
- {
- ByteBufferWriter byteBufferWriter = paramUdpConnection.startPacket();
- PacketTypesShort.doPacket((short)1004, byteBufferWriter);
- boolean bool = false;
- if (isIsoDevice()) {
- IsoWaveSignal isoWaveSignal = (IsoWaveSignal)getParent();
- IsoGridSquare isoGridSquare = isoWaveSignal.getSquare();
- if (isoGridSquare != null) {
- byteBufferWriter.putByte((byte)1);
- byteBufferWriter.putInt(isoGridSquare.getX());
- byteBufferWriter.putInt(isoGridSquare.getY());
- byteBufferWriter.putInt(isoGridSquare.getZ());
- byteBufferWriter.putInt(isoGridSquare.getObjects().indexOf(isoWaveSignal));
- bool = true;
- }
- } else if (isInventoryDevice()) {
- Radio radio = (Radio)getParent();
- IsoPlayer isoPlayer = null;
- if (radio.getEquipParent() != null && radio.getEquipParent() instanceof IsoPlayer)
- isoPlayer = (IsoPlayer)radio.getEquipParent();
- if (isoPlayer != null) {
- byteBufferWriter.putByte((byte)0);
- if (GameServer.bServer) {
- byteBufferWriter.putInt((isoPlayer != null) ? isoPlayer.OnlineID : -1);
- } else {
- byteBufferWriter.putByte((byte)isoPlayer.PlayerIndex);
- }
- if (isoPlayer.getPrimaryHandItem() == radio) {
- byteBufferWriter.putByte((byte)1);
- } else if (isoPlayer.getSecondaryHandItem() == radio) {
- byteBufferWriter.putByte((byte)2);
- } else {
- byteBufferWriter.putByte((byte)0);
- }
- bool = true;
- }
- } else if (isVehicleDevice()) {
- VehiclePart vehiclePart = (VehiclePart)getParent();
- byteBufferWriter.putByte((byte)2);
- byteBufferWriter.putShort((vehiclePart.getVehicle()).VehicleID);
- byteBufferWriter.putShort((short)vehiclePart.getIndex());
- bool = true;
- }
- if (bool) {
- byteBufferWriter.putByte(paramByte);
- switch (paramByte) {
- case 0:
- byteBufferWriter.putByte(this.isTurnedOn ? 1 : 0);
- break;
- case 1:
- byteBufferWriter.putInt(this.channel);
- break;
- case 2:
- byteBufferWriter.putByte(this.hasBattery ? 1 : 0);
- byteBufferWriter.putFloat(this.powerDelta);
- break;
- case 3:
- byteBufferWriter.putFloat(this.powerDelta);
- break;
- case 4:
- byteBufferWriter.putFloat(this.deviceVolume);
- break;
- case 5:
- byteBufferWriter.putInt(this.presets.getPresets().size());
- for (PresetEntry presetEntry : this.presets.getPresets()) {
- GameWindow.WriteString(byteBufferWriter.bb, presetEntry.getName());
- byteBufferWriter.putInt(presetEntry.getFrequency());
- }
- break;
- case 6:
- byteBufferWriter.putInt(this.headphoneType);
- break;
- }
- paramUdpConnection.endPacketImmediate();
- } else {
- paramUdpConnection.cancelPacket();
- } } public void receiveDeviceDataStatePacket(ByteBuffer paramByteBuffer, UdpConnection paramUdpConnection) throws IOException { byte b1;
- int j;
- float f3, f2, f1;
- boolean bool2;
- int i;
- if (!GameClient.bClient && !GameServer.bServer) {
- return;
- }
- boolean bool = GameServer.bServer;
- boolean bool1 = (isIsoDevice() || isVehicleDevice()) ? 1 : 0;
- byte b = paramByteBuffer.get();
- switch (b) {
- case 0:
- if (bool && bool1) {
- setIsTurnedOn((paramByteBuffer.get() == 1));
- } else {
- this.isTurnedOn = (paramByteBuffer.get() == 1);
- }
- if (bool) {
- transmitDeviceDataStateServer(b, !bool1 ? paramUdpConnection : null);
- }
- break;
- case 1:
- i = paramByteBuffer.getInt();
- if (bool && bool1) {
- setChannel(i);
- } else {
- this.channel = i;
- }
- if (bool) {
- transmitDeviceDataStateServer(b, !bool1 ? paramUdpConnection : null);
- }
- break;
- case 2:
- bool2 = (paramByteBuffer.get() == 1) ? 1 : 0;
- f1 = paramByteBuffer.getFloat();
- if (bool && bool1) {
- this.hasBattery = bool2;
- setPower(f1);
- } else {
- this.hasBattery = bool2;
- this.powerDelta = f1;
- }
- if (bool) {
- transmitDeviceDataStateServer(b, !bool1 ? paramUdpConnection : null);
- }
- break;
- case 3:
- f2 = paramByteBuffer.getFloat();
- if (bool && bool1) {
- setPower(f2);
- } else {
- this.powerDelta = f2;
- }
- if (bool) {
- transmitDeviceDataStateServer(b, !bool1 ? paramUdpConnection : null);
- }
- break;
- case 4:
- f3 = paramByteBuffer.getFloat();
- if (bool && bool1) {
- setDeviceVolume(f3);
- } else {
- this.deviceVolume = f3;
- }
- if (bool) {
- transmitDeviceDataStateServer(b, !bool1 ? paramUdpConnection : null);
- }
- break;
- case 5:
- j = paramByteBuffer.getInt();
- for (b1 = 0; b1 < j; b1++) {
- String str = GameWindow.ReadString(paramByteBuffer);
- int k = paramByteBuffer.getInt();
- if (b1 < this.presets.getPresets().size()) {
- PresetEntry presetEntry = (PresetEntry)this.presets.getPresets().get(b1);
- if (!presetEntry.getName().equals(str) || presetEntry.getFrequency() != k) {
- presetEntry.setName(str);
- presetEntry.setFrequency(k);
- }
- } else {
- this.presets.addPreset(str, k);
- }
- } if (bool) {
- transmitDeviceDataStateServer((byte)5, !bool1 ? paramUdpConnection : null);
- }
- break;
- case 6:
- this.headphoneType = paramByteBuffer.getInt();
- if (bool) {
- transmitDeviceDataStateServer(b, !bool1 ? paramUdpConnection : null);
- }
- break;
- } }
- public void save(ByteBuffer paramByteBuffer, boolean paramBoolean) throws IOException {
- GameWindow.WriteString(paramByteBuffer, this.deviceName);
- paramByteBuffer.put(this.twoWay ? 1 : 0);
- paramByteBuffer.putInt(this.transmitRange);
- paramByteBuffer.putInt(this.micRange);
- paramByteBuffer.put(this.micIsMuted ? 1 : 0);
- paramByteBuffer.putFloat(this.baseVolumeRange);
- paramByteBuffer.putFloat(this.deviceVolume);
- paramByteBuffer.put(this.isPortable ? 1 : 0);
- paramByteBuffer.put(this.isTelevision ? 1 : 0);
- paramByteBuffer.put(this.isHighTier ? 1 : 0);
- paramByteBuffer.put(this.isTurnedOn ? 1 : 0);
- paramByteBuffer.putInt(this.channel);
- paramByteBuffer.putInt(this.minChannelRange);
- paramByteBuffer.putInt(this.maxChannelRange);
- paramByteBuffer.put(this.isBatteryPowered ? 1 : 0);
- paramByteBuffer.put(this.hasBattery ? 1 : 0);
- paramByteBuffer.putFloat(this.powerDelta);
- paramByteBuffer.putFloat(this.useDelta);
- paramByteBuffer.putInt(this.headphoneType);
- if (this.presets != null) {
- paramByteBuffer.put((byte)1);
- this.presets.save(paramByteBuffer, paramBoolean);
- } else {
- paramByteBuffer.put((byte)0);
- }
- }
- public void load(ByteBuffer paramByteBuffer, int paramInt, boolean paramBoolean) throws IOException {
- if (this.presets == null) {
- this.presets = new DevicePresets();
- }
- if (paramInt >= 69) {
- this.deviceName = GameWindow.ReadString(paramByteBuffer);
- this.twoWay = (paramByteBuffer.get() == 1);
- this.transmitRange = paramByteBuffer.getInt();
- this.micRange = paramByteBuffer.getInt();
- this.micIsMuted = (paramByteBuffer.get() == 1);
- this.baseVolumeRange = paramByteBuffer.getFloat();
- this.deviceVolume = paramByteBuffer.getFloat();
- this.isPortable = (paramByteBuffer.get() == 1);
- this.isTelevision = (paramByteBuffer.get() == 1);
- this.isHighTier = (paramByteBuffer.get() == 1);
- this.isTurnedOn = (paramByteBuffer.get() == 1);
- this.channel = paramByteBuffer.getInt();
- this.minChannelRange = paramByteBuffer.getInt();
- this.maxChannelRange = paramByteBuffer.getInt();
- this.isBatteryPowered = (paramByteBuffer.get() == 1);
- this.hasBattery = (paramByteBuffer.get() == 1);
- this.powerDelta = paramByteBuffer.getFloat();
- this.useDelta = paramByteBuffer.getFloat();
- this.headphoneType = paramByteBuffer.getInt();
- if (paramByteBuffer.get() == 1)
- this.presets.load(paramByteBuffer, paramInt, paramBoolean);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement