Ejemplo n.º 1
0
        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());
            }
        }
Ejemplo n.º 2
0
        private void SpawnVoxel(Entity e, VoxelDatam voxelMeta)
        {
            CharacterRaycaster caster     = World.EntityManager.GetComponentData <CharacterRaycaster>(e);
            WorldBound         worldBound = World.EntityManager.GetComponentData <WorldBound>(e);

            if (caster.DidCast() == 1)
            {
                //Debug.LogError("Spawning voxel at: " + caster.voxelPosition.ToString());
                VoxelSpawnSystem.QueueVoxel(caster.voxelPosition, worldBound.world, voxelMeta.Value.id);
            }
        }
Ejemplo n.º 3
0
 protected override void OnUpdate()
 {
     Entities.WithAll <CharacterRaycaster>().ForEach((Entity e, ref CharacterRaycaster raycaster) =>
     {
         if (raycaster.commandID == 0)
         {
             if (UnityEngine.Time.time - raycaster.lastCasted >= 0.1f)
             {
                 raycaster.lastCasted = UnityEngine.Time.time;
                 if (voxelRaycastSystem != null)
                 {
                     Entity camera = raycaster.camera;
                     var zoxID     = World.EntityManager.GetComponentData <ZoxID>(camera).id;
                     if (World.EntityManager.HasComponent <Controller>(e))
                     {
                         Controller controller = World.EntityManager.GetComponentData <Controller>(e);
                         WorldBound worldBound = World.EntityManager.GetComponentData <WorldBound>(e);
                         if (controller.inputType == (byte)(DeviceType.KeyboardMouse))
                         {
                             float2 screenPosition = cameraSystem.GetScreenPosition(zoxID);
                             raycaster.commandID   = voxelRaycastSystem.QueueRaycast(screenPosition, worldBound.world, camera);
                         }
                         else
                         {
                             float2 screenPosition = cameraSystem.GetScreenPosition(zoxID, new float2(Screen.width / 2f, Screen.height / 2f));
                             raycaster.commandID   = voxelRaycastSystem.QueueRaycast(screenPosition, worldBound.world, camera);
                         }
                     }
                     else
                     {
                         Debug.LogError("Raycasting not supported by npcs yet.");
                         //raycaster.commandID = voxelRaycastSystem.QueueRaycast(screenPosition, raycaster.cameraID);
                     }
                 }
             }
         }
         else
         {
             if (VoxelRaycastSystem.commandOutputPositions.ContainsKey(raycaster.commandID))
             {
                 raycaster.voxelPosition = VoxelRaycastSystem.PullPosition(raycaster.commandID);
                 raycaster.commandID     = 0;
             }
         }
         if (raycaster.DidCast() == 1)
         {
             voxelPreviewSystem.SetPosition(raycaster.voxelPosition - new float3(0, 0.49f, 0));
             // Bootstrap.instance.selectedVoxel.transform.position = ;
         }
     });
 }
Ejemplo n.º 4
0
        private byte GetVoxelType(Voxels.World world, WorldBound worldBound, int3 voxelPosition)
        {
            var   chunkPosition = VoxelRaycastSystem.GetChunkPosition(voxelPosition, worldBound.voxelDimensions);
            Chunk chunk;

            if (GetChunk(world, chunkPosition, out chunk) && chunk.Value.voxels.Length > 0)
            {
                if (chunk.isGenerating == 1)
                {
                    return(1);
                }
                int voxelIndex = VoxelRaycastSystem.GetVoxelArrayIndex(voxelPosition - chunk.GetVoxelPosition(), worldBound.voxelDimensions);
                if (voxelIndex >= chunk.Value.voxels.Length)
                {
                    return(1);
                }
                return(chunk.Value.voxels[voxelIndex]);
            }
            return(1);
        }
Ejemplo n.º 5
0
 protected override void OnUpdate()
 {
     Entities.WithAll <Equipment>().ForEach((Entity e, ref Equipment equipment) =>
     {
         if (equipment.dirty == 1)
         {
             equipment.dirty = 0;
             // get VoxData of the character stored in world system
             VoxData model = new VoxData {
                 id = Bootstrap.GenerateUniqueID()
             };    // make this part of equipment
             //var voxes = new List<VoxData>();
             //var positions = new List<int3>();    // after added them all, offset all positions by min, also get max to use as size
             //var operations = new List<VoxOperation>();
             var bodyLayer = new VoxBuildLayer();
             bodyLayer.Init();
             var gearLayer = new VoxBuildLayer();
             gearLayer.Init();
             for (int i = 0; i < equipment.body.Length; i++)
             {
                 // first find core
                 // then for its meta
                 // find any children of that core
                 // then loop for them
                 // different merge function for each axis enum + the offset of the slot
                 var core = equipment.body[i].data;
                 if (meta.ContainsKey(core.id))
                 {
                     if (core.maleSlot.id == 0)
                     {
                         var coreDatam = meta[core.id];
                         //Debug.LogError("Adding Core");
                         bodyLayer.voxes.Add(coreDatam.model.data);
                         bodyLayer.positions.Add(int3.Zero());
                         bodyLayer.operations.Add(VoxOperation.None);
                         bodyLayer.parents.Add(-1);
                         bodyLayer.bonePositions.Add(coreDatam.model.data.size / 2);
                         bodyLayer.axes.Add((byte)SlotAxis.Center);
                         //float3 realPosition = coreDatam.model.data.size.ToFloat3()/2f;
                         //bodyLayer.realPositions.Add(realPosition);
                         AddChildren(ref equipment,
                                     ref bodyLayer, ref gearLayer, //ref voxes, ref positions, ref operations,
                                     VoxOperation.None, core, i, int3.Zero());
                         break;
                     }
                 }
             }
             // combine voxes
             var combinedVoxes = new List <VoxData>();
             combinedVoxes.AddRange(bodyLayer.voxes);
             combinedVoxes.AddRange(gearLayer.voxes);
             var combinedPositions = new List <int3>();
             combinedPositions.AddRange(bodyLayer.positions);
             combinedPositions.AddRange(gearLayer.positions);
             int3 size = VoxData.GetSize(combinedVoxes, combinedPositions);
             int3 min;
             int3 max;
             VoxData.CalculateMinMax(combinedVoxes, combinedPositions, out min, out max);
             int3 addition       = VoxData.CalculateAddition(min, max);
             bodyLayer.positions = VoxData.FixPositions(bodyLayer.positions, addition);
             gearLayer.positions = VoxData.FixPositions(gearLayer.positions, addition);
             model.Build(bodyLayer, gearLayer, size);
             // updates body model using this new vox data
             float3 bodySize = model.GetSize();
             World.EntityManager.SetComponentData(e, new Body {
                 size = bodySize
             });
             WorldBound worldBound = World.EntityManager.GetComponentData <WorldBound>(e);
             worldBound.size       = bodySize;
             World.EntityManager.SetComponentData(e, worldBound);
             // this can be done in equip system
             int id = World.EntityManager.GetComponentData <ZoxID>(e).id;
             //Debug.LogError("Equipment Mesh updated for: " + id);
             WorldSpawnSystem.QueueUpdateModel(World.EntityManager, e, id, model);
             if (World.EntityManager.HasComponent <Skeleton>(e))
             {
                 var skeleton = World.EntityManager.GetComponentData <Skeleton>(e);
                 //skeleton.SetBody(model.size, bodyLayer.positions, bodyLayer.voxes);
                 combinedPositions       = VoxData.FixPositions(combinedPositions, addition);
                 bodyLayer.bonePositions = VoxData.FixPositions(bodyLayer.bonePositions, addition);
                 skeleton.SetBody(model.size, combinedPositions, combinedVoxes);
                 skeleton.SetBones(World.EntityManager, e, bodyLayer.positions.ToArray(), bodyLayer.voxes.ToArray(), bodyLayer.bonePositions.ToArray(),
                                   bodyLayer.parents.ToArray(), bodyLayer.axes.ToArray());
                 World.EntityManager.SetComponentData(e, skeleton);
             }
         }
     });
 }