From 041de1100571c91f3df14dfba2e2ac7bdc7dbe21 Mon Sep 17 00:00:00 2001 From: Yang Chun Ung Date: Tue, 23 Jan 2024 13:56:25 +0900 Subject: [PATCH 01/11] Convert stat int to int64 for avoid int overflow --- .Lib9c.Tests/Action/Common/Doomfist.cs | 4 +- .Lib9c.Tests/Action/HitHelperTest.cs | 2 +- Lib9c/Battle/HitHelper.cs | 38 +++---- Lib9c/Model/Character/ArenaCharacter.cs | 56 +++++----- Lib9c/Model/Character/CharacterBase.cs | 38 +++---- Lib9c/Model/Character/Player.cs | 8 +- Lib9c/Model/Stat/CharacterStats.cs | 64 +++++------ Lib9c/Model/Stat/DecimalStat.cs | 12 +- Lib9c/Model/Stat/IBaseAndAdditionalStats.cs | 50 ++++----- Lib9c/Model/Stat/IStats.cs | 24 ++-- Lib9c/Model/Stat/StatMap.cs | 116 ++++++++++---------- Lib9c/Model/Stat/StatModifier.cs | 16 +-- Lib9c/Model/Stat/Stats.cs | 42 +++---- Lib9c/Model/Stat/StatsMap.cs | 86 +++++++-------- 14 files changed, 278 insertions(+), 278 deletions(-) diff --git a/.Lib9c.Tests/Action/Common/Doomfist.cs b/.Lib9c.Tests/Action/Common/Doomfist.cs index 66452e42fe..84aee1d7a0 100644 --- a/.Lib9c.Tests/Action/Common/Doomfist.cs +++ b/.Lib9c.Tests/Action/Common/Doomfist.cs @@ -55,10 +55,10 @@ public static Equipment GetOne( .Aggregate((row1, row2) => { var row1Value = row1.Stat.StatType == statType - ? row1.Stat.BaseValueAsInt + ? row1.Stat.BaseValueAsLong : 0; var row2Value = row2.Stat.StatType == statType - ? row2.Stat.BaseValueAsInt + ? row2.Stat.BaseValueAsLong : 0; return row1Value > row2Value ? row1 diff --git a/.Lib9c.Tests/Action/HitHelperTest.cs b/.Lib9c.Tests/Action/HitHelperTest.cs index 1b53168ffe..ab8ba20723 100644 --- a/.Lib9c.Tests/Action/HitHelperTest.cs +++ b/.Lib9c.Tests/Action/HitHelperTest.cs @@ -10,7 +10,7 @@ public class HitHelperTest public void GetHitStep2() { // copy from previous logic - int GetHitStep2Legacy(int attackerHit, int defenderHit) + long GetHitStep2Legacy(int attackerHit, int defenderHit) { attackerHit = Math.Max(1, attackerHit); defenderHit = Math.Max(1, defenderHit); diff --git a/Lib9c/Battle/HitHelper.cs b/Lib9c/Battle/HitHelper.cs index 49cb4932fc..43c02ddd1e 100644 --- a/Lib9c/Battle/HitHelper.cs +++ b/Lib9c/Battle/HitHelper.cs @@ -7,19 +7,19 @@ namespace Nekoyume.Battle { public static class HitHelper { - public const int GetHitStep1LevelDiffMin = -14; - public const int GetHitStep1LevelDiffMax = 10; - public const int GetHitStep1CorrectionMin = -5; - public const int GetHitStep1CorrectionMax = 50; - public const int GetHitStep2AdditionalCorrectionMin = 0; - public const int GetHitStep2AdditionalCorrectionMax = 50; - public const int GetHitStep3CorrectionMin = 10; - public const int GetHitStep3CorrectionMax = 90; + public const long GetHitStep1LevelDiffMin = -14; + public const long GetHitStep1LevelDiffMax = 10; + public const long GetHitStep1CorrectionMin = -5; + public const long GetHitStep1CorrectionMax = 50; + public const long GetHitStep2AdditionalCorrectionMin = 0; + public const long GetHitStep2AdditionalCorrectionMax = 50; + public const long GetHitStep3CorrectionMin = 10; + public const long GetHitStep3CorrectionMax = 90; public static bool IsHit( - int attackerLevel, int attackerHit, - int defenderLevel, int defenderHit, - int lowLimitChance) + long attackerLevel, long attackerHit, + long defenderLevel, long defenderHit, + long lowLimitChance) { var correction = GetHitStep1(attackerLevel, defenderLevel); correction += GetHitStep2(attackerHit, defenderHit); @@ -40,11 +40,11 @@ public static bool IsHit( } public static bool IsHitWithoutLevelCorrection( - int attackerLevel, int attackerHit, - int defenderLevel, int defenderHit, - int lowLimitChance) + long attackerLevel, long attackerHit, + long defenderLevel, long defenderHit, + long lowLimitChance) { - var correction = 40; + long correction = 40; correction += GetHitStep2(attackerHit, defenderHit); correction = GetHitStep3(correction); var isHit = GetHitStep4(lowLimitChance, correction); @@ -62,7 +62,7 @@ public static bool IsHitWithoutLevelCorrection( return isHit; } - public static int GetHitStep1(int attackerLevel, int defenderLevel) + public static long GetHitStep1(long attackerLevel, long defenderLevel) { var diff = attackerLevel - defenderLevel; @@ -105,7 +105,7 @@ public static int GetHitStep1(int attackerLevel, int defenderLevel) }; } - public static int GetHitStep2(int attackerHit, int defenderHit) + public static long GetHitStep2(long attackerHit, long defenderHit) { attackerHit = Math.Max(1, attackerHit); defenderHit = Math.Max(1, defenderHit); @@ -114,12 +114,12 @@ public static int GetHitStep2(int attackerHit, int defenderHit) GetHitStep2AdditionalCorrectionMax); } - public static int GetHitStep3(int correction) + public static long GetHitStep3(long correction) { return Math.Min(Math.Max(correction, GetHitStep3CorrectionMin), GetHitStep3CorrectionMax); } - public static bool GetHitStep4(int lowLimitChance, int correction) + public static bool GetHitStep4(long lowLimitChance, long correction) { return correction >= lowLimitChance; } diff --git a/Lib9c/Model/Character/ArenaCharacter.cs b/Lib9c/Model/Character/ArenaCharacter.cs index b2c3924c0a..f50e60b530 100644 --- a/Lib9c/Model/Character/ArenaCharacter.cs +++ b/Lib9c/Model/Character/ArenaCharacter.cs @@ -37,10 +37,10 @@ public class ArenaCharacter : ICloneable public readonly ArenaSkills _runeSkills = new ArenaSkills(); public readonly Dictionary RuneSkillCooldownMap = new Dictionary(); - private readonly int _attackCountMax; + private readonly long _attackCountMax; private ArenaCharacter _target; - private int _attackCount; + private long _attackCount; public Guid Id { get; } = Guid.NewGuid(); public BattleStatus.Arena.ArenaSkill SkillLog { get; private set; } @@ -50,14 +50,14 @@ public class ArenaCharacter : ICloneable public SizeType SizeType { get; } public float RunSpeed { get; } public float AttackRange { get; } - public int CharacterId { get; } + public long CharacterId { get; } public bool IsEnemy { get; } private bool _setExtraValueBuffBeforeGetBuffs = false; - private int _currentHP; + private long _currentHP; - public int CurrentHP + public long CurrentHP { get => _currentHP; set => _currentHP = Math.Min(Math.Max(0, value), HP); @@ -69,18 +69,18 @@ public int Level set => Stats.SetStats(value); } - public int HP => Stats.HP; - public int AdditionalHP => Stats.BuffStats.HP; - public int ATK => Stats.ATK; - public int DEF => Stats.DEF; - public int CRI => Stats.CRI; - public int HIT => Stats.HIT; - public int SPD => Stats.SPD; - public int DRV => Stats.DRV; - public int DRR => Stats.DRR; - public int CDMG => Stats.CDMG; - public int ArmorPenetration => Stats.ArmorPenetration; - public int Thorn => Stats.Thorn; + public long HP => Stats.HP; + public long AdditionalHP => Stats.BuffStats.HP; + public long ATK => Stats.ATK; + public long DEF => Stats.DEF; + public long CRI => Stats.CRI; + public long HIT => Stats.HIT; + public long SPD => Stats.SPD; + public long DRV => Stats.DRV; + public long DRR => Stats.DRR; + public long CDMG => Stats.CDMG; + public long ArmorPenetration => Stats.ArmorPenetration; + public long Thorn => Stats.Thorn; public bool IsDead => CurrentHP <= 0; public Dictionary Buffs { get; } = new Dictionary(); @@ -158,7 +158,7 @@ public ArenaCharacter( IArenaSimulator simulator, ArenaPlayerDigest digest, ArenaSimulatorSheets sheets, - int hpModifier, + long hpModifier, bool isEnemy = false, bool setExtraValueBuffBeforeGetBuffs = false) { @@ -261,7 +261,7 @@ private static CharacterStats GetStat( CharacterSheet.Row characterRow, EquipmentItemSetEffectSheet equipmentItemSetEffectSheet, CostumeStatSheet costumeStatSheet, - int hpModifier) + long hpModifier) { var stats = new CharacterStats(characterRow, digest.Level) { @@ -310,7 +310,7 @@ private static CharacterStats GetStatV1( private static bool TryGetStats( CostumeStatSheet statSheet, - int itemId, + long itemId, out IEnumerable statModifiers) { statModifiers = statSheet.OrderedList @@ -341,7 +341,7 @@ public void SetRuneV1( new StatModifier( x.stat.StatType, x.operationType, - x.stat.TotalValueAsInt))); + x.stat.TotalValueAsLong))); Stats.AddOptional(statModifiers); ResetCurrentHP(); @@ -402,7 +402,7 @@ public void SetRuneV2( new StatModifier( x.stat.StatType, x.operationType, - x.stat.TotalValueAsInt))); + x.stat.TotalValueAsLong))); Stats.AddOptional(statModifiers); ResetCurrentHP(); @@ -420,7 +420,7 @@ public void SetRuneV2( } else if (optionInfo.StatReferenceType == EnumType.StatReferenceType.Caster) { - var value = Stats.GetStatAsInt(optionInfo.SkillStatType); + var value = Stats.GetStatAsLong(optionInfo.SkillStatType); power = (int)Math.Round(value * optionInfo.SkillValue); } var skill = SkillFactory.GetForArena(skillRow, power, optionInfo.SkillChance, default, StatType.NONE); @@ -454,7 +454,7 @@ public void SetRune( new StatModifier( x.stat.StatType, x.operationType, - x.stat.TotalValueAsInt))); + x.stat.TotalValueAsLong))); Stats.AddRune(statModifiers); ResetCurrentHP(); @@ -472,7 +472,7 @@ public void SetRune( } else if (optionInfo.StatReferenceType == EnumType.StatReferenceType.Caster) { - var value = Stats.GetStatAsInt(optionInfo.SkillStatType); + var value = Stats.GetStatAsLong(optionInfo.SkillStatType); power = (int)Math.Round(value * optionInfo.SkillValue); } var skill = SkillFactory.GetForArena(skillRow, power, optionInfo.SkillChance, default, StatType.NONE); @@ -659,7 +659,7 @@ or SkillCategory.AreaAttack } } - private ArenaSkill GiveThornDamage(int targetThorn) + private ArenaSkill GiveThornDamage(long targetThorn) { var clone = (ArenaCharacter)Clone(); // minimum 1 damage @@ -905,7 +905,7 @@ public void RemoveRecentStatBuff() } } - public void Heal(int heal) + public void Heal(long heal) { CurrentHP += heal; } @@ -937,7 +937,7 @@ public virtual bool IsHit(ArenaCharacter caster) return isHit; } - public int GetDamage(int damage, bool considerAttackCount = true) + public long GetDamage(long damage, bool considerAttackCount = true) { if (!considerAttackCount) return damage; diff --git a/Lib9c/Model/Character/CharacterBase.cs b/Lib9c/Model/Character/CharacterBase.cs index 0852828b8c..4fc849b0f6 100644 --- a/Lib9c/Model/Character/CharacterBase.cs +++ b/Lib9c/Model/Character/CharacterBase.cs @@ -49,22 +49,22 @@ public int Level set => Stats.SetStats(value); } - public int HP => Stats.HP; - public int AdditionalHP => Stats.BuffStats.HP; - public int ATK => Stats.ATK; - public int DEF => Stats.DEF; - public int CRI => Stats.CRI; - public int HIT => Stats.HIT; - public int SPD => Stats.SPD; - public int DRV => Stats.DRV; - public int DRR => Stats.DRR; - public int CDMG => Stats.CDMG; - public int ArmorPenetration => Stats.ArmorPenetration; - public int Thorn => Stats.Thorn; - - private int _currentHP; - - public int CurrentHP + public long HP => Stats.HP; + public long AdditionalHP => Stats.BuffStats.HP; + public long ATK => Stats.ATK; + public long DEF => Stats.DEF; + public long CRI => Stats.CRI; + public long HIT => Stats.HIT; + public long SPD => Stats.SPD; + public long DRV => Stats.DRV; + public long DRR => Stats.DRR; + public long CDMG => Stats.CDMG; + public long ArmorPenetration => Stats.ArmorPenetration; + public long Thorn => Stats.Thorn; + + private long _currentHP; + + public long CurrentHP { get => _currentHP; set => _currentHP = Math.Min(Math.Max(0, value), HP); @@ -447,7 +447,7 @@ public virtual bool IsHit(CharacterBase caster) return isHit; } - public int GetDamage(int damage, bool considerAttackCount = true) + public long GetDamage(long damage, bool considerAttackCount = true) { if (!considerAttackCount) return damage; @@ -487,7 +487,7 @@ protected virtual void OnDead() } } - public void Heal(int heal) + public void Heal(long heal) { CurrentHP += heal; } @@ -633,7 +633,7 @@ or SkillCategory.AreaAttack FinishTargetIfKilled(usedSkill); } - internal BattleStatus.Skill GiveThornDamage(int targetThorn) + internal BattleStatus.Skill GiveThornDamage(long targetThorn) { bool log = Simulator.LogEvent; // Copy not damaged character diff --git a/Lib9c/Model/Character/Player.cs b/Lib9c/Model/Character/Player.cs index 41e5711a85..0776578346 100644 --- a/Lib9c/Model/Character/Player.cs +++ b/Lib9c/Model/Character/Player.cs @@ -588,7 +588,7 @@ public void SetRune( new StatModifier( x.stat.StatType, x.operationType, - x.stat.BaseValueAsInt))); + x.stat.BaseValueAsLong))); Stats.AddRune(statModifiers); ResetCurrentHP(); @@ -606,7 +606,7 @@ public void SetRune( } else if (optionInfo.StatReferenceType == EnumType.StatReferenceType.Caster) { - var value = Stats.GetStatAsInt(optionInfo.SkillStatType); + var value = Stats.GetStatAsLong(optionInfo.SkillStatType); power = (int)Math.Round(value * optionInfo.SkillValue); } var skill = SkillFactory.GetV1(skillRow, power, optionInfo.SkillChance); @@ -642,7 +642,7 @@ public void SetRuneV1( new StatModifier( x.stat.StatType, x.operationType, - x.stat.TotalValueAsInt))); + x.stat.TotalValueAsLong))); Stats.AddOptional(statModifiers); ResetCurrentHP(); @@ -660,7 +660,7 @@ public void SetRuneV1( } else if (optionInfo.StatReferenceType == EnumType.StatReferenceType.Caster) { - var value = Stats.GetStatAsInt(optionInfo.SkillStatType); + var value = Stats.GetStatAsLong(optionInfo.SkillStatType); power = (int)Math.Round(value * optionInfo.SkillValue); } var skill = SkillFactory.GetV1(skillRow, power, optionInfo.SkillChance); diff --git a/Lib9c/Model/Stat/CharacterStats.cs b/Lib9c/Model/Stat/CharacterStats.cs index 1e1c28041e..e8272da61d 100644 --- a/Lib9c/Model/Stat/CharacterStats.cs +++ b/Lib9c/Model/Stat/CharacterStats.cs @@ -44,32 +44,32 @@ public class CharacterStats : Stats, IBaseAndAdditionalStats, ICloneable public IStats BuffStats => _buffStats; public IStats OptionalStats => _optionalStats; - public int BaseHP => BaseStats.HP; - public int BaseATK => BaseStats.ATK; - public int BaseDEF => BaseStats.DEF; - public int BaseCRI => BaseStats.CRI; - public int BaseHIT => BaseStats.HIT; - public int BaseSPD => BaseStats.SPD; - public int BaseDRV => BaseStats.DRV; - public int BaseDRR => BaseStats.DRR; - public int BaseCDMG => BaseStats.CDMG; - public int BaseArmorPenetration => BaseStats.ArmorPenetration; - public int BaseThorn => BaseStats.Thorn; - - public int AdditionalHP => HP - _baseStats.HP; - public int AdditionalATK => ATK - _baseStats.ATK; - public int AdditionalDEF => DEF - _baseStats.DEF; - public int AdditionalCRI => CRI - _baseStats.CRI; - public int AdditionalHIT => HIT - _baseStats.HIT; - public int AdditionalSPD => SPD - _baseStats.SPD; - public int AdditionalDRV => DRV - _baseStats.DRV; - public int AdditionalDRR => DRR - _baseStats.DRR; - public int AdditionalCDMG => CDMG - _baseStats.CDMG; - public int AdditionalArmorPenetration => ArmorPenetration - _baseStats.ArmorPenetration; - public int AdditionalThorn => Thorn - _baseStats.Thorn; + public long BaseHP => BaseStats.HP; + public long BaseATK => BaseStats.ATK; + public long BaseDEF => BaseStats.DEF; + public long BaseCRI => BaseStats.CRI; + public long BaseHIT => BaseStats.HIT; + public long BaseSPD => BaseStats.SPD; + public long BaseDRV => BaseStats.DRV; + public long BaseDRR => BaseStats.DRR; + public long BaseCDMG => BaseStats.CDMG; + public long BaseArmorPenetration => BaseStats.ArmorPenetration; + public long BaseThorn => BaseStats.Thorn; + + public long AdditionalHP => HP - _baseStats.HP; + public long AdditionalATK => ATK - _baseStats.ATK; + public long AdditionalDEF => DEF - _baseStats.DEF; + public long AdditionalCRI => CRI - _baseStats.CRI; + public long AdditionalHIT => HIT - _baseStats.HIT; + public long AdditionalSPD => SPD - _baseStats.SPD; + public long AdditionalDRV => DRV - _baseStats.DRV; + public long AdditionalDRR => DRR - _baseStats.DRR; + public long AdditionalCDMG => CDMG - _baseStats.CDMG; + public long AdditionalArmorPenetration => ArmorPenetration - _baseStats.ArmorPenetration; + public long AdditionalThorn => Thorn - _baseStats.Thorn; public bool IsArenaCharacter { private get; set; } = false; - public int HpIncreasingModifier { private get; set; } = 2; + public long HpIncreasingModifier { private get; set; } = 2; private readonly Dictionary MinimumStatValues = new Dictionary() @@ -356,7 +356,7 @@ public void SetOption(IEnumerable statModifiers) public void IncreaseHpForArena() { var originalHP = _statMap[StatType.HP]; - _statMap[StatType.HP].SetBaseValue(Math.Max(0, originalHP.TotalValueAsInt * HpIncreasingModifier)); + _statMap[StatType.HP].SetBaseValue(Math.Max(0, originalHP.TotalValueAsLong * HpIncreasingModifier)); } private void UpdateBaseStats() @@ -395,7 +395,7 @@ private void UpdateRuneStats() { if (!LegacyDecimalStatTypes.Contains(stat.StatType)) { - var value = Math.Max(0m, stat.BaseValueAsInt); + var value = Math.Max(0m, stat.BaseValueAsLong); stat.SetBaseValue(value); } else @@ -429,7 +429,7 @@ private void UpdateTotalStats() var minimumValue = MinimumStatValues[stat.StatType]; if (!LegacyDecimalStatTypes.Contains(stat.StatType)) { - var value = Math.Max(minimumValue, stat.BaseValueAsInt); + var value = Math.Max(minimumValue, stat.BaseValueAsLong); stat.SetBaseValue(value); } else @@ -450,17 +450,17 @@ public override object Clone() return new CharacterStats(this); } - public IEnumerable<(StatType statType, int baseValue)> GetBaseStats(bool ignoreZero = false) + public IEnumerable<(StatType statType, long baseValue)> GetBaseStats(bool ignoreZero = false) { return _baseStats.GetStats(ignoreZero); } - public IEnumerable<(StatType statType, int additionalValue)> GetAdditionalStats(bool ignoreZero = false) + public IEnumerable<(StatType statType, long additionalValue)> GetAdditionalStats(bool ignoreZero = false) { var baseStats = _baseStats.GetStats(); foreach (var (statType, stat) in baseStats) { - var value = _statMap[statType].BaseValueAsInt - stat; + var value = _statMap[statType].BaseValueAsLong - stat; if (!ignoreZero || value != default) { yield return (statType, value); @@ -468,13 +468,13 @@ public override object Clone() } } - public IEnumerable<(StatType statType, int baseValue, int additionalValue)> GetBaseAndAdditionalStats( + public IEnumerable<(StatType statType, long baseValue, long additionalValue)> GetBaseAndAdditionalStats( bool ignoreZero = false) { var additionalStats = GetAdditionalStats(); foreach (var (statType, additionalStat) in additionalStats) { - var baseStat = _baseStats.GetStatAsInt(statType); + var baseStat = _baseStats.GetStatAsLong(statType); if (!ignoreZero || (baseStat != default) || (additionalStat != default)) { diff --git a/Lib9c/Model/Stat/DecimalStat.cs b/Lib9c/Model/Stat/DecimalStat.cs index 3fbea3c157..9b47eb21d1 100644 --- a/Lib9c/Model/Stat/DecimalStat.cs +++ b/Lib9c/Model/Stat/DecimalStat.cs @@ -13,11 +13,11 @@ public class DecimalStat : ICloneable, IState public decimal AdditionalValue { get; private set; } - public bool HasTotalValueAsInt => HasBaseValueAsInt || HasAdditionalValueAsInt; + public bool HasTotalValueAsLong => HasBaseValueAsLong || HasAdditionalValueAsLong; - public bool HasBaseValueAsInt => BaseValue > 0; + public bool HasBaseValueAsLong => BaseValue > 0; - public bool HasAdditionalValueAsInt => AdditionalValue > 0; + public bool HasAdditionalValueAsLong => AdditionalValue > 0; public bool HasBaseValue => BaseValue > 0m; @@ -26,12 +26,12 @@ public class DecimalStat : ICloneable, IState public StatType StatType; - public int BaseValueAsInt => (int)BaseValue; + public long BaseValueAsLong => (long)BaseValue; - public int AdditionalValueAsInt => (int)AdditionalValue; + public long AdditionalValueAsLong => (long)AdditionalValue; [Obsolete("For legacy equipments. (Before world 7 patch)")] - public int TotalValueAsInt => BaseValueAsInt + AdditionalValueAsInt; + public long TotalValueAsLong => BaseValueAsLong + AdditionalValueAsLong; public decimal TotalValue => BaseValue + AdditionalValue; diff --git a/Lib9c/Model/Stat/IBaseAndAdditionalStats.cs b/Lib9c/Model/Stat/IBaseAndAdditionalStats.cs index da11040eee..1dc45060f0 100644 --- a/Lib9c/Model/Stat/IBaseAndAdditionalStats.cs +++ b/Lib9c/Model/Stat/IBaseAndAdditionalStats.cs @@ -4,32 +4,32 @@ namespace Nekoyume.Model.Stat { public interface IBaseAndAdditionalStats { - int BaseHP { get; } - int BaseATK { get; } - int BaseDEF { get; } - int BaseCRI { get; } - int BaseHIT { get; } - int BaseSPD { get; } - int BaseDRV { get; } - int BaseDRR { get; } - int BaseCDMG { get; } - int BaseArmorPenetration { get; } - int BaseThorn { get; } + long BaseHP { get; } + long BaseATK { get; } + long BaseDEF { get; } + long BaseCRI { get; } + long BaseHIT { get; } + long BaseSPD { get; } + long BaseDRV { get; } + long BaseDRR { get; } + long BaseCDMG { get; } + long BaseArmorPenetration { get; } + long BaseThorn { get; } - int AdditionalHP { get; } - int AdditionalATK { get; } - int AdditionalDEF { get; } - int AdditionalCRI { get; } - int AdditionalHIT { get; } - int AdditionalSPD { get; } - int AdditionalDRV { get; } - int AdditionalDRR { get; } - int AdditionalCDMG { get; } - int AdditionalArmorPenetration { get; } - int AdditionalThorn { get; } + long AdditionalHP { get; } + long AdditionalATK { get; } + long AdditionalDEF { get; } + long AdditionalCRI { get; } + long AdditionalHIT { get; } + long AdditionalSPD { get; } + long AdditionalDRV { get; } + long AdditionalDRR { get; } + long AdditionalCDMG { get; } + long AdditionalArmorPenetration { get; } + long AdditionalThorn { get; } - IEnumerable<(StatType statType, int baseValue)> GetBaseStats(bool ignoreZero = false); - IEnumerable<(StatType statType, int additionalValue)> GetAdditionalStats(bool ignoreZero = false); - IEnumerable<(StatType statType, int baseValue, int additionalValue)> GetBaseAndAdditionalStats(bool ignoreZero = false); + IEnumerable<(StatType statType, long baseValue)> GetBaseStats(bool ignoreZero = false); + IEnumerable<(StatType statType, long additionalValue)> GetAdditionalStats(bool ignoreZero = false); + IEnumerable<(StatType statType, long baseValue, long additionalValue)> GetBaseAndAdditionalStats(bool ignoreZero = false); } } diff --git a/Lib9c/Model/Stat/IStats.cs b/Lib9c/Model/Stat/IStats.cs index 497e1d2e9a..a91fb048a8 100644 --- a/Lib9c/Model/Stat/IStats.cs +++ b/Lib9c/Model/Stat/IStats.cs @@ -4,18 +4,18 @@ namespace Nekoyume.Model.Stat { public interface IStats { - int HP { get; } - int ATK { get; } - int DEF { get; } - int CRI { get; } - int HIT { get; } - int SPD { get; } - int DRV { get; } - int DRR { get; } - int CDMG { get; } - int ArmorPenetration { get; } - int Thorn { get; } + long HP { get; } + long ATK { get; } + long DEF { get; } + long CRI { get; } + long HIT { get; } + long SPD { get; } + long DRV { get; } + long DRR { get; } + long CDMG { get; } + long ArmorPenetration { get; } + long Thorn { get; } - IEnumerable<(StatType statType, int value)> GetStats(bool ignoreZero = false); + IEnumerable<(StatType statType, long value)> GetStats(bool ignoreZero = false); } } diff --git a/Lib9c/Model/Stat/StatMap.cs b/Lib9c/Model/Stat/StatMap.cs index 86db8f88fb..9149fd2a1d 100644 --- a/Lib9c/Model/Stat/StatMap.cs +++ b/Lib9c/Model/Stat/StatMap.cs @@ -15,41 +15,41 @@ public DecimalStat this[StatType type] get => _statMap[type]; } - public int HP => _statMap[StatType.HP].TotalValueAsInt; - public int ATK => _statMap[StatType.ATK].TotalValueAsInt; - public int DEF => _statMap[StatType.DEF].TotalValueAsInt; - public int CRI => _statMap[StatType.CRI].TotalValueAsInt; - public int HIT => _statMap[StatType.HIT].TotalValueAsInt; - public int SPD => _statMap[StatType.SPD].TotalValueAsInt; - public int DRV => _statMap[StatType.DRV].TotalValueAsInt; - public int DRR => _statMap[StatType.DRR].TotalValueAsInt; - public int CDMG => _statMap[StatType.CDMG].TotalValueAsInt; - public int ArmorPenetration => _statMap[StatType.ArmorPenetration].TotalValueAsInt; - public int Thorn => _statMap[StatType.Thorn].TotalValueAsInt; - - public int BaseHP => _statMap[StatType.HP].BaseValueAsInt; - public int BaseATK => _statMap[StatType.ATK].BaseValueAsInt; - public int BaseDEF => _statMap[StatType.DEF].BaseValueAsInt; - public int BaseCRI => _statMap[StatType.CRI].BaseValueAsInt; - public int BaseHIT => _statMap[StatType.HIT].BaseValueAsInt; - public int BaseSPD => _statMap[StatType.SPD].BaseValueAsInt; - public int BaseDRV => _statMap[StatType.DRV].BaseValueAsInt; - public int BaseDRR => _statMap[StatType.DRR].BaseValueAsInt; - public int BaseCDMG => _statMap[StatType.CDMG].BaseValueAsInt; - public int BaseArmorPenetration => _statMap[StatType.ArmorPenetration].BaseValueAsInt; - public int BaseThorn => _statMap[StatType.Thorn].BaseValueAsInt; - - public int AdditionalHP => _statMap[StatType.HP].AdditionalValueAsInt; - public int AdditionalATK => _statMap[StatType.ATK].AdditionalValueAsInt; - public int AdditionalDEF => _statMap[StatType.DEF].AdditionalValueAsInt; - public int AdditionalCRI => _statMap[StatType.CRI].AdditionalValueAsInt; - public int AdditionalHIT => _statMap[StatType.HIT].AdditionalValueAsInt; - public int AdditionalSPD => _statMap[StatType.SPD].AdditionalValueAsInt; - public int AdditionalDRV => _statMap[StatType.DRV].AdditionalValueAsInt; - public int AdditionalDRR => _statMap[StatType.DRR].AdditionalValueAsInt; - public int AdditionalCDMG => _statMap[StatType.CDMG].AdditionalValueAsInt; - public int AdditionalArmorPenetration => _statMap[StatType.ArmorPenetration].AdditionalValueAsInt; - public int AdditionalThorn => _statMap[StatType.Thorn].AdditionalValueAsInt; + public long HP => _statMap[StatType.HP].TotalValueAsLong; + public long ATK => _statMap[StatType.ATK].TotalValueAsLong; + public long DEF => _statMap[StatType.DEF].TotalValueAsLong; + public long CRI => _statMap[StatType.CRI].TotalValueAsLong; + public long HIT => _statMap[StatType.HIT].TotalValueAsLong; + public long SPD => _statMap[StatType.SPD].TotalValueAsLong; + public long DRV => _statMap[StatType.DRV].TotalValueAsLong; + public long DRR => _statMap[StatType.DRR].TotalValueAsLong; + public long CDMG => _statMap[StatType.CDMG].TotalValueAsLong; + public long ArmorPenetration => _statMap[StatType.ArmorPenetration].TotalValueAsLong; + public long Thorn => _statMap[StatType.Thorn].TotalValueAsLong; + + public long BaseHP => _statMap[StatType.HP].BaseValueAsLong; + public long BaseATK => _statMap[StatType.ATK].BaseValueAsLong; + public long BaseDEF => _statMap[StatType.DEF].BaseValueAsLong; + public long BaseCRI => _statMap[StatType.CRI].BaseValueAsLong; + public long BaseHIT => _statMap[StatType.HIT].BaseValueAsLong; + public long BaseSPD => _statMap[StatType.SPD].BaseValueAsLong; + public long BaseDRV => _statMap[StatType.DRV].BaseValueAsLong; + public long BaseDRR => _statMap[StatType.DRR].BaseValueAsLong; + public long BaseCDMG => _statMap[StatType.CDMG].BaseValueAsLong; + public long BaseArmorPenetration => _statMap[StatType.ArmorPenetration].BaseValueAsLong; + public long BaseThorn => _statMap[StatType.Thorn].BaseValueAsLong; + + public long AdditionalHP => _statMap[StatType.HP].AdditionalValueAsLong; + public long AdditionalATK => _statMap[StatType.ATK].AdditionalValueAsLong; + public long AdditionalDEF => _statMap[StatType.DEF].AdditionalValueAsLong; + public long AdditionalCRI => _statMap[StatType.CRI].AdditionalValueAsLong; + public long AdditionalHIT => _statMap[StatType.HIT].AdditionalValueAsLong; + public long AdditionalSPD => _statMap[StatType.SPD].AdditionalValueAsLong; + public long AdditionalDRV => _statMap[StatType.DRV].AdditionalValueAsLong; + public long AdditionalDRR => _statMap[StatType.DRR].AdditionalValueAsLong; + public long AdditionalCDMG => _statMap[StatType.CDMG].AdditionalValueAsLong; + public long AdditionalArmorPenetration => _statMap[StatType.ArmorPenetration].AdditionalValueAsLong; + public long AdditionalThorn => _statMap[StatType.Thorn].AdditionalValueAsLong; private readonly Dictionary _statMap = new Dictionary(StatTypeComparer.Instance) @@ -87,14 +87,14 @@ public void Reset() } } - public int GetStatAsInt(StatType statType) + public long GetStatAsLong(StatType statType) { if (!_statMap.TryGetValue(statType, out var decimalStat)) { throw new KeyNotFoundException($"StatType {statType} is missing in statMap."); } - return decimalStat.TotalValueAsInt; + return decimalStat.TotalValueAsLong; } public decimal GetStat(StatType statType) @@ -107,95 +107,95 @@ public decimal GetStat(StatType statType) return decimalStat.TotalValue; } - public int GetBaseStat(StatType statType) + public long GetBaseStat(StatType statType) { if (!_statMap.TryGetValue(statType, out var decimalStat)) { throw new KeyNotFoundException($"StatType {statType} is missing in statMap."); } - return decimalStat.BaseValueAsInt; + return decimalStat.BaseValueAsLong; } - public int GetAdditionalStat(StatType statType) + public long GetAdditionalStat(StatType statType) { if (!_statMap.TryGetValue(statType, out var decimalStat)) { throw new KeyNotFoundException($"StatType {statType} is missing in statMap."); } - return decimalStat.AdditionalValueAsInt; + return decimalStat.AdditionalValueAsLong; } - public IEnumerable<(StatType statType, int value)> GetStats(bool ignoreZero = false) + public IEnumerable<(StatType statType, long value)> GetStats(bool ignoreZero = false) { foreach (var (statType, stat) in _statMap.OrderBy(x => x.Key)) { if (ignoreZero) { - if (stat.HasTotalValueAsInt) + if (stat.HasTotalValueAsLong) { - yield return (statType, stat.TotalValueAsInt); + yield return (statType, stat.TotalValueAsLong); } } else { - yield return (statType, stat.TotalValueAsInt); + yield return (statType, stat.TotalValueAsLong); } } } - public IEnumerable<(StatType statType, int baseValue)> GetBaseStats(bool ignoreZero = false) + public IEnumerable<(StatType statType, long baseValue)> GetBaseStats(bool ignoreZero = false) { foreach (var (statType, stat) in _statMap.OrderBy(x => x.Key)) { if (ignoreZero) { - if (stat.HasBaseValueAsInt) + if (stat.HasBaseValueAsLong) { - yield return (statType, stat.BaseValueAsInt); + yield return (statType, stat.BaseValueAsLong); } } else { - yield return (statType, stat.BaseValueAsInt); + yield return (statType, stat.BaseValueAsLong); } } } - public IEnumerable<(StatType statType, int additionalValue)> GetAdditionalStats(bool ignoreZero = false) + public IEnumerable<(StatType statType, long additionalValue)> GetAdditionalStats(bool ignoreZero = false) { foreach (var (statType, stat) in _statMap.OrderBy(x => x.Key)) { if (ignoreZero) { - if (stat.HasAdditionalValueAsInt) + if (stat.HasAdditionalValueAsLong) { - yield return (statType, stat.AdditionalValueAsInt); + yield return (statType, stat.AdditionalValueAsLong); } } else { - yield return (statType, stat.AdditionalValueAsInt); + yield return (statType, stat.AdditionalValueAsLong); } } } - public IEnumerable<(StatType statType, int baseValue, int additionalValue)> GetBaseAndAdditionalStats( + public IEnumerable<(StatType statType, long baseValue, long additionalValue)> GetBaseAndAdditionalStats( bool ignoreZero = false) { foreach (var (statType, stat) in _statMap.OrderBy(x => x.Key)) { if (ignoreZero) { - if (stat.HasBaseValueAsInt || stat.HasAdditionalValueAsInt) + if (stat.HasBaseValueAsLong || stat.HasAdditionalValueAsLong) { - yield return (statType, stat.BaseValueAsInt, stat.AdditionalValueAsInt); + yield return (statType, stat.BaseValueAsLong, stat.AdditionalValueAsLong); } } else { - yield return (statType, stat.BaseValueAsInt, stat.AdditionalValueAsInt); + yield return (statType, stat.BaseValueAsLong, stat.AdditionalValueAsLong); } } } @@ -204,7 +204,7 @@ public IEnumerable GetDecimalStats(bool ignoreZero) { var values = _statMap.OrderBy(x => x.Key).Select(x => x.Value); return ignoreZero ? - values.Where(x => x.HasBaseValueAsInt || x.HasAdditionalValueAsInt) : + values.Where(x => x.HasBaseValueAsLong || x.HasAdditionalValueAsLong) : values; } diff --git a/Lib9c/Model/Stat/StatModifier.cs b/Lib9c/Model/Stat/StatModifier.cs index 79453ea908..364b1f08da 100644 --- a/Lib9c/Model/Stat/StatModifier.cs +++ b/Lib9c/Model/Stat/StatModifier.cs @@ -13,17 +13,17 @@ public enum OperationType public StatType StatType { get; } public OperationType Operation { get; } - public int Value { get; private set; } + public long Value { get; private set; } - public StatModifier(StatType statType, OperationType operation, int value) + public StatModifier(StatType statType, OperationType operation, long value) { StatType = statType; Operation = operation; Value = value; } - + public StatModifier(DecimalStat decimalStat) : this(decimalStat.StatType, OperationType.Add, - decimalStat.TotalValueAsInt) + decimalStat.TotalValueAsLong) { } @@ -32,9 +32,9 @@ public StatModifier(DecimalStat decimalStat) : this(decimalStat.StatType, Operat /// /// /// - public int GetModifiedAll(int value) + public long GetModifiedAll(long value) { - return value + GetModifiedValue(value); + return value + (long)GetModifiedValue(value); } /// @@ -53,14 +53,14 @@ public decimal GetModifiedAll(decimal value) /// /// /// - public int GetModifiedValue(int value) + public long GetModifiedValue(int value) { switch (Operation) { case OperationType.Add: return Value; case OperationType.Percentage: - return (int)(value * Value / 100m); + return (long)(value * Value / 100m); default: throw new ArgumentOutOfRangeException(); } diff --git a/Lib9c/Model/Stat/Stats.cs b/Lib9c/Model/Stat/Stats.cs index da984619b9..c0140bd4f3 100644 --- a/Lib9c/Model/Stat/Stats.cs +++ b/Lib9c/Model/Stat/Stats.cs @@ -10,21 +10,21 @@ public class Stats : IStats, ICloneable { protected readonly StatMap _statMap; - public int HP => _statMap[StatType.HP].BaseValueAsInt; - public int ATK => _statMap[StatType.ATK].BaseValueAsInt; - public int DEF => _statMap[StatType.DEF].BaseValueAsInt; - public int CRI => _statMap[StatType.CRI].BaseValueAsInt; - public int HIT => _statMap[StatType.HIT].BaseValueAsInt; - public int SPD => _statMap[StatType.SPD].BaseValueAsInt; - public int DRV => _statMap[StatType.DRV].BaseValueAsInt; - public int DRR => _statMap[StatType.DRR].BaseValueAsInt; - public int CDMG => _statMap[StatType.CDMG].BaseValueAsInt; - public int ArmorPenetration => _statMap[StatType.ArmorPenetration].BaseValueAsInt; - public int Thorn => _statMap[StatType.Thorn].BaseValueAsInt; + public long HP => _statMap[StatType.HP].BaseValueAsLong; + public long ATK => _statMap[StatType.ATK].BaseValueAsLong; + public long DEF => _statMap[StatType.DEF].BaseValueAsLong; + public long CRI => _statMap[StatType.CRI].BaseValueAsLong; + public long HIT => _statMap[StatType.HIT].BaseValueAsLong; + public long SPD => _statMap[StatType.SPD].BaseValueAsLong; + public long DRV => _statMap[StatType.DRV].BaseValueAsLong; + public long DRR => _statMap[StatType.DRR].BaseValueAsLong; + public long CDMG => _statMap[StatType.CDMG].BaseValueAsLong; + public long ArmorPenetration => _statMap[StatType.ArmorPenetration].BaseValueAsLong; + public long Thorn => _statMap[StatType.Thorn].BaseValueAsLong; protected readonly HashSet LegacyDecimalStatTypes = new HashSet{ StatType.CRI, StatType.HIT, StatType.SPD }; - + public Stats() { _statMap = new StatMap(); @@ -46,10 +46,10 @@ public void Set(StatMap statMap, params Stats[] statsArray) { if (!LegacyDecimalStatTypes.Contains(stat.StatType)) { - int sum = 0; + long sum = 0; foreach (var s in statsArray) { - sum += s.GetStatAsInt(stat.StatType); + sum += s.GetStatAsLong(stat.StatType); } stat.SetBaseValue(sum); } @@ -82,7 +82,7 @@ public void Modify(IEnumerable statModifiers) var statType = statModifier.StatType; if (!LegacyDecimalStatTypes.Contains(statType)) { - var originalStatValue = GetStatAsInt(statType); + var originalStatValue = GetStatAsLong(statType); var result = statModifier.GetModifiedValue(originalStatValue); _statMap[statModifier.StatType].AddBaseValue(result); } @@ -104,13 +104,13 @@ public void Set(IEnumerable statModifiers, params Stats[] baseStat var statType = statModifier.StatType; if (!LegacyDecimalStatTypes.Contains(statType)) { - int originalStatValue = 0; + long originalStatValue = 0; foreach (var stats in baseStats) { - originalStatValue += stats.GetStatAsInt(statType); + originalStatValue += stats.GetStatAsLong(statType); } - int result = statModifier.GetModifiedValue(originalStatValue); + long result = (long)statModifier.GetModifiedValue(originalStatValue); _statMap[statModifier.StatType].AddBaseValue(result); } else @@ -127,9 +127,9 @@ public void Set(IEnumerable statModifiers, params Stats[] baseStat } } - public int GetStatAsInt(StatType statType) + public long GetStatAsLong(StatType statType) { - return _statMap.GetStatAsInt(statType); + return _statMap.GetStatAsLong(statType); } public decimal GetStat(StatType statType) @@ -148,7 +148,7 @@ public void SetStatForTest(StatType statType, decimal value) _statMap[statType].SetBaseValue(value); } - public IEnumerable<(StatType statType, int value)> GetStats(bool ignoreZero = false) + public IEnumerable<(StatType statType, long value)> GetStats(bool ignoreZero = false) { return _statMap.GetStats(ignoreZero); } diff --git a/Lib9c/Model/Stat/StatsMap.cs b/Lib9c/Model/Stat/StatsMap.cs index 9d29d2ddd1..5c134e38a5 100644 --- a/Lib9c/Model/Stat/StatsMap.cs +++ b/Lib9c/Model/Stat/StatsMap.cs @@ -10,41 +10,41 @@ namespace Nekoyume.Model.Stat [Serializable] public class StatsMap : IStats, IBaseAndAdditionalStats, IState { - public int HP => GetStat(StatType.HP); - public int ATK => GetStat(StatType.ATK); - public int DEF => GetStat(StatType.DEF); - public int CRI => GetStat(StatType.CRI); - public int HIT => GetStat(StatType.HIT); - public int SPD => GetStat(StatType.SPD); - public int DRV => GetStat(StatType.DRV); - public int DRR => GetStat(StatType.DRR); - public int CDMG => GetStat(StatType.CDMG); - public int ArmorPenetration => GetStat(StatType.ArmorPenetration); - public int Thorn => GetStat(StatType.Thorn); - - public int BaseHP => GetBaseStat(StatType.HP); - public int BaseATK => GetBaseStat(StatType.ATK); - public int BaseDEF => GetBaseStat(StatType.DEF); - public int BaseCRI => GetBaseStat(StatType.CRI); - public int BaseHIT => GetBaseStat(StatType.HIT); - public int BaseSPD => GetBaseStat(StatType.SPD); - public int BaseDRV => GetBaseStat(StatType.DRV); - public int BaseDRR => GetBaseStat(StatType.DRR); - public int BaseCDMG => GetBaseStat(StatType.CDMG); - public int BaseArmorPenetration => GetBaseStat(StatType.ArmorPenetration); - public int BaseThorn => GetBaseStat(StatType.Thorn); - - public int AdditionalHP => GetAdditionalStat(StatType.HP); - public int AdditionalATK => GetAdditionalStat(StatType.ATK); - public int AdditionalDEF => GetAdditionalStat(StatType.DEF); - public int AdditionalCRI => GetAdditionalStat(StatType.CRI); - public int AdditionalHIT => GetAdditionalStat(StatType.HIT); - public int AdditionalSPD => GetAdditionalStat(StatType.SPD); - public int AdditionalDRV => GetAdditionalStat(StatType.DRV); - public int AdditionalDRR => GetAdditionalStat(StatType.DRR); - public int AdditionalCDMG => GetAdditionalStat(StatType.CDMG); - public int AdditionalArmorPenetration => GetAdditionalStat(StatType.ArmorPenetration); - public int AdditionalThorn => GetAdditionalStat(StatType.Thorn); + public long HP => GetStat(StatType.HP); + public long ATK => GetStat(StatType.ATK); + public long DEF => GetStat(StatType.DEF); + public long CRI => GetStat(StatType.CRI); + public long HIT => GetStat(StatType.HIT); + public long SPD => GetStat(StatType.SPD); + public long DRV => GetStat(StatType.DRV); + public long DRR => GetStat(StatType.DRR); + public long CDMG => GetStat(StatType.CDMG); + public long ArmorPenetration => GetStat(StatType.ArmorPenetration); + public long Thorn => GetStat(StatType.Thorn); + + public long BaseHP => GetBaseStat(StatType.HP); + public long BaseATK => GetBaseStat(StatType.ATK); + public long BaseDEF => GetBaseStat(StatType.DEF); + public long BaseCRI => GetBaseStat(StatType.CRI); + public long BaseHIT => GetBaseStat(StatType.HIT); + public long BaseSPD => GetBaseStat(StatType.SPD); + public long BaseDRV => GetBaseStat(StatType.DRV); + public long BaseDRR => GetBaseStat(StatType.DRR); + public long BaseCDMG => GetBaseStat(StatType.CDMG); + public long BaseArmorPenetration => GetBaseStat(StatType.ArmorPenetration); + public long BaseThorn => GetBaseStat(StatType.Thorn); + + public long AdditionalHP => GetAdditionalStat(StatType.HP); + public long AdditionalATK => GetAdditionalStat(StatType.ATK); + public long AdditionalDEF => GetAdditionalStat(StatType.DEF); + public long AdditionalCRI => GetAdditionalStat(StatType.CRI); + public long AdditionalHIT => GetAdditionalStat(StatType.HIT); + public long AdditionalSPD => GetAdditionalStat(StatType.SPD); + public long AdditionalDRV => GetAdditionalStat(StatType.DRV); + public long AdditionalDRR => GetAdditionalStat(StatType.DRR); + public long AdditionalCDMG => GetAdditionalStat(StatType.CDMG); + public long AdditionalArmorPenetration => GetAdditionalStat(StatType.ArmorPenetration); + public long AdditionalThorn => GetAdditionalStat(StatType.Thorn); private readonly StatMap _statMap = new StatMap(); @@ -66,17 +66,17 @@ public override int GetHashCode() return _statMap != null ? _statMap.GetHashCode() : 0; } - public int GetStat(StatType statType) + public long GetStat(StatType statType) { - return _statMap.GetStatAsInt(statType); + return _statMap.GetStatAsLong(statType); } - public int GetBaseStat(StatType statType) + public long GetBaseStat(StatType statType) { return _statMap.GetBaseStat(statType); } - public int GetAdditionalStat(StatType statType) + public long GetAdditionalStat(StatType statType) { return _statMap.GetAdditionalStat(statType); } @@ -105,22 +105,22 @@ public void SetStatAdditionalValue(StatType key, decimal additionalValue) public void Deserialize(Dictionary serialized) => _statMap.Deserialize(serialized); - public IEnumerable<(StatType statType, int value)> GetStats(bool ignoreZero = false) + public IEnumerable<(StatType statType, long value)> GetStats(bool ignoreZero = false) { return _statMap.GetStats(ignoreZero); } - public IEnumerable<(StatType statType, int baseValue)> GetBaseStats(bool ignoreZero = false) + public IEnumerable<(StatType statType, long baseValue)> GetBaseStats(bool ignoreZero = false) { return _statMap.GetBaseStats(ignoreZero); } - public IEnumerable<(StatType statType, int additionalValue)> GetAdditionalStats(bool ignoreZero = false) + public IEnumerable<(StatType statType, long additionalValue)> GetAdditionalStats(bool ignoreZero = false) { return _statMap.GetAdditionalStats(ignoreZero); } - public IEnumerable<(StatType statType, int baseValue, int additionalValue)> GetBaseAndAdditionalStats( + public IEnumerable<(StatType statType, long baseValue, long additionalValue)> GetBaseAndAdditionalStats( bool ignoreZero = false) { return _statMap.GetBaseAndAdditionalStats(ignoreZero); From 933197ad7891b572def3ad16a9ffc4e65b080075 Mon Sep 17 00:00:00 2001 From: Yang Chun Ung Date: Tue, 23 Jan 2024 14:33:46 +0900 Subject: [PATCH 02/11] Change skill power int to int64 --- Lib9c/Battle/CriticalHelper.cs | 8 ++++---- Lib9c/Helper/ItemOptionHelper.cs | 12 ++++++------ Lib9c/Model/BattleStatus/Arena/ArenaSkill.cs | 8 ++++---- Lib9c/Model/BattleStatus/Skill.cs | 6 +++--- Lib9c/Model/Buff/Bleed.cs | 4 ++-- Lib9c/Model/Buff/Vampiric.cs | 4 ++-- Lib9c/Model/Character/ArenaCharacter.cs | 10 +++++----- Lib9c/Model/Elemental/ElementalType.cs | 4 ++-- Lib9c/Model/Skill/AreaAttack.cs | 2 +- Lib9c/Model/Skill/Arena/ArenaAreaAttack.cs | 2 +- Lib9c/Model/Skill/Arena/ArenaAttackSkill.cs | 8 ++++---- Lib9c/Model/Skill/Arena/ArenaBlowAttack.cs | 2 +- Lib9c/Model/Skill/Arena/ArenaBuffRemovalAttack.cs | 2 +- Lib9c/Model/Skill/Arena/ArenaBuffSkill.cs | 2 +- Lib9c/Model/Skill/Arena/ArenaDoubleAttack.cs | 2 +- Lib9c/Model/Skill/Arena/ArenaHealSkill.cs | 2 +- Lib9c/Model/Skill/Arena/ArenaNormalAttack.cs | 2 +- Lib9c/Model/Skill/Arena/ArenaSkill.cs | 8 ++++---- Lib9c/Model/Skill/AttackSkill.cs | 10 +++++----- Lib9c/Model/Skill/BlowAttack.cs | 2 +- Lib9c/Model/Skill/BuffRemovalAttack.cs | 2 +- Lib9c/Model/Skill/BuffSkill.cs | 2 +- Lib9c/Model/Skill/DoubleAttack.cs | 2 +- Lib9c/Model/Skill/HealSkill.cs | 2 +- Lib9c/Model/Skill/ISkill.cs | 4 ++-- Lib9c/Model/Skill/NormalAttack.cs | 2 +- Lib9c/Model/Skill/Skill.cs | 8 ++++---- Lib9c/Model/Skill/SkillCustomField.cs | 2 +- Lib9c/Model/Skill/SkillFactory.cs | 6 +++--- Lib9c/TableData/Skill/StatBuffSheet.cs | 4 ++-- 30 files changed, 67 insertions(+), 67 deletions(-) diff --git a/Lib9c/Battle/CriticalHelper.cs b/Lib9c/Battle/CriticalHelper.cs index c76f2621d9..ce3a2d3b54 100644 --- a/Lib9c/Battle/CriticalHelper.cs +++ b/Lib9c/Battle/CriticalHelper.cs @@ -12,22 +12,22 @@ public static class CriticalHelper { private const decimal MinimumDamageMultiplier = 1m; - public static int GetCriticalDamage(CharacterBase caster, int originalDamage) + public static long GetCriticalDamage(CharacterBase caster, long originalDamage) { var critMultiplier = Math.Max( MinimumDamageMultiplier, CharacterBase.CriticalMultiplier + (caster.CDMG / 10000m)); - return (int)(originalDamage * critMultiplier); + return (long)(originalDamage * critMultiplier); } - public static int GetCriticalDamageForArena(ArenaCharacter caster, int originalDamage) + public static long GetCriticalDamageForArena(ArenaCharacter caster, long originalDamage) { var critMultiplier = Math.Max( MinimumDamageMultiplier, ArenaCharacter.CriticalMultiplier + (caster.CDMG / 10000m)); - return (int)(originalDamage * critMultiplier); + return (long)(originalDamage * critMultiplier); } } } diff --git a/Lib9c/Helper/ItemOptionHelper.cs b/Lib9c/Helper/ItemOptionHelper.cs index 2ac7a55cd1..b9d4027f1b 100644 --- a/Lib9c/Helper/ItemOptionHelper.cs +++ b/Lib9c/Helper/ItemOptionHelper.cs @@ -11,13 +11,13 @@ public class ItemOptionInfo { public readonly int OptionCountFromCombination; - public readonly (StatType type, int baseValue, int totalValue) MainStat; + public readonly (StatType type, long baseValue, long totalValue) MainStat; - public readonly List<(StatType type, int value, int count)> StatOptions - = new List<(StatType type, int value, int count)>(); + public readonly List<(StatType type, long value, int count)> StatOptions + = new List<(StatType type, long value, int count)>(); - public readonly List<(SkillSheet.Row skillRow, int power, int chance, int statPowerRatio, StatType refStatType)> SkillOptions - = new List<(SkillSheet.Row skillRow, int power, int chance, int statPowerRatio, StatType refStatType)>(); + public readonly List<(SkillSheet.Row skillRow, long power, int chance, int statPowerRatio, StatType refStatType)> SkillOptions + = new List<(SkillSheet.Row skillRow, long power, int chance, int statPowerRatio, StatType refStatType)>(); public readonly int CP; @@ -168,7 +168,7 @@ public static bool TryGet(ItemUsable itemUsable, out ItemOptionInfo itemOptionIn } public static List GetStatOptionRows( - int subRecipeId, + long subRecipeId, ItemUsable itemUsable, EquipmentItemSubRecipeSheetV2 subRecipeSheet, EquipmentItemOptionSheet itemOptionSheet) diff --git a/Lib9c/Model/BattleStatus/Arena/ArenaSkill.cs b/Lib9c/Model/BattleStatus/Arena/ArenaSkill.cs index 4380020c41..f4a4d1aae3 100644 --- a/Lib9c/Model/BattleStatus/Arena/ArenaSkill.cs +++ b/Lib9c/Model/BattleStatus/Arena/ArenaSkill.cs @@ -13,17 +13,17 @@ public abstract class ArenaSkill : ArenaEventBase public class ArenaSkillInfo { public readonly ArenaCharacter Target; - public readonly int Effect; + public readonly long Effect; public readonly bool Critical; public readonly SkillCategory SkillCategory; public readonly ElementalType ElementalType; public readonly SkillTargetType SkillTargetType; public readonly int Turn; - + public readonly Model.Buff.Buff? Buff; - public ArenaSkillInfo(ArenaCharacter character, int effect, bool critical, SkillCategory skillCategory, + public ArenaSkillInfo(ArenaCharacter character, long effect, bool critical, SkillCategory skillCategory, int turn, ElementalType elementalType = ElementalType.Normal, SkillTargetType targetType = SkillTargetType.Enemy, Model.Buff.Buff? buff = null) { @@ -40,7 +40,7 @@ public ArenaSkillInfo(ArenaCharacter character, int effect, bool critical, Skill public readonly IEnumerable SkillInfos; - + public readonly IEnumerable? BuffInfos; protected ArenaSkill( diff --git a/Lib9c/Model/BattleStatus/Skill.cs b/Lib9c/Model/BattleStatus/Skill.cs index 48149d5a4d..17240eab63 100644 --- a/Lib9c/Model/BattleStatus/Skill.cs +++ b/Lib9c/Model/BattleStatus/Skill.cs @@ -13,20 +13,20 @@ public abstract class Skill : EventBase public class SkillInfo { public readonly CharacterBase? Target; - public readonly int Effect; + public readonly long Effect; public readonly bool Critical; public readonly SkillCategory SkillCategory; public readonly ElementalType ElementalType; public readonly SkillTargetType SkillTargetType; public readonly int WaveTurn; - public readonly int Thorn; + public readonly long Thorn; public readonly bool IsDead; public readonly Guid CharacterId; public readonly Model.Buff.Buff? Buff; - public SkillInfo(Guid characterId, bool isDead, int thorn, int effect, bool critical, SkillCategory skillCategory, + public SkillInfo(Guid characterId, bool isDead, long thorn, long effect, bool critical, SkillCategory skillCategory, int waveTurn, ElementalType elementalType = ElementalType.Normal, SkillTargetType targetType = SkillTargetType.Enemy, Model.Buff.Buff? buff = null, CharacterBase? target = null) { diff --git a/Lib9c/Model/Buff/Bleed.cs b/Lib9c/Model/Buff/Bleed.cs index e93e190617..c5ec159068 100644 --- a/Lib9c/Model/Buff/Bleed.cs +++ b/Lib9c/Model/Buff/Bleed.cs @@ -9,9 +9,9 @@ namespace Nekoyume.Model.Buff [Serializable] public class Bleed : ActionBuff { - public int Power { get; } + public long Power { get; } - public Bleed(ActionBuffSheet.Row row, int power) : base(row) + public Bleed(ActionBuffSheet.Row row, long power) : base(row) { Power = power; } diff --git a/Lib9c/Model/Buff/Vampiric.cs b/Lib9c/Model/Buff/Vampiric.cs index 9efb86cb33..3b8a202ee7 100644 --- a/Lib9c/Model/Buff/Vampiric.cs +++ b/Lib9c/Model/Buff/Vampiric.cs @@ -9,9 +9,9 @@ namespace Nekoyume.Model.Buff [Serializable] public class Vampiric : ActionBuff { - public int BasisPoint { get; } + public long BasisPoint { get; } - public Vampiric(ActionBuffSheet.Row row, int basisPoint) : base(row) + public Vampiric(ActionBuffSheet.Row row, long basisPoint) : base(row) { BasisPoint = basisPoint; } diff --git a/Lib9c/Model/Character/ArenaCharacter.cs b/Lib9c/Model/Character/ArenaCharacter.cs index f50e60b530..f2153029be 100644 --- a/Lib9c/Model/Character/ArenaCharacter.cs +++ b/Lib9c/Model/Character/ArenaCharacter.cs @@ -37,10 +37,10 @@ public class ArenaCharacter : ICloneable public readonly ArenaSkills _runeSkills = new ArenaSkills(); public readonly Dictionary RuneSkillCooldownMap = new Dictionary(); - private readonly long _attackCountMax; + private readonly int _attackCountMax; private ArenaCharacter _target; - private long _attackCount; + private int _attackCount; public Guid Id { get; } = Guid.NewGuid(); public BattleStatus.Arena.ArenaSkill SkillLog { get; private set; } @@ -351,12 +351,12 @@ public void SetRuneV1( continue; } - var power = 0; + long power = 0; if (optionInfo.StatReferenceType == EnumType.StatReferenceType.Caster) { if (optionInfo.SkillValueType == StatModifier.OperationType.Add) { - power = (int)optionInfo.SkillValue; + power = (long)optionInfo.SkillValue; } else { @@ -373,7 +373,7 @@ public void SetRuneV1( break; } - power = (int)Math.Round(power * optionInfo.SkillValue); + power = (long)Math.Round(power * optionInfo.SkillValue); } } var skill = SkillFactory.GetForArena(skillRow, power, optionInfo.SkillChance, default, StatType.NONE); diff --git a/Lib9c/Model/Elemental/ElementalType.cs b/Lib9c/Model/Elemental/ElementalType.cs index 2d93aecc61..73bf185299 100644 --- a/Lib9c/Model/Elemental/ElementalType.cs +++ b/Lib9c/Model/Elemental/ElementalType.cs @@ -117,9 +117,9 @@ public static ElementalResult GetBattleResult(this ElementalType from, Elemental return ElementalResult.Draw; } - public static int GetDamage(this ElementalType from, ElementalType to, int damage) + public static long GetDamage(this ElementalType from, ElementalType to, long damage) { - return Convert.ToInt32(damage * GetMultiplier(from, to)); + return Convert.ToInt64(damage * GetMultiplier(from, to)); } public static decimal GetMultiplier(this ElementalType from, ElementalType to) diff --git a/Lib9c/Model/Skill/AreaAttack.cs b/Lib9c/Model/Skill/AreaAttack.cs index 6da4cd3d87..b7f048d18a 100644 --- a/Lib9c/Model/Skill/AreaAttack.cs +++ b/Lib9c/Model/Skill/AreaAttack.cs @@ -10,7 +10,7 @@ public class AreaAttack : AttackSkill { public AreaAttack( SkillSheet.Row skillRow, - int power, + long power, int chance, int statPowerRatio, StatType referencedStatType) : base(skillRow, power, chance, statPowerRatio, referencedStatType) diff --git a/Lib9c/Model/Skill/Arena/ArenaAreaAttack.cs b/Lib9c/Model/Skill/Arena/ArenaAreaAttack.cs index 1c3ebe125b..584364c862 100644 --- a/Lib9c/Model/Skill/Arena/ArenaAreaAttack.cs +++ b/Lib9c/Model/Skill/Arena/ArenaAreaAttack.cs @@ -10,7 +10,7 @@ public class ArenaAreaAttack : ArenaAttackSkill { public ArenaAreaAttack( SkillSheet.Row skillRow, - int power, + long power, int chance, int statPowerRatio, StatType referencedStatType) : base(skillRow, power, chance, statPowerRatio, referencedStatType) diff --git a/Lib9c/Model/Skill/Arena/ArenaAttackSkill.cs b/Lib9c/Model/Skill/Arena/ArenaAttackSkill.cs index 009a6eaa5d..2acb4a85c7 100644 --- a/Lib9c/Model/Skill/Arena/ArenaAttackSkill.cs +++ b/Lib9c/Model/Skill/Arena/ArenaAttackSkill.cs @@ -12,7 +12,7 @@ public abstract class ArenaAttackSkill : ArenaSkill { protected ArenaAttackSkill( SkillSheet.Row skillRow, - int power, + long power, int chance, int statPowerRatio, StatType referencedStatType) : base(skillRow, power, chance, statPowerRatio, referencedStatType) @@ -37,13 +37,13 @@ protected ArenaAttackSkill( for (var i = 0; i < SkillRow.HitCount; i++) { var multiplier = multipliers[i]; - var damage = 0; + long damage = 0; var isCritical = false; if (target.IsHit(caster)) { damage = caster.ATK + Power + statAdditionalPower; - damage = (int) (damage * multiplier); + damage = (long) (damage * multiplier); damage = caster.GetDamage(damage, isNormalAttack); damage = elementalType.GetDamage(target.DefenseElementalType, damage); isCritical = caster.IsCritical(isNormalAttack); @@ -53,7 +53,7 @@ protected ArenaAttackSkill( } // Apply armor penetration and DEF. - var finalDEF = Math.Clamp(target.DEF - caster.ArmorPenetration, 0, int.MaxValue); + var finalDEF = Math.Clamp(target.DEF - caster.ArmorPenetration, 0, long.MaxValue); damage = Math.Max(damage - finalDEF, 1); // Apply damage reduce damage = (int)((damage - target.DRV) * (1 - target.DRR / 10000m)); diff --git a/Lib9c/Model/Skill/Arena/ArenaBlowAttack.cs b/Lib9c/Model/Skill/Arena/ArenaBlowAttack.cs index dae56c4d3e..d10dccbc99 100644 --- a/Lib9c/Model/Skill/Arena/ArenaBlowAttack.cs +++ b/Lib9c/Model/Skill/Arena/ArenaBlowAttack.cs @@ -10,7 +10,7 @@ public class ArenaBlowAttack : ArenaAttackSkill { public ArenaBlowAttack( SkillSheet.Row skillRow, - int power, + long power, int chance, int statPowerRatio, StatType referencedStatType) : base(skillRow, power, chance, statPowerRatio, referencedStatType) diff --git a/Lib9c/Model/Skill/Arena/ArenaBuffRemovalAttack.cs b/Lib9c/Model/Skill/Arena/ArenaBuffRemovalAttack.cs index b4f3e1d90f..43ff7695d0 100644 --- a/Lib9c/Model/Skill/Arena/ArenaBuffRemovalAttack.cs +++ b/Lib9c/Model/Skill/Arena/ArenaBuffRemovalAttack.cs @@ -10,7 +10,7 @@ public class ArenaBuffRemovalAttack : ArenaAttackSkill { public ArenaBuffRemovalAttack( SkillSheet.Row skillRow, - int power, + long power, int chance, int statPowerRatio, StatType referencedStatType) : base(skillRow, power, chance, statPowerRatio, referencedStatType) diff --git a/Lib9c/Model/Skill/Arena/ArenaBuffSkill.cs b/Lib9c/Model/Skill/Arena/ArenaBuffSkill.cs index 5e53901b7e..d4bae7ddbc 100644 --- a/Lib9c/Model/Skill/Arena/ArenaBuffSkill.cs +++ b/Lib9c/Model/Skill/Arena/ArenaBuffSkill.cs @@ -10,7 +10,7 @@ public class ArenaBuffSkill : ArenaSkill { public ArenaBuffSkill( SkillSheet.Row skillRow, - int power, + long power, int chance, int statPowerRatio, StatType referencedStatType) : base(skillRow, power, chance, statPowerRatio, referencedStatType) diff --git a/Lib9c/Model/Skill/Arena/ArenaDoubleAttack.cs b/Lib9c/Model/Skill/Arena/ArenaDoubleAttack.cs index 73e7b8235c..01f5b5109e 100644 --- a/Lib9c/Model/Skill/Arena/ArenaDoubleAttack.cs +++ b/Lib9c/Model/Skill/Arena/ArenaDoubleAttack.cs @@ -10,7 +10,7 @@ public class ArenaDoubleAttack : ArenaAttackSkill { public ArenaDoubleAttack( SkillSheet.Row skillRow, - int power, + long power, int chance, int statPowerRatio, StatType referencedStatType) : base(skillRow, power, chance, statPowerRatio, referencedStatType) diff --git a/Lib9c/Model/Skill/Arena/ArenaHealSkill.cs b/Lib9c/Model/Skill/Arena/ArenaHealSkill.cs index 508784327b..442d62262e 100644 --- a/Lib9c/Model/Skill/Arena/ArenaHealSkill.cs +++ b/Lib9c/Model/Skill/Arena/ArenaHealSkill.cs @@ -10,7 +10,7 @@ public class ArenaHealSkill : ArenaSkill { public ArenaHealSkill( SkillSheet.Row skillRow, - int power, + long power, int chance, int statPowerRatio, StatType referencedStatType) : base(skillRow, power, chance, statPowerRatio, referencedStatType) diff --git a/Lib9c/Model/Skill/Arena/ArenaNormalAttack.cs b/Lib9c/Model/Skill/Arena/ArenaNormalAttack.cs index 90aa269d5a..44fe6d8e7c 100644 --- a/Lib9c/Model/Skill/Arena/ArenaNormalAttack.cs +++ b/Lib9c/Model/Skill/Arena/ArenaNormalAttack.cs @@ -10,7 +10,7 @@ public class ArenaNormalAttack : ArenaAttackSkill { public ArenaNormalAttack( SkillSheet.Row skillRow, - int power, + long power, int chance, int statPowerRatio, StatType referencedStatType) : base(skillRow, power, chance, statPowerRatio, referencedStatType) diff --git a/Lib9c/Model/Skill/Arena/ArenaSkill.cs b/Lib9c/Model/Skill/Arena/ArenaSkill.cs index 5c63eebc93..eb86282e12 100644 --- a/Lib9c/Model/Skill/Arena/ArenaSkill.cs +++ b/Lib9c/Model/Skill/Arena/ArenaSkill.cs @@ -12,7 +12,7 @@ namespace Nekoyume.Model.Skill.Arena public abstract class ArenaSkill : ISkill { public SkillSheet.Row SkillRow { get; } - public int Power { get; private set; } + public long Power { get; private set; } public int Chance { get; private set; } public int StatPowerRatio { get; private set; } public StatType ReferencedStatType { get; private set; } @@ -23,7 +23,7 @@ public abstract class ArenaSkill : ISkill protected ArenaSkill( SkillSheet.Row skillRow, - int power, + long power, int chance, int statPowerRatio, StatType referencedStatType) @@ -68,7 +68,7 @@ public override int GetHashCode() unchecked { var hashCode = SkillRow.GetHashCode(); - hashCode = (hashCode * 397) ^ Power; + hashCode = (hashCode * 397) ^ Power.GetHashCode(); hashCode = (hashCode * 397) ^ Chance.GetHashCode(); hashCode = (hashCode * 397) ^ StatPowerRatio.GetHashCode(); hashCode = (hashCode * 397) ^ ReferencedStatType.GetHashCode(); @@ -153,7 +153,7 @@ private BattleStatus.Arena.ArenaSkill.ArenaSkillInfo GetSkillInfo(ICloneable tar } - public void Update(int chance, int power, int statPowerRatio) + public void Update(int chance, long power, int statPowerRatio) { Chance = chance; Power = power; diff --git a/Lib9c/Model/Skill/AttackSkill.cs b/Lib9c/Model/Skill/AttackSkill.cs index 6a2370d6ae..18bd604a22 100644 --- a/Lib9c/Model/Skill/AttackSkill.cs +++ b/Lib9c/Model/Skill/AttackSkill.cs @@ -13,7 +13,7 @@ public abstract class AttackSkill : Skill { protected AttackSkill( SkillSheet.Row skillRow, - int power, + long power, int chance, int statPowerRatio, StatType referencedStatType) : base(skillRow, power, chance, statPowerRatio, referencedStatType) @@ -41,7 +41,7 @@ protected AttackSkill( var statAdditionalPower = ReferencedStatType != StatType.NONE ? (int)(caster.Stats.GetStat(ReferencedStatType) * powerMultiplier) : default; - var totalDamage = caster.ATK + Power + statAdditionalPower; + long totalDamage = caster.ATK + Power + statAdditionalPower; var multipliers = GetMultiplier(SkillRow.HitCount, 1m); for (var i = 0; i < SkillRow.HitCount; i++) { @@ -49,7 +49,7 @@ protected AttackSkill( foreach (var target in targets) { - var damage = 0; + long damage = 0; var isCritical = false; // Skill or when normal attack hit. if (!isNormalAttack || @@ -59,9 +59,9 @@ protected AttackSkill( var finalDEF = Math.Clamp(target.DEF - caster.ArmorPenetration, 0, int.MaxValue); damage = totalDamage - finalDEF; // Apply multiple hits - damage = (int) (damage * multiplier); + damage = (long) (damage * multiplier); // Apply damage reduction - damage = (int) ((damage - target.DRV) * (1 - target.DRR / 10000m)); + damage = (long) ((damage - target.DRV) * (1 - target.DRR / 10000m)); if (damage < 1) { diff --git a/Lib9c/Model/Skill/BlowAttack.cs b/Lib9c/Model/Skill/BlowAttack.cs index b54b1ffa87..c83c3e9f88 100644 --- a/Lib9c/Model/Skill/BlowAttack.cs +++ b/Lib9c/Model/Skill/BlowAttack.cs @@ -10,7 +10,7 @@ public class BlowAttack : AttackSkill { public BlowAttack( SkillSheet.Row skillRow, - int power, + long power, int chance, int statPowerRatio, StatType referencedStatType) : base(skillRow, power, chance, statPowerRatio, referencedStatType) diff --git a/Lib9c/Model/Skill/BuffRemovalAttack.cs b/Lib9c/Model/Skill/BuffRemovalAttack.cs index 0302fa0df2..4ceac13c6c 100644 --- a/Lib9c/Model/Skill/BuffRemovalAttack.cs +++ b/Lib9c/Model/Skill/BuffRemovalAttack.cs @@ -10,7 +10,7 @@ public class BuffRemovalAttack : AttackSkill { public BuffRemovalAttack( SkillSheet.Row skillRow, - int power, + long power, int chance, int statPowerRatio, StatType referencedStatType) : base(skillRow, power, chance, statPowerRatio, referencedStatType) diff --git a/Lib9c/Model/Skill/BuffSkill.cs b/Lib9c/Model/Skill/BuffSkill.cs index 78b6eb309a..ed9e6496ff 100644 --- a/Lib9c/Model/Skill/BuffSkill.cs +++ b/Lib9c/Model/Skill/BuffSkill.cs @@ -10,7 +10,7 @@ public class BuffSkill : Skill { public BuffSkill( SkillSheet.Row skillRow, - int power, + long power, int chance, int statPowerRatio, StatType referencedStatType) : base(skillRow, power, chance, statPowerRatio, referencedStatType) diff --git a/Lib9c/Model/Skill/DoubleAttack.cs b/Lib9c/Model/Skill/DoubleAttack.cs index 33a457ee0e..c2661d28e4 100644 --- a/Lib9c/Model/Skill/DoubleAttack.cs +++ b/Lib9c/Model/Skill/DoubleAttack.cs @@ -10,7 +10,7 @@ public class DoubleAttack : AttackSkill { public DoubleAttack( SkillSheet.Row skillRow, - int power, + long power, int chance, int statPowerRatio, StatType referencedStatType) : base(skillRow, power, chance, statPowerRatio, referencedStatType) diff --git a/Lib9c/Model/Skill/HealSkill.cs b/Lib9c/Model/Skill/HealSkill.cs index 33747587b0..568838fce4 100644 --- a/Lib9c/Model/Skill/HealSkill.cs +++ b/Lib9c/Model/Skill/HealSkill.cs @@ -10,7 +10,7 @@ public class HealSkill : Skill { public HealSkill( SkillSheet.Row skillRow, - int power, + long power, int chance, int statPowerRatio, StatType referencedStatType) : base(skillRow, power, chance, statPowerRatio, referencedStatType) diff --git a/Lib9c/Model/Skill/ISkill.cs b/Lib9c/Model/Skill/ISkill.cs index 8dc273bb9b..59972fe7a7 100644 --- a/Lib9c/Model/Skill/ISkill.cs +++ b/Lib9c/Model/Skill/ISkill.cs @@ -10,11 +10,11 @@ public interface ISkill /// Determines damage of `AttackSkill`. /// Determines effect of `BuffSkill`. /// - public int Power { get; } + public long Power { get; } public int Chance { get; } public int StatPowerRatio { get; } public StatType ReferencedStatType { get; } public SkillCustomField? CustomField { get; } - public void Update(int chance, int power, int statPowerRatio); + public void Update(int chance, long power, int statPowerRatio); } } diff --git a/Lib9c/Model/Skill/NormalAttack.cs b/Lib9c/Model/Skill/NormalAttack.cs index b3c5fe7e37..0ee6cb99ff 100644 --- a/Lib9c/Model/Skill/NormalAttack.cs +++ b/Lib9c/Model/Skill/NormalAttack.cs @@ -10,7 +10,7 @@ public class NormalAttack : AttackSkill { public NormalAttack( SkillSheet.Row skillRow, - int power, + long power, int chance, int statPowerRatio, StatType referencedStatType) : base(skillRow, power, chance, statPowerRatio, referencedStatType) diff --git a/Lib9c/Model/Skill/Skill.cs b/Lib9c/Model/Skill/Skill.cs index 51d73c28c8..65a5599383 100644 --- a/Lib9c/Model/Skill/Skill.cs +++ b/Lib9c/Model/Skill/Skill.cs @@ -13,7 +13,7 @@ namespace Nekoyume.Model.Skill public abstract class Skill : IState, ISkill { public SkillSheet.Row SkillRow { get; } - public int Power { get; private set; } + public long Power { get; private set; } public int Chance { get; private set; } public int StatPowerRatio { get; private set; } public StatType ReferencedStatType { get; private set; } @@ -24,7 +24,7 @@ public abstract class Skill : IState, ISkill protected Skill( SkillSheet.Row skillRow, - int power, + long power, int chance, int statPowerRatio, StatType referencedStatType) @@ -60,7 +60,7 @@ public override int GetHashCode() unchecked { var hashCode = SkillRow.GetHashCode(); - hashCode = (hashCode * 397) ^ Power; + hashCode = (hashCode * 397) ^ Power.GetHashCode(); hashCode = (hashCode * 397) ^ Chance.GetHashCode(); hashCode = (hashCode * 397) ^ StatPowerRatio.GetHashCode(); hashCode = (hashCode * 397) ^ ReferencedStatType.GetHashCode(); @@ -88,7 +88,7 @@ public override int GetHashCode() return infos; } - public void Update(int chance, int power, int statPowerRatio) + public void Update(int chance, long power, int statPowerRatio) { Chance = chance; Power = power; diff --git a/Lib9c/Model/Skill/SkillCustomField.cs b/Lib9c/Model/Skill/SkillCustomField.cs index cc299b16a3..aa6abc4a2c 100644 --- a/Lib9c/Model/Skill/SkillCustomField.cs +++ b/Lib9c/Model/Skill/SkillCustomField.cs @@ -4,6 +4,6 @@ namespace Nekoyume.Model.Skill public struct SkillCustomField { public int BuffDuration { get; set; } - public int BuffValue { get; set; } + public long BuffValue { get; set; } } } diff --git a/Lib9c/Model/Skill/SkillFactory.cs b/Lib9c/Model/Skill/SkillFactory.cs index da6119ef2d..5a99433217 100644 --- a/Lib9c/Model/Skill/SkillFactory.cs +++ b/Lib9c/Model/Skill/SkillFactory.cs @@ -11,7 +11,7 @@ public static class SkillFactory { public static Skill Get( SkillSheet.Row skillRow, - int power, + long power, int chance, int statPowerRatio, StatType referencedStatType) @@ -48,7 +48,7 @@ public static Skill Get( [Obsolete("Use Get() instead.")] public static Skill GetV1( SkillSheet.Row skillRow, - int power, + long power, int chance) { switch (skillRow.SkillType) @@ -83,7 +83,7 @@ public static Skill GetV1( // Convert skill to arena skill public static ArenaSkill GetForArena( SkillSheet.Row skillRow, - int power, + long power, int chance, int statPowerRatio, StatType referencedStatType) diff --git a/Lib9c/TableData/Skill/StatBuffSheet.cs b/Lib9c/TableData/Skill/StatBuffSheet.cs index cf82663356..895d7b75d3 100644 --- a/Lib9c/TableData/Skill/StatBuffSheet.cs +++ b/Lib9c/TableData/Skill/StatBuffSheet.cs @@ -36,7 +36,7 @@ public class Row : SheetRow public SkillTargetType TargetType { get; private set; } public StatType StatType { get; private set; } public StatModifier.OperationType OperationType { get; private set; } - public int Value { get; private set; } + public long Value { get; private set; } public bool IsEnhanceable { get; private set; } public override void Set(IReadOnlyList fields) @@ -50,7 +50,7 @@ public override void Set(IReadOnlyList fields) // modifier StatType = (StatType)Enum.Parse(typeof(StatType), fields[5]); OperationType = (StatModifier.OperationType)Enum.Parse(typeof(StatModifier.OperationType), fields[6]); - Value = ParseInt(fields[7]); + Value = ParseLong(fields[7]); if (fields.Count < 9) { From 39b861d82d8a5121e1a97ac71d7406f55f6c9b37 Mon Sep 17 00:00:00 2001 From: Yang Chun Ung Date: Tue, 23 Jan 2024 15:40:02 +0900 Subject: [PATCH 03/11] Change Raid score int to long --- Lib9c/Action/Raid.cs | 4 ++-- Lib9c/Battle/RaidSimulator.cs | 2 +- Lib9c/Battle/RaidSimulatorV1.cs | 2 +- Lib9c/Battle/RaidSimulatorV2.cs | 2 +- Lib9c/Helper/WorldBossHelper.cs | 4 ++-- Lib9c/Model/State/RaiderState.cs | 10 +++++----- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Lib9c/Action/Raid.cs b/Lib9c/Action/Raid.cs index f28daa0ca6..871741ac8c 100644 --- a/Lib9c/Action/Raid.cs +++ b/Lib9c/Action/Raid.cs @@ -167,7 +167,7 @@ public override IAccount Execute(IActionContext context) itemSlotState.UpdateCostumes(CostumeIds); states = states.SetState(itemSlotStateAddress, itemSlotState.Serialize()); - int previousHighScore = raiderState.HighScore; + long previousHighScore = raiderState.HighScore; WorldBossState bossState; WorldBossGlobalHpSheet hpSheet = sheets.GetSheet(); if (states.TryGetState(worldBossAddress, out List rawBossState)) @@ -252,7 +252,7 @@ public override IAccount Execute(IActionContext context) equipmentList, costumeList, runeOptions, avatarState.level, characterRow, costumeStatSheet); - int score = simulator.DamageDealt; + long score = simulator.DamageDealt; raiderState.Update(avatarState, cp, score, PayNcg, context.BlockIndex); // Reward. diff --git a/Lib9c/Battle/RaidSimulator.cs b/Lib9c/Battle/RaidSimulator.cs index 4b0de7659d..5a4ab9df42 100644 --- a/Lib9c/Battle/RaidSimulator.cs +++ b/Lib9c/Battle/RaidSimulator.cs @@ -17,7 +17,7 @@ namespace Nekoyume.Battle public class RaidSimulator : Simulator { public int BossId { get; private set; } - public int DamageDealt { get; private set; } + public long DamageDealt { get; private set; } public List AssetReward { get; private set; } = new List(); public override IEnumerable Reward => new List(); private readonly List _waves; diff --git a/Lib9c/Battle/RaidSimulatorV1.cs b/Lib9c/Battle/RaidSimulatorV1.cs index 56bb47ce1e..be2d238108 100644 --- a/Lib9c/Battle/RaidSimulatorV1.cs +++ b/Lib9c/Battle/RaidSimulatorV1.cs @@ -16,7 +16,7 @@ namespace Nekoyume.Battle public class RaidSimulatorV1 : Simulator { public int BossId { get; private set; } - public int DamageDealt { get; private set; } + public long DamageDealt { get; private set; } public List AssetReward { get; private set; } = new List(); public override IEnumerable Reward => new List(); private readonly List _waves; diff --git a/Lib9c/Battle/RaidSimulatorV2.cs b/Lib9c/Battle/RaidSimulatorV2.cs index b5ab9bea1a..6b9e05f8d3 100644 --- a/Lib9c/Battle/RaidSimulatorV2.cs +++ b/Lib9c/Battle/RaidSimulatorV2.cs @@ -17,7 +17,7 @@ namespace Nekoyume.Battle public class RaidSimulatorV2 : Simulator { public int BossId { get; private set; } - public int DamageDealt { get; private set; } + public long DamageDealt { get; private set; } public List AssetReward { get; private set; } = new List(); public override IEnumerable Reward => new List(); private readonly List _waves; diff --git a/Lib9c/Helper/WorldBossHelper.cs b/Lib9c/Helper/WorldBossHelper.cs index 6a3fe605f5..ec818b2ad9 100644 --- a/Lib9c/Helper/WorldBossHelper.cs +++ b/Lib9c/Helper/WorldBossHelper.cs @@ -11,13 +11,13 @@ public static class WorldBossHelper public const long RefillInterval = 7200L; public const int MaxChallengeCount = 3; - public static int CalculateRank(WorldBossCharacterSheet.Row row, int score) + public static int CalculateRank(WorldBossCharacterSheet.Row row, long score) { var rank = 0; // Wave stats are already sorted by wave number. foreach (var waveData in row.WaveStats) { - score -= (int)waveData.HP; + score -= (long)waveData.HP; if (score < 0) { break; diff --git a/Lib9c/Model/State/RaiderState.cs b/Lib9c/Model/State/RaiderState.cs index bcdb65e34c..50a233da5b 100644 --- a/Lib9c/Model/State/RaiderState.cs +++ b/Lib9c/Model/State/RaiderState.cs @@ -8,8 +8,8 @@ namespace Nekoyume.Model.State [Serializable] public class RaiderState : IState { - public int TotalScore; - public int HighScore; + public long TotalScore; + public long HighScore; public int TotalChallengeCount; public int RemainChallengeCount; public int LatestRewardRank; @@ -35,8 +35,8 @@ public RaiderState() public RaiderState(List rawState) { - TotalScore = rawState[0].ToInteger(); - HighScore = rawState[1].ToInteger(); + TotalScore = rawState[0].ToLong(); + HighScore = rawState[1].ToLong(); TotalChallengeCount = rawState[2].ToInteger(); RemainChallengeCount = rawState[3].ToInteger(); LatestRewardRank = rawState[4].ToInteger(); @@ -52,7 +52,7 @@ public RaiderState(List rawState) UpdatedBlockIndex = rawState[14].ToLong(); } - public void Update(AvatarState avatarState, int cp, int score, bool payNcg, long blockIndex) + public void Update(AvatarState avatarState, int cp, long score, bool payNcg, long blockIndex) { Level = avatarState.level; AvatarAddress = avatarState.address; From 6f2629a909da724731fd69eeb50b475e9229ea2b Mon Sep 17 00:00:00 2001 From: Yang Chun Ung Date: Tue, 23 Jan 2024 16:00:28 +0900 Subject: [PATCH 04/11] Rollback unnecessary changed character id --- Lib9c/Model/Character/ArenaCharacter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib9c/Model/Character/ArenaCharacter.cs b/Lib9c/Model/Character/ArenaCharacter.cs index f2153029be..5b9b640a4b 100644 --- a/Lib9c/Model/Character/ArenaCharacter.cs +++ b/Lib9c/Model/Character/ArenaCharacter.cs @@ -50,7 +50,7 @@ public class ArenaCharacter : ICloneable public SizeType SizeType { get; } public float RunSpeed { get; } public float AttackRange { get; } - public long CharacterId { get; } + public int CharacterId { get; } public bool IsEnemy { get; } private bool _setExtraValueBuffBeforeGetBuffs = false; From 3a45435837fa252b5143ce51f870ee81246b7b16 Mon Sep 17 00:00:00 2001 From: Yang Chun Ung Date: Wed, 24 Jan 2024 20:40:09 +0900 Subject: [PATCH 05/11] Add tradable field --- .../TableData/StakeRegularRewardSheetTest.cs | 29 +++++++++++ Lib9c/TableCSV/Stake/StakePolicySheet.csv | 8 +-- .../StakeRegularFixedRewardSheet_V3.csv | 9 ++++ Lib9c/TableCSV/StakeRegularRewardSheet_V6.csv | 52 +++++++++++++++++++ Lib9c/TableData/StakeRegularRewardSheet.cs | 13 ++++- 5 files changed, 106 insertions(+), 5 deletions(-) create mode 100644 Lib9c/TableCSV/StakeRegularFixedRewardSheet_V3.csv create mode 100644 Lib9c/TableCSV/StakeRegularRewardSheet_V6.csv diff --git a/.Lib9c.Tests/TableData/StakeRegularRewardSheetTest.cs b/.Lib9c.Tests/TableData/StakeRegularRewardSheetTest.cs index 7e4f610a32..c68756a98c 100644 --- a/.Lib9c.Tests/TableData/StakeRegularRewardSheetTest.cs +++ b/.Lib9c.Tests/TableData/StakeRegularRewardSheetTest.cs @@ -1,5 +1,6 @@ namespace Lib9c.Tests.TableData { + using System.Linq; using Lib9c.Tests.Fixtures.TableCSV.Stake; using Libplanet.Action.State; using Libplanet.Types.Assets; @@ -36,6 +37,7 @@ public void SetToSheet() Assert.Equal(string.Empty, reward.CurrencyTicker); Assert.Null(reward.CurrencyDecimalPlaces); Assert.Equal(10m, reward.DecimalRate); + Assert.True(reward.Tradable); reward = row.Rewards[1]; Assert.Equal(500000, reward.ItemId); Assert.Equal(0, reward.Rate); @@ -43,6 +45,7 @@ public void SetToSheet() Assert.Equal(string.Empty, reward.CurrencyTicker); Assert.Null(reward.CurrencyDecimalPlaces); Assert.Equal(800m, reward.DecimalRate); + Assert.True(reward.Tradable); reward = row.Rewards[2]; Assert.Equal(20001, reward.ItemId); Assert.Equal(0, reward.Rate); @@ -50,6 +53,7 @@ public void SetToSheet() Assert.Equal(string.Empty, reward.CurrencyTicker); Assert.Null(reward.CurrencyDecimalPlaces); Assert.Equal(6000m, reward.DecimalRate); + Assert.True(reward.Tradable); row = _sheet[5]; Assert.Equal(500000, row.RequiredGold); @@ -61,6 +65,7 @@ public void SetToSheet() Assert.Equal(string.Empty, reward.CurrencyTicker); Assert.Null(reward.CurrencyDecimalPlaces); Assert.Equal(5m, reward.DecimalRate); + Assert.True(reward.Tradable); reward = row.Rewards[1]; Assert.Equal(500000, reward.ItemId); Assert.Equal(0, reward.Rate); @@ -68,6 +73,7 @@ public void SetToSheet() Assert.Equal(string.Empty, reward.CurrencyTicker); Assert.Null(reward.CurrencyDecimalPlaces); Assert.Equal(800m, reward.DecimalRate); + Assert.True(reward.Tradable); reward = row.Rewards[2]; Assert.Equal(20001, reward.ItemId); Assert.Equal(0, reward.Rate); @@ -75,6 +81,7 @@ public void SetToSheet() Assert.Equal(string.Empty, reward.CurrencyTicker); Assert.Null(reward.CurrencyDecimalPlaces); Assert.Equal(6000m, reward.DecimalRate); + Assert.True(reward.Tradable); } [Theory] @@ -101,5 +108,27 @@ public void FindLevelByStakedAmount_Throws_InsufficientBalanceException(int bala Assert.Throws( () => _sheet.FindLevelByStakedAmount(default, balance * _currency)); } + + [Fact] + public void Set_V6() + { + var csv = TableSheetsImporter.ImportSheets()["StakeRegularRewardSheet_V6"]; + var sheet = new StakeRegularRewardSheet(); + sheet.Set(csv); + var nonTradableIds = new[] + { + 600201, + 800201, + 800202, + }; + + foreach (var row in sheet.Values) + { + foreach (var rewardInfo in row.Rewards) + { + Assert.Equal(!nonTradableIds.Contains(rewardInfo.ItemId), rewardInfo.Tradable); + } + } + } } } diff --git a/Lib9c/TableCSV/Stake/StakePolicySheet.csv b/Lib9c/TableCSV/Stake/StakePolicySheet.csv index cd666c04d5..722635b139 100644 --- a/Lib9c/TableCSV/Stake/StakePolicySheet.csv +++ b/Lib9c/TableCSV/Stake/StakePolicySheet.csv @@ -1,5 +1,5 @@ attr_name,value -StakeRegularFixedRewardSheet,StakeRegularFixedRewardSheet_V2 -StakeRegularRewardSheet,StakeRegularRewardSheet_V5 -RewardInterval,50400 -LockupInterval,201600 \ No newline at end of file +StakeRegularFixedRewardSheet,StakeRegularFixedRewardSheet_V3 +StakeRegularRewardSheet,StakeRegularRewardSheet_V6 +RewardInterval,75600 +LockupInterval,302400 diff --git a/Lib9c/TableCSV/StakeRegularFixedRewardSheet_V3.csv b/Lib9c/TableCSV/StakeRegularFixedRewardSheet_V3.csv new file mode 100644 index 0000000000..06e860864a --- /dev/null +++ b/Lib9c/TableCSV/StakeRegularFixedRewardSheet_V3.csv @@ -0,0 +1,9 @@ +level,required_gold,item_id,count +1,50,500000,1 +2,500,500000,2 +3,5000,500000,2 +4,50000,500000,2 +5,500000,500000,2 +6,1000000,500000,2 +7,5000000,500000,2 +8,10000000,500000,2 diff --git a/Lib9c/TableCSV/StakeRegularRewardSheet_V6.csv b/Lib9c/TableCSV/StakeRegularRewardSheet_V6.csv new file mode 100644 index 0000000000..0a6917c8b2 --- /dev/null +++ b/Lib9c/TableCSV/StakeRegularRewardSheet_V6.csv @@ -0,0 +1,52 @@ +level,required_gold,item_id,rate,type,currency_ticker,currency_decimal_places,decimal_rate,tradable +1,50,400000,,Item,,,10,true +1,50,500000,,Item,,,800,true +1,50,20001,,Rune,,,6000,true +2,500,400000,,Item,,,4,true +2,500,500000,,Item,,,600,true +2,500,20001,,Rune,,,6000,true +2,500,,,Currency,CRYSTAL,18,0.1,true +3,5000,400000,,Item,,,2,true +3,5000,500000,,Item,,,400,true +3,5000,20001,,Rune,,,5000,true +3,5000,,,Currency,CRYSTAL,18,0.02,true +3,5000,600201,,Item,,,500,false +3,5000,800201,,Item,,,500,false +4,50000,400000,,Item,,,2,true +4,50000,500000,,Item,,,400,true +4,50000,20001,,Rune,,,5000,true +4,50000,,,Currency,CRYSTAL,18,0.02,true +4,50000,600201,,Item,,,500,false +4,50000,800201,,Item,,,500,false +4,50000,800202,,Item,,,10000,false +5,500000,400000,,Item,,,1,true +5,500000,500000,,Item,,,200,true +5,500000,20001,,Rune,,,3000,true +5,500000,,,Currency,CRYSTAL,18,0.02,true +5,500000,600201,,Item,,,357,false +5,500000,800201,,Item,,,357,false +5,500000,800202,,Item,,,10000,false +6,1000000,400000,,Item,,,1,true +6,1000000,500000,,Item,,,200,true +6,1000000,20001,,Rune,,,3000,true +6,1000000,,,Currency,CRYSTAL,18,0.02,true +6,1000000,600201,,Item,,,200,false +6,1000000,800201,,Item,,,200,false +6,1000000,800202,,Item,,,10000,false +6,1000000,,,Currency,GARAGE,18,10000,true +7,5000000,400000,,Item,,,1,true +7,5000000,500000,,Item,,,200,true +7,5000000,20001,,Rune,,,3000,true +7,5000000,800201,,Item,,,100,false +7,5000000,,,Currency,CRYSTAL,18,0.02,true +7,5000000,600201,,Item,,,100,false +7,5000000,800202,,Item,,,100,false +7,5000000,,,Currency,GARAGE,18,500,true +8,10000000,400000,,Item,,,0.4,true +8,10000000,500000,,Item,,,80,true +8,10000000,20001,,Rune,,,1200,true +8,10000000,600201,,Item,,,50,false +8,10000000,800201,,Item,,,50,false +8,10000000,,,Currency,GARAGE,18,100,true +8,10000000,,,Currency,CRYSTAL,18,0.01,true +8,10000000,800202,,Item,,,50,false diff --git a/Lib9c/TableData/StakeRegularRewardSheet.cs b/Lib9c/TableData/StakeRegularRewardSheet.cs index 6647969572..8f4189f602 100644 --- a/Lib9c/TableData/StakeRegularRewardSheet.cs +++ b/Lib9c/TableData/StakeRegularRewardSheet.cs @@ -51,10 +51,12 @@ public class RewardInfo /// public readonly decimal DecimalRate; + public readonly bool Tradable; public RewardInfo(params string[] fields) { ItemId = ParseInt(fields[0], 0); Rate = ParseInt(fields[1], 0); + Tradable = true; if (fields.Length == 2) { Type = StakeRewardType.Item; @@ -92,7 +94,16 @@ public RewardInfo(params string[] fields) return; } - DecimalRate = ParseDecimal(fields[5], 0m); + if (fields.Length == 6) + { + DecimalRate = ParseDecimal(fields[5], 0m); + return; + } + + if (fields.Length == 7) + { + Tradable = ParseBool(fields[6], true); + } } public RewardInfo( From 11bcdaca794a4cd4a6409d6988195367a1c0e369 Mon Sep 17 00:00:00 2001 From: Yang Chun Ung Date: Thu, 25 Jan 2024 14:35:39 +0900 Subject: [PATCH 06/11] Fix decimal rate set --- Lib9c/TableData/StakeRegularRewardSheet.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib9c/TableData/StakeRegularRewardSheet.cs b/Lib9c/TableData/StakeRegularRewardSheet.cs index 8f4189f602..138eab205f 100644 --- a/Lib9c/TableData/StakeRegularRewardSheet.cs +++ b/Lib9c/TableData/StakeRegularRewardSheet.cs @@ -94,9 +94,10 @@ public RewardInfo(params string[] fields) return; } + DecimalRate = ParseDecimal(fields[5], 0m); + if (fields.Length == 6) { - DecimalRate = ParseDecimal(fields[5], 0m); return; } From c38272b7a634c0b3de1668c95ced48316f59d6b4 Mon Sep 17 00:00:00 2001 From: Yang Chun Ung Date: Thu, 25 Jan 2024 14:35:52 +0900 Subject: [PATCH 07/11] Allow material in claimStakeReward --- .Lib9c.Tests/Action/ClaimStakeRewardTest.cs | 56 +++++++++++++++++++ .../Stake/StakePolicySheetFixtures.cs | 6 ++ .../StakeRegularFixedRewardSheetFixtures.cs | 10 ++++ .../Stake/StakeRegularRewardSheetFixtures.cs | 54 ++++++++++++++++++ Lib9c/Action/ClaimStakeReward.cs | 14 ++++- 5 files changed, 137 insertions(+), 3 deletions(-) diff --git a/.Lib9c.Tests/Action/ClaimStakeRewardTest.cs b/.Lib9c.Tests/Action/ClaimStakeRewardTest.cs index 8c6eb1ada7..4ca9746b52 100644 --- a/.Lib9c.Tests/Action/ClaimStakeRewardTest.cs +++ b/.Lib9c.Tests/Action/ClaimStakeRewardTest.cs @@ -11,6 +11,7 @@ namespace Lib9c.Tests.Action using Libplanet.Types.Assets; using Nekoyume; using Nekoyume.Action; + using Nekoyume.Model.Item; using Nekoyume.Model.Stake; using Nekoyume.Model.State; using Nekoyume.TableData.Stake; @@ -661,6 +662,61 @@ public void Execute_Success_With_StakeStateV2( } } + [Fact] + public void Execute_V6() + { + var prevState = _initialStates[1]; + var stakeAddr = StakeStateV2.DeriveAddress(AgentAddr); + var stakePolicySheet = new StakePolicySheet(); + stakePolicySheet.Set(StakePolicySheetFixtures.V6); + var stakeStateV2 = PrepareStakeStateV2( + stakePolicySheet, + 0L, + 0L); + prevState = prevState + .SetState( + Addresses.GetSheetAddress(), + StakePolicySheetFixtures.V6.Serialize()) + .SetState( + Addresses.GetSheetAddress("StakeRegularRewardSheet_V6"), + StakeRegularRewardSheetFixtures.V6.Serialize()) + .SetState( + Addresses.GetSheetAddress("StakeRegularRewardFixedRewardSheet_V3"), + StakeRegularFixedRewardSheetFixtures.V3.Serialize()) + .SetState(stakeAddr, stakeStateV2.Serialize()) + .MintAsset( + new ActionContext(), + stakeAddr, + _ncg * 10000000); + var agentAddr = AgentAddr; + var avatarAddr = AvatarAddr; + var blockIndex = stakePolicySheet.RewardIntervalValue; + var nextState = Execute(prevState, agentAddr, avatarAddr, blockIndex); + var avatarState = nextState.GetAvatarStateV2(AvatarAddr); + var expected = new[] + { + (400000, 25000000, true), + (500000, 125002, true), + (600201, 200000, false), + (800201, 200000, false), + (800202, 200000, false), + }; + foreach (var (itemId, count, tradable) in expected) + { + Assert.True(avatarState.inventory.TryGetItem(itemId, out var inventoryItem)); + Assert.Equal(count, inventoryItem.count); + if (tradable) + { + Assert.IsType(inventoryItem.item); + } + else + { + Assert.IsNotType(inventoryItem.item); + Assert.IsType(inventoryItem.item); + } + } + } + private static StakeStateV2 PrepareStakeStateV2( StakePolicySheet stakePolicySheet, long startedBlockIndex, diff --git a/.Lib9c.Tests/Fixtures/TableCSV/Stake/StakePolicySheetFixtures.cs b/.Lib9c.Tests/Fixtures/TableCSV/Stake/StakePolicySheetFixtures.cs index 7eb0dd83da..f12447fbd1 100644 --- a/.Lib9c.Tests/Fixtures/TableCSV/Stake/StakePolicySheetFixtures.cs +++ b/.Lib9c.Tests/Fixtures/TableCSV/Stake/StakePolicySheetFixtures.cs @@ -19,5 +19,11 @@ public static class StakePolicySheetFixtures StakeRegularRewardSheet,StakeRegularRewardSheet_V1 RewardInterval,40 LockupInterval,150"; + + public const string V6 = @"attr_name,value +StakeRegularFixedRewardSheet,StakeRegularFixedRewardSheet_V3 +StakeRegularRewardSheet,StakeRegularRewardSheet_V6 +RewardInterval,75600 +LockupInterval,302400"; } } diff --git a/.Lib9c.Tests/Fixtures/TableCSV/Stake/StakeRegularFixedRewardSheetFixtures.cs b/.Lib9c.Tests/Fixtures/TableCSV/Stake/StakeRegularFixedRewardSheetFixtures.cs index 5f21e66c9a..c23e8dcf48 100644 --- a/.Lib9c.Tests/Fixtures/TableCSV/Stake/StakeRegularFixedRewardSheetFixtures.cs +++ b/.Lib9c.Tests/Fixtures/TableCSV/Stake/StakeRegularFixedRewardSheetFixtures.cs @@ -18,5 +18,15 @@ public static class StakeRegularFixedRewardSheetFixtures 5,500000,500000,2 6,5000000,500000,2 7,10000000,500000,2"; + + public const string V3 = @"level,required_gold,item_id,count +1,50,500000,1 +2,500,500000,2 +3,5000,500000,2 +4,50000,500000,2 +5,500000,500000,2 +6,1000000,500000,2 +7,5000000,500000,2 +8,10000000,500000,2"; } } diff --git a/.Lib9c.Tests/Fixtures/TableCSV/Stake/StakeRegularRewardSheetFixtures.cs b/.Lib9c.Tests/Fixtures/TableCSV/Stake/StakeRegularRewardSheetFixtures.cs index 1ad2b95c6e..e52c707719 100644 --- a/.Lib9c.Tests/Fixtures/TableCSV/Stake/StakeRegularRewardSheetFixtures.cs +++ b/.Lib9c.Tests/Fixtures/TableCSV/Stake/StakeRegularRewardSheetFixtures.cs @@ -47,11 +47,65 @@ public static class StakeRegularRewardSheetFixtures 7,10000000,600201,50,Item, 7,10000000,800201,50,Item, 7,10000000,,100,Currency,GARAGE"; + // NOTE: belows are same. // since "claim_stake_reward8". // 7,10000000,20001,6000,Rune, // 7,10000000,,6000,Rune, // since "claim_stake_reward9". // 7,10000000,,6000,Currency,RUNE_GOLDENLEAF + public const string V6 = + @"level,required_gold,item_id,rate,type,currency_ticker,currency_decimal_places,decimal_rate,tradable +1,50,400000,,Item,,,10,true +1,50,500000,,Item,,,800,true +1,50,20001,,Rune,,,6000,true +2,500,400000,,Item,,,4,true +2,500,500000,,Item,,,600,true +2,500,20001,,Rune,,,6000,true +2,500,,,Currency,CRYSTAL,18,0.1,true +3,5000,400000,,Item,,,2,true +3,5000,500000,,Item,,,400,true +3,5000,20001,,Rune,,,5000,true +3,5000,,,Currency,CRYSTAL,18,0.02,true +3,5000,600201,,Item,,,500,false +3,5000,800201,,Item,,,500,false +4,50000,400000,,Item,,,2,true +4,50000,500000,,Item,,,400,true +4,50000,20001,,Rune,,,5000,true +4,50000,,,Currency,CRYSTAL,18,0.02,true +4,50000,600201,,Item,,,500,false +4,50000,800201,,Item,,,500,false +4,50000,800202,,Item,,,10000,false +5,500000,400000,,Item,,,1,true +5,500000,500000,,Item,,,200,true +5,500000,20001,,Rune,,,3000,true +5,500000,,,Currency,CRYSTAL,18,0.02,true +5,500000,600201,,Item,,,357,false +5,500000,800201,,Item,,,357,false +5,500000,800202,,Item,,,10000,false +6,1000000,400000,,Item,,,1,true +6,1000000,500000,,Item,,,200,true +6,1000000,20001,,Rune,,,3000,true +6,1000000,,,Currency,CRYSTAL,18,0.02,true +6,1000000,600201,,Item,,,200,false +6,1000000,800201,,Item,,,200,false +6,1000000,800202,,Item,,,10000,false +6,1000000,,,Currency,GARAGE,18,10000,true +7,5000000,400000,,Item,,,1,true +7,5000000,500000,,Item,,,200,true +7,5000000,20001,,Rune,,,3000,true +7,5000000,800201,,Item,,,100,false +7,5000000,,,Currency,CRYSTAL,18,0.02,true +7,5000000,600201,,Item,,,100,false +7,5000000,800202,,Item,,,100,false +7,5000000,,,Currency,GARAGE,18,500,true +8,10000000,400000,,Item,,,0.4,true +8,10000000,500000,,Item,,,80,true +8,10000000,20001,,Rune,,,1200,true +8,10000000,600201,,Item,,,50,false +8,10000000,800201,,Item,,,50,false +8,10000000,,,Currency,GARAGE,18,100,true +8,10000000,,,Currency,CRYSTAL,18,0.01,true +8,10000000,800202,,Item,,,50,false"; } } diff --git a/Lib9c/Action/ClaimStakeReward.cs b/Lib9c/Action/ClaimStakeReward.cs index 84b8d3bb50..d1296ed8b3 100644 --- a/Lib9c/Action/ClaimStakeReward.cs +++ b/Lib9c/Action/ClaimStakeReward.cs @@ -154,9 +154,17 @@ public override IAccount Execute(IActionContext context) } var itemRow = itemSheet[reward.ItemId]; - var item = itemRow is MaterialItemSheet.Row materialRow - ? ItemFactory.CreateTradableMaterial(materialRow) - : ItemFactory.CreateItem(itemRow, random); + ItemBase item; + if (itemRow is MaterialItemSheet.Row materialRow) + { + item = reward.Tradable + ? ItemFactory.CreateTradableMaterial(materialRow) + : ItemFactory.CreateMaterial(materialRow); + } + else + { + item = ItemFactory.CreateItem(itemRow, random); + } avatarState.inventory.AddItem(item, majorUnit); break; } From 532628b97b96854af2bef790cd0da5decb7b4955 Mon Sep 17 00:00:00 2001 From: Yang Chun Ung Date: Thu, 25 Jan 2024 18:47:48 +0900 Subject: [PATCH 08/11] Allow material in garages --- .../Garages/DeliverToOthersGaragesTest.cs | 63 +++++++++++-------- .../Action/Garages/LoadIntoMyGaragesTest.cs | 51 ++++++++++----- Lib9c/Action/Garages/LoadIntoMyGarages.cs | 27 +++----- .../Garages/LoadIntoMyGaragesCostSheet.csv | 7 ++- 4 files changed, 87 insertions(+), 61 deletions(-) diff --git a/.Lib9c.Tests/Action/Garages/DeliverToOthersGaragesTest.cs b/.Lib9c.Tests/Action/Garages/DeliverToOthersGaragesTest.cs index 3696f09003..87af50ee82 100644 --- a/.Lib9c.Tests/Action/Garages/DeliverToOthersGaragesTest.cs +++ b/.Lib9c.Tests/Action/Garages/DeliverToOthersGaragesTest.cs @@ -32,7 +32,7 @@ public class DeliverToOthersGaragesTest private readonly Address _recipientAgentAddr; private readonly FungibleAssetValue[] _fungibleAssetValues; private readonly (HashDigest fungibleId, int count)[] _fungibleIdAndCounts; - private readonly ITradableFungibleItem[] _tradableFungibleItems; + private readonly IFungibleItem[] _fungibleItems; private readonly IAccount _previousStates; public DeliverToOthersGaragesTest() @@ -52,7 +52,7 @@ public DeliverToOthersGaragesTest() _recipientAgentAddr, _fungibleAssetValues, _fungibleIdAndCounts, - _tradableFungibleItems, + _fungibleItems, _previousStates ) = GetSuccessfulPreviousStatesWithPlainValue(); } @@ -261,7 +261,7 @@ public void Execute_Throws_Exception() var (fungibleId, _) = _fungibleIdAndCounts[i]; var addr = Addresses.GetGarageAddress(_recipientAgentAddr, fungibleId); var nextIndex = (i + 1) % _fungibleIdAndCounts.Length; - var garage = new FungibleItemGarage(_tradableFungibleItems[nextIndex], 1); + var garage = new FungibleItemGarage(_fungibleItems[nextIndex], 1); var previousStatesWithInvalidGarageState = _previousStates.SetState(addr, garage.Serialize()); Assert.Throws(() => Execute( @@ -301,7 +301,7 @@ public void Execute_Throws_Exception() { var (fungibleId, _) = _fungibleIdAndCounts[i]; var addr = Addresses.GetGarageAddress(_recipientAgentAddr, fungibleId); - var garage = new FungibleItemGarage(_tradableFungibleItems[i], int.MaxValue); + var garage = new FungibleItemGarage(_fungibleItems[i], int.MaxValue); var previousStatesWithInvalidGarageState = _previousStates.SetState(addr, garage.Serialize()); Assert.Throws(() => Execute( @@ -353,7 +353,7 @@ private static FungibleAssetValue[] GetFungibleAssetValues() Address recipientAddr, FungibleAssetValue[] fungibleAssetValues, (HashDigest fungibleId, int count)[] fungibleIdAndCounts, - ITradableFungibleItem[] _tradableFungibleItems, + IFungibleItem[] _fungibleItems, IAccount previousStates) GetSuccessfulPreviousStatesWithPlainValue() { @@ -380,33 +380,44 @@ private static FungibleAssetValue[] GetFungibleAssetValues() fav); } - var fungibleIdAndCounts = _tableSheets.MaterialItemSheet.OrderedList! - .Take(3) - .Select(ItemFactory.CreateTradableMaterial) - .Select((tradableMaterial, index) => - { - var senderGarageAddr = Addresses.GetGarageAddress( - SenderAgentAddr, - tradableMaterial.FungibleId); - var garageState = previousStates.GetState(senderGarageAddr); - var garage = garageState is null - ? new FungibleItemGarage(tradableMaterial, 0) - : new FungibleItemGarage(garageState); - garage.Load(index + 1); - previousStates = previousStates - .SetState(senderGarageAddr, garage.Serialize()); + var fungibleIdAndCounts = new List<(IFungibleItem fungibleItem, int count)>(); + var tradableIds = new[] { 400000, 500000 }; + var nonTradableIds = new[] { 600201, 800201, 800202 }; + for (int i = 0; i < tradableIds.Count(); i++) + { + var id = tradableIds[i]; + var row = _tableSheets.MaterialItemSheet[id]; + fungibleIdAndCounts.Add((ItemFactory.CreateMaterial(row), i + 1)); + } + + for (int i = 0; i < nonTradableIds.Count(); i++) + { + var id = nonTradableIds[i]; + var row = _tableSheets.MaterialItemSheet[id]; + fungibleIdAndCounts.Add((ItemFactory.CreateTradableMaterial(row), i + 1)); + } + + foreach (var (fungibleItem, count) in fungibleIdAndCounts) + { + var senderGarageAddr = Addresses.GetGarageAddress( + SenderAgentAddr, + fungibleItem.FungibleId); + var garageState = previousStates.GetState(senderGarageAddr); + var garage = garageState is null + ? new FungibleItemGarage(fungibleItem, 0) + : new FungibleItemGarage(garageState); + garage.Load(count); + previousStates = previousStates + .SetState(senderGarageAddr, garage.Serialize()); + } - return ( - tradableFungibleItem: (ITradableFungibleItem)tradableMaterial, - count: index + 1); - }).ToArray(); return ( new PrivateKey().Address, fungibleAssetValues, fungibleIdAndCounts - .Select(tuple => (tuple.tradableFungibleItem.FungibleId, tuple.count)) + .Select(tuple => (tuple.fungibleItem.FungibleId, tuple.count)) .ToArray(), - fungibleIdAndCounts.Select(tuple => tuple.tradableFungibleItem).ToArray(), + fungibleIdAndCounts.Select(tuple => tuple.fungibleItem).ToArray(), previousStates); } } diff --git a/.Lib9c.Tests/Action/Garages/LoadIntoMyGaragesTest.cs b/.Lib9c.Tests/Action/Garages/LoadIntoMyGaragesTest.cs index 3460fdce90..5ee56aa359 100644 --- a/.Lib9c.Tests/Action/Garages/LoadIntoMyGaragesTest.cs +++ b/.Lib9c.Tests/Action/Garages/LoadIntoMyGaragesTest.cs @@ -34,7 +34,7 @@ public class LoadIntoMyGaragesTest private readonly Address? _inventoryAddr; private readonly (HashDigest fungibleId, int count)[] _fungibleIdAndCounts; private readonly FungibleAssetValue _cost; - private readonly ITradableFungibleItem[] _tradableFungibleItems; + private readonly IFungibleItem[] _fungibleItems; private readonly IAccount _previousStates; public LoadIntoMyGaragesTest() @@ -55,7 +55,7 @@ public LoadIntoMyGaragesTest() _inventoryAddr, _fungibleIdAndCounts, _cost, - _tradableFungibleItems, + _fungibleItems, _previousStates ) = GetSuccessfulPreviousStatesWithPlainValue(); } @@ -364,7 +364,7 @@ public void Execute_Throws_Exception() var (fungibleId, _) = _fungibleIdAndCounts[i]; var addr = Addresses.GetGarageAddress(AgentAddr, fungibleId); var nextIndex = (i + 1) % _fungibleIdAndCounts.Length; - var garage = new FungibleItemGarage(_tradableFungibleItems[nextIndex], 1); + var garage = new FungibleItemGarage(_fungibleItems[nextIndex], 1); var previousStatesWithInvalidGarageState = _previousStates.SetState(addr, garage.Serialize()); Assert.Throws(() => Execute( @@ -382,7 +382,7 @@ public void Execute_Throws_Exception() { var (fungibleId, _) = _fungibleIdAndCounts[i]; var addr = Addresses.GetGarageAddress(AgentAddr, fungibleId); - var garage = new FungibleItemGarage(_tradableFungibleItems[i], int.MaxValue); + var garage = new FungibleItemGarage(_fungibleItems[i], int.MaxValue); var previousStatesWithInvalidGarageState = _previousStates.SetState(addr, garage.Serialize()); Assert.Throws(() => Execute( @@ -453,7 +453,7 @@ private static (Address balanceAddr, FungibleAssetValue value)[] Address? inventoryAddr, (HashDigest fungibleId, int count)[] fungibleIdAndCounts, FungibleAssetValue cost, - ITradableFungibleItem[] _tradableFungibleItems, + IFungibleItem[] _fungibleItems, IAccount previousStates) GetSuccessfulPreviousStatesWithPlainValue() { @@ -484,20 +484,37 @@ private static (Address balanceAddr, FungibleAssetValue value)[] var inventoryAddr = Addresses.GetInventoryAddress(AgentAddr, AvatarIndex); var inventoryState = (List)previousStates.GetState(inventoryAddr)!; var inventory = new Inventory(inventoryState); - var fungibleItemAndCounts = _tableSheets.MaterialItemSheet.OrderedList! - .Where(row => _tableSheets.LoadIntoMyGaragesCostSheet.HasCost(row.ItemId)) - .Select(ItemFactory.CreateTradableMaterial) - .Select((tradableMaterial, index) => + var nonTradableIds = new[] + { + 600201, + 800201, + 800202, + }; + var fungibleItemAndCounts = new List<(IFungibleItem fungibleItem, int count)>(); + var rows = _tableSheets.MaterialItemSheet.OrderedList!.Where(row => + _tableSheets.LoadIntoMyGaragesCostSheet.HasCost(row.ItemId)).ToList(); + for (int i = 0; i < rows.Count; i++) + { + var row = rows[i]; + IFungibleItem item; + if (nonTradableIds.Contains(row.Id)) + { + item = ItemFactory.CreateMaterial(row); + } + else { - inventory.AddFungibleItem(tradableMaterial, index + 1); - return ( - tradableFungibleItem: (ITradableFungibleItem)tradableMaterial, - count: index + 1); - }).ToArray(); + item = ItemFactory.CreateTradableMaterial(row); + } + + var count = i + 1; + inventory.AddFungibleItem((ItemBase)item, count); + fungibleItemAndCounts.Add((item, count)); + } + var garageCost = _tableSheets.LoadIntoMyGaragesCostSheet.GetGarageCost( fungibleAssetValues.Select(tuple => tuple.value), fungibleItemAndCounts - .Select(tuple => (tuple.tradableFungibleItem.FungibleId, tuple.count))); + .Select(tuple => (tuple.fungibleItem.FungibleId, tuple.count))); previousStates = previousStates.MintAsset( new ActionContext { Signer = AgentAddr }, AgentAddr, @@ -506,10 +523,10 @@ private static (Address balanceAddr, FungibleAssetValue value)[] fungibleAssetValues, inventoryAddr, fungibleItemAndCounts - .Select(tuple => (tuple.tradableFungibleItem.FungibleId, tuple.count)) + .Select(tuple => (tuple.fungibleItem.FungibleId, tuple.count)) .ToArray(), garageCost, - fungibleItemAndCounts.Select(tuple => tuple.tradableFungibleItem).ToArray(), + fungibleItemAndCounts.Select(tuple => tuple.fungibleItem).ToArray(), previousStates.SetState(inventoryAddr, inventory.Serialize()) ); } diff --git a/Lib9c/Action/Garages/LoadIntoMyGarages.cs b/Lib9c/Action/Garages/LoadIntoMyGarages.cs index 71d68511c7..f088d5d558 100644 --- a/Lib9c/Action/Garages/LoadIntoMyGarages.cs +++ b/Lib9c/Action/Garages/LoadIntoMyGarages.cs @@ -247,20 +247,13 @@ private IAccount TransferFungibleItems( FungibleIdAndCounts); foreach (var (fungibleId, count, garageAddr, garageState) in fungibleItemTuples) { - if (!inventory.TryGetTradableFungibleItems( - fungibleId, - requiredBlockIndex: null, - blockIndex: blockIndex, - out var outItems)) + if (!inventory.TryGetFungibleItems(fungibleId, out var outItems)) { throw new ItemNotFoundException(InventoryAddr.Value, fungibleId); } - var itemArr = outItems as Inventory.Item[] ?? outItems.ToArray(); - var tradableFungibleItem = (ITradableFungibleItem)itemArr[0].item; - if (!inventory.RemoveTradableFungibleItem( + if (!inventory.RemoveFungibleItem( fungibleId, - requiredBlockIndex: null, blockIndex: blockIndex, count)) { @@ -268,19 +261,19 @@ private IAccount TransferFungibleItems( InventoryAddr.Value, fungibleId, count, - itemArr.Sum(item => item.count)); + outItems.Sum(i => i.count)); } - IFungibleItem fungibleItem = tradableFungibleItem switch + var item = outItems[0].item; + if (item is not Material material) { - TradableMaterial tradableMaterial => new Material(tradableMaterial), - _ => throw new InvalidCastException( - $"Invalid type of {nameof(tradableFungibleItem)}: " + - $"{tradableFungibleItem.GetType()}") - }; + throw new InvalidCastException( + $"Invalid type of {nameof(item)}: " + + $"{item.GetType()}"); + } var garage = garageState is null || garageState is Null - ? new FungibleItemGarage(fungibleItem, 0) + ? new FungibleItemGarage(material, 0) : new FungibleItemGarage(garageState); // NOTE: // Why not compare the garage.Item with tradableFungibleItem? diff --git a/Lib9c/TableCSV/Garages/LoadIntoMyGaragesCostSheet.csv b/Lib9c/TableCSV/Garages/LoadIntoMyGaragesCostSheet.csv index dbc28667ea..1ae9ee0417 100644 --- a/Lib9c/TableCSV/Garages/LoadIntoMyGaragesCostSheet.csv +++ b/Lib9c/TableCSV/Garages/LoadIntoMyGaragesCostSheet.csv @@ -4,4 +4,9 @@ id,_memo,currency_ticker,fungible_id,garage_cost_per_unit 3,silver dust(800201),,1a755098a2bc0659a063107df62e2ff9b3cdaba34d96b79519f504b996f53820,0.01 4,golden dust(600201),,f8faf92c9c0d0e8e06694361ea87bfc8b29a8ae8de93044b98470a57636ed0e0,0.01 5,golden leaf runestone,RUNE_GOLDENLEAF,,0.1 -6,crystal,CRYSTAL,,0.0000001 \ No newline at end of file +6,crystal,CRYSTAL,,0.0000001 +7,golden meat(800202),,48e50ecd6d1aa2689fd349c1f0611e6cc1e9c4c74ec4de9d4637ec7b78617308,0.01 +8,soul stone(1001),SOULSTONE_1001,,0.01 +9,soul stone(1002),SOULSTONE_1002,,0.01 +10,soul stone(1003),SOULSTONE_1003,,0.01 +11,soul stone(1004),SOULSTONE_1004,,0.01 From bc52cfdc0a9a43eced24018e0724641ad3ae5343 Mon Sep 17 00:00:00 2001 From: Yang Chun Ung Date: Fri, 26 Jan 2024 13:28:59 +0900 Subject: [PATCH 09/11] Fix tradableMaterial to non-tradable --- .../Garages/DeliverToOthersGaragesTest.cs | 10 +++++----- .../Action/Garages/LoadIntoMyGaragesTest.cs | 18 +++++++++--------- Lib9c/Action/Garages/LoadIntoMyGarages.cs | 4 ++++ 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/.Lib9c.Tests/Action/Garages/DeliverToOthersGaragesTest.cs b/.Lib9c.Tests/Action/Garages/DeliverToOthersGaragesTest.cs index 87af50ee82..4e20fba26e 100644 --- a/.Lib9c.Tests/Action/Garages/DeliverToOthersGaragesTest.cs +++ b/.Lib9c.Tests/Action/Garages/DeliverToOthersGaragesTest.cs @@ -168,9 +168,9 @@ public void Execute_Success() var recipientGarageAddr = Addresses.GetGarageAddress( _recipientAgentAddr, fungibleId); - Assert.Equal( - count, - new FungibleItemGarage(nextStates.GetState(recipientGarageAddr)).Count); + var garage = new FungibleItemGarage(nextStates.GetState(recipientGarageAddr)); + Assert.Equal(count, garage.Count); + Assert.IsType(garage.Item); } } @@ -387,14 +387,14 @@ private static FungibleAssetValue[] GetFungibleAssetValues() { var id = tradableIds[i]; var row = _tableSheets.MaterialItemSheet[id]; - fungibleIdAndCounts.Add((ItemFactory.CreateMaterial(row), i + 1)); + fungibleIdAndCounts.Add((ItemFactory.CreateTradableMaterial(row), i + 1)); } for (int i = 0; i < nonTradableIds.Count(); i++) { var id = nonTradableIds[i]; var row = _tableSheets.MaterialItemSheet[id]; - fungibleIdAndCounts.Add((ItemFactory.CreateTradableMaterial(row), i + 1)); + fungibleIdAndCounts.Add((ItemFactory.CreateMaterial(row), i + 1)); } foreach (var (fungibleItem, count) in fungibleIdAndCounts) diff --git a/.Lib9c.Tests/Action/Garages/LoadIntoMyGaragesTest.cs b/.Lib9c.Tests/Action/Garages/LoadIntoMyGaragesTest.cs index 5ee56aa359..94875b3837 100644 --- a/.Lib9c.Tests/Action/Garages/LoadIntoMyGaragesTest.cs +++ b/.Lib9c.Tests/Action/Garages/LoadIntoMyGaragesTest.cs @@ -36,6 +36,12 @@ public class LoadIntoMyGaragesTest private readonly FungibleAssetValue _cost; private readonly IFungibleItem[] _fungibleItems; private readonly IAccount _previousStates; + private readonly int[] _nonTradableIds = new[] + { + 600201, + 800201, + 800202, + }; public LoadIntoMyGaragesTest() { @@ -170,9 +176,8 @@ public void Execute_Success() var inventory = new Inventory((List)inventoryState); foreach (var (fungibleId, count) in action.FungibleIdAndCounts) { - Assert.False(inventory.HasTradableFungibleItem( + Assert.False(inventory.HasFungibleItem( fungibleId, - requiredBlockIndex: null, blockIndex: 0, 1)); var garageAddr = Addresses.GetGarageAddress( @@ -181,6 +186,7 @@ public void Execute_Success() var garage = new FungibleItemGarage(nextStates.GetState(garageAddr)); Assert.Equal(fungibleId, garage.Item.FungibleId); Assert.Equal(count, garage.Count); + Assert.IsType(garage.Item); } } @@ -484,12 +490,6 @@ private static (Address balanceAddr, FungibleAssetValue value)[] var inventoryAddr = Addresses.GetInventoryAddress(AgentAddr, AvatarIndex); var inventoryState = (List)previousStates.GetState(inventoryAddr)!; var inventory = new Inventory(inventoryState); - var nonTradableIds = new[] - { - 600201, - 800201, - 800202, - }; var fungibleItemAndCounts = new List<(IFungibleItem fungibleItem, int count)>(); var rows = _tableSheets.MaterialItemSheet.OrderedList!.Where(row => _tableSheets.LoadIntoMyGaragesCostSheet.HasCost(row.ItemId)).ToList(); @@ -497,7 +497,7 @@ private static (Address balanceAddr, FungibleAssetValue value)[] { var row = rows[i]; IFungibleItem item; - if (nonTradableIds.Contains(row.Id)) + if (_nonTradableIds.Contains(row.Id)) { item = ItemFactory.CreateMaterial(row); } diff --git a/Lib9c/Action/Garages/LoadIntoMyGarages.cs b/Lib9c/Action/Garages/LoadIntoMyGarages.cs index f088d5d558..ce725aea16 100644 --- a/Lib9c/Action/Garages/LoadIntoMyGarages.cs +++ b/Lib9c/Action/Garages/LoadIntoMyGarages.cs @@ -271,6 +271,10 @@ private IAccount TransferFungibleItems( $"Invalid type of {nameof(item)}: " + $"{item.GetType()}"); } + if (material is TradableMaterial tradableMaterial) + { + material = new Material(tradableMaterial); + } var garage = garageState is null || garageState is Null ? new FungibleItemGarage(material, 0) From 86f1b86d7c3515ec772523642098d19a036a5bb9 Mon Sep 17 00:00:00 2001 From: Yang Chun Ung Date: Fri, 26 Jan 2024 14:14:25 +0900 Subject: [PATCH 10/11] Fix broken test --- .Lib9c.Tests/Action/Garages/DeliverToOthersGaragesTest.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.Lib9c.Tests/Action/Garages/DeliverToOthersGaragesTest.cs b/.Lib9c.Tests/Action/Garages/DeliverToOthersGaragesTest.cs index 4e20fba26e..15438a1d6b 100644 --- a/.Lib9c.Tests/Action/Garages/DeliverToOthersGaragesTest.cs +++ b/.Lib9c.Tests/Action/Garages/DeliverToOthersGaragesTest.cs @@ -403,8 +403,11 @@ private static FungibleAssetValue[] GetFungibleAssetValues() SenderAgentAddr, fungibleItem.FungibleId); var garageState = previousStates.GetState(senderGarageAddr); + Material material = fungibleItem is TradableMaterial tradableMaterial + ? new Material(tradableMaterial) + : (Material)fungibleItem; var garage = garageState is null - ? new FungibleItemGarage(fungibleItem, 0) + ? new FungibleItemGarage(material, 0) : new FungibleItemGarage(garageState); garage.Load(count); previousStates = previousStates From 2b089a08babd82dc633edc36276b8d103174858c Mon Sep 17 00:00:00 2001 From: Yang Chun Ung Date: Mon, 29 Jan 2024 10:19:02 +0900 Subject: [PATCH 11/11] Add meta file --- Lib9c/TableCSV/StakeRegularFixedRewardSheet_V1.csv.meta | 7 +++++++ Lib9c/TableCSV/StakeRegularFixedRewardSheet_V2.csv.meta | 7 +++++++ Lib9c/TableCSV/StakeRegularRewardSheet_V1.csv.meta | 7 +++++++ Lib9c/TableCSV/StakeRegularRewardSheet_V2.csv.meta | 7 +++++++ Lib9c/TableCSV/StakeRegularRewardSheet_V3.csv.meta | 7 +++++++ Lib9c/TableCSV/StakeRegularRewardSheet_V4.csv.meta | 7 +++++++ Lib9c/TableCSV/StakeRegularRewardSheet_V5.csv.meta | 7 +++++++ 7 files changed, 49 insertions(+) create mode 100644 Lib9c/TableCSV/StakeRegularFixedRewardSheet_V1.csv.meta create mode 100644 Lib9c/TableCSV/StakeRegularFixedRewardSheet_V2.csv.meta create mode 100644 Lib9c/TableCSV/StakeRegularRewardSheet_V1.csv.meta create mode 100644 Lib9c/TableCSV/StakeRegularRewardSheet_V2.csv.meta create mode 100644 Lib9c/TableCSV/StakeRegularRewardSheet_V3.csv.meta create mode 100644 Lib9c/TableCSV/StakeRegularRewardSheet_V4.csv.meta create mode 100644 Lib9c/TableCSV/StakeRegularRewardSheet_V5.csv.meta diff --git a/Lib9c/TableCSV/StakeRegularFixedRewardSheet_V1.csv.meta b/Lib9c/TableCSV/StakeRegularFixedRewardSheet_V1.csv.meta new file mode 100644 index 0000000000..35433135a8 --- /dev/null +++ b/Lib9c/TableCSV/StakeRegularFixedRewardSheet_V1.csv.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 894e39fedde484dbd83c8329532e3c5c +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Lib9c/TableCSV/StakeRegularFixedRewardSheet_V2.csv.meta b/Lib9c/TableCSV/StakeRegularFixedRewardSheet_V2.csv.meta new file mode 100644 index 0000000000..a9ca4c658f --- /dev/null +++ b/Lib9c/TableCSV/StakeRegularFixedRewardSheet_V2.csv.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 5afe58c7ef3cc4bbd9481c4426d1dc50 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Lib9c/TableCSV/StakeRegularRewardSheet_V1.csv.meta b/Lib9c/TableCSV/StakeRegularRewardSheet_V1.csv.meta new file mode 100644 index 0000000000..5bd76b1a8d --- /dev/null +++ b/Lib9c/TableCSV/StakeRegularRewardSheet_V1.csv.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 8a090fd12b3254f71bbd23c7de9a9f06 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Lib9c/TableCSV/StakeRegularRewardSheet_V2.csv.meta b/Lib9c/TableCSV/StakeRegularRewardSheet_V2.csv.meta new file mode 100644 index 0000000000..1d591bc047 --- /dev/null +++ b/Lib9c/TableCSV/StakeRegularRewardSheet_V2.csv.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 440c9dbb9ee5e4ada8bf6333d68c450f +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Lib9c/TableCSV/StakeRegularRewardSheet_V3.csv.meta b/Lib9c/TableCSV/StakeRegularRewardSheet_V3.csv.meta new file mode 100644 index 0000000000..0cabebdfed --- /dev/null +++ b/Lib9c/TableCSV/StakeRegularRewardSheet_V3.csv.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 5d22627f4077c42948bf7cd952231b53 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Lib9c/TableCSV/StakeRegularRewardSheet_V4.csv.meta b/Lib9c/TableCSV/StakeRegularRewardSheet_V4.csv.meta new file mode 100644 index 0000000000..a45d18895f --- /dev/null +++ b/Lib9c/TableCSV/StakeRegularRewardSheet_V4.csv.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: ac7b5817a284948d095a8b8e312a247a +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Lib9c/TableCSV/StakeRegularRewardSheet_V5.csv.meta b/Lib9c/TableCSV/StakeRegularRewardSheet_V5.csv.meta new file mode 100644 index 0000000000..83bd4e2ef2 --- /dev/null +++ b/Lib9c/TableCSV/StakeRegularRewardSheet_V5.csv.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 3200739cb51ec41fa81a2127d1b87568 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: