Search in sources :

Example 6 with GamePlayStatsComponent

use of org.terasology.telemetry.GamePlayStatsComponent in project Terasology by MovingBlocks.

the class EntityDestructionAuthoritySystem method recordDestroyed.

private void recordDestroyed(DestroyEvent event, EntityRef entityRef) {
    EntityRef instigator = event.getInstigator();
    if (instigator != null) {
        if (entityRef.hasComponent(BlockComponent.class)) {
            BlockComponent blockComponent = entityRef.getComponent(BlockComponent.class);
            String blockName = blockComponent.getBlock().getDisplayName();
            if (instigator.hasComponent(GamePlayStatsComponent.class)) {
                GamePlayStatsComponent gamePlayStatsComponent = instigator.getComponent(GamePlayStatsComponent.class);
                Map<String, Integer> blockDestroyedMap = gamePlayStatsComponent.blockDestroyedMap;
                if (blockDestroyedMap.containsKey(blockName)) {
                    blockDestroyedMap.put(blockName, blockDestroyedMap.get(blockName) + 1);
                } else {
                    blockDestroyedMap.put(blockName, 1);
                }
                instigator.saveComponent(gamePlayStatsComponent);
            } else {
                GamePlayStatsComponent gamePlayStatsComponent = new GamePlayStatsComponent();
                Map<String, Integer> blockDestroyedMap = gamePlayStatsComponent.blockDestroyedMap;
                blockDestroyedMap.put(blockName, 1);
                instigator.addOrSaveComponent(gamePlayStatsComponent);
            }
        } else if (entityRef.hasComponent(CharacterComponent.class)) {
            String creatureName = entityRef.getParentPrefab().getName();
            if (instigator.hasComponent(GamePlayStatsComponent.class)) {
                GamePlayStatsComponent gamePlayStatsComponent = instigator.getComponent(GamePlayStatsComponent.class);
                Map<String, Integer> creatureKilled = gamePlayStatsComponent.creatureKilled;
                if (creatureKilled.containsKey(creatureName)) {
                    creatureKilled.put(creatureName, creatureKilled.get(creatureName) + 1);
                } else {
                    creatureKilled.put(creatureName, 1);
                }
                instigator.saveComponent(gamePlayStatsComponent);
            } else {
                GamePlayStatsComponent gamePlayStatsComponent = new GamePlayStatsComponent();
                Map<String, Integer> creatureKilled = gamePlayStatsComponent.creatureKilled;
                creatureKilled.put(creatureName, 1);
                instigator.addOrSaveComponent(gamePlayStatsComponent);
            }
        }
    }
}
Also used : BlockComponent(org.terasology.world.block.BlockComponent) GamePlayStatsComponent(org.terasology.telemetry.GamePlayStatsComponent) CharacterComponent(org.terasology.logic.characters.CharacterComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) Map(java.util.Map)

Aggregations

EntityRef (org.terasology.entitySystem.entity.EntityRef)6 GamePlayStatsComponent (org.terasology.telemetry.GamePlayStatsComponent)6 LocalPlayer (org.terasology.logic.players.LocalPlayer)4 Map (java.util.Map)1 CharacterComponent (org.terasology.logic.characters.CharacterComponent)1 BlockComponent (org.terasology.world.block.BlockComponent)1