private void ListViewActions_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { if (ListViewActions.SelectedIndex >= 0) { CurrentActions?.Clear(); Sim.RemoveActionAt(ListViewActions.SelectedIndex); } }
private void AddAction(Type type, Action <ImageAction> initializer = null) { var action = (ImageAction)Activator.CreateInstance(type); action.EventAggregator = _ea; action.IsEditMode = true; action.HasChanged = true; initializer?.Invoke(action); CurrentActions.Add(action); _ea.GetEvent <OperateOnImageEvent>().Publish(this.CurrentActions); }
private IEnumerable <Wait> RoutineTakeTurn(Turn turn) { FindAggroTarget(); if (AggroTarget != null) { FaceTowards(AggroTarget); } Skill usableSkill = GetUsableSkill(); foreach (Skill skill in Skills) { skill.Update(this); } if (usableSkill != null) { var target = usableSkill.GetEnemyTarget(this); CurrentActions.Add(Scheduler.Instance.RunAndWait(RoutineUseSkill(usableSkill, target))); if (usableSkill.WaitUse) { yield return(CurrentActions); } } else { var move = new[] { Facing.North, Facing.East, Facing.South, Facing.West }.Pick(Random).ToOffset(); if (AggroTarget != null) { var movementType = this.GetMovementType(); var costMap = new CostMap(Map, this, movementType.GetTileCost); costMap.SetMask(Mask); costMap.Recalculate(); var targetPoints = Mask.Select(o => new Point(AggroTarget.X, AggroTarget.Y) - o).ToList(); var dijkstra = Util.Dijkstra(new Point[] { new Point(X, Y) }, targetPoints, Map.Width, Map.Height, new Rectangle(X - 20, Y - 20, 41, 41), double.MaxValue, costMap, movementType.GetNeighbors()); var path = dijkstra.FindPath(targetPoints.Pick(Random)); if (path.Any()) { move = path.First() - new Point(X, Y); } else { move = new Point(0, 0); } } if (move != Point.Zero) //No move to self { CurrentActions.Add(Scheduler.Instance.RunAndWait(RoutineMove(move.X, move.Y))); } } }
private void Sim_FinishedExecution(CraftingSim sim) { Dispatcher.Invoke(() => { if (ListViewActions.ItemsSource != null) { var list = (ListViewActions.ItemsSource as List <CraftingActionContainer>); for (int i = 0; i < list.Count; i++) { list[i].Dispose(); } } if (Sim.CraftingActionsLength > 0) { for (int i = 0; i < CurrentActions.Count; i++) { CurrentActions[i].Update(); } } else { CurrentActions.Clear(); } ListViewActions.ItemsSource = CurrentActions.ToList(); if (ListViewCraftingBuffs.ItemsSource != null) { var list = (ListViewCraftingBuffs.ItemsSource as List <CraftingBuffContainer>); for (int i = 0; i < list.Count; i++) { list[i].Source = null; } } ListViewCraftingBuffs.ItemsSource = sim.CraftingBuffs.Select(x => new CraftingBuffContainer(G.Actions[x.Name].Images[sim.CurrentRecipe.ClassJob], x)).ToList(); if (AvailableActions != null) { for (int i = 0; i < AvailableActions.Length; i++) { AvailableActions[i].Update(); } } LabelScore.Content = "Score: " + Sim.Score.ToString("#.###"); }); }
private bool ApplyActionInternal(SettlerPivot settler, MapSquareImprovementPivot action, bool currentApplianceValue) { if (currentApplianceValue) { return(false); } var actionInProgress = CurrentActions.SingleOrDefault(a => a.Action == action); if (actionInProgress == null) { actionInProgress = new InProgressMapSquareImprovementPivot(action); _currentActions.Add(actionInProgress); } return(actionInProgress.AddSettler(settler)); }
private void Sim_FinishedStep(CraftingSim sim, int index) { if (index == 0) { if (CurrentActions != null) { CurrentActions.ForEach(x => x.Dispose()); CurrentActions.Clear(); } CurrentActions = new List <CraftingActionContainer>(); OldProgress = 0; OldQuality = 0; } var currentAction = sim.CraftingActions[index]; CraftingActionContainer container = new CraftingActionContainer(Sim, currentAction); container.ProgressIncreased = sim.CurrentProgress - OldProgress; container.QualityIncreased = sim.CurrentQuality - OldQuality; OldProgress = sim.CurrentProgress; OldQuality = sim.CurrentQuality; CurrentActions.Add(container); }