示例#1
0
        /// <summary>
        /// Main method called by the controller during POST action. Processes the log file provided to the API
        /// </summary>
        /// <param name="inputLog"></param>
        /// <returns>True/False boolean to confirm success or failure of execution</returns>
        public bool ProcessLog(InputLog inputLog)
        {
            try // to process the log provided
            {
                var validationResult = ValidateLog(inputLog);

                switch (validationResult)
                {
                case ValidationResult.VALID:
                    var validOutputLog = new OutputLog {
                        ID = inputLog.ID, Date = inputLog.Date, Content = inputLog.Content
                    };
                    return(SaveFile(validOutputLog));

                case ValidationResult.ID_MISSING:
                case ValidationResult.DATE_MISSING:
                    GenerateCustomError(validationResult, null, inputLog);
                    var warningOutputLog = new OutputLog {
                        ID = inputLog.ID, Date = inputLog.Date, Content = inputLog.Content
                    };
                    return(SaveFile(warningOutputLog));

                default:
                    GenerateCustomError(validationResult, null, inputLog);
                    break;
                }
            }
            catch (Exception e)
            {
                GenerateCustomError(ValidationResult.UNKNOWN_ERROR, e, inputLog);
            }

            return(false);
        }
示例#2
0
    public InputLog AddAttaquantInputLog(Dictionary <string, string> logs)
    {
        GameObject go           = Instantiate(attaquantInputLog, logContainer.transform);
        InputLog   logComponent = go.GetComponent <InputLog>();

        CompleteInputLog(logComponent, logs, FightController.instance.attaquant);

        return(logComponent);
    }
    public IEnumerator RollVitesseDice()
    {
        Dictionary <string, string> dictionaryLog;

        int vitesse;

        if (attaquant.pnj)
        {
            vitesse = RollDice(100);
        }
        else
        {
            dictionaryLog = CreateLogDictionary(attaquant.characterName, "Vitesse",
                                                "", "/ " + (DropdownUpdater.instance.GetStat("Vitesse", attaquant) / (2 * attackNumber)).ToString());
            InputLog inputLog = LogController.instance.AddAttaquantInputLog(dictionaryLog);

            yield return(new WaitUntil(() => inputLog.completed));

            vitesse = int.Parse(inputLog.roll.text);

            Destroy(inputLog.gameObject);
        }

        bool success = false;

        dictionaryLog = CreateLogDictionary(attaquant.characterName, "Vitesse",
                                            vitesse.ToString(), "/ " + (DropdownUpdater.instance.GetStat("Vitesse", attaquant) / (2 * attackNumber)).ToString());

        if (vitesse <= (DropdownUpdater.instance.GetStat("Vitesse", attaquant) / (2 * attackNumber)) && vitesse > 5)
        {
            LogController.instance.AddAttaquantWinLog(dictionaryLog);
            success = true;
        }
        else if (vitesse <= (DropdownUpdater.instance.GetStat("Vitesse", attaquant) / (2 * attackNumber)) && vitesse <= 5)
        {
            LogController.instance.AddAttaquantCriticalWinLog(dictionaryLog);
            success = true;
        }
        else if (vitesse > (DropdownUpdater.instance.GetStat("Vitesse", attaquant) / (2 * attackNumber)) && vitesse <= 95)
        {
            LogController.instance.AddAttaquantFailLog(dictionaryLog);
        }
        else if (vitesse > (DropdownUpdater.instance.GetStat("Vitesse", attaquant) / (2 * attackNumber)) && vitesse > 95)
        {
            LogController.instance.AddAttaquantCriticalFailLog(dictionaryLog);
        }

        if (success)
        {
            attackNumber += 1;
        }
        else
        {
            attackNumber = 1;
            LogController.instance.AddSeparator();
        }
    }
示例#4
0
 public static void Write(FileStream stream, InputLog log, bool text)
 {
     foreach (var str in log.Log)
     {
         var frame = new Frame();
         frame.Parse(str);
         var buffer = frame.GetBytes(text);
         stream.Write(buffer, 0, buffer.Length);
     }
 }
示例#5
0
    public void CompleteInputLog(InputLog logComponent, Dictionary <string, string> logs, SaveCharacter saveCharacter)
    {
        logComponent.characterName.text = logs["character"];
        logComponent.statName.text      = logs["stat name"];
        logComponent.stat.text          = logs["stat value"];

        List <float> floatColor = new List <float>();

        floatColor.Add((float)saveCharacter.color[0] / 255);
        floatColor.Add((float)saveCharacter.color[1] / 255);
        floatColor.Add((float)saveCharacter.color[2] / 255);
        logComponent.characterName.color = new Color(floatColor[0], floatColor[1], floatColor[2]);
    }
示例#6
0
        public ResultM AddInput(List <AttributeValueM> inputAttributeValue)
        {
            ResultM result = new ResultM();
//                calculator.Calculate(inputAttributeValue);
            InputLog log = new InputLog()
            {
                Values = inputAttributeValue,
                Result = result
            };

            _portDAO.SaveInputLog(log);
            return(result);
        }
示例#7
0
        public void CleanDBTests(Entities e, int output)
        {
            //cleaning test job results in DB

            InputLog logTest = e.InputLog.Find(output);

            if (logTest == null)
            {
                return;
            }

            Console.WriteLine(logTest.id + " | " + logTest.message + " | " + logTest.time);

            //cleaning logs
            e.InputLog.Remove(logTest);

            e.SaveChanges();
        }
示例#8
0
        public static void Write(ZipArchive archive, InputLog log, string logKey)
        {
            var archiveEntry = archive.Entries.SingleOrDefault(
                e => e.Name.StartsWith("Input Log", StringComparison.OrdinalIgnoreCase)
                );

            var entry = archiveEntry ?? archive.CreateEntry("Input Log.txt");

            var file = new StreamWriter(entry.Open());

            file.WriteLine(logKey);

            foreach (var frame in log.Log)
            {
                file.WriteLine(string.Join("", frame));
            }

            file.Flush();
            file.Close();
        }
示例#9
0
        /// <summary>
        /// Validates the log and assigns it appropiate ValidationResult enum value.
        /// </summary>
        /// <param name="inputLog">The log to validate.</param>
        /// <returns>ValidationResult enum value.</returns>
        private ValidationResult ValidateLog(InputLog inputLog)
        {
            if (inputLog.Content is null)
            {
                return(ValidationResult.INPUT_LOG_NULL);
            }
            else if (inputLog.Date == default(DateTime))
            {
                return(ValidationResult.DATE_MISSING);
            }
            else if (inputLog.ID == default(int))
            {
                return(ValidationResult.ID_MISSING);
            }
            else if (inputLog.Content.Length > 255)
            {
                return(ValidationResult.CONTENT_LONGER_THAN_255);
            }

            return(ValidationResult.VALID);
        }
示例#10
0
 public static void Write(FileStream stream, InputLog log, bool isWii)
 {
     if (isWii)
     {
         foreach (var str in log.Log)
         {
             var frame = new WiiMoteFrame();
             frame.Parse(str);
             var buffer = frame.GetBytes();
             stream.Write(buffer, 0, buffer.Length);
         }
     }
     else
     {
         foreach (var str in log.Log)
         {
             var frame = new GameCubeFrame();
             frame.Parse(str);
             var buffer = frame.GetBytes();
             stream.Write(buffer, 0, buffer.Length);
         }
     }
 }
示例#11
0
        /// <summary>
        /// Generates custom error based on ValidationResult and other conditions.
        /// </summary>
        /// <param name="exception">System/Default Exception when unhandled error happens.</param>
        /// <param name="invalidInputLog">Input log that has caused the issue.</param>
        /// <param name="validationResult">ValidationResult enum received.</param>
        /// <returns></returns>
        private bool GenerateCustomError(ValidationResult validationResult, Exception exception = null, InputLog invalidInputLog = null)
        {
            var customError = new CustomError(); //let constructor build default object

            // if input log is provided, copy the ID and date
            if (invalidInputLog != null)
            {
                customError.ID        = invalidInputLog.ID;
                customError.ErrorDate = invalidInputLog.Date;
            }

            // provide the content in RawErrorData
            customError.RawErrorData = invalidInputLog.Content ?? null;

            // if exception is provided, copy the message
            if (exception != null)
            {
                customError.RawErrorData += $" Raw Exception: {exception.Message ?? null}";
            }

            customError.Severity = "HIGH";

            // refactor on next push, the complexity of method suggest moving the whole functionality to a class level
            if (validationResult == ValidationResult.DATE_MISSING || validationResult == ValidationResult.ID_MISSING)
            {
                customError.Severity = "MEDIUM";
            }

            customError.ErrorSummary    = validationResult.ToString() ?? null;
            customError.ErrorCode       = Convert.ToInt32(validationResult);
            customError.CustomErrorText = validationResult.Description();

            return(ReportException(customError).Result);
        }
 public ContentResult Post([FromBody] InputLog inputLog)
 {
     // as little logic in the controller as possible
     return(Content(_businessLogic.ProcessLog(inputLog).ToString()));
 }
    public IEnumerator ShowAttackWithWeaponLogs()
    {
        // Creating each character color string in hex

        List <float> floatColor = new List <float>();

        floatColor.Add((float)attaquant.color[0] / 255);
        floatColor.Add((float)attaquant.color[1] / 255);
        floatColor.Add((float)attaquant.color[2] / 255);

        string attaquantColor = ColorUtility.ToHtmlStringRGB(new Color(floatColor[0], floatColor[1], floatColor[2]));

        floatColor = new List <float>();
        floatColor.Add((float)defenseur.color[0] / 255);
        floatColor.Add((float)defenseur.color[1] / 255);
        floatColor.Add((float)defenseur.color[2] / 255);

        string defenseurColor = ColorUtility.ToHtmlStringRGB(new Color(floatColor[0], floatColor[1], floatColor[2]));

        // Used variables

        Dictionary <string, string> dictionaryLog;

        // Lancer de stat 1

        int bonus = 0;

        if (DropdownUpdater.instance.bonusInput.text != "")
        {
            bonus = int.Parse(DropdownUpdater.instance.bonusInput.text);
        }

        int attackValue1;

        if (attaquant.pnj)
        {
            attackValue1 = RollDice(100);
        }
        else
        {
            dictionaryLog = CreateLogDictionary(attaquant.characterName, DropdownUpdater.instance.weaponStat1Dropdown.GetComponentInChildren <Text>().text,
                                                "", "/ " + (weaponStat1 + bonus).ToString());
            InputLog inputLog = LogController.instance.AddAttaquantInputLog(dictionaryLog);

            yield return(new WaitUntil(() => inputLog.completed));

            attackValue1 = int.Parse(inputLog.roll.text);

            Destroy(inputLog.gameObject);
        }

        dictionaryLog = CreateLogDictionary(attaquant.characterName, DropdownUpdater.instance.weaponStat1Dropdown.GetComponentInChildren <Text>().text,
                                            attackValue1.ToString(), "/ " + (weaponStat1 + bonus).ToString());

        bool success = true;

        if (attackValue1 <= weaponStat1 + bonus && attackValue1 > 5)
        {
            LogController.instance.AddAttaquantWinLog(dictionaryLog);
        }
        else if (attackValue1 <= weaponStat1 + bonus && attackValue1 <= 5)
        {
            LogController.instance.AddAttaquantCriticalWinLog(dictionaryLog);
        }
        else if (attackValue1 > weaponStat1 + bonus && attackValue1 <= 95)
        {
            LogController.instance.AddAttaquantFailLog(dictionaryLog);
            success = false;
        }
        else if (attackValue1 > weaponStat1 + bonus && attackValue1 > 95)
        {
            LogController.instance.AddAttaquantCriticalFailLog(dictionaryLog);
            success = false;
        }

        // Lancer de stat 2

        bool secondRoll   = false;
        int  attackValue2 = 0;

        if (DropdownUpdater.instance.weaponStat2Dropdown.GetComponentInChildren <Text>().text != "-")
        {
            secondRoll = true;

            if (attaquant.pnj)
            {
                attackValue2 = RollDice(100);
            }
            else
            {
                dictionaryLog = CreateLogDictionary(attaquant.characterName, DropdownUpdater.instance.weaponStat2Dropdown.GetComponentInChildren <Text>().text,
                                                    "", "/ " + weaponStat2.ToString());
                InputLog inputLog = LogController.instance.AddAttaquantInputLog(dictionaryLog);

                yield return(new WaitUntil(() => inputLog.completed));

                attackValue2 = int.Parse(inputLog.roll.text);

                Destroy(inputLog.gameObject);
            }

            dictionaryLog = CreateLogDictionary(attaquant.characterName, DropdownUpdater.instance.weaponStat2Dropdown.GetComponentInChildren <Text>().text,
                                                attackValue2.ToString(), "/ " + weaponStat2.ToString());

            if (attackValue2 <= weaponStat2 && attackValue2 > 5)
            {
                LogController.instance.AddAttaquantWinLog(dictionaryLog);
            }
            else if (attackValue2 <= weaponStat2 && attackValue2 <= 5)
            {
                LogController.instance.AddAttaquantCriticalWinLog(dictionaryLog);
            }
            else if (attackValue2 > weaponStat2 && attackValue2 <= 95)
            {
                LogController.instance.AddAttaquantFailLog(dictionaryLog);
                success = false;
            }
            else if (attackValue2 > weaponStat2 && attackValue2 > 95)
            {
                LogController.instance.AddAttaquantCriticalFailLog(dictionaryLog);
                success = false;
            }
        }

        if (!success)
        {
            string logTemp = "<color=#" + attaquantColor + "><b>" + attaquant.characterName + "</b></color>" + " échoue à attaquer "
                             + "<color=#" + defenseurColor + "><b>" + defenseur.characterName + "</b></color>";
            LogController.instance.AddResultLog(logTemp);

            StartCoroutine(RollVitesseDice());

            yield break;
        }

        bool parade  = DropdownUpdater.instance.defenseurAction.GetComponentInChildren <Text>().text == "Parer";
        bool esquive = DropdownUpdater.instance.defenseurAction.GetComponentInChildren <Text>().text == "Esquiver";

        if (esquive || parade)
        {
            int defensiveAction;
            if (defenseur.pnj)
            {
                defensiveAction = RollDice(100);
            }
            else
            {
                if (parade)
                {
                    dictionaryLog = CreateLogDictionary(defenseur.characterName, "Adresse",
                                                        "", "/ " + defenseurStat.ToString());
                }
                else if (esquive)
                {
                    dictionaryLog = CreateLogDictionary(defenseur.characterName, "Agilité",
                                                        "", "/ " + defenseurStat.ToString());
                }
                InputLog inputLog = LogController.instance.AddDefenseurInputLog(dictionaryLog);

                yield return(new WaitUntil(() => inputLog.completed));

                defensiveAction = int.Parse(inputLog.roll.text);

                Destroy(inputLog.gameObject);
            }

            success = false;

            if (parade)
            {
                dictionaryLog = CreateLogDictionary(defenseur.characterName, "Adresse",
                                                    defensiveAction.ToString(), "/ " + defenseurStat.ToString());
            }
            else if (esquive)
            {
                dictionaryLog = CreateLogDictionary(defenseur.characterName, "Agilité",
                                                    defensiveAction.ToString(), "/ " + defenseurStat.ToString());
            }
            else
            {
            }

            if (defensiveAction <= defenseurStat && defensiveAction > 5)
            {
                LogController.instance.AddDefenseurWinLog(dictionaryLog);
            }
            else if (defensiveAction <= defenseurStat && defensiveAction <= 5)
            {
                LogController.instance.AddDefenseurCriticalWinLog(dictionaryLog);
            }
            else if (defensiveAction > defenseurStat && defensiveAction <= 95)
            {
                LogController.instance.AddDefenseurFailLog(dictionaryLog);
                success = true;
            }
            else if (defensiveAction > defenseurStat && defensiveAction > 95)
            {
                LogController.instance.AddDefenseurCriticalFailLog(dictionaryLog);
                success = true;
            }

            if (!secondRoll)
            {
                if (attackValue1 / (float)weaponStat1 > defensiveAction / (float)defenseurStat)
                {
                    success = false;
                }
                else
                {
                    success = true;
                }
            }
            else
            {
                if (attackValue2 / (float)weaponStat2 > defensiveAction / (float)defenseurStat)
                {
                    success = false;
                }
                else
                {
                    success = true;
                }
            }

            if (!success)
            {
                string logTemp = "";
                if (parade)
                {
                    logTemp = "<color=#" + defenseurColor + "><b>" + defenseur.characterName + "</b></color>" + " pare l'attaque de "
                              + "<color=#" + attaquantColor + "><b>" + attaquant.characterName + "</b></color>";
                }
                else if (esquive)
                {
                    logTemp = "<color=#" + defenseurColor + "><b>" + defenseur.characterName + "</b></color>" + " esquive l'attaque de "
                              + "<color=#" + attaquantColor + "><b>" + attaquant.characterName + "</b></color>";
                }

                LogController.instance.AddResultLog(logTemp);

                StartCoroutine(RollVitesseDice());

                yield break;
            }
        }

        int defense;

        if (defenseur.pnj)
        {
            defense = RollDice(100);
        }
        else
        {
            dictionaryLog = CreateLogDictionary(defenseur.characterName, "Défense",
                                                "", "/ " + DropdownUpdater.instance.GetStat("Défense", defenseur).ToString());
            InputLog inputLog = LogController.instance.AddDefenseurInputLog(dictionaryLog);

            yield return(new WaitUntil(() => inputLog.completed));

            defense = int.Parse(inputLog.roll.text);

            Destroy(inputLog.gameObject);
        }

        success = false;

        dictionaryLog = CreateLogDictionary(defenseur.characterName, "Défense",
                                            defense.ToString(), "/ " + DropdownUpdater.instance.GetStat("Défense", defenseur).ToString());

        if (defense <= DropdownUpdater.instance.GetStat("Défense", defenseur) && defense > 5)
        {
            LogController.instance.AddDefenseurWinLog(dictionaryLog);
            success = true;
        }
        else if (defense <= DropdownUpdater.instance.GetStat("Défense", defenseur) && defense <= 5)
        {
            LogController.instance.AddDefenseurCriticalWinLog(dictionaryLog);
            success = true;
        }
        else if (defense > DropdownUpdater.instance.GetStat("Défense", defenseur) && defense <= 95)
        {
            LogController.instance.AddDefenseurFailLog(dictionaryLog);
        }
        else if (defense > DropdownUpdater.instance.GetStat("Défense", defenseur) && defense > 95)
        {
            LogController.instance.AddDefenseurCriticalFailLog(dictionaryLog);
        }

        int degatsAbsorbes = 0;

        if (success)
        {
            int temp = DropdownUpdater.instance.GetStat("Défense", defenseur);
            while (temp >= defense)
            {
                temp           -= 15;
                degatsAbsorbes += 1;
            }
        }

        int degats = 0;

        if (attaquant.pnj)
        {
            for (int i = 0; i < weapon.diceNumber; i++)
            {
                degats += RollDice(weapon.damages);
            }
        }
        else
        {
            dictionaryLog = CreateLogDictionary(attaquant.characterName, "Attaque (" + weapon.weaponName + ")",
                                                "", "/ " + weapon.diceNumber * weapon.damages);
            InputLog inputLog = LogController.instance.AddAttaquantInputLog(dictionaryLog);

            yield return(new WaitUntil(() => inputLog.completed));

            degats = int.Parse(inputLog.roll.text);

            Destroy(inputLog.gameObject);
        }

        dictionaryLog = CreateLogDictionary(attaquant.characterName, "Attaque (" + weapon.weaponName + ")",
                                            degats.ToString() + " + " + weapon.bonusDamages * weapon.diceNumber, "/ " + weapon.diceNumber * (weapon.damages + weapon.bonusDamages));

        LogController.instance.AddAttaquantClassicalLog(dictionaryLog);

        degats += weapon.bonusDamages * weapon.diceNumber;

        string log2;

        if (degatsAbsorbes == 0)
        {
            log2 = "<color=#" + attaquantColor + "><b>" + attaquant.characterName + "</b></color>" + " inflige "
                   + "<b>" + degats.ToString() + "</b> PV de dégât(s) à "
                   + "<color=#" + defenseurColor + "><b>" + defenseur.characterName + "</b></color>";
        }
        else
        {
            log2 = "<color=#" + attaquantColor + "><b>" + attaquant.characterName + "</b></color>" + " inflige "
                   + "<b>" + degats.ToString() + " - " + degatsAbsorbes.ToString() + "</b> PV de dégât(s) à "
                   + "<color=#" + defenseurColor + "><b>" + defenseur.characterName + "</b></color>";
        }
        LogController.instance.AddResultLog(log2);

        StartCoroutine(RollVitesseDice());
    }