Ejemplo n.º 1
0
        /// <inheritdoc />
        public IProjectile SpawnProjectile(ProjectileType projectileType, Vector3 position, Quaternion initRotation, IPlayer player, Vector3 movement)
        {
            var newProjectile = projectileType.ShootProjectile(GetNewID(entities), this, player, position, initRotation, movement);

            if (newProjectile != null)
            {
                RegisterEntity(newProjectile);
                projectiles.Add(newProjectile.ID, newProjectile);
            }

            return(newProjectile);
        }
Ejemplo n.º 2
0
            /// <summary>
            /// Creates a loader that loads the <paramref name="storedProjectile"/> into the <paramref name="level"/>.
            /// </summary>
            /// <param name="level">The level the projectile is being loaded into.</param>
            /// <param name="storedProjectile">The stored data of the projectile.</param>
            public Loader(LevelManager level,
                          StProjectile storedProjectile)
            {
                this.level            = level;
                this.storedProjectile = storedProjectile;
                this.componentLoaders = new List <DefaultComponentLoader>();

                type = level.Package.GetProjectileType(storedProjectile.TypeID);
                if (type == null)
                {
                    throw new ArgumentException($"Projectile type {storedProjectile.TypeID} was not loaded");
                }
            }
Ejemplo n.º 3
0
            /// <summary>
            /// Creates new projectile in the level.
            /// </summary>
            /// <param name="ID">The id of the new projectile.</param>
            /// <param name="level">Level the projectile is created in.</param>
            /// <param name="player">Owner of the new projectile.</param>
            /// <param name="position">Initial position of the projectile.</param>
            /// <param name="rotation">Initial rotation of the projectile.</param>
            /// <param name="type">Type of the projectile.</param>
            /// <returns>New projectile created in the level.</returns>
            public static Projectile CreateNew(int ID,
                                               ILevelManager level,
                                               IPlayer player,
                                               Vector3 position,
                                               Quaternion rotation,
                                               ProjectileType type)
            {
                Node projectileNode;

                try {
                    projectileNode      = type.Assets.Instantiate(level, position, rotation);
                    projectileNode.Name = NodeName;
                }
                catch (Exception e) {
                    string message = $"There was an Exception while creating a projectile: {e.Message}";
                    Urho.IO.Log.Write(LogLevel.Error, message);
                    throw new CreationException(message, e);
                }

                try {
                    new ProjectileComponentSetup().SetupComponentsOnNode(projectileNode, level);

                    var projectile = new Projectile(ID, level, type, player);
                    projectileNode.AddComponent(projectile);

                    projectileNode.NodeCollisionStart += projectile.CollisionHandler;

                    projectile.ProjectilePlugin = type.GetNewInstancePlugin(projectile, level);
                    return(projectile);
                }
                catch (Exception e) {
                    projectileNode.Remove();
                    projectileNode.Dispose();

                    string message = $"There was an Exception while creating a projectile: {e.Message}";
                    Urho.IO.Log.Write(LogLevel.Error, message);
                    throw new CreationException(message, e);
                }
            }
Ejemplo n.º 4
0
        /// <inheritdoc />
        public IProjectile SpawnProjectile(ProjectileType projectileType, Vector3 position, Quaternion initRotation, IPlayer player, IRangeTarget target)
        {
            IProjectile newProjectile;

            try {
                newProjectile = projectileType.ShootProjectile(GetNewID(entities), this, player, position, initRotation, target);
            }
            catch (CreationException) {
                return(null);
            }
            //Could not spawn projectile, maybe out of range
            if (newProjectile == null)
            {
                return(null);
            }


            RegisterEntity(newProjectile);
            projectiles.Add(newProjectile.ID, newProjectile);

            return(newProjectile);
        }