示例#1
0
        //called each time a unit/building is dead, only called when the mission type is set to "eliminate" or "produce"
        private void OnFactionEntityEvent (FactionEntity factionEntity)
        {
            //if the faction entity is dead and there are entities that the player is supposed to defend
            if(factionEntity.FactionID == GameManager.PlayerFactionID //only if the dead faction entity belongs to the player faction
                && defendFactionEntities.Length > 0 && factionEntity.EntityHealthComp.IsDead()) 
            {
                foreach(CodeCategoryField codeCategory in defendFactionEntities) //go through the entities that shouldn't be dead
                {
                    if (codeCategory.Contains(factionEntity.GetCode(), factionEntity.GetCategory())) //if the code/category matches
                    {
                        Forfeit(); //mission failed
                        return;
                    }
                }
            }

            if((factionEntity.EntityHealthComp.IsDead() && type == Type.eliminate && factionEntity.FactionID != GameManager.PlayerFactionID) //if this is an elimination mission and the entity doesn't belong to the player's faction
                || (!factionEntity.EntityHealthComp.IsDead() && type == Type.produce && factionEntity.FactionID == GameManager.PlayerFactionID)) //produce mission type and the entity belongs to the player faction
            foreach (CodeCategoryField codeCategory in targetCode) //go through all assigned codes
            {
                if (codeCategory.Contains(factionEntity.GetCode(), factionEntity.GetCategory())) //if the code/category matches
                {
                    OnProgress(1); //positive mission progress
                    break;
                }
            }
        }
示例#2
0
        //check if the attacker can engage target:
        public ErrorMessage CanEngageTarget(FactionEntity potentialTarget)
        {
            if (gameMgr.InPeaceTime() == true)
            {
                return(ErrorMessage.peaceTime);
            }
            else if (potentialTarget == null)                                                   //if there's no target assigned
            {
                return(!requireTarget ? ErrorMessage.none : ErrorMessage.attackTargetRequired); //see if the attack entity can attack without target
            }
            else if (potentialTarget.FactionID == FactionEntity.FactionID && engageFriendly == false)
            {
                return(ErrorMessage.targetSameFaction);
            }
            else if (potentialTarget.EntityHealthComp.CanBeAttacked == false) //peace time, same faction ID or target can't be attacked? -> nope
            {
                return(ErrorMessage.targetNoAttack);
            }

            if (engageAllTypes) //attack all types then yes!
            {
                return(ErrorMessage.none);
            }

            //if the target can't attack units/buildings and this is the case then nope
            if ((potentialTarget.Type == EntityTypes.building && engageBuildings == false) ||
                (potentialTarget.Type == EntityTypes.unit && engageUnits == false))
            {
                return(ErrorMessage.entityNotAllowed);
            }

            return(codesList.Contains(potentialTarget.GetCode(), potentialTarget.GetCategory()) == engageInList ? ErrorMessage.none : ErrorMessage.entityNotAllowed);
        }
示例#3
0
        //a method that returns the damage that is supposed to be dealt to a target.
        public int GetDamage(FactionEntity target)
        {
            foreach (CustomDamage cd in customDamages)                        //see if the target's code is in the custom damages list
            {
                if (cd.code.Contains(target.GetCode(), target.GetCategory())) //if the target is found then pick the custom damage
                {
                    return(cd.damage);
                }
            }

            //no custom damage? pick either the damage for units or for buildings
            return(target.Type == EntityTypes.unit ? unitDamage : buildingDamage);
        }
        /// <summary>
        /// NPCRegulator constructor.
        /// </summary>
        /// <param name="data">Holds information regarding how the faction entity type that will be regulated.</param>
        /// <param name="prefab">FactionEntity derived prefab to regulate.</param>
        /// <param name="gameMgr">GameManager instance of the currently active game.</param>
        /// <param name="npcMgr">NPCManager instance that manages the NPC faction to whome the regulator component belongs.</param>
        public NPCRegulator(NPCRegulatorData data, FactionEntity prefab, GameManager gameMgr, NPCManager npcMgr)
        {
            //assign components
            this.gameMgr = gameMgr;
            Assert.IsNotNull(this.gameMgr, "[NPCRegulator] Initializing without a reference to the GameManager instance is not allowed!");

            this.npcMgr = npcMgr;
            Assert.IsNotNull(this.npcMgr, "[NPCRegulator] Initializing without a reference to the faction's NPCManager instance is not allowed!");

            this.factionMgr = npcMgr.FactionMgr;
            Assert.IsNotNull(this.factionMgr, "[NPCRegulator] Initializing without a reference to the faction's FactionManager instance is not allowed!");

            //pick the rest random settings from the given info.
            MaxAmount        = data.GetMaxAmount();
            MinAmount        = data.GetMinAmount();
            MaxPendingAmount = data.GetMaxPendingAmount();

            Count = 0;

            //get the code and category
            Code     = prefab.GetCode();
            Category = prefab.GetCategory();
        }