Exemple #1
0
        static HurtBox CustomAITargetFilter(On.RoR2.CharacterAI.BaseAI.orig_FindEnemyHurtBox orig, RoR2.CharacterAI.BaseAI self, float maxDistance, bool full360Vision, bool filterByLoS)
        {
            if (!self.body)
            {
                return(null);
            }

            bool defaultSearch  = true;
            bool isPlayerBot    = self.master.playerCharacterMasterController ? true : false;
            bool isMinion       = self.master.minionOwnership.ownerMaster ? true : false;
            bool isPlayerMinion = false;

            if (isMinion)
            {
                if (self.master.minionOwnership.ownerMaster.playerCharacterMasterController)
                {
                    isPlayerMinion = true;
                }
            }

            BullseyeSearch enemySearch = self.GetFieldValue <BullseyeSearch>("enemySearch");

            enemySearch.viewer            = self.body;
            enemySearch.teamMaskFilter    = TeamMask.all;
            enemySearch.sortMode          = BullseyeSearch.SortMode.Distance;
            enemySearch.minDistanceFilter = 0f;
            enemySearch.maxDistanceFilter = maxDistance;
            enemySearch.searchOrigin      = self.bodyInputBank.aimOrigin;
            enemySearch.searchDirection   = self.bodyInputBank.aimDirection;
            enemySearch.maxAngleFilter    = (full360Vision ? 180f : 90f);
            enemySearch.filterByLoS       = filterByLoS;

            //Free for all pvp
            if (VoteAPI.VoteResults.HasVote(Settings.FreeForAllPVPToggle.Item2))
            {
                //Player bot AI  or player minion
                if (isPlayerBot || isPlayerMinion)
                {
                    if (PVPMode.IsGracePeriod)
                    {
                        enemySearch.teamMaskFilter.RemoveTeam(self.master.teamIndex);
                    }
                    enemySearch.RefreshCandidates();

                    enemySearch.FilterOutGameObject(self.body.gameObject);
                    if (isMinion)
                    {
                        CharacterBody ownerBody = self.master.minionOwnership.ownerMaster.GetBody();
                        if (ownerBody)
                        {
                            enemySearch.FilterOutGameObject(ownerBody.gameObject);
                        }
                        enemySearch.FilterOutMinionGroup(self.master.minionOwnership.ownerMaster.netId);
                    }
                    else
                    {
                        enemySearch.FilterOutMinionGroup(self.master.netId);
                    }

                    defaultSearch = false;
                }
            }

            //Team pvp or regular mobs AI
            if (defaultSearch)
            {
                enemySearch.teamMaskFilter.RemoveTeam(self.master.teamIndex);
                enemySearch.RefreshCandidates();
            }

            return(enemySearch.GetResults().FirstOrDefault <HurtBox>());
        }