コード例 #1
0
        void OnTriggerEnter(Collider other)
        {
            if (Triggered)
            {
                return;
            }

            //reject not-player if we're not allowing not-player
            if (OnPlayerOnly && other.gameObject == WorldUtils.GetPlayerObject())
            {
                return;
            }

            //execute special
            var activator = other.GetComponent <BaseController>();
            var data      = new ActionInvokerData()
            {
                Activator = activator
            };

            Special.Invoke(data);

            //lock if not repeatable
            if (!Repeatable)
            {
                Triggered = true;
                SaveState();
            }
        }
コード例 #2
0
        public void Activate(string targetString)
        {
            //decode string and point camera
            if (targetString.StartsWith("Player", StringComparison.OrdinalIgnoreCase))
            {
                //face player
                Transform playerTarget = WorldUtils.GetPlayerObject().transform;
                float     distance     = 1.0f;

                var dct = playerTarget.GetComponentInChildren <DialogueCameraTarget>();
                if (dct != null)
                {
                    playerTarget = dct.transform;

                    if (dct.DistanceOverride > 0)
                    {
                        distance = dct.DistanceOverride;
                    }
                }

                PointToTarget(playerTarget.position, playerTarget.forward, distance);
            }
            else if (targetString.StartsWith("FaceTarget", StringComparison.OrdinalIgnoreCase))
            {
                string tid = targetString.Substring(targetString.IndexOf(':') + 1);

                //face target
                Transform t        = WorldUtils.FindObjectByTID(tid).transform;
                float     distance = 1.0f;

                var dct = t.GetComponentInChildren <DialogueCameraTarget>();
                if (dct != null)
                {
                    t = dct.transform;

                    if (dct.DistanceOverride > 0)
                    {
                        distance = dct.DistanceOverride;
                    }
                }

                PointToTarget(t.position, t.forward, distance);
            }
            else if (targetString.StartsWith("CopyTransform", StringComparison.OrdinalIgnoreCase))
            {
                //copy transform
                string    tid = targetString.Substring(targetString.IndexOf(':') + 1);
                Transform t   = WorldUtils.FindObjectByTID(tid).transform;

                transform.position = t.position;
                transform.rotation = t.rotation;
            }
            else
            {
                throw new NotSupportedException();
            }

            Camera.gameObject.SetActive(true);
        }
コード例 #3
0
        private void CompleteItemDrop(InventoryItemInstance itemInstance, InventoryItemModel itemModel, int quantity, ModalStatusCode status)
        {
            if (quantity == 0 || status != ModalStatusCode.Complete)
            {
                return;
            }

            GameState.Instance.PlayerRpgState.Inventory.RemoveItem(itemInstance, quantity);
            Transform playerT = WorldUtils.GetPlayerObject().transform;
            Vector3   dropPos = (playerT.position + (playerT.forward.normalized * 1.0f));

            RpgWorldUtils.DropItem(itemModel, quantity, dropPos);

            SignalPaint();
        }
コード例 #4
0
        /// <summary>
        /// Gets the current player controller
        /// </summary>
        /// <returns></returns>
        public static PlayerController GetPlayerController()
        {
            //TODO split into Get and TryGet

            PlayerController pc = WorldUtils.GetPlayerObject()?.GetComponent <PlayerController>(); //should be safe because GetPlayerObject returns true null

            if (pc != null)
            {
                return(pc);
            }
            else
            {
                Debug.LogWarning("Couldn't find PlayerController!");
                return(null);
            }
        }
コード例 #5
0
        private string ResolveSpecialObjectName(string objectName)
        {
            if (objectName.StartsWith("#")) //interpret this literally
            {
                return(objectName.TrimStart('#'));
            }

            //resolve Player and Target
            if (objectName.Equals("Player", StringComparison.OrdinalIgnoreCase))
            {
                return(WorldUtils.GetPlayerObject().name);
            }

            if (objectName.Equals("Target", StringComparison.OrdinalIgnoreCase))
            {
                return(CurrentTarget);
            }

            return(objectName);
        }
コード例 #6
0
ファイル: MapPanelController.cs プロジェクト: XCVG/quattro
        public override void SignalPaint()
        {
            ClearPanel();

            //grab map name from string tables
            string sceneName   = SceneManager.GetActiveScene().name;
            string realMapName = StringSub.Sub.Replace(sceneName, "MAPS");

            TitleText.text = realMapName;

            //get cartographer
            Cartographer cartographer = Cartographer.Current;

            if (cartographer == null)
            {
                Debug.LogWarning("No cartographer exists!");
                ClearPanel();
                return;
            }

            //push map
            MapImage.texture = cartographer.MapTexture;

            //scale image
            if (MapImage.texture != null)
            {
                float ratio     = (float)MapImage.texture.height / (float)MapImage.texture.width;
                float newHeight = ratio * MapImage.rectTransform.rect.width;
                MapImage.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, newHeight);
                MapImage.rectTransform.ForceUpdateRectTransforms();
            }

            //draw player if applicable
            if (cartographer.ShowPlayer)
            {
                DrawIcon(WorldUtils.GetPlayerObject().transform.position, PlayerIcon, cartographer, GameState.Instance?.PlayerRpgState?.DisplayName);
            }

            DrawMarkers(cartographer);
        }
コード例 #7
0
        private void SelectTarget()
        {
            var gameplayConfig = ConfigState.Instance.GetGameplayConfig();

            if (TotalTickCount % SearchInterval * (1f / gameplayConfig.Difficulty.ActorAggression) != 0)
            {
                return;
            }

            var detectionDifficultyFactor = 1f / gameplayConfig.Difficulty.ActorPerception;

            //check player first since it's (relatively) cheap
            if (FactionModel.GetRelation(Faction, "Player") == FactionRelationStatus.Hostile && !MetaState.Instance.SessionFlags.Contains("NoTarget") && !GameState.Instance.PlayerFlags.Contains(PlayerFlags.NoTarget))
            {
                var playerObj = WorldUtils.GetPlayerObject();
                if (playerObj != null && RpgWorldUtils.TargetIsAlive(playerObj.transform))
                {
                    PlayerController pc = playerObj.GetComponent <PlayerController>();

                    if ((playerObj.transform.position - transform.position).magnitude <= SearchRadius &&
                        UnityEngine.Random.Range(0f, 1f * detectionDifficultyFactor) <= RpgValues.DetectionChance(GameState.Instance.PlayerRpgState, pc.MovementComponent.IsCrouching, pc.MovementComponent.IsRunning))
                    {
                        if (UseLineOfSight)
                        {
                            //additional check
                            RaycastHit hitinfo;
                            if (Physics.Raycast(transform.position + new Vector3(0, 1.0f, 0), (playerObj.transform.position - transform.position), out hitinfo))
                            {
                                if (hitinfo.collider.gameObject == playerObj)
                                {
                                    Target = playerObj.transform;
                                    return;
                                }
                            }
                        }
                        else
                        {
                            //otherwise, close enough
                            Target = playerObj.transform;
                            return;
                        }
                    }
                }
            }

            //if(TargetNpc)
            {
                //var sw = System.Diagnostics.Stopwatch.StartNew();

                //new code should be faster if n is large but it may not bear out in practice, and it probably allocs more dedotated wam

                var colliders = Physics.OverlapSphere(transform.position, SearchRadius, LayerMask.GetMask("Default", "ActorHitbox"));
                HashSet <ActorController> potentialTargets = new HashSet <ActorController>();

                foreach (var collider in colliders)
                {
                    var actorController = collider.GetComponent <ActorController>();
                    if (actorController != null)
                    {
                        potentialTargets.Add(actorController);
                        break;
                    }

                    var hitboxComponent = collider.GetComponent <IHitboxComponent>();
                    if (hitboxComponent != null && hitboxComponent.ParentController is ActorController hitboxAC)
                    {
                        potentialTargets.Add(hitboxAC);
                        break;
                    }
                }


                //old stupid code: should work well enough as long as n is small and your computer is fast enough
                //IEnumerable<ActorController> potentialTargets = transform.root.GetComponentsInChildren<ActorController>();

                foreach (var potentialTarget in potentialTargets)
                {
                    if (RpgWorldUtils.TargetIsAlive(potentialTarget.transform) &&
                        (potentialTarget.transform.position - transform.position).magnitude <= SearchRadius &&
                        FactionModel.GetRelation(Faction, potentialTarget.Faction) == FactionRelationStatus.Hostile &&
                        !(potentialTarget == this))
                    {
                        //roll some dice
                        if (potentialTarget.Detectability < 1 && UnityEngine.Random.Range(0f, 1f * detectionDifficultyFactor) > potentialTarget.Detectability) //probably correct
                        {
                            continue;
                        }

                        if (UseLineOfSight)
                        {
                            //additional check
                            RaycastHit hitinfo;
                            if (Physics.Raycast(transform.position + new Vector3(0, 1.0f, 0), (potentialTarget.transform.position - transform.position), out hitinfo))
                            {
                                if (hitinfo.collider.gameObject == potentialTarget.gameObject)
                                {
                                    Target = potentialTarget.transform;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            //otherwise, close enough
                            Target = potentialTarget.transform;
                            break;
                        }
                    }
                }

                //sw.Stop();
                //Debug.Log($"Target lookup: {sw.Elapsed.TotalMilliseconds:F4} ms");
            }

            if (!RpgWorldUtils.TargetIsAlive(Target))
            {
                Target = null;
            }
        }
コード例 #8
0
        private void SelectTarget()
        {
            var gameplayConfig = ConfigState.Instance.GetGameplayConfig();

            if (TotalTickCount % SearchInterval * (1f / gameplayConfig.Difficulty.ActorAggression) != 0)
            {
                return;
            }

            if (TargetPicker != null)
            {
                Target = TargetPicker();
                return;
            }

            var detectionDifficultyFactor = 1f / gameplayConfig.Difficulty.ActorPerception;

            //check player first since it's (relatively) cheap
            if (GameState.Instance.FactionState.GetRelation(Faction, "Player") == FactionRelationStatus.Hostile && !MetaState.Instance.SessionFlags.Contains("NoTarget") && !GameState.Instance.PlayerFlags.Contains(PlayerFlags.NoTarget))
            {
                var playerObj = WorldUtils.GetPlayerObject();
                if (playerObj != null && RpgWorldUtils.TargetIsAlive(playerObj.transform))
                {
                    PlayerController pc = playerObj.GetComponent <PlayerController>();

                    if ((playerObj.transform.position - transform.position).magnitude <= SearchRadius &&
                        UnityEngine.Random.Range(0f, 1f * detectionDifficultyFactor) <= ((IAmTargetable)pc).Detectability)
                    {
                        if (UseLineOfSight)
                        {
                            if (CheckLineOfSight(pc))
                            {
                                Target = playerObj.transform;
                                return;
                            }
                        }
                        else
                        {
                            //otherwise, close enough
                            Target = playerObj.transform;
                            return;
                        }
                    }
                }
            }

            //if(TargetNpc)
            {
                //var sw = System.Diagnostics.Stopwatch.StartNew();

                //new code should be faster if n is large but it may not bear out in practice, and it probably allocs more dedotated wam

                var colliders = Physics.OverlapSphere(transform.position, SearchRadius, WorldUtils.GetAttackLayerMask());
                HashSet <IAmTargetable> potentialTargets = new HashSet <IAmTargetable>();

                foreach (var collider in colliders)
                {
                    var baseController = collider.GetComponent <BaseController>();
                    if (baseController != null)
                    {
                        if (baseController is IAmTargetable iat && iat.ValidTarget)
                        {
                            potentialTargets.Add(iat);
                        }
                        continue; //continue anyway since we've found a base controller and it's either targetable or it's not
                    }

                    var hitboxComponent = collider.GetComponent <IHitboxComponent>();
                    if (hitboxComponent != null && hitboxComponent.ParentController is IAmTargetable iat2 && iat2.ValidTarget)
                    {
                        potentialTargets.Add(iat2);
                        continue;
                    }
                }


                //old stupid code: should work well enough as long as n is small and your computer is fast enough
                //IEnumerable<ActorController> potentialTargets = transform.root.GetComponentsInChildren<ActorController>();

                foreach (var potentialTarget in potentialTargets)
                {
                    BaseController targetController = potentialTarget as BaseController;
                    if (targetController == null)
                    {
                        continue;
                    }

                    if (RpgWorldUtils.TargetIsAlive(targetController.transform) &&
                        (targetController.transform.position - transform.position).magnitude <= SearchRadius &&
                        GameState.Instance.FactionState.GetRelation(Faction, potentialTarget.Faction) == FactionRelationStatus.Hostile &&
                        !(potentialTarget == this))
                    {
                        //roll some dice
                        if (potentialTarget.Detectability < 1 && UnityEngine.Random.Range(0f, 1f * detectionDifficultyFactor) > potentialTarget.Detectability) //probably correct
                        {
                            continue;
                        }

                        if (UseLineOfSight)
                        {
                            if (CheckLineOfSight(targetController))
                            {
                                Target = targetController.transform;
                                break;
                            }
                        }
                        else
                        {
                            //otherwise, close enough
                            Target = targetController.transform;
                            break;
                        }
                    }
                }

                //sw.Stop();
                //Debug.Log($"Target lookup: {sw.Elapsed.TotalMilliseconds:F4} ms");
            }

            if (!RpgWorldUtils.TargetIsAlive(Target))
            {
                Target = null;
            }
        }