This commit is contained in:
1 parent
42cf9e160f
commit
92d3afc2f0
8 files changed
+323
-12
No files matched your search
@@ -0,0 +1,203 @@
|
||||
package games.dmg.fantasystick;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import games.dmg.fantasystick.persistence.*;
|
||||
import games.dmg.fantasystick.shop.*;
|
||||
import games.dmg.fantasystick.session.EquipmentSessions;
|
||||
import games.dmg.fantasystick.progression.Stat;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
class MagicCoreEventsNativeTest {
|
||||
@TempDir Path data;
|
||||
@BeforeAll static void bootstrap() throws Exception { NativeRuntime.bootstrap(); }
|
||||
|
||||
@Test void registeredCoreConfigurationExportsReadsAndOnlyCommittedChanges() throws Exception {
|
||||
try (var f=new FantasyStickLifecycleNativeTest.Fixture(data)) {
|
||||
f.plugin.setEnabled(true);
|
||||
((games.dmg.fantasystick.events.LocalEventLog)FantasyStickLifecycleNativeTest.Fixture.field(f.plugin,"eventLog"))
|
||||
.ready().toCompletableFuture().get(5,TimeUnit.SECONDS);
|
||||
var sender=new EquipmentAdminCommandNativeTest.Sender();
|
||||
var keys=List.of("rare-price-magic-core","rare-stock-magic-core-min","rare-stock-magic-core-max");
|
||||
for(var key:keys){
|
||||
assertTrue(f.command.tabComplete(sender.port,"fstickadmin",new String[]{"config","rare-"}).contains(key));
|
||||
f.command.execute(sender.port,"fstickadmin",new String[]{"config",key});
|
||||
}
|
||||
int before=sender.messages.size();
|
||||
f.command.execute(sender.port,"fstickadmin",new String[]{"config",keys.getFirst(),"3001"});
|
||||
ReskillEventsNativeTest.await(f,()->sender.messages.size()>before);
|
||||
try(var channel=java.nio.channels.FileChannel.open(data.resolve(".config.lock"),
|
||||
StandardOpenOption.CREATE,StandardOpenOption.WRITE);var lock=channel.lock()){
|
||||
assertTrue(lock.isValid());int messages=sender.messages.size();
|
||||
f.command.execute(sender.port,"fstickadmin",new String[]{"config",keys.getFirst(),"3002"});
|
||||
ReskillEventsNativeTest.await(f,()->sender.messages.size()>messages);
|
||||
assertTrue(sender.messages.getLast().contains("save failed"));
|
||||
}
|
||||
f.command.execute(sender.port,"fstickadmin",new String[]{"config",keys.getFirst(),"-1"});
|
||||
sender.allowed=false;
|
||||
f.command.execute(sender.port,"fstickadmin",new String[]{"config",keys.getFirst(),"3003"});
|
||||
ReskillEventsNativeTest.await(f,()->config().size()==4);
|
||||
f.plugin.setEnabled(false);f.awaitWorkers();
|
||||
}
|
||||
var rows=config();assertEquals(3,rows.stream().filter(row->row.get("type").getAsString().endsWith("config.read")).count());
|
||||
var changes=rows.stream().filter(row->row.get("type").getAsString().endsWith("config.changed")).toList();
|
||||
assertEquals(1,changes.size());var proof=changes.getFirst().getAsJsonObject("data");
|
||||
assertEquals("3000",proof.get("before").getAsString());assertEquals("3001",proof.get("after").getAsString());
|
||||
assertEquals("next_rare_restock",proof.get("application").getAsString());
|
||||
}
|
||||
|
||||
@Test void purchasedCoresAtMaxLevelReachRealBookSpendingResetTransferAndJsonl() throws Exception {
|
||||
Files.writeString(data.resolve("config.yml"),"rare-price-variance-percent: 0\nrare-price-magic-core: 3000\n"
|
||||
+"rare-stock-magic-core-min: 5\nrare-stock-magic-core-max: 5\nrare-price-reskill: 2000\n"
|
||||
+"rare-stock-reskill-min: 1\nrare-stock-reskill-max: 1\n");
|
||||
var initial=BigInteger.TWO.pow(100);UUID character,newHolder;
|
||||
try(var f=new FantasyStickLifecycleNativeTest.Fixture(data)){
|
||||
f.plugin.setEnabled(true);var a=eligibleActor(f,initial);character=a.core.record.id();
|
||||
var inventory=(RareInventoryDirectory)FantasyStickLifecycleNativeTest.Fixture.field(f.plugin,"rareInventory");
|
||||
var directory=(RareMerchantDirectory)FantasyStickLifecycleNativeTest.Fixture.field(f.plugin,"rareMerchants");
|
||||
UUID world=UUID.randomUUID();when(a.world.getUID()).thenReturn(world);
|
||||
var shop=directory.place("Core market",world,a.core.location.getX(),a.core.location.getY(),a.core.location.getZ(),0,0).join();
|
||||
for(int count=1;count<=5;count++){
|
||||
buy(f,a,shop.id(),14);int expected=count;
|
||||
ReskillEventsNativeTest.await(f,()->inventory.quantity(character,RareProduct.MAGIC_CORE).equals(BigInteger.valueOf(expected))
|
||||
&¤t(f,a).coins().equals(BigInteger.valueOf(17000L-expected*3000L)));
|
||||
assertEquals(initial,current(f,a).unspentPoints(),"Buying a Core grants no point");
|
||||
}
|
||||
var rare=(RareShop)FantasyStickLifecycleNativeTest.Fixture.field(f.plugin,"rareShop");
|
||||
var noStock=new java.util.concurrent.atomic.AtomicReference<RareShop.Outcome>();
|
||||
var market=(RareMarket)FantasyStickLifecycleNativeTest.Fixture.field(f.plugin,"rareMarket");
|
||||
rare.buy(a.player,shop.id(),market.current().toCompletableFuture().join().revision(),RareProduct.MAGIC_CORE,noStock::set);
|
||||
ReskillEventsNativeTest.await(f,()->noStock.get()!=null);assertEquals(RareShop.Status.SOLD_OUT,noStock.get().status());
|
||||
useCore(f,a,initial.add(BigInteger.ONE));
|
||||
PartyBookNativeTest.open(f,a);PartyBookNativeTest.click(f,a,PartyBookNativeTest.button(a,"[+1 STR]"));
|
||||
ReskillEventsNativeTest.await(f,()->current(f,a).stats().get(Stat.STR).equals(BigInteger.valueOf(13)));
|
||||
useCore(f,a,initial.add(BigInteger.ONE));
|
||||
PartyBookNativeTest.open(f,a);PartyBookNativeTest.click(f,a,button(a,"[Learn]","great_sword"));
|
||||
ReskillEventsNativeTest.await(f,()->current(f,a).learned().contains("great_sword"));
|
||||
useCore(f,a,initial.add(BigInteger.ONE));
|
||||
PartyBookNativeTest.open(f,a);PartyBookNativeTest.click(f,a,button(a,"[Learn]","quicker_regeneration_i"));
|
||||
ReskillEventsNativeTest.await(f,()->current(f,a).passives().contains("quicker_regeneration_i"));
|
||||
useCore(f,a,initial.add(BigInteger.ONE));
|
||||
buy(f,a,shop.id(),13);
|
||||
ReskillEventsNativeTest.await(f,()->inventory.quantity(character,RareProduct.RESKILL).equals(BigInteger.ONE)
|
||||
&¤t(f,a).coins().signum()==0);
|
||||
PartyBookNativeTest.open(f,a);PartyBookNativeTest.click(f,a,button(a,"[Use]","reskill"));
|
||||
ReskillEventsNativeTest.await(f,()->PartyBookNativeTest.text(a).contains("Confirm Reskill"));
|
||||
PartyBookNativeTest.click(f,a,PartyBookNativeTest.button(a,"[Confirm Reskill]"));
|
||||
ReskillEventsNativeTest.await(f,()->inventory.quantity(character,RareProduct.RESKILL).signum()==0
|
||||
&¤t(f,a).unspentPoints().equals(initial.add(BigInteger.valueOf(40))));
|
||||
assertEquals(BigInteger.ONE,inventory.quantity(character,RareProduct.MAGIC_CORE),"Reset preserves the unused Core");
|
||||
assertTrue(current(f,a).learned().isEmpty());assertTrue(current(f,a).passives().stream().allMatch(String::isEmpty));
|
||||
var sessions=(EquipmentSessions)FantasyStickLifecycleNativeTest.Fixture.field(f.plugin,"sessions");
|
||||
assertEquals(games.dmg.fantasystick.items.EquipmentStorage.RestoreResult.RESTORED,sessions.exit(a.player));
|
||||
f.awaitCharacterAndReceipt(a);
|
||||
var b=new FantasyStickLifecycleNativeTest.Actor(data);f.players.put(b.core.id,b.player);newHolder=b.core.id;
|
||||
b.core.inventory.setItemInOffHand(a.core.inventory.getItemInOffHand().clone());f.activate(b);
|
||||
assertEquals(character,sessions.active(newHolder).orElseThrow().character());
|
||||
useCore(f,b,initial.add(BigInteger.valueOf(41)));
|
||||
ReskillEventsNativeTest.await(f,()->credits().size()==5);
|
||||
f.plugin.setEnabled(false);f.awaitWorkers();f.plugin.setEnabled(true);
|
||||
assertEquals(initial.add(BigInteger.valueOf(41)),new YamlCharacterRepository(data).load(character).orElseThrow().unspentPoints());
|
||||
f.plugin.setEnabled(false);f.awaitWorkers();
|
||||
}
|
||||
var rows=ReskillEventsNativeTest.records(data);var purchased=rows.stream().filter(row->row.get("type").getAsString()
|
||||
.endsWith("rare_item.purchased")&&row.getAsJsonObject("data").get("product_id").getAsString().equals("magic-core")).toList();
|
||||
assertEquals(5,purchased.size());assertEquals(5,purchased.stream().map(row->row.get("id").getAsString()).distinct().count());
|
||||
var credits=credits();assertEquals(5,credits.size());assertEquals(5,credits.stream().map(row->row.get("id").getAsString()).distinct().count());
|
||||
for(var credit:credits){var proof=credit.getAsJsonObject("data");
|
||||
assertEquals(BigInteger.ONE,new BigInteger(proof.get("points_after").getAsString()).subtract(new BigInteger(proof.get("points_before").getAsString())));
|
||||
assertEquals("30",proof.get("level_before").getAsString());assertEquals(proof.get("level_before"),proof.get("level_after"));
|
||||
assertEquals(proof.get("xp_before"),proof.get("xp_after"));assertTrue(proof.has("location"));
|
||||
}
|
||||
assertEquals(1,credits.stream().filter(row->row.getAsJsonObject("data").get("player_id").getAsString().equals(newHolder.toString())).count());
|
||||
assertEquals(1,rows.stream().filter(row->row.get("type").getAsString().endsWith("rare_catalog.refreshed")).count(),
|
||||
"Restart retains the full global catalog; Core does not emit another refresh");
|
||||
}
|
||||
|
||||
@Test void failedPointSaveRefundsCoreAndThrowingAuditCannotDuplicateOrUndoCredit() throws Exception {
|
||||
try(var f=new FantasyStickLifecycleNativeTest.Fixture(data)){
|
||||
f.plugin.setEnabled(true);var a=eligibleActor(f,BigInteger.valueOf(100));
|
||||
var inventory=(RareInventoryDirectory)FantasyStickLifecycleNativeTest.Fixture.field(f.plugin,"rareInventory");
|
||||
inventory.add(a.core.record.id(),RareProduct.MAGIC_CORE,UUID.randomUUID()).join();
|
||||
try(var channel=java.nio.channels.FileChannel.open(data.resolve("characters/.records.lock"),StandardOpenOption.WRITE);
|
||||
var lock=channel.lock()){
|
||||
assertTrue(lock.isValid());PartyBookNativeTest.open(f,a);PartyBookNativeTest.click(f,a,button(a,"[Use]","magic-core"));
|
||||
ReskillEventsNativeTest.await(f,()->a.messages.stream().anyMatch(message->message.contains("Magic Core could not be acknowledged")));
|
||||
assertEquals(BigInteger.valueOf(100),current(f,a).unspentPoints());
|
||||
assertEquals(BigInteger.ONE,inventory.quantity(a.core.record.id(),RareProduct.MAGIC_CORE));assertTrue(credits().isEmpty());
|
||||
}
|
||||
var characters=(CharacterStorage)FantasyStickLifecycleNativeTest.Fixture.field(f.plugin,"characters");
|
||||
var sessions=(EquipmentSessions)FantasyStickLifecycleNativeTest.Fixture.field(f.plugin,"sessions");
|
||||
var service=new RareMagicCoreService(inventory,characters,sessions,f.tasks::add,ignored->{});
|
||||
var attempts=new ArrayList<games.dmg.fantasystick.events.EventInput>();
|
||||
service.attachEvents(new games.dmg.fantasystick.events.RareEventBridge(event->{attempts.add(event);throw new IllegalStateException("audit failed");},java.time.Clock.systemUTC()));
|
||||
var outcome=new java.util.concurrent.atomic.AtomicReference<RareMagicCoreService.Outcome>();service.use(a.player,outcome::set);
|
||||
ReskillEventsNativeTest.await(f,()->outcome.get()!=null);assertEquals(RareMagicCoreService.Status.APPLIED,outcome.get().status());
|
||||
assertEquals(BigInteger.valueOf(101),current(f,a).unspentPoints());assertEquals(1,attempts.size());
|
||||
outcome.set(null);service.use(a.player,outcome::set);assertEquals(RareMagicCoreService.Status.NOT_AVAILABLE,outcome.get().status());
|
||||
assertEquals(BigInteger.valueOf(101),current(f,a).unspentPoints());assertEquals(1,attempts.size());
|
||||
f.plugin.setEnabled(false);f.awaitWorkers();
|
||||
}
|
||||
assertTrue(credits().isEmpty(),"A throwing non-durable test sink makes no export claim");
|
||||
}
|
||||
|
||||
private FantasyStickLifecycleNativeTest.Actor eligibleActor(FantasyStickLifecycleNativeTest.Fixture f,BigInteger points) throws Exception {
|
||||
var a=new FantasyStickLifecycleNativeTest.Actor(data);f.players.put(a.core.id,a.player);
|
||||
var repository=new YamlCharacterRepository(data);var old=repository.load(a.core.record.id()).orElseThrow();
|
||||
var stats=new EnumMap<>(old.stats());for(var stat:List.of(Stat.STR,Stat.CON,Stat.WIS))stats.put(stat,BigInteger.valueOf(12));
|
||||
repository.replace(new CharacterRecord(old.id(),old.name(),old.revision().add(BigInteger.ONE),stats,30,BigInteger.ZERO,
|
||||
points,new BigDecimal("22"),old.learned(),old.loadout(),old.passives(),old.cooldowns(),old.restrictedKills(),false,
|
||||
null,null,BigInteger.valueOf(17000),true,old.rewardReceipts(),old.pvpCoinEscrow(),old.gear(),old.sheetGeneration()),old.revision());
|
||||
f.activate(a);return a;
|
||||
}
|
||||
private static CharacterRecord current(FantasyStickLifecycleNativeTest.Fixture f,FantasyStickLifecycleNativeTest.Actor a){
|
||||
var sessions=(EquipmentSessions)FantasyStickLifecycleNativeTest.Fixture.field(f.plugin,"sessions");
|
||||
return sessions.currentRecord(sessions.active(a.core.id).orElseThrow()).orElseThrow();
|
||||
}
|
||||
private void useCore(FantasyStickLifecycleNativeTest.Fixture f,FantasyStickLifecycleNativeTest.Actor a,BigInteger expected) throws Exception {
|
||||
PartyBookNativeTest.open(f,a);var action=button(a,"[Use]","magic-core");PartyBookNativeTest.click(f,a,action);
|
||||
ReskillEventsNativeTest.await(f,()->current(f,a).unspentPoints().equals(expected));
|
||||
PartyBookNativeTest.click(f,a,action);
|
||||
}
|
||||
private static void buy(FantasyStickLifecycleNativeTest.Fixture f,FantasyStickLifecycleNativeTest.Actor a,UUID shop,int slot) throws Exception {
|
||||
var menus=(RareShopMenus)FantasyStickLifecycleNativeTest.Fixture.field(f.plugin,"rareShopMenus");int size=a.inventories.size();
|
||||
menus.open(a.player,shop);ReskillEventsNativeTest.await(f,()->a.inventories.size()>size);
|
||||
var menu=a.inventories.getLast();var click=mock(InventoryClickEvent.class);
|
||||
when(click.getInventory()).thenReturn(menu);when(click.getWhoClicked()).thenReturn(a.player);when(click.getCurrentItem()).thenReturn(menu.getItem(slot));
|
||||
menus.click(click);
|
||||
}
|
||||
private static net.minecraft.network.chat.ClickEvent.Custom button(FantasyStickLifecycleNativeTest.Actor a,String label,String identity){
|
||||
var content=org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(a.books.getLast())
|
||||
.get(net.minecraft.core.component.DataComponents.WRITTEN_BOOK_CONTENT);
|
||||
for(var page:content.pages()){var found=find(page.raw(),label,identity);if(found!=null)return found;}
|
||||
throw new AssertionError("Missing native book action "+label+" for "+identity);
|
||||
}
|
||||
private static net.minecraft.network.chat.ClickEvent.Custom find(net.minecraft.network.chat.Component component,String label,String identity){
|
||||
if(component.getString().equals(label)&&component.getStyle().getClickEvent() instanceof net.minecraft.network.chat.ClickEvent.Custom custom
|
||||
&&custom.payload().orElse(null) instanceof net.minecraft.nbt.StringTag payload&&payload.value().contains(":"+identity))return custom;
|
||||
for(var child:component.getSiblings()){var found=find(child,label,identity);if(found!=null)return found;}return null;
|
||||
}
|
||||
private List<JsonObject> credits(){
|
||||
try{return ReskillEventsNativeTest.records(data).stream().filter(row->row.get("type").getAsString().endsWith("rare_item.used")
|
||||
&&row.getAsJsonObject("data").get("product_id").getAsString().equals("magic-core")).toList();}
|
||||
catch(Exception failure){throw new IllegalStateException(failure);}
|
||||
}
|
||||
private List<JsonObject> config(){
|
||||
try{return ReskillEventsNativeTest.records(data).stream().filter(row->row.getAsJsonObject("data").has("key")
|
||||
&&row.getAsJsonObject("data").get("key").getAsString().contains("magic-core")).toList();}
|
||||
catch(Exception failure){throw new IllegalStateException(failure);}
|
||||
}
|
||||
}
|
||||
@@ -47,7 +47,9 @@ class RareShopNativeTest {
|
||||
&&hasRareEvent(events,"rare_shop.placed","shop_id",shop.id().toString())
|
||||
&&hasRareEvent(events,"rare_item.purchased","product_id","health-potion")
|
||||
&&hasRareEvent(events,"rare_item.purchased","product_id","phoenix-down")
|
||||
&&hasRareEvent(events,"rare_item.used","product_id","health-potion");
|
||||
&&hasRareEvent(events,"rare_item.used","product_id","health-potion")
|
||||
&&hasRareEvent(events,"rare_item.purchased","product_id","magic-core")
|
||||
&&hasRareEvent(events,"rare_item.used","product_id","magic-core");
|
||||
});
|
||||
f.plugin.setEnabled(false);f.awaitWorkers();
|
||||
var exported=new java.util.ArrayList<com.google.gson.JsonObject>();
|
||||
@@ -85,14 +87,32 @@ class RareShopNativeTest {
|
||||
.findFirst().orElseThrow();
|
||||
assertEquals("20",resetOffer.get("price").getAsString());
|
||||
assertEquals("2",resetOffer.get("stock").getAsString());
|
||||
var coreOffer=products.asList().stream().map(com.google.gson.JsonElement::getAsJsonObject)
|
||||
.filter(product->product.get("product_id").getAsString().equals("magic-core"))
|
||||
.findFirst().orElseThrow();
|
||||
assertEquals("30",coreOffer.get("price").getAsString());
|
||||
assertEquals("1",coreOffer.get("stock").getAsString());
|
||||
}
|
||||
assertTrue(exported.stream().anyMatch(event->event.get("type").getAsString()
|
||||
.endsWith("rare_item.purchased")&&event.getAsJsonObject("data")
|
||||
.get("product_id").getAsString().equals("phoenix-down")));
|
||||
assertFalse(exported.stream().anyMatch(event->event.get("type").getAsString()
|
||||
.endsWith("rare_item.purchased")&&event.getAsJsonObject("data")
|
||||
.get("product_id").getAsString().equals("magic-core")),
|
||||
"US-088 purchase events wait for their own implementation");
|
||||
var corePurchases=exported.stream().filter(event->event.get("type").getAsString()
|
||||
.endsWith("rare_item.purchased")&&event.getAsJsonObject("data").get("product_id")
|
||||
.getAsString().equals("magic-core")).toList();
|
||||
assertEquals(1,corePurchases.size());var corePurchase=corePurchases.getFirst().getAsJsonObject("data");
|
||||
assertEquals("30",corePurchase.get("price").getAsString());
|
||||
assertEquals("90",corePurchase.get("coins_before").getAsString());
|
||||
assertEquals("60",corePurchase.get("coins_after").getAsString());
|
||||
assertEquals("1",corePurchase.get("stock_before").getAsString());
|
||||
assertEquals("0",corePurchase.get("stock_after").getAsString());
|
||||
assertEquals(worldId.toString(),corePurchase.getAsJsonObject("location").get("world_id").getAsString());
|
||||
var coreUses=exported.stream().filter(event->event.get("type").getAsString()
|
||||
.endsWith("rare_item.used")&&event.getAsJsonObject("data").get("product_id")
|
||||
.getAsString().equals("magic-core")).toList();
|
||||
assertEquals(1,coreUses.size());var coreProof=coreUses.getFirst().getAsJsonObject("data");
|
||||
assertEquals("39",coreProof.get("points_before").getAsString());
|
||||
assertEquals("40",coreProof.get("points_after").getAsString());
|
||||
assertEquals("1",coreProof.get("credited_points").getAsString());
|
||||
var resetPurchases=exported.stream().filter(event->event.get("type").getAsString()
|
||||
.endsWith("rare_item.purchased")&&event.getAsJsonObject("data").get("product_id")
|
||||
.getAsString().equals("reskill")).toList();
|
||||
@@ -219,7 +239,21 @@ class RareShopNativeTest {
|
||||
}
|
||||
|
||||
@Test void magicCoreUseAddsOneVisibleSpendableOrdinaryPoint()throws Exception{
|
||||
try(var f=new FantasyStickLifecycleNativeTest.Fixture(data)){f.plugin.setEnabled(true);var actor=new FantasyStickLifecycleNativeTest.Actor(data);f.players.put(actor.core.id,actor.player);f.activate(actor);var inventory=(RareInventoryDirectory)FantasyStickLifecycleNativeTest.Fixture.field(f.plugin,"rareInventory");inventory.add(actor.core.record.id(),RareProduct.MAGIC_CORE,UUID.randomUUID()).join();PartyBookNativeTest.open(f,actor);String before=PartyBookNativeTest.text(actor);assertTrue(before.contains("Magic Core: 1"),before);PartyBookNativeTest.click(f,actor,PartyBookNativeTest.button(actor,"[Use]"));var sessions=(games.dmg.fantasystick.session.EquipmentSessions)FantasyStickLifecycleNativeTest.Fixture.field(f.plugin,"sessions");await(f,()->inventory.quantity(actor.core.record.id(),RareProduct.MAGIC_CORE).signum()==0&&sessions.active(actor.core.id).flatMap(sessions::currentRecord).map(record->record.unspentPoints().equals(BigInteger.valueOf(41))).orElse(false));var active=sessions.active(actor.core.id).orElseThrow();var record=sessions.currentRecord(active).orElseThrow();var characters=(CharacterStorage)FantasyStickLifecycleNativeTest.Fixture.field(f.plugin,"characters");var spent=characters.purchaseStat(record.id(),record.revision(),games.dmg.fantasystick.progression.Stat.STR,BigDecimal.valueOf(actor.player.getHealth()),new BigDecimal("1024")).join().record().orElseThrow();assertTrue(sessions.acknowledgeProgress(active,record.revision(),spent));assertEquals(BigInteger.ONE,spent.stats().get(games.dmg.fantasystick.progression.Stat.STR));assertEquals(BigInteger.valueOf(40),spent.unspentPoints());}
|
||||
try(var f=new FantasyStickLifecycleNativeTest.Fixture(data)){f.plugin.setEnabled(true);var actor=new FantasyStickLifecycleNativeTest.Actor(data);f.players.put(actor.core.id,actor.player);f.activate(actor);var inventory=(RareInventoryDirectory)FantasyStickLifecycleNativeTest.Fixture.field(f.plugin,"rareInventory");inventory.add(actor.core.record.id(),RareProduct.MAGIC_CORE,UUID.randomUUID()).join();PartyBookNativeTest.open(f,actor);String before=PartyBookNativeTest.text(actor);assertTrue(before.contains("Magic Core: 1"),before);PartyBookNativeTest.click(f,actor,PartyBookNativeTest.button(actor,"[Use]"));var sessions=(games.dmg.fantasystick.session.EquipmentSessions)FantasyStickLifecycleNativeTest.Fixture.field(f.plugin,"sessions");await(f,()->inventory.quantity(actor.core.record.id(),RareProduct.MAGIC_CORE).signum()==0&&sessions.active(actor.core.id).flatMap(sessions::currentRecord).map(record->record.unspentPoints().equals(BigInteger.valueOf(41))).orElse(false));var active=sessions.active(actor.core.id).orElseThrow();var record=sessions.currentRecord(active).orElseThrow();var characters=(CharacterStorage)FantasyStickLifecycleNativeTest.Fixture.field(f.plugin,"characters");var spent=characters.purchaseStat(record.id(),record.revision(),games.dmg.fantasystick.progression.Stat.STR,BigDecimal.valueOf(actor.player.getHealth()),new BigDecimal("1024")).join().record().orElseThrow();assertTrue(sessions.acknowledgeProgress(active,record.revision(),spent));assertEquals(BigInteger.ONE,spent.stats().get(games.dmg.fantasystick.progression.Stat.STR));assertEquals(BigInteger.valueOf(40),spent.unspentPoints());
|
||||
await(f,()->hasRareEvent(exportedRareEvents(data),"rare_item.used","product_id","magic-core"));
|
||||
f.plugin.setEnabled(false);f.awaitWorkers();
|
||||
var credits=exportedRareEvents(data).stream().filter(event->event.get("type").getAsString()
|
||||
.endsWith("rare_item.used")&&event.getAsJsonObject("data").get("product_id").getAsString()
|
||||
.equals("magic-core")).toList();
|
||||
assertEquals(1,credits.size());var proof=credits.getFirst().getAsJsonObject("data");
|
||||
assertEquals("40",proof.get("points_before").getAsString());
|
||||
assertEquals("41",proof.get("points_after").getAsString());
|
||||
assertEquals("1",proof.get("quantity_before").getAsString());
|
||||
assertEquals("0",proof.get("quantity_after").getAsString());
|
||||
assertEquals(proof.get("level_before"),proof.get("level_after"));
|
||||
assertEquals(proof.get("xp_before"),proof.get("xp_after"));
|
||||
assertEquals(actor.core.record.id().toString(),proof.get("character_id").getAsString());
|
||||
assertTrue(proof.has("location"));}
|
||||
}
|
||||
|
||||
@Test void reskillWithNothingInvestedRefusesWithoutConsumingTheStoredItem()throws Exception{
|
||||
|
||||
Reference in new issue
Block a user