item acquisition work
This commit is contained in:
		
							parent
							
								
									75ec43a54f
								
							
						
					
					
						commit
						6692e9261f
					
				| @ -1710,6 +1710,7 @@ Start moving character goal logic from behavior trees to macro level simulation | |||||||
| Goal macro data work | Goal macro data work | ||||||
| Shuffle where macro data is stored | Shuffle where macro data is stored | ||||||
| Structures are stored in character data as IDs into macro data now | Structures are stored in character data as IDs into macro data now | ||||||
|  | Item acquisition tree can be triggered by setting macro goal correctly | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -45,6 +45,11 @@ public class BlackboardKeys { | |||||||
|      */ |      */ | ||||||
|     public static final String BUILDING_MATERIAL_CURRENT = "buildingMaterialCurrent"; |     public static final String BUILDING_MATERIAL_CURRENT = "buildingMaterialCurrent"; | ||||||
| 
 | 
 | ||||||
|  |     /** | ||||||
|  |      * The type of item to try to acquire | ||||||
|  |      */ | ||||||
|  |     public static final String GOAL_ITEM_ACQUISITION_TARGET = "goalItemAcquisitionTarget"; | ||||||
|  | 
 | ||||||
|     /** |     /** | ||||||
|      * The type of item to scan the inventory for |      * The type of item to scan the inventory for | ||||||
|      */ |      */ | ||||||
|  | |||||||
| @ -46,7 +46,7 @@ public class BeginStructureNode implements AITreeNode { | |||||||
|             Vector3d placementPos = StructurePlacementUtils.getPlacementPosition(macroData, structureData, position); |             Vector3d placementPos = StructurePlacementUtils.getPlacementPosition(macroData, structureData, position); | ||||||
| 
 | 
 | ||||||
|             //add to macro data |             //add to macro data | ||||||
|             Structure struct = Structure.createStructure(structureData, placementPos); |             Structure struct = Structure.createStructure(macroData, structureData, placementPos); | ||||||
|             struct.setRepairable(true); |             struct.setRepairable(true); | ||||||
|             struct.setFab(BlockFab.read(FileUtils.getAssetFile(struct.getFabPath()))); |             struct.setFab(BlockFab.read(FileUtils.getAssetFile(struct.getFabPath()))); | ||||||
|             // macroData.getStructures().add(struct); |             // macroData.getStructures().add(struct); | ||||||
|  | |||||||
| @ -8,9 +8,11 @@ import electrosphere.entity.state.server.ServerCharacterData; | |||||||
| import electrosphere.server.ai.blackboard.Blackboard; | import electrosphere.server.ai.blackboard.Blackboard; | ||||||
| import electrosphere.server.ai.blackboard.BlackboardKeys; | import electrosphere.server.ai.blackboard.BlackboardKeys; | ||||||
| import electrosphere.server.ai.nodes.AITreeNode; | import electrosphere.server.ai.nodes.AITreeNode; | ||||||
|  | import electrosphere.server.ai.nodes.checks.spatial.BeginStructureNode; | ||||||
| import electrosphere.server.macro.character.Character; | import electrosphere.server.macro.character.Character; | ||||||
| import electrosphere.server.macro.character.goal.CharacterGoal; | import electrosphere.server.macro.character.goal.CharacterGoal; | ||||||
| import electrosphere.server.macro.character.goal.CharacterGoal.CharacterGoalType; | import electrosphere.server.macro.character.goal.CharacterGoal.CharacterGoalType; | ||||||
|  | import electrosphere.server.macro.structure.Structure; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Node for interacting with macro character goals |  * Node for interacting with macro character goals | ||||||
| @ -69,11 +71,19 @@ public class MacroCharacterGoalNode implements AITreeNode { | |||||||
|                 blackboard.put(BlackboardKeys.POINT_TARGET, targetPos); |                 blackboard.put(BlackboardKeys.POINT_TARGET, targetPos); | ||||||
|             } break; |             } break; | ||||||
|             case BUILD_STRUCTURE: { |             case BUILD_STRUCTURE: { | ||||||
|                 throw new Error("Not implemented yet"); |                 Object targetRaw = goal.getTarget(); | ||||||
|             } //break; |                 if(!(targetRaw instanceof Structure)){ | ||||||
|  |                     throw new Error("Target is not a structure " + targetRaw); | ||||||
|  |                 } | ||||||
|  |                 BeginStructureNode.setStructureTarget(blackboard, (Structure)goal.getTarget()); | ||||||
|  |             } break; | ||||||
|             case ACQUIRE_ITEM: { |             case ACQUIRE_ITEM: { | ||||||
|                 throw new Error("Not implemented yet"); |                 Object targetRaw = goal.getTarget(); | ||||||
|             } //break; |                 if(!(targetRaw instanceof String)){ | ||||||
|  |                     throw new Error("Target is not a string " + targetRaw); | ||||||
|  |                 } | ||||||
|  |                 blackboard.put(BlackboardKeys.GOAL_ITEM_ACQUISITION_TARGET, targetRaw); | ||||||
|  |             } break; | ||||||
|         } |         } | ||||||
|         if(type == goal.getType()){ |         if(type == goal.getType()){ | ||||||
|             return AITreeNodeResult.SUCCESS; |             return AITreeNodeResult.SUCCESS; | ||||||
|  | |||||||
| @ -53,7 +53,7 @@ public class CharacterGoalTree { | |||||||
|                     MacroCharacterGoalNode.create(CharacterGoalType.ACQUIRE_ITEM), |                     MacroCharacterGoalNode.create(CharacterGoalType.ACQUIRE_ITEM), | ||||||
|                     new PublishStatusNode("Acquire building material"), |                     new PublishStatusNode("Acquire building material"), | ||||||
|                     //try to find building materials |                     //try to find building materials | ||||||
|                     AcquireItemTree.create(BlackboardKeys.BUILDING_MATERIAL_CURRENT) |                     AcquireItemTree.create(BlackboardKeys.GOAL_ITEM_ACQUISITION_TARGET) | ||||||
|                 ) |                 ) | ||||||
|             ) |             ) | ||||||
|         ); |         ); | ||||||
|  | |||||||
| @ -55,7 +55,7 @@ public class BuildStructureTree { | |||||||
|                 ), |                 ), | ||||||
|                 //does not have building materials |                 //does not have building materials | ||||||
|                 new SequenceNode( |                 new SequenceNode( | ||||||
|                     new InverterNode(new SolveBuildMaterialNode()), |                     new InverterNode(new InventoryContainsNode(BlackboardKeys.BUILDING_MATERIAL_CURRENT)), | ||||||
|                     new RunnerNode(new PublishStatusNode("Waiting on macro character to set goal to find materials to build with")) |                     new RunnerNode(new PublishStatusNode("Waiting on macro character to set goal to find materials to build with")) | ||||||
|                 ), |                 ), | ||||||
|                 //has building materials AND we've already built the structure |                 //has building materials AND we've already built the structure | ||||||
|  | |||||||
| @ -1,12 +1,8 @@ | |||||||
| package electrosphere.server.macro.character.goal; | package electrosphere.server.macro.character.goal; | ||||||
| 
 | 
 | ||||||
| import org.joml.Vector3d; |  | ||||||
| 
 |  | ||||||
| import electrosphere.entity.Entity; |  | ||||||
| import electrosphere.server.macro.character.Character; | import electrosphere.server.macro.character.Character; | ||||||
| import electrosphere.server.macro.character.data.CharacterData; | import electrosphere.server.macro.character.data.CharacterData; | ||||||
| import electrosphere.server.macro.character.data.CharacterDataStrings; | import electrosphere.server.macro.character.data.CharacterDataStrings; | ||||||
| import electrosphere.server.macro.structure.Structure; |  | ||||||
| import electrosphere.util.annotation.Exclude; | import electrosphere.util.annotation.Exclude; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
| @ -38,28 +34,10 @@ public class CharacterGoal extends CharacterData { | |||||||
|     CharacterGoalType type; |     CharacterGoalType type; | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * The target structure |      * The target | ||||||
|      */ |      */ | ||||||
|     @Exclude |     @Exclude | ||||||
|     Structure structureTarget; |     Object target; | ||||||
| 
 |  | ||||||
|     /** |  | ||||||
|      * The entity to target |  | ||||||
|      */ |  | ||||||
|     @Exclude |  | ||||||
|     Entity entityTarget; |  | ||||||
| 
 |  | ||||||
|     /** |  | ||||||
|      * The id of some piece of data to target |  | ||||||
|      */ |  | ||||||
|     @Exclude |  | ||||||
|     String idTarget; |  | ||||||
| 
 |  | ||||||
|     /** |  | ||||||
|      * The point to target |  | ||||||
|      */ |  | ||||||
|     @Exclude |  | ||||||
|     Vector3d pointTarget; |  | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Constructor |      * Constructor | ||||||
| @ -94,17 +72,15 @@ public class CharacterGoal extends CharacterData { | |||||||
|      * @param target The target |      * @param target The target | ||||||
|      */ |      */ | ||||||
|     public void setTarget(Object target){ |     public void setTarget(Object target){ | ||||||
|         if(target instanceof Structure){ |         this.target = target; | ||||||
|             this.structureTarget = (Structure)target; |  | ||||||
|         } else if(target instanceof Entity){ |  | ||||||
|             this.entityTarget = (Entity)target; |  | ||||||
|         } else if(target instanceof String){ |  | ||||||
|             this.idTarget = (String)target; |  | ||||||
|         } else if(target instanceof Vector3d){ |  | ||||||
|             this.pointTarget = (Vector3d)target; |  | ||||||
|         } else { |  | ||||||
|             throw new Error("Trying to set target to unsupported type " + target); |  | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Gets the target of the goal | ||||||
|  |      * @return The target of the goal | ||||||
|  |      */ | ||||||
|  |     public Object getTarget(){ | ||||||
|  |         return this.target; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|  | |||||||
| @ -5,6 +5,7 @@ import org.joml.Vector3d; | |||||||
| 
 | 
 | ||||||
| import electrosphere.game.data.block.BlockFab; | import electrosphere.game.data.block.BlockFab; | ||||||
| import electrosphere.game.data.struct.StructureData; | import electrosphere.game.data.struct.StructureData; | ||||||
|  | import electrosphere.server.macro.MacroData; | ||||||
| import electrosphere.server.macro.spatial.MacroAreaObject; | import electrosphere.server.macro.spatial.MacroAreaObject; | ||||||
| import electrosphere.util.annotation.Exclude; | import electrosphere.util.annotation.Exclude; | ||||||
| 
 | 
 | ||||||
| @ -51,16 +52,18 @@ public class Structure implements MacroAreaObject { | |||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Creates a structure |      * Creates a structure | ||||||
|  |      * @param macroData The macro data | ||||||
|      * @param data The data |      * @param data The data | ||||||
|      * @param position The position |      * @param position The position | ||||||
|      * @return The structure |      * @return The structure | ||||||
|      */ |      */ | ||||||
|     public static Structure createStructure(StructureData data, Vector3d position){ |     public static Structure createStructure(MacroData macroData, StructureData data, Vector3d position){ | ||||||
|         Structure rVal = new Structure(); |         Structure rVal = new Structure(); | ||||||
|         rVal.fabPath = data.getFabPath(); |         rVal.fabPath = data.getFabPath(); | ||||||
|         rVal.type = data.getId(); |         rVal.type = data.getId(); | ||||||
|         rVal.position = position; |         rVal.position = position; | ||||||
|         rVal.aabb = new AABBd(new Vector3d(position), new Vector3d(position).add(data.getDimensions())); |         rVal.aabb = new AABBd(new Vector3d(position), new Vector3d(position).add(data.getDimensions())); | ||||||
|  |         macroData.addStructure(rVal); | ||||||
|         return rVal; |         return rVal; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -92,7 +92,7 @@ public class MacroSimulation { | |||||||
|             Vector3d placementPos = StructurePlacementUtils.getPlacementPosition(macroData, structureData, position); |             Vector3d placementPos = StructurePlacementUtils.getPlacementPosition(macroData, structureData, position); | ||||||
| 
 | 
 | ||||||
|             //add to macro data |             //add to macro data | ||||||
|             Structure struct = Structure.createStructure(structureData, placementPos); |             Structure struct = Structure.createStructure(macroData, structureData, placementPos); | ||||||
|             struct.setRepairable(true); |             struct.setRepairable(true); | ||||||
|             struct.setFab(BlockFab.read(FileUtils.getAssetFile(struct.getFabPath()))); |             struct.setFab(BlockFab.read(FileUtils.getAssetFile(struct.getFabPath()))); | ||||||
|             CharacterUtils.addShelter(chara, struct); |             CharacterUtils.addShelter(chara, struct); | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user