示例#1
0
 public bool IsUpdated()
 {
     if (PokemonDataClass.PokemonBaseData.Length == 0)
     {
         Debug.LogWarning("Pokemon Base Data is Invalid, cannot update it");
         PokemonBaseDataStats             = PokemonDataClass.GenerateBasePokemonDatas();
         PokemonDataClass.PokemonBaseData = PokemonBaseDataStats;
         return(false);
     }
     if (PokemonDataClass.PokemonBaseEntityData.Length == 0)
     {
         Debug.LogWarning("Pokemon Base Entity Data is Invalid, cannot update it");
         PokemonEntityDataStats = PokemonDataClass.GenerateBasePokemonEntityDatas();
         PokemonDataClass.PokemonBaseEntityData = PokemonEntityDataStats;
         return(false);
     }
     if (PokemonDataClass.PokemonBaseColliderData.Length == 0)
     {
         Debug.LogWarning("Pokemon Base Collider Data is Invalid, cannot update it");
         PokemonDataClass.PokemonBaseColliderData = PokemonDataClass.GenerateBasePokemonColliderData();
         return(false);
     }
     else if (PokemonBaseDataStats != PokemonDataClass.PokemonBaseData || PokemonEntityDataStats != PokemonDataClass.PokemonBaseEntityData
              /*!PokemonColliderDataStats.IsUpdated(PokemonDataClass.PokemonBaseColliderData)*/)
     {
         return(false);
     }
     return(true);
 }
示例#2
0
        public static void ExecutePhysicalAttack(EntityManager entityManager, string pokemonName, Entity pokemonEntity, PokemonEntityData ped, Scale scale)
        {
            //change the Entity's CollisionFilter From player/entity to attacking player/ entity
            entityManager.AddComponentData(pokemonEntity, PokemonDataClass.getPokemonPhysicsCollider(pokemonName,
                                                                                                     ped,
                                                                                                     new CollisionFilter {
                BelongsTo    = TriggerEventClass.PokemonAttacking,
                CollidesWith = uint.MaxValue,
                GroupIndex   = 1
            }, scale.Value, new Unity.Physics.Material {
                Flags = Unity.Physics.Material.MaterialFlags.IsTrigger
            })
                                           );
            //start physical attack animation

            //let the systems do the rest
        }
示例#3
0
        /// <summary>
        /// Sets the RenderMesh of the given parameters
        /// </summary>
        /// <param name="entityManager">EntityManager</param>
        /// <param name="entity">PokemonMove Entity</param>
        /// <param name="pokemonMoveName">name of the pokemonMove</param>

        /*	public static void SetPokemonMoveRenderMesh(EntityManager entityManager,Entity entity, string pokemonMoveName)
         *      {
         *      //	Debug.Log("Pokemon/PokemonMoves/" + pokemonMoveName + "/" + pokemonMoveName);
         *              GameObject go = Resources.Load("Pokemon/PokemonMoves/"+pokemonMoveName+"/"+pokemonMoveName) as GameObject;
         *              if (go != null)
         *              {
         *                      entityManager.SetSharedComponentData(entity, new RenderMesh
         *                      {
         *                              mesh = go.GetComponent<MeshFilter>().sharedMesh,
         *                              castShadows = UnityEngine.Rendering.ShadowCastingMode.On,
         *                              material = go.GetComponent<MeshRenderer>().sharedMaterial,
         *                              receiveShadows = true
         *                      });
         *              }
         *              else Debug.LogError("Failed to load pokemon move mesh");
         *      }*/
        /// <summary>
        /// Initializes the pokemon move entity
        /// </summary>
        /// <param name="entityManager">EntityManager</param>
        /// <param name="name">name of the pokemon move</param>
        /// <param name="orgEntity">the Entity that executed the move</param>
        /// <param name="entity">the PokemonMove Entity</param>
        /// <param name="ped">PokemonEntityData</param>
        public static void ExecutePokemonMove(EntityManager entityManager, string name, ByteString30 pokemonName, Entity orgEntity, Entity entity, PokemonEntityData ped, GroupIndexSystem groupIndexSystem)
        {
            //test if a move is already being executed on the entity parent
            if (!entityManager.HasComponent <EntityChild>(orgEntity))
            {
                entityManager.AddComponentData <EntityChild>(orgEntity, new EntityChild {
                    entity = entity, isValid = true, followChild = false
                });
                if (groupIndexSystem == null)
                {
                    Debug.LogError("GroupIndexSystem is null");
                }
                Debug.Log("executing pokemon move \"" + name + "\"");
                PokemonMoveDataSpawn  pmds = getPokemonMoveDataSpawn(entityManager, name, orgEntity, ped);
                PlayerInput           pi   = entityManager.GetComponentData <PlayerInput>(orgEntity);
                PokemonMoveDataEntity pmde = GetPokemonMoveDataEntity(new ByteString30(name), ped, pi.forward);
                if (pmds.hasEntity)
                {
                    entityManager.SetComponentData(entity, new EntityParent {
                        entity = orgEntity, isValid = true, followParent = true
                    });
                    if (pmds.projectOnParentInstead)
                    {
                        //				if (pmde.isValid) Debug.Log("It be valid!");
                        entityManager.AddComponentData(orgEntity, pmde);
                        pmde.preformActionsOn = false;
                    }
                }
                CoreData cd = entityManager.GetComponentData <CoreData>(orgEntity);
                entityManager.AddComponentData <CoreData>(entity, new CoreData(new ByteString30(name), new ByteString30("PokemonMove"), cd.size, cd.scale));

                //get Pokemon's GroupIndex
                GroupIndexInfo gii = entityManager.GetComponentData <GroupIndexInfo>(orgEntity);
                gii.CurrentGroupIndex = groupIndexSystem.GetNextEmptyGroup();
                gii.Update            = true;
                entityManager.SetComponentData(orgEntity, gii);
                int a = groupIndexSystem.ExludeGroupIndexNumber(gii.CurrentGroupIndex);
                //		Debug.Log("AAAAAAAAAAAAA "+a);
                //add group index but we want this to
                gii = new GroupIndexInfo
                {
                    CurrentGroupIndex  = gii.CurrentGroupIndex,
                    OldGroupIndex      = 0,
                    OriginalGroupIndex = gii.CurrentGroupIndex,
                    Update             = true,
                };
                entityManager.AddComponentData(entity, gii);
                //add/set collider
                if (pmds.hasCollider)
                {
                    if (entityManager.HasComponent <PhysicsCollider>(entity))
                    {
                        entityManager.SetComponentData(entity, pmds.physicsCollider);
                    }
                    else
                    {
                        entityManager.AddComponentData(entity, pmds.physicsCollider);
                    }
                }
                if (pmds.hasDamping)
                {
                    if (entityManager.HasComponent <PhysicsDamping>(entity))
                    {
                        entityManager.SetComponentData(entity, pmds.physicsDamping);
                    }
                    else
                    {
                        entityManager.AddComponentData(entity, pmds.physicsDamping);
                    }
                }
                if (pmds.hasGravityFactor)
                {
                    if (entityManager.HasComponent <PhysicsGravityFactor>(entity))
                    {
                        entityManager.SetComponentData(entity, pmds.physicsGravityFactor);
                    }
                    else
                    {
                        entityManager.AddComponentData(entity, pmds.physicsGravityFactor);
                    }
                }
                if (pmds.hasMass)
                {
                    if (entityManager.HasComponent <PhysicsMass>(entity))
                    {
                        entityManager.SetComponentData(entity, pmds.physicsMass);
                    }
                    else
                    {
                        entityManager.AddComponentData(entity, pmds.physicsMass);
                    }
                }
                if (entityManager.HasComponent <PokemonMoveDataEntity>(entity))
                {
                    entityManager.SetComponentData(entity, pmde);
                }
                else
                {
                    entityManager.AddComponentData(entity, pmde);
                }
                if (pmds.hasPhysicsVelocity)
                {
                    if (entityManager.HasComponent <PhysicsVelocity>(entity))
                    {
                        entityManager.SetComponentData(entity, pmds.physicsVelocity);
                    }
                    else
                    {
                        entityManager.AddComponentData(entity, pmds.physicsVelocity);
                    }
                }
                if (entityManager.HasComponent <Translation>(entity))
                {
                    entityManager.SetComponentData(entity, pmds.translation);
                }
                else
                {
                    entityManager.AddComponentData(entity, pmds.translation);
                }
                if (entityManager.HasComponent <Rotation>(entity))
                {
                    entityManager.SetComponentData(entity, pmds.rotation);
                }
                else
                {
                    entityManager.AddComponentData(entity, pmds.rotation);
                }
                //add particle stuff
                ParticleSystemSpawnData pssd = PokemonMoves.getPokemonMoveParticleSystemData(ped.PokedexNumber, name);
                if (pssd.isValid)
                {
                    Debug.Log("detected particleSystemspawn data");
                    entityManager.AddComponentData(entity, pssd);
                }
                else
                {
                    Debug.LogWarning("ExecutePokemonMove: Failed to get ParticleSystemSpawnData!");
                }
                if (pmds.hasParticles)
                {
                    entityManager.AddComponentData(entity, new ParticleSystemRequest {
                    });
                    entityManager.AddComponentData(entity, new ParticleSystemData {
                    });
                }
                if (!entityManager.HasComponent <Scale>(entity))
                {
                    entityManager.AddComponentData <Scale>(entity, new Scale {
                        Value = 1f
                    });
                }
                else
                {
                    entityManager.SetComponentData <Scale>(entity, new Scale {
                        Value = 1f
                    });
                }
                switch (name)
                {
                case "ThunderBolt":
                    Debug.Log("Spawning ThunderBolt");
                    //set name and render mesg
                    entityManager.SetName(entity, name);
                    //entityManager.SetSharedComponentData(entity, renderMesh);
                    PokemonDataClass.SetRenderMesh(entityManager, entity, pokemonName, 1);
                    break;

                case "Tackle":
                    entityManager.SetName(entity, name);
                    break;

                default: Debug.Log("Failed to set pokemon move data for \"" + name + "\""); break;
                }
                //
                PhysicsCollider op = entityManager.GetComponentData <PhysicsCollider>(orgEntity);
                op = entityManager.GetComponentData <PhysicsCollider>(orgEntity);
                PhysicsCollider tmpA = entityManager.GetComponentData <PhysicsCollider>(entity);
                //		Debug.Log("Chaned original entities collision filter to " + op.Value.Value.Filter.GroupIndex.ToString() + " with entity index = " + tmpA.Value.Value.Filter.GroupIndex.ToString());
            }
            else
            {
                //maybe cancel but for now we do nothing
            }
        }
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            if (pokemonMoveQuery.CalculateEntityCount() == 0)
            {
                return(inputDeps);
            }

            NativeArray <PokemonMove>       pokemonMoves = new NativeArray <PokemonMove>(pokemonMoveQuery.CalculateEntityCount(), Allocator.TempJob);
            NativeArray <PokemonEntityData> pmds         = pokemonMoveQuery.ToComponentDataArray <PokemonEntityData>(Allocator.TempJob);
            NativeArray <PlayerInput>       playerInputs = pokemonMoveQuery.ToComponentDataArray <PlayerInput>(Allocator.TempJob);
            NativeArray <Entity>            entities     = pokemonMoveQuery.ToEntityArray(Allocator.TempJob);
            JobHandle jh = new AttackInputJob
            {
                ecb                = ecbs.CreateCommandBuffer(),
                entities           = entities,
                pokemonEntityDatas = pmds,
                playerInputs       = playerInputs,
                moveSpawnArray     = pokemonMoves
            }.Schedule(inputDeps);

            jh.Complete();
            int i = 0, counter = 0;

            for (; i < pokemonMoves.Length; i++)
            {
                if (pokemonMoves[i].isValid)
                {
                    counter++;
                }
            }
            if (counter > 0)
            {
                NativeArray <Entity> pokemonMoveEntities = new NativeArray <Entity>(counter, Allocator.TempJob);
                EntityManager.CreateEntity(pokemonMoveArchtype, pokemonMoveEntities);
                for (i = 0; i < pokemonMoveEntities.Length; i++)
                {
                    if (pokemonMoves[i].name.ToString() != "spawnPoke")
                    {
                        PokemonMoveSpawn.ExecutePokemonMove(EntityManager, pokemonMoves[i].name.ToString(),
                                                            EntityManager.GetComponentData <CoreData>(entities[i]).BaseName, entities[i],
                                                            pokemonMoveEntities[i], pmds[i], groupIndexSystem);
                    }
                    else
                    {
                        EntityManager.DestroyEntity(pokemonMoveEntities[i]);
                        //ignore this because this is a test anyway and i haven't got to this yet
                        PokemonDataClass.GeneratePokemonEntity(new CoreData
                        {
                            BaseName = new ByteString30("Electrode"),
                            Name     = new ByteString30("Entity"),
                            isValid  = true,
                            scale    = new float3(1f, 1f, 1f),
                            size     = new float3(1f, 1f, 1f)
                        },
                                                               EntityManager,
                                                               quaternion.identity,
                                                               EntityManager.GetComponentData <Translation>(entities[i]).Value + new float3(0, 10, 0)
                                                               );
                    }
                }
                pokemonMoveEntities.Dispose();
            }
            entities.Dispose();
            pmds.Dispose();
            playerInputs.Dispose();
            pokemonMoves.Dispose();
            return(jh);
        }
示例#5
0
    public void Update(EntityManager entityManager, Entity entity)
    {
        if (!EditMode)
        {
            position = entityManager.GetComponentData <Translation>(entity).Value;
            scale    = entityManager.GetComponentData <Scale>(entity).Value;
            temp     = entityManager.GetName(entity).Split(':');
            //	coreData.Name = temp[0];
            //	coreData.BaseName = temp.Length > 1 ? temp[1] : "";
            if (!coreData.IsUpdated(entityManager, entity))
            {
                coreData.Update(entityManager, entity, scale);
            }
            if (entityManager.HasComponent <PhysicsVelocity>(entity) && !physicsVelocity.IsUpdated(entityManager, entity))
            {
                physicsVelocity.Update(entityManager, entity);
            }
            if (entityManager.HasComponent <PhysicsDamping>(entity) && !physicsDamping.IsUpdated(entityManager, entity))
            {
                physicsDamping.Update(entityManager, entity);
            }
            if (entityManager.HasComponent <PhysicsMass>(entity) && !physicsMass.IsUpdated(entityManager, entity))
            {
                physicsMass.Update(entityManager, entity);
            }
            if (entityManager.HasComponent <PokemonEntityData>(entity) && !pokemonEntityData.IsUpdated(entityManager, entity))
            {
                pokemonEntityData.Update(entityManager, entity);
            }
        }
        if (applyChange)
        {
            if (!DoNotChangePosition)
            {
                entityManager.SetComponentData(entity, new Translation {
                    Value = position
                });
            }
            if (!DoNotChangeScale)
            {
                entityManager.SetComponentData(entity, new Scale {
                    Value = scale
                });                                                                                 //got to scale of physics collider as well
                coreData.Update(entityManager, entity, scale);
                PhysicsCollider pc         = entityManager.GetComponentData <PhysicsCollider>(entity);
                int             groupIndex = 1;
                if (entityManager.HasComponent <GroupIndexInfo>(entity))
                {
                    groupIndex = entityManager.GetComponentData <GroupIndexInfo>(entity).CurrentGroupIndex;
                }
                entityManager.SetComponentData(entity, PokemonDataClass.getPokemonPhysicsCollider(coreData.BaseName, pokemonEntityData.ped, pc.Value.Value.Filter, scale, PokemonDataClass.GetPokemonColliderMaterial(PokemonDataClass.StringToPokedexEntry(coreData.BaseName)), groupIndex));
                entityManager.SetComponentData(entity, new Translation
                {
                    Value = entityManager.GetComponentData <Translation>(entity).Value + ((pokemonEntityData.ped.Height * scale) / 2)
                });
            }
            if (!coreData.DoNotChange)
            {
                coreData.Update(entityManager, entity, scale);
            }

            if (!physicsVelocity.DoNotChange)
            {
                physicsVelocity.ApplyChanges(entityManager, entity);
            }
            if (!physicsDamping.DoNotChange)
            {
                physicsDamping.ApplyChanges(entityManager, entity);
            }
            if (!pokemonEntityData.DoNotChange)
            {
                pokemonEntityData.ApplyChange(entityManager, entity);
            }
            if (!physicsMass.DoNotChange)
            {
                physicsMass.ApplyChange(entityManager, entity, pokemonEntityData.ped.Mass);
            }


            if (!constantChange)
            {
                applyChange = false;
                EditMode    = false;
            }
        }
    }