public static Sequence GetSequence() { var UsePots = new BehaviorAction( () => { var pot = Player.InventoryItems.FirstOrDefault(i => i.Id == ItemId.Health_Potion); if (pot == null) { return(BehaviorState.Success); } Player.Spellbook.CastSpell(pot.SpellSlot); return(BehaviorState.Failure); }); var UnderTurret = new Sequence( new Inverter(Utils.NotSafeUnderEnemyTurret(_nearestTurret)), new Inverter(Utils.IsDead()), new Inverter(Utils.IsPlayerRecalling()), Utils.StopOrbwalker()); var CastRecall = new BehaviorAction( () => Player.Spellbook.CastSpell(SpellSlot.Recall) ? BehaviorState.Success : BehaviorState.Failure); RecallSequence = new Sequence(PrepareRecall, CastRecall); // add move away from enemy var NormalRecallLogic = new Sequence(Utils.IsLowHealth(), UsePots, Utils.IsEnemyNear(500), RecallSequence); return(new Sequence(NormalRecallLogic, RecallSequence)); }
private Selector Shoot() { BehaviorAction shoot = new BehaviorAction(aiWeapon.Shoot); Conditional targetAlive = new Conditional(aiWeapon.TargetAlive); Conditional canIShoot = new Conditional(aiWeapon.IsTargetHittable); Conditional hasCD = new Conditional(aiWeapon.HasCD); return(new Selector(new Inverter(targetAlive), hasCD, new Inverter(canIShoot), shoot)); }
private StatefulSelector Dodge() { BehaviorAction dodgeJump = new BehaviorAction(aiToTarget.DodgeJump); Conditional projectileNearby = new Conditional(projectileDetector.ProjectileNearby); Conditional isGrounded = new Conditional(aiToTarget.IsGrounded); return(new StatefulSelector(new Inverter(isGrounded), new Inverter(projectileNearby), dodgeJump)); }
//private static List<ShopItem> _currentItemList = new List<ShopItem>(); public static Sequence GetSequence() { try { _itemList = Program.ChampData.GetItemList(); // var shop = new LeagueLib.Shop(); //LeagueLib.Shop.AddList(_itemList); var CanShop = new Conditional( () => { if (!Player.InShop() && !ObjectManager.Player.IsDead) { Console.WriteLine("Cant Shop"); return(false); } Console.WriteLine("CAN SHOP"); Program.FinishedShopping = false; return(true); }); var Shop = new BehaviorAction( () => { Console.WriteLine("TICK"); // if (LeagueLib.Shop.Tick()) // { Console.WriteLine("FINISHED"); Program.FinishedShopping = true; Program.LastShop = Environment.TickCount; // } return(BehaviorState.Success); }); var Finished = new BehaviorAction( () => { if ((int)ObjectManager.Player.HealthPercentage() == 100) { Program.FinishedShopping = true; } return(BehaviorState.Success); }); var shopSequence = new Sequence(CanShop, Shop); return(shopSequence); } catch (Exception e) { Console.WriteLine(e); } return(new Sequence()); }
private void HideSelectedAttackTargets(object deselectedLoad) { var deselectedAttack = (BehaviorAction)deselectedLoad; if (deselectedAttack == currentSelectedAttack) { InternalHideAttackTargets(); currentSelectedAttack = null; } }
public FollowPath(Entity entity, Entity target, float followDistance, ECSInstance ecsInstance) { //perform all needed setup f_ThisEntity = entity; f_FollowDistance = followDistance; f_Target = target; s_EcsInstance = ecsInstance; tooClose = new Conditional(isTooClose); targetMoved = new Conditional(hasTargetMoved); pathFound = new Conditional(hasPathBeenFound); reachedCell = new Conditional(hasReachedCell); reachedTarget = new Conditional(hasReachedTarget); isNewPath = new Conditional(hasNewPath); moveToCell = new BehaviorAction(moveTowardsCell); calcPath = new BehaviorAction(calculatePath); initPathfinder = new BehaviorAction(initializePathfinder); getNextCell = new BehaviorAction(getNextPathCell); setPath = new BehaviorAction(setNewPath); getPath = new BehaviorAction(getCurrentPath); updatePosition = new BehaviorAction(updateTargetPosision); reset = new BehaviorAction(resetPathfinder); animate = new BehaviorAction(updateAnimation); Sequence pSeqA = new Sequence(initPathfinder, calcPath); Selector pSelA = new Selector(new Inverter(targetMoved), new Inverter(reachedTarget), new Inverter(reset), calcPath); //Selector pSelA = new Selector(new Inverter(targetMoved));//, new Inverter(reset), calcPath); Selector pSelB = new Selector(new Inverter(pathFound), getPath); Selector pSelC = new Selector(new Inverter(isNewPath), setPath); Selector pSelD = new Selector(new Inverter(reachedCell), getNextCell); Selector pSelE = new Selector(reachedTarget, moveToCell); //Sequence pSeqC = new Sequence(pSelE, reset, calcPath); Sequence pSeqB = new Sequence(new Inverter(tooClose), updatePosition, pSelA, pSelB, pSelC, pSelD, pSelE, animate); //setup root node, choose initialization phase or pathing/movement phase root = new IndexSelector(switchBehaviors, pSeqA, pSeqB); f_Behavior = new Behavior(root); f_PositionMapper = new ComponentMapper(new Position(), ecsInstance); f_VelocityMapper = new ComponentMapper(new Velocity(), ecsInstance); f_HeadingMapper = new ComponentMapper(new Heading(), ecsInstance); f_GameMapMapper = new ComponentMapper(new GameMap(), ecsInstance); f_ViewPortMapper = new ComponentMapper(new ViewPort(), ecsInstance); f_MapDebugMapper = new ComponentMapper(new MapDebug(), ecsInstance); f_SpatialMapper = new ComponentMapper(new SpatialPartition(), ecsInstance); f_SpriteMapper = new ComponentMapper(new Sprite(), ecsInstance); f_PathMapper = new ComponentMapper(new APath(), ecsInstance); }
private void PrepareEncounterToResolve(BehaviorAction attack, UnitBasicProperties originalTarget) { var sourcePosition = positions.FirstOrDefault(p => p.HasActiveUnit()); var targetPosition = positions.FirstOrDefault(p => p.HasUnit(originalTarget.gameObject)); var encounter = new Encounter(attack, currentUnit, originalTarget); UnregisterPositionClicked(); EventManager.RaiseEvent(ObjectEventType.EncounterToResolve, encounter); EventManager.StartListening(ObjectEventType.EncountersResolved, CheckUnitStatusAfterEncounter); }
private StatefulSequence CalculatePath(System.Func <BehaviorReturnCode> calcPathStratigie) { BehaviorAction updateMemory = new BehaviorAction(aiToTarget.UpdateMemory); BehaviorAction calculatePath = new BehaviorAction(calcPathStratigie); BehaviorAction updateMemoryAdditional = new BehaviorAction(aiToTarget.UpdateMemoryWithAdditionalRange); StatefulSequence calcNewPath = new StatefulSequence(updateMemoryAdditional, calculatePath); StatefulSelector calculatePathSecure = new StatefulSelector(calculatePath, calcNewPath); return(new StatefulSequence(updateMemory, calculatePathSecure)); }
private Sequence AggressiveAI() { BehaviorAction stop = new BehaviorAction(aiToTarget.Stop); Sequence sequenceShootWhileMove = new Sequence(Shoot(), DoTransitionBehavior()); RepeatUntilFail followPathLoop = new RepeatUntilFail(sequenceShootWhileMove); RepeatUntilFail stopLoop = new RepeatUntilFail(stop); IndexSelector minDistance = new IndexSelector(MinDistanceReached, stopLoop, followPathLoop); return(new Sequence(Shoot(), new StatefulSequence(CalculatePath(aiToTarget.CalculatePath), minDistance))); }
private void CheckUnitStatusAfterEncounter(object _) { EventManager.StopListening(ObjectEventType.EncountersResolved, CheckUnitStatusAfterEncounter); RegisterPositionClicked(); var currentAttack = currentSelectedAttack; currentUnitHasAttacked = true; currentSelectedAttack = null; InternalHideAttackTargets(); EventManager.RaiseEvent(ObjectEventType.AttackApplied, currentAttack); CheckUnitsAlive(); }
public void selector_1() { _log.enterScope(); UtilityVector vector = new UtilityVector(0, 1, 0, 2); BehaviorAction action = new BehaviorAction(delegate() { return(BehaviorReturnCode.Success); }); UtilityPair pair = new UtilityPair(vector, action); UtilitySelector sel = new UtilitySelector(delegate(){ return(new UtilityVector(0, 1, 1, 2)); }, pair, pair); BehaviorReturnCode result = sel.Behave(); Verify.VerifyNotEquals("basic vector compare", true, result, BehaviorReturnCode.Failure); _log.exitScope(); }
private void OnSpeechRecognitionAndSentimentProcessed(object sender, SpeechRecognitionAndSentimentResult e) { if (this.currentRecommendation != null) { string alternativeUrl = null; // See if there is an alternative result based on keywords in the spoken text if (this.currentRecommendation.SpeechKeywordBehavior != null) { BehaviorAction behaviorAction = this.currentRecommendation.SpeechKeywordBehavior.FirstOrDefault(behavior => e.SpeechRecognitionText.IndexOf(behavior.Key, StringComparison.OrdinalIgnoreCase) != -1); if (behaviorAction != null) { alternativeUrl = behaviorAction.Url; } } // If we didn't find an alternative based on keywords see if we have a generic one based on the sentiment of the spoken text if (string.IsNullOrEmpty(alternativeUrl) && this.currentRecommendation.SpeechSentimentBehavior != null) { BehaviorAction behaviorAction = null; if (e.TextAnalysisSentiment <= 0.33) { // look for an override for negative sentiment behaviorAction = this.currentRecommendation.SpeechSentimentBehavior.FirstOrDefault(behavior => string.Compare(behavior.Key, "Negative", true) == 0); } else if (e.TextAnalysisSentiment >= 0.66) { // look for an override for positive sentiment behaviorAction = this.currentRecommendation.SpeechSentimentBehavior.FirstOrDefault(behavior => string.Compare(behavior.Key, "Positive", true) == 0); } if (behaviorAction != null) { alternativeUrl = behaviorAction.Url; } } if (!string.IsNullOrEmpty(alternativeUrl)) { webView.Navigate(new Uri(alternativeUrl)); } } }
public void SetupTile(BehaviorAction action, UnitBasicProperties properties, AttackSide side) { action.Side = side; if (action is AttackAction) { attack = (AttackAction)action; } else if (action is MovementAction) { movement = (MovementAction)action; } UnitProperties = properties; IsSelected = false; IsDisabled = false; SetupAttack(); }
private StatefulSequence DoTransitionBehavior() { BehaviorAction move = new BehaviorAction(aiToTarget.Move); Conditional stopped = new Conditional(aiToTarget.StoppedCheck); BehaviorAction fail = new BehaviorAction(ReturnFail); BehaviorAction respawn = new BehaviorAction(aiToTarget.Respawn); BehaviorAction die = new BehaviorAction(Die); BehaviorAction nextTransition = new BehaviorAction(aiToTarget.NextTransition); BehaviorAction waitForGrounded = new BehaviorAction(ReturnRunning); Sequence stopOrMove = new Sequence(new Inverter(stopped), move); StatefulSelector fallingBehavior = new StatefulSelector(respawn, die); IndexSelector fallingOrStanding = new IndexSelector(FallOrStandSelect, fail, fallingBehavior, waitForGrounded); StatefulSelector moveSelect = new StatefulSelector(stopOrMove, fallingOrStanding); return(new StatefulSequence(nextTransition, moveSelect)); }
// Use this for initialization void Start() { Memory = new BlackBoard(); Memory.Set <GameObject>("Player", GameObject.FindGameObjectWithTag("Player")); Conditional playerClose = new Conditional(isCloseToPlayer); Conditional playerMoving = new Conditional(isPlayerMoving); BehaviorAction MoveToPlayer = new BehaviorAction(moveToPlayer); BehaviorAction WanderAroundPlayer = new BehaviorAction(wanderAroundPlayer); Selector stayCloseToPlayer = new Selector( new Sequence( new Inverter(playerClose), playerMoving, MoveToPlayer ), WanderAroundPlayer ); behaviour = new BehaviorLibrary.Behavior(stayCloseToPlayer); }
private void SetLeftAttack(BehaviorAction action, UnitBasicProperties unitProperties, int index) { if (index == 0) { LeftAttack1.gameObject.SetActive(true); LeftAttack1.Reset(); LeftAttack1.SetupTile(action, unitProperties, AttackSide.Left); existing.Add(LeftAttack1); } else if (index == 1) { LeftAttack2.gameObject.SetActive(true); LeftAttack2.Reset(); LeftAttack2.SetupTile(action, unitProperties, AttackSide.Left); existing.Add(LeftAttack2); } else if (index == 2) { LeftAttack3.gameObject.SetActive(true); LeftAttack3.Reset(); LeftAttack3.SetupTile(action, unitProperties, AttackSide.Left); existing.Add(LeftAttack3); } }
// Use this for initialization void Start () { Memory = new BlackBoard(); Memory.Set<GameObject>("Player", GameObject.FindGameObjectWithTag("Player")); Conditional playerClose = new Conditional(isCloseToPlayer); Conditional playerMoving = new Conditional(isPlayerMoving); BehaviorAction MoveToPlayer = new BehaviorAction(moveToPlayer); BehaviorAction WanderAroundPlayer = new BehaviorAction(wanderAroundPlayer); Selector stayCloseToPlayer = new Selector( new Sequence( new Inverter(playerClose), playerMoving, MoveToPlayer ), WanderAroundPlayer ); behaviour = new BehaviorLibrary.Behavior(stayCloseToPlayer); }
/// <summary> /// Update and execute the action until updater tells to stop. /// /// Updater must return: Running in order to execute action; Failure in order to stop (and nothing else); /// Action must return: Running in order to keep running; Success in order to executer updater; and Failure to stop. /// /// </summary> /// <param name="updater"></param> /// <param name="action"></param> public ConditionalRepeater(BehaviorAction updater, BehaviorAction action) { this._Updater = updater; this._Action = action; }
public LeafNode(BehaviorTreeBlueprint <T> blueprint, int selfIndex, BehaviorAction <T> action) : base(blueprint, selfIndex) => this.action = action;
public ConditionerNode(BehaviorTreeBlueprint <T> blueprint, int selfIndex, BehaviorAction <T> condition) : base(blueprint, selfIndex) => this.condition = condition;
private void ShowSelectedAttackTargets(object attackObject) { currentSelectedAttack = (BehaviorAction)attackObject; ShowAvailableAttackTargets(attackObject); }
public Leaf(BehaviorAction <T> action) => this.action = action;
public Conditioner(BehaviorAction <T> condition) => this.condition = condition;
public static void Soraka() { try { var sequence = new[] { 1, 2, 3, 2, 2, 4, 2, 1, 2, 3, 4, 3, 3, 1, 1, 4, 1, 3 }; var items = new List <ItemId> { ItemId.Ancient_Coin, ItemId.Health_Potion, ItemId.Health_Potion, ItemId.Health_Potion, // ItemId.Warding_Totem_Trinket, ItemId.Nomads_Medallion, ItemId.Chalice_of_Harmony, ItemId.Boots_of_Speed, ItemId.Athenes_Unholy_Grail, ItemId.Ionian_Boots_of_Lucidity, ItemId.Rylais_Crystal_Scepter, ItemId.Haunting_Guise, ItemId.Liandrys_Torment }; #region Menu var menu = new Menu("Spells", "Spells"); //Q menu.AddItem(new MenuItem("QEnabled", "Use Q").SetValue(true)); //W menu.AddItem(new MenuItem("WEnabled", "Use W").SetValue(true)); menu.AddItem(new MenuItem("WMinAllyHP", "W Ally Min HP %").SetValue(new Slider(30, 0, 90))); //E menu.AddItem(new MenuItem("EEnabled", "Use E").SetValue(true)); //R menu.AddItem(new MenuItem("REnabled", "Use R").SetValue(true)); menu.AddItem(new MenuItem("RSelf", "R on Self").SetValue(true)); menu.AddItem(new MenuItem("RMinHP", "R Ally Min HP %").SetValue(new Slider(30, 0, 50))); menu.AddItem(new MenuItem("RMode", "R Mode").SetValue(new StringList(new[] { "R All", "R Near" }))); menu.AddItem(new MenuItem("RDistance", "R Near Distance").SetValue(new Slider(1500, 1000, 10000))); #endregion #region Spells SpellDictionary.Add(SpellSlot.Q, new Spell(SpellSlot.Q, 975)); SpellDictionary.Add(SpellSlot.W, new Spell(SpellSlot.W, 550)); SpellDictionary.Add(SpellSlot.E, new Spell(SpellSlot.E, 925)); SpellDictionary.Add(SpellSlot.R, new Spell(SpellSlot.R)); SpellDictionary[SpellSlot.Q].SetSkillshot(0.5f, 300, 1750, false, SkillshotType.SkillshotCircle); SpellDictionary[SpellSlot.E].SetSkillshot(0.5f, 70f, 1750, false, SkillshotType.SkillshotCircle); #region Q var qGetTarget = new BehaviorAction( () => { SelectedSpell = SpellDictionary[SpellSlot.Q]; SpellTarget = TargetSelector.GetTarget(SelectedSpell.Range, TargetSelector.DamageType.Magical); return(BehaviorState.Success); }); var qCheckTarget = new Conditional(() => SpellTarget.IsValidTarget(SelectedSpell.Range)); var qCast = new BehaviorAction( () => { SelectedSpell.Cast(SpellTarget); return(BehaviorState.Success); }); var qLogic = new Sequence(SpellSlot.Q.IsReady(), qGetTarget, qCheckTarget, qCast); #endregion #region W var wGetTarget = new BehaviorAction( () => { SelectedSpell = SpellDictionary[SpellSlot.W]; var minHP = Program.Menu.SubMenu("Spells").Item("WMinAllyHP").GetValue <Slider>().Value; SpellTarget = Program.Allies.FirstOrDefault( h => h.Distance(Player) < SelectedSpell.Range + 200 && h.HealthPercentage() <= minHP); return(BehaviorState.Success); }); var wCheckTarget = new Conditional(() => SpellTarget.IsValidTarget(SelectedSpell.Range + 200, false)); var wCast = new BehaviorAction( () => { SelectedSpell.Cast(SpellTarget); return(BehaviorState.Success); }); var wLogic = new Sequence(SpellSlot.W.IsReady(), wGetTarget, wCheckTarget, wCast); #endregion #region E var eGetTarget = new BehaviorAction( () => { SelectedSpell = SpellDictionary[SpellSlot.E]; SpellTarget = TargetSelector.GetTarget(SelectedSpell.Range, TargetSelector.DamageType.Magical); return(BehaviorState.Success); }); var eCheckTarget = new Conditional(() => SpellTarget.IsValidTarget(SelectedSpell.Range)); var eCast = new BehaviorAction( () => { SelectedSpell.Cast(SpellTarget); return(BehaviorState.Success); }); var eLogic = new Sequence(SpellSlot.E.IsReady(), eGetTarget, eCheckTarget, eCast); #endregion #region R var rGetTarget = new BehaviorAction( () => { SelectedSpell = SpellDictionary[SpellSlot.R]; var minHP = Program.Menu.SubMenu("Spells").Item("RMinHP").GetValue <Slider>().Value; var maxD = Program.Menu.SubMenu("Spells").Item("RDistance").GetValue <Slider>().Value; SpellTarget = Program.Allies.FirstOrDefault( h => h.Distance(Player) < maxD && h.HealthPercentage() <= minHP); return(BehaviorState.Success); }); var rCheckTarget = new Conditional(() => SpellTarget.IsValidTarget(float.MaxValue, false)); var rCast = new BehaviorAction( () => { SelectedSpell.Cast(SpellTarget); return(BehaviorState.Success); }); var rLogic = new Sequence(SpellSlot.R.IsReady(), rGetTarget, rCheckTarget, rCast); #endregion var spellLogic = new List <Sequence> { rLogic, wLogic, eLogic, qLogic }; #endregion SupportedChampions.Add("Soraka", new ChampionData(menu, spellLogic, items, sequence)); } catch (Exception e) { Console.WriteLine(e); } }
public WanderingEnemyBehavior(Entity entity, ECSInstance ecsInstance) { w_ECSInstance = ecsInstance; w_ThisEntity = entity; w_CurrentState = STATE_INITIALIZE; //setup all conditionals tooClose = new Conditional(tooCloseToTarget); tooFar = new Conditional(tooFarFromTarget); detectedHostile = new Conditional(hasDetectedHostile); collided = new Conditional(hasCollided); healthy = new Conditional(isHealthy); targetDead = new Conditional(isTargetDead); //setup all behavior actions init = new BehaviorAction(initialize); setStateWander = new BehaviorAction(stateChangeWander); setStatePursue = new BehaviorAction(stateChangePursue); setStateFlee = new BehaviorAction(stateChangeFlee); choseDirection = new BehaviorAction(chooseRandomDirection); collideCorrection = new BehaviorAction(correctHeadingForCollision); move = new BehaviorAction(moveViaHeading); towardsHeading = new BehaviorAction(headingTowardsTarget); awayHeading = new BehaviorAction(headingAwayTarget); fireShot = new BehaviorAction(fireAtTarget); animate = new BehaviorAction(updateAnimation); playDetected = new BehaviorAction(playDetectedSound); playFlee = new BehaviorAction(playFleeSound); Sequence setPursue = new Sequence(playDetected, setStatePursue); Sequence setFlee = new Sequence(playFlee, setStateFlee); //initialize sequence Sequence initSeq = new Sequence(init, setStateWander); //if not healthy, flee Selector healthSel = new Selector(healthy, new Inverter(setFlee)); //if target is dead, wander Selector deadTargetSel = new Selector(new Inverter(targetDead), setStateWander); //if not collided, then chose a new direction every second Sequence randWalk = new Sequence(new Inverter(collided), new BehaviorLib.Components.Decorators.Timer(elapsedTime, 500, choseDirection)); //if not randomly walking, correct for a collision Selector walkOrCorrect = new Selector(randWalk, collideCorrection); //wander sequence, while no hostiles detected, walk around randomly Sequence wanderSeq = new Sequence(new Inverter(new BehaviorLib.Components.Decorators.Timer(elapsedTime, 250, detectedHostile)), walkOrCorrect, move, animate); //Sequence wanderSeq = new Sequence(new Inverter(detectedHostile), walkOrCorrect, move, animate); //wander or change to pursue state88 Selector wanderSel2 = new Selector(wanderSeq, new Inverter(setPursue)); //move towards your target Sequence moveTowards = new Sequence(towardsHeading, move, animate); //move away from your target Sequence moveAway = new Sequence(new BehaviorLib.Components.Decorators.Timer(elapsedTime, 250, awayHeading), move, animate); //if too far from your target, move towards it Selector moveTooFar = new Selector(new Inverter(tooFar), moveTowards); //if too close to your target, move away from it Selector moveTooClose = new Selector(new Inverter(tooClose), moveAway); //if target isnt dead and you're not too far and not too close, shoot at it Sequence attackSeq = new Sequence(deadTargetSel, new Inverter(tooFar), new Inverter(tooClose), new BehaviorLib.Components.Decorators.Timer(elapsedTime, 500, fireShot), animate); //move towards or away from your target, then attemp to attack it Sequence pursAttackSeq1 = new Sequence(moveTooFar, moveTooClose, attackSeq); //as long as your healthy, pursue and attack your target Sequence pursAttackSeq2 = new Sequence(healthSel, pursAttackSeq1); //flee sequence, while unhealthy, flee Sequence fleeSeq = new Sequence(new Inverter(healthy), deadTargetSel, new BehaviorLib.Components.Decorators.Timer(elapsedTime, 250, awayHeading), move, animate); Selector fleeSel = new Selector(fleeSeq, setStateWander); //setup root selector w_Root = new IndexSelector(switchBehaviors, initSeq, wanderSel2, pursAttackSeq2, fleeSel); //set tree reference w_Behavior = new Behavior(w_Root); //initialize mappers w_PositionMapper = new ComponentMapper(new Position(), ecsInstance); w_VelocityMapper = new ComponentMapper(new Velocity(), ecsInstance); w_HeadingMapper = new ComponentMapper(new Heading(), ecsInstance); w_ColidableMapper = new ComponentMapper(new MapCollidable(), ecsInstance); w_ViewPortMapper = new ComponentMapper(new ViewPort(), ecsInstance); w_SpatialMapper = new ComponentMapper(new SpatialPartition(), ecsInstance); //w_SpriteMapper = new ComponentMapper(new Sprite(), ecsInstance); w_FactionMapper = new ComponentMapper(new Factions(), ecsInstance); w_HealthMapper = new ComponentMapper(new Health(), ecsInstance); w_EquipmentMapper = new ComponentMapper(new Equipment(), ecsInstance); w_ItemMapper = new ComponentMapper(new Item(), ecsInstance); w_AggroMapper = new ComponentMapper(new Aggrivation(), ecsInstance); }
public void selector_3() { _log.enterScope(); //build vectors UtilityVector a = new UtilityVector(0, 1, 0, 1); UtilityVector b = new UtilityVector(1, 1, 0, 0); UtilityVector c = new UtilityVector(1, 0, 1, 0); UtilityVector d = new UtilityVector(0, 0, 1, 1); string choice = ""; //build actions that change choice if called BehaviorAction aa = new BehaviorAction(delegate() { choice = "a"; return(BehaviorReturnCode.Success); }); BehaviorAction ba = new BehaviorAction(delegate() { choice = "b"; return(BehaviorReturnCode.Success); }); BehaviorAction ca = new BehaviorAction(delegate() { choice = "c"; return(BehaviorReturnCode.Success); }); BehaviorAction da = new BehaviorAction(delegate() { choice = "d"; return(BehaviorReturnCode.Success); }); //build the appropraite pairs UtilityPair ap = new UtilityPair(a, aa); UtilityPair bp = new UtilityPair(b, ba); UtilityPair cp = new UtilityPair(c, ca); UtilityPair dp = new UtilityPair(d, da); //execute tests UtilitySelector sel = new UtilitySelector(delegate() { return(new UtilityVector(0.5f, 0.7f, 0.4f, 0.8f)); }, ap, bp, cp, dp); sel.Behave(); Verify.VerifyTrue("a chosen", true, choice == "a"); sel = new UtilitySelector(delegate() { return(new UtilityVector(0.7f, 0.8f, 0.5f, 0.4f)); }, ap, bp, cp, dp); sel.Behave(); Verify.VerifyTrue("b chosen", true, choice == "b"); sel = new UtilitySelector(delegate() { return(new UtilityVector(0.7f, 0.5f, 0.8f, 0.4f)); }, ap, bp, cp, dp); sel.Behave(); Verify.VerifyTrue("c chosen", true, choice == "c"); sel = new UtilitySelector(delegate() { return(new UtilityVector(0.5f, 0.4f, 0.7f, 0.8f)); }, ap, bp, cp, dp); sel.Behave(); Verify.VerifyTrue("d chosen", true, choice == "d"); _log.exitScope(); }
public static Sequence GetSequence() { try { var PreWalk = new BehaviorAction(() => Player.IsDead ? BehaviorState.Failure : BehaviorState.Success); var GetTarget = new BehaviorAction( () => { // Console.WriteLine("GetTarget"); //FollowTarget = Program.Allies.FirstOrDefault(x => !Program.IsBadFollowTarget(x)); FollowTarget = TargetPriority.GetPriorityHero(); return(FollowTarget.IsValidTarget(float.MaxValue, false) ? BehaviorState.Success : BehaviorState.Failure); }); //recall logic var FollowRecallLogic = new Inverter(new Sequence(FollowTarget.IsPlayerRecalling(), new Inverter(Utils.IsEnemyNear(500)), Recalling.RecallSequence)); // don't move to follow when you are already moving to it var IsOTW = new Conditional( () => Player.GetWaypoints().Count > 3 && Player.GetWaypoints().Last().Distance(FollowTarget.Position) < 200); //if follow target is recalling do somethign else var SetOrbwalkerMode = new BehaviorAction( () => { // Console.WriteLine("SETMODE"); Orbwalking.OrbwalkingMode.Combo.SetOrbwalkingMode(); return(BehaviorState.Success); }); var GetFollowPosition = new BehaviorAction( () => { // Console.WriteLine("GetFollowPosition"); // if follow unit is headed towards (and within x range of ) enemy decrease this range var pos = FollowTarget.ServerPosition.To2D(); if (FollowTarget.GetWaypoints().Count > 1) { var rng = new Random(Environment.TickCount); var rnd = rng.Next(100); if (rnd % 3 == 0) { pos = FollowTarget.GetWaypoints().Last(); } else if (rnd % 2 == 0) { pos = FollowTarget.GetWaypoints()[2]; } } //var pos = FollowTarget.GetWaypoints().Count > 1 ? FollowTarget.GetWaypoints().Last() : FollowTarget.Position.To2D(); var c = new Geometry.Circle(pos, 500); var c2 = new Geometry.Circle(pos, 300); c.ToPolygon().Draw(Color.Red, 2); c2.ToPolygon().Draw(Color.Blue, 2); var poly = Geometry.ClipPolygons(new List <Geometry.Polygon> { c.ToPolygon(), c2.ToPolygon() }); var ran = new Random(); FollowPosition = poly.GetRandomPoint(LastMovePosition, ran.Next(50, 70), ran.Next(100, 200)); return(FollowPosition == Vector3.Zero ? BehaviorState.Failure : BehaviorState.Success); }); //new Inverter(IsOTW), //Utils.IsPlayerFullHealth()), var Follow = new BehaviorAction( () => { Console.WriteLine("FOLLOW"); FollowPosition.SetOrbwalkingPoint(); return(BehaviorState.Success); }); var NeedRandom = new Conditional(() => Orbwalking.GetLastMoveTime() > 300); var RandomWalk = new BehaviorAction( () => { ObjectManager.Player.IssueOrder(GameObjectOrder.MoveTo, Player.Position.Randomize(50, 100)); return(BehaviorState.Success); }); var RandomSequence = new Selector(NeedRandom, RandomWalk); var FollowSequence = new Sequence(GetTarget, SetOrbwalkerMode, GetFollowPosition, Follow); return(new Sequence(PreWalk, FollowRecallLogic, FollowSequence)); //, RandomSequence)); } catch (Exception e) { Console.WriteLine(e); } //PreWalk, return(new Sequence()); // IsOTW, //Utils.Dead() // ShouldFollow, //atfountain //, RandomLogic)); }
public Encounter(BehaviorAction action, UnitBasicProperties attacker, UnitBasicProperties defender) { Action = action; Attacker = attacker; Defender = defender; }