Exemple #1
0
        //init the faction without modifying the faction attributes
        public void Init(int factionID, FactionManager factionMgr, GameManager gameMgr)
        {
            this.ID         = factionID;
            this.FactionMgr = factionMgr;

            FactionMgr.Init(gameMgr, ID, typeInfo ? typeInfo.GetLimits() : null, this); //init the faction manager component of this faction

            //depending on the faction type, add extra units/buildings (if there's actually any) to be created for each faction:
            if (playerControlled == true)                                                //if this faction is player controlled:
            {
                if (typeInfo != null)                                                    //if this faction has a valid type.
                {
                    gameMgr.PlacementMgr.AddBuildingRange(typeInfo.GetExtraBuildings()); //add the extra buildings so that this faction can use them.
                }
            }
            else if (IsNPCFaction() == true) //if this is not controlled by the local player but rather NPC.
            //Init the NPC Faction manager:
            {
                InitNPCMgr(gameMgr);
            }

            Lost = false;

            CustomEvents.OnFactionInit(this);
        }
Exemple #2
0
        //update for an indirect attack
        public bool OnIndirectAttackUpdate()
        {
            if (sourceStepTimer > 0)
            {
                sourceStepTimer -= Time.deltaTime;
            }
            else
            {
                source.InvokeAttackPerformedEvent();
                //not an area attack:
                CustomEvents.OnAttackPerformed(source, source.Target, source.GetTargetPosition());

                sources[sourceStep].Launch(gameMgr.EffectPool, source);
                if (launchType == LaunchTypes.inOrder)                                //if the attack is supposed to go through attack objects in order and launch them
                {
                    sourceStep++;                                                     //increment the source step
                }
                if (sourceStep >= sources.Length || launchType == LaunchTypes.random) //if we reached the last attack object or the launch type is set to random
                {
                    sourceStep = 0;                                                   //end of attack
                    source.OnAttackComplete();
                }
                else //move to next attack object
                {
                    sourceStepTimer = sources[sourceStep].GetDelay();
                }

                return(true); //return whenever an attack object is launched
            }

            return(false);
        }
        //abort placing the building:
        private void Cancel()
        {
            //Call the stop building placement custom event:
            CustomEvents.OnBuildingStopPlacement(currentBuilding);

            //abort the building process
            Destroy(currentBuilding.gameObject);
            currentBuilding = null;
        }
Exemple #4
0
        //a method that upgrades a faction entity instance locally
        public void UpgradeInstance(FactionEntity instance, FactionEntity target, int factionID, EffectObj upgradeEffect)
        {
            switch (instance.Type)
            {
            case EntityTypes.building:

                Building currBuilding = instance as Building;
                Unit[]   currBuilders = currBuilding.WorkerMgr.GetAll(); //get the current builders of this building if there are any
                foreach (Unit unit in currBuilders)                      //and make them stop building the instance of the building since it will be destroyed.
                {
                    unit.BuilderComp.Stop();
                }

                //create upgraded instance of the building
                Building upgradedBuilding = gameMgr.BuildingMgr.CreatePlacedInstanceLocal(
                    (Building)target,
                    instance.transform.position,
                    target.transform.rotation.eulerAngles.y,
                    ((Building)instance).CurrentCenter,
                    factionID,
                    currBuilding.IsBuilt,     //depends on the current state of the instance to destroy
                    ((Building)instance).FactionCapital);

                foreach (Unit unit in currBuilders)
                {
                    unit.BuilderComp.SetTarget(upgradedBuilding);
                }

                CustomEvents.OnBuildingInstanceUpgraded((Building)instance);     //trigger custom event
                break;

            case EntityTypes.unit:

                //create upgraded instance of the unit
                gameMgr.UnitMgr.CreateUnit(
                    (Unit)target,
                    instance.transform.position,
                    instance.transform.rotation,
                    instance.transform.position,
                    factionID,
                    null);

                CustomEvents.OnUnitInstanceUpgraded((Unit)instance);     //trigger custom event
                break;
            }

            //if there's a valid upgrade effect assigned:
            if (upgradeEffect != null)
            {
                //show the upgrade effect for the player:
                gameMgr.EffectPool.SpawnEffectObj(upgradeEffect, instance.transform.position, upgradeEffect.transform.rotation);
            }

            instance.EntityHealthComp.DestroyFactionEntity(true); //destroy the instance
        }