Let strangers pick up party money and split it equally
Money has no owner - unlike a dropped item it can be picked up by anyone standing on it. Deriving the drop's shares from the killer's party made a stranger's pick up pay nothing and leave the money on the ground, destroying zen that was previously taken and split by the picking party. The recorded shares now apply only when the party picking the money up is the one which earned it; otherwise there is no experience of theirs to follow and the money is split equally between the picking party, as it was before and as share-less money (e.g. from an item box) already is. Covered by DroppedMoneyTest.StrangerPartySplitsPickedUpMoneyEquallyAsync and EarningPartyReceivesMoneyByExperienceShareAsync. (cherry picked from commit ae7cad81da6893cfbd1c28bb29811b7f0a10d540)
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
namespace MUnique.OpenMU.Tests;
|
||||
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using MUnique.OpenMU.GameLogic;
|
||||
using MUnique.OpenMU.Pathfinding;
|
||||
using NUnit.Framework;
|
||||
@@ -62,4 +63,76 @@ public class DroppedMoneyTest
|
||||
Assert.That(await money.TryPickUpByAsync(otherPlayer).ConfigureAwait(false), Is.False);
|
||||
Assert.That(otherPlayer.Money, Is.EqualTo(0));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that money earned by one party can still be picked up by a stranger's party - money has no
|
||||
/// owner - and is then split equally between the picking party, because there is no experience of theirs
|
||||
/// to follow. The earner, who is not in the picking party, receives nothing.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task StrangerPartySplitsPickedUpMoneyEquallyAsync()
|
||||
{
|
||||
var earner = await PlayerTestHelper.CreatePlayerAsync().ConfigureAwait(false);
|
||||
var gameContext = earner.GameContext;
|
||||
gameContext.Configuration.MaximumInventoryMoney = int.MaxValue;
|
||||
|
||||
var strangerParty = CreateParty();
|
||||
var stranger1 = await AddPartyMemberAsync(gameContext, strangerParty).ConfigureAwait(false);
|
||||
var stranger2 = await AddPartyMemberAsync(gameContext, strangerParty).ConfigureAwait(false);
|
||||
|
||||
// The money was earned by 'earner', who is in neither of the picking party's members.
|
||||
var shares = new[] { new MoneyShare(earner, DroppedAmount) };
|
||||
var money = new DroppedMoney(DroppedAmount, new Point(100, 100), stranger1.CurrentMap!, shares);
|
||||
|
||||
Assert.That(await money.TryPickUpByAsync(stranger1).ConfigureAwait(false), Is.True);
|
||||
Assert.That(earner.Money, Is.EqualTo(0));
|
||||
Assert.That(stranger1.Money + stranger2.Money, Is.EqualTo((int)DroppedAmount));
|
||||
Assert.That(stranger1.Money, Is.EqualTo((int)DroppedAmount / 2));
|
||||
Assert.That(stranger2.Money, Is.EqualTo((int)DroppedAmount / 2));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests that when the earning party picks its own money up, it follows the recorded shares
|
||||
/// (proportional to the experience each member gained) instead of being split equally.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public async Task EarningPartyReceivesMoneyByExperienceShareAsync()
|
||||
{
|
||||
var big = await PlayerTestHelper.CreatePlayerAsync().ConfigureAwait(false);
|
||||
var gameContext = big.GameContext;
|
||||
gameContext.Configuration.MaximumInventoryMoney = int.MaxValue;
|
||||
|
||||
var party = CreateParty();
|
||||
await party.AddAsync(big).ConfigureAwait(false);
|
||||
var small = await AddPartyMemberAsync(gameContext, party).ConfigureAwait(false);
|
||||
|
||||
var shares = new[]
|
||||
{
|
||||
new MoneyShare(big, 800),
|
||||
new MoneyShare(small, 200),
|
||||
};
|
||||
var money = new DroppedMoney(DroppedAmount, new Point(100, 100), big.CurrentMap!, shares);
|
||||
|
||||
Assert.That(await money.TryPickUpByAsync(big).ConfigureAwait(false), Is.True);
|
||||
Assert.That(big.Money, Is.EqualTo(800));
|
||||
Assert.That(small.Money, Is.EqualTo(200));
|
||||
}
|
||||
|
||||
private static Party CreateParty()
|
||||
{
|
||||
// The party manager of the lightweight test context has a maximum size of zero, which would
|
||||
// reject every member. A stand-alone party with a real size is enough for the money distribution.
|
||||
var partyManager = new PartyManager(5, new NullLogger<Party>());
|
||||
return new Party(partyManager, 5, new NullLogger<Party>());
|
||||
}
|
||||
|
||||
private static async ValueTask<Player> AddPartyMemberAsync(IGameContext gameContext, Party party)
|
||||
{
|
||||
// The test helper already enters the player into the world, so it shares the live map of the
|
||||
// context with the other members created from the same context - which is what the money
|
||||
// distribution's eligibility check compares.
|
||||
var player = await PlayerTestHelper.CreatePlayerAsync(gameContext).ConfigureAwait(false);
|
||||
await party.AddAsync(player).ConfigureAwait(false);
|
||||
return player;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user