LookAt() public method

Looks at the NPC
public LookAt ( ) : bool
return bool
Example #1
0
 protected void ResolveNPCs()
 {
     if (NPC1 != null)
     {
         NPC1.LookAt(Player.transform);
     }
     if (NPC2 != null)
     {
         NPC2.LookAt(Player.transform);
     }
 }
Example #2
0
        public void OnNPCAtJob(ref NPCBase.NPCState state)
        {
            try
            {
                var currentposition = NPC.Position;
                _hadAmmo.Clear();

                if (_inv.Weapon != null && !_inv.Weapon.IsEmpty())
                {
                    if (_target == null || !_target.IsValid)
                    {
                        _target = MonsterTracker.Find(currentposition, 100, WeaponFactory.WeaponLookup[_inv.Weapon.Id].Damage.TotalDamage());
                    }

                    if (_target != null && _target.IsValid)
                    {
                        state.SetIndicator(new IndicatorState(COOLDOWN, _inv.Weapon.Id));
                        state.SetCooldown(COOLDOWN);
                        NPC.LookAt(_target.Position);
                        AudioManager.SendAudio(_target.PositionToAimFor, "punch");

                        _target.OnHit(WeaponFactory.WeaponLookup[_inv.Weapon.Id].Damage.TotalDamage());
                        _waitingFor = 0;
                    }
                    else
                    {
                        state.SetIndicator(new IndicatorState(COOLDOWN, ItemId.GetItemId(GameLoader.NAMESPACE + ".Monster").Id, true));
                        state.SetCooldown(COOLDOWN);
                        _waitingFor++;
                        _target = null;
                    }
                }
                else
                {
                    if (_target == null || !_target.IsValid || !VoxelPhysics.CanSee(NPC.Position.Vector, _target.Position))
                    {
                        _target = MonsterTracker.Find(currentposition, _weapon.Range, _weapon.Damage);
                    }

                    if (_target != null && _target.IsValid && VoxelPhysics.CanSee(NPC.Position.Vector, _target.Position))
                    {
                        foreach (var projectile in _weapon.ShootItem)
                        {
                            _hadAmmo[projectile] = false;

                            if (NPC.Inventory.Contains(projectile))
                            {
                                _hadAmmo[projectile] = true;
                                continue;
                            }

                            if (_stock.Contains(projectile))
                            {
                                _hadAmmo[projectile] = true;
                            }
                        }

                        if (!_hadAmmo.Any(a => !a.Value))
                        {
                            state.SetIndicator(new IndicatorState(_weapon.CooldownShot, _weapon.ShootItem[0].Type));

                            foreach (var ammo in _hadAmmo)
                            {
                                if (NPC.Inventory.Contains(ammo.Key))
                                {
                                    NPC.Inventory.TryRemove(ammo.Key);
                                    continue;
                                }

                                if (_stock.Contains(ammo.Key))
                                {
                                    _stock.TryRemove(ammo.Key);
                                }
                            }

                            NPC.LookAt(_target.Position);

                            if (_weapon.OnShootAudio != null)
                            {
                                AudioManager.SendAudio(Position.Vector, _weapon.OnShootAudio);
                            }

                            if (_weapon.OnHitAudio != null)
                            {
                                AudioManager.SendAudio(_target.PositionToAimFor, _weapon.OnHitAudio);
                            }

                            if (_weapon.ShootItem.Count > 0)
                            {
                                foreach (var proj in _weapon.ShootItem)
                                {
                                    var projName = ItemTypes.IndexLookup.GetName(proj.Type);

                                    if (AnimationManager.AnimatedObjects.ContainsKey(projName))
                                    {
                                        AnimationManager.AnimatedObjects[projName].SendMoveToInterpolated(Position.Vector, _target.PositionToAimFor);

                                        break;
                                    }
                                }
                            }

                            ServerManager.SendParticleTrail(currentposition.Vector, _target.PositionToAimFor, 2);
                            _target.OnHit(_weapon.Damage);
                            state.SetCooldown(_weapon.CooldownShot);
                            _waitingFor = 0;
                        }
                        else
                        {
                            state.SetIndicator(new IndicatorState(_weapon.CooldownMissingItem, _weapon.ShootItem[0].Type, true));
                            state.SetCooldown(_weapon.CooldownMissingItem);
                        }
                    }
                    else
                    {
                        state.SetIndicator(new IndicatorState(_weapon.CooldownSearchingTarget, ItemId.GetItemId(GameLoader.NAMESPACE + ".Monster").Id, true));
                        state.SetCooldown(_weapon.CooldownMissingItem);
                        _target = null;
                    }
                }
            }
            catch (Exception)
            {
                state.SetIndicator(new IndicatorState(_weapon.CooldownSearchingTarget, ItemId.GetItemId(GameLoader.NAMESPACE + ".Monster").Id, true));
                state.SetCooldown(_weapon.CooldownMissingItem);
                _target = null;
            }
        }
Example #3
0
        public override void OnNPCAtJob(ref NPCBase.NPCState state)
        {
            var  status             = ItemId.GetItemId(GameInitializer.NAMESPACE + ".Waiting");
            var  cooldown           = COOLDOWN;
            var  allActionsComplete = false;
            bool actionFound        = false;

            try
            {
                if (TargetObjective != null && NPC != null)
                {
                    NPC.LookAt(TargetObjective.Position.Vector);

                    foreach (var action in new Dictionary <string, float>(TargetObjective.ActionEnergy))
                    {
                        if (action.Value < .5f)
                        {
                            if (TargetObjective.RoamingJobSettings.ActionCallbacks.TryGetValue(action.Key, out var roamingJobObjective))
                            {
                                status   = roamingJobObjective.PreformAction(Owner, TargetObjective);
                                cooldown = roamingJobObjective.TimeToPreformAction;
                                AudioManager.SendAudio(TargetObjective.Position.Vector, roamingJobObjective.AudioKey);
                                actionFound = true;
                            }
                        }
                    }

                    if (!actionFound)
                    {
                        PreviousObjective      = null;
                        TargetObjective.JobRef = null;
                        TargetObjective        = null;
                        allActionsComplete     = true;
                    }
                }

                // if the objective is gone, Abort.
                CheckIfValidObjective();

                if (OkStatus.Contains(status))
                {
                    if (actionFound)
                    {
                        ActionsPreformed++;
                    }

                    _stuckCount = 0;
                }
                else if (status != 0)
                {
                    _stuckCount++;
                }

                if (_stuckCount > 5 || TargetObjective == null)
                {
                    state.JobIsDone = true;
                    status          = ItemId.GetItemId(GameInitializer.NAMESPACE + ".Waiting");

                    if (allActionsComplete)
                    {
                        cooldown = 0.5f;
                    }

                    if (_stuckCount > 5)
                    {
                        PreviousObjective      = TargetObjective;
                        TargetObjective.JobRef = null;
                        TargetObjective        = null;
                    }
                }

                if (OkStatus.Contains(status))
                {
                    state.SetIndicator(new IndicatorState(cooldown, status.Id));
                }
                else if (status != 0)
                {
                    state.SetIndicator(new IndicatorState(cooldown, status.Id, true));
                }
                else
                {
                    state.SetIndicator(new IndicatorState(cooldown, ColonyBuiltIn.ItemTypes.MISSINGERROR.Name));
                }
            }
            catch (Exception ex)
            {
                APILogger.LogError(ex);
            }

            state.SetCooldown(cooldown);
        }