Exemplo n.º 1
0
    // rematch button for Completed Challenges
    void OnCompleteChallengeItemRematchClick(ChallengeData challengeData)
    {
        //print ("OnCompleteChallengeItemRematchClick() " + challengeData.username + " a: " + challengeData.auth);
        GameControl.instance.soundManager.PlayLowToneButton();

        GameControl.instance.selectedChallengedPlayer = new PlayerData();

        string displayName = "";

        if (challengeData.username == GameControl.instance.username)
        {
            displayName = challengeData.frienduser;
            GameControl.instance.selectedChallengedPlayer.email = challengeData.friendemail;
        }
        else
        {
            displayName = challengeData.username;
            GameControl.instance.selectedChallengedPlayer.email = challengeData.useremail;
        }

        GameControl.instance.selectedResource = challengeData.resourceid;

        // "caticons/02_Performance_Tires/T_icon_C13_Potenza_RE970AS_normal.png"
        GameControl.instance.selectedResourceIconPath = GetIconFromGameDataByResourceID(challengeData.resourceid);

        //print ("challengeData.resourceid: " + challengeData.resourceid);
        //print ("GameControl.instance.selectedResourceIconPath: " + GameControl.instance.selectedResourceIconPath);

        _modalPanel.Choice("Play again with", displayName.Split(' ')[0] + "?", _mRematchChallengeYesAction, _mChallengeNoAction);
    }
Exemplo n.º 2
0
        public static void MontaArquivo(ChallengeData challengeData)
        {
            string caminhoArquivo = $"{ Environment.CurrentDirectory }/answer.json";
            string jsonString     = JsonSerializer.Serialize(challengeData);

            File.WriteAllText(caminhoArquivo, jsonString);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Receives the challenge and responds with a Connect request
        /// </summary>
        /// <param name="packet">The packet.</param>
        private void ReceiveChallenge(UdpPacket packet)
        {
            if (state != State.ChallengeReqSent)
            {
                return;
            }

            ChallengeData cr = new ChallengeData();

            cr.Deserialize(packet.Payload);

            ConnectData cd = new ConnectData();

            cd.ChallengeValue = cr.ChallengeValue ^ ConnectData.CHALLENGE_MASK;

            MemoryStream ms = new MemoryStream();

            cd.Serialize(ms);
            ms.Seek(0, SeekOrigin.Begin);

            SendSequenced(new UdpPacket(EUdpPacketType.Connect, ms));

            state        = State.ConnectSent;
            inSeqHandled = packet.Header.SeqThis;
        }
Exemplo n.º 4
0
 private void OpenChallengeAction(ChallengeData challengeData)
 {
     currentChallengeData            = challengeData;
     challengeDecriptionImage.sprite = challengeData.DescriptionIcon;
     challengeView.Initialize(challengeData);
     canvasControllerView.Show();
 }
Exemplo n.º 5
0
        public async Task <ChallengeProgressData> CheckProgress(double lat, double @long)
        {
            UserSession session = await Database.UserSessions.FromSignalRId(Context.UserIdentifier);

            User      user            = session.User;
            Challenge chal            = user.GroupMember.Group.Challenge;
            var       geometryFactory = NtsGeometryServices.Instance.CreateGeometryFactory();

            var nPoint = geometryFactory.CreatePoint(new Coordinate(lat, @long));
            var fPoint = geometryFactory.CreatePoint(chal.LongLat.Coordinates.FirstOrDefault());

            double dist   = nPoint.Distance(fPoint);
            double scaled = dist / chal.Radius;

            if (dist <= 10)
            {
                user.GroupMember.IsDone = true;
                await Clients.Caller.FinishChallenge();

                if (user.GroupMember.Group.GroupMembers.All(b => b.IsDone))
                {
                    Challenge newChal = await user.GroupMember.Group.GetNewChallenge(Database.Challenges);

                    ChallengeData cData = new ChallengeData(newChal.Id.ToString(), newChal.Description, newChal.Points, newChal.ImageJPG.ToString());
                    await Clients.Group(user.GroupMember.Group.SignalRId).UpdateChallenge(cData);
                }
            }

            return(new ChallengeProgressData(nPoint.Distance(fPoint).ToString(), scaled));
        }
 public static Challenge MapToEntity(this ChallengeData data, User user, string code)
 {
     return(new Challenge
     {
         Cables = data.Cables.Select(map => new ChallengeCable
         {
             CableColor = (eCableColor)map.CableId,
             Order = map.Order
         }).ToList(),
         Commands = data.Commands.Select(map => new ChallengeCommand
         {
             Command = (eCommand)map.CommandId
         }).ToList(),
         ConectionType = (eConectionType)data.ConnectionTypeId,
         Description = data.Description,
         Elements = data.Elements.Select(map => new ChallengeElement
         {
             Element = (eElement)map.ElementId,
             Quantity = map.Quantity
         }).ToList(),
         NetType = (eNetType)data.NetTypeId,
         Title = data.Title,
         UserId = user.Id,
         Code = code
     });
 }
        private void CreateChallenges(ChallengeData challenegeData)
        {
            GameObject geo = Instantiate(challengePrefab, challengesParent);
            CreatedChallengeUIController challenegeController = geo.GetComponent <CreatedChallengeUIController>();

            challenegeController.SetupChallenge(challenegeData);
        }
Exemplo n.º 8
0
    void OnChallengeAcceptedComplete(bool success, ChallengeData info)
    {
        HideBlackLoaderPanel();

        GameControl.instance.OnChallengeAcceptedComplete -= OnChallengeAcceptedComplete;

        /*Debug.Log("OnChallengeAcceptedComplete success: " + success);
         * Debug.Log("OnChallengeAcceptedComplete resourceid: " + info.resourceid);
         * Debug.Log("OnChallengeAcceptedComplete friendaccepted: " + info.friendaccepted);
         * Debug.Log("OnChallengeAcceptedComplete friendcompleted: " + info.friendcompleted);*/

        GameControl.instance.selectedResource         = info.resourceid;
        GameControl.instance.selectedResourceIconPath = GetIconFromGameDataByResourceID(info.resourceid);

        if (success)         // first time accepting challenge check
        {
            _modalPanel.Choice("Challenge Accepted", "Play Now?", _mChallengeAcceptedPlayNowYesAction, _mChallengeNoAction);
        }
        else                               // it will fail if we already accepted previously
        {
            if (info.friendcompleted == 1) // check if we already played
            {
                // Debug.Log("Challenge Completed");
            }
            else             // If we are here, this means user already accepted challenge
            {
                // _modalPanel.Choice ("Challenge Already Accepted", "Play Now?", _mChallengeYesAction, _mChallengeNoAction);
            }
        }
    }
Exemplo n.º 9
0
 public static void OnChallengeDone(ChallengeData p_challenge, E_RESULT_STATE p_state, string p_talk)
 {
     challengeResultBox.Talk(p_talk);
     p_challenge.state = p_state;
     challengeButDict[p_challenge.name].RefreahState();
     PlayerPrefs.SetInt(p_challenge.name, (int)p_state);
 }
Exemplo n.º 10
0
    private void Start()
    {
        string         _lastChallengeName = PlayerPrefs.GetString("nowChallenge");
        ChallengeGroup _lastGroup         = null;
        ChallengeData  _lastChallenge     = null;

        foreach (var _group in challengeGroups)
        {
            foreach (var _challenge in _group.challenges)
            {
                if (_challenge.title == _lastChallengeName)
                {
                    _lastGroup     = _group;
                    _lastChallenge = _challenge;
                    break;
                }
            }
        }

        if (_lastChallenge != null)
        {
            ToChallenge(_lastGroup, _lastChallenge, true);
        }
        else
        {
            ToMenu(true);
        }
    }
Exemplo n.º 11
0
    public static void EditChallenge(ChallengeData p_challenge)
    {
        var _script = MonoScript.FromScriptableObject(p_challenge);

        AssetDatabase.OpenAsset(_script);
        EditorApplication.isPlaying = false;
    }
Exemplo n.º 12
0
        public static async Task UpdateChallengesDB()
        {
            var collec = DatabaseConnection.GetDb().GetCollection <ChallengeData>("ChallengeCollec");
            var count  = await collec.CountDocumentsAsync(new BsonDocument());

            var serverError = false;

            while (!serverError)
            {
                var json = "";
                using (System.Net.WebClient wc = new System.Net.WebClient())
                {
                    try
                    {
                        count++;
                        json = wc.DownloadString("https://api.axieinfinity.com/v1/battle/challenge/match/" + count.ToString());
                    }
                    catch (Exception ex)
                    {
                        serverError = true;
                        continue;
                    }
                }
                JObject axieJson = JObject.Parse(json);
                JObject script   = JObject.Parse((string)axieJson["script"]);
                var     data     = new ChallengeData
                {
                    _id    = (int)axieJson["id"],
                    winner = (string)axieJson["winner"],
                    loser  = (string)axieJson["loser"],
                };
                await collec.InsertOneAsync(data);
            }
        }
Exemplo n.º 13
0
    void WriteJoystickResult(ChallengeData chData, StreamWriter sw)
    {
        float[]  averageTimeSpent = new float[4];
        float[]  averageFailures  = new float[4];
        double[] averageDistance  = new double[4];
        double[] averageArea      = new double[4];
        string   header           = "Attack,Average Time Spent,Average Failures,Average Distance,Average Area";

        sw.WriteLine("--------" + chData.name + "--------");
        sw.WriteLine(header);

        for (int i = 0; i < 4; i++)
        {
            int attackID = LogParser.ReorderAttackID(i);
            averageTimeSpent[attackID] = chData.totalTimeSpent[attackID] / (
                chData.attempts[attackID] - chData.failures[attackID]
                );
            averageFailures[attackID] = (float)chData.failures[attackID] / chData.attempts[attackID];
            averageDistance[attackID] = chData.totalDistance[attackID] / chData.attempts[attackID];
            averageArea[attackID]     = chData.totalArea[attackID] / chData.attempts[attackID];

            string line = LogParser.AttackIDToName(attackID) + ",";
            line += averageTimeSpent[attackID].ToString(usCulture) + ",";
            line += averageFailures[attackID].ToString(usCulture) + ",";
            line += averageDistance[attackID].ToString(usCulture) + ",";
            line += averageArea[attackID].ToString(usCulture);
            sw.WriteLine(line);
        }
    }
Exemplo n.º 14
0
        /// <summary>
        /// Create the challenge from user with role = teacher
        /// </summary>
        /// <param name="data"></param>
        /// <param name="userName"></param>
        /// <returns></returns>
        public ResponseData Create(ChallengeData data, string userName)
        {
            var user = _userRepository.FindByCondition(f => f.Email.ToUpper().Trim().Equals(userName.ToUpper().Trim()) && f.IsActive && f.Role == Domain.Entities.eRole.Teacher).FirstOrDefault();

            if (user != null)
            {
                _challengeRepository.Create(data.MapToEntity(user, RandomCode(10, new Random(), true)));
                if (_challengeRepository.Save())
                {
                    return(new ResponseData
                    {
                        Result = true,
                        Message = string.Format(ResponseMessages.MsgSaveSuccess, _entity)
                    });
                }
                else
                {
                    return(new ResponseData
                    {
                        Result = false,
                        Message = string.Format(ResponseMessages.MsgSaveError, _entity)
                    });
                }
            }
            return(new ResponseData
            {
                Result = false,
                Message = string.Format(ResponseMessages.MsgSaveError, _entity)
            });
        }
Exemplo n.º 15
0
 public void Init(Main_ChallengeViewer parent, Json_Challenge_ListNode mySaveData, ChallengeData myData)
 {
     _ParentComponent = parent;
     _mySaveData      = mySaveData;
     _myData          = myData;
     UpdateView();
 }
Exemplo n.º 16
0
 void RunChallenge(ChallengeData p_challenge)
 {
     if (runChallengeCoroutine != null)
     {
         StopCoroutine(runChallengeCoroutine);
     }
     runChallengeCoroutine = StartCoroutine(IeRunChallenge(p_challenge));
 }
Exemplo n.º 17
0
    void OnChallengeIgnoredComplete(bool success, ChallengeData info)
    {
        GameControl.instance.OnChallengeIgnoredComplete -= OnChallengeIgnoredComplete;

        HideBlackLoaderPanel();

        StartCoroutine(ResetContent());
    }
Exemplo n.º 18
0
    //public int index { get; private set; }

    public void init(ChallengeGroup p_group, ChallengeData p_challenge)
    {
        challenge  = p_challenge;
        group      = p_group;
        title.text = string.Format("{0:00} ", challenge.index) + challenge.title;
        RefreahState();
        MainManager.challengeButDict.Add(p_challenge.name, this);
    }
Exemplo n.º 19
0
 public static void ToChallenge(ChallengeGroup p_group, ChallengeData p_challenge, bool p_Immediately = false)
 {
     state = E_STATE.Challenge;
     challengeResultBox.ClearResult();
     challengeView.Show(p_group, p_challenge);
     instance.RunChallenge(p_challenge);
     PlayerPrefs.SetString("nowChallenge", p_challenge.title);
     instance.animator.Play("ToChallenge", 0, p_Immediately ? 1 : 0);
 }
Exemplo n.º 20
0
 public IActionResult AddElement(ChallengeData data)
 {
     ModelState.Clear();
     if (data.ElementId.HasValue && data.ElementId.Value > 0 && data.Quantity.HasValue && data.Quantity > 0)
     {
         _challengeService.AddElement(data);
     }
     return(PartialView("_Element", data));
 }
Exemplo n.º 21
0
 public IActionResult AddCommand(ChallengeData data)
 {
     ModelState.Clear();
     if (data.CommandId.HasValue && data.CommandId.Value > 0)
     {
         _challengeService.AddCommand(data);
     }
     return(PartialView("_Command", data));
 }
Exemplo n.º 22
0
 public void AddCommand(ChallengeData data)
 {
     data.Commands.Add(new CommandCableData
     {
         CommandId = data.CommandId.Value,
         Name      = ((eCommand)data.CommandId.Value).GetAttribute <DescriptionAttribute>().Description
     });
     data.CommandId = null;
 }
Exemplo n.º 23
0
    // ignore button for New Challenges
    void OnNewChallengeItemIgnoreClick(ChallengeData challengeData)
    {
        // print ("OnNewChallengeItemIgnoreClick() " + challengeData.username + " a: " + challengeData.auth);
        GameControl.instance.soundManager.PlayLowToneButton();

        GameControl.instance.challengeAuth = challengeData.auth;

        _modalPanel.Choice("Ignore game with", challengeData.username.Split(' ')[0] + "?", _mIngoreChallengeYesAction, _mChallengeNoAction);
    }
 private void StartChallengeAction(ChallengeData challengeData)
 {
     restartButton.SetActive(false);
     finishButton.SetActive(true);
     currentChallengeData = challengeData;
     challengeView.Initialize(challengeData);
     canvasControllerView.Show();
     StartTimer(challengeData.Duration);
 }
Exemplo n.º 25
0
 public IActionResult AddCable(ChallengeData data)
 {
     ModelState.Clear();
     if (data.CableId.HasValue && data.CableId.Value > 0 && data.Order.HasValue && data.Order > 0)
     {
         _challengeService.AddCable(data);
     }
     return(PartialView("_Cable", data));
 }
Exemplo n.º 26
0
 public IActionResult Create(ChallengeData data)
 {
     if (ModelState.IsValid)
     {
         TempData.Put("RESPONSE", _challengeService.Create(data, User.Identity.Name));
         return(RedirectToAction("Index"));
     }
     LoadReferences();
     return(View(data));
 }
Exemplo n.º 27
0
 public void AddElement(ChallengeData data)
 {
     data.Elements.Add(new ChallengeElementData
     {
         ElementId = data.ElementId.Value,
         Name      = ((eElement)data.ElementId.Value).GetAttribute <DescriptionAttribute>().Description,
         Quantity  = data.Quantity.Value
     });
     data.Quantity  = null;
     data.ElementId = null;
 }
Exemplo n.º 28
0
    // Save the challenge data to a path
    public static void SaveChallengeData(bool[] statuses, float distance)
    {
        BinaryFormatter formatter = new BinaryFormatter();
        string          path      = Path.Combine(Application.persistentDataPath, "ChallengeData");

        using (FileStream stream = new FileStream(path, FileMode.Create))
        {
            ChallengeData data = new ChallengeData(statuses, distance);
            formatter.Serialize(stream, data);
        }
    }
Exemplo n.º 29
0
    // Reset the challenge data of a path
    public static void ResetChallengeData()
    {
        string path = Path.Combine(Application.persistentDataPath, "ChallengeData");

        using (FileStream stream = new FileStream(path, FileMode.Create))
        {
            BinaryFormatter formatter = new BinaryFormatter();

            ChallengeData data = new ChallengeData();
            formatter.Serialize(stream, data);
        }
    }
Exemplo n.º 30
0
 public void AddCable(ChallengeData data)
 {
     data.Cables.Add(new ChallenteCableData
     {
         CableId = data.CableId.Value,
         Name    = ((eCableColor)data.CableId.Value).GetAttribute <DescriptionAttribute>().Description,
         Order   = data.Order.Value
     });
     data.Cables  = data.Cables.OrderBy(o => o.Order).ToList();
     data.Order   = null;
     data.CableId = null;
 }
Exemplo n.º 31
0
    void Awake()
    {
        if (!mInstance)
            mInstance = this;
        else
        {
            Destroy(this.gameObject);
            return;
        }

        DontDestroyOnLoad(this.gameObject);

        loginManager = GetComponent<LoginManager>();
        facebookFriends = GetComponent<FacebookFriends>();
        userData = GetComponent<UserData>();
        userHiscore = GetComponent<UserHiscore>();
        ranking = GetComponent<Ranking>();
        challengesManager = GetComponent<ChallengersManager>();
        challengeData = GetComponent<ChallengeData>();
        userData.Init();
    }