public override ActionList GetActions(Board b, Agent a, Field dest) { var aList = new ActionList(); aList.AddAction(new Action(ActionType.Moving, a.GetField())); int i = 0; var f = a.GetField(); if (f.X != dest.X) { i++; } if (f.Y != dest.Y) { i++; } if (i == 2) { aList.AddAction(Genome.Rnd.NextDouble() > 0.5 ? new Action(ActionType.Moving, dest.GetRelative(a.GetField().X - dest.X, 0)) : new Action(ActionType.Moving, dest.GetRelative(0, a.GetField().Y - dest.Y))); } aList.AddAction(new Action(ActionType.Moving, dest)); return(aList); }
public override ActionList GetActions(Board b, Agent a) { var aList = new ActionList(); List <Field> foodFields = new List <Field>(); for (int i = -9; i < 10; i++) { int X = (int)a.GetCurrentX + i; for (int j = -9; j < 10; j++) { int Y = (int)a.GetCurrentY + j; if (b.IsValid(X, Y)) { if (b.FullBoard[X, Y].GetFood().Value >= a.GetGenome().GetStrength() * 0.25f) { foodFields.Add(b.FullBoard[X, Y]); } } } } if (foodFields.Count > 0) { Field nearestField = null; float minDist = float.MaxValue; foreach (var f in foodFields) { if (f.DistSqr(a.GetField()) < minDist) { minDist = f.DistSqr(a.GetField()); nearestField = f; } } aList.AddAction(new Action(ActionType.PickingUpFood, nearestField)); aList.AddAction(new Action(ActionType.ReturningFood, b.FullBoard[(int)a.GetVillage().VillageMain.X, (int)a.GetVillage().VillageMain.Y])); } else { int x = (int)a.GetCurrentX, y = (int)a.GetCurrentY; int i, j; do { float ang = (float)(Genome.Rnd.NextDouble() * 2 * Math.PI); i = (int)(15 * Math.Cos(ang)); j = (int)(15 * Math.Sin(ang)); } while (!b.IsValid(x + i, y + j)); aList.UnPack(a.GetGenome().GetChromosomes().Item2.GetRandomMoveFunction().GetActions(b, a, b.FullBoard[x + i, y + j]), null); } return(aList); }
public override ActionList GetActions(Board b, Agent a, Field dest) { var aList = new ActionList(); aList.AddAction(new Action(ActionType.Moving, dest)); return(aList); }
public override ActionList GetActions(Board b, Agent a) { var aList = new ActionList(); aList.AddAction(new Action(ActionType.FarmingArea, a.GetField())); return(aList); }
public void ShowCity(City city) { this.loc_city = city; m_CityName.text = city.CityName; m_CityIntroduce.text = city.Introduce; m_CityBuffIntroduce.text = city.BuffIntroduce; foreach (var item in city.CommunicationEntrys) { if (item == null) { continue; } NpcActionList.AddAction(item.ForName, () => { NpcCommunicationContorl.ShowCommunication(city, item); }); // if (item.Name == "CityCommEntry_UnitShop") // { // } } NpcActionList.AddAction("离开", () => { Leave(); }); Show(); }
public override ActionList GetActions(Board b, Agent a) { var aList = new ActionList(); List <Field> foodFields = new List <Field>(); for (int i = -5; i < 6; i++) { int X = (int)a.GetCurrentX + i; for (int j = -5; j < 6; j++) { int Y = (int)a.GetCurrentY + j; if (b.IsValid(X, Y)) { if (b.FullBoard[X, Y].GetFood().Value > 0) { foodFields.Add(b.FullBoard[X, Y]); } } } } if (foodFields.Count > 0) { aList.AddAction(new Action(ActionType.PickingUpFood, foodFields[Genome.Rnd.Next(foodFields.Count)])); aList.AddAction(new Action(ActionType.ReturningFood, b.FullBoard[(int)a.GetVillage().VillageMain.X, (int)a.GetVillage().VillageMain.Y])); } else { int x = (int)a.GetCurrentX, y = (int)a.GetCurrentY; int i, j; do { float ang = (float)(Genome.Rnd.NextDouble() * 2 * Math.PI); i = (int)(15 * Math.Cos(ang)); j = (int)(15 * Math.Sin(ang)); } while (!b.IsValid(x + i, y + j)); aList.UnPack(a.GetGenome().GetChromosomes().Item2.GetRandomMoveFunction().GetActions(b, a, b.FullBoard[x + i, y + j]), null); } return(aList); }
private void ButtonAddAction_Click(object sender, RoutedEventArgs e) { if (ActionAdd.SelectedWARecordType == null) { ActionAdd.LabelValidation.Content = "It is necessary to choose an action."; } else if (ActionList.AddAction(ActionAdd.Time, ActionAdd.SelectedWARecordType.Id, ActionAdd.SelectedWARecordType.Duration)) { _scenarioDescription.addACS(ActionAdd.SelectedWARecordType, ActionAdd.Time); ActionAdd.CleanValues(); } else { ActionAdd.LabelValidation.Content = "Two actions at the some time are forbidden."; } }
public Boolean HandleShowLinks(Boolean show = true) { ActionList actions = new ActionList(); Boolean hadMyGames = false; foreach (Game game in this.Games) { if (!game.Checked) { continue; } if (game.State != Game.SaveState.FullLink) { continue; } if (hadMyGames == false) { if (game.OriginalPath.IndexOf(this.placeholderMyGames) != -1) { hadMyGames = true; } } List<String> paths = this.GetPathsToHide(game.OriginalPath); for (int i = 0, t = paths.Count; i < t; i++) { String realPath = GamePlaceholder.ReplacePlaceholders(paths[i]); if (show) { if (DirectoryEx.IsHidden(realPath)) { actions.AddAction("show", game, paths[i]); } } else { if (!DirectoryEx.IsHidden(realPath)) { actions.AddAction("hide", game, paths[i]); } } } } if (hadMyGames) { Boolean isHidden = DirectoryEx.IsHidden(GamePlaceholder.ReplacePlaceholders(this.placeholderMyGames)); if ((show && isHidden) || (!show && !isHidden)) { actions.AddAction((show ? "show" : "hide"), this.placeholderMyGames); } } if (!this.Games.HasChecked()) { this.ShowErrorDialog("No games checked"); return false; } if (actions.Count == 0) { this.ShowErrorDialog(String.Format("No links found that need to be {0}", (show ? "shown" : "hidden"))); return false; } // Sort the actions by number of slashes (descending) so we hide sub folders first. This should prevent // the parent folders from failing to hide. actions.Sort(delegate(Action a1, Action a2) { return a2.Path.Split(Path.DirectorySeparatorChar).Length - a1.Path.Split(Path.DirectorySeparatorChar).Length; }); return this.ShowPreviewDialog(actions) == DialogResult.OK; }
public Boolean HandleMoveToStorage(Boolean create = true) { ActionList actions = new ActionList(); Boolean handledMyGames = false; foreach (Game game in this.Games) { if (game.Checked != true) { continue; } if (game.State == Game.SaveState.Missing || game.State == Game.SaveState.Conflict) { Trace.WriteLine(String.Format("{0}.HandleCreateLinks({1}) Skipping game due to save state {2}", this.GetType(), create, game.ToString())); continue; } if (create) { if (game.State == Game.SaveState.FullLink) { Trace.WriteLine(String.Format("{0}.HandleCreateLinks({1}) Skipping game due to save state {2}", this.GetType(), create, game.ToString())); continue; } if (Directory.Exists(game.OriginalPathFull)) { actions.AddAction("move-storage", game); } actions.AddAction("create-link", game); } else { if (game.State == Game.SaveState.NoLink) { Trace.WriteLine(String.Format("{0}.HandleCreateLinks({1}) Skipping game due to save state {2}", this.GetType(), create, game.ToString())); continue; } List<String> paths = this.GetPathsToHide(game.OriginalPath); if (handledMyGames == false) { if (game.OriginalPath.IndexOf(this.placeholderMyGames) != -1) { if (DirectoryEx.IsHidden(GamePlaceholder.ReplacePlaceholders(this.placeholderMyGames))) { actions.AddAction("show", game, this.placeholderMyGames); } handledMyGames = true; } } // Start at 1 since the actual save path does not need to be unhidden for (int i = 1, t = paths.Count; i < t; i++) { if (DirectoryEx.IsHidden(GamePlaceholder.ReplacePlaceholders(paths[i]))) { actions.AddAction("show", game, paths[i]); } } if (game.State == Game.SaveState.FullLink) { actions.AddAction("delete-link", game); } actions.AddAction("move-original", game); } } if (!this.Games.HasChecked()) { this.ShowErrorDialog("No games checked"); return false; } if (actions.Count == 0) { this.ShowErrorDialog(String.Format("No games found that need to be moved to {0}", (create ? "storage" : "their original location"))); return false; } return this.ShowPreviewDialog(actions) == DialogResult.OK; }
public void RegisterAction(PerformableAction pa) { actionList.AddAction(pa); }
public static void OnActivate(NPCInteraction __instance) { try { //SoroboreanTravelAgency.Instance.MyLogger.LogDebug(__instance.ActorLocKey); Character character = CharacterManager.Instance.GetCharacter(CharacterManager.Instance.PlayerCharacters.Values[0]); if (character == null) { return; } if (StoreManager.Instance.IsDlcInstalled(OTWStoreAPI.DLCs.Soroboreans)) { return; } AreaEnum areaN = (AreaEnum)AreaManager.Instance.GetAreaIndexFromSceneName(SceneManagerHelper.ActiveSceneName); if (!SoroboreanTravelAgency.StartAreaToTravel.ContainsKey(areaN)) { return; } SoroboreanTravelAgency.TravelDayCost = (int)(float)SoroboreanTravelAgency.Instance.MyConfig.GetValue("Travel Day Cost"); // 80 - 100 - 120 if (areaN == AreaEnum.Levant) // TODO: check quest "Blood under the Sun" { SoroboreanTravelAgency.TravelDayCost = (int)(SoroboreanTravelAgency.TravelDayCost * 1.75); // 140 - 175 - 210 } // TODO: HallowPeaceGuardBlock if (__instance.ActorLocKey == "name_unpc_caravantrader_01") { var graphOwner = __instance.NPCDialogue.DialogueController; var graph = (Graph)graphOwner.GetType().BaseType.GetField("_graph", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(graphOwner as GraphOwner <DialogueTreeExt>); var nodes = typeof(Graph).GetField("_nodes", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(graph as Graph) as List <Node>; var firstNode = (nodes.First(n => n.GetType().Name == "MultipleChoiceNodeExt") as MultipleChoiceNodeExt); if (SoroboreanTravelAgency.DialogIsSet) { foreach (var node in graph.allNodes.Where(n => n.tag == "SoroboreanTravelAgency").ToList()) { graph.RemoveNode(node); } firstNode.availableChoices.RemoveAll(c => c.statement.meta == "TRAVEL"); } int cnt = firstNode.availableChoices.Count - 2; firstNode.availableChoices.Insert(cnt, new MultipleChoiceNodeExt.Choice(new Statement("I want to travel, please.", GlobalAudioManager.Sounds.BGM_Empty, "TRAVEL"))); StatementNodeExt nStart = graph.AddNode <StatementNodeExt>(); nStart.tag = "SoroboreanTravelAgency"; nStart.statement = new Statement($"Where do you want to go?"); nStart.SetActorName(__instance.ActorLocKey); StatementNodeExt nResultMoneyBad = graph.AddNode <StatementNodeExt>(); nResultMoneyBad.tag = "SoroboreanTravelAgency"; nResultMoneyBad.statement = new Statement("Sorry, you don't have enough silver. Come back when you can afford it!"); nResultMoneyBad.SetActorName(__instance.ActorLocKey); StatementNodeExt nResultRationsBad = graph.AddNode <StatementNodeExt>(); nResultRationsBad.tag = "SoroboreanTravelAgency"; nResultRationsBad.statement = new Statement("Sorry, you don't have enough rations to travel this far."); nResultRationsBad.SetActorName(__instance.ActorLocKey); StatementNodeExt nCancel = graph.AddNode <StatementNodeExt>(); nCancel.tag = "SoroboreanTravelAgency"; nCancel.statement = new Statement("See you soon!"); nCancel.SetActorName(__instance.ActorLocKey); FinishNode nFinish = graph.AddNode <FinishNode>(); nFinish.tag = "SoroboreanTravelAgency"; StatementNodeExt nNoDestination = graph.AddNode <StatementNodeExt>(); nNoDestination.tag = "SoroboreanTravelAgency"; nNoDestination.statement = new Statement("Sorry, you have not discovered any other town... You can only travel to places you visited at least once!"); nNoDestination.SetActorName(__instance.ActorLocKey); bool hasEntry = false; MultipleChoiceNodeExt nChoose = graph.AddNode <MultipleChoiceNodeExt>(); nChoose.tag = "SoroboreanTravelAgency"; foreach (StrTravel travel in SoroboreanTravelAgency.StartAreaToTravel[areaN]) { //if (!QuestEventManager.Instance.HasQuestEvent(SoroboreanTravelAgency.AreaToQuestEvent[travel.TargetArea])) if (!(bool)SoroboreanTravelAgency.Instance.MyConfig.GetValue(travel.TargetArea + "Visited")) { continue; // This town has not been visited yet } hasEntry = true; string areaLabel = travel.TargetArea.ToString(); if (travel.TargetArea == AreaEnum.CierzoVillage) { areaLabel = "Cierzo"; } int rationsCost = travel.DurationDays; int moneyCost = travel.DurationDays * SoroboreanTravelAgency.TravelDayCost; string msgCost = $"{areaLabel} ({moneyCost} silver and {rationsCost} rations)."; if (travel.DurationDays == 0) { rationsCost = 0; moneyCost = SoroboreanTravelAgency.TravelDayCost; msgCost = $"{areaLabel} ({moneyCost} silver)."; } nChoose.availableChoices.Add(new MultipleChoiceNodeExt.Choice(new Statement(msgCost))); ConditionNode nCheckMoney = graph.AddNode <ConditionNode>(); nCheckMoney.tag = "SoroboreanTravelAgency"; nCheckMoney.condition = new Condition_OwnsItem() { character = character, item = new ItemReference { ItemID = 9000010 }, minAmount = moneyCost }; ConditionNode nCheckRations = graph.AddNode <ConditionNode>(); nCheckRations.tag = "SoroboreanTravelAgency"; nCheckRations.condition = new Condition_OwnsItem() { character = character, item = new ItemReference { ItemID = 4100550 }, // Travel Ration minAmount = rationsCost }; graph.ConnectNodes(nChoose, nCheckMoney); ActionNode nWishRent = graph.AddNode <ActionNode>(); nWishRent.tag = "SoroboreanTravelAgency"; ActionList actions = new ActionList(); actions.AddAction(new NodeCanvas.Tasks.Actions.PlaySound() { Sound = GlobalAudioManager.Sounds.UI_MERCHANT_CompleteTransaction }); actions.AddAction(new NodeCanvas.Tasks.Actions.FadeOut() { fadeTime = 1.0f }); actions.AddAction(new SetTravelArea() { Script = SoroboreanTravelAgency.Instance, TargetArea = travel.TargetArea }); actions.AddAction(new AreaSwitchPlayersTime() { Character = new BBParameter <Character>(character), Area = travel.TargetArea, IncreaseTime = travel.DurationDays * 24 }); actions.AddAction(new NodeCanvas.Tasks.Actions.RemoveItem() { fromCharacter = new BBParameter <Character>(character), Items = new List <BBParameter <ItemReference> >() { new ItemReference { ItemID = 9000010 }, new ItemReference { ItemID = 4100550 } }, Amount = new List <BBParameter <int> >() { new BBParameter <int>(moneyCost), new BBParameter <int>(rationsCost) }, }); nWishRent.action = actions; graph.ConnectNodes(nCheckMoney, nCheckRations); graph.ConnectNodes(nCheckMoney, nResultMoneyBad); graph.ConnectNodes(nCheckRations, nWishRent); graph.ConnectNodes(nCheckRations, nResultRationsBad); graph.ConnectNodes(nWishRent, nFinish); } if (hasEntry) { graph.ConnectNodes(firstNode, nStart, cnt); nChoose.availableChoices.Add(new MultipleChoiceNodeExt.Choice(new Statement("Changed my mind."))); graph.ConnectNodes(nStart, nChoose); graph.ConnectNodes(nChoose, nCancel); } else { graph.ConnectNodes(firstNode, nNoDestination, cnt); } graph.ConnectNodes(nResultMoneyBad, nFinish); graph.ConnectNodes(nResultRationsBad, nFinish); graph.ConnectNodes(nNoDestination, nFinish); graph.ConnectNodes(nCancel, nFinish);//*/ SoroboreanTravelAgency.DialogIsSet = true; } } catch (Exception ex) { SoroboreanTravelAgency.Instance.MyLogger.LogError(ex.Message); } }
public static void OnActivate(NPCInteraction __instance) { try { AreaEnum areaN = (AreaEnum)AreaManager.Instance.GetAreaIndexFromSceneName(SceneManagerHelper.ActiveSceneName); if (!InnRentStash.StashAreaToQuestEvent.ContainsKey(areaN) || CharacterManager.Instance.PlayerCharacters.Count == 0) { return; } Character character = CharacterManager.Instance.GetCharacter(CharacterManager.Instance.PlayerCharacters.Values[0]); if (character == null) { return; } if (__instance.ActorLocKey != InnRentStash.StashAreaToQuestEvent[areaN].NpcName) { return; } var graphOwner = __instance.NPCDialogue.DialogueController; var graph = (Graph)graphOwner.GetType().BaseType.GetField("_graph", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(graphOwner as GraphOwner <DialogueTreeExt>); var nodes = typeof(Graph).GetField("_nodes", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(graph as Graph) as List <Node>; var firstNode = nodes.First(n => n.GetType().Name == "MultipleChoiceNodeExt") as MultipleChoiceNodeExt; foreach (var node in graph.allNodes.Where(n => n.tag == "InnRentStash").ToList()) { graph.RemoveNode(node); } firstNode.availableChoices.RemoveAll(c => c.statement.meta == "RENT"); //TreeNode<Node>.DebugDialogue(nodes[0], 0); /* Un dialogue c'est: afficher un texte + action(optionnel) + choix(optionnel) * * Outil de conversion Graph --> ma structure */ firstNode.availableChoices.Insert(1, new MultipleChoiceNodeExt.Choice(new Statement("I want to rent a stash, please.", GlobalAudioManager.Sounds.BGM_Empty, "RENT"))); StatementNodeExt nStart = graph.AddNode <StatementNodeExt>(); nStart.tag = "InnRentStash"; nStart.statement = new Statement($"Of course! Renting a stash costs only {InnRentStash.Instance.ConfigRentPrice.Value} silver for one week."); nStart.SetActorName(__instance.ActorLocKey); MultipleChoiceNodeExt nChoose = graph.AddNode <MultipleChoiceNodeExt>(); nChoose.tag = "InnRentStash"; nChoose.availableChoices.Add(new MultipleChoiceNodeExt.Choice(new Statement("Sh*t up and take my money!"))); nChoose.availableChoices.Add(new MultipleChoiceNodeExt.Choice(new Statement("I will be back."))); ConditionNode nCheckMoney = graph.AddNode <ConditionNode>(); nCheckMoney.tag = "InnRentStash"; nCheckMoney.condition = new Condition_OwnsItem() { character = character, item = new ItemReference { ItemID = 9000010 }, minAmount = InnRentStash.Instance.ConfigRentPrice.Value }; ConditionNode nCheckHouse = graph.AddNode <ConditionNode>(); nCheckHouse.tag = "InnRentStash"; nCheckHouse.condition = new Condition_QuestEventOccured() { QuestEventRef = new QuestEventReference { EventUID = InnRentStash.StashAreaToQuestEvent[areaN].PlayerHouseQuestEventUID } }; StatementNodeExt nCheckHouseBad = graph.AddNode <StatementNodeExt>(); nCheckHouseBad.tag = "InnRentStash"; nCheckHouseBad.statement = new Statement("You have a house, no need to rent a stash anymore."); nCheckHouseBad.SetActorName(__instance.ActorLocKey); ConditionNode nCheckAlready = graph.AddNode <ConditionNode>(); nCheckAlready.tag = "InnRentStash"; nCheckAlready.condition = new Condition_QuestEventOccured() { QuestEventRef = new QuestEventReference { EventUID = InnRentStash.StashAreaToQuestEvent[areaN].QuestEvent.EventUID } }; StatementNodeExt nCheckAlreadyBad = graph.AddNode <StatementNodeExt>(); nCheckAlreadyBad.tag = "InnRentStash"; nCheckAlreadyBad.statement = new Statement("You've already rented a stash for the week! Just use it."); nCheckAlreadyBad.SetActorName(__instance.ActorLocKey); ActionNode nWishRent = graph.AddNode <ActionNode>(); nWishRent.tag = "InnRentStash"; ActionList action = new ActionList(); action.AddAction(new NodeCanvas.Tasks.Actions.RemoveItem() { fromCharacter = new BBParameter <Character>(character), Items = new List <BBParameter <ItemReference> >() { new ItemReference { ItemID = 9000010 } }, Amount = new List <BBParameter <int> >() { new BBParameter <int>(InnRentStash.Instance.ConfigRentPrice.Value) }, }); action.AddAction(new NodeCanvas.Tasks.Actions.SendQuestEvent() { QuestEventRef = new QuestEventReference { EventUID = InnRentStash.StashAreaToQuestEvent[areaN].QuestEvent.EventUID } }); action.AddAction(new NodeCanvas.Tasks.Actions.PlaySound() { Sound = GlobalAudioManager.Sounds.UI_MERCHANT_CompleteTransaction }); nWishRent.action = action; StatementNodeExt nResultOk = graph.AddNode <StatementNodeExt>(); nResultOk.tag = "InnRentStash"; nResultOk.statement = new Statement("Thanks, I've unlocked the stash for you."); nResultOk.SetActorName(__instance.ActorLocKey); StatementNodeExt nResultBad = graph.AddNode <StatementNodeExt>(); nResultBad.tag = "InnRentStash"; nResultBad.statement = new Statement("Sorry, you don't have enough silver. Come back when you can afford it!"); nResultBad.SetActorName(__instance.ActorLocKey); StatementNodeExt nCancel = graph.AddNode <StatementNodeExt>(); nCancel.tag = "InnRentStash"; nCancel.statement = new Statement("See you soon!"); nCancel.SetActorName(__instance.ActorLocKey); FinishNode nFinish = graph.AddNode <FinishNode>(); nFinish.tag = "InnRentStash"; graph.ConnectNodes(firstNode, nCheckHouse, 1); // Check if the player owns the house of the town graph.ConnectNodes(nCheckHouse, nCheckHouseBad); // The player owns it --> exit graph.ConnectNodes(nCheckHouse, nCheckAlready); // Check if the player has already a rent ongoing in the town graph.ConnectNodes(nCheckAlready, nCheckAlreadyBad); // The player already has the rent --> exit graph.ConnectNodes(nCheckAlready, nStart); // All checks successfull, we can show the pricefor the rent graph.ConnectNodes(nStart, nChoose); // Show the choices for the player (to rent or not) graph.ConnectNodes(nChoose, nCheckMoney); // Check if the player has enough money graph.ConnectNodes(nChoose, nCancel); // The player doesn't want to rent --> exit graph.ConnectNodes(nCheckMoney, nWishRent); // The player has enough money, go activate the rent graph.ConnectNodes(nCheckMoney, nResultBad); // The player doesn't have enough money --> exit graph.ConnectNodes(nWishRent, nResultOk); // Activate the rent! graph.ConnectNodes(nCheckHouseBad, nFinish); graph.ConnectNodes(nCheckAlreadyBad, nFinish); graph.ConnectNodes(nResultBad, nFinish); graph.ConnectNodes(nResultOk, nFinish); graph.ConnectNodes(nCancel, nFinish);//*/ } catch (Exception ex) { InnRentStash.MyLogger.LogError("OnActivate: " + ex.Message); } }