Example #1
0
            public static GameObject Clone(string prefabName, string instanceId = null)
            {
                try
                {
                    EffectParameters.GetEffectNameAndParameters(ref prefabName, out string parameters);

                    GameObject original = Get(prefabName);
                    if (original == null)
                    {
                        return(null);
                    }

                    GameObject prefab = UnityEngine.Object.Instantiate(original);
                    if (prefab == null)
                    {
                        return(null);
                    }

                    EffectParameters.ApplyAfterCreation(prefab, parameters);

                    if (instanceId != null)
                    {
                        Instances.Add(instanceId, prefab);
                    }

                    //Log.Debug($"UnityEngine.Object.DontDestroyOnLoad(prefab);");
                    //UnityEngine.Object.DontDestroyOnLoad(prefab);
                    return(prefab);
                }
                catch (Exception ex)
                {
                    Log.Exception(ex);
                    return(null);
                }
            }
Example #2
0
            private static GameObject GetEffect(string effectName, string spellId = "", bool isMoveable = false)
            {
                GameObject result;

                if (isMoveable)
                {
                    result = Instances.GetMoveableSpell(spellId, effectName);
                    if (result == null)
                    {
                        Log.Error($"Moveable spell {spellId}.{effectName} not found!");
                    }
                    else
                    {
                        Log.Warning($"Moveable spell {spellId}.{effectName} FOUND!");
                        return(result);
                    }
                }

                string prefabName = Effects.GetIndividualEffectName(EffectParameters.GetEffectNameOnly(effectName));

                Log.Debug($"GetEffect() - prefabName = \"{prefabName}\"");
                if (Prefabs.Has(prefabName))
                {
                    Log.Debug($"Cloning...");
                    result = Prefabs.Clone(effectName);
                }
                else
                {
                    Log.Debug($"CompositeEffect.CreateKnownEffect(\"{effectName}\")");
                    result = CompositeEffect.CreateKnownEffect(effectName);
                }

                PrepareEffect(result);
                return(result);
            }
Example #3
0
            public static GameObject AttachEffect(CreatureBoardAsset creatureBoardAsset, string effectName, string spellId, float enlargeTime, float lifeTime, float shrinkTime, string parentNodeName = null, string prefix = null)
            {
                GameObject spell = GetEffect(effectName);

                if (spell == null)
                {
                    Log.Error($"Spell effect \"{effectName}\" not found. Unable to Attach the effect.");
                    return(null);
                }

                //Log.Indent("Spells.AttachEffect");

                spell.name = GetAttachedEffectName(spellId, prefix);

                GameObject creatureBase    = creatureBoardAsset.GetAssetLoader();
                Transform  parentTransform = creatureBase.transform;

                if (parentNodeName != null)
                {
                    GameObject parentNode = creatureBase.FindChild(parentNodeName, true);
                    if (parentNode != null)
                    {
                        parentTransform = parentNode.transform;
                    }
                }

                // TODO: IS the same technique required for localScale?
                Vector3 savePosition = spell.transform.localPosition;

                spell.transform.SetParent(parentTransform);
                spell.transform.position      = parentTransform.position;
                spell.transform.localPosition = savePosition;

                if (parentNodeName != null)
                {
                    spell.transform.localEulerAngles = Vector3.zero;
                }

                EffectParameters.ApplyAfterPositioning(spell);

                if (lifeTime > 0)
                {
                    Instances.AddTemporal(spell, lifeTime, 2f * shrinkTime / 3f, enlargeTime, shrinkTime);
                }
                else if (enlargeTime > 0)
                {
                    Instances.EnlargeSoon(spell, enlargeTime);
                }

                //Log.Unindent("Spells.AttachEffect");
                return(spell);
            }
Example #4
0
            private static void PlayEffect(string effectName, string spellId, string creatureId, float lifeTime, float enlargeTimeSeconds, float secondsDelayStart, float shrinkTime, SpellLocation location, float rotationDegrees, bool isMoveable)
            {
                if (secondsDelayStart > 0)
                {
                    Log.Debug($"QueueEffect \"{effectName}\" for {secondsDelayStart} seconds...");
                    QueueEffect(new WaitingToCast(location, secondsDelayStart, effectName, spellId, creatureId, enlargeTimeSeconds, lifeTime, null, shrinkTime, rotationDegrees, isMoveable));
                    return;
                }

                CreatureBoardAsset creatureBoardAsset = Minis.GetCreatureBoardAsset(creatureId);

                if (creatureBoardAsset == null)
                {
                    Log.Error($"CreatureBoardAsset matching id {creatureId} not found!");
                    return;
                }

                GameObject spell = GetSpell(effectName, spellId, lifeTime, enlargeTimeSeconds, shrinkTime, rotationDegrees, isMoveable);

                if (spell == null)
                {
                    Log.Error($"Spell name \"{effectName}\" not found!");
                    return;
                }

                GameObject creatureBase = creatureBoardAsset.GetBase();

                if (location == SpellLocation.CreatureCastSpell)
                {
                    Log.Vector("creatureBoardAsset.HookSpellCast.position", creatureBoardAsset.HookSpellCast.position);
                    spell.transform.position = creatureBoardAsset.HookSpellCast.position;
                }
                else                  // Default to base position...
                {
                    spell.transform.position = creatureBase.transform.position;
                }

                float creatureRotationDegrees = creatureBoardAsset.GetRotationDegrees();

                spell.transform.Rotate(Vector3.up, creatureRotationDegrees);
                //spell.transform.localEulerAngles = new Vector3(spell.transform.localEulerAngles.x, rotationDegrees, spell.transform.localEulerAngles.z);
                //Log.Vector("spell.transform.localEulerAngles", spell.transform.localEulerAngles);
                //spell.transform.Rotate(creatureBoardAsset.GetRotation());
                //Log.Vector("spell.transform.localEulerAngles2", spell.transform.localEulerAngles);

                if (isMoveable)
                {
                    Log.Warning($"EffectParameters.ApplyAfterPositioning(spell) on moveable effect {effectName}");
                }
                EffectParameters.ApplyAfterPositioning(spell, isMoveable);
            }
 public static GameObject CreateKnownEffect(string effectName, string instanceId = null)
 {
     if (KnownEffectsBuilder != null)
     {
         EffectParameters.GetEffectNameAndParameters(ref effectName, out string parameters);
         GameObject result = KnownEffectsBuilder.Create(effectName, instanceId);
         EffectParameters.ApplyAfterCreation(result, parameters);
         return(result);
     }
     else
     {
         Talespire.Log.Error($"KnownEffectsBuilder == null!!!");
     }
     return(null);
 }
Example #6
0
            public static void DeleteSpellSoon(string spellId, float shrinkOnDeleteTime = 1)
            {
                if (!spells.ContainsKey(spellId))
                {
                    return;
                }

                foreach (GameObject spellEffect in spells[spellId])
                {
                    EffectParameters.EndingSpell(spellEffect);
                    AddTemporal(spellEffect, Mathf.Max(2, shrinkOnDeleteTime), 2, 0, shrinkOnDeleteTime);
                }

                spells.Remove(spellId);
            }
Example #7
0
            public static GameObject PlayEffectAtPosition(string effectName, string spellId, Vector3 position, float lifeTime = 0, float enlargeTimeSeconds = 0, float secondsDelayStart = 0, float shrinkTime = 0, float rotationDegrees = 0, bool isMoveable = false, Action <GameObject> conditioning = null)
            {
                if (secondsDelayStart > 0)
                {
                    QueueEffect(new WaitingToCast(SpellLocation.AtPosition, secondsDelayStart, effectName, spellId, null, enlargeTimeSeconds, lifeTime, position, shrinkTime, rotationDegrees, isMoveable, conditioning));
                    return(null);
                }

                Log.Warning($"PlayEffectAtPosition(\"{effectName}\"...)");
                GameObject spell = GetSpell(effectName, spellId, lifeTime, enlargeTimeSeconds, shrinkTime, rotationDegrees, isMoveable);

                if (spell != null)
                {
                    spell.transform.position = position;
                    EffectParameters.ApplyAfterPositioning(spell, isMoveable);
                }

                conditioning?.Invoke(spell);

                return(spell);
            }