Overview

A CounterManager is attached to each player. It keeps track of all stats being tracked for that player.

For my visual learners:

---
config:
  layout: dagre
  look: neo
---
flowchart TB
    n1["Cancelled?"] -- No --> n3["Increase the Count for the stat/pokemon"]
    n4["Filled Circle"] --> n6["record
  (pokemon, counterType)"]
    n6 --> n7["Check for form override"]
    n7 --> n8(["Fire RECORD_PRE event"])
    n8 --> n1
    n3 --> n9["Streak would break?"]
    n9 -- Yes --> n10["breakStreak(counterType, finalSpeciesId, finalFormName, pokemon)"]
    n9 -- No --> n11["Increase the Streak for the stat/pokemon"]
    n10 --> n12[" "]
    n11 --> n12
    n12 --> n13["Send client update packet"]
    n13 --> n14(["Fire RECORD_POST event"])
    n14 --> n15["Untitled Node"]
    n1 -- Yes --> n15
    n16["Filled Circle"] --> n17["breakStreak<br>(counterType, speciesId, formName, originatingPokemon, silently)"]
    n17 --> n18["Silently?"]
    n18 -- No --> n19(["Fire BREAK_STREAK_PRE event"])
    n19 --> n20["Cancelled?"]
    n20 -- Yes --> n22["Untitled Node"]
    n23["Received speciesId and formName?"] -- Yes --> n24["Start a new streak with those"]
    n23 -- No --> n25["Start a new empty streak"]
    n24 --> n26[" "]
    n25 --> n26
    n26 --> n27(["Fire BREAK_STREAK_POST event"])
    n27 --> n22
    n20 -- No --> n23
    n18 -- Yes --> n23
    n1@{ shape: diam}
    n4@{ shape: f-circ}
    n9@{ shape: diam}
    n12@{ shape: tri}
    n15@{ shape: fr-circ}
    n16@{ shape: f-circ}
    n18@{ shape: diam}
    n20@{ shape: diam}
    n22@{ shape: fr-circ}
    n23@{ shape: diam}
    n26@{ shape: tri}

Getting a player’s CounterManager

Use the extension function ServerPlayer.getCounterManager from us.timinc.mc.cobblemon.counter.extension.PlayerExtension.

Using a CounterManager

record

Params

pokemon: Pokemon

An instance of a Pokémon tied to this stat record that’s about to go off.

counterType: CounterType

The type of stat that’s about to be recorded.

Use

This method logs an encounter, updates the count and streak appropriately, breaking the streak if necessary, and notifies the client, which causes a broadcast in the chat if the config doesn’t have them turned off for this counter type.

breakStreak

Params

counterType: CounterType

The type of stat whose streak is being broken.