void EmptyCell_MouseDown(object sender, MouseButtonEventArgs e) { if (Occupied == true || Occupant != null) { return; } ListBoxItem lbi = (Window1.instance.Towers.SelectedItem as ListBoxItem); if (lbi == null) { return; } Occupied = true; Arena.instance.PathInvaliation.Enqueue(this); foreach (EmptyCell C in Adjacent) { if (Arena.instance.PathInvaliation.Contains(C) == false) { Arena.instance.PathInvaliation.Enqueue(C); } } // if (Arena.instance.FindPathCells(Arena.instance.Begin, Arena.instance.End) != null) { Tower b = null; //System.Xml.XmlParserContext xpc = new System.Xml.XmlParserContext( System.Windows.Markup.ParserContext parserContext; parserContext = new System.Windows.Markup.ParserContext(); parserContext.XmlnsDictionary.Add("", "http://schemas.microsoft.com/winfx/2006/xaml/presentation"); parserContext.XmlnsDictionary.Add("x", "http://schemas.microsoft.com/winfx/2006/xaml"); TowerData PTD = lbi.Tag as TowerData; if ((PTD as HeatTowerData) != null) { HeatTower ht = new HeatTower(); ht.Data = (PTD as HeatTowerData); object tf = System.Windows.Markup.XamlReader.Parse(ht.Data.XAML, parserContext); FrameworkElement tb = tf as FrameworkElement; Shape bc = LogicalTreeHelper.FindLogicalNode(tb, "_Body") as Shape; ht.Body = bc; tb.SetValue(Canvas.TopProperty, this.GetValue(Canvas.TopProperty)); tb.SetValue(Canvas.LeftProperty, this.GetValue(Canvas.LeftProperty)); ht.SetValue(Canvas.TopProperty, this.GetValue(Canvas.TopProperty)); ht.SetValue(Canvas.LeftProperty, this.GetValue(Canvas.LeftProperty)); ht.VisualObject = tb; Arena.instance.AddToArena(tb); Arena.instance.AddToArena(ht); ht.OwningCell = this; this.Occupant = ht; this.Occupied = true; } if ((PTD as ProjectileTowerData) != null) { ProjectileTower pt = new ProjectileTower(); pt.Data = (PTD as ProjectileTowerData); object tf = System.Windows.Markup.XamlReader.Parse(pt.Data.XAML, parserContext); FrameworkElement tb = tf as FrameworkElement; if (tb != null) { Shape bb = LogicalTreeHelper.FindLogicalNode(tb, "_Barrel") as Shape; pt.Barrel = bb; Shape bc = LogicalTreeHelper.FindLogicalNode(tb, "_Body") as Shape; pt.Body = bc; tb.SetValue(Canvas.TopProperty, this.GetValue(Canvas.TopProperty)); tb.SetValue(Canvas.LeftProperty, this.GetValue(Canvas.LeftProperty)); pt.SetValue(Canvas.TopProperty, this.GetValue(Canvas.TopProperty)); pt.SetValue(Canvas.LeftProperty, this.GetValue(Canvas.LeftProperty)); pt.VisualObject = tb; Arena.instance.AddToArena(tb); Arena.instance.AddToArena(pt); pt.OwningCell = this; this.Occupant = pt; this.Occupied = true; //Arena.instance.Children.Add(pt); //Arena.instance.Children.Add(tb); } //b.OwningCell = this; //Arena.instance.BankBalance -= b.Data.Price; //FrameworkElement fe = new FrameworkElement(); } if ((PTD as BeamTowerData) != null) { BeamTower pt = new BeamTower(); pt.Data = (PTD as BeamTowerData); object tf = System.Windows.Markup.XamlReader.Parse(pt.Data.XAML, parserContext); FrameworkElement tb = tf as FrameworkElement; if (tb != null) { Shape bb = LogicalTreeHelper.FindLogicalNode(tb, "_Barrel") as Shape; pt.Barrel = bb; Shape bc = LogicalTreeHelper.FindLogicalNode(tb, "_Body") as Shape; pt.Body = bc; tb.SetValue(Canvas.TopProperty, this.GetValue(Canvas.TopProperty)); tb.SetValue(Canvas.LeftProperty, this.GetValue(Canvas.LeftProperty)); pt.SetValue(Canvas.TopProperty, this.GetValue(Canvas.TopProperty)); pt.SetValue(Canvas.LeftProperty, this.GetValue(Canvas.LeftProperty)); pt.VisualObject = tb; Arena.instance.AddToArena(tb); Arena.instance.AddToArena(pt); pt.OwningCell = this; this.Occupant = pt; this.Occupied = true; //Arena.instance.Children.Add(pt); //Arena.instance.Children.Add(tb); } //b.OwningCell = this; //Arena.instance.BankBalance -= b.Data.Price; //FrameworkElement fe = new FrameworkElement(); } //TowerData // // MessageBox.Show((lbi.Tag as System.Xml.XPath.XPathItem).Value); /* * switch (Window1.instance.Towers.SelectedIndex) * { * case 0: * b = new ShortProjectileTower(); * * break; * case 1: * * b = new MediumProjectileTower(); * break; * case 2: * b = new LongProjectileTower(); * break; * default: * Occupied = false; * break; * * } */ if (b != null) { if (Arena.instance.BankBalance >= b.Data.Price) { b.SetValue(Canvas.TopProperty, this.GetValue(Canvas.TopProperty)); b.SetValue(Canvas.LeftProperty, this.GetValue(Canvas.LeftProperty)); b.OwningCell = this; Arena.instance.Children.Add(b); Arena.instance.BankBalance -= b.Data.Price; Occupant = b; } else { Occupied = false; } } //Occupied = true; } // else { // Occupied = false; } foreach (EmptyCell C in Adjacent) { if (Arena.instance.PathInvaliation.Contains(C) == false) { Arena.instance.PathInvaliation.Enqueue(C); } } //Arena.instance.DrawTrack(); //Arena.instance.FindPath(); }
public HeatTowerData SubClassData;// = new ProjectileTowerData(); // public TargetLock Target = new TargetLock(); // public Creep CurrentTarget; // public Shape Barrel; // public float RefireCount = 0; // static Random R = new Random(); // System.Windows.Media.Color ProjectileColor = Colors.Transparent; public new void Tick(int Frame) { if (this.SubClassData == null) { if (this.Data == null) { return; } SubClassData = Data as HeatTowerData; } //Shape bb = LogicalTreeHelper.FindLogicalNode(VisualObject, "_Grill") as Shape; //Body.Fill = new System.Windows.Media.VisualBrush(this); //System.Windows.Media.Color bc = Color.FromScRgb(1f, (float)(Heat / Data.ShutdownHeat), 0f, 0f); //Body.Fill = new System.Windows.Media.SolidColorBrush(bc); List <Tower> HotNeighbor = new List <Tower>(); float TotalNeighborHeat = 0; float startingheat = this.Heat; float HottestNeighborHeat = 0; //Make of list of neighbors who's heat level is higher than self. foreach (EmptyCell C in this.OwningCell.Adjacent) { Tower CT = C.Occupant as Tower; if (CT != null) { if (CT.Heat / CT.Data.ShutdownHeat > startingheat / Data.ShutdownHeat) { HotNeighbor.Add(CT); TotalNeighborHeat += (CT.Heat - startingheat); HottestNeighborHeat = Math.Max(HottestNeighborHeat, CT.Heat); } } } if (HotNeighbor.Count > 0 && TotalNeighborHeat > 1) { float RemainingHeatAbsorb = SubClassData.HeatAbsorb; // if self is close to overheating, don't take more heat than capacity, and never get hotter than hottest neighbor. float ModifiedHeatLimit = Math.Min(this.Data.ShutdownHeat, HottestNeighborHeat); if (RemainingHeatAbsorb + startingheat > ModifiedHeatLimit) { RemainingHeatAbsorb = ModifiedHeatLimit - startingheat; } //ModifiedHeatAbsorb = SubClassData.HeatAbsorb / HotNeighbor.Count; foreach (Tower HN in HotNeighbor) { float SplitHeatAbsorb; float HeatDiff = (HN.Heat - startingheat); //figure this neighors 'share' of heat absorbtion. SplitHeatAbsorb = (HeatDiff / TotalNeighborHeat) * RemainingHeatAbsorb; //Take no more than half the heat differance. if (HeatDiff < SplitHeatAbsorb * 2) { //float s = (this.Heat +CT.Heat) this.Heat += HeatDiff / 2; HN.Heat -= HeatDiff / 2; } else { this.Heat += SplitHeatAbsorb; HN.Heat -= SplitHeatAbsorb; } } } //Body.Fill = new System.Windows.Media.SolidColorBrush(HeatColor(Heat, Data.ShutdownHeat)); Body.Fill = StaticHelpers.HeatBrush(Heat, Data.ShutdownHeat); base.Tick(Frame); }