Exemplo n.º 1
0
        public IGamestateSingleton GameLoad(SerializationReader reader)
        {
            var count = reader.ReadInt32();

            for (int i = 0; i < count; i++)
            {
                Data.Add(reader.ReadString(), AbilityUsageEntry.Load(reader));
            }
            return(this);
        }
Exemplo n.º 2
0
        public static AbilityUsageEntry Load(SerializationReader reader)
        {
            var instance = new AbilityUsageEntry();

            instance.Average = reader.ReadInt64();
            var count = reader.ReadInt32();

            for (var i = 0; i < count; i++)
            {
                instance.history.Add(reader.ReadInt64());
            }

            return(instance);
        }
        public static void Postfix(QudGameObject __instance, State __state)
        {
            if (!__instance.IsPlayer())
            {
                return;
            }

            var game = Mod.Game;
            var activatedAbilities = game.Player.Body?.GetPart(nameof(ActivatedAbilities)) as ActivatedAbilities;

            if (activatedAbilities == null)
            {
                return;
            }

            // No easy access to the command that triggers abilities.
            // Have to search through all the player's abilities for a match instead.
            var ability = activatedAbilities.AbilityByGuid.Values
                          .FirstOrDefault(v => v.Command == __state.eventID);

            if (ability == null)
            {
                return;
            }

            var data  = AbilityUsageGameState.Instance.Data;
            var usage = default(AbilityUsageEntry);

            if (data.TryGetValue(ability.Command, out usage))
            {
                usage.AddEntry(game.Turns);
                GameLog.Info($"Updated `AbilityUsageEntry` for {ability.DisplayName}; avg = {usage.Average}");
            }
            else
            {
                usage = new AbilityUsageEntry();
                usage.AddEntry(game.Turns);
                data[ability.Command] = usage;
                GameLog.Info($"Created `AbilityUsageEntry` for {ability.DisplayName}; avg = {usage.Average}");
            }
        }