/// <summary> /// Generate energy as long the generator is not full. /// If it's on server the timer will go on and sync the data every time it reach 0 /// </summary> public override void Update() { try { if (EnergyContainer.GetCurrentEnergy() != EnergyContainer.MaxEnergy) { this.EnergyContainer.ReceiveEnergy(4); } if (Main.netMode == NetmodeID.Server) { updateTimer--; if (updateTimer <= 0) { NetMessage.SendData(MessageID.TileEntitySharing, -1, -1, null, ID); updateTimer = 3; } } } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); } }
private void sortListByPriority(List <GameObject> list) { for (int i = 0; i < list.Count; i++) { bool changed = false; for (int j = i; j < list.Count - 1; j++) { EnergyContainer contA = list[j].GetComponent <EnergyContainer>(); EnergyContainer contB = list[j + 1].GetComponent <EnergyContainer>(); if (contA == null || contB == null) { continue; } if (Vector3.Distance(contB.GetGameObject().transform.position, this.transform.position) < Vector3.Distance(contA.GetGameObject().transform.position, this.transform.position)) { changed = true; list.Remove(list[j + 1]); list.Insert(j, contB.GetGameObject()); Debug.Log("changed list position of " + contA.GetGameObject().name + " and " + contB.GetGameObject().name); } } if (!changed) { break; } } }
public void addEnergy(float amount, EnergyContainer from) { this.storedEnergy += amount; if (!from.Equals(this)) { recievedFromLast = from; } }
private static void TransferEnergyToShield(EnergyContainer shield, EnergyContainer reactor) { var roomForShields = shield.Capacity - shield.Energy; var energyTransferredToShields = Math.Min(roomForShields, reactor.Energy); shield.Energy += energyTransferredToShields; reactor.Energy -= energyTransferredToShields; }
private bool inNetwork(EnergyContainer container) { if (network != null && network.Contains(container)) { return(true); } return(false); }
private void createNetwork(EnergyContainer target) { Debug.Log("Creating new network!"); this.network = new List <EnergyContainer>(); if (!network.Contains(this)) { network.Add(this); } //network.Add(target); }
public ProviderTileEntity(long capacity, long maxTransfer) { tag = new TagCompound(); storage = new EnergyContainer(capacity, maxTransfer, 0); IO = new Dictionary <Side, bool>(); IO.Add(Side.down, true); IO.Add(Side.up, true); IO.Add(Side.left, true); IO.Add(Side.right, true); }
public ExampleWireTileEntity() { storage = new EnergyContainer(1024, 32, 16); IO = new Dictionary <Side, bool>(); IO.Add(Side.up, true); IO.Add(Side.left, true); IO.Add(Side.right, true); IO.Add(Side.down, true); maxTransferRate = 16; tag = new TagCompound(); }
void TryToSpawnEnergyContainer(float dropChange, EnergyContainer energyContainer) { if (Random.Range(0f, 1f) <= dropChange) { bool placeRight = Random.Range(0f, 1f) > 0.5; bool placeUp = Random.Range(0f, 1f) > 0.5; EnergyContainer newEnergyContainerInstance = Instantiate(energyContainer, new Vector2(transform.position.x + (placeRight ? Random.Range(0.1f, 0.5f) : Random.Range(-0.5f, -0.1f)), transform.position.y + (placeUp ? Random.Range(0.1f, 0.5f) : Random.Range(-0.5f, -0.1f))), Quaternion.identity); newEnergyContainerInstance.transform.parent = this.transform.parent; } }
public override void Update() { ModTileEntity up = ExampleTEMod.GetTileEntity(Position.X, Position.Y - 1); ModTileEntity down = ExampleTEMod.GetTileEntity(Position.X, Position.Y + 1); ModTileEntity left = ExampleTEMod.GetTileEntity(Position.X - 1, Position.Y); ModTileEntity right = ExampleTEMod.GetTileEntity(Position.X + 1, Position.Y); if (Main.netMode == NetmodeID.Server) { updateTimer--; if (updateTimer == 0) { NetMessage.SendData(MessageID.TileEntitySharing, -1, -1, null, ID); updateTimer = 3; } } EnergyContainer.WriteTagCompound(tag); }
public new void handleConnections() { if (network == null) { return; } float minEnergy = float.MaxValue; EnergyContainer target = null; foreach (EnergyContainer connection in base.network) { if (connection.getMaxInput() < 1) { continue; } if (connection.getCurEnergy() < minEnergy) { target = connection; minEnergy = connection.getCurEnergy(); } } if (target == null) { return; } float transferAmount = (target.getMaxInput() > this.getMaxOutput()) ? target.getMaxInput() : this.getMaxOutput(); if (target.getMaxInput() < this.getMaxOutput()) { transferAmount = target.getMaxInput(); } if (transferAmount > this.getCurEnergy()) { transferAmount = this.getCurEnergy(); } target.addEnergy(transferAmount, this); this.addEnergy(-transferAmount, this); }
protected Shield(Reactor source, int capacity, int energy) : base(capacity, energy) { Source = source; }
public void addConnection(EnergyContainer container) { this.connections.Add(container); }
public override void Start() { base.Start(); emitter.gameObject.GetComponent <BulletShot>().damagePerBullet = damagePerBullet; energyContainer = this.GetComponent <EnergyContainer>(); }
private void EnergyLeaksOut(EnergyContainer reactor) { Damage(reactor.Energy); reactor.Energy = 0; }