コード例 #1
0
        private static EntityModel SaturateBasicItemModel(
            Entity itemEntity,
            EntityData entityData,
            bool toLowercase)
        {
            EntityWorld     world       = itemEntity.EntityWorld;
            EntityDataCache entityDatas = WorldCache.GetCache(world).EntityDatas;
            EntityModel     entityModel = new EntityModel();

            // Get basic item details.
            if (toLowercase)
            {
                entityModel.Name = entityData.Name.ToLower();
            }
            else
            {
                entityModel.Name = entityData.Name;
            }
            entityModel.Id = itemEntity.UniqueId;
            // entityModel.Type = entityDatas.GetBasePrototype(itemEntity).Name;

            // Get quantity.
            EntityStack entityStack = itemEntity.GetComponent <EntityStack>();

            if (entityStack == null)
            {
                entityModel.Quantity = 1;
            }
            else
            {
                entityModel.Quantity = entityStack.Quantity;
            }

            return(entityModel);
        }
コード例 #2
0
        public static MapNode GetMapNode(this Entity entity)
        {
            Location location = entity.GetComponent <Location>();

            if (location == null)
            {
                return(null);
            }

            MapCache maps = WorldCache.GetCache(entity.EntityWorld).Maps;
            Map      map  = maps[location.Map];

            return(map[location.Position]);
        }
コード例 #3
0
        private void AddNewPlayerInventory(Entity entity)
        {
            EntityWorld     gameWorld   = entity.EntityWorld;
            EntityDataCache entityDatas = WorldCache.GetCache(gameWorld).EntityDatas;

            Container inventory = new Container(10);

            entity.AddComponent(inventory);

            Entity itemStack = gameWorld.CreateEntity();

            itemStack.AddComponent(new EntityStack(3, 3));
            itemStack.AddComponent(entityDatas[EntityType.Consumable]);

            Entity itemSingle = gameWorld.CreateEntity();

            itemSingle.AddComponent(entityDatas[EntityType.Consumable]);

            Entity     bag           = gameWorld.CreateEntity();
            Container  bagContainer  = new Container(3);
            EntityData bagEntityData = new EntityData(
                Guid.NewGuid(),
                "Bag",
                "Just some bag.",
                null,
                EntityType.Container);

            entityDatas.Add(bagEntityData);
            bag.AddComponent(bagEntityData);
            bag.AddComponent(bagContainer);
            bagContainer.AddEntity(itemStack);

            Entity     backpack           = gameWorld.CreateEntity();
            Container  backpackContainer  = new Container(3);
            EntityData backpackEntityData = new EntityData(
                Guid.NewGuid(),
                "Backpack",
                "A weathered old backpack.",
                null,
                EntityType.Container);

            entityDatas.Add(backpackEntityData);
            backpack.AddComponent(backpackEntityData);
            backpack.AddComponent(backpackContainer);

            inventory.AddEntity(bag);
            inventory.AddEntity(backpack);
            inventory.AddEntity(itemSingle);
        }
コード例 #4
0
        //TODO
        private void MergeAllParentProperties(
            EntityWorld world,
            EntityData parentEntityData)
        {
            foreach (KeyValuePair <string, DynamicValue> parentProperty in parentEntityData.properties)
            {
                if (this.properties.ContainsKey(parentProperty.Key))
                {
                    continue;
                }
                this.properties.Add(parentProperty.Key, parentProperty.Value);
            }

            if (parentEntityData.parentPrototypeId != null)
            {
                parentEntityData =
                    WorldCache.GetCache(world).EntityDatas[parentEntityData.parentPrototypeId];
                MergeAllParentProperties(world, parentEntityData);
            }
        }
コード例 #5
0
        public void SetUp()
        {
            this.world  = MockWorld.Generate();
            this.entity = this.world.CreateEntity();

            this.interpreter = new Interpreter(Assembly.GetAssembly(typeof(ReverieGame)));

            Container inventory = new Container(10);

            this.entity.AddComponent(inventory);

            EntityDataCache entityDatas = WorldCache.GetCache(this.world).EntityDatas;

            Entity itemStack = this.world.CreateEntity();

            itemStack.AddComponent(new EntityStack(3, 3));
            itemStack.AddComponent(entityDatas[EntityType.Consumable]);

            Entity itemSingle = this.world.CreateEntity();

            itemSingle.AddComponent(entityDatas[EntityType.Consumable]);

            Entity     bag           = this.world.CreateEntity();
            Container  container     = new Container(3);
            EntityData bagEntityData = new EntityData(
                Guid.NewGuid(),
                "Bag",
                "Just a bag.",
                null,
                EntityType.Container);

            bag.AddComponent(bagEntityData);
            bag.AddComponent(container);
            container.AddEntity(itemStack);

            inventory.AddEntity(bag);
            inventory.AddEntity(itemSingle);
        }