public void Resolve(ResolverType type, Strike strike) { resolverType = type; GameObject whiteBall = ballsCollector.GetBall(BallIdentity.White); Rigidbody whiteBallRB = whiteBall.GetComponent <Rigidbody>(); if (type == ResolverType.Strike) { hitTracker = new HitTracker(); var whiteBallReflection = whiteBall.GetComponent <BallReflection>(); whiteBallReflection.onBallCollision += TrackScore; onResolved += (resolverType) => { whiteBallReflection.onBallCollision -= TrackScore; }; if (onStrikeStart != null) { onStrikeStart(); } } else if (type == ResolverType.Replay) { Time.timeScale = 0.8f; ballsCollector.Iterate((identity, ball) => { ball.transform.position = strike.GetBallStartingPosition(identity); }); if (onReplayStart != null) { onReplayStart(); } } whiteBallRB.AddForce(strike.StrikeForce, ForceMode.Impulse); StartCoroutine(WaitForForceToAddUp()); }
/// <summary> /// Applies damage to Life, kills creature if necessary. /// </summary> /// <param name="damage"></param> /// <param name="from"></param> public void TakeDamage(float damage, Creature from) { var lifeBefore = this.Life; this.Life -= damage; // Track hit if (from != null) { HitTracker tracker; lock (_hitTrackers) { // Create new tracker if there is none yet if (!_hitTrackers.TryGetValue(from.EntityId, out tracker)) _hitTrackers[from.EntityId] = (tracker = new HitTracker(this, from)); } tracker.RegisterHit(damage); _totalHits = Interlocked.Increment(ref _totalHits); } // Kill if life too low if (this.Life < 0 && !this.ShouldSurvive(damage, from, lifeBefore)) this.Kill(from); }
/// <summary> /// Applies damage to Life, kills creature if necessary. /// </summary> /// <param name="damage"></param> /// <param name="from"></param> public void TakeDamage(float damage, Creature from) { var lifeBefore = this.Life; this.Life -= damage; // Track hit if (from != null) { HitTracker tracker; lock (_hitTrackers) { // Create new tracker if there is none yet if (!_hitTrackers.TryGetValue(from.EntityId, out tracker)) { var newId = Interlocked.Increment(ref _hitTrackerIds); _hitTrackers[from.EntityId] = (tracker = new HitTracker(newId, this, from)); } } tracker.RegisterHit(damage); _totalHits = Interlocked.Increment(ref _totalHits); } // Update equip var mainArmors = this.Inventory.GetMainEquipment(a => a.Info.Pocket.IsMainArmor()); if (mainArmors.Length != 0) { // Select a random armor item to gain proficiency and lose // durability, as the one that was "hit" by the damage. var item = mainArmors.Random(); // Give proficiency var profAmount = Item.GetProficiencyGain(this.Age, ProficiencyGainType.Damage); this.Inventory.AddProficiency(item, profAmount); // Reduce durability var duraAmount = RandomProvider.Get().Next(1, 30); this.Inventory.ReduceDurability(item, duraAmount); } // Kill if life too low if (this.Life < 0 && !this.ShouldSurvive(damage, from, lifeBefore)) this.Kill(from); }
/// <summary> /// Applies damage to Life, kills creature if necessary. /// </summary> /// <param name="damage"></param> /// <param name="from"></param> public void TakeDamage(float damage, Creature from) { var lifeBefore = this.Life; this.Life -= damage; // Track hit if (from != null) { HitTracker tracker; lock (_hitTrackers) { // Create new tracker if there is none yet if (!_hitTrackers.TryGetValue(from.EntityId, out tracker)) { var newId = Interlocked.Increment(ref _hitTrackerIds); _hitTrackers[from.EntityId] = (tracker = new HitTracker(newId, this, from)); } } tracker.RegisterHit(damage); _totalHits = Interlocked.Increment(ref _totalHits); } var equip = this.Inventory.GetEquipment(); // Give proficiency to random main armor var mainArmors = equip.Where(a => a.Info.Pocket.IsMainArmor()); if (mainArmors.Count() != 0) { var item = mainArmors.Random(); var amount = Item.GetProficiencyGain(this.Age, ProficiencyGainType.Damage); this.Inventory.AddProficiency(item, amount); } // Reduce durability of random item if (!ChannelServer.Instance.Conf.World.NoDurabilityLoss) { if (equip.Length != 0) { var item = equip.Random(); var amount = RandomProvider.Get().Next(1, 30); this.Inventory.ReduceDurability(item, amount); } } // Kill if life too low if (this.Life < 0 && !this.ShouldSurvive(damage, from, lifeBefore)) this.Kill(from); }