Esempio n. 1
0
        /// <summary>
        /// Spawn a particular elite type with the specified monster type at the specified location.  This will
        /// apply appropriate HP and Dmg scaling per the specifications on the affix card, as well as calling the affix onSpawned.
        /// This is primarily intended for testing, but could also be used to easily spawn elites for other purposes.
        /// Note that this does not set XP and Gold rewards, as it does not have access to the cost function; you will need to
        /// add those yourself if you want these.
        /// </summary>
        /// <param name="spawnCard">Card describing the type of monster to spawn</param>
        /// <param name="affixCard">Card describing the type of elite to spawn; may pass null to spawn a non-elite</param>
        /// <param name="placement">How to place the elite in the scene</param>
        /// <param name="rng">Random number generator to use for placement</param>
        /// <returns></returns>
        public static CharacterMaster TrySpawnElite(CharacterSpawnCard spawnCard, EliteAffixCard affixCard, DirectorPlacementRule placement, Xoroshiro128Plus rng)
        {
            var spawnRequest = new DirectorSpawnRequest(spawnCard, placement, rng)
            {
                teamIndexOverride     = TeamIndex.Monster,
                ignoreTeamMemberLimit = true
            };
            var spawned = DirectorCore.instance.TrySpawnObject(spawnRequest);

            if (spawned == null)
            {
                return(null);
            }

            //Configure as the chosen elite
            var spawnedMaster = spawned.GetComponent <CharacterMaster>();

            if (affixCard != null)
            {
                //Elites are boosted
                var healthBoost = affixCard.healthBoostCoeff;
                var damageBoost = affixCard.damageBoostCoeff;

                spawnedMaster.inventory.GiveItem(ItemIndex.BoostHp, Mathf.RoundToInt((float)((healthBoost - 1.0) * 10.0)));
                spawnedMaster.inventory.GiveItem(ItemIndex.BoostDamage, Mathf.RoundToInt((float)((damageBoost - 1.0) * 10.0)));
                var eliteDef = EliteCatalog.GetEliteDef(affixCard.eliteType);
                if (eliteDef != null)
                {
                    spawnedMaster.inventory.SetEquipmentIndex(eliteDef.eliteEquipmentIndex);
                }

                affixCard.onSpawned?.Invoke(spawnedMaster);
            }
            return(spawnedMaster);
        }
Esempio n. 2
0
        private static void Spawn(ConCommandArgs args)
        {
            var spawnCardStr = args.userArgs[0];
            var eliteStr     = args.userArgs.Count > 1 ? args.userArgs[1] : "";

            var spawnCard = Resources.Load <CharacterSpawnCard>("SpawnCards/CharacterSpawnCards/" + spawnCardStr);

            if (spawnCard == null)
            {
                Debug.LogWarning($"Could not locate character spawn card asset with name {spawnCardStr}; should be 'cscBeetle' for spawning a beetle, for instance");
                return;
            }

            EliteAffixCard affixCard = null;

            if (!string.IsNullOrEmpty(eliteStr))
            {
                affixCard = EsoLib.Cards.FirstOrDefault(c => EliteCatalog
                                                        .GetEliteDef(c.eliteType).modifierToken.ToLower()
                                                        .Contains(eliteStr.ToLower()));
            }

            var user = LocalUserManager.GetFirstLocalUser();
            var body = user.cachedBody;

            if (body?.master == null)
            {
                Debug.LogError("Cannot find local user body!");
                return;
            }

            var placement = new DirectorPlacementRule
            {
                spawnOnTarget   = body.transform,
                maxDistance     = 40,
                placementMode   = DirectorPlacementRule.PlacementMode.Approximate,
                preventOverhead = false
            };

            var rng = new Xoroshiro128Plus((ulong)DateTime.Now.Ticks);

            if (EsoLib.TrySpawnElite(spawnCard, affixCard, placement, rng) == null)
            {
                Debug.LogWarning("Failed to spawn elite; try again somewhere less crowded");
            }
        }