Exemplo n.º 1
0
        private void SetPlayerCharacter(Entity entity, int id, Entity world, int metaID, float3 position)
        {
            CharacterDatam characterDatam  = meta[metaID];
            var            voxelDimensions = new int3(16, 64, 16);

            if (worldSpawnSystem != null)
            {
                voxelDimensions = World.EntityManager.GetComponentData <Voxels.World>(world).voxelDimensions;
            }

            Inventory inventory = new Inventory {
            };

            inventory.InitializeItems(9, characterDatam.items);
            World.EntityManager.SetComponentData(entity, inventory);

            QuestLog questlog = new QuestLog {
            };

            questlog.Initialize(characterDatam.quests);
            World.EntityManager.SetComponentData(entity, questlog);

            World.EntityManager.SetComponentData(entity, new ItemHitTaker {
                radius = characterDatam.itemPickupRadius
            });
            StatbarSystem.SpawnPlayerStatbar(World.EntityManager, entity);
            ActionbarSystem.SpawnUI(World.EntityManager, entity);
            CrosshairSpawnSystem.SpawnUI(World.EntityManager, entity);
            World.EntityManager.SetComponentData(entity, new ChunkStreamPoint
            {
                world           = world,
                voxelDimensions = voxelDimensions,
                didUpdate       = 1,
                chunkPosition   = VoxelRaycastSystem.GetChunkPosition(new int3(position), voxelDimensions)
            });
        }
Exemplo n.º 2
0
        private void StartDying(Entity statsEntity, int zoxID)
        {
            float3 position = World.EntityManager.GetComponentData <Translation>(statsEntity).Value;

            if (World.EntityManager.HasComponent <Character>(statsEntity))
            {
                CharacterDatam characterDatam = characterSpawnSystem.meta[World.EntityManager.GetComponentData <Character>(statsEntity).metaID];
                for (int i = 0; i < characterDatam.dropItems.Count; i++)
                {
                    ItemDatam itemToDrop = characterDatam.dropItems[i].GetItem();
                    itemSpawnSystem.QueueItem(position,// + new float3(UnityEngine.Random.Range(-1f, 1f), 0, UnityEngine.Random.Range(-1f, 1f)),
                                              itemToDrop, characterDatam.dropItems[i].GetQuantity());
                }
            }

            playerSpawnSystem.RemoveControllerCharacter(statsEntity);

            // game stuff
            if (World.EntityManager.HasComponent <Skills>(statsEntity))
            {
                World.EntityManager.RemoveComponent <Skills>(statsEntity);
            }
            skillsSystem.RemoveSkills(statsEntity);
            if (World.EntityManager.HasComponent <Stats>(statsEntity))
            {
                World.EntityManager.RemoveComponent <Stats>(statsEntity);
            }
            if (World.EntityManager.HasComponent <BulletHitTaker>(statsEntity))
            {
                World.EntityManager.RemoveComponent <BulletHitTaker>(statsEntity);
            }
            // movement
            if (World.EntityManager.HasComponent <Body>(statsEntity))
            {
                World.EntityManager.RemoveComponent <Body>(statsEntity);
            }
            if (World.EntityManager.HasComponent <WorldBound>(statsEntity))
            {
                World.EntityManager.RemoveComponent <WorldBound>(statsEntity);
            }
            if (World.EntityManager.HasComponent <BodyForce>(statsEntity))
            {
                World.EntityManager.RemoveComponent <BodyForce>(statsEntity);
            }
            if (World.EntityManager.HasComponent <BodyTorque>(statsEntity))
            {
                World.EntityManager.RemoveComponent <BodyTorque>(statsEntity);
            }
            if (World.EntityManager.HasComponent <BodyInnerForce>(statsEntity))
            {
                World.EntityManager.RemoveComponent <BodyInnerForce>(statsEntity);
            }
            // ai
            if (World.EntityManager.HasComponent <Targeter>(statsEntity))
            {
                World.EntityManager.RemoveComponent <Targeter>(statsEntity);
            }
            if (World.EntityManager.HasComponent <Wander>(statsEntity))
            {
                World.EntityManager.RemoveComponent <Wander>(statsEntity);
            }
            if (World.EntityManager.HasComponent <Mover>(statsEntity))
            {
                World.EntityManager.RemoveComponent <Mover>(statsEntity);
            }
            if (World.EntityManager.HasComponent <AIState>(statsEntity))
            {
                World.EntityManager.RemoveComponent <AIState>(statsEntity);
            }
            else
            {
                CrosshairSpawnSystem.RemoveUI(World.EntityManager, statsEntity);
            }

            // int uiIndex = StatbarSystem.GetListIndex(statsComponent.id);
            if (StatbarSystem.frontBars.ContainsKey(zoxID))
            //   if (uiIndex != -1)
            {
                Entity    characterHealthBar = StatbarSystem.frontBars[zoxID];
                StatBarUI statBar1           = World.EntityManager.GetComponentData <StatBarUI>(characterHealthBar);
                statBar1.isDead           = 1;
                statBar1.targetPercentage = 0;
                //statBar1.timeStateChanged = UnityEngine.Time.time;
                World.EntityManager.SetComponentData(characterHealthBar, statBar1);
            }
            if (characterSpawnSystem.characters.ContainsKey(zoxID))
            {
                characterSpawnSystem.characters.Remove(zoxID);
            }
            World.EntityManager.AddComponentData(statsEntity, new DyingOne
            {
                timeOfDeath = UnityEngine.Time.time
            });
            if (TurretSpawnerSystem.bases.ContainsKey(zoxID))
            {
                World.EntityManager.AddComponentData(TurretSpawnerSystem.bases[zoxID], new ScaleLerper
                {
                    createdTime = UnityEngine.Time.time,
                    lifeTime    = deadbodyRemovalTime,
                    scaleBegin  = World.EntityManager.GetComponentData <NonUniformScale>(TurretSpawnerSystem.bases[zoxID]).Value,
                    scaleEnd    = float3.zero
                });
            }
            World.EntityManager.AddComponentData(statsEntity, new ScaleLerper
            {
                createdTime = UnityEngine.Time.time,
                lifeTime    = deadbodyRemovalTime,
                scaleBegin  = World.EntityManager.GetComponentData <NonUniformScale>(statsEntity).Value,
                scaleEnd    = float3.zero
            });
        }