Exemplo n.º 1
0
 private void SetNPCCharacter(Entity entity, int id, int metaID, float3 position) //  Entity world,
 {
     if (meta.ContainsKey(metaID))
     {
         CharacterDatam characterDatam = meta[metaID];
         BehaviourData  beh            = characterDatam.behaviour.Value;
         SetNPC(entity, beh, id, characterDatam.movementSpeed, characterDatam.turnSpeed);
     }
 }
Exemplo n.º 2
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.º 3
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
            });
        }
Exemplo n.º 4
0
        private bool SetCharacter(Entity entity, int id, bool isLoadingPlayer, Entity world, int metaID, int classID, int clanID, float3 position, int creatorID = 0)
        {
            if (!World.EntityManager.Exists(world))
            {
                Debug.LogError("Cannot spawn character into a non existing world.");
                return(false);
            }
            if (!World.EntityManager.HasComponent <Voxels.World>(world))
            {
                Debug.LogError("Cannot spawn character into a world without a component.");
                return(false);
            }
            if (characters.ContainsKey(id) == true)
            {
                return(false);
            }
            characters.Add(id, entity);
            if (!meta.ContainsKey(metaID))
            {
                Debug.LogError("Meta not contained: " + metaID);
                return(false);
            }
            CharacterDatam characterDatam = meta[metaID];

            // ZOXID
            World.EntityManager.SetComponentData(entity,
                                                 new ZoxID
            {
                id        = id,
                clanID    = clanID,
                creatorID = creatorID
            });
            World.EntityManager.SetComponentData(entity,
                                                 new Character
            {
                metaID = metaID
            });
            // WORLD BINDING
            int3 voxelDimensions = new int3(16, 64, 16); // float3.zero;

            if (worldSpawnSystem != null)
            {
                voxelDimensions = World.EntityManager.GetComponentData <Voxels.World>(world).voxelDimensions;
            }
            // TRANSFORMS
            World.EntityManager.SetComponentData(entity, new Translation {
                Value = position
            });
            World.EntityManager.SetComponentData(entity, new Rotation {
                Value = quaternion.identity
            });
            World.EntityManager.SetComponentData(entity, new NonUniformScale
            {
                Value = new float3(1, 1, 1)
            });
            // RENDERING
            World.EntityManager.SetSharedComponentData(entity, new RenderMesh {
                material       = Bootstrap.GetVoxelMaterial(),
                mesh           = new Mesh(),
                castShadows    = UnityEngine.Rendering.ShadowCastingMode.On,
                receiveShadows = true
            });
            float3 bodySize = new float3(0.1f, 0.1f, 0.1f);

            if (characterDatam.vox != null && !isLoadingPlayer)
            {
                bodySize = characterDatam.vox.data.GetSize();
                World.EntityManager.SetComponentData(entity, new Body {
                    size = bodySize
                });
                // this can be done in equip system
                WorldSpawnSystem.QueueUpdateModel(World.EntityManager, entity, id, characterDatam.vox.data);
            }
            World.EntityManager.SetComponentData(entity, new WorldBound {
                size            = bodySize,
                world           = world,
                voxelDimensions = voxelDimensions
            });
            World.EntityManager.SetComponentData(entity, characterDatam.stats.Clone());
            // Physics
            World.EntityManager.SetComponentData(entity, new BodyInnerForce
            {
                movementForce  = characterDatam.movementSpeed,
                movementTorque = characterDatam.turnSpeed,
                maxVelocity    = characterDatam.maxVelocity
            });
            // combat stuff
            World.EntityManager.SetComponentData(entity,
                                                 new Targeter
            {
                Value = characterDatam.behaviour.Value.seek
            });

            if (!isLoadingPlayer)
            {
                if (classID != 0)
                {
                    GiveClassSkills(id, classMeta[classID]);
                }
                else if (characterDatam.defaultClass)
                {
                    GiveClassSkills(id, characterDatam.defaultClass);
                }
            }
            Equipment equipment = new Equipment {
            };

            if (!isLoadingPlayer)
            {
                equipment.EquipBody(characterDatam.body);
                equipment.EquipGear(characterDatam.gear);
            }
            World.EntityManager.SetComponentData(entity, equipment);
            return(true);
        }