repairability validation check
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit

This commit is contained in:
austin 2025-05-11 13:38:20 -04:00
parent 76dcc4540e
commit fa4fd1e106
4 changed files with 51 additions and 4 deletions

View File

@ -1722,6 +1722,7 @@ Character data tracks associated player id
Player characters not simulated at macro level
Macro simulation inventory utilities
Build structure goal properly working from macro sim
Repairability check when repairing structure

View File

@ -68,6 +68,11 @@ public class CharacterDataSerializer implements JsonDeserializer<CharacterData>,
return context.serialize((CharacterAssociatedId)src);
}
//a structure
case CharacterDataStrings.SHELTER: {
return context.serialize((CharacterAssociatedId)src);
}
//a town
case CharacterDataStrings.TOWN: {
return context.serialize((Town)src);

View File

@ -106,4 +106,41 @@ public class StructureRepairUtils {
}
}
/**
* Validates the repairability status of the structure
* @param realm The realm the structure is within
* @param struct The structure
* @return true if the structure is actaully repairable, false otherwise
*/
public static boolean validateRepairable(Realm realm, Structure struct){
//error checking
if(!(realm.getDataCellManager() instanceof GriddedDataCellManager)){
throw new Error("Realm is not a gridded realm!");
}
BlockFab fab = struct.getFab();
Vector3d structStartPos = struct.getStartPos();
GriddedDataCellManager griddedDataCellManager = (GriddedDataCellManager)realm.getDataCellManager();
for(int x = 0; x < fab.getDimensions().x; x++){
for(int y = 0; y < fab.getDimensions().y; y++){
for(int z = 0; z < fab.getDimensions().z; z++){
Vector3d offsetPos = new Vector3d(structStartPos).add(
x * BlockChunkData.BLOCK_SIZE_MULTIPLIER,
y * BlockChunkData.BLOCK_SIZE_MULTIPLIER,
z * BlockChunkData.BLOCK_SIZE_MULTIPLIER
);
Vector3i chunkPos = ServerWorldData.convertRealToChunkSpace(offsetPos);
Vector3i blockPos = ServerWorldData.convertRealToLocalBlockSpace(offsetPos);
BlockChunkData blockChunkData = griddedDataCellManager.getBlocksAtPosition(chunkPos);
short existingBlockType = blockChunkData.getType(blockPos.x, blockPos.y, blockPos.z);
short desiredType = fab.getType(x, y, z);
if(existingBlockType != desiredType){
return true;
}
}
}
}
return false;
}
}

View File

@ -84,11 +84,15 @@ public class MacroSimulation {
if(CharacterUtils.getShelter(macroData,chara) != null){
Structure shelter = CharacterUtils.getShelter(macroData,chara);
if(shelter.isRepairable()){
String repairMat = StructureRepairUtils.getNextRepairMat(realm, shelter);
if(CharaInventoryUtils.containsItem(chara, repairMat)){
CharacterGoal.setCharacterGoal(chara, new CharacterGoal(CharacterGoalType.BUILD_STRUCTURE, shelter));
if(StructureRepairUtils.validateRepairable(realm, shelter)){
String repairMat = StructureRepairUtils.getNextRepairMat(realm, shelter);
if(CharaInventoryUtils.containsItem(chara, repairMat)){
CharacterGoal.setCharacterGoal(chara, new CharacterGoal(CharacterGoalType.BUILD_STRUCTURE, shelter));
} else {
CharacterGoal.setCharacterGoal(chara, new CharacterGoal(CharacterGoalType.ACQUIRE_ITEM, repairMat));
}
} else {
CharacterGoal.setCharacterGoal(chara, new CharacterGoal(CharacterGoalType.ACQUIRE_ITEM, repairMat));
shelter.setRepairable(false);
}
}
// Vector2i charPos = CharacterUtils.getDiscretePosition(chara);