예제 #1
0
        public bool RestartPathing(SmartEntity troopEntity, out bool found, bool ignoreWall)
        {
            ShooterComponent   shooterComp = troopEntity.ShooterComp;
            IShooterVO         shooterVO   = shooterComp.ShooterVO;
            TroopComponent     troopComp   = troopEntity.TroopComp;
            TeamComponent      teamComp    = troopEntity.TeamComp;
            ITroopDeployableVO troopType   = troopComp.TroopType;
            uint            maxAttackRange = this.GetMaxAttackRange(troopEntity, shooterComp.Target);
            PathTroopParams troopParams    = new PathTroopParams
            {
                TroopWidth            = troopEntity.SizeComp.Width,
                DPS                   = shooterVO.DPS,
                MinRange              = shooterVO.MinAttackRange,
                MaxRange              = maxAttackRange,
                MaxSpeed              = troopComp.SpeedVO.MaxSpeed,
                PathSearchWidth       = troopType.PathSearchWidth,
                IsMelee               = shooterComp.IsMelee,
                IsOverWall            = shooterVO.OverWalls,
                IsHealer              = TroopController.IsEntityHealer(troopEntity),
                SupportRange          = troopType.SupportFollowDistance,
                ProjectileType        = shooterVO.ProjectileType,
                CrushesWalls          = TroopController.CanEntityCrushWalls(troopEntity),
                IsTargetShield        = GameUtils.IsEntityShieldGenerator(troopEntity.ShooterComp.Target),
                TargetInRangeModifier = troopType.TargetInRangeModifier
            };
            PathBoardParams boardParams = new PathBoardParams
            {
                IgnoreWall   = ignoreWall || TroopController.CanEntityIgnoreWalls(troopEntity),
                Destructible = teamComp.CanDestructBuildings()
            };

            return(this.StartPathing(troopEntity, shooterComp.Target, troopEntity.TransformComp, true, out found, -1, troopParams, boardParams, true, false));
        }
예제 #2
0
    public void tmb_enable_movement(GameObject troop)
    {
        TroopController tc = troop.GetComponent <TroopController>();

        tc.isTroopSelected = true;
        Debug.Log("You are controlling a troop !");
    }
예제 #3
0
    private IEnumerator LoadTroops()
    {
        List <FighterData> fighters = gameData.GetFightersOwned();

        for (int i = 0; i < fighters.Count; i++)
        {
            GameObject go = Instantiate(troopPrefab);
            go.AddComponent <FighterModel>();
            go.transform.SetParent(teamPanel);
            ((RectTransform)go.transform).localPosition = Vector3.zero;
            TroopController tc = go.GetComponent <TroopController>();
            model.troops.Add(tc);
            tc.SetTroop(fighters[i]);
        }

        // Resize scrollable background based on number of elements
        float         elementHeight = troopPrefab.GetComponent <LayoutElement>().minHeight + content.spacing;
        RectTransform rt            = content.GetComponent <RectTransform>();

        rt.sizeDelta = new Vector2(rt.rect.width, elementHeight * fighters.Count + 1 + content.padding.right + content.padding.bottom);

        yield return(new WaitForEndOfFrame());

        ShowTroopDetails(fighters[0]);
    }
예제 #4
0
    public void Raid(int attackUnitsCount, int defenceUnitsCount, int speedUnitsCount, int raidedBaseIndex)
    {
        var raidedBase = map.BaseList[raidedBaseIndex];

        var raidedBaseIsNull = raidedBase == null;
        var baseIsRaided     = raidedBase.isRaided == true;

        if (raidedBaseIsNull && baseIsRaided)
        {
            return;
        }

        Troop troop = Base.CreateTroop(attackUnitsCount, defenceUnitsCount, speedUnitsCount);

        if (troop != null)
        {
            raidedBase.isRaided = true;
            GameObject go = Instantiate(TroopPrefab, Base.TileList[0].transform);
            Troop                 = go.GetComponent <TroopController>();
            Troop.map             = map;
            Troop.Base            = Base;
            Troop.raidedBaseIndex = raidedBaseIndex;
            Troop.troop           = troop;
            Base.isRaiding        = true;
        }
    }
예제 #5
0
        public static Target CreateTargetForTroop(SmartEntity troopEntity, SmartEntity targetEntity, SecondaryTargetsComponent secondaryTargets)
        {
            if (targetEntity == null)
            {
                return(null);
            }
            Target target;

            if (secondaryTargets.ObstacleTarget != null)
            {
                target = new Target();
                target.TargetEntity = targetEntity;
                target.TargetBoardX = secondaryTargets.ObstacleTargetPoint.x;
                target.TargetBoardZ = secondaryTargets.ObstacleTargetPoint.z;
                Target.SetDefaultTargetWorldLocation(target, 1.25f);
                return(target);
            }
            TransformComponent transformComponent = (!TroopController.IsEntityHealer(troopEntity)) ? targetEntity.TransformComp : troopEntity.TransformComp;

            if (transformComponent == null)
            {
                return(null);
            }
            target = new Target();
            target.TargetEntity = targetEntity;
            target.TargetBoardX = transformComponent.CenterGridX();
            target.TargetBoardZ = transformComponent.CenterGridZ();
            Target.SetDefaultTargetWorldLocation(target, 1.25f);
            return(target);
        }
예제 #6
0
        private SmartEntity DeployHero(TroopTypeVO troopType)
        {
            if (Service.Get <SimTimeEngine>().IsPaused())
            {
                return(null);
            }
            if (!this.CanDeploy)
            {
                return(null);
            }
            BattleController battleController = Service.Get <BattleController>();

            if (battleController.BattleEndProcessing)
            {
                return(null);
            }
            if (battleController.GetPlayerDeployableHeroCount(troopType.Uid) == 0)
            {
                this.CanDeploy = false;
                Service.Get <EventManager>().SendEvent(EventId.TroopNotPlacedInvalidTroop, this.currentWorldPosition);
                return(null);
            }
            TeamType teamType = TeamType.Attacker;

            if (battleController.GetCurrentBattle().Type == BattleType.PveDefend)
            {
                teamType = TeamType.Defender;
            }
            IntPosition     intPosition     = Units.WorldToBoardIntDeployPosition(this.currentWorldPosition);
            TroopController troopController = Service.Get <TroopController>();

            if (battleController.GetCurrentBattle().IsRaidDefense())
            {
                Entity             entity    = null;
                BoardCell <Entity> boardCell = null;
                if (!troopController.FinalizeSafeBoardPosition(troopType, ref entity, ref intPosition, ref boardCell, TeamType.Attacker, TroopSpawnMode.Unleashed, false))
                {
                    Service.Get <EventManager>().SendEvent(EventId.TroopNotPlacedInvalidArea, intPosition);
                    return(null);
                }
            }
            SmartEntity smartEntity = troopController.SpawnHero(troopType, teamType, intPosition, false);

            if (smartEntity != null)
            {
                base.PlaySpawnEffect(smartEntity);
                this.CanDeploy = false;
                battleController.OnHeroDeployed(troopType.Uid, teamType, intPosition);
                Service.Get <EventManager>().SendEvent(EventId.HeroDeployed, smartEntity);
            }
            return(smartEntity);
        }
예제 #7
0
        public void Trigger(Entity intruder)
        {
            SmartEntity smartEntity = (SmartEntity)intruder;
            TroopType   type        = smartEntity.TroopComp.TroopType.Type;
            ArmorType   armorType   = smartEntity.TroopComp.TroopType.ArmorType;

            if (smartEntity.TeamComp.TeamType != TeamType.Attacker)
            {
                return;
            }
            if (TroopController.IsEntityPhantom(smartEntity))
            {
                return;
            }
            int i     = 0;
            int count = this.triggerConditions.Count;

            while (i < count)
            {
                TrapCondition trapCondition = this.triggerConditions[i];
                if (trapCondition is IntruderTypeTrapCondition && ((IntruderTypeTrapCondition)trapCondition).IntruderType != type)
                {
                    return;
                }
                if (trapCondition is ArmorNotTrapCondition && ((ArmorNotTrapCondition)trapCondition).IntruderArmorTypes.Contains(armorType))
                {
                    return;
                }
                i++;
            }
            int    boardX = 0;
            int    boardZ = 0;
            string a      = this.comp.Type.TargetType.ToLower();

            if (a == "self")
            {
                boardX = this.transform.X;
                boardZ = this.transform.Z;
            }
            else if (a == "intruder")
            {
                boardX = smartEntity.TransformComp.X;
                boardZ = smartEntity.TransformComp.Z;
            }
            this.health.Health = 0;
            this.controller.ExecuteTrap(this.comp, boardX, boardZ);
        }
예제 #8
0
 public void MoveTroops(Transform destination)
 {
     foreach (Transform pos in GetSpawnPositions())
     {
         if (pos.childCount > 0)   //If pos has troop
         {
             for (int i = 0; i < pos.childCount; i++)
             {
                 TroopController troop = pos.GetChild(i).GetComponent <TroopController>();
                 troop.Target        = destination.position; //Set new destination for troop
                 troop.HomeBuildSite = destination;          //Set homeBuildSite
                 troop.ResetCanHitObstacle();
             }
             pos.DetachChildren();
         }
     }
 }
예제 #9
0
    // Use this for initialization
    void Start()
    {
        foreach (TroopController tci in FindObjectsOfType <TroopController>())
        {
            if (tci.team == team)
            {
                tc = tci;
            }
        }

        foreach (PortraitData pdi in FindObjectsOfType <PortraitData>())
        {
            if (pdi.team == team)
            {
                pd = pdi;
            }
        }
    }
예제 #10
0
 //---- TRIGGER METHODS ----
 private void OnCollisionStay2D(Collision2D collision)
 {
     if (status != TroopStatus.Attack && collision.transform.tag == enemyTag) //Collided with Enemy
     {
         enemy = collision.transform.GetComponent <TroopController>();        //Set enemy
         StartCoroutine(Attack());
     }
     else if (collision.transform.tag == "Wall1" && canHitWall1)     //Collided with wall1
     {
         obstaclePos1  = collision.transform.Find("Pos").position;
         obstacleMove1 = true;
         canHitWall1   = false;
     }
     else if (collision.transform.tag == "Wall2" && canHitWall2)     //Collided with wall2
     {
         obstaclePos2  = collision.transform.Find("Pos").position;
         obstacleMove2 = true;
         canHitWall2   = false;
     }
 }
예제 #11
0
    private void Raid()
    {
        var unitCountIsLow = Base.UnitsCount < 10;

        if (unitCountIsLow)
        {
            return;
        }

        System.Random random            = new System.Random();
        int           attackUnitsCount  = random.Next((int)Base.AttackUnitsCount / 2, Base.AttackUnitsCount);
        int           defenceUnitsCount = random.Next((int)Base.DefenceUnitsCount / 2, Base.DefenceUnitsCount);
        int           speedUnitsCount   = random.Next((int)Base.SpeedUnitsCount / 2, Base.SpeedUnitsCount);

        var raidedBase = GetRandomRaidBase();

        var raidedBaseIsNull = raidedBase == null;
        var baseIsRaided     = raidedBase.isRaided == true;

        if (raidedBaseIsNull && baseIsRaided)
        {
            return;
        }

        Troop troop = Base.CreateTroop(attackUnitsCount, defenceUnitsCount, speedUnitsCount);

        if (troop != null && raidedBase != null && raidedBase.isRaided == false)
        {
            raidedBase.isRaided = true;
            GameObject go = Instantiate(TroopPrefab, Base.TileList[0].transform);
            Troop                 = go.GetComponent <TroopController>();
            Troop.origin          = Base.TileList[0];
            Troop.map             = map;
            Troop.Base            = Base;
            Troop.raidedBaseIndex = raidedBase.baseIndex;
            Troop.troop           = troop;
        }
    }
예제 #12
0
 public iTroopState(TroopController troopController)
 {
     controller = troopController;
 }
예제 #13
0
 public AggroState(TroopController troopController) : base(troopController)
 {
 }
예제 #14
0
 public IdleState(TroopController troopController) : base(troopController)
 {
 }
예제 #15
0
 public WalkState(TroopController troopController) : base(troopController)
 {
 }
예제 #16
0
 public FightState(TroopController troopController) : base(troopController)
 {
 }
예제 #17
0
        public SmartEntity CreateTroopEntity(TroopTypeVO troopType, TeamType teamType, IntPosition boardPosition, Entity spawnBuilding, TroopSpawnMode spawnMode, bool isShooter, bool requestAsset)
        {
            SmartEntity   smartEntity = this.CreateWalkerBaseEntity(boardPosition, troopType.SizeX, troopType.SizeY);
            TeamComponent component   = new TeamComponent(teamType);

            smartEntity.Add(component);
            if (teamType == TeamType.Defender)
            {
                DefenderComponent component2;
                if (spawnMode == TroopSpawnMode.LeashedToBuilding)
                {
                    DamageableComponent damageableComponent = spawnBuilding.Get <DamageableComponent>();
                    component2 = new DefenderComponent(boardPosition.x, boardPosition.z, damageableComponent, true, damageableComponent.GetLastSpawnIndex());
                }
                else
                {
                    component2 = new DefenderComponent(boardPosition.x, boardPosition.z, null, spawnMode == TroopSpawnMode.LeashedToSpawnPoint, 0);
                }
                smartEntity.Add(component2);
            }
            else
            {
                smartEntity.Add(new AttackerComponent());
            }
            TroopComponent troopComponent = new TroopComponent(troopType);

            smartEntity.Add(troopComponent);
            smartEntity.Add(new BuffComponent());
            smartEntity.Add(new HealthViewComponent());
            if (isShooter)
            {
                ShooterComponent component3 = new ShooterComponent(troopType);
                smartEntity.Add(component3);
            }
            Service.EventManager.SendEvent(EventId.TroopCreated, smartEntity);
            if (isShooter)
            {
                smartEntity.ShooterComp.TargetingDelayed = (teamType == TeamType.Attacker);
                bool       flag       = TroopController.IsEntityHealer(smartEntity);
                HealthType healthType = (!flag) ? HealthType.Damaging : HealthType.Healing;
                smartEntity.ShooterComp.AttackFSM = new AttackFSM(Service.BattleController, smartEntity, smartEntity.StateComp, smartEntity.ShooterComp, smartEntity.TransformComp, healthType);
                if (flag)
                {
                    smartEntity.Add(new PathingComponent());
                    smartEntity.Add(new HealerComponent());
                }
                else
                {
                    smartEntity.Add(new KillerComponent());
                }
                SecondaryTargetsComponent component4 = new SecondaryTargetsComponent();
                smartEntity.Add(component4);
            }
            HealthComponent component5 = new HealthComponent(troopType.Health, troopComponent.TroopType.ArmorType);

            smartEntity.Add(component5);
            if (troopType.ShieldHealth > 0)
            {
                TroopShieldHealthComponent component6 = new TroopShieldHealthComponent(troopType.ShieldHealth, ArmorType.Shield);
                smartEntity.Add(component6);
            }
            if (requestAsset)
            {
                Service.EntityViewManager.LoadEntityAsset(smartEntity);
            }
            return(smartEntity);
        }