Basically I'm working on a custom spell effect that summons a temporary enemy entity that is set to the team of the player (hopefully set to the team of the caster eventually if I can get this into the spell table of other entities). Now I got the basic function of this spell working with only a slight bit of hacking involved with adding a custom variable to the "EntityEffectManager" script. The specified enemy gets created when the spell is cast using the "CreateFoeGameObjects" method, the basic requirements are done to make this an active gameobject as the method comments say you need to do, and store a reference of the enemy gameobject that was created in my custom variable I mentioned for later use, also the player is informed in a text pop-up of what they just summoned.
Currently, I have it so when the duration of the spell effect wears off the attached gameobject (the summoned entity) is destroyed from the scene and the custom variable that was storing their gameobject reference is set to null, still have to work out how I will make it so the spell effect will end early when the attached entity dies through any means and be deleted from the scene in the same way before they can leave a corpse and such, but I'll deal with that logic later, likely have to make it a constant effect that checks their health or something.
Now, the issue I'm having is that I would like to somehow attach this gameobject reference of the summoned entity to the spell bundle itself, that way I will have an individual instance anytime this spell is cast that can keep track of the respective summoned entities they are associated with. The problem though is that this is sort of a chicken before the egg situation, since the spell bundle is created before the "start" part of a spell is ever ran, and the gameobject entity is created during the "start" of the spell. So I'd like to know if there could be some way I could do this where I can somehow associate the summoned enemy with the spell bundle it is created by, but after all my thinking I still can't figure out a way that I could do this, so I figure I may as well post this here and see if anyone is more clever than me. I'm working with a separate DFU fork btw, so altering code and scripts is entirely within reason here.
Here is a screenshot of the main working part of the spell effect if that might be helpful to get a better idea what is going on. Here is that screenshot in text form as well.
Code: Select all
void StartSummon() // Change this for summon behavior
{
// Get peered entity gameobject
DaggerfallEntityBehaviour entityBehaviour = GetPeeredEntityBehaviour(manager);
if (!entityBehaviour)
return;
if (manager.AttachedSummonedEntity != null) // This seems to have worked for the one problem at least, that's good.
return;
// Part where monster ally is actually created
UnityEngine.GameObject player = GameManager.Instance.PlayerObject;
UnityEngine.GameObject[] mobile = DaggerfallWorkshop.Utility.GameObjectHelper.CreateFoeGameObjects(player.transform.position + player.transform.forward * 2, (MobileTypes)(int)monsterCareer, 1, MobileReactions.Hostile, null, true);
DaggerfallEntityBehaviour behaviour = mobile[0].GetComponent<DaggerfallEntityBehaviour>();
EnemyEntity entity = behaviour.Entity as EnemyEntity;
//mobile[0].transform.LookAt(mobile[0].transform.position + (mobile[0].transform.position - player.transform.position));
mobile[0].SetActive(true);
manager.AttachedSummonedEntity = mobile[0];
// Output "You Summoned Something" if the host manager is player
if (awakeAlert && manager.EntityBehaviour == GameManager.Instance.PlayerEntityBehaviour)
{
DaggerfallUI.AddHUDText(string.Format("You Summon A {0}", (MobileTypes)monsterCareer), 1.5f);
awakeAlert = false;
}
}
void EndSummon() // Change this for summon behavior
{
// Get peered entity gameobject
DaggerfallEntityBehaviour entityBehaviour = GetPeeredEntityBehaviour(manager);
if (!entityBehaviour)
return;
UnityEngine.GameObject summonedEntity = manager.AttachedSummonedEntity;
UnityEngine.GameObject.Destroy(summonedEntity);
manager.AttachedSummonedEntity = null;
ResignAsIncumbent();
}