Skip to content

Commit

Permalink
Fix mob reward source positioning
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaioru committed Dec 7, 2023
1 parent 6b81702 commit 6879c21
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Edelstein.Protocol.Gameplay.Game.Objects.User;
using Edelstein.Protocol.Gameplay.Models.Characters.Skills.Templates;
using Edelstein.Protocol.Gameplay.Models.Characters.Stats;
using Edelstein.Protocol.Utilities.Spatial;
using Edelstein.Protocol.Utilities.Templates;

namespace Edelstein.Common.Gameplay.Game.Combat;
Expand Down Expand Up @@ -37,10 +38,10 @@ public async Task HandleAttack(IFieldUser user, int skillID, bool IsHitMob)
await context.Execute();
}

public async Task HandleAttackMob(IFieldUser user, IFieldMob mob, int skillID, int damage)
public async Task HandleAttackMob(IFieldUser user, IFieldMob mob, int skillID, int damage, IPoint2D positionHit)
{
if (damage == 0) return;
await mob.Damage(damage, user);
await mob.Damage(damage, user, positionHit);
var context = await CreateContext(user, skillID, user.Stats.SkillLevels[skillID], mob: mob);
if (context == null) return;
var handler = await Retrieve(user.Character.Job);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public async Task Handle(IPipelineContext ctx, FieldOnPacketSummonedAttack messa
{
var mob = mobs.TryGetValue(entry.MobID, out var e) ? e : null;
if (mob == null) continue;
await _skillManager.HandleAttackMob(message.User, mob, message.Summoned.SkillID, entry.Damage.Sum());
await _skillManager.HandleAttackMob(message.User, mob, message.Summoned.SkillID, entry.Damage.Sum(), entry.PositionHit);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ Skill.BmageFinishAttack4 or
{
var mob = mobs.TryGetValue(entry.MobID, out var e) ? e : null;
if (mob == null) continue;
await _skillManager.HandleAttackMob(message.User, mob, message.Attack.SkillID, entry.Damage.Sum());
await _skillManager.HandleAttackMob(message.User, mob, message.Attack.SkillID, entry.Damage.Sum(), entry.PositionHit);
}
}
}
14 changes: 11 additions & 3 deletions src/common/Edelstein.Common.Gameplay.Game/Objects/Mob/FieldMob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using Edelstein.Common.Gameplay.Handling;
using Edelstein.Common.Gameplay.Models.Inventories.Items;
using Edelstein.Common.Utilities.Packets;
using Edelstein.Common.Utilities.Spatial;
using Edelstein.Protocol.Gameplay.Game.Combat.Damage;
using Edelstein.Protocol.Gameplay.Game.Objects;
using Edelstein.Protocol.Gameplay.Game.Objects.Mob;
using Edelstein.Protocol.Gameplay.Game.Objects.Mob.Stats;
Expand Down Expand Up @@ -63,7 +65,7 @@ public FieldMob(

private DateTime LastUpdateBurned { get; set; }

public async Task Damage(int damage, IFieldUser? attacker = null)
public async Task Damage(int damage, IFieldUser? attacker = null, IPoint2D? positionHit = null)
{
await _lock.WaitAsync();

Expand Down Expand Up @@ -101,9 +103,15 @@ public async Task Damage(int damage, IFieldUser? attacker = null)
var template = await attacker.StageUser.Context.Templates.Item.Retrieve(reward.ItemID.Value);
if (template == null) continue;

var position = Position;
var position = positionHit ?? Position;
var foothold = Field.Template.Footholds
.FindBelow(new Point2D(
position.X,
position.Y - 100
))
.FirstOrDefault();
var drop = new FieldDropItem(
position,
foothold?.Line.AtX(position.X) ?? position,
template.ToItemSlot(ItemVariationOption.Normal),
sourceID: ObjectID ?? 0
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public async Task<ICollection<IMobReward>> CalculateRewards(IFieldUser user, IFi
items.AddRange(await pool.RetrieveAll());
items.AddRange(await Global.RetrieveAll());

return items.ToImmutableArray();
return items
.OrderBy(i => Random.Shared.Next())
.ToImmutableArray();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Edelstein.Protocol.Gameplay.Game.Objects.Mob;
using Edelstein.Protocol.Gameplay.Game.Objects.User;
using Edelstein.Protocol.Utilities.Repositories.Methods;
using Edelstein.Protocol.Utilities.Spatial;

namespace Edelstein.Protocol.Gameplay.Game.Combat;

Expand All @@ -13,7 +14,7 @@ public interface ISkillManager :
Task<bool> Check(IFieldUser user, int skillID);

Task HandleAttack(IFieldUser user, int skillID, bool IsHitMob);
Task HandleAttackMob(IFieldUser user, IFieldMob mob, int skillID, int damage);
Task HandleAttackMob(IFieldUser user, IFieldMob mob, int skillID, int damage, IPoint2D positionHit);

Task HandleSkillUse(IFieldUser user, int skillID);
Task HandleSkillCancel(IFieldUser user, int skillID);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using Edelstein.Protocol.Gameplay.Game.Objects.Mob.Stats;
using Edelstein.Protocol.Gameplay.Game.Combat.Damage;
using Edelstein.Protocol.Gameplay.Game.Objects.Mob.Stats;
using Edelstein.Protocol.Gameplay.Game.Objects.Mob.Stats.Modify;
using Edelstein.Protocol.Gameplay.Game.Objects.Mob.Templates;
using Edelstein.Protocol.Gameplay.Game.Objects.User;
using Edelstein.Protocol.Gameplay.Game.Spatial;
using Edelstein.Protocol.Utilities.Spatial;

namespace Edelstein.Protocol.Gameplay.Game.Objects.Mob;

Expand All @@ -18,7 +20,7 @@ public interface IFieldMob : IFieldLife<IFieldMobMovePath, IFieldMobMoveAction>,
int HP { get; }
int MP { get; }

Task Damage(int damage, IFieldUser? attacker = null);
Task Damage(int damage, IFieldUser? attacker = null, IPoint2D? positionHit = null);

Task ModifyTemporaryStats(Action<IModifyMobTemporaryStatContext> action = null);
}

0 comments on commit 6879c21

Please sign in to comment.