Add support for the diminished state.
This commit is contained in:
parent
1fe75062b7
commit
d8ce46fe43
20 changed files with 337 additions and 155 deletions
|
|
@ -103,41 +103,77 @@ class CampaignService(
|
|||
|
||||
// Data manipulation through WebSocket.
|
||||
|
||||
suspend fun updateCharacterCharacteristic(
|
||||
suspend fun updateCharacteristic(
|
||||
characterInstanceId: Campaign.CharacterInstance.Id,
|
||||
characteristic: Campaign.CharacterInstance.Characteristic,
|
||||
value: Int,
|
||||
) {
|
||||
// fetch all the current campaign character
|
||||
val characters = campaign.characters.toMutableMap()
|
||||
// update the corresponding character using the use case.
|
||||
characters[characterInstanceId] = useCase.updateCharacteristic(
|
||||
character = campaign.character(id = characterInstanceId),
|
||||
characteristic = characteristic,
|
||||
value = value,
|
||||
)
|
||||
// save the campaign to the disk + update the flow.
|
||||
store.save(
|
||||
campaign = campaign.copy(characters = characters)
|
||||
)
|
||||
when {
|
||||
campaign.characters.containsKey(characterInstanceId) -> {
|
||||
// fetch all the current campaign character
|
||||
val characters = campaign.characters.toMutableMap()
|
||||
// update the corresponding character using the use case.
|
||||
characters[characterInstanceId] = useCase.updateCharacteristic(
|
||||
instance = campaign.character(id = characterInstanceId),
|
||||
characteristic = characteristic,
|
||||
value = value,
|
||||
)
|
||||
// save the campaign to the disk + update the flow.
|
||||
store.save(
|
||||
campaign = campaign.copy(characters = characters)
|
||||
)
|
||||
}
|
||||
|
||||
campaign.npcs.containsKey(characterInstanceId) -> {
|
||||
// fetch all the current campaign character
|
||||
val npcs = campaign.npcs.toMutableMap()
|
||||
// update the corresponding character using the use case.
|
||||
npcs[characterInstanceId] = useCase.updateCharacteristic(
|
||||
instance = campaign.npc(id = characterInstanceId),
|
||||
characteristic = characteristic,
|
||||
value = value,
|
||||
)
|
||||
// save the campaign to the disk + update the flow.
|
||||
store.save(
|
||||
campaign = campaign.copy(npcs = npcs)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun updateNpcCharacteristic(
|
||||
npcInstanceId: Campaign.CharacterInstance.Id,
|
||||
characteristic: Campaign.CharacterInstance.Characteristic,
|
||||
value: Int,
|
||||
suspend fun updateDiminished(
|
||||
characterInstanceId: Campaign.CharacterInstance.Id,
|
||||
diminished: Int,
|
||||
) {
|
||||
// fetch all the current campaign character
|
||||
val npcs = campaign.npcs.toMutableMap()
|
||||
// update the corresponding character using the use case.
|
||||
npcs[npcInstanceId] = useCase.updateCharacteristic(
|
||||
character = campaign.npc(id = npcInstanceId),
|
||||
characteristic = characteristic,
|
||||
value = value,
|
||||
)
|
||||
// save the campaign to the disk + update the flow.
|
||||
store.save(
|
||||
campaign = campaign.copy(npcs = npcs)
|
||||
)
|
||||
when {
|
||||
campaign.characters.containsKey(characterInstanceId) -> {
|
||||
// fetch all the current campaign character
|
||||
val characters = campaign.characters.toMutableMap()
|
||||
// update the corresponding character using the use case.
|
||||
characters[characterInstanceId] = useCase.updateDiminished(
|
||||
instance = campaign.character(id = characterInstanceId),
|
||||
diminished = diminished,
|
||||
)
|
||||
// save the campaign to the disk + update the flow.
|
||||
store.save(
|
||||
campaign = campaign.copy(characters = characters)
|
||||
)
|
||||
}
|
||||
|
||||
campaign.npcs.containsKey(characterInstanceId) -> {
|
||||
// fetch all the current campaign character
|
||||
val npcs = campaign.npcs.toMutableMap()
|
||||
// update the corresponding character using the use case.
|
||||
npcs[characterInstanceId] = useCase.updateDiminished(
|
||||
instance = campaign.npc(id = characterInstanceId),
|
||||
diminished = diminished,
|
||||
)
|
||||
// save the campaign to the disk + update the flow.
|
||||
store.save(
|
||||
campaign = campaign.copy(npcs = npcs)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -10,7 +10,6 @@ import kotlinx.coroutines.Job
|
|||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.json.Json
|
||||
import java.io.File
|
||||
|
||||
|
|
@ -18,7 +17,6 @@ class CampaignStore(
|
|||
private val factory: CampaignJsonFactory,
|
||||
private val json: Json,
|
||||
) {
|
||||
|
||||
private val flow = MutableStateFlow(value = Campaign.EMPTY)
|
||||
|
||||
init {
|
||||
|
|
|
|||
|
|
@ -3,11 +3,12 @@ package com.pixelized.server.lwa.server
|
|||
import com.pixelized.server.lwa.model.alteration.AlterationService
|
||||
import com.pixelized.server.lwa.model.campaign.CampaignService
|
||||
import com.pixelized.server.lwa.model.character.CharacterSheetService
|
||||
import com.pixelized.shared.lwa.model.campaign.Campaign
|
||||
import com.pixelized.shared.lwa.model.campaign.CampaignJsonFactory
|
||||
import com.pixelized.shared.lwa.protocol.websocket.Message
|
||||
import com.pixelized.shared.lwa.protocol.websocket.payload.CampaignMessage
|
||||
import com.pixelized.shared.lwa.protocol.websocket.payload.RestSynchronisation
|
||||
import com.pixelized.shared.lwa.protocol.websocket.payload.RollMessage
|
||||
import com.pixelized.shared.lwa.protocol.websocket.payload.UpdatePlayerCharacteristicMessage
|
||||
import com.pixelized.shared.lwa.protocol.websocket.payload.UpdateSkillUsageMessage
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
|
||||
|
|
@ -24,12 +25,23 @@ class Engine(
|
|||
|
||||
is RollMessage -> Unit // Nothing to do here.
|
||||
|
||||
is UpdatePlayerCharacteristicMessage -> {
|
||||
campaignService.updateCharacterCharacteristic(
|
||||
characterInstanceId = campaignJsonFactory.convertFromV1(characterInstanceIdJson = data.characterInstanceId),
|
||||
characteristic = campaignJsonFactory.convertFromV1(characteristicJson = data.characteristic),
|
||||
value = data.value,
|
||||
is CampaignMessage -> {
|
||||
val instanceId = Campaign.CharacterInstance.Id(
|
||||
characterSheetId = data.characterSheetId,
|
||||
instanceId = data.instanceId,
|
||||
)
|
||||
when (data) {
|
||||
is CampaignMessage.UpdateCharacteristic -> campaignService.updateCharacteristic(
|
||||
characterInstanceId = instanceId,
|
||||
characteristic = campaignJsonFactory.convertFromV1(characteristicJson = data.characteristic),
|
||||
value = data.value,
|
||||
)
|
||||
|
||||
is CampaignMessage.UpdateDiminished -> campaignService.updateDiminished(
|
||||
characterInstanceId = instanceId,
|
||||
diminished = data.diminished,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
is UpdateSkillUsageMessage -> characterService.updateCharacterSkillUsage(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue