Example #1
0
        public override IActivity <PhysicalActor> GetActivity()
        {
            GameObject?bestWeapon     = null;
            double     bestMultiplier = 1.0;

            foreach (GameObject item in Actor.Contents)
            {
                if (item.Is(out Weapon? weapon))
                {
                    if (weapon.DamageMultiplier > bestMultiplier)
                    {
                        bestWeapon     = item;
                        bestMultiplier = weapon.DamageMultiplier;
                    }
                }
            }
            if (bestWeapon is null)
            {
                return(Do <UnarmedStrike>(Target));
            }
            else
            {
                return(Do <WeaponStrike>(Target, bestWeapon));
            }
        }
Example #2
0
        //Movable end

        public GameObject(GameObject?parent = null)
        {
            ID = currentMaxID;
            currentMaxID++;
            this.Parent = parent;
            Debug(this, "has been newed . ");
        }
Example #3
0
        public void Spawn(Vector3 location, Quaternion rotation, Vector3 speen, Vector3 force)
        {
            _spawnedObj = GameObject.Instantiate(_obj, location, rotation);
            //Assign `GetComponent`s to a variable, because `GetComponent` is resource intensive
            Rigidbody objphys = _spawnedObj.GetComponent <Rigidbody>();

            objphys.AddTorque(speen);

            objphys.AddForce(force);

            //If it aint a grenade, dont touch it, or if you dont want it to go BOOM
            if (!_isGrenade || !_primeGrenade)
            {
                return;
            }

            PinnedGrenade grenade;

            try
            {
                grenade = _spawnedObj.GetComponent <PinnedGrenade>();
            }
            catch (Exception e)
            {
                Debug.Log($"Could not find PinnedGrenade component on {_spawnedObj.name}");
                Debug.Log(e.Message);
                return;
            }
            grenade.ReleaseLever();
        }
Example #4
0
 private void StopLockOn()
 {
     Find.PlayerState.RotateBlocked.Remove(this);
     LockOnDispose?.Dispose();
     LockOnDispose = null;
     LockOnTarget  = null;
 }
Example #5
0
        public virtual void ConsumeGameObject(GameObject obj)
        {
            myGameObject = obj;
            obj.SetActive(myVisible);

            OnInstanceCreated?.Invoke(obj);
        }
Example #6
0
 public GameContext(IEntityManager entityManager, ITimeManager timeManager)
 {
     this.RandomGeneratorManager = new RandomGeneratorManager();
     this.EntityManager          = entityManager;
     this.TimeManager            = timeManager;
     this.player = null;
 }
        private void PrepareWarningText()
        {
            _peakWarningGo = new GameObject("DiffWarningCanvas");
            var canvas = _peakWarningGo.AddComponent <Canvas>();

            canvas.renderMode = RenderMode.WorldSpace;

            _peakWarningGo.AddComponent <CurvedCanvasSettings>().SetRadius(0f);

            var ct = canvas.transform;

            ct.position    = new Vector3(0, 2.25f, 3.5f);
            ct.localScale /= 100;

            if (ct is RectTransform crt)
            {
                crt.sizeDelta = new Vector2(140, 50);

                _text           = BeatSaberUI.CreateText <TextMeshProUGUI>(crt, string.Empty, Vector2.zero);
                _text.alignment = TextAlignmentOptions.Center;
                _text.fontSize  = 16f;
                _text.alpha     = 0f;
            }

            _peakWarningGo.SetActive(false);

            _timeTillPeak = _audioTimeSyncController.songLength;
        }
Example #8
0
 public GameObject GetPlayer()
 {
     if (player == null)
     {
         player = EntityManager.FindObjectWithTag("Player");
     }
     return(player !);
 }
Example #9
0
 public bool Add(GameObject gameObject)
 {
     if (IsAllowed(gameObject))
     {
         _gameObject = gameObject;
         return(true);
     }
     return(false);
 }
Example #10
0
 void initiateLoadLevel(int?index = null)
 {
     // load Scene and set (every 'instance') of Scene relevant Objects to NULL, e.g. contentText, answerText
     SceneManager.LoadScene(index is null ? (int)SCENE_IDENTIFIER : (int)index);
     channelDictonary[TEXT.contentText] = contentText = null;
     channelDictonary[TEXT.answerText]  = answerText = null;
     answerGameObj = mcAnsGameObj = null;
     mcAnswers     = null;
     checkButton   = null;
 }
Example #11
0
        public GameObject ProcNotNull(Vector2 source, Vector2 target, float targetPerimeterRadius)
        {
            GameObject?w = ProcGO(source, target, targetPerimeterRadius);

            if (w == null)
            {
                throw new Exception("EffectStrategy.ProcNotNull called with null result");
            }
            return(w);
        }
Example #12
0
 private void Awake()
 {
     tr = transform;
     lastRequestedBGC    = NextSceneStartupBGC;
     NextSceneStartupBGC = null;
     MaybeCreateFirst();
     Time = 0f;
     Instantiate(backgroundCombiner, Vector3.zero, Quaternion.identity)
     .GetComponent <BackgroundCombiner>()
     .Initialize(this);
 }
Example #13
0
    public string GetDisplayText(GameObject?gameObject)
    {
        var stringBuilder = new StringBuilder(_verb.Text);

        if (gameObject is not null && IsAllowed(gameObject))
        {
            stringBuilder.Append($" {gameObject.DisplayName}");
        }

        return(stringBuilder.ToString());
    }
Example #14
0
        static bool OnUnload(UnityModManager.ModEntry modEntry)
        {
            if (behaviourRoot != null)
            {
                GameObject.Destroy(behaviourRoot);
            }
            behaviourRoot = null;
            var harmony = new Harmony(modEntry.Info.Id);

            harmony.UnpatchAll(modEntry.Info.Id);
            return(true);
        }
Example #15
0
        /// <summary>
        /// 碰撞检测,如果这样行走是否会与之碰撞,返回与之碰撞的物体
        /// </summary>
        /// <param name="obj">移动的物体</param>
        /// <param name="moveVec">移动的位移向量</param>
        /// <returns>和它碰撞的物体</returns>
        public GameObject?CheckCollision(GameObject obj, Vector moveVec)
        {
            XYPosition nextPos = obj.Position + Vector.Vector2XY(moveVec);

            if (!obj.IsRigid)
            {
                if (gameMap.OutOfBound(obj))
                {
                    return(new OutOfBoundBlock(nextPos));
                }
                return(null);
            }

            //在某列表中检查碰撞
            Func <ArrayList, ReaderWriterLockSlim, GameObject> CheckCollisionInList =
                (ArrayList lst, ReaderWriterLockSlim listLock) =>
            {
                GameObject?collisionObj = null;
                listLock.EnterReadLock();
                try
                {
                    foreach (GameObject listObj in lst)
                    {
                        if (WillCollide(obj, listObj, nextPos))
                        {
                            collisionObj = listObj;
                            break;
                        }
                    }
                }
                finally { listLock.ExitReadLock(); }
                return(collisionObj);
            };

            GameObject collisionObj = null;

            foreach (var list in lists)
            {
                if ((collisionObj = CheckCollisionInList(list.Item1, list.Item2)) != null)
                {
                    return(collisionObj);
                }
            }

            //如果越界,则与越界方块碰撞
            if (gameMap.OutOfBound(obj))
            {
                return(new OutOfBoundBlock(nextPos));
            }

            return(null);
        }
        public static GameObject?GetBenchInScene()
        {
            if (_bench == null)
            {
                var restBench = Object.FindObjectOfType <RestBench>();
                if (restBench)
                {
                    _bench = restBench.gameObject;
                }
            }

            return(_bench);
        }
Example #17
0
        public void OnEnable()
        {
            logger.Debug("Creating scheduler host object");

            schedulerHostObject = new GameObject(ownMeta.Name + " Dispatcher Scheduler Host");
            UnityObject.DontDestroyOnLoad(schedulerHostObject);
            schedulerHost = schedulerHostObject.AddComponent <CoroHost>();
            UnityObject.DontDestroyOnLoad(schedulerHost);

            // start the scheduler
            schedulerHost.StartCoroutine(scheduler.Coroutine());

            logger.Debug("Plugin enabled");
        }
Example #18
0
        /// <summary>
        /// Gets a value indicating whether this actor is still valid in memory.
        /// </summary>
        /// <param name="actor">The actor to check.</param>
        /// <returns>True or false.</returns>
        public static bool IsValid(GameObject?actor)
        {
            if (actor is null)
            {
                return(false);
            }

            if (actor.Dalamud.ClientState.LocalContentId == 0)
            {
                return(false);
            }

            return(true);
        }
Example #19
0
        public static bool Unload(UnityModManager.ModEntry modEntry)
        {
            Main.Stoker.Reset();
            Main.StatusDisplay?.Clear();
            HarmonyInstance.UnpatchAll(nameof(DVStokerMod));

            if (BehaviourRoot != null)
            {
                Object.Destroy(BehaviourRoot);
            }
            BehaviourRoot = null;
            StatusDisplay = null;

            return(true);
        }
Example #20
0
    void multipleChoiceSetup()
    {
        //* shortly activate the inputGameObject so that the Multiple Choice Holder can be found
        answerGameObj.SetActive(true);
        mcAnsGameObj = GameObject.FindWithTag(TAG.MULTIPLE_CHOICE);
        answerGameObj.SetActive(activateAnsObjOnLoad);

        mcAnswers = new MCToggle[segment.answer.multipleChoices.Length];

        for (int i = 0; i < mcAnswers.Length; i++)
        {
            GameObject mcGO = Instantiate(MultipleChoiceObj, mcAnsGameObj.transform);
            mcAnswers[i] = mcGO.GetComponent <MCToggle>().initialize(segment.answer.multipleChoices[i]);
        }
    }
Example #21
0
 public void ConstructTarget(GameObject bgp, bool withTransition, bool destroyIfExists = false)
 {
     lastRequestedBGC = bgp;
     if (FromBG == null)
     {
         return;
     }
     if (destroyIfExists ||
         (ToBG == null && FromBG.source != bgp) ||
         (ToBG != null && ToBG.source != bgp))
     {
         ClearTransition();
         SetTarget(CreateBGC(bgp), withTransition);
     }
 }
Example #22
0
        public int Compare(GameObject?x, GameObject?y)
        {
            var xInit = x?.GetInt32(obj_f.initiative) ?? int.MinValue;
            var yInit = y?.GetInt32(obj_f.initiative) ?? int.MinValue;

            if (xInit != yInit)
            {
                return(yInit.CompareTo(xInit));
            }

            var xSubinit = x?.GetInt32(obj_f.subinitiative) ?? int.MinValue;
            var ySubinit = y?.GetInt32(obj_f.subinitiative) ?? int.MinValue;

            return(ySubinit.CompareTo(xSubinit));
        }
Example #23
0
        protected override IActivity <PhysicalActor>?BuildActivity(IVerbalAI <PhysicalActor> ai, Dictionary <string, string> lookup)
        {
            List <GameObject> targets = ai.ObjectsWithName(lookup["TARGET"]).ToList();

            if (targets.Count == 0)
            {
                return(new AutoFailAction <PhysicalActor>(
                           ai.Actor,
                           new FailedOutcome($"There is no {lookup["TARGET"]} here")
                           ));
            }
            List <TAction>?activities      = null;
            List <TAction>?validActivities = null;

            while (validActivities == null || validActivities.Count > 1)
            {
                IEnumerable <TAction> query =
                    from target in targets
                    select new TAction
                {
                    Actor  = ai.Actor,
                    Target = target,
                };
                activities      = new List <TAction>(query);
                validActivities = activities.Where(x => x.IsValid()).ToList();
                IEnumerable <GameObject> validTargets = from act in validActivities select act.Target;
                var uniqueTargets = new HashSet <GameObject>(validTargets);
                if (uniqueTargets.Count > 1)
                {
                    GameObject?definiteTarget = ai.ChooseObject(lookup["TARGET"], uniqueTargets);
                    if (definiteTarget == null)
                    {
                        targets = new List <GameObject>(); // empty
                    }
                    else
                    {
                        targets = new List <GameObject>()
                        {
                            definiteTarget
                        };
                    }
                }
            }
            // activities cannot be null here, because the above loop only exits if it is non-null
            if (activities !.Count == 0)
            {
                return(null);
            }
Example #24
0
    private void Start()
    {
        player       = ReferenceManager.PlayerObject;
        spawnManager = ReferenceManager.SpawnManagerComponent;
        playerState  = ReferenceManager.PlayerStateComponent;

        healthBarCurr       = transform.Find("MaxHealth/CurrHealth").gameObject;
        healthBarCurrXScale = healthBarCurr.transform.localScale.x;
        pathDestination     = GameObject.Find("Destination").transform;

        currHealth = maxHealth;

        NavMeshAgent agent = GetComponent <NavMeshAgent>();

        agent.destination = pathDestination.position;
    }
Example #25
0
        /// <summary>
        /// Gets a value indicating whether this actor is still valid in memory.
        /// </summary>
        /// <param name="actor">The actor to check.</param>
        /// <returns>True or false.</returns>
        public static bool IsValid(GameObject?actor)
        {
            var clientState = Service <ClientState> .Get();

            if (actor is null)
            {
                return(false);
            }

            if (clientState.LocalContentId == 0)
            {
                return(false);
            }

            return(true);
        }
Example #26
0
    void getSceneRelevantObj()
    {
        answerGameObj = GameObject.FindWithTag(TAG.ANSWER_GAMEOBJ);

        channelDictonary[TEXT.contentText] = contentText = tmpTextOrNull(TAG.CONTENT_TEXT);        //* add the Scenes current contentTexts: TMPText Component or NULL
        channelDictonary[TEXT.answerText]  = answerText = tmpTextOrNull(TAG.ANSWER_TEXT);          //* add the Scenes current answerTexts: TMPText Component or NULL

        if (answerGameObj is null)
        {
            return;     //=> break HERE out if there is NO AnwerGameObj in this scene and (so no button can be set an onClick.Event)
        }
        checkButton = answerGameObj.GetComponentInChildren <Button>();
        keyBHandler = answerGameObj.GetComponent <keyboardHandler>();

        answerGameObj.SetActive(activateAnsObjOnLoad);      //? keep an eye on that thingy: wont allways deactivate then the Story_Scene loads up the first time

        //_ set the checkButtons onClick function call to either [checkAnswer] if we are in a single or multiple Answer Scene or [sceneButtonPress]
        if (isAnswerScene())
        {
            // set battManager depending on the whether it was not yet started or in a Scene Change
            if (!battManager.countdownStarted)
            {
                battManager.setup(this);
            }
            if (battManager.isInSceneSwitch)
            {
                battManager.endSceneChange();
            }

            if (SCENE_IDENTIFIER == SCENE.SINGLE_ANSWER)
            {
                keyBHandler.currentKeyMode = segment.answer.singleAnswer.mode;
            }

            checkButton.onClick.AddListener(checkAnswer);
        }
        else
        {
            checkButton.onClick.AddListener(sceneButtonPress);
        }

        if (SCENE_IDENTIFIER == SCENE.MULTIPLE_ANSWER)
        {
            multipleChoiceSetup();
        }
    }
Example #27
0
        public static GameObject GetPrefab(string assetName)
        {
            GameObject?obj = null;

            Utils.Log($"Loading prefab '{assetName}'");
            if (Prefabs != null)
            {
                Utils.Log("Prefabs available, loading asset from it.");
                obj = Prefabs.LoadAsset(assetName) as GameObject;
            }

            if (obj == null)
            {
                throw new IOException($"Could not load prefab '{assetName}' from asset bundle");
            }
            return(obj);
        }
Example #28
0
        /// <summary>
        /// Tells the user when they have selected a song that is not on BeatSaver.com.
        /// </summary>
        static bool Prefix(IPreviewBeatmapLevel level)
        {
            if (beatSaverWarning == null)
            {
                StandardLevelDetailView?levelDetail = Resources.FindObjectsOfTypeAll <StandardLevelDetailView>().First();
                beatSaverWarning = new GameObject("BeatSaverWarning", typeof(CurvedTextMeshPro));
                beatSaverWarning.transform.SetParent(levelDetail.transform, false);
                beatSaverWarning.GetComponent <CurvedTextMeshPro>().text      = "Song not found on BeatSaver.com!";
                beatSaverWarning.GetComponent <CurvedTextMeshPro>().fontSize  = 4;
                beatSaverWarning.GetComponent <CurvedTextMeshPro>().fontStyle = TMPro.FontStyles.Italic;
                beatSaverWarning.GetComponent <CurvedTextMeshPro>().color     = Color.red;
                beatSaverWarning.GetComponent <RectTransform>().offsetMin     = new Vector2(-23.5f, 100f);
                beatSaverWarning.GetComponent <RectTransform>().offsetMax     = new Vector2(100f, -28f);
                beatSaverWarning.SetActive(false);
            }

            beatSaverWarning.SetActive(false);

            if (level.levelID.Contains("custom_level") && LobbyJoinPatch.IsMultiplayer)
            {
                string levelHash = level.levelID.Replace("custom_level_", "");
                if (songsNotFound.Contains(levelHash))
                {
                    Plugin.Log?.Warn($"Could not find song '{levelHash}' on BeatSaver.");
                    beatSaverWarning.SetActive(true);
                    songsNotFound.Add(levelHash);
                    return(true);
                }

                BeatSaverSharp.BeatSaver.Client.Hash(levelHash, CancellationToken.None).ContinueWith(r =>
                {
                    if (r.Result == null)
                    {
                        Plugin.Log?.Warn($"Could not find song '{levelHash}' on BeatSaver.");
                        beatSaverWarning.SetActive(true);
                        songsNotFound.Add(levelHash);
                    }
                    else
                    {
                        Plugin.Log?.Debug($"Selected song '{levelHash}' from BeatSaver.");
                    }
                });
                return(true);
            }
            return(true);
        }
        public void CommonInstall()
        {
            SignalBusInstaller.Install(Container);
            signalBus = Container.Resolve <SignalBus>();

            randomGenerator = new RandomGeneratorStub();
            var randomGeneratorMap = new Dictionary <string, IRandomGenerator>()
            {
                { "Game", randomGenerator }
            };
            var context = EditModeUtil.CreateGameContext(signalBus, randomGeneratorMap: randomGeneratorMap);

            gameObject = new GameObject();
            gameObject.AddComponent <PlayerUnit>();

            Container.Bind <GameContext>().FromInstance(context).AsSingle();
            Container.Inject(this);
        }
Example #30
0
        public static Character?Convert(GameObject?actor)
        {
            if (actor == null)
            {
                return(null);
            }

            return(actor switch
            {
                PlayerCharacter p => p,
                BattleChara b => b,
                _ => actor.ObjectKind switch
                {
                    ObjectKind.BattleNpc => Character(actor.Address),
                    ObjectKind.Companion => Character(actor.Address),
                    ObjectKind.Retainer => Character(actor.Address),
                    ObjectKind.EventNpc => Character(actor.Address),
                    _ => null,
                },
            });