示例#1
0
        /// <summary>
        /// Attempts to spawn an item at a spawn point.
        /// If successful the return value will be true otherwise false.
        /// </summary>
        /// <param name="toSpawn">The transform of the object to spawn</param>
        /// <returns>True if the spawn was successful otherwise false</returns>
        public virtual bool spawn(Transform toSpawn)
        {
#if ULTIMATE_SPAWNER_NETWORKED == true
            if (isServer == false)
            {
                NetError.raise();
            }
#endif

            // Check if we can spawn
            if (canSpawn() == false)
            {
                // Trigger failed
                invokeSpawnFailedEvent();
                return(false);
            }

            // Get the spawn point
            ISpawn spawn = this.selectSpawn(spawnMode);

            // Get the spawn info
            SpawnInfo info = spawn.getSpawnInfo();

            // Spawn the item
            info.spawnObjectAt(toSpawn);

            // Success
            invokeSpawnedEvent(toSpawn);

            return(true);
        }
示例#2
0
        /// <summary>
        /// Maintains an enumerator state between calls so thet subsiquent calls to this method will return the next spawn inline.
        /// </summary>
        /// <param name="inSpawn">Extension input</param>
        /// <returns></returns>
        public static ISpawn sequentialSpawn(this ISpawn inSpawn)
        {
            // Check for existing
            if (sequential.ContainsKey(inSpawn) == false)
            {
                sequential.Add(inSpawn, inSpawn.GetEnumerator());
            }

            // Get the keypair
            IEnumerator <ISpawn> enumerator = sequential[inSpawn];

            // Try to move the enumerator otherwise reset it
            if (enumerator.MoveNext() == false)
            {
                // Reset the enumerator (Cant use Reset in this case), Move next makes usre we start at the first item
                sequential[inSpawn] = inSpawn.GetEnumerator();
                sequential[inSpawn].MoveNext();

                // Update the local enumerator
                enumerator = sequential[inSpawn];
            }

            // Get the current spawn
            return(enumerator.Current);
        }
示例#3
0
        /// <summary>
        /// Attempt to spawn an item using current settings.
        /// </summary>
        /// <returns>The transform of the spawned item</returns>
        public override Transform spawn()
        {
#if ULTIMATE_SPAWNER_NETWORKED == true
            if (isServer == false)
            {
                NetError.raise();
            }
#endif

            // Make sure we can spawn
            if (canSpawn() == false)
            {
                // Spawn failed
                invokeSpawnFailedEvent();
                return(null);
            }

            // Select the spawn location
            ISpawn spawn = this.selectSpawn(spawnMode);

            // Call spawn on the child
            Transform result = spawn.spawn();

            // Trigger event
            if (result == null)
            {
                invokeSpawnFailedEvent();
            }
            else
            {
                invokeSpawnedEvent(result);
            }

            return(result);
        }
示例#4
0
        // Constructor
        /// <summary>
        /// Create a new instance of the spawn info using a spawn location.
        /// </summary>
        /// <param name="owner">The spawn location that created this instance</param>
        /// <param name="transform">The transform representing the location and rotation</param>
        public SpawnInfo(ISpawn owner, Transform transform)
        {
            // Store the owner of this spawn point
            this.owner = owner;

            // Get the transform information
            this.spawnPoint    = transform.position;
            this.spawnRotation = transform.rotation;
        }
示例#5
0
文件: Npc.cs 项目: steynh/GamingMinor
        public Npc(World world, ISpawn spawn, int difficulty)
            : base(world, spawn)
        {
            World = world;
            VisionRectangle = new VectorRectangle();

            this.Difficulty = difficulty;

            //makeBody();
            hitBehaviour = new HitBehaviour(this);
        }
示例#6
0
        public void Summon(ISpawn spawn)
        {
            if (this.spawns[spawn.Rank] <= 0)
            {
                throw new SpawnInventoryFullException("A Player cannot have more than 7 Junior, 5 Regular or 3 Senior Spawns!");
            }

            this.playerInventory.Add(spawn);

            this.spawns[spawn.Rank]--;

            FileLogger.Log($" -- Player {this.Name} has summoned {spawn.Rank} {spawn.Type} {spawn.Name}!");
        }
示例#7
0
 // Methods
 /// <summary>
 /// Iterates through all child spawns in a specified spawn and returns a collection of un-occupied spawns.
 /// </summary>
 /// <param name="inSpawn">Extension input</param>
 /// <returns></returns>
 public static IEnumerable <ISpawn> freeSpawns(this ISpawn inSpawn)
 {
     // Iterate through the spawn to check if there are any free spawns
     foreach (ISpawn spawn in inSpawn)
     {
         // Check if the spawn is occupied
         if (spawn.canSpawn() == true)
         {
             // Get the item
             yield return(spawn);
         }
     }
 }
示例#8
0
        /// <summary>
        /// Returns true of the spawner is configured correctly.
        /// </summary>
        /// <param name="inSpawn">The spawn point to validate</param>
        /// <returns>True is the spawner is correctly configured</returns>
        public static bool isValidConfiguration(this ISpawn inSpawn)
        {
            // Check for correct setup
            if (inSpawn.SpawnSettings == SpawnSettings.Custom)
            {
                if (inSpawn.Spawner == null)
                {
                    return(false);
                }
            }

            return(true);
        }
    private void Start()
    {
        navMesh = GetComponent <NavMeshAgent>();

        moveSystem         = new AIMovementSystem();
        invisibilitySystem = new InvisibilitySystem();
        spawnSystem        = new SpawnSystem();

        moveSystem.Setup(speed, raycastLimit);
        moveSystem.TriggerMovement(transform);

        invisibilitySystem.Show(false, model.gameObject);
    }
示例#10
0
        public Character(IParent parent, ISpawn spawn = null)
            : base(parent)
        {
            Spawn = spawn;
            MovableBehaviour = new MovableBehaviour();

            _onDieListeners = new List<Delegate>();
            _colorBehaviour = new ColorBehaviour(this);

            WalkingAcceleration = 15;
            WalkingSpeed = 40;
            jumpPower = 42;
        }
示例#11
0
    public bool Spawn(GameObject spawnController, Vector2 spawnPosition)
    {
        Instantiate(spawnController, new Vector3(spawnPosition.x, spawnPosition.y, 0), Quaternion.identity);
        ISpawn spawn = spawnController.gameObject.GetComponent <ISpawn>();

        if (spawn != null)
        {
            spawn.Spawn();
            return(true);
        }

        return(false);
    }
示例#12
0
        /// <summary>
        /// Called by Unity.
        /// </summary>
        protected virtual void Start()
        {
            // Check for parent
            if (transform.parent == null)
            {
                return;
            }

            // Get the parent object
            GameObject parentObject = transform.parent.gameObject;

            // Get the ISpawn parent
            parent = parentObject.GetComponent <ISpawn>();
        }
示例#13
0
    public GameObject Spawn(string tag, Vector3?position = null, Quaternion?rotation = null, Transform parent = null, bool willSpawn = false)
    {
        GameObject obj = poolDictionary[tag].Dequeue();

        obj.SetActive(true);
        obj.transform.position = position ?? new Vector3(0f, 0f, 0f);
        obj.transform.rotation = rotation ?? Quaternion.Euler(0f, 0f, 0f);
        poolDictionary[tag].Enqueue(obj);
        ISpawn spawn = obj.GetComponent <ISpawn>();

        if (!(spawn is null))
        {
            spawn.Spawn();
        }
        return(obj);
    }
示例#14
0
    public GameObject SpawnUI(string tag, Vector3?position = null, Transform parent = null)
    {
        GameObject obj = poolDictionary[tag].Dequeue();

        obj.SetActive(true);
        obj.transform.SetParent(parent, false);
        obj.transform.position = position ?? new Vector3(0f, 0f, 0f);
        poolDictionary[tag].Enqueue(obj);
        ISpawn spawn = obj.GetComponent <ISpawn>();

        if (!(spawn is null))
        {
            spawn.Spawn();
        }
        return(obj);
    }
示例#15
0
    public GameObject GetObjectFromPool(GameObject argGameObject, bool argIgnoreAllActiveCheck = false, bool argActivateGameObject = true, bool argShouldPeek = false)
    {
        if (null == argGameObject)
        {
            Debug.LogError("Cannot Get object from pool because given object is null");
            return(null);
        }

        if (m_objectPool.ContainsKey(argGameObject.name))
        {
            if (m_objectPool[argGameObject.name].Peek().activeSelf&& !argIgnoreAllActiveCheck)
            {
                Debug.LogWarning("All objects in queue are active, given key=" + argGameObject.name);
            }

            GameObject poolObject;
            if (argShouldPeek)
            {
                poolObject = m_objectPool[argGameObject.name].Peek().gameObject;
            }
            else
            {
                poolObject = m_objectPool[argGameObject.name].Dequeue().gameObject;
                m_objectPool[argGameObject.name].Enqueue(poolObject);
            }

            if (argActivateGameObject)
            {
                poolObject.SetActive(true);
            }

            ISpawn spawnInterface = poolObject.GetComponent <ISpawn>();

            if (null != spawnInterface)
            {
                spawnInterface.OnSpawn();
            }

            return(poolObject);
        }
        else
        {
            Debug.LogError("Cannot get object from pool because key is invalid, given key=" + argGameObject.name);
            return(null);
        }
    }
示例#16
0
        public static List <ManagedJob> CreateJobs()
        {
            List <ManagedJob> jobCollection = new List <ManagedJob>();
            List <JobElement> jobList       = ConfigurationHelper.GetEnabledJobs();

            foreach (JobElement job in jobList)
            {
                // Look for implementation for the Job
                Type jobImplClass = LoadImplementationClass(ConfigurationHelper.GetJobType(job));

                if (jobImplClass != null)
                {
                    JobArgumentCollection jac = ConfigurationHelper.GetJobArgumentCollection(job);

                    List <object> arguments = new List <object>();
                    arguments.Add(job.Name);
                    arguments.Add(job.WaitForEvent);
                    arguments.Add(jac);

                    // Create an instance of the job
                    ManagedJob managedJob = Activator.CreateInstance(jobImplClass, arguments.ToArray()) as ManagedJob;

                    ISpawn spawn = managedJob as ISpawn;

                    if (spawn != null)
                    {
                        ManagedJob[] spawnedJobs = spawn.SpawnJobs();

                        foreach (ManagedJob j in spawnedJobs)
                        {
                            job.Log.FileName = Path.Combine(Path.GetDirectoryName(job.Log.FileName), j.Name) + Path.GetExtension(job.Log.FileName);
                            InitializeTracing(j, job.Log);
                            jobCollection.Add(j);
                        }
                    }
                    else
                    {
                        InitializeTracing(managedJob, job.Log);
                        jobCollection.Add(managedJob);
                    }
                }
            }

            return(jobCollection);
        }
示例#17
0
    void Start()
    {
        spawn = FindObjectOfType<ISpawn>();
        BeforeGameStart();

        if (!player)
        {
            player = FindObjectOfType<CPlayer>();
        }

        if (!camera)
        {
            camera = FindObjectOfType<CameraMovement>();
            if (camera) camera.SetTarget(player);
        }

        OnGameStart(player);
    }
示例#18
0
        /// <summary>
        /// Selects a spawn based on the spawn mode from the collection of child spawns that are available.
        /// </summary>
        /// <param name="inSpawn">Extension input</param>
        /// <param name="spawnMode">The spawn mode to use for selection</param>
        /// <returns></returns>
        public static ISpawn selectSpawn(this ISpawn inSpawn, SpawnMode spawnMode)
        {
            // Different spawn modes
            switch (spawnMode)
            {
            default:
            case SpawnMode.Random:
            {
                // Select a random spawn (Area or point)
                return(inSpawn.randomSpawn());
            }

            case SpawnMode.Sequential:
            {
                // Select the next spawn (Area or point)
                return(inSpawn.sequentialSpawn());
            }
            }
        }
示例#19
0
        /// <summary>
        /// Iterates through all child spawns and selects a random un-occupied spawn.
        /// </summary>
        /// <param name="inSpawn">Extension input</param>
        /// <returns></returns>
        public static ISpawn randomSpawn(this ISpawn inSpawn)
        {
            // Find all free spawns
            IEnumerable <ISpawn> spawns = inSpawn.freeSpawns();

            // Get the size
            int size = spawns.size();

            // Check for error
            if (size == 0)
            {
                return(null);
            }

            // Select a random index
            int index = Random.Range(0, size);

            // Get the spawn
            return(spawns.element(index));
        }
示例#20
0
        /// <summary>
        /// Create an instance for the current spawner.
        /// </summary>
        /// <param name="inSpawn">The spawn point to spawn from</param>
        /// <returns>The trnsform of the spawned instance</returns>
        public static Transform createSpawnableInstance(this ISpawn inSpawn)
        {
            Transform result = null;

            switch (inSpawn.SpawnSettings)
            {
            case SpawnSettings.Custom:
            {
                // Make sure our spawner is setup
                if (inSpawn.Spawner == null)
                {
                    return(null);
                }

                // Try to spawn the enemy
                GameObject temp = inSpawn.Spawner.createSpawnable();

                if (temp != null)
                {
                    result = temp.transform;
                }
            }
            break;

            case SpawnSettings.UseParent:
            {
                // Make sure our parent is valid
                if (inSpawn.Parent == null)
                {
                    Debug.Log("Null parent");
                    return(null);
                }

                // Try to spawn from our parent
                result = inSpawn.Parent.createSpawnableInstance();
            }
            break;
            }

            return(result);
        }
示例#21
0
        /// <summary>
        /// Returns an instance of the spawn info class representing a free spawn point at the time of calling this method.
        /// This can be used to access the location and rotation of the spawn point for manual spawning.
        /// </summary>
        /// <returns>An instance of the spawn info class representing a specific spawn location</returns>
        public override SpawnInfo getSpawnInfo()
        {
#if ULTIMATE_SPAWNER_NETWORKED == true
            if (isServer == false)
            {
                NetError.raise();
            }
#endif

            // Select a spawn using the spawn mode
            ISpawn spawn = this.selectSpawn(spawnMode);

            // Check for null
            if (spawn == null)
            {
                return(null);
            }

            // Get the spawn info
            return(spawn.getSpawnInfo());
        }
示例#22
0
 public SpawnElementStrategy(ISpawn spawn)
 {
     _spawn = spawn;
 }
示例#23
0
        public static bool TryGetCreepOrSpawn(string name, out ICreep creep, Bodypart[] parts, ISpawn spawn)
        {
            if (Game.instance.creeps.TryGetValue(name, out creep))
            {
                return(true);
            }

            Log(spawn?.SpawnCreep(parts, name).ToString() ?? "-42");

            return(false);
        }
示例#24
0
 private void Awake()
 {
     _spawn      = GetComponent <ISpawn>();
     _destroy    = GetComponent <IDestroy>();
     _difficulty = GetComponent <IDifficulty>();
 }
示例#25
0
 private void SetEnemy(ISpawn enemy)
 {
     spawn = enemy;
 }
示例#26
0
 public Player(World world, ISpawn spawn)
     : base(world, spawn)
 {
     _availableColorList = new List<Color>();
 }
 public void SetSpawner(ISpawn spawn)
 {
     spawner = spawn;
 }