Exemplo n.º 1
0
        private void OnErrorCallback(Error error)
        {
            DevLogger.Error(string.Format("Can't load {0} from API", Type));

            FormModel.Text = string.Format("Load text error:\n{0}", Type);
            View.SetLoadingState(false);
        }
Exemplo n.º 2
0
        public void Open(IGameIntegrationModel gameItems)
        {
            if (!IsInitialized)
            {
                DevLogger.Error("Initialize MarketWidget before use.", MarketLogType.MarketWidget);
                return;
            }

            if (gameItems == null)
            {
                DevLogger.Error("It's not impossible to Open MarketWidget. IGameIntegrationModel is null", MarketLogType.MarketWidget);
                return;
            }

            ApplyMarketStrategy();
            GameModel = gameItems;
            _formContainer.Run();
            var textPopUp = GetForm <MarketTextPopUp>();

            PopUpController.Initialize(textPopUp);
            _soundManager.IsRuning = true;

            View = GetForm <MarketView>();
            View.ApplyModel(Model);

            ApplyState <MarketOpeningState>();
        }
Exemplo n.º 3
0
        /*    public static TComponent InstantiateAndGetSafeComponent<TComponent>(
         *  this RelativeLinkToGameObject relativeLinkToGameObject,
         *  Vector3? position = null,
         *  Quaternion? rotation = null) where TComponent : MonoBehaviour
         * {
         *  GameObject go = relativeLinkToGameObject;
         *  return go.InstantiateAndGetSafeComponent<TComponent>(position, rotation);
         * }*/

        public static TComponent InstantiateAndGetSafeComponent <TComponent>(
            this GameObject objectToInstantiate,
            Vector3?position    = null,
            Quaternion?rotation = null) where TComponent : MonoBehaviour
        {
            if (objectToInstantiate != null)
            {
                GameObject o = UnityEngine.Object.Instantiate(
                    objectToInstantiate,
                    position != null ? position.Value : Vector3.zero,
                    rotation != null ? rotation.Value : Quaternion.identity);

                if (o != null)
                {
                    return(o.GetSafeComponent <TComponent>());
                }
            }
            else
            {
                DevLogger.Error(
                    string.Format("Instantiated object with component {0} is null", typeof(TComponent)),
                    LogChannel.Common);
            }

            DevLogger.Error("Couldn't instantiate object", LogChannel.Common);

            return(default(TComponent));
        }
Exemplo n.º 4
0
        public void MakeCall(RequestMethod method, string path, string data, Dictionary <string, string> headers, ApiCallCallback callback)
        {
            if (_baseHost == null)
            {
                DevLogger.Error(string.Format("Need initialize {0} before MakeCall",
                                              GetType()), MarketLogType.MarketApi);
                return;
            }
            var uri = new Uri(_baseHost, path);

            Log(string.Format("{0} request: {1} \n{2}", method.ToString().ToUpper(),
                              GetShortUrl(uri.ToString()), data));
            switch (method)
            {
            case RequestMethod.Get:
                StartCoroutine(MakeGet(uri, headers, callback, _apiSettings.UseDebug));
                break;

            case RequestMethod.Post:
                StartCoroutine(MakePost(uri, data, headers, callback, _apiSettings.UseDebug));
                break;

            case RequestMethod.Put:
                StartCoroutine(MakePut(uri, data, headers, callback, _apiSettings.UseDebug));
                break;

            default:
                throw new ArgumentOutOfRangeException("method", method, null);
            }
        }
Exemplo n.º 5
0
 public void AddItem(PlayerItemInfo item)
 {
     if (Items.Any(c => c.WorldId == item.WorldId))
     {
         DevLogger.Error("Item already in game inventory");
         return;
     }
     Items.Add(item);
 }
        private void CheckTransactionsStatuses()
        {
            if (_pendingOperations.Count == 0)
            {
                return;
            }

            var transactionIds = _pendingOperations.Keys;

            DMarketApi.CheckAsyncOperation(Model.GetPlayerMarketAccessToken(_connectionId), transactionIds.ToArray(),
                                           (response, request) =>
            {
                foreach (var item in response.Items)
                {
                    string itemAssetId    = item.assetId;
                    string operationId    = item.operationId;
                    var transactionStatus = _apiResponseAdapter.GetTransactionStatusType(item.status);

                    switch (transactionStatus)
                    {
                    case DMarketTransactionStatusType.Fail:
                        _pendingOperations.Remove(operationId);
                        DevLogger.Error(string.Format("Transaction for item: {0} was failed.", itemAssetId));
                        break;

                    case DMarketTransactionStatusType.Pending:
                        break;

                    case DMarketTransactionStatusType.Success:
                        _pendingOperations.Remove(operationId);
                        _successItemsIds.Add(itemAssetId);
                        break;
                    }
                }

                if (_pendingOperations.Count == 0)
                {
                    if (_actionType == ItemActionType.FromMarket)
                    {
                        AddMovedItemsToInventory();
                    }
                    else
                    {
                        RemoveMovedItemsFromInventory();
                    }

                    SendLoadInventoryData();
                    Terminate();
                }
            },
                                           error =>
            {
                _pendingOperations.Clear();;
                OnItemOperationError(error);
            });
        }
Exemplo n.º 7
0
 void IWidget.Open()
 {
     if ((this as IWidget).IsInitialize)
     {
         ApplyState <WidgetOpeningState>();
     }
     else
     {
         DevLogger.Error("Need initialize widget before opening");
     }
 }
Exemplo n.º 8
0
        protected static TPoolObject GetObjectOfType <TPoolObject>(PoolControllerBase instance)
            where TPoolObject : IPoolObject
        {
            if (instance != null)
            {
                return(instance.GetObject <TPoolObject>());
            }

            DevLogger.Error("Pool controller is not exists", LogChannel.Common);

            return(default(TPoolObject));
        }
Exemplo n.º 9
0
        public void EquipItem(long worldId)
        {
            if (EquippedItems.Contains(worldId))
            {
                DevLogger.Error(string.Format("Item with Id:{0} already equipped.", worldId));
                return;
            }
            PlayerItemInfo item = GetItem(worldId);

            TakeOffEquipItems(item.ItemCategory);
            EquippedItems.Add(worldId);
        }
Exemplo n.º 10
0
 public void Start(string serverIP, int port)
 {
     _currentClient = new NetworkClient();
     RegisterHandles();
     try
     {
         _currentClient.Connect(serverIP, port);
     }
     catch (Exception e)
     {
         DevLogger.Error(e.Message);
     }
 }
Exemplo n.º 11
0
 private static string GetCurrencySpriteName(string currency)
 {
     if (string.IsNullOrEmpty(currency))
     {
         return(string.Empty);
     }
     if (BindedCurrencyNames.ContainsKey(currency))
     {
         return(BindedCurrencyNames[currency]);
     }
     DevLogger.Error(string.Format("Currency {0} not binded", currency));
     return(string.Empty);
 }
Exemplo n.º 12
0
 public GameItemType GetItemType(string classId)
 {
     try
     {
         return((GameItemType)Enum.Parse(typeof(GameItemType), classId));
     }
     catch (Exception e)
     {
         DevLogger.Error("Cannot find game item type for " + classId
                         + " " + e.Message);
         return(GameItemType.Unknow);
     }
 }
Exemplo n.º 13
0
        public static AppMessageBase ReadAppMessage(NetworkMessage msg)
        {
            var type = (AppMsgType)msg.msgType;

            if (AppMsgHandlers.ContainsKey(type))
            {
                var result = AppMsgHandlers[type](msg);
                result.ConnectionId = msg.conn.connectionId;
                return(result);
            }

            DevLogger.Error("Have no receive method for " + type, DTanksLogChannel.Network);
            return(null);
        }
Exemplo n.º 14
0
        public void Open()
        {
            if (!IsInitialized)
            {
                DevLogger.Error("Initialize MarketWidget before use.");
                return;
            }

            _formContainer.Run();

            WidgetView = GetForm <BasicView>();
            WidgetView.ApplyModel(Model);

            ApplyState <BasicWidgetOpeningState>();
        }
Exemplo n.º 15
0
        public DMarketTransactionOperationType GetTransactionOperationType(string operationType)
        {
            switch (operationType)
            {
            case "toMarket":
                return(DMarketTransactionOperationType.ToMarket);

            case "fromMarket":
                return(DMarketTransactionOperationType.FromMarket);

            default:
                DevLogger.Error("Cannot parse transaction operation type: " + operationType);
                return(DMarketTransactionOperationType.FromMarket);
            }
        }
Exemplo n.º 16
0
        protected virtual void LoadFormItems()
        {
            ShowingItemsInfo showingItemsInfo = FormModel.ShowingItemsInfo;
            ItemModelType    modelType        = WidgetModel.CurrentItemType;

            Action <ShowingItemsInfo> loadAction;

            if (!_itemLoaders.TryGetValue(modelType, out loadAction))
            {
                DevLogger.Error(string.Format("Need add loader for {0}", modelType));
                return;
            }

            loadAction.SafeRaise(showingItemsInfo);
        }
Exemplo n.º 17
0
        public static Price operator -(Price p1, Price p2)
        {
            if (p1.Currency == p2.Currency)
            {
                var result = new Price
                {
                    Currency = p1.Currency,
                    Amount   = p1.Amount - p2.Amount
                };
                return(result);
            }

            DevLogger.Error("Cannot make operation [-] with different currency types");
            return(null);
        }
Exemplo n.º 18
0
        public static GameMessageBase ReadGameMessage(NetworkMessage msg)
        {
            var type = (GameMsgType)msg.msgType;

            if (_gameMsgHandlers.ContainsKey(type))
            {
                var result = _gameMsgHandlers[type](msg);
                result.ClientId = msg.conn.connectionId;
                return(result);
            }
            else
            {
                DevLogger.Error("Have no recive method for " + type, TankGameLogChannel.Network);
                return(null);
            }
        }
        public void DetectTargetForm()
        {
#if !UNITY_EDITOR && !UNITY_STANDALONE
            _autoDetectPlatformUI = true;
#endif
            var targetType = _autoDetectPlatformUI ? GetTargetUIType() : _targetPlatformUI;
            TargetContainer = _forms.Find(form => form.UIType == targetType);
            ApplyCanvasReferenceResolution();
            if (TargetContainer == null)
            {
                DevLogger.Error("Cannot find form container for " + targetType,
                                MarketLogType.UI);
            }

            _targetPlatformUI = targetType;
        }
Exemplo n.º 20
0
        public void ChangeLanguage(LanguageType lang)
        {
            ErrorsInfo = new List <ErrorInfo>();
            if (_grid.Length > 0 && _grid[0].Length > 0)
            {
                int CurrentLanguageColumn = 1;
                for (int column = 0; column < _grid[0].Length; column++)
                {
                    if (_grid[0][column] == lang.ToString())
                    {
                        CurrentLanguageColumn = column;
                        break;
                    }
                }

                for (int row = 1; row < _grid.Length; row++)
                {
                    var column    = 0;
                    var errorCode = ErrorCode.Unknown;
                    try
                    {
                        errorCode = (ErrorCode)Enum.Parse(typeof(ErrorCode), _grid[row][column]);
                    }
                    catch (ArgumentOutOfRangeException)
                    {
                        DevLogger.Error(string.Format("The are no error in row {0} column {1}",
                                                      row, column));
                    }
                    catch (Exception e)
                    {
                        DevLogger.Error(string.Format("Cannot parse error code {0}. Exception: {1}",
                                                      _grid[row][column], e.Message));
                    }

                    var error = new ErrorInfo
                    {
                        ErrorCode    = errorCode,
                        ErrorMessage = _grid[row][CurrentLanguageColumn]
                    };
                    ErrorsInfo.Add(error);
                }
            }
            else
            {
                throw new ArgumentNullException("Wrong format of spreadsheet in ApiErrorHelper");
            }
        }
Exemplo n.º 21
0
        public DMarketTransactionStatusType GetTransactionStatusType(string status)
        {
            switch (status)
            {
            case "processing":
                return(DMarketTransactionStatusType.Pending);

            case "success":
                return(DMarketTransactionStatusType.Success);

            case "fail":
                return(DMarketTransactionStatusType.Fail);

            default:
                DevLogger.Error("Cannot parse transaction status: " + status);
                return(DMarketTransactionStatusType.Pending);
            }
        }
Exemplo n.º 22
0
        public bool Start(int port)
        {
            try
            {
                NetworkServer.useWebSockets = UnityEngine.Application.platform == RuntimePlatform.WebGLPlayer;

                NetworkServer.Listen(port);
                NetworkServer.maxDelay = 0;

                RegisterServerHandlers();
            }
            catch (Exception e)
            {
                DevLogger.Error("Cannot run server " + e, DTanksLogChannel.Network);
                return(false);
            }
            return(true);
        }
Exemplo n.º 23
0
        public void Init(string basicAccessToken, string basicRefreshToken, ClientApi clientApi)
        {
            if (string.IsNullOrEmpty(basicAccessToken) || string.IsNullOrEmpty(basicRefreshToken))
            {
                DevLogger.Error(string.Format("It is not possible to initialize MarketWidget. Basic tokens are empty. BasicAccessToken: {0}, BasicRefreshToken: {1}",
                                              basicAccessToken, basicRefreshToken), MarketLogType.MarketWidget);
                return;
            }

            if (clientApi == null)
            {
                DevLogger.Error("It is not possible to initialize MarketWidget. ClientApi is null", MarketLogType.MarketWidget);
                return;
            }

            Model = new WidgetModel();
            Model.SetBasicTokens(basicAccessToken, basicRefreshToken);
            MarketApi = clientApi;
            MobileInputFieldHandler.InputSelected += OnMobileInputFieldSelected;
        }
Exemplo n.º 24
0
        public bool Start(int port)
        {
            try
            {
#if APPTYPE_WEBSERVER
                NetworkServer.useWebSockets = true;
#endif
                NetworkServer.Listen(port);
                NetworkServer.maxDelay = 0;

                var networkConfig = new ConnectionConfig();
                networkConfig.DisconnectTimeout = 100000;

                RegisterServerHandlers();
            }
            catch (Exception e)
            {
                DevLogger.Error("Cannot run server " + e.Message, TankGameLogChannel.Network);
                return(false);
            }
            return(true);
        }
Exemplo n.º 25
0
        private bool CorrectDataCheck(string userName, bool mustExist)
        {
            var isExist      = (this as IServerStorage).IsExist(userName);
            var errorMessage = string.Empty;

            if (!isExist && mustExist)
            {
                errorMessage = string.Format("{0} not exist in base", userName);
            }
            else if (isExist && !mustExist)
            {
                errorMessage = string.Format("{0} already exist in base", userName);
            }
            if (errorMessage != string.Empty)
            {
                DevLogger.Error(errorMessage);
                return(false);
            }
            else
            {
                return(true);
            }
        }
Exemplo n.º 26
0
        public void Login(string login, string marketAccessToken, string marketRefreshToken)
        {
            if (string.IsNullOrEmpty(login))
            {
                DevLogger.Error("It is not possible to login. Login is empty or null.", MarketLogType.MarketWidget);
                return;
            }

            if (string.IsNullOrEmpty(marketAccessToken) || string.IsNullOrEmpty(marketRefreshToken))
            {
                DevLogger.Error(string.Format("It is not possible to login. Market tokens are empty. MarketAccessToken: {0}, MarketRefreshToken: {1}",
                                              marketAccessToken, marketRefreshToken), MarketLogType.MarketWidget);
                return;
            }

            Model.UserName = login;
            Model.SetMarketTokens(marketAccessToken, marketRefreshToken);
            Model.SetChanges();

            MarketApi.MarketToken = marketAccessToken;

            LoginEvent.SafeRaise(new LoginEventData(marketAccessToken, marketRefreshToken, login));
        }
Exemplo n.º 27
0
        private void PoolObjectDestroyed(IPoolObject poolObject)
        {
            poolObject.PoolObjectDestroyed -= PoolObjectDestroyed;
            poolObject.Deactivate();

            var o = poolObject as TPoolObject;

            if (ReferenceEquals(o, null) == false)
            {
                lock (ActiveObjects)
                {
                    ActiveObjects.Remove(o);
                }

                PoolStorage.Add(o);
            }
            else
            {
                DevLogger.Error(
                    string.Format("Pool object was not casted to type '{0}'", typeof(TPoolObject)),
                    LogChannel.Common);
            }
        }
Exemplo n.º 28
0
        private void OnErrorCallback(Error error)
        {
            DevLogger.Error(string.Format("Can't load {0} from API", Type));

            View.SetLoadingState(false);
        }
Exemplo n.º 29
0
        public static void HandleResults(string rawResponse, int code, out TResultType result, out Error error)
        {
            result = default(TResultType);
            error  = null;

            try
            {
                if (IsMissingDataHTTPCode(code))
                {
                    if (!string.IsNullOrEmpty(rawResponse))
                    {
                        result = JsonConvert.DeserializeObject <TResultType>(rawResponse, new JsonSerializerSettings
                        {
                            MissingMemberHandling = MissingMemberHandling.Error
                        });
                    }
                }
                else if (IsSuccessHTTPCode(code))
                {
                    error  = null;
                    result = JsonConvert.DeserializeObject <TResultType>(rawResponse);
                }
                else if (code == 0)
                {
                    error = new Error
                    {
                        HttpCode  = code,
                        ErrorCode = ErrorCode.CannotResolveDestinationHost
                    };
                }
                else
                {
                    var response = JsonConvert.DeserializeObject <ErrorRepresentation>(rawResponse);

                    error = new Error
                    {
                        HttpCode     = code,
                        ErrorCode    = response.Code,
                        ErrorMessage = response.Message
                    };
                }
            }
            catch (JsonException e)
            {
                DevLogger.Error(string.Format("Cannot parse {0}. Error: {1}", rawResponse, e.Message),
                                MarketLogType.MarketApi);
                error = new Error
                {
                    ErrorCode    = ErrorCode.CannotParseResponse,
                    ErrorMessage = "Cant parse response to destination type"
                };
            }
            catch (Exception e)
            {
                DevLogger.Error(e.Message, MarketLogType.MarketApi);
                error = new Error
                {
                    ErrorCode    = ErrorCode.Unknown,
                    ErrorMessage = e.ToString()
                };
            }
        }
Exemplo n.º 30
0
 void FailHandler(Firebase sender, FirebaseError err)
 {
     DevLogger.Error("Firebase.FailHandler " + err.Message);
 }