Beispiel #1
0
        static global::Ammo ResolveAmmoInternal(AmmoIdentifier identifier)
        {
            switch (identifier.AmmoType)
            {
            case AmmoType.PLAYER:
                return(SceneContext.Instance.PlayerState.ammoDict[(PlayerState.AmmoMode)identifier.longIdentifier]);

            default:
                foreach (var v in Resources.FindObjectsOfTypeAll <Drone>())
                {
                    if (v.ammo != null && AmmoIdentifier.GetIdentifier(v.ammo).Equals(identifier))
                    {
                        return(v.ammo);
                    }
                }
                foreach (var v in Resources.FindObjectsOfTypeAll <SiloStorage>())
                {
                    if (v.ammo != null && AmmoIdentifier.GetIdentifier(v.ammo).Equals(identifier))
                    {
                        return(v.ammo);
                    }
                }
                break;
            }
            return(null);
        }
Beispiel #2
0
        static AmmoModel ResolveModelInternal(AmmoIdentifier identifier)
        {
            switch (identifier.AmmoType)
            {
            case AmmoType.PLAYER:
                return(SceneContext.Instance.GameModel.player.ammoDict
                       [(PlayerState.AmmoMode)identifier.longIdentifier]);

            case AmmoType.GADGET:
                var gadget = SceneContext.Instance.GameModel.gadgetSites[identifier.stringIdentifier].attached;
                if (gadget is DroneModel drone)
                {
                    return(drone.ammo);
                }
                if (gadget is WarpDepotModel depot)
                {
                    return(depot.ammo);
                }
                return(null);

            case AmmoType.LANDPLOT:
                var plot = SceneContext.Instance.GameModel.landPlots
                           [identifier.stringIdentifier];

                var type = (SiloStorage.StorageType)(uint) identifier.longIdentifier;
                return(plot.siloAmmo[type]);

            default:
                throw new NotImplementedException();
            }
        }
Beispiel #3
0
 public static void Write(AmmoIdentifier identifier, BinaryWriter writer)
 {
     writer.Write((int)identifier.AmmoType);
     writer.Write(identifier.longIdentifier);
     writer.Write(identifier.stringIdentifier);
     if (identifier.AmmoType.IsCustom())
     {
         writer.Write(identifier.custommodid);
     }
 }
Beispiel #4
0
        public static global::Ammo ResolveAmmo(AmmoIdentifier identifier)
        {
            switch (identifier.AmmoType)
            {
            case AmmoType.PLAYER:
                return(SceneContext.Instance.PlayerState.ammoDict[(PlayerState.AmmoMode)identifier.longIdentifier]);

            default:
                throw new NotImplementedException();
            }
        }
Beispiel #5
0
        internal static SRMod GetModForIdentifier(AmmoIdentifier id)
        {
            switch (id.AmmoType)
            {
            case AmmoType.PLAYER:
                return(ModdedIDRegistry.ModForID((PlayerState.AmmoMode)(int) id.longIdentifier));

            case AmmoType.LANDPLOT:
                return(ModdedIDRegistry.ModForID((SiloStorage.StorageType)(int) id.longIdentifier));
            }
            return(id.AmmoType.IsCustom() ? SRModLoader.GetMod(id.custommodid) : null);
        }
Beispiel #6
0
        public static bool IsModdedIdentifier(AmmoIdentifier id)
        {
            switch (id.AmmoType)
            {
            case AmmoType.PLAYER:
                return(ModdedIDRegistry.IsModdedID((PlayerState.AmmoMode)(int) id.longIdentifier));

            case AmmoType.LANDPLOT:
                return(ModdedIDRegistry.IsModdedID((SiloStorage.StorageType)(int) id.longIdentifier));
            }
            return(id.AmmoType.IsCustom());
        }
Beispiel #7
0
        public static global::Ammo ResolveAmmo(AmmoIdentifier identifier)
        {
            if (_ammoCache.TryGetValue(identifier, out var model))
            {
                return(model);
            }
            var newModel = ResolveAmmoInternal(identifier);

            if (newModel != null)
            {
                _ammoCache.Add(identifier, newModel);
            }
            return(newModel);
        }
Beispiel #8
0
        public static AmmoModel ResolveModel(AmmoIdentifier identifier)
        {
            if (_cache.TryGetValue(identifier, out var model))
            {
                return(model);
            }
            var newModel = ResolveModelInternal(identifier);

            if (newModel != null)
            {
                _cache.Add(identifier, newModel);
            }
            return(newModel);
        }
Beispiel #9
0
        public static bool IsValidIdentifier(AmmoIdentifier identifier)
        {
            switch (identifier.AmmoType)
            {
            case AmmoType.GADGET:
                return(ModdedStringRegistry.IsValidString(identifier.stringIdentifier));

            case AmmoType.LANDPLOT:
                return(ModdedStringRegistry.IsValidString(identifier.stringIdentifier) && Enum.IsDefined(typeof(SiloStorage.StorageType), (SiloStorage.StorageType)(int) identifier.longIdentifier));

            case AmmoType.PLAYER:
                return(Enum.IsDefined(typeof(PlayerState.AmmoMode), (PlayerState.AmmoMode)(int) identifier.longIdentifier));
            }
            return(true);
        }
Beispiel #10
0
        public static List <AmmoDataV02> ResolveToData(AmmoIdentifier identifier, Game game)
        {
            switch (identifier.AmmoType)
            {
            case AmmoType.PLAYER:
                return(game.player.ammo[(PlayerState.AmmoMode)identifier.longIdentifier]);

            case AmmoType.GADGET:
                return(ModdedStringRegistry.IsValidString(identifier.stringIdentifier) ? (game.world.placedGadgets[identifier.stringIdentifier].drone?.drone?.ammo is AmmoDataV02 amdat ? new AmmoDataV02[] { amdat }.ToList() : game.world.placedGadgets[identifier.stringIdentifier].ammo) :null);

            case AmmoType.LANDPLOT:
                return(game.ranch.plots.FirstOrDefault((x) => x.id == identifier.stringIdentifier)?
                       .siloAmmo[(SiloStorage.StorageType)identifier.longIdentifier]);
            }

            return(null);
        }
Beispiel #11
0
        public static List <AmmoDataV02> ResolveToData(AmmoIdentifier identifier, GameV09 game)
        {
            switch (identifier.AmmoType)
            {
            case AmmoType.PLAYER:
                return(game.player.ammo[(PlayerState.AmmoMode)identifier.longIdentifier]);

            case AmmoType.GADGET:
                return(game.world.placedGadgets[identifier.stringIdentifier].ammo);

            case AmmoType.LANDPLOT:
                return(game.ranch.plots.First((x) => x.id == identifier.stringIdentifier)
                       .siloAmmo[(SiloStorage.StorageType)identifier.longIdentifier]);
            }

            return(null);
        }
Beispiel #12
0
        static AmmoIdentifier GetIdentifierInternal(AmmoModel ammoModel) // warning, this is a reference based check
        {
            foreach (var candidate in SceneContext.Instance.GameModel.player.ammoDict)
            {
                if (candidate.Value == ammoModel)
                {
                    return(new AmmoIdentifier(Ammo.AmmoType.PLAYER, (long)candidate.Key));
                }
            }

            foreach (var candidate in SceneContext.Instance.GameModel.gadgetSites.Where((x) => x.Value.HasAttached()))
            {
                var potentialKey = new AmmoIdentifier(AmmoType.GADGET, candidate.Key);
                if (candidate.Value.attached is DroneModel drone)
                {
                    if (drone.ammo == ammoModel)
                    {
                        return(potentialKey);
                    }
                }

                if (candidate.Value.attached is WarpDepotModel depot)
                {
                    if (depot.ammo == ammoModel)
                    {
                        return(potentialKey);
                    }
                }
            }

            foreach (var candidate in SceneContext.Instance.GameModel.landPlots)
            {
                foreach (var ammo in candidate.Value.siloAmmo)
                {
                    if (ammo.Value == ammoModel)
                    {
                        return(new AmmoIdentifier(AmmoType.LANDPLOT, (long)ammo.Key, candidate.Key));
                    }
                }
            }

            return(new AmmoIdentifier(AmmoType.NONE, 0));
        }
Beispiel #13
0
 public static bool TryGetIdentifier(global::Ammo model, out AmmoIdentifier identifier)
 {
     return(TryGetIdentifier(model.ammoModel, out identifier));
 }
Beispiel #14
0
 public static bool TryGetIdentifier(AmmoModel model, out AmmoIdentifier identifier)
 {
     identifier = GetIdentifier(model);
     return(identifier.AmmoType != AmmoType.NONE);
 }
Beispiel #15
0
 public static bool TryGetIdentifier(List <AmmoDataV02> ammo, Game game, out AmmoIdentifier identifier)
 {
     identifier = GetIdentifier(ammo, game);
     return(identifier.AmmoType != AmmoType.NONE);
 }
Beispiel #16
0
 public static void Write(AmmoIdentifier identifier, BinaryWriter writer)
 {
     writer.Write((int)identifier.AmmoType);
     writer.Write(identifier.longIdentifier);
     writer.Write(identifier.stringIdentifier);
 }