// Creates a new pool item with NPC prefab - returns -1 if could not be created int CreateNewPoolItem() { // Must have an NPC prefab set if (!DaggerfallUnity.Instance.Option_MobileNPCPrefab) { return(-1); } // Instantiate NPC prefab GameObject go = GameObjectHelper.InstantiatePrefab(DaggerfallUnity.Instance.Option_MobileNPCPrefab.gameObject, mobileNPCName, dfLocation.transform, Vector3.zero); go.SetActive(false); // Get MobilePersonNPC reference MobilePersonNPC npc = go.GetComponent <MobilePersonNPC>(); // Get motor and set reference to navgrid MobilePersonMotor motor = go.GetComponent <MobilePersonMotor>(); motor.cityNavigation = cityNavigation; // Create the pool item and assign new GameObject // This pool item starts inactive and can be used later PoolItem poolItem = new PoolItem(); poolItem.npc = npc; poolItem.npc.Motor = motor; // Add to pool populationPool.Add(poolItem); return(populationPool.Count - 1); }
protected override void Start() { npcMotor = GetComponent <MobilePersonNPC>(); controller = GetComponent <CharacterController>(); mobile = GetComponent <DaggerfallMobileUnit>(); base.Start(); }
/// <summary> /// Handle shared logic when player attacks entity. /// </summary> public void HandleAttackFromSource(DaggerfallEntityBehaviour sourceEntityBehaviour) { // Break "normal power" concealment effects on source if (sourceEntityBehaviour.Entity.IsMagicallyConcealedNormalPower) { EntityEffectManager.BreakNormalPowerConcealmentEffects(sourceEntityBehaviour); } // When source is player if (sourceEntityBehaviour == GameManager.Instance.PlayerEntityBehaviour) { // Handle civilian NPC crime reporting if (EntityType == EntityTypes.CivilianNPC) { PlayerEntity playerEntity = GameManager.Instance.PlayerEntity; MobilePersonNPC mobileNpc = transform.GetComponent <MobilePersonNPC>(); if (mobileNpc) { // Handle assault or murder if (Entity.CurrentHealth > 0) { playerEntity.CrimeCommitted = PlayerEntity.Crimes.Assault; playerEntity.SpawnCityGuards(true); } else { playerEntity.TallyCrimeGuildRequirements(false, 5); // TODO: LOS check from each townsperson. If seen, register crime and start spawning guards as below. playerEntity.CrimeCommitted = PlayerEntity.Crimes.Murder; playerEntity.SpawnCityGuards(true); // Disable when dead mobileNpc.Motor.gameObject.SetActive(false); } } } // Handle mobile enemy aggro if (EntityType == EntityTypes.EnemyClass || EntityType == EntityTypes.EnemyMonster) { // Make enemy aggressive to player EnemyMotor enemyMotor = transform.GetComponent <EnemyMotor>(); if (enemyMotor) { if (!enemyMotor.IsHostile) { GameManager.Instance.MakeEnemiesHostile(); } enemyMotor.MakeEnemyHostileToAttacker(GameManager.Instance.PlayerEntityBehaviour); } } } }
public Marker() { markerObject = null; markerIcon = null; markerType = Minimap.MarkerGroups.None; isActive = false; inVision = false; inLOS = false; markerLayerMask = 10; markerDistance = 0; enemySenses = null; npcMesh = null; npcMarkerColor = Color.magenta; mobileNPC = null; mobileEnemy = null; flatNPC = null; }
/// <summary> /// Handle shared logic when player attacks entity. /// </summary> public void HandleAttackFromSource(DaggerfallEntityBehaviour sourceEntityBehaviour) { // Break "normal power" concealment effects on source if (sourceEntityBehaviour.Entity.IsMagicallyConcealedNormalPower) { EntityEffectManager.BreakNormalPowerConcealmentEffects(sourceEntityBehaviour); } // When source is player if (sourceEntityBehaviour == GameManager.Instance.PlayerEntityBehaviour) { PlayerEntity playerEntity = GameManager.Instance.PlayerEntity; // Handle civilian NPC crime reporting if (EntityType == EntityTypes.CivilianNPC) { MobilePersonNPC mobileNpc = transform.GetComponent <MobilePersonNPC>(); if (mobileNpc) { // Handle assault or murder if (Entity.CurrentHealth > 0) { playerEntity.CrimeCommitted = PlayerEntity.Crimes.Assault; playerEntity.SpawnCityGuards(true); } else { if (!mobileNpc.IsGuard) { playerEntity.TallyCrimeGuildRequirements(false, 5); playerEntity.CrimeCommitted = PlayerEntity.Crimes.Murder; playerEntity.SpawnCityGuards(true); } else { playerEntity.CrimeCommitted = PlayerEntity.Crimes.Assault; playerEntity.SpawnCityGuard(mobileNpc.transform.position, mobileNpc.transform.forward); } // Disable when dead mobileNpc.Motor.gameObject.SetActive(false); } } } // Handle mobile enemy aggro if (EntityType == EntityTypes.EnemyClass || EntityType == EntityTypes.EnemyMonster) { // Make enemy aggressive to player EnemyMotor enemyMotor = transform.GetComponent <EnemyMotor>(); if (enemyMotor) { if (!enemyMotor.IsHostile) { GameManager.Instance.MakeEnemiesHostile(); } enemyMotor.MakeEnemyHostileToAttacker(GameManager.Instance.PlayerEntityBehaviour); } // Handle killing guards EnemyEntity enemyEntity = entity as EnemyEntity; if (enemyEntity.MobileEnemy.ID == (int)MobileTypes.Knight_CityWatch && entity.CurrentHealth <= 0) { playerEntity.TallyCrimeGuildRequirements(false, 1); playerEntity.CrimeCommitted = PlayerEntity.Crimes.Murder; } } } }