private void OnShotHit(ShotHit e) { if (e.Target.Equals(_owner)) { Add(e.DamageAmount.ToString()); } }
public void HandleShotEnd(ServerPlayer sender, MsgShotEnd shotMessage) { ShotInfo shot = FindShot(shotMessage.PlayerID, shotMessage.ShotID); if (shot == null) { return; } bool valid = false; if (sender.Info.ShotImmunities > 0) { sender.Info.ShotImmunities--; valid = true; } if (shot.ShotType == ShotTypes.ThiefShot || shot.ShotType == ShotTypes.GuidedShot) { valid = true; } if (!valid) // don't penalize them for sending this, they just always send it { return; // we know that all other cases must be followed by a death to be valid, so just remove the shot then. } Flags.HandlePlayerTakeHit(sender, shot.Owner, shot); ShotHit?.Invoke(this, shot); EndShot(shot, shotMessage.Exploded); }
private void OnShotHit(ShotHit e) { _shots.Add(new HitShotVisual( new RectangleTexture(UiColors.Gunshot).Create(), CalculateTransform(e.Attacker, e.Target, _random.Next(-10, 10) * 0.001), e.Attacker, e.Target)); }
public void Shoot(Vector3 position, Vector3 dir) { Ray ray = new Ray(position, Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, float.MaxValue)) { ShotHit?.Invoke(hit.collider.gameObject); } }
public void TakeDamage(ShotHit shot) { if (!isImmune) { if (shot.thisShot == ShotHit.ShotType.Normal) { health -= shot.damage; } else if (shot.thisShot == ShotHit.ShotType.Fire) { StartCoroutine(DoT(shot.damage)); } else if (shot.thisShot == ShotHit.ShotType.Poison) { StartCoroutine(DoT(shot.damage)); } else if (shot.thisShot == ShotHit.ShotType.Slow) { StartCoroutine(Slowed()); } else if (shot.thisShot == ShotHit.ShotType.Fear) { print("fear hit"); //enemy runs from player } else if (shot.thisShot == ShotHit.ShotType.Change) { if (this.gameObject.tag != "Boss") { StartCoroutine(Changed()); } } else if (shot.thisShot == ShotHit.ShotType.Betray) { print("betray hit"); //enemy attacks other enemies } else if (shot.thisShot == ShotHit.ShotType.Death) { if (this.gameObject.tag != "Boss") { health = 0; } } } if (health <= 0) { Die(); } }
public void RemoveShotForDeath(ServerPlayer player, int killerID, int shotID) { ShotInfo shot = FindShot(killerID, shotID); if (shot == null) { shot = FindUndeadShot(killerID, shotID); if (shot == null) { Logger.Log1("Player " + player.Callsign + " killed by unknown shot"); return; } } else { EndShot(shot, false); } ShotHit?.Invoke(this, shot); ShotKilled?.Invoke(this, new ShotHitArgs(shot, player)); }
private static Vector3D[] CalculateVelocites(Point3D[] centers, ShotHit[] hits, double hullRadius, ExplosionForceOptions options) { Vector3D[] retVal = new Vector3D[centers.Length]; foreach (var hit in hits) { Point3D shotStart = hit.Hit.Item1; if (options.InteriorVelocityCenterPercent != null) { shotStart += ((hit.Hit.Item2 - hit.Hit.Item1) * options.InteriorVelocityCenterPercent.Value); } Vector3D[] velocities = DistributeForces(centers, shotStart, hit.Shot.Item2 * (hit.Shot.Item3 * options.ShotMultiplier), hullRadius, options); for (int cntr = 0; cntr < retVal.Length; cntr++) { retVal[cntr] += velocities[cntr]; } } return retVal; }
private static Vector3D[] GetVelocities(ExplosionForceShard[] hullShards, ShotHit[] hits, double hullRadius, ExplosionForceOptions options) { //TODO: When the asteroid shards aren't resmoothed, the velocities are very small // //Maybe add more orth velocity // //Maybe pull the hit source slightly into the asteroid --- done // //Maybe add some random velocity (size proportional to the velocity) --- done Vector3D[] retVal = CalculateVelocites(hullShards.Select(o => o.Center_ParentCoords).ToArray(), hits, hullRadius, options); if (options.RandomVelocityPercent != null) { retVal = retVal. Select(o => o + Math3D.GetRandomVector_Spherical(o.Length * options.RandomVelocityPercent.Value)). ToArray(); } return retVal; }
public static Point3D[] GetVoronoiCtrlPoints(ShotHit[] hits, ITriangle[] convexHull, int maxCount = 33) { const int MIN = 5; Random rand = StaticRandom.GetRandomForThread(); #region examine hits Tuple<int, double>[] hitsByLength = hits. Select((o, i) => Tuple.Create(i, (o.Hit.Item2 - o.Hit.Item1).Length)). OrderByDescending(o => o.Item2). ToArray(); double totalLength = hitsByLength.Sum(o => o.Item2); Tuple<int, double>[] hitsByPercentLength = hitsByLength. Select(o => Tuple.Create(o.Item1, o.Item2 / totalLength)). ToArray(); #endregion #region define control point cones var aabb = Math3D.GetAABB(convexHull); double aabbLen = (aabb.Item2 - aabb.Item1).Length; double entryRadius = aabbLen * .05; double exitRadius = aabbLen * .35; double maxAxisLength = aabbLen * .75; int count = hits.Length * 2; count += (totalLength / (aabbLen * .1)).ToInt_Round(); if (count > maxCount) { count = maxCount; } #endregion #region randomly pick control points // Keep adding rings around shots until the count is exceeded var sets = new List<Tuple<int, List<Point3D>>>(); int runningSum = 0; // Make sure each hit line gets some points for (int cntr = 0; cntr < hits.Length; cntr++) { AddToHitline(ref runningSum, sets, cntr, hits[cntr].Hit, entryRadius, exitRadius, maxAxisLength, rand); } // Now that all hit lines have points, randomly choose lines until count is exceeded while (runningSum < count) { var pointsPerLength = hitsByLength. Select(o => { var pointsForIndex = sets.FirstOrDefault(p => p.Item1 == o.Item1); int countForIndex = pointsForIndex == null ? 0 : pointsForIndex.Item2.Count; return Tuple.Create(o.Item1, countForIndex / o.Item2); }). OrderBy(o => o.Item2). ToArray(); double sumRatio = pointsPerLength.Sum(o => o.Item2); var pointsPerLengthNormalized = pointsPerLength. Select(o => Tuple.Create(o.Item1, o.Item2 / sumRatio)). ToArray(); int index = UtilityCore.GetIndexIntoList(rand.NextPow(3), pointsPerLengthNormalized); AddToHitline(ref runningSum, sets, index, hits[index].Hit, entryRadius, exitRadius, maxAxisLength, rand); } #endregion #region remove excessive points while (runningSum > count) { Tuple<int, double>[] fractions = sets. Select((o, i) => Tuple.Create(i, o.Item2.Count.ToDouble() / runningSum.ToDouble())). OrderByDescending(o => o.Item2). ToArray(); int fractionIndex = UtilityCore.GetIndexIntoList(rand.NextPow(1.5), fractions); //nextPow will favor the front of the list, which is where the rings with the most points are int setIndex = fractions[fractionIndex].Item1; sets[setIndex].Item2.RemoveAt(UtilityCore.GetIndexIntoList(rand.NextDouble(), sets[setIndex].Item2.Count)); runningSum--; } #endregion #region ensure enough for voronoi algorithm List<Point3D> retVal = new List<Point3D>(); retVal.AddRange(sets.SelectMany(o => o.Item2)); // The voronoi algrorithm fails if there aren't at least 5 points (really should fix that). So add points that are // way away from the hull. This will make the voronoi algorithm happy, and won't affect the local results if (count < MIN) { retVal.AddRange( Enumerable.Range(0, MIN - count). Select(o => Math3D.GetRandomVector_Spherical_Shell(aabbLen * 20).ToPoint()) ); } #endregion return retVal.ToArray(); }
private void OnShotHit(ShotHit obj) { Sound.SoundEffect($"SFX/shot-hit-1.wav", DefaultVolume).Play(); }
private void OnShotHit(ShotHit e) => e.Target.Notify(e);
internal void Notify(ShotHit e) => State.RemainingHealth -= e.DamageAmount;
void Awake() { shotHit = GetComponent<ShotHit> (); myRenderer = GetComponent<SpriteRenderer> (); defaultShotSpeed = shotSpeed; }