Exemple #1
0
    internal void AddCharacterResearch(Research research, int level)
    {
        foreach (var chResearch in _characterResearches)
        {
            if (chResearch.ResearchId == research.Id)
            {
                if (level <= chResearch.Level)
                {
                    throw new Exception("CharacterResearch Invalid <= ");
                }
                if (chResearch.Level + 1 != level)
                {
                    throw new Exception("CharacterResearch Invalid != ");
                }
                chResearch.Level += 1;
                _xmlHelper.SaveCharacterResearches(_characterResearches);
                //SaveCharacterResearch(chResearch);
                return;
            }
        }
        var newResearch = new CharacterResearch(research.Id, _userPlayer.Id);

        _characterResearches.Add(newResearch);
        _xmlHelper.SaveCharacterResearches(_characterResearches);
        //SaveCharacterResearch(newResearch);
    }
Exemple #2
0
    private void DoResearch()
    {
        //Set the Target Research
        _clickedButton = EventSystem.current.currentSelectedGameObject;
        string buttonName = _clickedButton.name;
        int    researchId = Int32.Parse(buttonName);

        Research          research          = null;
        CharacterResearch characterResearch = null;

        for (int i = 0; i < _researches.Count; i++)
        {
            if (_researches[i].Id == researchId)
            {
                research = _researches[i];
                break;
            }
        }
        if (research == null)
        {
            throw new Exception("Research is not available ");
        }
        research.Print();
        for (int i = 0; i < _characterResearches.Count; i++)
        {
            if (_characterResearches[i].ResearchId == researchId)
            {
                characterResearch = _characterResearches[i];
                break;
            }
        }
        int nextLevel = characterResearch != null ? characterResearch.Level + 1 : 1;

        //Check criteria
        if (!ResearchUpgradeIsValid(research))
        {
            _messagePanelHandler.ShowMessage("Invalid Research!", MessagePanel.PanelType.Ok);
            return;
        }
        //Process the pay
        var payAmount = research.CalculatePrice(nextLevel);

        if (_characterManager.CharacterSetting.Coin < payAmount)
        {
            _messagePanelHandler.ShowMessage("You don't have enough Coin ! ", MessagePanel.PanelType.Ok);
            return;
        }
        _characterManager.AddCharacterSetting("Coin", -payAmount);
        MakeResearching(research, nextLevel);
        NewResearchInProgress(researchId);
        _messagePanelHandler.ShowMessage(research.Name + " is in progress ! ", MessagePanel.PanelType.Ok);
    }
Exemple #3
0
    internal void PutCharacterResearch(CharacterResearch characterResearch)
    {
        _apiGate = "GetCharacterResearches";
        _uri     = String.Format(ApiPath + ApiStage + _apiGate + "?id={0}", characterResearch.Id.ToString());
        string action = "Insert";

        if (characterResearch.Level != 1)
        {
            action = "Update";
        }
        ApiRequest ap = new ApiRequest
        {
            Action            = action,
            CharacterResearch = characterResearch
        };

        StartCoroutine(PutRequest(_uri, ap));
    }
Exemple #4
0
 private void SaveCharacterResearch(CharacterResearch characterResearch)
 {
     Debug.Log("UDB-characterResearch = " + characterResearch.MyInfo());
     //_apiGatewayConfig.PutCharacterResearch(characterResearch);
 }