Exemplo n.º 1
0
    public bool IsEnemyInRange()
    {
        foreach (KeyValuePair <uLink.NetworkPlayer, ComponentPlayer> pair in Player.Players)
        {
            AgentHuman h = pair.Value.Owner;

            if (h.IsAlive == false)
            {
                continue;
            }

            if (m_Owner.IsFriend(h) || m_Owner == h)
            {
                continue;
            }

            Vector3 targetPos   = h.Position;
            Vector3 dirToTarget = targetPos - Transform.position;

            if (dirToTarget.y < -0.5f || dirToTarget.y > 2.5f)
            {
                continue;
            }

            if (dirToTarget.sqrMagnitude > CheckDistance)
            {
                continue;
            }
            return(true);
        }

        return(false);
    }
Exemplo n.º 2
0
    protected void AgentDetected(NetworkViewID senderID, NetworkViewID agentID, bool detected, uLink.NetworkMessageInfo info)
    {
        uLink.NetworkView agentView = uLink.NetworkView.Find(agentID);
        if (!agentView)
        {
            return;
        }

        uLink.NetworkView senderView = uLink.NetworkView.Find(senderID);
        if (!senderView)
        {
            return;
        }

        AgentHuman agent  = agentView.GetComponent <AgentHuman>();
        AgentHuman sender = senderView.GetComponent <AgentHuman>();

#if !DEADZONE_CLIENT
        if (Owner.IsServer)
        {
            ServerAnticheat.ReportAgentDetected(Owner.NetworkView.owner, agent, sender, info);
        }
#endif

        if (sender && sender.IsAlive && agent && agent.IsAlive && sender.IsFriend(agent) == false)
        {
            agent.BlackBoard.IsDetected = detected;

//			Debug.Log ("AgentDetected(), detected=" + detected + ", Owner=" + Owner.name + ", sender=" + sender.name + ", agent=" + agent.name);
        }
    }
Exemplo n.º 3
0
    public override bool IsFriend(AgentHuman target)
    {
        if (m_Owner == null)
        {
            return(true);
        }

        if (target == m_Owner)
        {
            return(true);
        }

        return(m_Owner.IsFriend(target));
    }
Exemplo n.º 4
0
    protected bool ValidateHitAgainstEnemy(RaycastHit hit)
    {
#if !DEADZONE_CLIENT
        if (uLink.Network.isServer)
        {
            AgentHuman other = hit.transform.gameObject.GetComponent <AgentHuman>();
            if ((other != null) && !other.IsFriend(Agent))
            {
                return(ServerAnticheat.ValidateHit(Agent, this, hit));
            }
        }
#endif

        return(true);
    }
Exemplo n.º 5
0
    //
    public void OnProjectileHit(Projectile projectile)
    {
        if (!Owner && GameObj.transform.parent)
        {
            Owner = GameObj.transform.parent.gameObject.GetFirstComponentUpward <AgentHuman>();
        }

        if ((Owner != null) && (Owner.IsFriend(projectile.Agent) == true))
        {
            projectile.ignoreThisHit = true;
            return;
        }

        Vector3 impulse = (projectile.Transform.forward * (projectile.Impulse * 0.005f)) + (Vector3.up * (projectile.Impulse * 0.002f));

//		Debug.Log ("HatObject, impulse=" + impulse.ToString("F5") + ", projectile.Impulse=" + projectile.Impulse.ToString("F5") + ", impulse.magnitude=" + impulse.magnitude);
//		Debug.DrawLine(GameObj.transform.position, GameObj.transform.position + impulse, Color.red, 5.0f);

        if (uLink.Network.isServer)
        {
            if (Owner)
            {
                //send impulse to clients
                Owner.NetworkView.RPC("ShotOffHat", uLink.RPCMode.Others, impulse, false);

                //shot off the hat on server
                Owner.ShotOffHat(impulse, true);
            }
        }
        else
        {
            //apply impulse to a hat which is already shot off
            if (null == GameObj.transform.parent)
            {
                GameObj.GetComponent <Rigidbody>().isKinematic = false;
                GameObj.GetComponent <Rigidbody>().useGravity  = true;

                GameObj.GetComponent <Rigidbody>().AddForce(impulse, ForceMode.Impulse);
            }
            else
            {
                return;                 // on client and still on head --> do nothing
            }
        }

        DestroyTime = Time.timeSinceLevelLoad + 20;         //destroy hat after 20 seconds
    }
Exemplo n.º 6
0
    private float ComputeYaw(AgentHuman humanFrom, ref bool hasEnemy)
    {
        GameObject objFrom = humanFrom.gameObject;

        Vector3 from      = objFrom.transform.position + Vector3.up * 1.0f;
        Vector3 direction = objFrom.transform.rotation * Vector3.forward;
        Vector3 right     = objFrom.transform.rotation * Vector3.right;

        float hornRadius = 0.5f;
        float hornLength = 7.5f;

        float yawPower = 400.0f * Time.deltaTime;

        Vector3 hitPosition = from;
        Vector3 hitNormal   = Vector3.up;

        float result = 0.0f;

        if (true == GetHornInfo(from, direction, hornRadius, hornLength, ref hitPosition, ref hitNormal))            // horn hit collision
        {
            hitNormal.y = 0;
            hitNormal.Normalize();

            float distance01 = (from - hitPosition).magnitude / hornLength;
            float power01    = 0.5f * (1.0f - Vector3.Dot(hitNormal, direction));

            result = yawPower * distance01 * power01;

            float dotRight = Vector3.Dot(hitNormal, right);

            if (dotRight < 0)
            {
                result *= -1;
            }
        }

        foreach (KeyValuePair <uLink.NetworkPlayer, ComponentPlayer> pair in Player.Players)
        {
            if (null == pair.Value)
            {
                continue;
            }

            AgentHuman human = pair.Value.Owner;

            if (null == human || human.IsFriend(humanFrom))
            {
                continue;
            }

            Vector3 vectorTo = human.ChestPosition - humanFrom.ChestPosition;
            vectorTo.y = 0.0f;
            Vector3 dirTo = vectorTo.normalized;

            if (Vector3.Dot(humanFrom.Forward, dirTo) > 0.3f)
            {
                float dist = vectorTo.magnitude;

                if (dist < 10)
                {
                    RaycastHit hit;

                    if (!Physics.Raycast(humanFrom.ChestPosition, dirTo, out hit, dist, ObjectLayerMask.Default | ObjectLayerMask.PhysicsMetal))
                    {
                        result = Vector3.Angle(humanFrom.Forward, vectorTo);

                        if (Vector3.Cross(humanFrom.Forward, vectorTo).y < 0)
                        {
                            result *= -1;
                        }

                        hasEnemy = true;
                    }
                }
            }
        }

        //hasEnemy = true;

        return(result);
    }
Exemplo n.º 7
0
    // ---------
    void UpdateRadarInternal(bool forced = false)
    {
        if (!Camera.main || !Player.LocalInstance)
        {
            return;
        }

        foreach (FlagInfo info in m_FlagData)
        {
            info.UpdateDistance();
        }

        Transform playerTrans = Player.LocalInstance.transform;
        Vector3   playerPos   = playerTrans.position;
        Vector3   playerDir   = playerTrans.forward;

        playerDir.y = 0;

        // ----------
        foreach (FlagInfo info in m_FlagData)
        {
            ShowRadarPos(info.RadarFlag.Widget, info.Pos, playerPos, playerDir);
            if (info.IsChanging)
            {
                if (!info.CoroutineActive)
                {
                    info.RadarFlag.Widget.StopAllCoroutines();
                    info.CoroutineActive = true;
                    info.RadarFlag.Widget.StartCoroutine(HighlightObject(info.RadarFlag.Widget, info));
                }
            }
            else
            {
                if (info.CoroutineActive)
                {
                    info.RadarFlag.Widget.StopAllCoroutines();
                    info.CoroutineActive = false;
                }
                info.RadarFlag.Widget.FadeAlpha = 1.0f;
                info.RadarFlag.Widget.Color     = info.Color;
            }
        }

        PlayerPersistantInfo ppi = PPIManager.Instance.GetPPI(Player.LocalInstance.networkView.owner);
        E_Team playerTeam        = (ppi != null) ? ppi.Team : E_Team.None;

        // ----------
        //int indexFriend = 0;
        int indexEnemy = 0;

        foreach (KeyValuePair <uLink.NetworkPlayer, ComponentPlayer> pair in Player.Players)
        {
            if (pair.Value == Player.LocalInstance)
            {
                continue;
            }
            AgentHuman a = pair.Value.Owner;
            if (a.IsAlive == false)
            {
                continue;
            }

            PlayerPersistantInfo ppi2 = PPIManager.Instance.GetPPI(pair.Key);
            if (ppi2 == null)
            {
                continue;
            }

            if (a.IsFriend(Player.LocalInstance.Owner))
            {
                // ----------
                RadarFriend free  = null;
                bool        found = false;
                foreach (RadarFriend friend in RadarFriends)
                {
                    if (friend.m_Used && (friend.m_Agent == a))
                    {
                        found = true;
                        break;
                    }
                    else if (!friend.m_Used)
                    {
                        free = friend;
                    }
                }
                if (!found && (free != null))
                {
                    free.SetAgent(a);
                }
                else
                {
                    if (!found && (free == null))
                    {
                        Debug.LogWarning("Free sprite for radar - friend not found!");
                    }
                }
            }
            else if (a.BlackBoard.IsDetected)
            {
                if (a.IsAlive == false)
                {
                    continue;
                }

                if (a.GadgetsComponent.IsBoostActive(E_ItemBoosterBehaviour.Invisible) &&
                    Player.LocalInstance.Owner.GadgetsComponent.GetGadget(E_ItemID.EnemyDetectorII) == null)
                {
                    continue;
                }

                if (!a.IsFriend(Player.LocalInstance.Owner))
                {
                    if (indexEnemy < RadarEnemies.Length)
                    {
                        E_Team enemyTeam = (playerTeam == E_Team.Bad) ? E_Team.Good : E_Team.Bad;
                        ShowRadarPos(RadarEnemies[indexEnemy].Widget, a.Position, playerPos, playerDir);
                        RadarEnemies[indexEnemy].Widget.Color = ZoneControlFlag.Colors[enemyTeam];
                        ++indexEnemy;
                    }
                }
            }
        }

        // ----------
        foreach (RadarFriend friend in RadarFriends)
        {
            friend.Refresh(forced);
            if (friend.m_Used)
            {
                ShowRadarPos(friend.m_MultiSprite.Widget, friend.m_Agent.Position, playerPos, playerDir);
            }
        }

        // ----------
        for (; indexEnemy < RadarEnemies.Length; indexEnemy++)
        {
            if (RadarEnemies[indexEnemy].Widget.IsVisible() || forced)
            {
                RadarEnemies[indexEnemy].Widget.Show(false, false);
            }
        }
    }
    // -----
    void UpdateLabels()
    {
        if (!LocalPlayer)
        {
            return;
        }
        Vector3 origPos = m_Labels[0].Transform.position;

        int index         = 0;
        int medkitsShown  = 0;
        int ammokitsShown = 0;

        Camera Cam;

        Cam = Camera.main ? Camera.main : (Camera.current ? Camera.current : GameCamera.Instance.MainCamera);

        PlayerPersistantInfo ppi = PPIManager.Instance.GetPPI(LocalPlayer.networkView.owner);
        E_Team playerTeam        = (ppi != null) ? ppi.Team : E_Team.None;

        if (Cam)
        {
            foreach (KeyValuePair <uLink.NetworkPlayer, ComponentPlayer> pair in Player.Players)
            {
                bool modified = false;
                if (pair.Value == LocalPlayer)
                {
                    continue;
                }
                AgentHuman a = pair.Value.Owner;
                if (a.IsAlive == false)
                {
                    continue;
                }
                if (LocalPlayer != null && !a.IsFriend(LocalPlayer.Owner))
                {
                    continue;
                }

                PlayerPersistantInfo ppi2 = PPIManager.Instance.GetPPI(pair.Key);
                if (ppi2 == null)
                {
                    continue;
                }
                Vector3 pos = Cam.WorldToViewportPoint(a.Position + new Vector3(0, 2.2f, 0));
                if (pos.z < 0)
                {
                    continue;
                }

                pos.z  = origPos.z;
                pos.y  = (1 - pos.y) * Screen.height;
                pos.x *= Screen.width;

                /**/
                modified |= m_Labels[index].Transform.position != pos;
                m_Labels[index].Transform.position = pos;
                bool modif = SetTextAndAdjustBackground(ppi2.NameForGui,
                                                        m_Labels[index].Name,
                                                        m_Labels[index].Base,
                                                        m_Labels[index].OrigBaseWidth,
                                                        m_Labels[index].OrigNameScale);
                /**/
                modified |= modif;
                /**/
                modified |= m_Labels[index].Base.Color != ZoneControlFlag.Colors[playerTeam];
                m_Labels[index].Base.Color = ZoneControlFlag.Colors[playerTeam];
                if (!m_Labels[index].Base.IsVisible())
                {
                    m_Labels[index].Base.Show(true, true);
                }
                bool insideCrosshairArea = Owner.Crosshair.WidgetInsideCrosshairArea(m_Labels[index].Base.GetWidth(),
                                                                                     m_Labels[index].Base.GetHeight(),
                                                                                     m_Labels[index].Transform,
                                                                                     3f);
                float alpha;
                if (insideCrosshairArea)
                {
                    alpha = 0.4f;
                }
                else
                {
                    alpha = 1.0f;
                }
                /**/
                modified |= !Mathf.Approximately(m_Labels[index].Base.FadeAlpha, alpha);
                m_Labels[index].Base.FadeAlpha = alpha;
                /**/
                modified |= !Mathf.Approximately(m_Labels[index].Name.Widget.FadeAlpha, alpha);
                m_Labels[index].Name.Widget.FadeAlpha = alpha;
                /**/
                modified |= !Mathf.Approximately(m_Labels[index].Name.Widget.FadeAlpha, alpha);
                if (modified)
                {
                    m_Labels[index].Base.SetModify(true);
                }
                //else
                //	Debug.Log("Optimization!");
                index++;
                if (index >= m_Labels.Count)
                {
                    break;
                }
            }

/*			//------------
 *                      if (!LocalPlayer.Owner.IsFullyHealed)
 *                      {
 *                              // sort list
 *                              Vector3 ownerPos = LocalPlayer.Owner.Position;
 *                              m_RegisteredMedkits.Sort(delegate(MedKit m1, MedKit m2)
 *                                                                                      {
 *                                                                                              return (ownerPos - m1.transform.position).sqrMagnitude.CompareTo((ownerPos - m2.transform.position).sqrMagnitude);
 *                                                                                      }
 *                                                                               );
 *
 *
 *                              origPos = m_Medkits[0].Transform.position;
 *                              foreach (MedKit medkit in m_RegisteredMedkits)
 *                              {
 *                                      if ((ownerPos - medkit.transform.position).sqrMagnitude < HUD_INDICATOR_MAX_SQRT_DIST)
 *                                      {
 *                                              if (ShowHudIndicator(Cam, m_Medkits[medkitsShown], medkit.transform, origPos))
 *                                              {
 ++medkitsShown;
 *                                                      if (medkitsShown >= m_Medkits.Count)
 *                                                              break;
 *                                              }
 *                                      }
 *                              }
 *                      }
 *
 *                      //------------
 *                      if (true)
 *                      {
 *                              // sort list
 *                              Vector3 ownerPos = LocalPlayer.Owner.Position;
 *                              m_RegisteredAmmokits.Sort(delegate(AmmoKit m1, AmmoKit m2)
 *                                                                                      {
 *                                                                                              return (ownerPos - m1.transform.position).sqrMagnitude.CompareTo((ownerPos - m2.transform.position).sqrMagnitude);
 *                                                                                      }
 *                                                                               );
 *
 *
 *                              origPos = m_Ammokits[0].Transform.position;
 *                              foreach (AmmoKit ammokit in m_RegisteredAmmokits)
 *                              {
 *                                      if ((ownerPos - ammokit.transform.position).sqrMagnitude < HUD_INDICATOR_MAX_SQRT_DIST)
 *                                      {
 *                                              if (ShowHudIndicator(Cam, m_Ammokits[ammokitsShown], ammokit.transform, origPos))
 *                                              {
 ++ammokitsShown;
 *                                                      if (ammokitsShown >= m_Ammokits.Count)
 *                                                              break;
 *                                              }
 *                                      }
 *                              }
 *                      }
 * /**/
        }

        // -----
        for (int i = index; i < m_Labels.Count; i++)
        {
            if (m_Labels[i].Base.IsVisible())
            {
                m_Labels[i].Base.Show(false, true);
            }
        }
        // -----
        for (int i = medkitsShown; i < m_Medkits.Count; i++)
        {
            if (m_Medkits[i].Base.IsVisible())
            {
                m_Medkits[i].Base.Show(false, true);
            }
        }
        // -----
        for (int i = ammokitsShown; i < m_Ammokits.Count; i++)
        {
            if (m_Ammokits[i].Base.IsVisible())
            {
                m_Ammokits[i].Base.Show(false, true);
            }
        }
    }
Exemplo n.º 9
0
    void InternalUpdate(float deltaTime)
    {
        if (!Rigidbody.isKinematic)
        {
            return;
        }

        bool MovementAllowed = true;
        bool CoverHit        = false;

        Vector3 CurrentTheoreticalPosition = ComputeThrowPosition(StartPos, Velocity, FlightTime);

        Vector3 v = CurrentTheoreticalPosition - Transform.position;

        FlightTime += deltaTime;

        float sqrDistanceToOrigin = (StartPos - Transform.position).magnitude;

        if (!ThrowedFromCover || sqrDistanceToOrigin > 1.5f * 1.5f)
        {
            RaycastHit[] hits = Physics.RaycastAll(Transform.position, v.normalized, v.magnitude, ~(ObjectLayerMask.IgnoreRayCast));

            if (hits.Length > 0)
            {
                foreach (RaycastHit hit in hits)
                {
                    //skip friends when the projectile should explode near the player (this solves the unwanted suicide when a friend suddenly enters the area in front of me)
                    AgentHuman hitAgent = hit.transform.gameObject.GetFirstComponentUpward <AgentHuman>();
                    if (hitAgent != null)
                    {
                        float dist = Vector3.Distance(Owner.Position, hitAgent.Position);

//						Debug.Log ("GHIT: hitAgent=" + hitAgent.name + ", dist=" + dist);

                        if (dist < 3)                         //ignore only if the projectile is still within X m radius
                        {
                            if (Owner.IsFriend(hitAgent))
                            {
//								Debug.Log ("GHIT: hitAgent=" + hitAgent.name + ", dist=" + dist + " -- FRIENDS");
                                continue;
                            }
//							else
//							{
//								Debug.Log ("GHIT: hitAgent=" + hitAgent.name + ", dist=" + dist + " -- ENEMIES");
//							}
                        }
                    }

                    if (!hit.collider.transform.IsChildOf(Owner.transform))
                    {
                        MovementAllowed = false;

                        if (null != hit.collider.transform.GetComponentInChildren <Cover>())
                        {
                            CoverHit = true;
                        }

                        break;
                    }
                }
            }
        }

        if (MovementAllowed)
        {
            // movement
            Transform.position += v;
            Transform.Rotate(new Vector3(1, 1, 1), deltaTime * 6.0f * Mathf.Rad2Deg);
        }
        else
        {
            Rigidbody.isKinematic = false;

            if (CoverHit)
            {
                Rigidbody.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic;
            }

            // slow down in case of thin cover - otherwise grenade will go through the wall
            //Rigidbody.velocity = CoverHit ? 0.1f*v/deltaTime : v/deltaTime;
            // 'Velocity' is not right, it should be 'v/deltaTime' - but current physics settings is based on this
            Rigidbody.velocity = CoverHit ? 0.1f * v / deltaTime : Velocity;
            //Rigidbody.velocity = Velocity;
        }
    }
Exemplo n.º 10
0
 bool IsAgentValid(AgentHuman agent)
 {
     return(agent != null &&
            agent.IsAlive &&
            Owner.IsFriend(agent) == false);
 }