コード例 #1
0
 public override void setData(Dictionary <string, object> data)
 {
     this.radish   = (RadishEntity)this._map.getNetObject((int)data["radish"]);
     this.radishCD = (IntervalAction)this._map.getNetObject((int)data["radishCD"]);
     this.radishCD.intervalHandler = this.addPoint;
     base.setData(data);
 }
コード例 #2
0
        public void Common()
        {
            AutoResetEvent signal   = new AutoResetEvent(false);
            int            times    = 0;
            List <long>    elapseds = new List <long>();
            Stopwatch      temp     = new Stopwatch();
            IntervalAction action   = new IntervalAction(50, handle);

            signal.WaitOne();

            var average = elapseds.Average();

            var range = new NumericalRangeInt(50, 0.2f);

            Assert.IsTrue(range.Contains((int)average));


            void handle(IntervalAction sender)
            {
                times++;
                if (temp.IsRunning)
                {
                    elapseds.Add(temp.ElapsedMilliseconds);
                }
                temp.Restart();
                if (times >= 10)
                {
                    sender.Dispose();
                    signal.Set();
                }
            }
        }
コード例 #3
0
        public void Defaults()
        {
            var test = new IntervalAction();

            Assert.IsTrue(test.NotifyAfterSeconds > 0);
            Assert.IsTrue(test.NotifyAfterSeconds < 1);
        }
コード例 #4
0
 public override void init(RefereeController refereeController)
 {
     base.init(refereeController);
     this.radish = (RadishEntity)this._map.createFightEntity(ConfigConstant.ENTITY_RADISH);
     this.radish.initConfig((Dictionary <string, object>)ConfigConstant.combat["radish"]);
     this.radishCD    = new IntervalAction(this._map).init(ConfigConstant.RADISH_POINT_CD, int.MaxValue, this.addPoint);
     this.radishCD.cd = this.radishCD.interval;
 }
コード例 #5
0
        /// <summary>
        /// Startet den Timer
        /// </summary>
        public void Start()
        {
            //TODO: Verhindern dass der Timer mehrmals hintereinander gestartet wird!

            _currentThread = Dispatcher.CurrentDispatcher;

            if (_timerThread == null || _timerThread.ThreadState != ThreadState.Running)
            {
                _timerThread = new Thread(() =>
                {
                    while (MaxSteps == null || (_currentSteps < MaxSteps))
                    {
                        try
                        {
                            _cts?.Token.ThrowIfCancellationRequested();
                            Thread.Sleep(Interval);
                            _cts?.Token.ThrowIfCancellationRequested();


                            if (!InvokeAction)
                            {
                                IntervalAction?.Invoke();
                            }
                            else
                            {
                                _currentThread.Invoke(new Action(() => IntervalAction?.Invoke()));
                            }


                            _currentSteps++;
                        }
                        catch (OperationCanceledException)
                        {
                            return;
                        }
                    }

                    if (!InvokeAction)
                    {
                        FinishAction?.Invoke();
                    }
                    else
                    {
                        _currentThread.Invoke(new Action(() => FinishAction?.Invoke()));
                    }
                });

                _cts = new CancellationTokenSource();

                //Threads laufen standardmäßig im Vordergrund, d.h. sie werden nicht automatisch beendet
                //wenn der Main-Thread fertig ist
                _timerThread.IsBackground = IsBackground;

                _currentSteps = 0;

                _timerThread.Start();
            }
        }
コード例 #6
0
        public void InvokeLong()
        {
            var  test   = new IntervalAction();
            long called = -1;

            test.Invoke(delegate(long l) { called = l; }, 666);
            Assert.AreEqual(666L, called);
            test.Invoke(delegate(long l) { called = l; }, 669);
            Assert.AreNotEqual(669L, called);
        }
コード例 #7
0
        public void Invoke()
        {
            var test   = new IntervalAction();
            var called = false;

            test.Invoke(() => called = true);
            Assert.IsTrue(called);
            called = false;
            test.Invoke(() => called = true);
            Assert.IsFalse(called);
        }
コード例 #8
0
        public void InvokeTest()
        {
            var intervalAction = new IntervalAction();
            var called         = 0;

            // First Call ok
            intervalAction.Invoke(() => called++);
            Assert.AreEqual(1, called);
            // First Call This time its not called because time was not sufficient
            intervalAction.Invoke(() => called++);
            Assert.AreEqual(1, called);
        }
コード例 #9
0
        public void InvokeStringLong()
        {
            var  test    = new IntervalAction();
            long called  = -1;
            var  calledS = string.Empty;
            var  calledB = false;

            test.Invoke((s, l, arg3) =>
            {
                called  = l;
                calledS = s;
                calledB = arg3;
            }, "Hello", -10, true);
            Assert.AreEqual(-10L, called);
            Assert.AreEqual("Hello", calledS);
            Assert.AreEqual(true, calledB);
            test.Invoke((s, l, arg3) =>
            {
                called  = l;
                calledS = s;
                calledB = arg3;
            }, "World", -20, true);
            Assert.AreNotEqual("World", calledS);
        }
コード例 #10
0
 /// <summary>
 /// Remove an IntervalAction for a given interval if that callback is set
 /// </summary>
 /// <param name="callback">Ref to the IntervalAction to remove</param>
 public bool Remove (IntervalAction callback) {
     return IntervalActions.Remove(callback);
 }
コード例 #11
0
 /// <summary>
 /// Run callback action after interval seconds
 /// </summary>
 /// <param name="interval">Number of seconds to wait</param>
 /// <param name="callback">Action to perform after interval seconds</param>
 public void After (float interval, Action callback) {
     IntervalAction ia = new IntervalAction(interval, callback);
     ia.SelfDestruct = true;
     RegisterIntervalAction(ia);
 }
コード例 #12
0
 /// <summary>
 /// Run callback at every (float) interval
 /// </summary>
 /// <param name="interval">Interval (in high-precision part-seconds) to call callback on</param>
 /// <param name="callback">Callback to call</param>
 public void Every (float interval, Action callback) {
     IntervalAction ia = new IntervalAction(interval, callback);
     RegisterIntervalAction(ia);
 }
コード例 #13
0
 /// <summary>
 /// Set LastRunTime and register an IntervalAction
 /// </summary>
 /// <param name="action">IntervalAction to register</param>
 private void RegisterIntervalAction (IntervalAction action) {
     action.LastRunTime = timer;
     IntervalActions.Add(action);
 }
コード例 #14
0
    public override void initConfig(Dictionary <string, object> data = null)
    {
        if (data.ContainsKey("speed"))
        {
            this._speed = (int)(data["speed"]);
        }
        if (data.ContainsKey("accSpeed"))
        {
            this._accSpeed = (int)(data["accSpeed"]);
        }
        if (data.ContainsKey("atk"))
        {
            this.atk = (int)(data["atk"]);
        }
        if (data.ContainsKey("aoe"))
        {
            this._aoe = (int)(data["aoe"]);
        }
        if (data.ContainsKey("lifeTime"))
        {
            this._lifeTime = (int)(data["lifeTime"]);
        }
        if (data.ContainsKey("angle"))
        {
            this._angle = Math2.angleToRadian(Convert.ToSingle(data["angle"]));
        }
        if (data.ContainsKey("seek"))
        {
            this.seekData = (Dictionary <string, object>)data["seek"];
        }
        if (data.ContainsKey("backForce"))
        {
            this.backForce = (int)(data["backForce"]);
        }
        if (data.ContainsKey("preTime"))
        {
            this._preTime = (int)(data["preTime"]);
        }
        //bang伤害。
        if (data.ContainsKey("bangCount"))
        {
            this.bangCount = (int)(data["bangCount"]);
        }
        if (data.ContainsKey("bangRadiusMax"))
        {
            this.bangRadiusMax = (int)(data["bangRadiusMax"]);
        }
        if (data.ContainsKey("bangRateMax"))
        {
            this.bangRateMax = Convert.ToDouble(data["bangRateMax"]);
        }
        if (data.ContainsKey("bangRadiusMin"))
        {
            this.bangRadiusMin = (int)(data["bangRadiusMin"]);
        }
        if (data.ContainsKey("bangRateMin"))
        {
            this.bangRateMin = Convert.ToDouble(data["bangRateMin"]);
        }
        //zoom增幅。
        if (data.ContainsKey("zoomCount"))
        {
            this.zoomCount = (int)(data["zoomCount"]);
        }
        if (data.ContainsKey("zoomRadius"))
        {
            this.zoomRadius = (int)(data["zoomRadius"]);
        }
        if (data.ContainsKey("zoomDamage"))
        {
            this.zoomDamage = (int)(data["zoomDamage"]);
        }
        if (data.ContainsKey("zoomStun"))
        {
            this.zoomStun = (int)(data["zoomStun"]);
        }


        //检查障碍物。
        this.checkBarrier = Utils.equal(data, "checkBarrier", 1);
        this._repeat      = Utils.equal(data, "repeat", 1);

        if (null != seekData)
        {
            this.seekRange = Collision.createGeom(this, (object[])this.seekData["range"], (object[])this.seekData["offset"]);
        }
        this.atk = Mathf.CeilToInt(Convert.ToSingle(this.owner.getProperty(ConfigConstant.PROPERTY_ATK_RATE) * this.atk));

        this._shape = Collision.createGeom(this, (object[])data["range"]);

        if (this.zoomRadius != 0)
        {
            this.zoomScale = Convert.ToDouble(this.zoomRadius) / this._shape.radius;
        }

        if (data.ContainsKey("offset"))
        {
            Vector2D offset = Vector2D.createVector3((object[])data["offset"]);
            offset.angle += this.owner.angle;
            this._position.add(offset);
            offset.clear();
        }

        if (data.ContainsKey("reactionForce"))
        {
            this.owner.velocity.length = 1;
            this.owner.addForce(Vector2D.createVector2(Convert.ToSingle(data["reactionForce"]), Math.PI + this.owner.angle));
        }
        this.id          = "";
        this.ownerPlayer = this.owner.ownerPlayer;

        this.isFree = !Utils.equal(data, "posTarget", 1);
        PersonEntity target = this.isFree ? this.owner : this.lockTarget;

        this._angle += target.angle;
        this._position.add(target.position);
        //根据飞船大小 偏移。
        if (data.ContainsKey("offsetType") && (int)data["offsetType"] != 0)
        {
            Vector2D v = target.getVertexPosition((int)data["offsetType"]).clone();
            v.angle += target.angle;
            this._position.add(v);
            v.clear();
        }

        this._velocity.length = this._speed;
        this._velocity.angle  = this._angle;

        this.changeDir();
        //TODO:优化修改。
        this.applyPosition();
        //hitCd
        if (data.ContainsKey("hitCDMax"))
        {
            if (0 != (int)data["hitCDMax"])
            {
                this._hitAction = new IntervalAction(this._map).init((int)data["hitCDMax"], this._lifeTime, this.checkHit);
            }
        }
        else
        {
            this._hitAction = new IntervalAction(this._map).init(66 * 2, this._lifeTime, this.checkHit);
        }

        if (data.ContainsKey("bangCDMax"))
        {
            this._bombAction = new IntervalAction(this._map).init((int)data["bangCDMax"], this._lifeTime, this.bomb);
        }


        base.initConfig(data);
    }
コード例 #15
0
    public override void setData(Dictionary <string, object> data)
    {
        //this._lifeTime = Convert.ToSingle(data["lifeTime"]);
        if (data.ContainsKey("owner"))
        {
            this.owner = (PersonEntity)this._map.getNetObject((int)(data["owner"]));
        }

        this._speed    = (int)(data["speed"]);
        this._accSpeed = (int)(data["accSpeed"]);
        this.atk       = (int)(data["atk"]);
        this._aoe      = (int)(data["aoe"]);

        this.backForce = (int)(data["backForce"]);
        this._lifeTime = (int)(data["lifeTime"]);
        this._preTime  = (int)(data["preTime"]);
        if (data.ContainsKey("seekData"))
        {
            this.seekData = (Dictionary <string, object>)data["seekData"];
        }
        if (data.ContainsKey("seekTarget"))
        {
            this.seekTarget = (PersonEntity)this._map.getNetObject((int)(data["seekTarget"]));
        }
        if (data.ContainsKey("lockTarget"))
        {
            this.lockTarget = (PersonEntity)this._map.getNetObject((int)(data["lockTarget"]));
        }
        if (data.ContainsKey("seekRange"))
        {
            this.seekRange = (GeomBase)this._map.getNetObject((int)(data["seekRange"]));
        }
        if (data.ContainsKey("shallow"))
        {
            this.shallow = (BulletShallow)this._map.getNetObject((int)(data["shallow"]));
        }


        if (data.ContainsKey("hitAction"))
        {
            this._hitAction = (IntervalAction)this._map.getNetObject((int)(data["hitAction"]));
            this._hitAction.intervalHandler = this.checkHit;
        }
        if (data.ContainsKey("bombAction"))
        {
            this._bombAction = (IntervalAction)this._map.getNetObject((int)(data["bombAction"]));
            this._bombAction.intervalHandler = this.bomb;
        }
        this.hitList   = new List <object>((object[])data["hitList"]).ConvertAll <PersonEntity>((id) => { return((PersonEntity)this._map.getNetObject((int)id)); });
        this.bangCount = (int)data["bangCount"];

        this.bangRadiusMax = (int)data["bangRadiusMax"];
        this.bangRadiusMin = (int)data["bangRadiusMin"];
        this.zoomCount     = (int)data["zoomCount"];
        this.zoomRadius    = (int)data["zoomRadius"];
        this.zoomScale     = Convert.ToDouble(data["zoomScale"]);
        this.zoomDamage    = (int)data["zoomDamage"];
        this.zoomStun      = (int)data["zoomStun"];
        this.stun          = (int)data["stun"];

        base.setData(data);


        this.bangRateMax = Convert.ToDouble(this._data["bangRateMax"]);
        this.bangRateMin = Convert.ToDouble(this._data["bangRateMin"]);


        this.checkBarrier = Utils.equal(this._data, "checkBarrier", 1);
        this.isFree       = !Utils.equal(this._data, "posTarget", 1);
    }