Example #1
0
    public bool IsIWin(SamuraiBLEAPI.FullUserFightResult fightResult)
    {
        if (fightResult.localResult.TimeOffset > fightResult.oppositeResult.TimeOffset)
        {
            if (fightResult.localResult.TimeOffset  < 0)
            {
                return true;
            }
            else
            {
                return false;
            }

        }
        else
        {
            if (fightResult.localResult.TimeOffset < 0)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
    }
Example #2
0
    public void UpdateFightState(SamuraiBLEAPI.FullUserFightResult fightResult,System.Action done = null)
    {
        ParseUser.LogInAsync ("client", "2adixrxl").ContinueWith (t =>
        {
            if (t.IsFaulted || t.IsCanceled)
            {
                Debug.Log ("Failed:" + t.Exception);
            }
            else
            {
                Debug.Log ("Login Success:"+UserID.Value);

                ParseObject.GetQuery("Fighter").WhereEqualTo("objectId",UserID.Value).FirstAsync().ContinueWith((Task<ParseObject> result)=>
                {
                    Debug.Log("Find Fighter");

                    ParseObject fighter = result.Result;

                    fighter.Increment("fightCount");

                    if (IsIWin (fightResult))
                    {
                        fighter.Increment("winCount");
                    }

                    fighter ["firstFight"] = false;

                    if(fightResult.localResult.TimeOffset>0)
                    {
                        if(fighter.Get<float>("bestSpeed")>fightResult.localResult.TimeOffset || fighter.Get<int>("validateSlash") ==0)
                        {
                            fighter ["bestSpeed"] = fightResult.localResult.TimeOffset;
                        }

                        fighter ["aveSpeed"] = (fighter.Get<float>("aveSpeed") * fighter.Get<int>("validateSlash") + fightResult.localResult.TimeOffset)/(fighter.Get<int>("validateSlash") +1);

                        fighter.Increment("validateSlash");
                    }

                    fighter.SaveAsync().ContinueWith((Task t2)=>
                    {
                        Debug.Log("Server User Data Updated");

                        fightCount.Value = fighter.Get<int>("fightCount");
                        winCount.Value = fighter.Get<int>("winCount");
                        bestSpeed.Value = fighter.Get<float>("bestSpeed");
                        aveSpeed.Value = fighter.Get<float>("aveSpeed");
                        validateSlash.Value = fighter.Get<int>("validateSlash");

                        if(done!=null)done.Invoke();

                        dirty = true;

                    });

                });
            }
        });

        fightCount.Value ++;
        firstFight.Value = false;

        if (IsIWin (fightResult))
        {
            winCount.Value++;
        }

        if(fightResult.localResult.TimeOffset>0)
        {
            if(bestSpeed.Value>fightResult.localResult.TimeOffset || validateSlash.Value ==0)
            {
                bestSpeed.Value = fightResult.localResult.TimeOffset;
            }

            aveSpeed.Value = (aveSpeed.Value * validateSlash.Value + fightResult.localResult.TimeOffset)/(validateSlash.Value +1);
            validateSlash.Value++;
        }

        dirty = true;
    }