Esempio n. 1
0
        /// <summary>
        /// Returns the ServerCharacter of the foe we hit, or null if none found.
        /// </summary>
        /// <returns></returns>
        private IDamageable DetectFoe(ulong foeHint = 0)
        {
            //this simple detect just does a boxcast out from our position in the direction we're facing, out to the range of the attack.

            RaycastHit[] results;
            int          numResults = ActionUtils.DetectMeleeFoe(Description.IsFriendly ^ m_Parent.IsNpc, m_Parent.GetComponent <Collider>(), Description, out results);

            if (numResults == 0)
            {
                return(null);
            }

            //everything that passes the mask should have a ServerCharacter component.
            IDamageable foundFoe = results[0].collider.GetComponent <IDamageable>();

            //we always prefer the hinted foe. If he's still in range, he should take the damage, because he's who the client visualization
            //system will play the hit-react on (in case there's any ambiguity).
            for (int i = 0; i < numResults; i++)
            {
                var serverChar = results[i].collider.GetComponent <IDamageable>();
                if (serverChar != null && serverChar.NetworkObjectId == foeHint)
                {
                    foundFoe = serverChar;
                    break;
                }
            }

            return(foundFoe);
        }