Exemplo n.º 1
0
        public static CampaignEngine restoreFromState(CampaignState state)
        {
            List<Player> lstPlayers = new List<Player>();
            foreach (var pi in state.ListPlayers)
            {
                Player p = new Player(pi);
                lstPlayers.Add(p);
            }

            // Feld erstellen;
            //Type fieldType = Type.GetType(state.getFieldtype());  // Todo: GetType funktioniert nicht obwohl GenericCampaignMasterModel.Field korrekt ist

            // Feld mit Sektoren erzeugen.
            clsSektorKoordinaten objSekKoord = state.FieldDimension;
            Type fieldType = typeof(GenericCampaignMasterModel.Field);
            Field field = (Field)Activator.CreateInstance(fieldType, new object[] { objSekKoord });

            // Engine erstellen
            CampaignEngine engine = new CampaignEngine((Field)field);
            engine.CampaignId = state.CampaignId;
            engine.CampaignName = state.CampaignName;
            engine.setPlayerList(lstPlayers);

            clsUnit.objUnitTypeFountain.dicUnitTypeData = state.getDicUnitTypeInfo();

            // Units platzieren
            foreach (UnitInfo uInfo in state.ListUnitInfo)
            {
                //UnitTypeBase newUnitType = (UnitTypeBase)Activator.CreateInstance(unitType);

                Player aktP = (from p in lstPlayers
                               where p.Id == uInfo.playerId
                               select p).First();

                clsUnit unit = aktP.getUnitByID(uInfo.unitId);

                //clsUnit unit = new clsUnit(uInfo.unitId);
                field.dicSektors[uInfo.sektorId].addUnit(unit);
            }

            // Ressourcehandler erzeugen und Ressourcen wiederherstellen
            ResourceHandler resHandler = new ResourceHandler();
            engine.ResourceHandler = resHandler;
            foreach (ResourceInfo resInfo in state.ListResourceInfo)
            {
                string strResType = resInfo.resourceableType;
                Type resType = Type.GetType(strResType);
                Object typeObj = Activator.CreateInstance(resType);

                Player resourceOwner = (from p in lstPlayers
                                        where p.Id == resInfo.ownerId
                                        select p).First() as Player;

                resHandler.addRessourcableObject(resourceOwner, (IResourceable)typeObj);
            }

            return engine;
        }
Exemplo n.º 2
0
        public static CampaignController createNewCampaign(CampaignInfo info)
        {
            string newCampaignId = Guid.NewGuid().ToString();
            info.campaignId = newCampaignId;

            Field field = new Field(info.FieldDimension);
            CampaignEngine engine = new CampaignEngine(field);
            engine.CampaignName = info.campaignName;
            engine.CampaignId = info.campaignId;
            engine.setPlayerList(info.ListPlayerInfo.Select(p => new Player(p)).AsEnumerable());

            CampaignController controller = new CampaignController(engine);
            return controller;
        }