private void BotMain_OnStart(IBot bot) { if (!Service.IsConnected) { Service.Connect(); CommunicationThread.ThreadStart(); } SelectBehavior(); CurrentBehavior.Activate(); }
/// <summary> /// Update chooses a new behavior, allows that behavior to update, and then /// moves the entity forward. /// </summary> /// <param name="gameTime"></param> public void Update(GameTime gameTime) { // Use ChooseBehavior to decide what the next behavior is. this is an // abstract method that our subclasses will implement. ChooseBehavior(gameTime); if (CurrentBehavior != null) { CurrentBehavior.Update(); } Vector2 heading = new Vector2( (float)Math.Cos(Orientation), (float)Math.Sin(Orientation)); Position += heading * CurrentSpeed; Position = ClampToLevelBoundary(Position); }
public void OnDisabled() { Enabled = false; Log.Info("Plugin disabled! "); if (CurrentBehavior != null) { CurrentBehavior.Deactivate(); } BotMain.OnStart -= BotMain_OnStart; BotMain.OnStop -= BotMain_OnStop; EventManager.Disable(); EventManager.OnPulseOutOfGame += Pulse; Service.OnUpdatePreview -= ServiceOnUpdatePreview; BotHistory.Disable(); TabUi.RemoveTab(); ChangeMonitor.Disable(); }
protected override void OnUpdate(float dt) { CurrentBehavior.Execute(dt); }
public void Damage(int amount, DamageType damageType = DamageType.Generic, GameObject attacker = null) { if (dead) { return; } if (CurrentBehavior != null) { CurrentBehavior.ModifyDamage(ref amount, damageType); } if (amount <= 0) { return; } hitpoints -= amount; if (hitpoints <= 0) { moveVector = Vector3.zero; gameObject.layer = 14; //ragdoll dead = true; if (DieFrames.Length > 0) { frametime = 0f; frameindex = 0; refreshSprite = true; SetSprite(DieFrames[0]); } if (DieSounds.Length > 0) { audioSource.Stop(); audioSource.clip = DieSounds[Random.Range(0, DieSounds.Length)]; audioSource.Play(); } //change type into decoration RemoveFromGrid(); thingType = ThingType.Decor; AddToGrid(); if (dropOnDeath != null) { ThingController loot = Instantiate(dropOnDeath); loot.transform.position = transform.position + transform.forward * .1f; loot.transform.rotation = transform.rotation; loot.Init(); loot.transform.SetParent(GameManager.Instance.TemporaryObjectsHolder); } return; } if (Random.value <= PainChance) { if (painTime < .1f) { if (PainSounds.Length > 0) { audioSource.Stop(); audioSource.clip = PainSounds[Random.Range(0, PainSounds.Length)]; audioSource.Play(); } } painTime = _PainTime; if (PainFrames.Length > 0) { frameindex = 0; frametime = 0f; refreshSprite = true; SetSprite(PainFrames[0]); } } CurrentBehavior.alert = true; //alert nearby enemies, since sound won't propagate here if (attacker != null) { if (attacker.GetComponent <PlayerThing>() != null) { if (GameManager.Instance.Player[0].playerBreath.GetBreath(cell) == null) { BreathArea alarmBreath = new BreathArea(15); alarmBreath.position = cell; List <ThingController> monsters = new List <ThingController>(); AI.FillBreath(ref alarmBreath, ref monsters, true); foreach (ThingController tc in monsters) { if (tc.CurrentBehavior != null) { tc.CurrentBehavior.AlertByNoise(); } } } } } }
void Update() { if (GameManager.Paused) { return; } if (finished) { ApplySimpleGravity(); return; } Triangle sectorTriangle = TheGrid.GetExactTriangle(transform.position.x, transform.position.z); if (sectorTriangle != null) { lastSector = currentSector; if (currentSector != sectorTriangle.sector) { if (currentSector != null) { currentSector.floorObject.DynamicThings.Remove(this); } currentSector = sectorTriangle.sector; currentSector.floorObject.DynamicThings.AddLast(this); SetBrightness(currentSector.brightness); } } int cx = Mathf.FloorToInt(transform.position.x); int cy = Mathf.FloorToInt(transform.position.z); if (cx != cell.x || cy != cell.y) { RemoveFromGrid(); cell.x = cx; cell.y = cy; AddToGrid(); } /*if (dead) * { * ApplySimpleGravity(); * UpdateSpriteAnimation(); * return; * }*/ //smoother elevator movement bool sticktofloor = false; if (currentSector != null) { if (lastSector == currentSector) { if (lastFloorHeight != currentSector.floorHeight) { if (Mathf.Abs(transform.position.y - currentSector.floorHeight) <= MapLoader._4units) { sticktofloor = true; } } } if (transform.position.y < currentSector.floorHeight - 1f) { transform.position = new Vector3(transform.position.x, currentSector.floorHeight, transform.position.z); } lastFloorHeight = currentSector.floorHeight; } //fall down or hit ground if (controller.isGrounded) { gravityAccumulator = 0f; } else { gravityAccumulator += Time.deltaTime * GameManager.Instance.gravity; } //terminal velocity or in elevator if (gravityAccumulator > GameManager.Instance.terminalVelocity || sticktofloor) { gravityAccumulator = GameManager.Instance.terminalVelocity; } if (!dead) { if (painTime > 0f) { painTime -= Time.deltaTime; if (painTime <= 0) { frameindex = 0; frametime = 0f; refreshSprite = true; } CurrentBehavior.Pain(); } CurrentBehavior.Tick(); } //apply force vectors) if (controller.enabled) { Vector3 walk = transform.forward * moveVector.x * walkspeed; Vector3 gravity = Vector3.down * gravityAccumulator; controller.Move((walk + gravity + impulseVector) * Time.deltaTime); //dampen impulse if (impulseVector != Vector3.zero) { if (controller.isGrounded) { impulseVector = Vector3.Lerp(impulseVector, Vector3.zero, impulseGroundDampening * Time.deltaTime); } else { impulseVector = Vector3.Lerp(impulseVector, Vector3.zero, impulseAirDampening * Time.deltaTime); } if ((impulseVector).sqrMagnitude < .001f) { impulseVector = Vector3.zero; } } } UpdateSpriteAnimation(); }
private void BotMain_OnStop(IBot bot) { CurrentBehavior.Deactivate(); }
//private void OnProfileLoaded(object sender, EventArgs eventArgs) //{ // if (!Enabled) return; // SelectBehavior(); //} private void OnHooksCleared(object sender, EventArgs e) { // Need to activate current behavior to ensure its hooks are added before game is started. CurrentBehavior.Activate(); }
public static async Task <bool> RootLogic() { if (!CacheStaticLookUp.InitalizedCache) { CacheStaticLookUp.Update(); ObjectCacheManager.Initalize(); TargetManager.Initalize(); Movement.IgnoreTaxiCheck = false; //Simple Check if garrison can be accessed! if (Player.Level < 90 || Player.Inventory.GarrisonHearthstone == null) { GarrisonBase.Log("No access to garrison!"); TreeRoot.Stop("No Access to Garrison"); return(false); } } if (await Common.CheckCommonCoroutines()) { return(true); } //Do we need to hearth or fly to our garrison? if (await Common.PreChecks.BehaviorRoutine()) { return(true); } //Disable and reload UI if master plan is enabled.. //if (await Common.PreChecks.CheckAddons()) return true; //We need "open" the garrison up and initalize it.. (so we don't get errors trying to inject!) if (await Common.PreChecks.InitalizeGarrisonManager()) { return(true); } ////Inject our lua addon code for mission success function //if (!LuaEvents.LuaAddonInjected) //{ // if (LuaCommands.TestLuaInjectionCode()) // {//Prevent multiple injections by checking simple function return! // LuaEvents.LuaAddonInjected = true; // } // else // { // await LuaEvents.InjectLuaAddon(); // return true; // } //} if (!InitalizedBehaviorList) { InitalizeBehaviorsList(); } //Check for next behavior if (CurrentBehavior == null) { while (Behaviors.Count > 0) { if (!Behaviors[0].CheckCriteria()) { Behaviors.RemoveAt(0); } else { CurrentBehavior = Behaviors[0]; CurrentBehavior.Initalize(); break; } } } if (CurrentBehavior != null) { //Check for any switch behaviors.. (override current behavior temporarly) if (SwitchBehaviors.Count > 0 && SwitchBehavior == null) { while (SwitchBehaviors.Count > 0) { if (!SwitchBehaviors[0].CheckCriteria()) { SwitchBehaviors.RemoveAt(0); } else { SwitchBehavior = SwitchBehaviors[0]; break; } } } if (SwitchBehavior != null && CurrentBehavior != SwitchBehavior) { GarrisonBase.Debug("Switching behaviors to {0}", SwitchBehavior.Type); CurrentBehavior = SwitchBehavior; CurrentBehavior.Initalize(); } bool x = await CurrentBehavior.BehaviorRoutine(); if (x && !CurrentBehavior.IsDone) { return(true); } GarrisonBase.Debug( !x ? "Finishing Behavior {0} because it returned false!" : "Finishing Behavior {0} because IsDone is true", CurrentBehavior.Type); if (!CurrentBehavior.Disposed) { CurrentBehavior.Dispose(); } if (SwitchBehavior != null && CurrentBehavior.Equals(SwitchBehavior)) { CurrentBehavior = Behaviors[0]; CurrentBehavior.Initalize(); SwitchBehaviors.RemoveAt(0); SwitchBehavior = null; } else { Behaviors.RemoveAt(0); CurrentBehavior = null; } return(true); } //if (Common.PreChecks.DisabledMasterPlanAddon) //{ // Common.PreChecks.ShouldCheckAddons = false; // LuaCommands.EnableAddon("MasterPlan"); // LuaCommands.ReloadUI(); // Common.PreChecks.DisabledMasterPlanAddon = false; // await Coroutine.Wait(6000, () => StyxWoW.IsInGame); // return true; //} TreeRoot.StatusText = "GarrisonBase is finished!"; TreeRoot.Stop(); return(false); }