public override void Trigger(TriggerableContext context) { // Debug.Log($"Transistor shape triggered with {ClosestNeighbors.Count} neighbors!"); foreach (Shape shape in ClosestNeighbors) { if (CanAbsorpToExplosion(shape)) { context.WillExplode = true; } else if (CanAbsorp(shape)) { Absorption absorption = new Absorption(); absorption.Consumer = this; absorption.Consumee = shape; if (!context.Absorptions.Contains(absorption)) { context.Absorptions.Add(absorption); context.Completed = false; // Debug.Log("...and absorbed one of them!"); } } } }
// ckecks all types of shapes interactions upon placing them on tile map private void CheckoutShapeTriggers() { TriggerableContext context = new TriggerableContext(); while (!context.Completed) { context.Completed = true; for (int row = 0; row < 4; row++) { for (int col = 0; col < 4; col++) { if (!m_Cells[row, col].IsEmpty) { m_Cells[row, col].shape.Trigger(context); } } } } // check for infinity explosions if (context.WillExplode) { foreach (TileMapCell cell in m_Cells) { cell.RemoveShape(); } } else { // create Absorption graph and execute it AbsorptionGraph absorptionGraph = AbsorptionGraph.FromContext(context); absorptionGraph.Execute(); } // Debug.Log("Triggers executed!"); }
public virtual void Trigger(TriggerableContext context) { }