コード例 #1
0
        public IOngoingDiplomaticExchange DecomposeOngoingExchange(SerializableOngoingDiplomaticExchange ongoingData)
        {
            var retval = ExchangeFactory.BuildOngoingExchangeForType(ongoingData.Type);

            var sender   = CivFactory.AllCivilizations.Where(civ => civ.Template.Name.Equals(ongoingData.Sender)).FirstOrDefault();
            var receiver = CivFactory.AllCivilizations.Where(civ => civ.Template.Name.Equals(ongoingData.Receiver)).FirstOrDefault();

            if (sender == null)
            {
                throw new InvalidOperationException("Could not find a sender of the specified name");
            }

            if (receiver == null)
            {
                throw new InvalidOperationException("Could not find a receiver of the specified name");
            }

            retval.Sender       = sender;
            retval.Receiver     = receiver;
            retval.IntegerInput = ongoingData.IntInput;

            if (ongoingData.ResourceInput != null)
            {
                var resourceInput = AvailableResources.Where(resource => resource.name.Equals(ongoingData.ResourceInput)).FirstOrDefault();

                if (resourceInput == null)
                {
                    throw new InvalidOperationException("Could not find a resource with the specified name");
                }

                retval.ResourceInput = resourceInput;
            }

            return(retval);
        }
コード例 #2
0
        public SerializableOngoingDiplomaticExchange ComposeOngoingExchange(IOngoingDiplomaticExchange ongoingExchange)
        {
            var retval = new SerializableOngoingDiplomaticExchange();

            retval.Type          = ongoingExchange.Type;
            retval.Sender        = ongoingExchange.Sender.Template.Name;
            retval.Receiver      = ongoingExchange.Receiver.Template.Name;
            retval.ResourceInput = ongoingExchange.ResourceInput.name;
            retval.IntInput      = ongoingExchange.IntegerInput;

            return(retval);
        }