Skip to content

Commit

Permalink
Added defined cost to spells
Browse files Browse the repository at this point in the history
  • Loading branch information
david-buderus committed May 30, 2024
1 parent 5084360 commit 07a1569
Show file tree
Hide file tree
Showing 28 changed files with 439 additions and 342 deletions.
91 changes: 54 additions & 37 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -3653,14 +3653,14 @@
}
]
},
"CharacterResourceRecipeEntry": {
"CharacterResourceUsage": {
"required": [
"resource"
],
"type": "object",
"allOf": [
{
"$ref": "#/components/schemas/IRecipeEntryObject"
"$ref": "#/components/schemas/IResourceUsageObject"
},
{
"type": "object",
Expand Down Expand Up @@ -3694,13 +3694,13 @@
"items": {
"oneOf": [
{
"$ref": "#/components/schemas/CharacterResourceRecipeEntry"
"$ref": "#/components/schemas/CharacterResourceUsage"
},
{
"$ref": "#/components/schemas/ItemRecipeEntry"
"$ref": "#/components/schemas/ItemUsage"
},
{
"$ref": "#/components/schemas/MaterialRecipeEntry"
"$ref": "#/components/schemas/MaterialUsage"
}
]
}
Expand All @@ -3709,7 +3709,7 @@
"type": "string"
},
"product": {
"$ref": "#/components/schemas/ItemRecipeEntry"
"$ref": "#/components/schemas/ItemUsage"
},
"profession": {
"type": "string"
Expand All @@ -3718,7 +3718,7 @@
"type": "string"
},
"sideProduct": {
"$ref": "#/components/schemas/ItemRecipeEntry"
"$ref": "#/components/schemas/ItemUsage"
}
}
},
Expand Down Expand Up @@ -3838,7 +3838,7 @@
"IGrantedAuthorityDTO": {
"type": "object"
},
"IRecipeEntryObject": {
"IResourceUsageObject": {
"type": "object"
},
"Item": {
Expand Down Expand Up @@ -3903,29 +3903,6 @@
}
}
},
"ItemRecipeEntry": {
"required": [
"resource"
],
"type": "object",
"allOf": [
{
"$ref": "#/components/schemas/IRecipeEntryObject"
},
{
"type": "object",
"properties": {
"amount": {
"type": "number",
"format": "float"
},
"resource": {
"$ref": "#/components/schemas/Item"
}
}
}
]
},
"ItemType": {
"required": [
"name",
Expand Down Expand Up @@ -3976,6 +3953,29 @@
}
}
},
"ItemUsage": {
"required": [
"resource"
],
"type": "object",
"allOf": [
{
"$ref": "#/components/schemas/IResourceUsageObject"
},
{
"type": "object",
"properties": {
"amount": {
"type": "number",
"format": "float"
},
"resource": {
"$ref": "#/components/schemas/Item"
}
}
}
]
},
"Jewellery": {
"required": [
"description",
Expand Down Expand Up @@ -4048,14 +4048,14 @@
}
}
},
"MaterialRecipeEntry": {
"MaterialUsage": {
"required": [
"resource"
],
"type": "object",
"allOf": [
{
"$ref": "#/components/schemas/IRecipeEntryObject"
"$ref": "#/components/schemas/IResourceUsageObject"
},
{
"type": "object",
Expand Down Expand Up @@ -4313,6 +4313,7 @@
},
"Spell": {
"required": [
"additionalCost",
"castTime",
"cost",
"effect",
Expand All @@ -4322,11 +4323,27 @@
],
"type": "object",
"properties": {
"additionalCost": {
"type": "string"
},
"castTime": {
"type": "string"
},
"cost": {
"type": "string"
"type": "array",
"items": {
"oneOf": [
{
"$ref": "#/components/schemas/CharacterResourceUsage"
},
{
"$ref": "#/components/schemas/ItemUsage"
},
{
"$ref": "#/components/schemas/MaterialUsage"
}
]
}
},
"effect": {
"type": "string"
Expand Down Expand Up @@ -4514,13 +4531,13 @@
"items": {
"oneOf": [
{
"$ref": "#/components/schemas/CharacterResourceRecipeEntry"
"$ref": "#/components/schemas/CharacterResourceUsage"
},
{
"$ref": "#/components/schemas/ItemRecipeEntry"
"$ref": "#/components/schemas/ItemUsage"
},
{
"$ref": "#/components/schemas/MaterialRecipeEntry"
"$ref": "#/components/schemas/MaterialUsage"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package de.pnp.manager.component;

import de.pnp.manager.component.IRecipeEntry.ItemRecipeEntry;
import de.pnp.manager.component.IResourceUsage.ItemUsage;
import de.pnp.manager.server.database.CraftingRecipeRepository;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
Expand Down Expand Up @@ -40,24 +40,24 @@ public class CraftingRecipe extends DatabaseObject {
*/
@NotNull
@Valid
private final ItemRecipeEntry product;
private final IResourceUsage.ItemUsage product;

/**
* The side-product of this {@link CraftingRecipe}
*/
@Nullable
@Valid
private final ItemRecipeEntry sideProduct;
private final IResourceUsage.ItemUsage sideProduct;

/**
* The materials needed to use this {@link CraftingRecipe}
*/
@NotEmpty
private final Collection<@Valid IRecipeEntry<?>> materials;
private final Collection<@Valid IResourceUsage<?>> materials;

public CraftingRecipe(ObjectId id, String profession, String requirement,
String otherCircumstances, ItemRecipeEntry product, @Nullable ItemRecipeEntry sideProduct,
Collection<IRecipeEntry<?>> materials) {
String otherCircumstances, ItemUsage product, @Nullable IResourceUsage.ItemUsage sideProduct,
Collection<IResourceUsage<?>> materials) {
super(id);
this.profession = profession;
this.requirement = requirement;
Expand All @@ -80,16 +80,16 @@ public String getOtherCircumstances() {
return otherCircumstances;
}

public ItemRecipeEntry getProduct() {
public ItemUsage getProduct() {
return product;
}

@Nullable
public ItemRecipeEntry getSideProduct() {
public IResourceUsage.ItemUsage getSideProduct() {
return sideProduct;
}

public Collection<IRecipeEntry<?>> getMaterials() {
public Collection<IResourceUsage<?>> getMaterials() {
return materials;
}

Expand Down
59 changes: 0 additions & 59 deletions server/src/main/java/de/pnp/manager/component/IRecipeEntry.java

This file was deleted.

62 changes: 62 additions & 0 deletions server/src/main/java/de/pnp/manager/component/IResourceUsage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package de.pnp.manager.component;

import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import de.pnp.manager.component.IResourceUsage.CharacterResourceUsage;
import de.pnp.manager.component.IResourceUsage.ItemUsage;
import de.pnp.manager.component.IResourceUsage.MaterialUsage;
import de.pnp.manager.component.attributes.SecondaryAttribute;
import de.pnp.manager.component.item.Item;
import de.pnp.manager.component.item.Material;
import de.pnp.manager.component.upgrade.UpgradeRecipe;
import de.pnp.manager.validation.IsConsumable;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;
import org.springframework.data.mongodb.core.mapping.DBRef;

/**
* The product or an entry in the material list of a {@link CraftingRecipe} or an {@link UpgradeRecipe}.
*/
@JsonSubTypes({
@JsonSubTypes.Type(value = ItemUsage.class, name = "ItemUsage"),
@JsonSubTypes.Type(value = MaterialUsage.class, name = "MaterialUsage"),
@JsonSubTypes.Type(value = CharacterResourceUsage.class, name = "CharacterResourceUsage")
})
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME)
public sealed interface IResourceUsage<T> {

/**
* The amount needed for this {@link IResourceUsage}.
*/
float amount();

/**
* The resource needed for this {@link IResourceUsage}.
*/
T resource();

/**
* An {@link IResourceUsage} which uses a specific {@link Item}.
*/
record ItemUsage(@Positive float amount, @DBRef @NotNull Item resource) implements
IResourceUsage<Item> {

}

/**
* An {@link IResourceUsage} which uses a {@link Material}.
*/
record MaterialUsage(@Positive float amount, @DBRef @NotNull Material resource) implements
IResourceUsage<Material> {

}

/**
* An {@link IResourceUsage} which uses a {@link SecondaryAttribute} of a player.
*/
record CharacterResourceUsage(@Positive float amount,
@DBRef @NotNull @IsConsumable SecondaryAttribute resource) implements
IResourceUsage<SecondaryAttribute> {

}
}
Loading

0 comments on commit 07a1569

Please sign in to comment.