Example #1
0
        /// <summary>
        /// returns the pokemon's camera offset
        /// </summary>
        /// <param name="pokemonName"></param>
        /// <param name="entity"></param>
        /// <param name="entityManager"></param>
        public static void SetPokemonCameraData(ByteString30 pokemonName, Entity entity, EntityManager entityManager)
        {
            PokemonCameraData pcd = new PokemonCameraData {
                thridPersonOffset = new float3(0, 5f, -10f),
                firstPersonOffset = new float3(0, 2f, 0f)
            };

            switch (pokemonName.ToString())
            {
            case "Bulbasaur":
                break;

            case "Ivysaur":
                break;

            case "Venasaur":
                break;

            case "Electrode":
                pcd = new PokemonCameraData
                {
                    thridPersonOffset = new float3(0, 2f, 3.5f),
                    firstPersonOffset = new float3(0, 0.3f, -0.35f)
                };
                break;

            case "Cubone":
                pcd = new PokemonCameraData {
                    firstPersonOffset = new float3(0, 0.3f, -0.35f),
                    thridPersonOffset = new float3(0, 1f, -3f)
                };
                break;

            default:
                Debug.LogError("Failed to get pokemonCameraData!");
                break;
            }
            if (entityManager.HasComponent <PokemonCameraData>(entity))
            {
                entityManager.SetComponentData <PokemonCameraData>(entity, pcd);
            }
            else
            {
                entityManager.AddComponentData(entity, pcd);
            }
        }
Example #2
0
        public static GameObject GetGameObjectPrefab(ByteString30 name, int type = 0)
        {
            GameObject go   = null;
            string     path = "";

            switch (type)
            {
            case 0: path += "Pokemon/" + name + "/" + name; break;

            case 1: path += "Pokemon/PokemonMoves/" + name + "/" + name; break;

            case 2: path += "Enviroment/" + name; break;

            default: Debug.LogWarning("Failed to load the render mesh for \"" + name + "\""); return(null);
            }
            go = Resources.Load(path) as GameObject;
            return(go);
        }
Example #3
0
        /// <summary>
        /// gets the render mesh for any gameobject (that has been coded) and set the RenderMesh Component Data
        /// </summary>
        /// <param name="entityManager">EntityManager</param>
        /// <param name="entity">entity to be modified</param>
        /// <param name="name">base name of the entity</param>
        /// <param name="type">type of entity 0 = Pokemon, 1 = PokemonMove</param>
        /// <returns></return>
        public static bool SetRenderMesh(EntityManager entityManager, Entity entity, ByteString30 name, int type = 0)
        {
            GameObject go   = null;
            string     path = "";

            switch (type)
            {
            case 0: path += "Pokemon/" + name + "/" + name; break;

            case 1: path += "Pokemon/PokemonMoves/" + name + "/" + name; break;

            case 2: path += "Enviroment/" + name; break;

            default: Debug.LogWarning("Failed to load the render mesh for \"" + name + "\""); return(false);
            }
            go = Resources.Load(path) as GameObject;
            try
            {
                RenderMesh rm = new RenderMesh
                {
                    mesh           = go.GetComponent <MeshFilter>().sharedMesh,
                    castShadows    = UnityEngine.Rendering.ShadowCastingMode.On,
                    material       = go.GetComponent <MeshRenderer>().sharedMaterial,
                    receiveShadows = true
                };
                if (entityManager.HasComponent <RenderMesh>(entity))
                {
                    entityManager.SetSharedComponentData(entity, rm);
                }
                else
                {
                    entityManager.AddSharedComponentData(entity, rm);
                }
            }
            catch
            {
                Debug.LogError("Exception Rose when trying to create RenderMesh with name \"" + name + "\" with type " + type.ToString());
            }
            return(false);
        }
Example #4
0
        /*public void setMoveEntityData(Entity moveEntity, Entity mEntity, PokemonMove pokemonMove,
         *                      PokemonEntityData pmd, EntityManager entityManager, PlayerInput pi)
         *              {
         *                      PokemonMoveDataSpawn pmds = Core.Spawning.PokemonMoveSpawn.getPokemonMoveDataSpawn(entityManager,
         *                              pokemonMove.name, mEntity, pmd);
         *                      Debug.Log("Spawning "+ (pokemonMove.name) + pokemonMove.index);
         *                      entityManager.SetName(moveEntity, (pokemonMove.name) + pokemonMove.index);
         *                      entityManager.SetSharedComponentData(moveEntity, renderMeshDefault);
         *                      entityManager.SetComponentData(moveEntity, pmds.translation);
         *                      entityManager.SetComponentData(moveEntity, pmds.rotation);
         *                      entityManager.SetComponentData(moveEntity, GetPokemonMoveDataEntity(pokemonMove.name, pmd, pi.forward));
         *                      if (pmds.hasCollider) entityManager.SetComponentData(moveEntity, pmds.physicsCollider);
         *                      if (pmds.hasPhysicsVelocity) entityManager.SetComponentData(moveEntity, pmds.physicsVelocity);
         *                      if (pmds.hasMass) entityManager.AddComponentData(moveEntity, pmds.physicsMass);
         *                      if (pmds.hasDamping) entityManager.AddComponentData(moveEntity, pmds.physicsDamping);
         *                      if (pmds.hasGravityFactor) entityManager.AddComponentData(moveEntity, pmds.physicsGravityFactor);
         *                      if (pmds.hasParticles)
         *                      {
         *                              entityManager.AddComponentData(moveEntity, new ParticleSystemRequest { });
         *                              entityManager.AddComponentData(moveEntity, new ParticleSystemData { });
         *                              ParticleSystemSpawnData pssd = PokemonMoves.getPokemonMoveParticleSystemData(pmd.PokedexNumber,(pokemonMove.name));
         *                              if (pssd.isValid)
         *                              {
         *                                      Debug.Log("detected particleSystemspawn data");
         *                                      entityManager.AddComponentData(moveEntity, pssd);
         *                              }
         *                      }
         *                      if (pmds.hasEntity)
         *                      {
         *                              EntityManager.SetComponentData(moveEntity, new EntityParent {isValid = true,entity = pokemonMove.entity });
         *                              EntityManager.AddComponentData(mEntity, new EntityChild { isValid = true, entity = moveEntity });
         *                              EntityManager.AddComponentData(mEntity, GetPokemonMoveDataEntity(pokemonMove.name, pmd, pi.forward));
         *                      }
         *              }*/
        public static PokemonMoveDataEntity GetPokemonMoveDataEntity(ByteString30 name, PokemonEntityData ped, float3 forward)
        {
            PokemonMoveDataEntity pmde = new PokemonMoveDataEntity {
            };

            switch (name.ToString())
            {
            case "Tackle":
                pmde = new PokemonMoveDataEntity
                {
                    name        = name,
                    accuracy    = 1f,
                    attackType  = PokemonMoves.AttackType.normal,
                    damage      = calculateDamage(ped.currentLevel, 40f),
                    statusType  = PokemonMoves.StatusType.none,
                    contactType = PokemonMoves.ContactType.Physical,
                    isValid     = true,
                    pokemonMoveAdjustmentData = new PokemonMoveAdjustmentData
                    {
                        isValid = true,
                        pokemonMoveVelocitySet = new PokemonMoveVelocitySet
                        {
                            value = new PokemonMoveAdjustmentSet
                            {
                                A = new PokemonMoveAdjustment
                                {
                                    value = new float3 {
                                        x = ped.Speed, y = 0f, z = ped.Speed
                                    },
                                    timeLength         = -1f,
                                    useCameraDirection = true,
                                    staminaCost        = 5f
                                },
                                isValid = true
                            }
                        }
                    },
                    forward          = forward,
                    hasParticles     = true,
                    preformActionsOn = true
                };
                break;

            case "ThunderBolt":
                pmde = new PokemonMoveDataEntity
                {
                    attackType  = PokemonMoves.AttackType.electric,
                    contactType = PokemonMoves.ContactType.Special,
                    name        = name,
                    isValid     = true,
                    statusType  = PokemonMoves.StatusType.none,
                    accuracy    = 1f,
                    damage      = calculateDamage(ped.currentLevel, 40f),
                    pokemonMoveAdjustmentData = new PokemonMoveAdjustmentData
                    {
                        isValid = true,
                        pokemonMoveVelocitySet = new PokemonMoveVelocitySet
                        {
                            value = new PokemonMoveAdjustmentSet
                            {
                                isValid = true,
                                A       = new PokemonMoveAdjustment
                                {
                                    timeLength = 1f,
                                    value      = new float3 {
                                        x = 50f, y = 1f, z = 50f
                                    },
                                    useCameraDirection = true,
                                },
                                B = new PokemonMoveAdjustment
                                {
                                    timeLength = 0.5f,
                                    value      = new float3 {
                                        x = 0, y = 100f, z = 0
                                    },
                                    useCameraDirection = false
                                },
                                C = new PokemonMoveAdjustment
                                {
                                    timeLength = 0.1f,
                                    value      = new float3 {
                                        x = 0, y = -1000f, z = 0
                                    },
                                    useCameraDirection = false
                                }
                            }
                        }
                    },
                    forward          = forward,
                    hasParticles     = true,
                    preformActionsOn = true
                };
                break;

            default:
                Debug.LogError("failed to find a matching pokemon move data entity");
                break;
            }
            return(pmde);
        }
Example #5
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
            }
        }
Example #6
0
        public static bool SetPhysicsDamping(EntityManager entityManager, Entity entity, ByteString30 name, PokemonEntityData ped)
        {
            PhysicsDamping ps = new PhysicsDamping
            {
                Angular = 0.05f,
                Linear  = 0.01f
            };

            switch (name.ToString())
            {
            case "Electrode":
                ps = new PhysicsDamping
                {
                    Angular = 0.5f,
                    Linear  = 0.1f
                };
                break;

            default: Debug.LogError("failed to find PhysicsDamping for pokemon \"" + name + "\""); break;
            }
            try
            {
                if (entityManager.HasComponent <PhysicsDamping>(entity))
                {
                    entityManager.SetComponentData <PhysicsDamping>(entity, ps);
                }
                else
                {
                    entityManager.AddComponentData(entity, ps);
                }
                return(true);
            }
            catch
            {
                Debug.LogError("Failed to set AngularDamping!");
            }
            return(false);
        }