Пример #1
0
    /////////////////////////////////////////////////////////////////////////////
    /// Function:               SpawnNPC
    /////////////////////////////////////////////////////////////////////////////
    public static void SpawnNPC(IAIBase.ETeam eTeam, IAIBase.ENPCType eType)
    {
        foreach (GameObject goObject in m_liSpawnPoints)
        {
            CSpawner cSpawner = goObject.GetComponent <CSpawner>();

            if (cSpawner.SpawnerType != ESpawnerType.TYPE_NPC)
            {
                continue;
            }

            if (cSpawner.Team == eTeam && true == cSpawner.CanSpawn)
            {
                cSpawner.Spawn(NPCResource.GetObjectByType(eTeam, eType));
                break;
            }
        }
    }
Пример #2
0
        public void SetTargetResourceLocal(Resource Target)
        {
            if (Target == null)
            {
                return;
            }

            //Check first if the resource needs collectors:
            if (Target.Amount > 0)
            {
                if (TargetResource != Target && Target.CurrentCollectors.Count < Target.MaxCollectors)
                {
                    UnitMvt.CancelCollecting();                      //stop collecting from the last resource

                    TargetResource = null;
                    IsCollecting   = false;

                    Target.CurrentCollectors.Add(gameObject.GetComponent <Unit> ());

                    TargetResource   = Target;
                    LastResourceName = TargetResource.Name;

                    //Search for the nearest drop off building if we are not automatically collecting:
                    if (ResourceMgr.AutoCollect == false)
                    {
                        FindClosetDropOffBuilding();
                    }

                    /*UnitMvt.NavAgent.avoidancePriority = GameManager.Instance.UnitMgr.MinArmyPriority + Target.CurrentCollectors.Count - 1;
                     * if (UnitMvt.NavAgent.avoidancePriority > 99) {
                     * UnitMvt.NavAgent.avoidancePriority = 99;
                     * }*/

                    //if it's a single player game:
                    if (GameManager.MultiplayerGame == false)
                    {
                        //if this unit belongs to a NPC faction
                        if (UnitMvt.FactionID != GameManager.PlayerFactionID)
                        {
                            //if the targer resource is not already inside the exploited resource lists of the NPC Resource mgr.
                            NPCResource NPCResourceMgr = UnitMvt.GameMgr.Factions [UnitMvt.FactionID].FactionMgr.ResourceMgr;
                            if (NPCResourceMgr.ExploitedResources [ResourceMgr.GetResourceID(TargetResource.Name)].Contains(TargetResource) == false)
                            {
                                //add it then:
                                NPCResourceMgr.ExploitedResources [ResourceMgr.GetResourceID(TargetResource.Name)].Add(TargetResource);
                            }
                        }
                    }

                    CurrentCollectionObj = null;
                    //look for the collection object if it exists:
                    if (CollectionInfo.Length > 0)
                    {
                        for (int i = 0; i < CollectionInfo.Length; i++)
                        {
                            if (CollectionInfo [i].ResourceName == TargetResource.Name)
                            {
                                CurrentCollectionObj = CollectionInfo [i].Obj;                                 //set the collection object:

                                //set the collection animation:
                                if (CollectionInfo [i].AnimatorOverride != null)
                                {
                                    UnitMvt.AnimMgr.runtimeAnimatorController = CollectionInfo [i].AnimatorOverride;
                                }
                            }
                        }
                    }
                }

                //Move the unit to the resource:
                UnitMvt.CheckUnitPathLocal(Vector3.zero, TargetResource.gameObject, UnitMvt.GameMgr.MvtStoppingDistance, -1);
            }
        }
Пример #3
0
        public void DestroyResourceLocal(GatherResource Collector)
        {
            //custom event:
            if (GameManager.Instance.Events)
            {
                GameManager.Instance.Events.OnResourceEmpty(this);
            }

            //stop collecting
            Collector.UnitMvt.CancelCollecting();

            if (DestroyOnComplete == true)
            { //if the resource is meant to be destroyed when it has 0 amount
                if (gameObject.GetComponent <Treasure>())
                {
                    Treasure Treasure = gameObject.GetComponent <Treasure>();
                    if (Treasure.Resources.Length > 0)
                    {
                        for (int i = 0; i < Treasure.Resources.Length; i++)
                        { //go through all the resources to reward
                            ResourceMgr.AddResource(Collector.UnitMvt.FactionID, Treasure.Resources[i].Name, Treasure.Resources[i].Amount);
                        }

                        //play the claimed reward sound:
                        if (GameManager.PlayerFactionID == Collector.UnitMvt.FactionID && Treasure.ClaimedAudio != null)
                        { //only if the unit is the local player's faction:
                            AudioManager.PlayAudio(GameManager.Instance.GeneralAudioSource.gameObject, Treasure.ClaimedAudio, false);
                        }
                        //create the effect
                        if (Treasure.ClaimedEffect != null)
                        {
                            Instantiate(Treasure.ClaimedEffect, transform.position, Treasure.ClaimedEffect.transform.rotation);
                        }
                    }
                }

                //remove resource from list:
                GameManager.Instance.ResourceMgr.AllResources.Remove(this);

                //remove the resource minimap icon:
                MinimapIconManager.Instance.RemoveMinimapIcon(PlayerSelection);

                //if this is a single player game
                if (GameManager.MultiplayerGame == false)
                {
                    //if this unit belongs to a NPC faction
                    if (Collector.UnitMvt.FactionID != GameManager.PlayerFactionID)
                    {
                        //if the targer resource is already inside the exploited resource lists of the NPC Resource mgr.
                        NPCResource NPCResourceMgr = GameManager.Instance.Factions[Collector.UnitMvt.FactionID].FactionMgr.ResourceMgr;
                        if (NPCResourceMgr.ExploitedResources[ResourceMgr.GetResourceID(Name)].Contains(this) == false)
                        {
                            //remove it
                            NPCResourceMgr.ExploitedResources[ResourceMgr.GetResourceID(Name)].Remove(this);
                            //trigger searching for resources:
                            NPCResourceMgr.CheckResources = true;
                        }
                    }
                }

                Destroy(gameObject);
            }
        }
Пример #4
0
        public void SetTargetResourceLocal(Resource Target)
        {
            if (Target == null)
            {
                return;
            }

            //Check first if the resource needs collectors:
            if (Target.Amount > 0)
            {
                if (TargetResource != Target)
                {
                    if (Target.WorkerMgr.CurrentWorkers < Target.WorkerMgr.WorkerPositions.Length)
                    {
                        UnitMvt.CancelCollecting(); //stop collecting from the last resource

                        TargetResource = null;
                        IsCollecting   = false;

                        TargetResource = Target;

                        //Search for the nearest drop off building if we are not automatically collecting:
                        if (ResourceMgr.AutoCollect == false)
                        {
                            FindClosetDropOffBuilding();
                        }

                        //if it's a single player game:
                        if (GameManager.MultiplayerGame == false)
                        {
                            //if this unit belongs to a NPC faction
                            if (UnitMvt.FactionID != GameManager.PlayerFactionID)
                            {
                                //if the targer resource is not already inside the exploited resource lists of the NPC Resource mgr.
                                NPCResource NPCResourceMgr = UnitMvt.GameMgr.Factions[UnitMvt.FactionID].FactionMgr.ResourceMgr;
                                if (NPCResourceMgr.ExploitedResources[ResourceMgr.GetResourceID(TargetResource.Name)].Contains(TargetResource) == false)
                                {
                                    //add it then:
                                    NPCResourceMgr.ExploitedResources[ResourceMgr.GetResourceID(TargetResource.Name)].Add(TargetResource);
                                }
                            }
                        }

                        CurrentCollectionObj = null;
                        //look for the collection object if it exists:
                        if (CollectionInfo.Length > 0)
                        {
                            for (int i = 0; i < CollectionInfo.Length; i++)
                            {
                                if (CollectionInfo[i].ResourceName == TargetResource.Name)
                                {
                                    CurrentCollectionObj = CollectionInfo[i].Obj; //set the collection object:

                                    //set the collection animation:
                                    if (CollectionInfo[i].AnimatorOverride != null)
                                    {
                                        UnitMvt.AnimMgr.runtimeAnimatorController = CollectionInfo[i].AnimatorOverride;
                                    }
                                }
                            }
                        }

                        //Move the unit to the resource by registering the unit in the worker manager
                        MovementManager.Instance.MoveLocal(UnitMvt, TargetResource.WorkerMgr.AddWorker(UnitMvt), TargetResource.Radius, TargetResource.gameObject, InputTargetMode.Resource);
                    }
                }
                else
                {
                    MovementManager.Instance.MoveLocal(UnitMvt, TargetResource.WorkerMgr.GetWorkerPos(UnitMvt.LastWorkerPosID), TargetResource.Radius, TargetResource.gameObject, InputTargetMode.Resource);
                }
            }
        }