예제 #1
0
파일: SkillsSystem.cs 프로젝트: Deus0/zoxel
        public void InitializeSkills(Entity e, Skills skills)
        {
            RemoveSkills(e);
            if (skills.selectedSkillIndex < 0 || skills.selectedSkillIndex >= skills.skills.Length)
            {
                //Debug.LogError("Selected skill index out of range: " + skills.selectedSkillIndex + " out of " + skills.skills.Length);
                return;
            }
            SkillData  datim = skills.skills[skills.selectedSkillIndex];
            SkillDatam datum = meta[datim.id];

            if (datum.Value.attackType == 1)
            {
                AddMeleeAttack(e, datum);
            }
            else if (datum.bullet != null)
            {
                AddShooter(e, datum);
            }
            else
            {
                if (datum.turret != null || datum.monster != null || datum.voxel != null)
                {
                    AddCaster(e);
                }
            }
        }
예제 #2
0
파일: SkillsSystem.cs 프로젝트: Deus0/zoxel
        private void SpawnMonster(Entity e, SkillDatam datam)
        {
            if (World.EntityManager.HasComponent <CharacterRaycaster>(e) == false)
            {
                return;
            }
            int   monsterID               = datam.monster.Value.id;
            ZoxID zoxID                   = World.EntityManager.GetComponentData <ZoxID>(e);
            CharacterRaycaster caster     = World.EntityManager.GetComponentData <CharacterRaycaster>(e);
            WorldBound         worldBound = World.EntityManager.GetComponentData <WorldBound>(e);

            if (caster.DidCast() == 1)
            {
                ZoxID stats = World.EntityManager.GetComponentData <ZoxID>(e);
                //caster.triggered = 1;
                World.EntityManager.SetComponentData(e, caster);
                int clanID = stats.clanID;
                if (datam.Value.isSpawnHostile == 1)
                {
                    clanID = Bootstrap.GenerateUniqueID();
                }
                CharacterSpawnSystem.SpawnNPC(World.EntityManager, worldBound.world, monsterID, clanID, caster.voxelPosition, zoxID.id);

                /*if (datam.Value.isSpawnHostile != 1)
                 * {
                 *  Entity npc = characterSpawnSystem.characters[spawnedID];
                 *  ZoxID spawnedZoxID = World.EntityManager.GetComponentData<ZoxID>(npc);
                 *  spawnedZoxID.creatorID = zoxID.id;
                 *  World.EntityManager.SetComponentData(npc, spawnedZoxID);
                 * }*/
                AudioManager.instance.PlaySound(datam.audio, caster.voxelPosition);
                //Debug.LogError("Spawning Turret at: " + caster.voxelPosition.ToString());
            }
        }
예제 #3
0
파일: SkillsSystem.cs 프로젝트: Deus0/zoxel
 private void AddMeleeAttack(Entity e, SkillDatam datum)
 {
     if (World.EntityManager.HasComponent <MeleeAttack>(e) == false)
     {
         //Debug.Log("Adding MElee Component");
         World.EntityManager.AddComponentData(e, new MeleeAttack
         {
             attackDamage   = datum.Value.attackDamage,
             attackCooldown = datum.Value.attackSpeed
         });
     }
 }
예제 #4
0
파일: SkillsSystem.cs 프로젝트: Deus0/zoxel
 protected override void OnUpdate()
 {
     Entities.WithAll <ZoxID, Skills>().ForEach((Entity e, ref ZoxID zoxID, ref Skills skills) => // , ref RenderMesh renderer
     {
         if (skills.updated == 1)
         {
             skills.updated = 0;
             // update skills icons
             actionbarSpawnSystem.SetSlotPosition(zoxID.id, skills.selectedSkillIndex);
             // turn off or on raycasting
             // change crosshair for skill
             // change character animation
             InitializeSkills(e, skills);
         }
         if (skills.triggered == 1)
         {
             skills.triggered = 0;
             if (skills.skills.Length == 0)
             {
                 return; // no skill to activate
             }
             // activate the skills
             SkillData datim  = skills.skills[skills.selectedSkillIndex];
             SkillDatam datum = meta[datim.id];
             if (datum.Value.attackType == 1)
             {
                 // trigger melee attack here
                 // ai should trigger the skills component
                 ActivateMeleeAttack(e, ref skills);
             }
             else if (datum.bullet != null)
             {
                 ShootBullet(datum, e);
             }
             else if (datum.turret != null)
             {
                 SpawnTurret(e, 0);
             }
             else if (datum.monster != null)
             {
                 SpawnMonster(e, datum);
             }
             else if (datum.voxel != null)
             {
                 SpawnVoxel(e, datum.voxel);
             }
         }
     });
 }
예제 #5
0
파일: SkillsSystem.cs 프로젝트: Deus0/zoxel
        private void ShootBullet(SkillDatam skillDatam, Entity e)
        {
            if (World.EntityManager.HasComponent <Shooter>(e) == false)
            {
                return;
            }
            Shooter shooter = World.EntityManager.GetComponentData <Shooter>(e);

            if (shooter.CanTrigger(UnityEngine.Time.time))
            {
                shooter.triggered = 1;
                Entity camera;
                if (World.EntityManager.HasComponent <CameraLink>(e))
                {
                    camera = World.EntityManager.GetComponentData <CameraLink>(e).camera;
                }
                else
                {
                    camera = new Entity();
                }
                if (World.EntityManager.Exists(camera))
                {
                    //GameObject shooterCamera = CameraSystem.cameraObjects[cameraID];
                    //Debug.LogError("Shooting with camera: " + shooterCamera.name);
                    float3     position = World.EntityManager.GetComponentData <Translation>(camera).Value;
                    quaternion rotation = World.EntityManager.GetComponentData <Rotation>(camera).Value;
                    shooter.shootPosition = position + math.rotate(rotation, new float3(0, 0, 0.1f)); // shooterCamera.transform.position + shooterCamera.transform.forward * 0.1f;//aimer.originalPosition + math.mul(aimer.targetRotation, new float3(0, 0, 0.19f + 0.2f));
                    shooter.shootRotation = rotation;                                                 // shooterCamera.transform.rotation;
                }
                else
                {
                    Translation translation = World.EntityManager.GetComponentData <Translation>(e);
                    Rotation    rotation    = World.EntityManager.GetComponentData <Rotation>(e);
                    shooter.shootPosition = translation.Value;//aimer.originalPosition + math.mul(aimer.targetRotation, new float3(0, 0, 0.19f + 0.2f));

                    Targeter   targeter      = World.EntityManager.GetComponentData <Targeter>(e);
                    float3     normalBetween = math.normalizesafe(targeter.nearbyCharacter.position - translation.Value);
                    quaternion targetAngle   = quaternion.LookRotationSafe(normalBetween, math.up());
                    //rotation.Value = QuaternionHelpers.slerpSafe(rotation.Value, targetAngle, mover.turnSpeed);
                    shooter.shootRotation = targetAngle; // rotation.Value;
                                                         //Debug.LogError("Shoot Camera ID is 0.");
                }
                AudioManager.instance.PlaySound(skillDatam.audio, shooter.shootPosition);
                World.EntityManager.SetComponentData(e, shooter);
                //Debug.LogError("Shooting Bullet from: " + shooter.shootPosition);
            }
        }
예제 #6
0
파일: SkillsSystem.cs 프로젝트: Deus0/zoxel
 private void AddShooter(Entity e, SkillDatam datum)
 {
     //Debug.Log("Adding SHooter Component");
     if (World.EntityManager.HasComponent <Shooter>(e) == false)
     {
         /*int cameraID = 0;
          * if (World.EntityManager.HasComponent<Controller>(e))
          * {
          *  cameraID = World.EntityManager.GetComponentData<Controller>(e).cameraID;
          * }*/
         World.EntityManager.AddComponentData(e, new Shooter
         {
             attackForce  = datum.Value.attackForce, // get this from stats!
             attackDamage = datum.Value.attackDamage,
             bulletMetaID = datum.bullet.Value.id    //,
                                                     // cameraID = cameraID
         });
     }
 }