XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFESpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/XFESpaceNinjaServer

chore: defer giving of MissionRewards so we can do most of them at once (#3152)

Just a small refactor. Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/3152 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>

18022168
Sainan <63328889+Sainan@users.noreply.github.com>
提交于

代码差异

1 个文件 +97 -100
Modified src/services/missionInventoryUpdateService.ts +97 -100
@@ -1403,28 +1403,6 @@ export const addMissionRewards = async (
1403 1403 ConquestCompletedMissionsCount = rewardInfo.ConquestCompleted == 2 ? 0 : rewardInfo.ConquestCompleted + 1;
1404 1404 }
1405 1405
1406 for (const reward of MissionRewards) {
1407 const inventoryChange = await handleStoreItemAcquisition(
1408 reward.StoreItem,
1409 inventory,
1410 reward.ItemCount,
1411 undefined,
1412 true
1413 );
1414 //TODO: combineInventoryChanges improve type safety, merging 2 of the same item?
1415 //TODO: check for the case when two of the same item are added, combineInventoryChanges should merge them, but the client also merges them
1416 //TODO: some conditional types to rule out binchanges?
1417 combineInventoryChanges(inventoryChanges, inventoryChange.InventoryChanges);
1418 }
1419
1420 inventory.RegularCredits += missionCompletionCredits;
1421
1422 const credits = await addCredits(account, inventory, {
1423 missionCompletionCredits,
1424 missionDropCredits: creditDrops ?? 0,
1425 rngRewardCredits: inventoryChanges.RegularCredits ?? 0
1426 });
1427
1428 1406 if (voidTearWave && voidTearWave.Participants[0].QualifiesForReward) {
1429 1407 if (!voidTearWave.Participants[0].HaveRewardResponse) {
1430 1408 // non-endless fissure; giving reward now
@@ -1442,81 +1420,6 @@ export const addMissionRewards = async (
1442 1420 }
1443 1421 }
1444 1422
1445 if (strippedItems) {
1446 if (endOfMatchUpload) {
1447 for (const si of strippedItems) {
1448 if (si.DropTable in droptableAliases) {
1449 logger.debug(`rewriting ${si.DropTable} to ${droptableAliases[si.DropTable]}`);
1450 si.DropTable = droptableAliases[si.DropTable];
1451 }
1452 const droptables = ExportEnemies.droptables[si.DropTable] ?? [];
1453 if (si.DROP_MOD) {
1454 const modDroptable = droptables.find(x => x.type == "mod");
1455 if (modDroptable) {
1456 for (let i = 0; i != si.DROP_MOD.length; ++i) {
1457 const reward = getRandomReward(modDroptable.items)!;
1458 logger.debug(`stripped droptable (mods pool) rolled`, reward);
1459 await addItem(inventory, reward.type);
1460 MissionRewards.push({
1461 StoreItem: toStoreItem(reward.type),
1462 ItemCount: 1,
1463 FromEnemyCache: true // to show "identified"
1464 });
1465 }
1466 } else {
1467 logger.error(`unknown droptable ${si.DropTable} for DROP_MOD`);
1468 }
1469 }
1470 if (si.DROP_BLUEPRINT) {
1471 const blueprintDroptable = droptables.find(x => x.type == "blueprint");
1472 if (blueprintDroptable) {
1473 for (let i = 0; i != si.DROP_BLUEPRINT.length; ++i) {
1474 const reward = getRandomReward(blueprintDroptable.items)!;
1475 logger.debug(`stripped droptable (blueprints pool) rolled`, reward);
1476 await addItem(inventory, reward.type);
1477 MissionRewards.push({
1478 StoreItem: toStoreItem(reward.type),
1479 ItemCount: 1,
1480 FromEnemyCache: true // to show "identified"
1481 });
1482 }
1483 } else {
1484 logger.error(`unknown droptable ${si.DropTable} for DROP_BLUEPRINT`);
1485 }
1486 }
1487 // e.g. H-09 Apex Turret Sumdali
1488 if (si.DROP_MISC_ITEM) {
1489 const resourceDroptable = droptables.find(x => x.type == "resource");
1490 if (resourceDroptable) {
1491 for (let i = 0; i != si.DROP_MISC_ITEM.length; ++i) {
1492 const reward = getRandomReward(resourceDroptable.items)!;
1493 logger.debug(`stripped droptable (resources pool) rolled`, reward);
1494 if (Object.keys(await addItem(inventory, reward.type)).length == 0) {
1495 logger.debug(`item already owned, skipping`);
1496 } else {
1497 MissionRewards.push({
1498 StoreItem: toStoreItem(reward.type),
1499 ItemCount: 1,
1500 FromEnemyCache: true // to show "identified"
1501 });
1502 }
1503 }
1504 } else {
1505 logger.error(`unknown droptable ${si.DropTable} for DROP_MISC_ITEM`);
1506 }
1507 }
1508
1509 if (si.DropTable == "/Lotus/Types/DropTables/ContainerDropTables/VoidVaultMissionRewardsDropTable") {
1510 // Consume netracells search pulse; only when the container reward was picked up. Discussed in https://onlyg.it/OpenWF/SpaceNinjaServer/issues/2673
1511 updateEntratiVault(inventory);
1512 inventory.EntratiVaultCountLastPeriod! += 1;
1513 }
1514 }
1515 } else {
1516 logger.debug(`ignoring StrippedItems in intermediate inventory update, deferring until extraction`);
1517 }
1518 }
1519
1520 1423 if (inventory.Nemesis) {
1521 1424 if (
1522 1425 nemesis ||
@@ -1646,7 +1549,6 @@ export const addMissionRewards = async (
1646 1549 }
1647 1550 }
1648 1551 if (typeof medallionAmount === "number" && !isNaN(medallionAmount)) {
1649 await addItem(inventory, "/Lotus/Types/Items/Deimos/EntratiFragmentUncommonB", medallionAmount);
1650 1552 MissionRewards.push({
1651 1553 StoreItem: "/Lotus/StoreItems/Types/Items/Deimos/EntratiFragmentUncommonB",
1652 1554 ItemCount: medallionAmount
@@ -1680,7 +1582,6 @@ export const addMissionRewards = async (
1680 1582 if (syndicateTag === "ZarimanSyndicate") {
1681 1583 let medallionAmount = tier + 1;
1682 1584 if (isSteelPath) medallionAmount = Math.round(medallionAmount * 1.5);
1683 await addItem(inventory, "/Lotus/Types/Gameplay/Zariman/Resources/ZarimanDogTagBounty", medallionAmount);
1684 1585 MissionRewards.push({
1685 1586 StoreItem: "/Lotus/StoreItems/Types/Gameplay/Zariman/Resources/ZarimanDogTagBounty",
1686 1587 ItemCount: medallionAmount
@@ -1708,7 +1609,6 @@ export const addMissionRewards = async (
1708 1609 }
1709 1610 }
1710 1611 if (isSteelPath) {
1711 await addItem(inventory, "/Lotus/Types/Items/MiscItems/SteelEssence", 1);
1712 1612 MissionRewards.push({
1713 1613 StoreItem: "/Lotus/StoreItems/Types/Items/MiscItems/SteelEssence",
1714 1614 ItemCount: 1
@@ -1716,6 +1616,103 @@ export const addMissionRewards = async (
1716 1616 }
1717 1617 }
1718 1618
1619 for (const reward of MissionRewards) {
1620 const inventoryChange = await handleStoreItemAcquisition(
1621 reward.StoreItem,
1622 inventory,
1623 reward.ItemCount,
1624 undefined,
1625 true
1626 );
1627 //TODO: combineInventoryChanges improve type safety, merging 2 of the same item?
1628 //TODO: check for the case when two of the same item are added, combineInventoryChanges should merge them, but the client also merges them
1629 //TODO: some conditional types to rule out binchanges?
1630 combineInventoryChanges(inventoryChanges, inventoryChange.InventoryChanges);
1631 }
1632
1633 inventory.RegularCredits += missionCompletionCredits;
1634
1635 const credits = await addCredits(account, inventory, {
1636 missionCompletionCredits,
1637 missionDropCredits: creditDrops ?? 0,
1638 rngRewardCredits: inventoryChanges.RegularCredits ?? 0
1639 });
1640
1641 if (strippedItems) {
1642 if (endOfMatchUpload) {
1643 for (const si of strippedItems) {
1644 if (si.DropTable in droptableAliases) {
1645 logger.debug(`rewriting ${si.DropTable} to ${droptableAliases[si.DropTable]}`);
1646 si.DropTable = droptableAliases[si.DropTable];
1647 }
1648 const droptables = ExportEnemies.droptables[si.DropTable] ?? [];
1649 if (si.DROP_MOD) {
1650 const modDroptable = droptables.find(x => x.type == "mod");
1651 if (modDroptable) {
1652 for (let i = 0; i != si.DROP_MOD.length; ++i) {
1653 const reward = getRandomReward(modDroptable.items)!;
1654 logger.debug(`stripped droptable (mods pool) rolled`, reward);
1655 await addItem(inventory, reward.type);
1656 MissionRewards.push({
1657 StoreItem: toStoreItem(reward.type),
1658 ItemCount: 1,
1659 FromEnemyCache: true // to show "identified"
1660 });
1661 }
1662 } else {
1663 logger.error(`unknown droptable ${si.DropTable} for DROP_MOD`);
1664 }
1665 }
1666 if (si.DROP_BLUEPRINT) {
1667 const blueprintDroptable = droptables.find(x => x.type == "blueprint");
1668 if (blueprintDroptable) {
1669 for (let i = 0; i != si.DROP_BLUEPRINT.length; ++i) {
1670 const reward = getRandomReward(blueprintDroptable.items)!;
1671 logger.debug(`stripped droptable (blueprints pool) rolled`, reward);
1672 await addItem(inventory, reward.type);
1673 MissionRewards.push({
1674 StoreItem: toStoreItem(reward.type),
1675 ItemCount: 1,
1676 FromEnemyCache: true // to show "identified"
1677 });
1678 }
1679 } else {
1680 logger.error(`unknown droptable ${si.DropTable} for DROP_BLUEPRINT`);
1681 }
1682 }
1683 // e.g. H-09 Apex Turret Sumdali
1684 if (si.DROP_MISC_ITEM) {
1685 const resourceDroptable = droptables.find(x => x.type == "resource");
1686 if (resourceDroptable) {
1687 for (let i = 0; i != si.DROP_MISC_ITEM.length; ++i) {
1688 const reward = getRandomReward(resourceDroptable.items)!;
1689 logger.debug(`stripped droptable (resources pool) rolled`, reward);
1690 if (Object.keys(await addItem(inventory, reward.type)).length == 0) {
1691 logger.debug(`item already owned, skipping`);
1692 } else {
1693 MissionRewards.push({
1694 StoreItem: toStoreItem(reward.type),
1695 ItemCount: 1,
1696 FromEnemyCache: true // to show "identified"
1697 });
1698 }
1699 }
1700 } else {
1701 logger.error(`unknown droptable ${si.DropTable} for DROP_MISC_ITEM`);
1702 }
1703 }
1704
1705 if (si.DropTable == "/Lotus/Types/DropTables/ContainerDropTables/VoidVaultMissionRewardsDropTable") {
1706 // Consume netracells search pulse; only when the container reward was picked up. Discussed in https://onlyg.it/OpenWF/SpaceNinjaServer/issues/2673
1707 updateEntratiVault(inventory);
1708 inventory.EntratiVaultCountLastPeriod! += 1;
1709 }
1710 }
1711 } else {
1712 logger.debug(`ignoring StrippedItems in intermediate inventory update, deferring until extraction`);
1713 }
1714 }
1715
1719 1716 return {
1720 1717 inventoryChanges,
1721 1718 MissionRewards,