public void testComponentMergeDifferentMassLarger() { List <string> component3Values = new List <string> { "2", "989.9", "99.9", "5", "6", "0.02", "88.8", "0.888", "10-15", "11.1-12.2", "10.55" }; InputFile componentInputFile3 = new InputFile("fake.txt", Purpose.Identification); Component createdComponent3 = new Component(component3Values, componentInputFile3); ChargeState cs1 = new ChargeState(10, 200d, 100d);//(int charge_count, double intensity, double mz_centroid) createdComponent3.charge_states.Add(cs1); List <string> component4Values = new List <string> { "2", "990.9", "99.9", "5", "6", "0.02", "88.8", "0.888", "10-15", "11.1-12.2", "10.55" }; Component createdComponent4 = new Component(component3Values, componentInputFile3); ChargeState cs2 = new ChargeState(10, 300d, 100.10023d); //(int charge_count, double intensity, double mz_centroid) ChargeState cs3 = new ChargeState(11, 500d, 91.09177968d); //(int charge_count, double intensity, double mz_centroid) createdComponent4.charge_states.Add(cs2); createdComponent4.charge_states.Add(cs3); createdComponent3.mergeTheseComponents(createdComponent4); Assert.AreEqual(1000d, createdComponent3.intensity_sum); Assert.AreEqual(Math.Round(989.92723551500012d, 5), Math.Round(createdComponent3.weighted_monoisotopic_mass, 5)); Assert.AreEqual(2, createdComponent3.charge_states.Count); Assert.AreEqual(true, createdComponent3.accepted); Assert.AreEqual(2, createdComponent3.charge_states.Count()); }
public void testComponentCreationFromChargeStates() { List <string> component2Values = new List <string> { "2", "989.9", "99.9", "5", "6", "0.02", "88.8", "0.888", "10-15", "11.1-12.2", "10.55" }; InputFile componentInputFile2 = new InputFile("fake.txt", Purpose.Identification); Component createdComponent2 = new Component(component2Values, componentInputFile2); ChargeState cs1 = new ChargeState(10, 200d, 100d, 0d);//(int charge_count, double intensity, double mz_centroid, double mz_correction) createdComponent2.charge_states.Add(cs1); createdComponent2.calculate_properties(); Assert.AreEqual(componentInputFile2.UniqueId + "_2", createdComponent2.id); Assert.AreEqual(989.9d, createdComponent2.reported_monoisotopic_mass); Assert.AreEqual(99.9d, createdComponent2.intensity_reported); Assert.AreEqual(200d, createdComponent2.intensity_sum); Assert.AreEqual(1, createdComponent2.num_charge_states); Assert.AreEqual(6, createdComponent2.num_detected_intervals); Assert.AreEqual(0.02d, createdComponent2.delta_mass); Assert.AreEqual(88.8d, createdComponent2.relative_abundance); Assert.AreEqual(0.888, createdComponent2.fract_abundance); Assert.AreEqual("10-15", createdComponent2.scan_range); Assert.AreEqual("11.1-12.2", createdComponent2.rt_range); Assert.AreEqual(10.55d, createdComponent2.rt_apex); Assert.AreEqual(200d, createdComponent2.intensity_sum); Assert.AreEqual(true, createdComponent2.accepted); Assert.AreEqual(1, createdComponent2.charge_states.Count()); }
public void OnUpdate() { var newLevel = GetNewChargeLevel(); if (newLevel != _lastChargeLevel && _lastChargeLevelChange + TimeSpan.FromSeconds(VisualsChangeDelay) < _gameTiming.CurTime) { _lastChargeLevel = newLevel; _lastChargeLevelChange = _gameTiming.CurTime; if (Owner.TryGetComponent(out AppearanceComponent? appearance)) { appearance.SetData(SmesVisuals.LastChargeLevel, newLevel); } } var newChargeState = GetNewChargeState(); if (newChargeState != _lastChargeState && _lastChargeStateChange + TimeSpan.FromSeconds(VisualsChangeDelay) < _gameTiming.CurTime) { _lastChargeState = newChargeState; _lastChargeStateChange = _gameTiming.CurTime; if (Owner.TryGetComponent(out AppearanceComponent? appearance)) { appearance.SetData(SmesVisuals.LastChargeState, newChargeState); } } }
public void testComponentMergeSameMass() { List <string> component3Values = new List <string> { "2", "989.9", "99.9", "5", "6", "0.02", "88.8", "0.888", "10-15", "11.1-12.2", "10.55" }; InputFile componentInputFile3 = new InputFile("fake.txt", Purpose.Identification); Component createdComponent3 = new Component(component3Values, componentInputFile3); ChargeState cs1 = new ChargeState(10, 200d, 100d);//(int charge_count, double intensity, double mz_centroid) createdComponent3.charge_states.Add(cs1); List <string> component4Values = new List <string> { "2", "989.9", "99.9", "5", "6", "0.02", "88.8", "0.888", "10-15", "11.1-12.2", "10.55" }; Component createdComponent4 = new Component(component3Values, componentInputFile3); ChargeState cs2 = new ChargeState(11, 300d, 91.0006615d);//(int charge_count, double intensity, double mz_centroid) createdComponent4.charge_states.Add(cs1); createdComponent4.charge_states.Add(cs2); createdComponent3.mergeTheseComponents(createdComponent4); Assert.AreEqual(componentInputFile3.UniqueId + "_2", createdComponent3.id); Assert.AreEqual(989.9d, createdComponent3.reported_monoisotopic_mass); Assert.AreEqual(99.9d, createdComponent3.intensity_reported); Assert.AreEqual(700d, createdComponent3.intensity_sum); Assert.AreEqual(2, createdComponent3.charge_states.Count); Assert.AreEqual(true, createdComponent3.accepted); Assert.AreEqual(2, createdComponent3.charge_states.Count()); }
public void CompressHarmonicsEqualNumberChargeStates() { cList.Clear(); L.neucode_labeled = false; List <double> possibleMissedMonoisotopicsList = new List <double> { 1000d, 500d }; int counter = 0; foreach (double mass in possibleMissedMonoisotopicsList) { Component c = new Component(); InputFile i = new InputFile("path", Purpose.Identification); c.input_file = i; c.id = counter.ToString(); c.weighted_monoisotopic_mass = mass; for (int j = 1; j < 4; j++) { ChargeState cs = new ChargeState(j, 100d, (mass + j * Lollipop.PROTON_MASS) / j, 0d);//(int charge_count, double intensity, double mz_centroid, double mz_correction) c.charge_states.Add(cs); } c.scan_range = "1-2"; c.calculate_properties(); cList.Add(c); counter++; } List <Component> compressed = new List <Component>(cr.TEST_remove_monoisotopic_duplicates_harmonics_from_same_scan(cList)); Assert.AreEqual(1, compressed.Count); Assert.AreEqual(1000, Convert.ToInt32(compressed.FirstOrDefault().weighted_monoisotopic_mass)); }
public override Type Tick() { switch (state) { case ChargeState.Start: StartCoroutine(Observe()); state = ChargeState.Idle; break; case ChargeState.Charge: Charge(); if (chargeTimer <= 0) { StartCoroutine(Recover()); state = ChargeState.Idle; } break; case ChargeState.Finished: state = ChargeState.Start; return(typeof(State_Charger_Pursuit)); } return(null); }
// Update is called once per frame void Update() { if (cs == ChargeState.Stable) { transform.rotation = Quaternion.LookRotation( Vector3.forward, Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position); if (Input.GetMouseButtonDown(0)) { cs = ChargeState.Charging; chargeStart = Time.time; } } else if (cs == ChargeState.Charging) { Vector2 barScale = bar.sizeDelta; barScale.x += charge; bar.sizeDelta = barScale; if (Input.GetMouseButtonUp(0)) { thisRb.AddForce(power * transform.up * (Time.time - chargeStart)); cs = ChargeState.Launched; transform.GetChild(0).gameObject.SetActive(false); } } }
public async Task SaveCharge([ActivityTrigger] ChargeState charge, [CosmosDB( databaseName: "ChargeState", collectionName: "Charges", ConnectionStringSetting = "CosmosConnection")] IAsyncCollector <TeslaCharge> teslaCharge, ILogger log) { var client = new HttpClient(); var locationResponse = await client.PostAsync(Environment.GetEnvironmentVariable( "GoogleReverseGeocodeUri") + $"?latlng={charge.Latitude},{charge.Longitude}&key={Environment.GetEnvironmentVariable("GoogleMapsApiKey")}", null); var locationResult = JsonConvert.DeserializeObject <ReverseResponse>(await locationResponse.Content.ReadAsStringAsync()); var newCharge = new TeslaCharge() { Vin = charge.Vin, Amount = charge.ChargeEnergyAdded, Date = DateTime.UtcNow, Location = locationResult.Results[0].FormattedAddress }; try { await teslaCharge.AddAsync(newCharge); log.LogInformation("************** CHARGING DATA SAVED TO DB"); } catch (Exception e) { log.LogError(e.Message, e); throw; } }
// Use this for initialization void Start() { //Set ourself to follow mode. motionState = ChargeState.Following; GetComponent<Renderer>().material.color = Color.green; player = GameObject.FindGameObjectWithTag("Player"); }
protected override void Update() { if (Input.GetMouseButtonDown(1) && spendRage(chargeCost)) { chargeState = ChargeState.Charging; movementActive = false; canAttack = false; attacking = false; attackFrame = 0; } if (currentRage < chargeCost) { rageBarImage.color = new Color(1, 1, 1, 0.5f); } else { rageBarImage.color = Color.white; } rageBarImage.fillAmount = currentRage / maxRage; base.Update(); }
public Boss() : base(Difficulty.Hard) { this.TextureBackground = TextureManager.boss; this.Texture = TextureManager.bossForeground; this.charge = ChargeState.NotCharging; this.dodge = DodgeState.NotDodging; this.Depth = 0.5f; this.Opacity = 0f; this.possibleAttacks = new List <int>(); this.EngineAnimation = TextureManager.bossEngineAnimation; this.MaxFrame = 3; this.FrameWidth = 163; this.FrameHeight = 139; this.Colour = Color.Red; // Modules this.Health = new Bar(new Vector2(70, 10), 200, 25, 150, Color.Red); ShipShield = new Shield(new Vector2(270, 10), (int)ShipShield.Width, 20, 0, 0, 3); ShipShield.Description = "|W|Shield: |0,0,255|" + ShipShield.MaxValue + "|W|\nWill teleport to another location just before being hit."; ShipHull = new Hull(this, 0, 3); ShipHull.Description = "|W|Armor: |255,255,0|" + ShipHull.Armor + "|255,255,100|\nPlaces mines on tiles in the tileboard.\nThe Player will take 20 damage when matching tiles with mines.\nMines will be disarmed when matched or then falling."; Weapons[0].Description = "|W|Charges forward and deals massive damage if it hits the Player.\nThe Boss is vurnerable when charging."; Weapons[1].Description = "|W|Shoot several shots, eighter in a X pattern or a V patterns."; Weapons[1].Method = Weapon.ListOfMethods()[0]; }
// Update is called once per frame void FixedUpdate() { if (state == ChargeState.cooldown) { /* if we are down with our CD, then go into the aiming state */ if (Time.time - coolTime > coolDownTime) { aimTime = Time.time; DrawAimingLock(); state = ChargeState.aiming; } } else if (state == ChargeState.aiming) { if (Time.time - aimTime > chargeTime) { /* start the charge */ ChargeAtTarget(); state = ChargeState.charging; } } else if (state == ChargeState.charging) { Vector2 diffVec = lockPosition - Vec2FromVec3(transform.position); float projection = Vector2.Dot(body.velocity, diffVec); if (projection < 0) { /* start a cooldown */ coolTime = Time.time; body.velocity = Vector2.zero; state = ChargeState.cooldown; } } }
// Update is called once per frame void Update() { if (playerShip.dead) { state = ChargeState.cancelled; } if (!GameManager.S.inGame) { return; } if (Input.GetKeyUp(Y) || (playerShip != null && playerShip.player.device != null && playerShip.player.device.Action4.WasReleased)) { //Cancel the charge if we're not ready yet if (state == ChargeState.charging) { CancelCharge(); } else if (state == ChargeState.charged) { Fire(); } } }
/// <summary> /// Toggles the UI between a "ready" mode and a "recharging" mode /// </summary> /// <param name="isCharging"></param> protected virtual void SetChargeStateUI(ChargeState newState) { chargeState = newState; if (newState == ChargeState.Ready) { Fields["ChargeStatus"].guiActive = true; Fields["CoreTemp"].guiActive = false; Fields["HeatOutput"].guiActive = false; Fields["ReactorOutput"].guiActive = false; Fields["FuelInput"].guiActive = false; Events["EnableReactor"].guiActive = true; } if (newState == ChargeState.Running) { Fields["ChargeStatus"].guiActive = false; Fields["CoreTemp"].guiActive = true; Fields["HeatOutput"].guiActive = true; Fields["ReactorOutput"].guiActive = true; Fields["FuelInput"].guiActive = true; Events["EnableReactor"].guiActive = false; } if (newState == ChargeState.Charging) { Fields["ChargeStatus"].guiActive = true; Fields["CoreTemp"].guiActive = false; Fields["HeatOutput"].guiActive = false; Fields["ReactorOutput"].guiActive = false; Fields["FuelInput"].guiActive = false; Events["EnableReactor"].guiActive = false; } }
private void write_inclusion_list(List <ExperimentalProteoform> proteoforms) { SaveFileDialog saveDialog = new SaveFileDialog(); saveDialog.Filter = "Text files (*.txt)|*.txt"; saveDialog.FileName = "inclusion_list.txt"; DialogResult dr = saveDialog.ShowDialog(); if (dr == System.Windows.Forms.DialogResult.OK) { using (var writer = new StreamWriter(saveDialog.FileName)) { foreach (ExperimentalProteoform proteoform in proteoforms) { //get highest intensity charge state ChargeState max = proteoform.aggregated_components.SelectMany(p => p.charge_states).OrderByDescending(c => c.intensity).First(); double mz = max.mz_centroid; if (SaveState.lollipop.neucode_labeled) { mz = mz - (136.109162 * proteoform.lysine_count).ToMz(max.charge_count) + (128.094963 * proteoform.lysine_count).ToMz(max.charge_count); } writer.WriteLine(mz + "\t" + max.charge_count + "\t" + proteoform.agg_rt); } } MessageBox.Show("Successfully exported inclusion list."); } else { return; } }
protected override void TickCore(Entity host, RealmTime time, ref object state) { ChargeState s = (state == null) ? new ChargeState() : (ChargeState)state; Status = CycleStatus.NotStarted; if (host.HasConditionEffect(ConditionEffectIndex.Paralyzed)) { return; } Player player = (Player)host.GetNearestEntity(range, null); if (player == null) { return; } float length = new Vector2(player.X - host.X, player.Y - host.Y).Length; if (s.RemainingTime <= 0) { if (s.Direction == Vector2.Zero) { if (player.X != host.X && player.Y != host.Y) { s.Direction = new Vector2(player.X - host.X, player.Y - host.Y); float dist = s.Direction.Length; s.Direction.Normalize(); s.RemainingTime = (int)(dist / host.EntitySpeed(speed, time) * 1000); Status = CycleStatus.InProgress; } } else { s.Direction = Vector2.Zero; s.RemainingTime = coolDown.Next(Random); Status = CycleStatus.Completed; } } if (s.Direction != Vector2.Zero) { float dist = host.EntitySpeed(speed, time); host.ValidateAndMove(host.X + s.Direction.X * dist, host.Y + s.Direction.Y * dist); host.UpdateCount++; Status = CycleStatus.InProgress; } if (length <= 0.5) { s.Direction = Vector2.Zero; s.RemainingTime = 1000; Status = CycleStatus.Completed; } s.RemainingTime -= time.ElapsedMsDelta; state = s; }
public Boss() : base(Difficulty.Hard) { this.TextureBackground = TextureManager.boss; this.Texture = TextureManager.bossForeground; this.charge = ChargeState.NotCharging; this.dodge = DodgeState.NotDodging; this.Depth = 0.5f; this.Opacity = 0f; this.possibleAttacks = new List<int>(); this.EngineAnimation = TextureManager.bossEngineAnimation; this.MaxFrame = 3; this.FrameWidth = 163; this.FrameHeight = 139; this.Colour = Color.Red; // Modules this.Health = new Bar(new Vector2(70, 10), 200, 25, 150, Color.Red); ShipShield = new Shield(new Vector2(270, 10), (int)ShipShield.Width, 20, 0, 0, 3); ShipShield.Description = "|W|Shield: |0,0,255|" + ShipShield.MaxValue + "|W|\nWill teleport to another location just before being hit."; ShipHull = new Hull(this, 0, 3); ShipHull.Description = "|W|Armor: |255,255,0|" + ShipHull.Armor + "|255,255,100|\nPlaces mines on tiles in the tileboard.\nThe Player will take 20 damage when matching tiles with mines.\nMines will be disarmed when matched or then falling."; Weapons[0].Description = "|W|Charges forward and deals massive damage if it hits the Player.\nThe Boss is vurnerable when charging."; Weapons[1].Description = "|W|Shoot several shots, eighter in a X pattern or a V patterns."; Weapons[1].Method = Weapon.ListOfMethods()[0]; }
void PlayerHit() { MainPlayer player = target.GetComponent <MainPlayer>(); player.GetHit(); currentState = ChargeState.done; GameManager.Instance.SlowMotion(0.2f, 3); }
private ChargeState() { if (_instance != null) { return; } _instance = this; }
private void SyncState(ChargeState old, ChargeState newState) { if (old != newState) { chargeState = newState; spriteHandler.ChangeSprite((int)chargeState); } }
IEnumerator Charge() { state = ChargeState.charging; float timeElapsed = 0f; ParticleSystem.ShapeModule shape = chargeParticle.shape; //Set initial values before playing shape.radius = 1f; shape.angle = maxChargeAngle; chargeParticle.startSize = maxStartSize; chargeParticle.startColor = startColor; chargeParticle.Play(); if (GameManager.S.inGame) { SoundManager.instance.Play("ChargeAttackCharge"); } while (timeElapsed < chargeTime && state == ChargeState.charging) { timeElapsed += Time.deltaTime; float percent = timeElapsed / chargeTime; //Animate the charge effect shape.radius = Mathf.Lerp(1, 0, percent); shape.angle = Mathf.Lerp(maxChargeAngle, minChargeAngle, percent * percent); Vector3 curRot = chargeParticle.transform.localRotation.eulerAngles; curRot.z += Mathf.Lerp(minChargeRotationSpeed, maxChargeRotationSpeed, percent * percent); chargeParticle.transform.localRotation = Quaternion.Euler(curRot); chargeParticle.startSize = Mathf.Lerp(maxStartSize, minStartSize, percent * percent); chargeParticle.startColor = Color.Lerp(startColor, endColor, percent * percent); playerShip.movement.SlowPlayer(Mathf.Lerp(1, maxChargeSlow, percent), 0, true); yield return(null); } if (state != ChargeState.cancelled) { if (GameManager.S.inGame) { SoundManager.instance.Play("FullyCharged"); } state = ChargeState.charged; } while (state == ChargeState.charged) { playerShip.movement.SlowPlayer(maxChargeSlow, 0, true); yield return(null); } if (state == ChargeState.cancelled) { CancelCharge(); } }
void HandleCharging() { currentChargeTime += Time.deltaTime; if (currentChargeTime >= chargeTime) { Shoot(); currentState = ChargeState.shooting; } HandleChargeValues(); }
protected override void HandleFixedUpdate() { switch (chargeState) { case ChargeState.IDLE: chargesOnCable.Clear(); chargeTime = 0; if (powerVoltage * 0.99f > voltage) { chargeState = ChargeState.CHARGING; StartCoroutine("ElectronChargeEffect"); } else if (powerVoltage < voltage) { chargeState = ChargeState.DISCHARGING; StartCoroutine("ElectronChargeEffect"); } break; case ChargeState.CHARGING: if (voltage >= powerVoltage * 0.99f) { chargeState = ChargeState.IDLE; previousPowerVoltage = voltage; break; } else { Charge(); chargeTime += Time.fixedDeltaTime * 0.25f; } break; case ChargeState.DISCHARGING: if (voltage * 0.99f <= powerVoltage) { chargeState = ChargeState.IDLE; previousPowerVoltage = voltage; } else { Discharge(); chargeTime += Time.fixedDeltaTime * 0.25f; } break; default: break; } }
void HandleStopCharging() { currentChargeTime -= Time.deltaTime * decayfactor; if (currentChargeTime <= 0) { StopAnimation(); currentState = ChargeState.start; return; } HandleChargeValues(); }
/// <summary> /// Generates a hash code. /// </summary> /// <returns>Hash code based on stored data.</returns> public override int GetHashCode() { var hashCode = Abundance.GetHashCode() ^ ChargeState.GetHashCode() ^ DriftTime.GetHashCode() ^ Id.GetHashCode() ^ Net.GetHashCode(); return(hashCode); }
public void CompressHarmonics() { cList.Clear(); L.neucode_labeled = false; List <double> possibleHarmonicList = // 2 missed on the top means up to 4 missed monos on the 2nd harmonic and 6 missed monos on the 3rd harmonic Enumerable.Range(-4, 9).Select(x => (1000d + ((double)x) * Lollipop.MONOISOTOPIC_UNIT_MASS) / 2d) .Concat( Enumerable.Range(-6, 13).Select(x => (1000d + ((double)x) * Lollipop.MONOISOTOPIC_UNIT_MASS) / 3d)) .ToList(); possibleHarmonicList.Add(1000d); int counter = 0; foreach (double mass in possibleHarmonicList) { Component c = new Component(); InputFile i = new InputFile("path", Purpose.Identification); c.input_file = i; c.id = counter.ToString(); c.weighted_monoisotopic_mass = mass; if (mass == 1000d) { ChargeState cs1 = new ChargeState(10, 1000d, (c.weighted_monoisotopic_mass + 10d * Lollipop.PROTON_MASS) / 10d);//(int charge_count, double intensity, double mz_centroid) c.charge_states.Add(cs1); } else { if (mass == 1000d / 2d || mass == 1000d / 3d) { ChargeState cs1 = new ChargeState(10, 5d, (c.weighted_monoisotopic_mass + 10d * Lollipop.PROTON_MASS) / 10d);//(int charge_count, double intensity, double mz_centroid) c.charge_states.Add(cs1); } else { ChargeState cs1 = new ChargeState(10, 1d, (c.weighted_monoisotopic_mass + 10d * Lollipop.PROTON_MASS) / 10d);//(int charge_count, double intensity, double mz_centroid) c.charge_states.Add(cs1); } } c.min_scan = 1; c.max_scan = 2; c.calculate_properties(); cList.Add(c); counter++; } List <Component> compressed = new List <Component>(cr.remove_monoisotopic_duplicates_harmonics_from_same_scan(cList)); Assert.AreEqual(1, compressed.Count); }
public override string ToString() { var data = new List <string> { ID.ToString(), MonoIsotopicMass.ToString("0.0000"), MZ.ToString("0.0000"), ChargeState.ToString(), NormalizedElutionTime.ToString("0.000"), Code }; return(string.Join("; ", data)); }
public ElectroTurret(Vector3 pos, Vector3 targetDir, Game1 game) : base(pos, targetDir,game) { col = new CircleCollider(pos, 20); wakeRange = new CircleCollider(pos, 25); electroModel = new ElectroTurretModel(this, game); game.modelManager.addObject(electroModel); cooldownMax = 0.25f; chargeState = ChargeState.idle; chargeTime = 3; targets = new List<Enemy>(); shotPos = pos; shotPos.Y += 5; }
public void testSetValuesWithExistingChargeStates() { ChargeState chargeState1 = new ChargeState(10, 1, 100); testComponent1.charge_states.Add(chargeState1); testComponent1.calculate_properties(); Assert.AreEqual(1, testComponent1.charge_states.Count); Assert.That(() => testComponent1.intensity_sum = 2d, Throws.TypeOf <ArgumentException>() .With.Property("Message") .EqualTo("Charge state data exists that can't be overwritten with intensity input")); Assert.That(() => testComponent1.weighted_monoisotopic_mass = 2d, Throws.TypeOf <ArgumentException>() .With.Property("Message") .EqualTo("Charge state data exists that can't be overwritten with mass input")); }
private async Task GetChargeState() { var chargeState = await _service.GetChargeState(_configuration.Settings["vehicleId"]); if (chargeState == ChargeState.Empty) { return; } _chargeState = chargeState; RaisePropertyChanged(nameof(StateOfChargePercentage)); RaisePropertyChanged(nameof(StateOfChargeKm)); RaisePropertyChanged(nameof(StateOfCharge)); }
void CancelCharge() { if (GameManager.S.inGame) { SoundManager.instance.Stop("ChargeAttackCharge"); SoundManager.instance.Stop("FullyCharged"); } state = ChargeState.cancelled; if (chargeParticle != null) { Destroy(chargeParticle.gameObject); } Destroy(gameObject, 2f); playerShip.movement.RestoreSpeed(); }
public async Task <ChargeState> GetChargeState(long vehicleId) { ChargeState chargeState = null; using (var response = await _client.GetAsync($"api/1/vehicles/{vehicleId}/data_request/charge_state")) { var responseString = response.Content.ReadAsStringAsync().Result; if (response.IsSuccessStatusCode) { chargeState = JsonConvert.DeserializeObject <TeslaResponse <ChargeState> >(responseString).Content; } } return(chargeState); }
public void ResetObject() { voltage = 0; previousPowerVoltage = 0; chargeTime = 0; chargeState = ChargeState.IDLE; foreach (Charge charge in chargesOnCable) { if (charge != null) { Destroy(charge.gameObject); } } }
protected override void TickCore(Entity host, RealmTime time, ref object state) { ChargeState s; if (state == null) s = new ChargeState(); else s = (ChargeState)state; Status = CycleStatus.NotStarted; if (host.HasConditionEffect(ConditionEffects.Paralyzed)) return; if (s.RemainingTime <= 0) { if (s.Direction == Vector2.Zero) { var player = (Player)host.GetNearestEntity(range, null); if (player != null && player.X != host.X && player.Y != host.Y) { s.Direction = new Vector2(player.X - host.X, player.Y - host.Y); var d = s.Direction.Length(); s.Direction.Normalize(); s.RemainingTime = coolDown.Next(Random); if (d / host.GetSpeed(speed) < s.RemainingTime) s.RemainingTime = (int)(d / host.GetSpeed(speed) * 1000); Status = CycleStatus.InProgress; } } else { s.Direction = Vector2.Zero; s.RemainingTime = coolDown.Next(Random); Status = CycleStatus.Completed; } } if (s.Direction != Vector2.Zero) { float dist = host.GetSpeed(speed) * (time.thisTickTimes / 1000f); host.ValidateAndMove(host.X + s.Direction.X * dist, host.Y + s.Direction.Y * dist); host.UpdateCount++; Status = CycleStatus.InProgress; } s.RemainingTime -= time.thisTickTimes; state = s; }
public override void Update() { if(cooldown > 0) { cooldown -= Utilities.deltaTime; if (cooldown < 0) cooldown = 0; } if(state == State.idle) { if(enemyManager.enemies.Count() > 0) { if (enemiesInRange(wakeRange)) state = State.active; } } if (state == State.active) { if (cooldown == 0) chargeState = ChargeState.charging; if (chargeState == ChargeState.charging) { chargeTime += Utilities.deltaTime; if (chargeTime > 4) { if (enemiesInRange(col)) { fire(); chargeState = ChargeState.idle; } } if (!enemiesInRange(wakeRange)) { state = State.idle; chargeTime = 3; chargeState = ChargeState.idle; cooldown = 2; } } } updateProjectiles(); }
public override void UpdateLevel(Level level) { // Animation AnimationTimer++; if (AnimationTimer > 7) { AnimationTimer = 0; if (Frame < MaxFrame) { Frame++; } else { Frame = 0; } } // Renew attacks if (possibleAttacks.Count() == 0) { possibleAttacks.Add(0); possibleAttacks.Add(1); possibleAttacks.Add(1); possibleAttacks.Add(2); possibleAttacks.Add(2); possibleAttacks.Add(2); } DamageOverTime(); // Weapons foreach (Weapon w in Weapons) { w.UpdateLevel(level); } // Move to normal position after knockback if (charge == ChargeState.NotCharging) { Position = new Vector2(Position.X, (float)MathHelper.Lerp(Position.Y, Texture.Height, 0.05f)); } if (level.Started) { // Die if (Health.Value <= 0 && deathTimer == 0 && dodge == DodgeState.NotDodging && charge == ChargeState.NotCharging) { deathTimer = 180; SoundManager.die.Play(); } if (deathTimer > 0) { deathTimer--; if (deathTimer % 5 == 0) { dodge = DodgeState.Dodge; List<int> possibleLocations = new List<int>(); for (int i = 0; i < 3; i++) { if (i != (int)ShipLocation) { possibleLocations.Add(i); } } ShipLocation = (Location)possibleLocations[Globals.Randomizer.Next(0, possibleLocations.Count())]; } } if (deathTimer == 1) { Dead = true; SoundManager.explosion.Play(); for (int i = 0; i < 100; i++) { level.ToAdd.Add(new Piece(Position, Texture, 60, 3f)); } SceneManager.ChangeScene(SceneManager.winScene); } attackCooldown--; // Choose attack if (dodge == DodgeState.NotDodging && charge == ChargeState.NotCharging && shootTimer < -20 && Globals.Randomizer.Next(0, 101) < 3 && attackCooldown < 0 && deathTimer == 0) { attackCooldown = 60; int attack = possibleAttacks[Globals.Randomizer.Next(0, possibleAttacks.Count())]; possibleAttacks.Remove(attack); if (attack == 0) { if (ShipLocation == level.Player.ShipLocation) { charge = ChargeState.Initialize; SoundManager.bossChargeAttack.Play(); } else { SoundManager.bossTeleport.Play(); dodge = DodgeState.Dodge; ShipLocation = level.Player.ShipLocation; possibleAttacks.Add(0); } } else if (attack == 1) { shootTimer = 200; Opacity = 0; SoundManager.bossChargeShot.Play(); } else if (attack == 2) { // Place mine in tiles int random = Globals.Randomizer.Next(0, level.Tiles.Count()); level.Tiles[random][Globals.Randomizer.Next(0, level.Tiles[random].Count() - 2)].Mine = true; SoundManager.bossMine.Play(); } } // Shoot shootTimer--; if (shootTimer > 0) { if (shootTimer > 100) { Opacity += 0.015f; } else if (shootTimer < 20) { Opacity -= 0.07f; } if (shootTimer == 100) { if (ShipLocation == level.Player.ShipLocation) { Weapon.FireBossV(this, Weapons[1], 0, level, false); } else { Weapon.FireBossX(this, Weapons[1], 0, level, false); } } } // Shield if (dodge == DodgeState.Dodge) { Weapons[1].ShotsToShoot.Clear(); Size = MathHelper.Lerp(Size, 0, 0.1f); if (Size < 0.1f) { dodge = DodgeState.NotDodging; Position = new Vector2((int)ShipLocation * 100 + 200, Position.Y); Size = 1; } } // Back away to gain more power for charge if (charge == ChargeState.Initialize) { accelerate = -2; charge = ChargeState.Beginning; } if (charge == ChargeState.Beginning) { Position += new Vector2((float)Math.Cos(Direction) * accelerate, (float)Math.Sin(Direction) * accelerate); accelerate += 0.023f; if (accelerate > 0) { charge = ChargeState.Charge; } } // Charge if (charge == ChargeState.Charge) { Position += new Vector2((float)Math.Cos(Direction) * accelerate, (float)Math.Sin(Direction) * accelerate); accelerate += 0.2f; } else if (charge == ChargeState.Finished) // Return to normal position { if (accelerate < 4) { accelerate = 4; } Position += new Vector2((float)Math.Cos(Direction) * accelerate, (float)Math.Sin(Direction) * accelerate); Vector2 afterChargeTarget = new Vector2((int)ShipLocation * 100 + 200, -400); Direction = MathHelper.Lerp(Direction, (float)Math.Atan2(afterChargeTarget.Y - Position.Y, afterChargeTarget.X - Position.X), 0.03f); if (Position.Y < -300) { charge = ChargeState.NotCharging; Direction = StandardDirection; Position = new Vector2((int)ShipLocation * 100 + 200, Position.Y); accelerate = 0f; } } // Hit player with charge if (level.Player.Box.Intersects(chargeRectangle) && charge == ChargeState.Charge) { charge = ChargeState.Finished; level.Player.KnockBack = 10; level.Player.TakeDamage(50, 0.5f, DamageType.rock, false); Camera.ScreenShakeTimer = 30; } // Miss if (Position.Y > Globals.ScreenSize.Y) { charge = ChargeState.Finished; } } }
public override bool Reset(Enemy enemy) { if (enemy == null) return false; _myEnemy = enemy; _chargeState = ChargeState.START_CHARGE; return true; }
public override State DoTask() { Vector2 enemyToPlayer = (Vector2)(_playerTrans.position) - _myEnemy.Position; float sqrDist = enemyToPlayer.sqrMagnitude; switch (_chargeState) { case ChargeState.START_CHARGE: // begin charge _dir = enemyToPlayer.normalized; _initSqrDist = sqrDist; _chargeState = ChargeState.CHARGING; break; case ChargeState.CHARGING: // check if overshot if (sqrDist < _sqrOvershoot) _chargeState = ChargeState.OVERSHOT; else if (sqrDist > _initSqrDist) _chargeState = ChargeState.START_CHARGE; break; case ChargeState.OVERSHOT: // check dist is greater than overshoot if (sqrDist > _sqrOvershoot) _chargeState = ChargeState.START_CHARGE; break; } // Move based on ability if(_myEnemy.HasAbilities(EnemyProps.WALKS)) { _myEnemy.Walk(Mathf.Sign(_dir.x)); } else if (_myEnemy.HasAbilities(EnemyProps.FLYS)) { _myEnemy.Fly(_dir); } else { return State.FAILED; } return State.ONGOING; }
public override void TakeDamage(float damage, float goThroughShield, DamageType damageType, bool FromShield) { if (charge != ChargeState.NotCharging) { charge = ChargeState.Finished; base.TakeDamage(damage, goThroughShield, damageType, true); } else if (damageType == DamageType.laser) { dodge = DodgeState.Dodge; SoundManager.bossTeleport.Play(); List<int> possibleLocations = new List<int>(); for (int i = 0; i < 3; i++) { if (i != (int)ShipLocation) { possibleLocations.Add(i); } } ShipLocation = (Location)possibleLocations[Globals.Randomizer.Next(0, possibleLocations.Count())]; } }
// Update is called once per frame void Update() { //Increase our counter. counter += Time.deltaTime; #region Following if (motionState == ChargeState.Following) { //Find Vector3 to the player. dirToPlayer = player.transform.position - transform.position; //Set the velocity while it is following the player GetComponent<Rigidbody>().velocity = dirToPlayer.normalized * followVelocity; //If we have followed long enough. if (counter > followDuration) { //Stop moving and any forward motion GetComponent<Rigidbody>().velocity = Vector3.zero; GetComponent<Rigidbody>().rotation = Quaternion.identity; //Update to pause color and pause state. GetComponent<Renderer>().material.color = Color.yellow; motionState = ChargeState.Pausing; //Reset timer counter = 0.0f; } } #endregion #region Pausing if (motionState == ChargeState.Pausing) { //Set ourself to our pause velocity. GetComponent<Rigidbody>().velocity = dirToPlayer.normalized * pauseVelocity; //If we have paused long enough if (counter > pauseDuration) { //Set our velocity and rotation to zero GetComponent<Rigidbody>().velocity = Vector3.zero; GetComponent<Rigidbody>().rotation = Quaternion.identity; //Show them we are angry GetComponent<Renderer>().material.color = Color.red; //Update our state to say we're charging motionState = ChargeState.Charging; counter = 0.0f; //We move in the direction of the player. We don't update that when charging //Give ourselves a force that scales with our charge force and mass. GetComponent<Rigidbody>().AddForce(dirToPlayer.normalized * chargeForce * GetComponent<Rigidbody>().mass); } } #endregion #region Charging if (motionState == ChargeState.Charging) { //If we have charged for long enough if (counter > chargeDuration) { //Set our velocity and rotation back to zero to stop charge. GetComponent<Rigidbody>().velocity = Vector3.zero; GetComponent<Rigidbody>().rotation = Quaternion.identity; //Change our color and state to say we're not aggressive. GetComponent<Renderer>().material.color = Color.green; motionState = ChargeState.Following; //Reset our counter counter = 0.0f; } } #endregion }
/// <summary> /// What the Client sends to the server. /// </summary> public override void FromClient(PacketFromClient packet) { while (phase == Phases.Handshake) Thread.Sleep(100); //Wait for handshake to complete if (phase == Phases.FinalClose) throw new SessionClosedException(); if (packet.PacketID == PassThrough.ID) { SendToBackend(packet); return; } //Fix players eid to what is known for the server if (packet is IEntity) { IEntity ie = (IEntity)packet; if (ie.EID == Player.EntityID) { ie.EID = EID; packet.SetPacketBuffer(null); } } WorldRegion region = CurrentRegion; switch (packet.PacketID) { case PlayerPosition.ID: if (AttachedEntity > 0) { //Ignore relative movements } else { var pp = ((PlayerPosition)packet); if (pp.Position.Y > -900) { SetPosition(pp.Position, true); OnGround = pp.OnGround != 0; } } break; case PlayerPositionLookClient.ID: if (AttachedEntity > 0) { //Ignore relative movements } else { PlayerPositionLookClient pp = ((PlayerPositionLookClient)packet); if (pp.Position.Y > -900) { SetPosition(pp.Position, true); OnGround = pp.OnGround; } } Pitch = ((PlayerPositionLookClient)packet).Pitch; Yaw = ((PlayerPositionLookClient)packet).Yaw; break; case PlayerGround.ID: OnGround = ((PlayerGround)packet).OnGround; //Good but a few false positives /* if (Sprinting)//Hacked client: Invalid sprint { Chatting.Parser.TellAdmin(Player.Name + Chat.Gray + " sprinting standing still"); }*/ break; case EntityAction.ID: EntityAction ea = packet as EntityAction; switch (ea.Action) { case EntityAction.Actions.LeaveBed: Sleeping = false; break; case EntityAction.Actions.Crounch: Crouched = true; break; case EntityAction.Actions.Uncrounch: Crouched = false; break; case EntityAction.Actions.StartSprinting: Sprinting = true; break; case EntityAction.Actions.StopSprinting: Sprinting = false; break; } break; case UseEntity.ID: if (Mode == GameMode.Creative && (Player.Admin() == false)) return; //Donors can't hurt while in creative mode if (UseEntityFromClient((UseEntity)packet)) return; break; case HeldItemClient.ID: //Active item var hc = (HeldItemClient)packet; if (hc.SlotID >= 0 && hc.SlotID <= 8) ActiveInventoryIndex = hc.SlotID; else Log.Write( new InvalidOperationException("Invalid holding slot id: " + hc.SlotID), this.Player ); break; //Prevent non admins from getting items in creative case CreativeInventory.ID: if (Player.Admin() == false) { Player.SendToClient(new EntityStatus(Player.EntityID, EntityStatuses.EntityHurt)); Player.TellSystem(Chat.Yellow, "Creative Inventory Disabled"); return; } CreativeInventory ci = (CreativeInventory)packet; if (0 <= ci.Slot && ci.Slot <= Inventory.Length) Inventory[ci.Slot] = ci.Item; break; //If block action is done from another region case PlayerBlockPlacement.ID: //AfkTime = DateTime.Now; //Non admins can't place block if (Mode == GameMode.Creative && (Player.Admin() == false)) { Player.SendToClient(new EntityStatus(Player.EntityID, EntityStatuses.EntityHurt)); Player.TellSystem(Chat.Yellow, "Creative Build Disabled"); return; } PlayerBlockPlacement pb = (PlayerBlockPlacement)packet; if (pb.BlockPosition.IsNull() == false) { CoordDouble pos = pb.BlockPosition.CloneDouble(); region = RegionCrossing.GetRegion(pos, Dimension, World.Regions); //Remember the last position clicked so we can do better chest protection LastClickRegion = region; //this is obsolete since we moved to blocking open across regions } else { if (pb.Item != null) Charge = new ChargeState(pb.Item.ItemID); } if (FilterDirection(pb.BlockPosition)) return; if (region == null) { if (Dimension == 0 && FilterLava(pb)) return; } if (Protected.ProtectBlockPlace(this, region, pb)) return; break; case PlayerDigging.ID: //AfkTime = DateTime.Now; PlayerDigging pd = (PlayerDigging)packet; if (pd.Status == PlayerDigging.StatusEnum.FinishedDigging || pd.Status == PlayerDigging.StatusEnum.StartedDigging) { CoordDouble pos = pd.Position.CloneDouble(); region = RegionCrossing.GetRegion(pos, Dimension, World.Regions); } //Log breaking blocks to determine if they found the diamond if (pd.Status == PlayerDigging.StatusEnum.FinishedDigging) OreTracker.BrokeBlock = DateTime.Now; if (pd.Status == PlayerDigging.StatusEnum.ShootArrow) Charge = null; //Prevent non admin creative from digging if (Mode == GameMode.Creative && Player.Admin() == false) return; if (FilterDirection(pd.Position)) return; if (Protected.ProtectBlockBreak(this, region, pd)) return; break; case WindowClick.ID: var wc = packet as WindowClick; if (wc.WindowID == 0) { //TODO: handle } //AfkTime = DateTime.Now; if (Protected.ProtectChestsClick(this, wc)) return; ///Workaround bug clicky items duplication if (wc.Item != null) { if (wc.Item.Count > 64) return; } break; case WindowCloseClient.ID: WindowClose((WindowCloseClient)packet); break; } if (region != null) { if (region.Type == SpawnRegion.Type) if (SpawnRegion.FilterClient(Player, packet)) return; if (region.Type == SpawnTimeRegion.Type) if (SpawnTimeRegion.FilterClient(region, Player, packet)) return; } SendToBackend(packet); }