상속: MonoBehaviour
예제 #1
0
        public SimulationManager(GraphicsDevice device, ContentManager content)
        {
            if (Instance != null)
            {
                throw new InvalidOperationException("Cannot create more than once instance of the simulation manager.");
            }
            Instance = this;

            _sb       = new SpriteBatch(device);
            _blankTex = new Texture2D(device, 1, 1);
            _blankTex.SetData(new Color[] { Color.White });

            _device    = device;
            _world     = new WorldModel(device, (int)Constants.WorldSize.X / 10);
            _uavModel  = new CModel(device, content.Load <Model>("UAV"));
            _tankModel = new CModel(device, content.Load <Model>("tank"));
            _missModel = new CModel(device, content.Load <Model>("sphere_missile"));
            _cone      = new ConeModel(device);
            _ring      = new RingModel(device, Constants.TankFiringRange / 10, 1);

            _font  = content.Load <SpriteFont>("debugfont");
            _lRect = new Rectangle(0, 0, 130, 70);

            Simulation = new Simulation();

            _entityFollow = new EntityFollowBehavior();
        }
        internal static void RespawnCompanions(RingModel summoningRing, Farmer who, GameLocation location, bool removeFromActive = true)
        {
            var boundCompanions = activeCompanions.FirstOrDefault(a => a.SummoningRing == summoningRing);

            if (boundCompanions is null)
            {
                CustomCompanions.monitor.Log($"Unable to find summoning ring match to {summoningRing.Name}, will be unable to respawn companions!");
                return;
            }

            foreach (var companion in boundCompanions.Companions)
            {
                if (location.characters != null && !location.characters.Contains(companion))
                {
                    companion.ResetForNewLocation(location, who.getTileLocation());
                    location.characters.Add(companion);
                }
            }
        }
예제 #3
0
    public override GameObject BuildObject(EnumRingColors.RingColor color)
    {
        GameObject prefab = Resources.Load <GameObject>(UnitType(color));
        RingModel  model  = prefab.GetComponentInChildren <RingModel>();

        model.unitSpawnRadius   = Random.Range(GameData.UnitSpawnMinRadius, GameData.UnitSpawnMaxRadius);
        model.unitDestroyRadius = GameData.UnitDestroyRadius;
        model.unitSpeed         = Random.Range(GameData.UnitSpawnMinSpeed, GameData.UnitSpawnMaxRadius);

        if (color == EnumRingColors.RingColor.blue)
        {
            model.GetComponent <RingModel>().isBlue = true;
        }
        else if (color == EnumRingColors.RingColor.red)
        {
            model.GetComponent <RingModel>().isBlue = false;
        }

        return(prefab);
    }
        internal static void RemoveCompanions(RingModel summoningRing, GameLocation location, bool removeFromActive = true)
        {
            var boundCompanions = activeCompanions.FirstOrDefault(a => a.SummoningRing == summoningRing);

            if (boundCompanions is null)
            {
                CustomCompanions.monitor.Log($"Unable to find summoning ring match to {summoningRing.Name}, will be unable to despawn companions!");
                return;
            }

            foreach (var companion in boundCompanions.Companions)
            {
                if (location.characters != null && location.characters.Contains(companion))
                {
                    companion.PrepareForDeletion();
                    location.characters.Remove(companion);
                }
            }

            if (removeFromActive)
            {
                activeCompanions.Remove(boundCompanions);
            }
        }
예제 #5
0
 private void Awake()
 {
     model = GetComponent <RingModel>();
 }
        private void LoadContentPacks(bool isReload = false)
        {
            this.Reset(false, isReload);

            // Load the owned content packs
            foreach (IContentPack contentPack in Helper.ContentPacks.GetOwned())
            {
                Monitor.Log($"Loading companions from pack: {contentPack.Manifest.Name} {contentPack.Manifest.Version} by {contentPack.Manifest.Author}", LogLevel.Debug);

                var companionFolders = new DirectoryInfo(Path.Combine(contentPack.DirectoryPath, "Companions")).GetDirectories();
                if (companionFolders.Count() == 0)
                {
                    Monitor.Log($"No sub-folders found under Companions for the content pack {contentPack.Manifest.Name}!", LogLevel.Warn);
                    continue;
                }

                // Load in the companions
                foreach (var companionFolder in companionFolders)
                {
                    if (!File.Exists(Path.Combine(companionFolder.FullName, "companion.json")))
                    {
                        Monitor.Log($"Content pack {contentPack.Manifest.Name} is missing a companion.json under {companionFolder.Name}!", LogLevel.Warn);
                        continue;
                    }

                    CompanionModel companion = contentPack.ReadJsonFile <CompanionModel>(Path.Combine(companionFolder.Parent.Name, companionFolder.Name, "companion.json"));
                    companion.Name  = companion.Name.Replace(" ", "");
                    companion.Owner = contentPack.Manifest.UniqueID;

                    // Save the TileSheet, if one is given
                    if (String.IsNullOrEmpty(companion.TileSheetPath) && !File.Exists(Path.Combine(companionFolder.FullName, "companion.png")))
                    {
                        Monitor.Log($"Unable to add companion {companion.Name} from {contentPack.Manifest.Name}: No associated companion.png or TileSheetPath given", LogLevel.Warn);
                        continue;
                    }
                    else if (String.IsNullOrEmpty(companion.TileSheetPath))
                    {
                        companion.TileSheetPath = contentPack.ModContent.GetInternalAssetName(Path.Combine(companionFolder.Parent.Name, companionFolder.Name, "companion.png")).Name;
                    }

                    // Save the PortraitSheet, if one is given
                    if (companion.Portrait != null)
                    {
                        if (!File.Exists(Path.Combine(companionFolder.FullName, "portrait.png")))
                        {
                            Monitor.Log($"Warning for companion {companion.Name} from {contentPack.Manifest.Name}: Portrait property was given but no portrait.png was found", LogLevel.Warn);
                        }
                        else
                        {
                            companion.PortraitSheetPath = contentPack.ModContent.GetInternalAssetName(Path.Combine(companionFolder.Parent.Name, companionFolder.Name, "portrait.png")).Name;
                        }
                    }

                    if (contentPack.Translation != null)
                    {
                        companion.Translations = contentPack.Translation;
                    }
                    Monitor.Log(companion.ToString(), LogLevel.Trace);

                    // Add the companion to our cache
                    CompanionManager.companionModels.Add(companion);

                    // Cache the full name of the companion, so that it can be reference by a Content Patcher token
                    if (_contentPatcherApi != null)
                    {
                        var assetToken = $"{TOKEN_HEADER}{companion.GetId()}";
                        AssetManager.idToAssetToken[companion.GetId()] = assetToken;

                        if (!isReload)
                        {
                            var modelObject = Helper.GameContent.Load <TokenModel>(assetToken);
                            //var modelObject = AssetManager.GetCompanionModelObject(Helper.Content.Load<Dictionary<string, object>>(assetToken, ContentSource.GameContent));
                            trackedModels[$"{CustomCompanions.TOKEN_HEADER}{companion.GetId()}"] = modelObject.Companion;
                        }
                    }
                }

                if (_jsonAssetsApi != null && !isReload)
                {
                    // Load in the rings that will be paired to a companion
                    if (!Directory.Exists(Path.Combine(contentPack.DirectoryPath, "Objects")))
                    {
                        Monitor.Log($"No summoning rings available from {contentPack.Manifest.Name}, this may be intended", LogLevel.Trace);
                        continue;
                    }

                    foreach (var ringFolder in new DirectoryInfo(Path.Combine(contentPack.DirectoryPath, "Objects")).GetDirectories())
                    {
                        if (!File.Exists(Path.Combine(ringFolder.FullName, "object.json")))
                        {
                            Monitor.Log($"Content pack {contentPack.Manifest.Name} is missing a object.json under {ringFolder.Name}!", LogLevel.Warn);
                            continue;
                        }

                        RingModel ring = contentPack.ReadJsonFile <RingModel>(Path.Combine(ringFolder.Parent.Name, ringFolder.Name, "object.json"));
                        ring.Owner = contentPack.Manifest.UniqueID;

                        RingManager.rings.Add(ring);
                    }

                    // Generate content.json for Json Assets
                    contentPack.WriteJsonFile("content-pack.json", new ContentPackModel
                    {
                        Name        = contentPack.Manifest.Name,
                        Author      = contentPack.Manifest.Author,
                        Version     = contentPack.Manifest.Version.ToString(),
                        Description = contentPack.Manifest.Description,
                        UniqueID    = contentPack.Manifest.UniqueID,
                        UpdateKeys  = contentPack.Manifest.UpdateKeys,
                    });

                    // Load in the associated rings objects (via JA)
                    _jsonAssetsApi.LoadAssets(contentPack.DirectoryPath);
                }
            }
        }
예제 #7
0
 private static bool FilterRing(RingModel e)
 {
     return(e.Type == "Icy" || string.IsNullOrWhiteSpace(e.Type));
 }
        internal static void SummonCompanions(CompanionModel model, int numberToSummon, RingModel summoningRing, Farmer who, GameLocation location)
        {
            if (location.characters is null)
            {
                CustomCompanions.monitor.Log($"Unable to summon {model.Name} due to the location {location.Name} not having an instantiated GameLocation.characters!");
                return;
            }

            List <Companion> companions = new List <Companion>();

            for (int x = 0; x < numberToSummon; x++)
            {
                Companion companion = new Companion(model, who);
                location.characters.Add(companion);
                companions.Add(companion);
            }

            activeCompanions.Add(new BoundCompanions(summoningRing, companions));
        }
 public BoundCompanions(RingModel ring, List <Companion> companions)
 {
     SummoningRing = ring;
     Companions    = companions;
 }