public void UpgradeEffectPtjCheck() { var effect = new UpgradeEffect(UpgradeType.Suffix); effect.SetPtjCheck(PtjType.Bank, 21); Assert.Equal(( "01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00" + "00 00 00 00 0A 00 00 00 00 00 00 00 13 00 00 00" + "06 00 15 00" ).Replace(" ", ""), ToHex(effect)); }
public UpgradeEffect GetUpgradeEffect(Random rnd) { var effect = new UpgradeEffect(this.Type); // Stat effect if (this.Stat != null) { // Stat var stat = (UpgradeStat)this.Stat; // Value type UpgradeValueType valueType; if (this.Value.EndsWith("%")) { valueType = UpgradeValueType.Percent; } else { valueType = UpgradeValueType.Value; } // Value if (this.Value == null) { throw new NullReferenceException("Value can't be empty if Stat is set."); } var match = _valueRegex.Match(this.Value); if (!match.Success) { throw new FormatException("Invalid value format: " + this.Value); } var min = Convert.ToInt32(match.Groups["min"].Value); var maxs = match.Groups["max"].Value; var max = (maxs == "" ? min : (int)Math.Max(min, Convert.ToInt32(maxs))); if (match.Groups["sign"].Value == "-") { // For negative numbers min and max must be reversed, // e.g. -1~2 becomes "from -2 to -1". var temp = min; min = -max; max = -temp; } var value = (short)rnd.Next(min, max + 1); // Set effect.SetStatEffect(stat, value, valueType); } // Stat check if (this.Check == "gte" || this.Check == "lte" || this.Check == "gt" || this.Check == "lt" || this.Check == "equal") { // Check type UpgradeCheckType checkType; switch (this.Check) { case "gte": checkType = UpgradeCheckType.GreaterEqualThan; break; case "lte": checkType = UpgradeCheckType.LowerEqualThan; break; case "gt": checkType = UpgradeCheckType.GreaterThan; break; case "lt": checkType = UpgradeCheckType.LowerThan; break; case "equal": checkType = UpgradeCheckType.Equal; break; default: throw new NotSupportedException("Unknown check type: " + this.Check); } // Stat var stat = (UpgradeStat)Enum.Parse(typeof(UpgradeStat), this.If); // Value type var valueType = UpgradeValueType.Value; if (this.CheckValue.EndsWith("%")) { valueType = UpgradeValueType.Percent; } // Value var value = short.Parse(this.CheckValue.TrimEnd('%')); // Set effect.SetStatCheck(stat, checkType, value, valueType); } // Skill check else if (this.Check == "rank_gte" || this.Check == "rank_lte" || this.Check == "rank_equal") { // Check type UpgradeCheckType checkType; switch (this.Check) { case "rank_gte": checkType = UpgradeCheckType.SkillRankGreaterThan; break; case "rank_lte": checkType = UpgradeCheckType.SkillRankLowerThan; break; case "rank_equal": checkType = UpgradeCheckType.SkillRankEqual; break; default: throw new NotSupportedException("Unknown check type: " + this.Check); } // Skill id var skillId = (SkillId)Enum.Parse(typeof(SkillId), this.If); // Rank var rank = (this.CheckValue == "N" ? SkillRank.Novice : (SkillRank)(16 - Convert.ToInt32(this.CheckValue, 16))); // Set effect.SetSkillCheck(skillId, checkType, rank); } // Ptj check else if (this.Check == "ptj_gte") { // Ptj type var ptjType = (PtjType)Enum.Parse(typeof(PtjType), this.If); // Count var count = int.Parse(this.CheckValue); // Set effect.SetPtjCheck(ptjType, count); } // Broken check else if (this.If == "intact" || this.If == "broken") { var broken = (this.If == "intact" ? false : true); effect.SetBrokenCheck(broken); } // Title check else if (this.If == "title") { var titleId = int.Parse(this.CheckValue); effect.SetTitleCheck(titleId); } // Condition check else if (this.If == "condition") { var condition = int.Parse(this.CheckValue); effect.SetConditionCheck(condition); } // Month check else if (this.If == "month") { var month = (Month)Enum.Parse(typeof(Month), this.CheckValue); effect.SetMonthCheck(month); } // Summon check else if (this.If == "summoned") { var summonStat = (UpgradeStat)Enum.Parse(typeof(UpgradeStat), this.CheckValue); effect.SetSummonCheck(summonStat); } // Support check else if (this.If == "supporting") { var race = (SupportRace)Enum.Parse(typeof(SupportRace), this.CheckValue); effect.SetSupportCheck(race); } return(effect); }