Пример #1
0
        /// <summary>
        ///     将一个对象字段转换为二进制元数据
        /// </summary>
        /// <param name="metadata">需要转换成元数据的Value字典</param>
        /// <param name="proxy">内存段代理器</param>
        internal unsafe static void ToBytes(ResourceBlock metadata, IMemorySegmentProxy proxy)
        {
            Dictionary <byte, BaseValueStored> valueStoreds = metadata.GetMetaDataDictionary();
            uint           markRangeLength      = (uint)(valueStoreds.Count * 5);
            MemoryPosition wrapperStartPosition = proxy.GetPosition();

            proxy.Skip(4U);
            proxy.WriteUInt16((ushort)(valueStoreds.Count));
            MemoryPosition wrapperMarkRangeStartPosition = proxy.GetPosition();

            proxy.Skip(markRangeLength);
            MemoryPosition wrapperOffsetStartPosition = proxy.GetPosition();
            MarkRange *    markRange = stackalloc MarkRange[valueStoreds.Count];
            int            i         = 0;

            foreach (KeyValuePair <byte, BaseValueStored> valueStored in valueStoreds)
            {
                //转化成二进制数组的形式
                MemoryPosition wrapperCurrentPosition = proxy.GetPosition();
                uint           currentOffset          = (uint)MemoryPosition.CalcLength(proxy.SegmentCount, wrapperOffsetStartPosition, wrapperCurrentPosition);
                (markRange + i)->Id     = valueStored.Key;
                (markRange + i++)->Flag = (uint)((currentOffset << 8) | (int)valueStored.Value.TypeId);
                if (valueStored.Value.IsNull)
                {
                    continue;
                }
                valueStored.Value.ToBytes(proxy);
            }
            MemoryPosition wrapperEndPosition = proxy.GetPosition();

            //回写mark Range
            proxy.WriteBackMemory(wrapperMarkRangeStartPosition, markRange, markRangeLength);
            //回写4bytes总长
            proxy.WriteBackInt32(wrapperStartPosition, MemoryPosition.CalcLength(proxy.SegmentCount, wrapperStartPosition, wrapperEndPosition));
        }
Пример #2
0
        /// <summary>
        ///     元数据转换成第三方数据
        /// </summary>
        /// <param name="metadataObject">元数据集合</param>
        /// <param name="id">属性对应key</param>
        /// <param name="data">属性对应byte数组</param>
        /// <param name="offsetStart">属性在数组中的偏移值</param>
        /// <param name="length">属性在byte数组中的长度</param>
        /// <exception cref="ArgumentNullException">参数不能为空</exception>
        public void DataProcessor(MetadataContainer metadataObject, byte id, byte[] data, int offsetStart, uint length)
        {
            if (metadataObject == null)
            {
                throw new ArgumentNullException("metadataObject");
            }
            uint arrayLength = BitConverter.ToUInt32(data, offsetStart);

            ResourceBlock[] resourceBlocks = new ResourceBlock[arrayLength];
            offsetStart += 4;
            for (int j = 0; j < arrayLength; j++)
            {
                uint resouceBlockLength = BitConverter.ToUInt32(data, offsetStart);
                if (resouceBlockLength == 0)
                {
                    resourceBlocks[j] = null;
                    offsetStart      += 4;
                }
                else
                {
                    resourceBlocks[j] = MetadataObjectEngine.GetObject(data, (uint)offsetStart, resouceBlockLength);
                    offsetStart      += (int)resouceBlockLength;
                }
            }
            metadataObject.SetAttribute(id, new ResourceBlockArrayStored(resourceBlocks));
        }
Пример #3
0
        private void handleDragging(PlayerAction.Action action)
        {
            PlayerAction.Dragging dragClick = (PlayerAction.Dragging)action;
            Ray     dragRay   = dragClick.getRay();
            Vector3?dragBlock = world.getBlockAlongRay(dragRay);

            if (dragBlock.HasValue)
            {
                BlockLoc currentDragBlock = new BlockLoc((int)((Vector3)dragBlock).X, (int)((Vector3)dragBlock).Y, (int)((Vector3)dragBlock).Z);
                IEnumerable <BlockLoc> draggedBlocks;
                if (dragClick.getDragType() == PlayerAction.Dragging.DragType.excavate)
                {
                    draggedBlocks = world.GetBlocksBoundBy(player.getFirstBlockInDrag(), currentDragBlock);
                }
                else
                {
                    draggedBlocks = world.getSurfaceBlocksBoundBy(player.getFirstBlockInDrag(), currentDragBlock);
                }
                float draggedBlockOpacity = .5f;
                foreach (BlockLoc test in draggedBlocks)
                {
                    switch (dragClick.getDragType())
                    {
                    case PlayerAction.Dragging.DragType.farm:
                        WorldMarkupHandler.addFlagPathWithPosition(ContentDistributor.getEmptyString() + @"worldMarkup\farmMarker.chr",
                                                                   test.toWorldSpaceVector3() + new Vector3(.5f, .5f, .5f));
                        break;

                    case PlayerAction.Dragging.DragType.storeWheat:
                        WorldMarkupHandler.addCharacter(ResourceBlock.getPathForResourceType(ResourceBlock.ResourceType.Wheat),
                                                        test.toWorldSpaceVector3() + new Vector3(.5f, 1.5f, .5f), 1f / 7f, draggedBlockOpacity);
                        WorldMarkupHandler.addCharacter(ResourceBlock.getPathForResourceType(ResourceBlock.ResourceType.Wheat),
                                                        test.toWorldSpaceVector3() + new Vector3(.5f, 2.5f, .5f), 1f / 7f, draggedBlockOpacity);
                        break;

                    case PlayerAction.Dragging.DragType.storeWood:
                        WorldMarkupHandler.addCharacter(ResourceBlock.getPathForResourceType(ResourceBlock.ResourceType.Wood),
                                                        test.toWorldSpaceVector3() + new Vector3(.5f, 1.5f, .5f), 1f / 7f, draggedBlockOpacity);
                        WorldMarkupHandler.addCharacter(ResourceBlock.getPathForResourceType(ResourceBlock.ResourceType.Wood),
                                                        test.toWorldSpaceVector3() + new Vector3(.5f, 2.5f, .5f), 1f / 7f, draggedBlockOpacity);
                        break;

                    case PlayerAction.Dragging.DragType.storeStone:
                        WorldMarkupHandler.addCharacter(ResourceBlock.getPathForResourceType(ResourceBlock.ResourceType.standardBlock),
                                                        test.toWorldSpaceVector3() + new Vector3(.5f, 1.5f, .5f), 1f / 7f, draggedBlockOpacity);
                        WorldMarkupHandler.addCharacter(ResourceBlock.getPathForResourceType(ResourceBlock.ResourceType.standardBlock),
                                                        test.toWorldSpaceVector3() + new Vector3(.5f, 2.5f, .5f), 1f / 7f, draggedBlockOpacity);
                        break;

                    case PlayerAction.Dragging.DragType.excavate:
                        WorldMarkupHandler.addFlagPathWithPosition(ContentDistributor.getEmptyString() + @"worldMarkup\redCubeOutline.chr",
                                                                   test.toWorldSpaceVector3() + new Vector3(.5f, .5f, .5f), 1.1f / 7f);
                        break;

                    default:
                        throw new Exception("unhandled dragType " + dragClick.getDragType());
                    }
                }
            }
        }
Пример #4
0
        public IActionResult DeleteResourceBlock(int resourceBlockID)
        {
            ResourceBlock rb = inventoryRepository.GetResourceBlock(resourceBlockID);

            inventoryRepository.DeleteResourceBlock(rb);

            return(RedirectToAction(nameof(Blocks)));
        }
Пример #5
0
 /// <summary>
 ///     ResourceBlock类型存储的初始化构造器
 /// </summary>
 public ResourceBlockStored(ResourceBlock value)
 {
     _value  = value;
     _typeId = (byte)PropertyTypes.ResourceBlock;
     if (_value == null)
     {
         IsNull = true;
     }
 }
Пример #6
0
        /// <summary>
        ///     MetadataContainer扩展方法
        /// </summary>
        /// <typeparam name="T">返回的类型</typeparam>
        /// <param name="obj">metadataContainer对象</param>
        /// <param name="id">id编号</param>
        /// <returns>value值</returns>
        public static T GetAttributeByIdSafety <T>(this ResourceBlock obj, byte id)
        {
            if (obj == null)
            {
                return(default(T));
            }
            T value;

            return(obj.TryGetAttributeAsType(id, out value) ? value : default(T));
        }
Пример #7
0
        private MetadataContainer GetSucceedResponseMessage(ResourceBlock data)
        {
            MetadataContainer rspMsg = new MetadataContainer();

            rspMsg.SetAttribute(0x00, new MessageIdentityValueStored(new MessageIdentity {
                ProtocolId = 1, ServiceId = 0, DetailsId = 1
            }));
            rspMsg.SetAttribute(0x0F, new ResourceBlockStored(data));
            return(rspMsg);
        }
Пример #8
0
        protected override void DoBussiness(MetadataContainer reqMsg, MetadataMessageTransaction transaction)
        {
            CoinTypes      coinType      = (CoinTypes)reqMsg.GetAttribute(0x0F).GetValue <byte>();
            PlatformTypes  platformType  = (PlatformTypes)reqMsg.GetAttribute(0x10).GetValue <byte>();
            IExecuteResult executeResult = CacheManager.Instance.GetValue(coinType, platformType);

            if (executeResult.State != ExecuteResults.Succeed)
            {
                transaction.SendResponse(GetErrorResponseMessage(SystemErrors.Unknown, executeResult.Error));
            }
            else
            {
                ResourceBlock rspCampaignData = ConverterFactory.GetTickerConverter().ConvertToNetworkObject(executeResult.GetResult <Ticker>());
                transaction.SendResponse(GetSucceedResponseMessage(rspCampaignData));
            }
        }
Пример #9
0
        /// <summary>
        ///     将一个网络对象转换为领域模型对象
        /// </summary>
        /// <param name="data">Ticker网络数据</param>
        /// <returns>返回转换回来的结果</returns>
        public Ticker ConvertToDomainObject(ResourceBlock data)
        {
            if (data == null)
            {
                return(null);
            }

            Ticker ticker = new Ticker
            {
                BuyPrice  = data.GetAttributeByIdSafety <double>(0x00),
                SellPrice = data.GetAttributeByIdSafety <double>(0x01),
                HignPrice = data.GetAttributeByIdSafety <double>(0x02),
                LowPrice  = data.GetAttributeByIdSafety <double>(0x03),
                LastPrice = data.GetAttributeByIdSafety <double>(0x04),
                Vol       = data.GetAttributeByIdSafety <double>(0x05)
            };

            return(ticker);
        }
Пример #10
0
        public void display3D()
        {
            if (isEmbodyingCharacter())
            {
                if (selectedCharacter.isCarryingItem())
                {
                    ResourceBlock.ResourceType type = selectedCharacter.getLoad();
                    String  blockChrPath            = ResourceBlock.getPathForResourceType(type);
                    Vector3 centerOfFloatingCube    = getPlayerAimingAtPointAtDistance(.7f, currentMouseState);

                    WorldMarkupHandler.addFlagPathWithPosition(blockChrPath, centerOfFloatingCube, 1f / 7f / 12f);
                }
            }

            if (selectedCharacter != null && !isEmbodyingCharacter())
            {
                Compositer.addFlagForThisFrame(selectedCharacter.getLocation() + new Vector3(0, 1.1f, 0), "white");
            }
        }
Пример #11
0
        /// <summary>
        ///     第三方数据转换成元数据
        /// </summary>
        /// <param name="metadata">第三方数据对象</param>
        /// <returns>元数据的二进制表现形式</returns>
        public static byte[] ToBytes(ResourceBlock metadata)
        {
            if (metadata == null)
            {
                return(null);
            }
            MemoryAllotter.Instance.Initialize();
            IMemorySegmentProxy proxy = null;

            try
            {
                proxy = MemorySegmentProxyFactory.Create();
                ToBytes(metadata, proxy);
                return(proxy.GetBytes());
            }
            catch
            {
                if (proxy != null)
                {
                    proxy.Dispose();
                }
                throw;
            }
        }
Пример #12
0
    //Function called externally and from the second constructor to set this tile's info based on a RegionInfo class
    public void SetTileBasedOnRegion(RegionInfo thisTilesRegion_)
    {
        //Setting the tile's name, type, and texture based on the region
        this.regionName   = thisTilesRegion_.regionName;
        this.type         = thisTilesRegion_.environmentType;
        this.tileMaterial = thisTilesRegion_.tileMaterial;

        //Setting this tile's elevation between the height min/max
        this.elevation = Random.Range(thisTilesRegion_.heightMinMax.x, thisTilesRegion_.heightMinMax.y);
        //Setting the movement cost between the region's min/max
        this.movementCost = Mathf.RoundToInt(Random.Range(thisTilesRegion_.movementCostMinMax.x, thisTilesRegion_.movementCostMinMax.y));

        //Setting the decoration for this tile as long as there's a model to choose from
        if (thisTilesRegion_.tileDecorations.Count > 0)
        {
            this.decorationModel = thisTilesRegion_.tileDecorations[Mathf.RoundToInt(Random.Range(0, thisTilesRegion_.tileDecorations.Count - 1))];
        }
        //Setting the decoration's rotation in degrees
        this.decorationRotation = Random.Range(0, 360);

        //Initializing the (now empty) list of objects on this tile
        this.objectsOnThisTile = new List <GameObject>();

        //Setting the random encounter chance and encounters
        this.randomEncounterChance = thisTilesRegion_.randomEncounterChance;
        this.randomEncounterList   = new List <EncounterBlock>();
        foreach (EncounterBlock encounter in thisTilesRegion_.randomEncounterList)
        {
            //Creating a placeholder encounter variable
            EncounterBlock newEncounter = new EncounterBlock();
            newEncounter.encounterChance  = encounter.encounterChance;
            newEncounter.encounterEnemies = encounter.encounterEnemies;

            //Adding the placeholder encounter to this tile's encounter list
            this.randomEncounterList.Add(newEncounter);
        }

        //Setting the resource list for foraging
        this.foragingResources = new List <ResourceBlock>();
        foreach (ResourceBlock forageResource in thisTilesRegion_.foragingResources)
        {
            //Seeing if this resource will be spawned on this tile
            float spawnRoll = Random.Range(0f, 1f);

            //If the spawn roll is under the resource's spawn chance, we add it to this tile
            if (spawnRoll <= forageResource.spawnChance)
            {
                //Creating a placeholder resource block variable
                ResourceBlock forageR = new ResourceBlock();
                forageR.skillCheck = forageResource.skillCheck;
                //Duplicating the list of resources earned
                forageR.resources = new List <Item>();
                for (int r = 0; r < forageResource.resources.Count; ++r)
                {
                    forageR.resources.Add(forageResource.resources[r]);
                }
                //Duplicating the list of resource quantities
                forageR.resourceQuantities = new List <int>();
                for (int q = 0; q < forageResource.resourceQuantities.Count; ++q)
                {
                    forageR.resourceQuantities.Add(forageResource.resourceQuantities[q]);
                }

                //Adding the placeholder forage resource to this tile's resource list
                this.foragingResources.Add(forageR);
            }
        }

        //Setting the resource list for fishing
        this.fishingResources = new List <ResourceBlock>();
        foreach (ResourceBlock fishResource in thisTilesRegion_.fishingResources)
        {
            //Seeing if this resource will be spawned on this tile
            float spawnRoll = Random.Range(0f, 1f);

            //If the spawn roll is under the resource's spawn chance, we add it to this tile
            if (spawnRoll <= fishResource.spawnChance)
            {
                //Creating a placeholder resource block variable
                ResourceBlock fishR = new ResourceBlock();
                fishR.skillCheck         = fishResource.skillCheck;
                fishR.resources          = fishResource.resources;
                fishR.resourceQuantities = fishResource.resourceQuantities;

                //Adding the placeholder fish resource to this tile's resource list
                this.fishingResources.Add(fishR);
            }
        }

        //Setting the encounter list for tracking
        this.trackingEncounters = new List <EncounterBlock>();
        foreach (EncounterBlock trackEncounter in thisTilesRegion_.trackingEncounters)
        {
            //Creating a placeholder encounter block variable
            EncounterBlock trackE = new EncounterBlock();
            trackE.skillCheck       = trackEncounter.skillCheck;
            trackE.encounterChance  = trackEncounter.encounterChance;
            trackE.encounterEnemies = trackEncounter.encounterEnemies;

            //Adding the placeholder track encounter to this tile's encounter list
            this.trackingEncounters.Add(trackE);
        }
    }
Пример #13
0
 public IActionResult AddResourceBlock(ResourceBlock resourceBlock)
 {
     inventoryRepository.AddResourceBlock(resourceBlock);
     return(RedirectToAction(nameof(Blocks)));
 }
Пример #14
0
 /// <summary>
 ///     Attempts packing a ResourceBlock as a MetadataContainer
 /// </summary>
 /// <param name="resource">Targeted ResourceBlock object.</param>
 /// <returns>return a packed MetadataContainer object.</returns>
 public static MetadataContainer AsMetadataContainer(this ResourceBlock resource)
 {
     return(new MetadataContainer(resource.GetMetaDataDictionary()));
 }