Esempio n. 1
0
    void Start()
    {
        Debug.Log("Start");

        // Attempt to load the JSON file.

        MetadataMap map = MetadataLoader.LoadMetaDataFile(METADATA_FILE);

        UnitFactory uf = UnitFactory.GetInstance();

        uf.SetMetadata(map);

        List <Unit> playerUnits  = new List <Unit>();
        List <Unit> enemyUnits   = new List <Unit>();
        List <Unit> neutralUnits = new List <Unit>();

        Unit scout = uf.CreateNewUnit(UNIT_SCOUT, CHAR_SHERMAN, CombatantFactionEnum.Player);

        playerUnits.Add(scout);

        for (int i = 0; i < 8; i++)
        {
            Unit deimosScout = uf.CreateNewUnit(UNIT_DSCOUT, CHAR_DEFAULT, CombatantFactionEnum.Enemy);
            enemyUnits.Add(deimosScout);
        }

        CombatEncounterController cec = CombatEncounterController.GetInstance();

        cec.StartEncounter(playerUnits, enemyUnits, neutralUnits);

        // While the encounter is still going on try to force the units to attack the first one
        // in the enemy list
        while (!cec.IsEncounterOver())
        {
            List <Unit> pendingUnits = cec.CurrentEncounter.UnitsPendingAction;
            if (cec.CurrentFaction == CombatantFactionEnum.Player)
            {
                List <Unit> enemyEncounterUnits = cec.CurrentEncounter.EnemyUnits;

                TryAttacking(pendingUnits, enemyEncounterUnits);
            }
            else if (cec.CurrentFaction == CombatantFactionEnum.Enemy)
            {
                List <Unit> playerEncounterUnits = cec.CurrentEncounter.PlayerUnits;

                TryAttacking(pendingUnits, playerEncounterUnits);
            }
            else
            {
                cec.GoToNextStep();
            }
        }

        Debug.Log("End");
    }
Esempio n. 2
0
        /// <summary>
        /// Execute action on the selected target
        /// </summary>
        /// <param name="target">Selected target</param>
        public override void Execute(ITargetable target)
        {
            switch (SpawnableDef)
            {
            case BuildingDef buildingDef:
                using (ConstructingBuildingFactory factory = new ConstructingBuildingFactory(factionController))
                {
                    ConstructingBuildingController building = factory.CreateConstructingBuildingControllerOf(buildingDef);
                    SpawnBuilding(building, target);
                }

                break;

            case UnitDef unitDef:
                using (UnitFactory factory = new UnitFactory(factionController, gameController))
                {
                    UnitController unit = factory.CreateNewUnit(unitDef);
                    SpawnUnit(unit, target);
                }

                break;

            default:
                throw new NotImplementedException();
            }
        }