Skip to content

Commit

Permalink
Merge pull request #2291 from planetarium/bugfix/vampiric-overflow
Browse files Browse the repository at this point in the history
fix calculating logic of Vampiric, for avoid int overflow
  • Loading branch information
sonohoshi authored Dec 11, 2023
2 parents dc3f4f7 + 3813ed1 commit 4ffef62
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions .Lib9c.Tests/Model/PlayerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ public void Vampiric(int duration, int percent)
{
var defaultAttack = SkillFactory.GetV1(
_tableSheets.SkillSheet.Values.First(r => r.Id == GameConfig.DefaultAttackId),
100,
int.MaxValue / 2,
100
);

Expand All @@ -604,7 +604,12 @@ public void Vampiric(int duration, int percent)
_tableSheets.MaterialItemSheet)
);
var player = simulator.Player;
var enemy = new Enemy(player, _tableSheets.CharacterSheet.Values.First(), 1);
var enemy = new Enemy(
player,
_tableSheets.CharacterSheet.Values.First(),
1,
new[] { new StatModifier(StatType.HP, StatModifier.OperationType.Add, int.MaxValue / 2), }
);
player.Targets.Add(enemy);
simulator.Characters = new SimplePriorityQueue<CharacterBase, decimal>();
simulator.Characters.Enqueue(enemy, 0);
Expand Down Expand Up @@ -648,7 +653,7 @@ public void Vampiric(int duration, int percent)
var prevAttack = logList.Take(i).OfType<Nekoyume.Model.BattleStatus.NormalAttack>()
.Last();
Assert.Equal(
(int)(prevAttack.SkillInfos.First().Effect * vampiric.BasisPoint / 10000m),
(int)(prevAttack.SkillInfos.First().Effect * (vampiric.BasisPoint / 10000m)),
healInfo.Effect);
}
}
Expand Down
4 changes: 2 additions & 2 deletions Lib9c/Model/Buff/Vampiric.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public override object Clone()
public BattleStatus.Skill GiveEffect(CharacterBase affectedCharacter, BattleStatus.Skill.SkillInfo skillInfo, int simulatorWaveTurn, bool copyCharacter = true)
{
var target = copyCharacter ? (CharacterBase) affectedCharacter.Clone() : null;
var effect = (int)(skillInfo.Effect * BasisPoint / 10000m);
var effect = (int)(skillInfo.Effect * (BasisPoint / 10000m));
affectedCharacter.Heal(effect);
// Copy new Character with healed.
var infos = new List<BattleStatus.Skill.SkillInfo>
Expand All @@ -59,7 +59,7 @@ public BattleStatus.Skill GiveEffect(CharacterBase affectedCharacter, BattleStat
public ArenaSkill GiveEffectForArena(ArenaCharacter affectedCharacter, ArenaSkill.ArenaSkillInfo skillInfo, int simulatorWaveTurn)
{
var clone = (ArenaCharacter)affectedCharacter.Clone();
var effect = (int)(skillInfo.Effect * BasisPoint / 10000m);
var effect = (int)(skillInfo.Effect * (BasisPoint / 10000m));
affectedCharacter.Heal(effect);
// Copy new Character with healed.
var infos = new List<ArenaSkill.ArenaSkillInfo>
Expand Down

0 comments on commit 4ffef62

Please sign in to comment.