示例#1
0
    protected override void OnUpdate()
    {
        Entities.WithNone <SendRpcCommandRequestComponent>().ForEach((Entity reqEnt, ref GoInGameRequest req, ref ReceiveRpcCommandRequestComponent reqSrc) =>
        {
            PostUpdateCommands.AddComponent <NetworkStreamInGame>(reqSrc.SourceConnection);
            UnityEngine.Debug.Log(String.Format("Server setting connection {0} to in game", EntityManager.GetComponentData <NetworkIdComponent>(reqSrc.SourceConnection).Value));
            var ghostCollection = GetSingleton <GhostPrefabCollectionComponent>();


            //var serverPrefabs = EntityManager.GetBuffer<GhostPrefabBuffer>(ghostCollection.serverPrefabs);
            //for (int ghostId = 0; ghostId < serverPrefabs.Length; ++ghostId)
            //{
            //    if (EntityManager.HasComponent<MovableCubeComponent>(serverPrefabs[ghostId].Value))
            //        prefab = serverPrefabs[ghostId].Value;
            //}



            // old implementation, was deprecated annoyingly
            //var ghostId = NetAgentGhostSerializerCollection.FindGhostType<AgentSnapshotData>();
            var ghostId = 0;
            var prefab  = EntityManager.GetBuffer <GhostPrefabBuffer>(ghostCollection.serverPrefabs)[ghostId].Value;
            var player  = EntityManager.Instantiate(prefab);

            Entity sword  = SwordSystem.AddAbility(player, EntityManager, ghostCollection);
            Entity shield = ShieldSystem.AddAbility(player, EntityManager, ghostCollection);


            ghostId     = 4;
            prefab      = EntityManager.GetBuffer <GhostPrefabBuffer>(ghostCollection.serverPrefabs)[ghostId].Value;
            var hurtbox = EntityManager.Instantiate(prefab);
            EntityManager.SetComponentData(hurtbox, new OwningPlayer {
                Value = player
            });
            EntityManager.AddBuffer <Hit>(hurtbox);

            ghostId          = 5;
            prefab           = EntityManager.GetBuffer <GhostPrefabBuffer>(ghostCollection.serverPrefabs)[ghostId].Value;
            var shieldHitbox = EntityManager.Instantiate(prefab);
            EntityManager.SetComponentData(shieldHitbox, new OwningPlayer {
                Value = player
            });
            EntityManager.SetComponentData(shieldHitbox, new AssociatedEntity {
                Value = shield
            });
            EntityManager.AddBuffer <Hit>(shieldHitbox);


            EntityManager.SetComponentData(player, new AgentComponent {
                PlayerId = EntityManager.GetComponentData <NetworkIdComponent>(reqSrc.SourceConnection).Value
            });

            InitializeAgent(player);

            PostUpdateCommands.AddBuffer <AgentInput>(player);

            PostUpdateCommands.SetComponent(reqSrc.SourceConnection, new CommandTargetComponent {
                targetEntity = player
            });

            PostUpdateCommands.DestroyEntity(reqEnt);

            Entity dash1 = DashSystem.AddAbility(player, 1, 1000, 7, new float3(0, 0, 1), KeyCode.A, EntityManager, ghostCollection);
            Entity dash2 = DashSystem.AddAbility(player, 1, 1000, 7, new float3(0, 0, -1), KeyCode.S, EntityManager, ghostCollection);
            Entity dash3 = DashSystem.AddAbility(player, 1, 1000, 7, new float3(1, 0, 0), KeyCode.D, EntityManager, ghostCollection);
            Entity dash4 = DashSystem.AddAbility(player, 1, 1000, 7, new float3(-1, 0, 0), KeyCode.F, EntityManager, ghostCollection);



//#if (!UNITY_EDITOR)
            //GameObject animate_prefab = Resources.Load<GameObject>("Prefabs/gladiator");
            //GameObject obj = UnityEngine.Object.Instantiate(animate_prefab);
            // setup pointer to entity from object
            //obj.GetComponent<PlayerMono>().entity = player;
            // setup pointers to entities from sword object
            //var swordObj = obj.transform.Find("CharArmature/Pelvis/Ribcage/Chest/Shoulder.R/UpperArm.R/Forearm.R/Hand.R/SwordArmature/Bone/Sword");
            //SwordMono swordMono = swordObj.GetComponent<SwordMono>();
            //swordMono.entity = sword;
            //swordMono.player = player;
            //EntityManager.AddComponentObject(sword, swordMono);

            //var shieldObj = obj.transform.Find("CharArmature/Pelvis/Ribcage/Chest/Shoulder.L/UpperArm.L/Forearm.L/ShieldArmature/Bone.001/Shield");
            //ShieldMono shieldMono = shieldObj.GetComponent<ShieldMono>();
            //shieldMono.entity = shield;
            //shieldMono.player = player;
            //EntityManager.AddComponentObject(shield, shieldMono);

            //obj.transform.localScale *= 0.5f;
            //EntityManager.AddComponentObject(player, obj);
            PostUpdateCommands.AddComponent <AnimationInitialized>(player);
//#endif
        });
    }
示例#2
0
    void Shoot()
    {
        muzzelflash.Play();
        RaycastHit hit;

        if (Physics.Raycast(muzzel.position, muzzel.forward, out hit, range))
        {
            RealDamage = (damage) * (Mathf.Sin((Vector3.Angle(hit.normal, muzzel.forward) / 2) * Mathf.Deg2Rad));



            Health       PlayersHealth = hit.transform.GetComponent <Health>();
            ShieldSystem shields       = hit.transform.GetComponent <ShieldSystem>();

            GameObject side = hit.collider.transform.gameObject;
//            Debug.Log(side.name);

            //1
            if (side.CompareTag("SideShields"))
            {
                if (damage >= shields.SideArmor)
                {
                    hitpoints = 10;
                    PlayersHealth.TakeDamage(10);
                    // Debug.Log(  hitpoints + i); i++;
                }
                else
                {
                    Debug.Log("Hit but no damage");
                }
            }
            //2
            if (side.CompareTag("LowerFront"))
            {
                if (damage >= shields.LowerFrontArmor)
                {
                    hitpoints = 10;
                    PlayersHealth.TakeDamage(10);
                }
                else
                {
                    Debug.Log("Hit but no damage");
                }
            }
            //3
            if (side.CompareTag("UpperFront"))
            {
                if (damage >= shields.UpperFrontArmor)
                {
                    hitpoints = 10;
                    PlayersHealth.TakeDamage(10);
                }
                else
                {
                    Debug.Log("Hit but no damage");
                }
            }
            //4
            if (side.CompareTag("LowerBack"))
            {
                if (damage >= shields.LowerBackArmor)
                {
                    hitpoints = 10;
                    PlayersHealth.TakeDamage(10);
                }
                else
                {
                    Debug.Log("Hit but no damage");
                }
            }
            //5
            if (side.CompareTag("UpperBack"))
            {
                if (damage >= shields.UpperBackArmor)
                {
                    hitpoints = 10;
                    PlayersHealth.TakeDamage(10);
                }
                else
                {
                    Debug.Log("Hit but no damage");
                }
            }
            //6
            if (side.CompareTag("CabinFront"))
            {
                if (damage >= shields.CabinFrontArmor)
                {
                    hitpoints = 10;
                    PlayersHealth.TakeDamage(10);
                    Debug.Log(hitpoints + i); i++;
                }
                else
                {
                    Debug.Log("Hit but no damage");
                }
            }
            //7
            if (side.CompareTag("CabinSide"))
            {
                if (damage >= shields.CabinSideArmor)
                {
                    hitpoints = 10;
                    PlayersHealth.TakeDamage(10);
                }
                else
                {
                    Debug.Log("Hit but no damage");
                }
            }
            //8
            if (side.CompareTag("EngineCover"))
            {
                if (damage >= shields.EngineCoverAarmor)
                {
                    hitpoints = 10;
                    PlayersHealth.TakeDamage(10);
                }
                else
                {
                    Debug.Log("Hit but no damage");
                }
            }
            //9
            if (side.CompareTag("Turret"))
            {
                if (damage >= shields.TurretAarmor)
                {
                    hitpoints = 10;
                    PlayersHealth.TakeDamage(10);
                }
                else
                {
                    Debug.Log("Hit but no damage");
                }
            }
            //10
            if (side.CompareTag("TopRoof"))
            {
                if (damage >= shields.TopRoofArmor)
                {
                    hitpoints = 10;
                    PlayersHealth.TakeDamage(10);
                }
                else
                {
                    Debug.Log("Hit but no damage");
                }
            }
            //11
            if (side.CompareTag("Buttom"))
            {
                if (damage >= shields.ButtomArmor)
                {
                    hitpoints = 10;
                    PlayersHealth.TakeDamage(10);
                }
                else
                {
                    Debug.Log("Hit but no damage");
                }
            }


            // GameObject impactobject = Instantiate(impacteffect, hit.point, Quaternion.LookRotation(hit.normal));
            //  Destroy(impactobject, 2f);
        }
    }
示例#3
0
    void Shoot()
    {
        //Shooting Effects
        muzzelflash.Play();
        //

        //Subbtracts Ammo
        currentAmmo--;
        #region variables
        RaycastHit hit;
        #endregion

        if (Physics.Raycast(RayCenter.position, RayCenter.forward, out hit, range))
        {
            ShieldSystem shields = hit.transform.GetComponent <ShieldSystem>();

            //Relative Damage
            relativeDamage = (damage) * (Mathf.Sin((Vector3.Angle(hit.normal, GunCenter.transform.forward) * 0.5f) * Mathf.Deg2Rad));


            // Add bullet effects for every object it hits
            GameObject impactobject = Instantiate(impacteffect, hit.point, Quaternion.LookRotation(hit.normal));
            GameObject bullethole   = Instantiate(paintpoint, hit.point, Quaternion.LookRotation(hit.normal), hit.transform);

            //

            //Identifies Enemies
            GameObject side   = hit.collider.gameObject;
            Target     target = hit.transform.GetComponent <Target>();
            Debug.Log(side.tag + "   " + relativeDamage);

            Health PlayersHealth;

            if (hit.rigidbody != null)
            {
                if (hit.rigidbody.GetComponent <Health>() != null)
                {
                    PlayersHealth    = hit.rigidbody.GetComponent <Health>();
                    EnemyHealth.text = "Enemy Health :" + PlayersHealth.health.ToString();
                }
                else
                {
                    PlayersHealth = null;
                }
            }
            else
            {
                PlayersHealth = null;
            }

            HitSide.text = "Side :" + side.tag;

            //Destroys The effects
            Destroy(impactobject, 2f);
            Destroy(bullethole, 2f);
            #region Commented


            /////////////////////////////// For ricochet and penetration may work on it later delete if you dont want it
            //
            //to the top
            //        if (reflectionsRemaining == 0)
            //      {
            //        return;
            //  }


            // if (Physics.Raycast(muzzel.position, muzzel.forward, out hit, range))
            //{


            //  Gizmos.color = Color.magenta;
            // Gizmos.DrawLine(startingPosition, position);

            //  DrawPredictionReflectionPattern(position, direction, reflectionsRemaining - 1);

            //}

            #endregion

            //To destory Red Cubes when shot
            //For Testing only
            if (target != null)
            {
                target.TakeDamage(50);
            }


            // Checks if the Relative dimentions of the bullet are greater than the dimentions of the shields and if so it applies damage
            //1
            if (shields != null)
            {
                if (side.CompareTag("SideShields"))
                {
                    if (relativeDamage >= shields.SideArmor)
                    {
                        if (PlayersHealth != null)
                        {
                            PlayersHealth.TakeDamage(10);
                        }
                    }
                    else
                    {
                        Debug.Log("Hit but no damage");
                    }
                }
                //2
                if (side.CompareTag("LowerFront"))
                {
                    if (relativeDamage >= shields.LowerFrontArmor)
                    {
                        if (PlayersHealth != null)
                        {
                            PlayersHealth.TakeDamage(10);
                        }
                    }
                    else
                    {
                        Debug.Log("Hit but no damage");
                    }
                }
                //3
                if (side.CompareTag("UpperFront"))
                {
                    if (relativeDamage >= shields.UpperFrontArmor)
                    {
                        if (PlayersHealth != null)
                        {
                            PlayersHealth.TakeDamage(10);
                        }
                    }
                    else
                    {
                        Debug.Log("Hit but no damage");
                    }
                }
                //4
                if (side.CompareTag("LowerBack"))
                {
                    if (relativeDamage >= shields.LowerBackArmor)
                    {
                        if (PlayersHealth != null)
                        {
                            PlayersHealth.TakeDamage(10);
                        }
                    }
                    else
                    {
                        Debug.Log("Hit but no damage");
                    }
                }
                //5
                if (side.CompareTag("UpperBack"))
                {
                    if (relativeDamage >= shields.UpperBackArmor)
                    {
                        if (PlayersHealth != null)
                        {
                            PlayersHealth.TakeDamage(10);
                        }
                    }
                    else
                    {
                        Debug.Log("Hit but no damage");
                    }
                }
                //6
                if (side.CompareTag("CabinFront"))
                {
                    if (relativeDamage >= shields.CabinFrontArmor)
                    {
                        if (PlayersHealth != null)
                        {
                            PlayersHealth.TakeDamage(10);
                        }
                    }
                    else
                    {
                        Debug.Log("Hit but no damage");
                    }
                }
                //7
                if (side.CompareTag("CabinSide"))
                {
                    if (relativeDamage >= shields.CabinSideArmor)
                    {
                        if (PlayersHealth != null)
                        {
                            PlayersHealth.TakeDamage(10);
                        }
                    }
                    else
                    {
                        Debug.Log("Hit but no damage");
                    }
                }
                //8
                if (side.CompareTag("EngineCover"))
                {
                    if (relativeDamage >= shields.EngineCoverAarmor)
                    {
                        if (PlayersHealth != null)
                        {
                            PlayersHealth.TakeDamage(10);
                        }
                    }
                    else
                    {
                        Debug.Log("Hit but no damage");
                    }
                }
                //9
                if (side.CompareTag("Turret"))
                {
                    if (relativeDamage >= shields.TurretAarmor)
                    {
                        if (PlayersHealth != null)
                        {
                            PlayersHealth.TakeDamage(10);
                        }
                    }
                    else
                    {
                        Debug.Log("Hit but no damage");
                    }
                }
                //10
                if (side.CompareTag("TopRoof"))
                {
                    if (relativeDamage >= shields.TopRoofArmor)
                    {
                        if (PlayersHealth != null)
                        {
                            PlayersHealth.TakeDamage(10);
                        }
                    }
                    else
                    {
                        Debug.Log("Hit but no damage");
                    }
                }
                //11
                if (side.CompareTag("Buttom"))
                {
                    if (relativeDamage >= shields.ButtomArmor)
                    {
                        if (PlayersHealth != null)
                        {
                            PlayersHealth.TakeDamage(10);
                        }
                    }
                    else
                    {
                        Debug.Log("Hit but no damage");
                    }
                }
            }
        }
    }