Exemplo n.º 1
0
 protected override void Start()
 {
     base.Start();
     _currentEventData   = currentEventData [0];
     _availableEventData = availableEventData [0];
     SetBannerForEvent();
 }
        public List <EventStateData> GetCurrentEvents()
        {
            List <EventConfigData> availableEvents = GetAvailableEvents();

            if (availableEvents.Count == 0)
            {
                _currentEvents.Clear();
                return(_currentEvents);
            }

            List <EventStateData> unConcludedEvents = eventStateModel.GetUnConcludedEvents();
            EventStateData        currEvent         = unConcludedEvents.FirstOrDefault(ev => ev.id == availableEvents[0].id);

            // Avoid creating a new list for performance reasons, optimized for running on update:

            if (currEvent == null)
            {
                _currentEvents.Clear();
                return(_currentEvents);
            }

            if (_currentEvents.Count == 0)
            {
                _currentEvents.Add(currEvent);
            }
            else
            {
                _currentEvents[0] = currEvent;
            }

            return(_currentEvents);
        }
        public void UpdateEventScore(string eventID, int score)
        {
            EventStateData eventData = eventStateModel.GetEvent(eventID);

            if (eventData.score < score)
            {
                eventData.score = score;
                eventStateModel.SaveEvent(eventData);

                logger.Log(Tag, String.Format("Updated Event:{0} score:{1}", eventID, score));
            }
        }
Exemplo n.º 4
0
        public ISharedData Clone()
        {
            var c = new EventStateData();

            c.id               = id;
            c.score            = score;
            c.progressionIndex = progressionIndex;
            c.playerName       = playerName;
            c.bucket           = bucket;
            c.isConcluded      = isConcluded;

            return(c);
        }
        public IPromise <EventStateData> RegisterToEvent(string eventID)
        {
            var promise = new Promise <EventStateData>();

            Action <ConnectionHandler.RequestResult, string> HandleRegisterToEventResponse = (ConnectionHandler.RequestResult result, string response) => {
                logger.Log(Tag, "HandleRegisterToEventResponse (result=" + result + ")\nresponse=" + response);

                if (result != ConnectionHandler.RequestResult.Ok)
                {
                    modelSyncService.HandleErrorResponse(result, response);
                    promise.Reject(new Exception(response));
                    return;
                }

                // Parse the response and save the event to db

                JsonData data = JsonMapper.ToObject(response);
                string   id   = data ["id"].ToString();
                Debug.Log("Saving sharedItem: table=" + TableName + " id=" + id + " data=" + data.ToJson().SSubstring(200));
                gameDB.SaveSharedState(TableName, id, data.ToJson());

                syncSharedStateSignal.Dispatch(new List <string> {
                    TableName
                });

                EventStateData eventStateData = eventStateModel.GetEvent(id);
                if (eventStateData == null)
                {
                    logger.LogError(Tag, "HandleRegisterToEventResponse : Could not load new registered event");
                    promise.Reject(new Exception("Could not load event"));
                    return;
                }


                promise.Resolve(eventStateData);
            };

            _coroutineFactory.StartCoroutine(() => connectionHandler.SendRequest(ConnectionHandler.RequestType.EventSystemRegistration, HandleRegisterToEventResponse, eventID, null));
            return(promise);
        }