Skip to content

Commit

Permalink
Merge branch 'development' into improve/cancel-mail
Browse files Browse the repository at this point in the history
  • Loading branch information
ipdae authored Oct 2, 2024
2 parents 8ee74ca + 84926d5 commit 897c093
Show file tree
Hide file tree
Showing 19 changed files with 206 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,14 @@ public CustomEquipmentCraftTest()
10, null, 8,
};

// First craft in relationship group
// Move to next group with additional cost
yield return new object?[]
{
new List<CustomCraftData>
{
new () { RecipeId = 1, SlotIndex = 0, IconId = 10111000, },
},
true, 11, false,
true, 10, false,
new List<TestResult>
{
new ()
Expand All @@ -156,15 +156,15 @@ public CustomEquipmentCraftTest()
ElementalType = ElementalType.Wind,
},
},
12, null,
10, null,
};
yield return new object?[]
{
new List<CustomCraftData>
{
new () { RecipeId = 1, SlotIndex = 0, IconId = 10111000, },
},
true, 101, false,
true, 100, false,
new List<TestResult>
{
new ()
Expand All @@ -175,15 +175,15 @@ public CustomEquipmentCraftTest()
ElementalType = ElementalType.Wind,
},
},
15, null,
12, null,
};
yield return new object?[]
{
new List<CustomCraftData>
{
new () { RecipeId = 1, SlotIndex = 0, IconId = 10111000, },
},
true, 1001, false,
true, 1000, false,
new List<TestResult>
{
new ()
Expand All @@ -194,7 +194,7 @@ public CustomEquipmentCraftTest()
ElementalType = ElementalType.Wind,
},
},
20, null,
15, null,
};

// Multiple slots
Expand Down Expand Up @@ -340,7 +340,7 @@ public CustomEquipmentCraftTest()

[Theory]
[MemberData(nameof(GetTestData_Success))]
// [MemberData(nameof(GetTestData_Failure))]
[MemberData(nameof(GetTestData_Failure))]
public void Execute(
List<CustomCraftData> craftList,
bool enoughMaterials,
Expand Down Expand Up @@ -398,18 +398,20 @@ public void Execute(

_avatarState.inventory.AddItem(circle, (int)Math.Floor(circleAmount));

if (relationshipRow.Relationship == initialRelationship)
var nextRow = relationshipSheet.Values.FirstOrDefault(row =>
row.Relationship == initialRelationship + 1);
if (nextRow is not null)
{
if (relationshipRow.GoldAmount > 0)
if (nextRow.GoldAmount > 0)
{
state = state.MintAsset(
context,
_agentAddress,
state.GetGoldCurrency() * relationshipRow.GoldAmount
state.GetGoldCurrency() * nextRow.GoldAmount
);
}

foreach (var cost in relationshipRow.MaterialCosts)
foreach (var cost in nextRow.MaterialCosts)
{
var row = materialSheet[cost.ItemId];
_avatarState.inventory.AddItem(
Expand Down Expand Up @@ -443,7 +445,7 @@ public void Execute(
);
}

var action = new Nekoyume.Action.CustomEquipmentCraft.CustomEquipmentCraft
var action = new CustomEquipmentCraft
{
AvatarAddress = _avatarAddress,
CraftList = craftList,
Expand Down Expand Up @@ -500,7 +502,7 @@ public void Execute(
.First(row => row.Id == craftData.RecipeId).ItemSubType;
var expectedEquipmentId =
_tableSheets.CustomEquipmentCraftRelationshipSheet.OrderedList!
.First(row => row.Relationship >= initialRelationship)
.Last(row => row.Relationship <= initialRelationship)
.GetItemId(itemSubType);
var equipment = inventory.Equipments.First(e =>
e.ItemId == slotState.Result.itemUsable.ItemId);
Expand Down
40 changes: 36 additions & 4 deletions .github/workflows/publish-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ name: publish docs

on:
push:
branches:
- main
branches-ignore:
- v*
tags-ignore:
- v*

jobs:
publish-docs:
Expand All @@ -17,18 +19,48 @@ jobs:
uses: actions/checkout@v4
with:
submodules: recursive
fetch-tags: true
- name: Dotnet Setup
uses: actions/setup-dotnet@v4
with:
dotnet-version: 6.0.400

- run: dotnet restore
- run: dotnet tool restore
- run: docfx docs/docfx.json
- run: dotnet docfx docs/docfx.json

- name: update index.html
run: |
set -ev
if [[ "${{ github.ref_name }}" =~ ^v ]]; then
echo "Prevent tags started with 'v'" >&2
exit
fi
mkdir -p /tmp/gh-pages-root
latest_version=$(git tag --sort -v:refname | grep -E -i '^[0-9]+\.[0-9]+\.[0-9]+' | head -n 1)
if [[ "$latest_version" = "${{ github.ref_name }}" ]]; then
index=$(cat docs/_site/index.html)
{
echo -n "${index%</title>*}</title>"
echo "<meta http-equiv=\"refresh\" content=\"0;${{ github.ref_name }}/\">"
echo "<base href=\"${{ github.ref_name }}/\">"
echo -n "${index#*</title>}"
} > /tmp/gh-pages-root/index.html
fi
if: github.ref_type == 'tag'
- name: deploy
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/_site/
destination_dir: docs
destination_dir: ${{ github.ref_name }}
- name: deploy (index.html)
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: /tmp/gh-pages-root
destination_dir: .
keep_files: true
if: github.ref_type == 'tag'
6 changes: 6 additions & 0 deletions Lib9c.DevExtensions/Action/Craft/UnlockCraftAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ public override IWorld Execute(IActionContext context)
}

var avatarState = states.GetAvatarState(AvatarAddress);
if (avatarState is null || !avatarState.agentAddress.Equals(context.Signer))
{
var addressesHex = GetSignerAndOtherAddressesHex(context, AvatarAddress);
throw new FailedLoadStateException($"{addressesHex}Aborted as the avatar state of the signer was failed to load.");
}

avatarState.worldInformation = new WorldInformation(
context.BlockIndex,
states.GetSheet<WorldSheet>(),
Expand Down
5 changes: 5 additions & 0 deletions Lib9c.DevExtensions/Action/Stage/ClearStage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public override IWorld Execute(IActionContext context)
context.UseGas(1);
var states = context.PreviousState;
var avatarState = states.GetAvatarState(AvatarAddress);
if (avatarState is null || !avatarState.agentAddress.Equals(context.Signer))
{
var addressesHex = GetSignerAndOtherAddressesHex(context, AvatarAddress);
throw new FailedLoadStateException($"{addressesHex}Aborted as the avatar state of the signer was failed to load.");
}
avatarState.worldInformation = new WorldInformation(
context.BlockIndex,
states.GetSheet<WorldSheet>(),
Expand Down
4 changes: 2 additions & 2 deletions Lib9c/Action/AdventureBoss/SweepAdventureBoss.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ public override IWorld Execute(IActionContext context)
}

var avatarState = states.GetAvatarState(AvatarAddress);
if (avatarState.agentAddress != context.Signer)
if (avatarState is null || !avatarState.agentAddress.Equals(context.Signer))
{
throw new InvalidAddressException();
throw new FailedLoadStateException($"{addressesHex}Aborted as the avatar state of the signer was failed to load.");
}

var exploreBoard = states.GetExploreBoard(Season);
Expand Down
9 changes: 8 additions & 1 deletion Lib9c/Action/AdventureBoss/UnlockFloor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,14 @@ public override IWorld Execute(IActionContext context)

// Check balance and unlock
var price = costSheet[floorId];
var agentAddress = states.GetAvatarState(AvatarAddress).agentAddress;
var avatarState = states.GetAvatarState(AvatarAddress);
if (avatarState is null || !avatarState.agentAddress.Equals(context.Signer))
{
var addressesHex = GetSignerAndOtherAddressesHex(context, AvatarAddress);
throw new FailedLoadStateException($"{addressesHex}Aborted as the avatar state of the signer was failed to load.");
}

var agentAddress = avatarState.agentAddress;
var balance = states.GetBalance(agentAddress, currency);
var exploreBoard = states.GetExploreBoard(Season);
if (UseNcg)
Expand Down
13 changes: 10 additions & 3 deletions Lib9c/Action/AdventureBoss/Wanted.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,15 @@ public override IWorld Execute(IActionContext context)
}

var requiredStakingAmount = stakeRegularRewardSheet[requiredStakingLevel].RequiredGold;
var stakedAmount =
states.GetStakedAmount(states.GetAvatarState(AvatarAddress).agentAddress);

var avatarState = states.GetAvatarState(AvatarAddress);
if (avatarState is null || !avatarState.agentAddress.Equals(context.Signer))
{
var addressesHex = GetSignerAndOtherAddressesHex(context, AvatarAddress);
throw new FailedLoadStateException($"{addressesHex}Aborted as the avatar state of the signer was failed to load.");
}

var stakedAmount = states.GetStakedAmount(avatarState.agentAddress);
if (stakedAmount < requiredStakingAmount * currency)
{
throw new InsufficientStakingException(
Expand Down Expand Up @@ -168,7 +175,7 @@ public override IWorld Execute(IActionContext context)
states = states.TransferAsset(context, context.Signer,
Addresses.BountyBoard.Derive(AdventureBossHelper.GetSeasonAsAddressForm(Season)),
Bounty);
bountyBoard.AddOrUpdate(AvatarAddress, states.GetAvatarState(AvatarAddress).name,
bountyBoard.AddOrUpdate(AvatarAddress, avatarState.name,
Bounty);
return states.SetBountyBoard(Season, bountyBoard);
}
Expand Down
3 changes: 1 addition & 2 deletions Lib9c/Action/CreateAvatar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ public override IWorld Execute(IActionContext context)
var avatarState = states.GetAvatarState(avatarAddress);
if (avatarState is not null)
{
throw new InvalidAddressException(
$"{addressesHex}Aborted as there is already an avatar at {avatarAddress}.");
throw new InvalidAddressException($"{addressesHex}Aborted as there is already an avatar at {avatarAddress}.");
}

if (!(0 <= index && index < GameConfig.SlotCount))
Expand Down
25 changes: 23 additions & 2 deletions Lib9c/Action/CustomEquipmentCraft/CustomEquipmentCraft.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,9 @@ public override IWorld Execute(IActionContext context)
// ~Validate RecipeId

// Validate Recipe ResultEquipmentId
var relationshipRow = sheets.GetSheet<CustomEquipmentCraftRelationshipSheet>()
.OrderedList.Last(row => row.Relationship <= relationship);
var relationshipSheet = sheets.GetSheet<CustomEquipmentCraftRelationshipSheet>();
var relationshipRow =
relationshipSheet.OrderedList.Last(row => row.Relationship <= relationship);
var equipmentItemId = relationshipRow.GetItemId(recipeRow.ItemSubType);
var equipmentItemSheet = sheets.GetSheet<EquipmentItemSheet>();
if (!equipmentItemSheet.TryGetValue(equipmentItemId, out var equipmentRow))
Expand All @@ -169,6 +170,26 @@ public override IWorld Execute(IActionContext context)
relationshipRow,
states.GetGameConfigState().CustomEquipmentCraftIconCostMultiplier
);

// Calculate additional costs to move to next group
var additionalCost =
CustomCraftHelper.CalculateAdditionalCost(relationship, relationshipSheet);
if (additionalCost is not null)
{
ncgCost += additionalCost.Value.Item1;
foreach (var cost in additionalCost.Value.Item2)
{
if (materialCosts.ContainsKey(cost.Key))
{
materialCosts[cost.Key] += cost.Value;
}
else
{
materialCosts[cost.Key] = cost.Value;
}
}
}

if (ncgCost > 0)
{
var arenaData = sheets.GetSheet<ArenaSheet>()
Expand Down
Loading

0 comments on commit 897c093

Please sign in to comment.