public ResourceCommandDecorated(ICommand command, ResourceHandler handler, Guid resourceId)
 {
     m_command = command;
     m_resourceHandler = handler;
     m_resourceId = resourceId;
 }
Ejemplo n.º 2
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;
        }