コード例 #1
0
ファイル: Prediction.cs プロジェクト: Esk0r/Ensage.Common
        public static void SpeedTrack(EventArgs args)
        {
            if (!Game.IsInGame || Game.IsPaused)
            {
                return;
            }
            var me = ObjectMgr.LocalHero;

            if (me == null)
            {
                return;
            }

            var heroes = ObjectMgr.GetEntities <Hero>();
            var tick   = Environment.TickCount;

            foreach (var unit in heroes)
            {
                var data =
                    TrackTable.FirstOrDefault(
                        unitData => unitData.UnitName == unit.Name || unitData.UnitClassID == unit.ClassID);
                if (data == null && unit.IsAlive && unit.IsVisible)
                {
                    data = new Prediction(unit.Name, unit.ClassID, new Vector3(0, 0, 0), 0, new Vector3(0, 0, 0), 0, 0);
                    TrackTable.Add(data);
                }
                if (data != null && (!unit.IsAlive || !unit.IsVisible))
                {
                    TrackTable.Remove(data);
                    continue;
                }
                if (data == null || (data.LastPosition != new Vector3(0, 0, 0) && !((tick - data.Lasttick) > 0)))
                {
                    continue;
                }
                if (data.LastPosition == new Vector3(0, 0, 0))
                {
                    data.LastPosition = unit.Position;
                    data.LastRotR     = unit.RotationRad;
                    data.Lasttick     = tick;
                }
                else
                {
                    data.RotSpeed = data.LastRotR - unit.RotationRad;
                    var speed = (unit.Position - data.LastPosition) / (tick - data.Lasttick);
                    if (Math.Abs(data.RotSpeed) > 0.05 && data.Speed != new Vector3(0, 0, 0))
                    {
                        data.Speed = unit.Vector3FromPolarAngle(data.RotSpeed) / (tick - data.Lasttick);
                    }
                    else
                    {
                        if (unit.Modifiers.Any(x => x.Name == "modifier_storm_spirit_ball_lightning"))
                        {
                            var ballLightning  = EntityExtensions.FindSpell(unit, "storm_spirit_ball_lightning");
                            var firstOrDefault =
                                ballLightning.AbilityData.FirstOrDefault(x => x.Name == "ball_lightning_move_speed");
                            if (firstOrDefault != null)
                            {
                                var ballSpeed = firstOrDefault.GetValue(ballLightning.Level - 1);
                                Console.WriteLine(ballSpeed);
                                var newpredict = unit.Vector3FromPolarAngle(data.RotSpeed) * (ballSpeed / 1000);
                                data.Speed = newpredict;
                            }
                        }
                        else if (unit.NetworkActivity != NetworkActivity.Move)
                        {
                            data.Speed = speed;
                        }
                        else
                        {
                            var newpredict = unit.Vector3FromPolarAngle(data.RotSpeed) * (unit.MovementSpeed / 1000);
                            data.Speed = newpredict;
                        }
                    }
                    var predict   = PredictedXYZ(unit, 1000);
                    var realspeed = predict.Distance2D(unit.Position);
                    if ((realspeed + 100 > unit.MovementSpeed) && unit.NetworkActivity != NetworkActivity.Move)
                    {
                        var newpredict = unit.Vector3FromPolarAngle() * (unit.MovementSpeed / 1000);
                        data.Speed = newpredict;
                    }
                    data.LastPosition = unit.Position;
                    data.LastRotR     = unit.RotationRad;
                    data.Lasttick     = tick;
                }
            }
        }