void Update() { // Create new foe list when changed in editor if (FoeType != MobileTypes.None && FoeType != lastFoeType && SpawnCount > 0) { DestroyOldFoeGameObjects(pendingFoeGameObjects); SetFoeGameObjects(GameObjectHelper.CreateFoeGameObjects(Vector3.zero, FoeType, SpawnCount, alliedToPlayer: AlliedToPlayer)); lastFoeType = FoeType; } // Do nothing if no spawns or we are done spawning if (pendingFoeGameObjects == null || !spawnInProgress) { return; } // Clear pending foes if all have been spawned if (spawnInProgress && pendingFoesSpawned >= pendingFoeGameObjects.Length) { spawnInProgress = false; Destroy(gameObject); return; } // Try placing foes near player PlaceFoeFreely(pendingFoeGameObjects, MinDistance, MaxDistance); // Keep breaking rest if spawn in progress if (spawnInProgress && DaggerfallUI.Instance.UserInterfaceManager.TopWindow is DaggerfallRestWindow) { (DaggerfallUI.Instance.UserInterfaceManager.TopWindow as DaggerfallRestWindow).AbortRestForEnemySpawn(); } }
public static DaggerfallUnityItem CreateRandomlyFilledSoulTrap() { // Create a trapped soul type and filter invalid creatures MobileTypes soul = MobileTypes.None; while (soul == MobileTypes.None) { MobileTypes randomSoul = (MobileTypes)UnityEngine.Random.Range((int)MobileTypes.Rat, (int)MobileTypes.Lamia + 1); if (randomSoul == MobileTypes.Horse_Invalid || randomSoul == MobileTypes.Dragonling) // NOTE: Dragonling (34) is soulless, only soul of Dragonling_Alternate (40) from B0B70Y16 has a soul { continue; } else { soul = randomSoul; } } // Generate item DaggerfallUnityItem newItem = CreateItem(ItemGroups.MiscItems, (int)MiscItems.Soul_trap); newItem.TrappedSoulType = soul; MobileEnemy mobileEnemy = GameObjectHelper.EnemyDict[(int)soul]; newItem.value = 5000 + mobileEnemy.SoulPts; return(newItem); }
public void SpawnEnemy(MobileTypes mobileType) { if (DaggerfallUnity.FindDaggerfallUnity(out dfUnity)) { Logger.GetInstance().log("Creating a Daggerfall enemy GameObject.\n", this); tmpEnemy = GameObjectHelper.CreateDaggerfallEnemyGameObject(mobileType, this.transform, MobileReactions.Hostile); if (!tmpEnemy) { return; } GameObject mainCamera = GameObject.FindGameObjectWithTag("MainCamera"); GameObject player = GameObject.FindGameObjectWithTag("Player"); //Ray ray = new Ray(mainCamera.transform.position, Quaternion.Euler(45, 0, 0) * mainCamera.transform.forward); Ray ray = new Ray(mainCamera.transform.position, mainCamera.transform.forward); RaycastHit[] hits; hits = Physics.RaycastAll(ray, 100.0f); if (hits != null && hits.Length > 0) { tmpEnemy.transform.position = hits[0].point; tmpEnemy.transform.Translate(new Vector3(0, tmpEnemy.GetComponent <CharacterController>().height / 2 + 1f)); //tmpEnemy.transform.Translate(0, 10f, 0); } else { tmpEnemy.transform.position = player.transform.position; } Logger.GetInstance().log("Created a Daggerfall enemy GameObject.\n", this); } }
public override void SetResource(string line) { base.SetResource(line); string matchStr = @"(Foe|foe) (?<symbol>[a-zA-Z0-9_.-]+) is (?<count>\d+) (?<aFoe>\w+)|(Foe|foe) (?<symbol>[a-zA-Z0-9_.-]+) is (?<aFoe>\w+)"; Match match = Regex.Match(line, matchStr); if (match.Success) { // Store symbol for quest system Symbol = new Symbol(match.Groups["symbol"].Value); // Get name of foe and count string name = match.Groups["aFoe"].Value; int count = Parser.ParseInt(match.Groups["count"].Value); // Read foe from table data Table foesTable = QuestMachine.Instance.FoesTable; if (foesTable.HasValue(name)) { foeType = (MobileTypes)Parser.ParseInt(foesTable.GetValue("id", name)); } else { throw new Exception(string.Format("Foes data table does not contain an entry for {0}", name)); } // Setup spawn count spawnCount = Mathf.Clamp(count, 1, maxSpawnCount); // Assign name SetFoeName(); } }
void Update() { // Create new foe list when changed in editor if (FoeType != MobileTypes.None && FoeType != lastFoeType && SpawnCount > 0) { DestroyOldFoeGameObjects(pendingFoeGameObjects); SetFoeGameObjects(GameObjectHelper.CreateFoeGameObjects(Vector3.zero, FoeType, SpawnCount, alliedToPlayer: AlliedToPlayer)); lastFoeType = FoeType; } // Do nothing if no spawns or we are done spawning if (pendingFoeGameObjects == null || !spawnInProgress) { return; } // Clear pending foes if all have been spawned if (spawnInProgress && pendingFoesSpawned >= pendingFoeGameObjects.Length) { spawnInProgress = false; Destroy(gameObject); return; } // Try placing foes near player PlaceFoeFreely(pendingFoeGameObjects, MinDistance, MaxDistance); if (spawnInProgress) { GameManager.Instance.RaiseOnEncounterEvent(); } }
private static void AddEnemy( DFBlock.RdbObject obj, MobileTypes type, Transform parent = null, DFRegion.DungeonTypes dungeonType = DFRegion.DungeonTypes.HumanStronghold) { // Get default reaction MobileReactions reaction = MobileReactions.Hostile; if (obj.Resources.FlatResource.FlatData.Reaction == (int)DFBlock.EnemyReactionTypes.Passive) { reaction = MobileReactions.Passive; } // Just setup demo enemies at this time string name = string.Format("DaggerfallEnemy [{0}]", type.ToString()); Vector3 position = new Vector3(obj.XPos, -obj.YPos, obj.ZPos) * MeshReader.GlobalScale; GameObject go = GameObjectHelper.InstantiatePrefab(DaggerfallUnity.Instance.Option_EnemyPrefab.gameObject, name, parent, position); SetupDemoEnemy setupEnemy = go.GetComponent <SetupDemoEnemy>(); if (setupEnemy != null) { // Configure enemy setupEnemy.ApplyEnemySettings(type, reaction); // Align non-flying units with ground DaggerfallMobileUnit mobileUnit = setupEnemy.GetMobileBillboardChild(); if (mobileUnit.Summary.Enemy.Behaviour != MobileBehaviour.Flying) { GameObjectHelper.AlignControllerToGround(go.GetComponent <CharacterController>()); } } }
/// <summary> /// Change enemy settings and configure in a single call. /// </summary> /// <param name="enemyType">Enemy type.</param> public void ApplyEnemySettings(MobileTypes enemyType, MobileReactions enemyReaction, MobileGender gender) { EnemyType = enemyType; EnemyReaction = enemyReaction; Gender = gender; ApplyEnemySettings(); }
/// <summary> /// Creates from a serialized item. /// </summary> internal void FromItemData(ItemData_v1 data) { uid = data.uid; shortName = data.shortName; nativeMaterialValue = data.nativeMaterialValue; dyeColor = data.dyeColor; weightInKg = data.weightInKg; drawOrder = data.drawOrder; value = data.value1; // These are being saved in DF Unity saves as one int32 value but are two 16-bit values in classic unknown = (ushort)(data.value2 & 0xffff); flags = (ushort)(data.value2 >> 16); currentCondition = data.hits1; maxCondition = data.hits2; // These are being saved in DF Unity saves as one int32 value but are two 8-bit values in classic unknown2 = (byte)(data.hits3 & 0xff); typeDependentData = (byte)(data.hits3 >> 8); enchantmentPoints = data.enchantmentPoints; message = data.message; legacyMagic = data.legacyMagic; playerTextureArchive = data.playerTextureArchive; playerTextureRecord = data.playerTextureRecord; worldTextureArchive = data.worldTextureArchive; worldTextureRecord = data.worldTextureRecord; itemGroup = data.itemGroup; groupIndex = data.groupIndex; currentVariant = data.currentVariant; stackCount = data.stackCount; isQuestItem = data.isQuestItem; questUID = data.questUID; questItemSymbol = data.questItemSymbol; trappedSoulType = data.trappedSoulType; }
/// <summary> /// Change enemy settings and configure in a single call. /// </summary> /// <param name="enemyType">Enemy type.</param> public void ApplyEnemySettings(MobileTypes enemyType, MobileReactions enemyReaction, MobileGender gender, byte classicSpawnDistanceType = 0) { EnemyType = enemyType; EnemyReaction = enemyReaction; ClassicSpawnDistanceType = classicSpawnDistanceType; ApplyEnemySettings(gender); }
public MobileTypes GetMobileType(MobileTypes mobiletypes) { string fetchMobileType = $"SELECT * FROM Mobifix_DB.MOBILE_TYPE WHERE LOWER (MOBILE_CMPNY_ID) = '{ mobiletypes.MobileCompanyID.ToString() }'"; var dtResult = MySqlMobileTypesHelper.ExecuteQuery(fetchMobileType); var mobiletype = FillMobileTypesModel(dtResult); return(mobiletype.FirstOrDefault <MobileTypes>()); }
/// <summary> /// Change enemy settings and configure in a single call. /// </summary> /// <param name="enemyType">Enemy type.</param> public void ApplyEnemySettings(MobileTypes enemyType, MobileReactions enemyReaction, MobileGender gender, byte classicSpawnDistanceType = 0, bool alliedToPlayer = false) { EnemyType = enemyType; EnemyReaction = enemyReaction; ClassicSpawnDistanceType = classicSpawnDistanceType; AlliedToPlayer = alliedToPlayer; ApplyEnemySettings(gender); }
private static void AddRandomRDBEnemy( DFBlock.RdbObject obj, DFRegion.DungeonTypes dungeonType, float monsterPower, int monsterVariance, Transform parent, ref DFBlock blockData, bool serialize) { // Must have a dungeon type if (dungeonType == DFRegion.DungeonTypes.NoDungeon) { return; } // Get dungeon type index int dungeonIndex = (int)dungeonType >> 8; if (dungeonIndex < RandomEncounters.EncounterTables.Length) { // Get encounter table RandomEncounterTable table = RandomEncounters.EncounterTables[dungeonIndex]; // Get base monster index into table int baseMonsterIndex = (int)((float)table.Enemies.Length * monsterPower); // Set min index int minMonsterIndex = baseMonsterIndex - monsterVariance; if (minMonsterIndex < 0) { minMonsterIndex = 0; } // Set max index int maxMonsterIndex = baseMonsterIndex + monsterVariance; if (maxMonsterIndex >= table.Enemies.Length) { maxMonsterIndex = table.Enemies.Length; } // Get random monster from table MobileTypes type = table.Enemies[UnityEngine.Random.Range(minMonsterIndex, maxMonsterIndex)]; // Create unique LoadID for save sytem long loadID = 0; if (serialize) { loadID = (blockData.Index << 24) + obj.This; } // Add enemy AddEnemy(obj, type, parent, loadID); } else { DaggerfallUnity.LogMessage(string.Format("RDBLayout: Dungeon type {0} is out of range or unknown.", dungeonType), true); } }
public IHttpActionResult GetMobileType(MobileTypes mobiletypes) { var moblietypeRepo = new MobileTypesRepository(); var getmobiletype = moblietypeRepo.GetMobileType(mobiletypes); if (getmobiletype == null) { return(NotFound()); } return(Ok(getmobiletype)); }
public IHttpActionResult UpdateMobileTypes([FromBody] MobileTypes mobiletypes) { var mobiletypesRepo = new MobileTypesRepository(); var result = mobiletypesRepo.UpdateMobileTypes(mobiletypes); if (result <= 0) { return(Ok("Error occurred while updating Mobile Type status")); } return(Ok("Mobile Type updated")); }
private static bool IsQuestGiverInternal(string mobileTypeString) { if (!String.IsNullOrEmpty(mobileTypeString)) { MobileTypes type = (MobileTypes)Enum.Parse(typeof(MobileTypes), mobileTypeString, true); if ((type & MobileTypes.QuestGiver) == MobileTypes.QuestGiver) { return(true); } } return(false); }
void Awake() { attributes = new Attributes(); _UUID = System.Guid.NewGuid(); // TODO: Sane defaults? creatureType = MobileTypes.Acrobat; behaviour = MobileBehaviour.General; DaggerfallUnity.FindDaggerfallUnity(out dfUnity); //setupMobile(); }
public override PayloadCallbackResults?EnchantmentPayloadCallback(EnchantmentPayloadFlags context, EnchantmentParam?param = null, DaggerfallEntityBehaviour sourceEntity = null, DaggerfallEntityBehaviour targetEntity = null, DaggerfallUnityItem sourceItem = null, int sourceDamage = 0) { base.EnchantmentPayloadCallback(context, param, sourceEntity, targetEntity, sourceItem, sourceDamage); // Validate if (context != EnchantmentPayloadFlags.Strikes || targetEntity == null) { return(null); } // Change target enemy if (targetEntity.Entity is EnemyEntity) { // Get enemy entity - cannot have Wabbajack active already EnemyEntity enemy = (EnemyEntity)targetEntity.Entity; if (enemy == null || enemy.WabbajackActive) { return(null); } // Get new enemy career and transform MobileTypes enemyType = careerIDs[Random.Range(0, careerIDs.Length)]; if ((int)enemyType == enemy.CareerIndex) { enemyType = (MobileTypes)(((int)enemyType + 1) % careerIDs.Length); } Transform parentTransform = targetEntity.gameObject.transform.parent; // Do not disable enemy if in use by the quest system QuestResourceBehaviour questResourceBehaviour = targetEntity.GetComponent <QuestResourceBehaviour>(); if (questResourceBehaviour && !questResourceBehaviour.IsFoeDead) { return(null); } string[] enemyNames = TextManager.Instance.GetLocalizedTextList("enemyNames"); if (enemyNames == null) { throw new System.Exception("enemyNames array text not found"); } // Switch entity targetEntity.gameObject.SetActive(false); GameObject gameObject = GameObjectHelper.CreateEnemy(enemyNames[(int)enemyType], enemyType, targetEntity.transform.localPosition, MobileGender.Unspecified, parentTransform); DaggerfallEntityBehaviour newEnemyBehaviour = gameObject.GetComponent <DaggerfallEntityBehaviour>(); EnemyEntity newEnemy = (EnemyEntity)newEnemyBehaviour.Entity; newEnemy.WabbajackActive = true; newEnemy.CurrentHealth -= enemy.MaxHealth - enemy.CurrentHealth; // carry over damage to new monster } return(null); }
public static bool FillEmptyTrapItem(MobileTypes soulType, bool azurasStarOnly = false) { // In classic, the player's items are iterated through and the first instance found of an empty soul trap or Azura's Star is used. // Whichever is chosen first would depend on the order of the list of items, which would probably be the order in which the items were added to the inventory. // For here, fill Azura's Star first, then soul traps, as this is probably the behavior players would expect. DaggerfallUnityItem emptyTrap = null; // Get empty Azura's Star List <DaggerfallUnityItem> amulets = GameManager.Instance.PlayerEntity.Items.SearchItems(ItemGroups.Jewellery, (int)Jewellery.Amulet); foreach (DaggerfallUnityItem amulet in amulets) { if (amulet.ContainsEnchantment(EnchantmentTypes.SpecialArtifactEffect, (short)ArtifactsSubTypes.Azuras_Star) && amulet.TrappedSoulType == MobileTypes.None) { emptyTrap = amulet; break; } } // Exit if trapping to Azura's Star and it was not found or already full if (emptyTrap == null && azurasStarOnly) { return(false); } // Get another trap if (emptyTrap == null) { // Get empty soul trap List <DaggerfallUnityItem> traps = GameManager.Instance.PlayerEntity.Items.SearchItems(ItemGroups.MiscItems, (int)MiscItems.Soul_trap); foreach (DaggerfallUnityItem trap in traps) { if (trap.TrappedSoulType == MobileTypes.None) { emptyTrap = trap; break; } } } // Fill the empty trap if (emptyTrap != null) { emptyTrap.TrappedSoulType = soulType; return(true); } return(false); }
private static void AddFixedRDBEnemy(DFBlock.RdbObject obj, Transform parent) { // Get type value and ignore known invalid types int typeValue = (int)(obj.Resources.FlatResource.FactionMobileId & 0xff); if (typeValue == 99) { return; } // Cast to enum MobileTypes type = (MobileTypes)(obj.Resources.FlatResource.FactionMobileId & 0xff); AddEnemy(obj, type, parent); }
private static bool IsGoodsAndServicesSellerInternal(string mobileTypeString) { if (!String.IsNullOrEmpty(mobileTypeString)) { MobileTypes type = (MobileTypes)Enum.Parse(typeof(MobileTypes), mobileTypeString, true); if (((type & MobileTypes.Banker) == MobileTypes.Banker) || ((type & MobileTypes.Merchant) == MobileTypes.Merchant) || ((type & MobileTypes.Innkeeper) == MobileTypes.Innkeeper) || ((type & MobileTypes.Priest) == MobileTypes.Priest) || ((type & MobileTypes.Trainer) == MobileTypes.Trainer)) { return(true); } } return(false); }
public override void RestoreSaveData(object dataIn) { SaveData_v1 data = (SaveData_v1)dataIn; if (dataIn == null) { return; } spawnCount = data.spawnCount; foeType = data.foeType; injuredTrigger = data.injuredTrigger; killCount = data.killCount; displayName = data.displayName; typeName = data.typeName; }
public override void RestoreSaveData(object dataIn) { if (dataIn == null) { return; } SaveData_v1 data = (SaveData_v1)dataIn; spawnCount = data.spawnCount; foeType = data.foeType; humanoidGender = data.humanoidGender; injuredTrigger = data.injuredTrigger; restrained = data.restrained; killCount = data.killCount; displayName = data.displayName; typeName = data.typeName; }
/// <summary> /// Gets how many enemies of a given type exist. /// </summary> /// <param name="type">Enemy type to search for.</param> /// <param name="stopLookingIfFound">Return as soon as an enemy of given type is found.</param> /// <returns>Number of this enemy type.</returns> public int HowManyEnemiesOfType(MobileTypes type, bool stopLookingIfFound = false, bool includingPacified = false) { int numberOfEnemies = 0; DaggerfallEntityBehaviour[] entityBehaviours = FindObjectsOfType <DaggerfallEntityBehaviour>(); for (int i = 0; i < entityBehaviours.Length; i++) { DaggerfallEntityBehaviour entityBehaviour = entityBehaviours[i]; if (entityBehaviour.EntityType == EntityTypes.EnemyMonster || entityBehaviour.EntityType == EntityTypes.EnemyClass) { EnemyEntity entity = entityBehaviour.Entity as EnemyEntity; if (entity.MobileEnemy.ID == (int)type) { // Is it hostile or pacified? EnemyMotor enemyMotor = entityBehaviour.GetComponent <EnemyMotor>(); if (includingPacified || (enemyMotor.IsHostile && entity.Team != MobileTeams.PlayerAlly)) { numberOfEnemies++; if (stopLookingIfFound) { return(numberOfEnemies); } } } } } // Also check for enemy spawners that might emit an enemy FoeSpawner[] spawners = FindObjectsOfType <FoeSpawner>(); for (int i = 0; i < spawners.Length; i++) { // Is a spawner inside min distance? if (spawners[i].FoeType == type) { numberOfEnemies++; if (stopLookingIfFound) { return(numberOfEnemies); } } } return(numberOfEnemies); }
private IList <MobileTypes> FillMobileTypesModel(DataTable dtMobileType) { var mobiletypesList = new List <MobileTypes>(); if (null != dtMobileType && dtMobileType.Rows.Count > 0) { foreach (DataRow row in dtMobileType.Rows) { var mobiletype = new MobileTypes(); mobiletype.MobileCompanyID = Convert.ToInt32(row["MOBILE_CMPNY_ID"]); mobiletype.MobileCompany = Convert.ToString(row["MOBILE_CMPNY_DESC"]); mobiletype.MobileTypeInd = Convert.ToString(row["MOBILE_TYPE_IND"]); mobiletype.CreatedDate = Convert.ToDateTime(row["CREATED_DATE"]); mobiletype.CreatedBy = Convert.ToInt32(row["CREATED_BY"]); mobiletypesList.Add(mobiletype); } } return(mobiletypesList); }
public IMobile GetMobileByName(MobileTypes mobileName) { var nullMobile = NullObject.Instance; switch (mobileName) { case MobileTypes.AppleIphone: return(new Iphone()); case MobileTypes.SamsungGalaxy: return(new SamsungGalaxy()); case MobileTypes.NokiaN97: return(new NokiaN97()); default: return(nullMobile); } }
static Weapons GetCombatClassWeapon(MobileTypes enemyType) { switch (enemyType) { case MobileTypes.Barbarian: return(RandomBigWeapon()); case MobileTypes.Knight: return(CoinFlip() ? RandomBlunt() : RandomLongblade()); case MobileTypes.Knight_CityWatch: return(RandomAxeOrBlade()); case MobileTypes.Monk: return(RandomBlunt()); default: return(RandomLongblade()); } }
public override void MagicRound() { base.MagicRound(); DaggerfallEntityBehaviour entityBehaviour = GetPeeredEntityBehaviour(manager); if (!entityBehaviour) { return; } if (entityBehaviour.Entity is EnemyEntity) { EnemyEntity enemy = (EnemyEntity)entityBehaviour.Entity; if (enemy.WabbajackActive) { return; } MobileTypes enemyType = careerIDs[Random.Range(0, careerIDs.Length)]; if ((int)enemyType == enemy.CareerIndex) { enemyType = (MobileTypes)(((int)enemyType + 1) % careerIDs.Length); } Transform parentTransform = entityBehaviour.gameObject.transform.parent; // Do not disable enemy if in use by the quest system QuestResourceBehaviour questResourceBehaviour = entityBehaviour.GetComponent <QuestResourceBehaviour>(); if (questResourceBehaviour) { if (!questResourceBehaviour.IsFoeDead) { return; } } entityBehaviour.gameObject.SetActive(false); GameObject gameObject = GameObjectHelper.CreateEnemy(HardStrings.enemyNames[(int)enemyType], enemyType, entityBehaviour.transform.localPosition, parentTransform); DaggerfallEntityBehaviour newEnemyBehaviour = gameObject.GetComponent <DaggerfallEntityBehaviour>(); EnemyEntity newEnemy = (EnemyEntity)newEnemyBehaviour.Entity; newEnemy.WabbajackActive = true; newEnemy.CurrentHealth -= enemy.MaxHealth - enemy.CurrentHealth; // carry over damage to new monster } }
/// <summary> /// Gets how many enemies of a given type exist. /// </summary> /// <param name="type">Enemy type to search for.</param> /// <param name="stopLookingIfFound">Return as soon as an enemy of given type is found.</param> /// <returns>Number of this enemy type.</returns> public int HowManyEnemiesOfType(MobileTypes type, bool stopLookingIfFound = false) { int numberOfEnemies = 0; DaggerfallEntityBehaviour[] entityBehaviours = FindObjectsOfType <DaggerfallEntityBehaviour>(); for (int i = 0; i < entityBehaviours.Length; i++) { DaggerfallEntityBehaviour entityBehaviour = entityBehaviours[i]; if (entityBehaviour.EntityType == EntityTypes.EnemyMonster || entityBehaviour.EntityType == EntityTypes.EnemyClass) { EnemyEntity entity = entityBehaviour.Entity as EnemyEntity; if (entity.MobileEnemy.ID == (int)type) { numberOfEnemies++; if (stopLookingIfFound) { return(numberOfEnemies); } } } } // Also check for enemy spawners that might emit an enemy FoeSpawner[] spawners = FindObjectsOfType <FoeSpawner>(); for (int i = 0; i < spawners.Length; i++) { // Is a spawner inside min distance? if (spawners[i].FoeType == type) { numberOfEnemies++; if (stopLookingIfFound) { return(numberOfEnemies); } } } return(numberOfEnemies); }
private void AddRandomRDBEnemy(DFBlock.RdbObject obj) { // Get dungeon type index int index = (int)dungeonType >> 8; if (index < RandomEncounters.EncounterTables.Length) { // Get encounter table RandomEncounterTable table = RandomEncounters.EncounterTables[index]; // Get random monster from table // Normally this would be weighted by player level MobileTypes type = table.Enemies[UnityEngine.Random.Range(0, table.Enemies.Length)]; // Add enemy AddEnemy(obj, type); } else { DaggerfallUnity.LogMessage(string.Format("RDBLayout: Dungeon type {0} is out of range or unknown.", dungeonType), true); } }
private void AddEnemy(DFBlock.RdbObject obj, MobileTypes type) { // Get default reaction MobileReactions reaction = MobileReactions.Hostile; if (obj.Resources.FlatResource.FlatData.Reaction == (int)DFBlock.EnemyReactionTypes.Passive) { reaction = MobileReactions.Passive; } // Spawn enemy gameobject GameObject go = GameObjectHelper.CreateDaggerfallEnemyGameObject(type, enemiesNode.transform, reaction); if (go == null) { return; } // Set transform Vector3 enemyPosition = new Vector3(obj.XPos, -obj.YPos, obj.ZPos) * MeshReader.GlobalScale; go.transform.position = enemyPosition; }
/// <summary> /// Gets enemy definition based on type. /// Runs a brute force search for ID, so use sparingly. /// Store a dictionary from GetEnemyDict() for faster lookups. /// </summary> /// <param name="enemyType">Enemy type to extract definition.</param> /// <param name="mobileEnemyOut">Receives details of enemy type.</param> /// <returns>True if successful.</returns> public static bool GetEnemy(MobileTypes enemyType, out MobileEnemy mobileEnemyOut) { // Cast type enum to ID. // You can add additional IDs to enum to create new enemies. int id = (int)enemyType; // Search for matching definition in enemy list. // Don't forget to add new enemy IDs to Enemies definition array. for (int i = 0; i < Enemies.Length; i++) { if (Enemies[i].ID == id) { mobileEnemyOut = Enemies[i]; return true; } } // No match found, just return an empty definition mobileEnemyOut = new MobileEnemy(); return false; }
/// <summary> /// Change enemy settings and configure in a single call. /// </summary> /// <param name="enemyType">Enemy type.</param> public void ApplyEnemySettings(MobileTypes enemyType, MobileReactions enemyReaction) { EnemyType = enemyType; EnemyReaction = enemyReaction; ApplyEnemySettings(); }
private static void AddEnemy( DFBlock.RdbObject obj, MobileTypes type, Transform parent = null, long loadID = 0) { // Get default reaction MobileReactions reaction = MobileReactions.Hostile; if (obj.Resources.FlatResource.Action == (int)DFBlock.EnemyReactionTypes.Passive) reaction = MobileReactions.Passive; // Just setup demo enemies at this time string name = string.Format("DaggerfallEnemy [{0}]", type.ToString()); Vector3 position = new Vector3(obj.XPos, -obj.YPos, obj.ZPos) * MeshReader.GlobalScale; GameObject go = GameObjectHelper.InstantiatePrefab(DaggerfallUnity.Instance.Option_EnemyPrefab.gameObject, name, parent, position); SetupDemoEnemy setupEnemy = go.GetComponent<SetupDemoEnemy>(); if (setupEnemy != null) { // Configure enemy setupEnemy.ApplyEnemySettings(type, reaction); // Align non-flying units with ground DaggerfallMobileUnit mobileUnit = setupEnemy.GetMobileBillboardChild(); if (mobileUnit.Summary.Enemy.Behaviour != MobileBehaviour.Flying) GameObjectHelper.AlignControllerToGround(go.GetComponent<CharacterController>()); } DaggerfallEnemy enemy = go.GetComponent<DaggerfallEnemy>(); if (enemy) { enemy.LoadID = loadID; } }