Example #1
0
        public void InitTargetBullet(TargetBullet _this,
                                     ObjCharacter caster,
                                     BulletRecord tbbullet,
                                     int nLevel,
                                     eSkillHitType hitType,
                                     ObjCharacter target)
        {
            _this.Type        = 0;
            _this.Caster      = caster;
            _this.Target      = target;
            _this.TableBullet = tbbullet;
            _this.HitType     = hitType;
            foreach (var i in tbbullet.Buff)
            {
                _this.Buff[i] = nLevel;
            }
            double delaytime = (_this.Caster.GetPosition() - _this.Target.GetPosition()).Length() /
                               _this.TableBullet.Speed;
            var DelaySecond = (int)(delaytime * 1000);

            DelaySecond = DelaySecond - 100; //减去100毫秒的延迟
            DelaySecond = DelaySecond + tbbullet.ShotDelay;
            if (DelaySecond > 300)
            {
                _this.ArriveTrigger = SceneServerControl.Timer.CreateTrigger(DateTime.Now.AddMilliseconds(DelaySecond),
                                                                             () => { _this.DelayArrive(); });
                target.PushBullet(_this);
                //CoroutineFactory.NewCoroutine(TimeTrigger).MoveNext();
                Logger.Info("TargetBullet From={0} To={1} Bullet={2}", _this.Caster.ObjId, target.ObjId, tbbullet.Id);
                caster.BroadcastShootBullet(tbbullet.Id, caster.ObjId, target.ObjId, tbbullet.ShotDelay);
            }
            else
            {
                caster.BroadcastShootBullet(tbbullet.Id, caster.ObjId, target.ObjId, tbbullet.ShotDelay);
                var hitResult = _this.Caster.Attr.GetHitResult(_this.Target, _this.HitType);
                if (DelaySecond > 0)
                {
                    foreach (var i in _this.Buff)
                    {
                        _this.Target.AddBuff(i.Key, i.Value, _this.Caster, DelaySecond, hitResult, _this.Modify);
                    }
                }
                else
                {
                    foreach (var i in _this.Buff)
                    {
                        _this.Target.AddBuff(i.Key, i.Value, _this.Caster, 0, hitResult, _this.Modify);
                    }
                }
            }
        }