瀏覽代碼

Add IChunkColumnStorage (#96)

WangJun 8 年之前
父節點
當前提交
aa7f301fae

+ 16 - 0
src/MineCase.Algorithm/Game/Entity/Ai/MobAi/AiSpider.cs

@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using MineCase.Algorithm.Game.Entity.Ai.MobAi;
+using MineCase.Server.World.EntitySpawner.Ai.Action;
+
+namespace MineCase.Server.World.EntitySpawner.Ai.MobAi
+{
+    public class AiSpider : AiMonster
+    {
+        public AiSpider(Func<CreatureState> getter, Action<CreatureState> setter)
+            : base(getter, setter)
+        {
+        }
+    }
+}

+ 10 - 0
src/MineCase.Algorithm/Game/Entity/EntityPath.cs

@@ -0,0 +1,10 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace MineCase.Algorithm.Game.Entity.Ai.Action
+{
+    public class EntityPath
+    {
+    }
+}

+ 1 - 1
src/MineCase.Algorithm/World/Biomes/Biome.cs

@@ -287,7 +287,7 @@ namespace MineCase.Algorithm.World.Biomes
         }
 
         // 添加生物群系特有的怪物
-        public virtual void SpawnMonster(IWorld world, IGrainFactory grainFactory, ChunkColumnStorage chunk, Random rand, BlockWorldPos pos)
+        public virtual void SpawnMonster(IWorld world, IGrainFactory grainFactory, IChunkColumnStorage chunk, Random rand, BlockWorldPos pos)
         {
             ChunkWorldPos chunkPos = pos.ToChunkWorldPos();
             int seed = chunkPos.Z * 16384 + chunkPos.X;

+ 1 - 1
src/MineCase.Core/World/ChunkColumnCompactStorage.cs

@@ -14,7 +14,7 @@ namespace MineCase.World
         public const int BlocksInSection = BlockEdgeWidthInSection * BlockEdgeWidthInSection * BlockEdgeWidthInSection;
     }
 
-    public sealed class ChunkColumnCompactStorage
+    public sealed class ChunkColumnCompactStorage : IChunkColumnStorage
     {
         public uint SectionBitMask
         {

+ 1 - 1
src/MineCase.Core/World/ChunkColumnStorage.cs

@@ -4,7 +4,7 @@ using System.Text;
 
 namespace MineCase.World
 {
-    public sealed class ChunkColumnStorage
+    public sealed class ChunkColumnStorage : IChunkColumnStorage
     {
         public ChunkSectionStorage[] Sections { get; } = new ChunkSectionStorage[ChunkConstants.SectionsPerChunk];
 

+ 11 - 0
src/MineCase.Core/World/IChunkColumnStorage.cs

@@ -0,0 +1,11 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace MineCase.World
+{
+    public interface IChunkColumnStorage
+    {
+        BlockState this[int x, int y, int z] { get; set; }
+    }
+}

+ 3 - 0
src/MineCase.Server.Grains/Game/Entities/Components/EntityAiComponent.cs

@@ -96,6 +96,9 @@ namespace MineCase.Server.Game.Entities.Components
                 case Entities.MobType.Skeleton:
                     ai = new AiSkeleton(getter, setter);
                     break;
+                case Entities.MobType.Spider:
+                    ai = new AiSpider(getter, setter);
+                    break;
                 case Entities.MobType.Squid:
                     // TODO new ai for squid
                     ai = new AiChicken(getter, setter);

+ 2 - 2
src/MineCase.Server.Grains/Game/Entities/Components/MobSpawnerComponent.cs

@@ -58,7 +58,7 @@ namespace MineCase.Server.Game.Entities.Components
 
         private async Task OnGameTick(object sender, GameTickArgs e)
         {
-            if (e.WorldAge % 512 == 0 && e.TimeOfDay > 9000 && e.TimeOfDay < 18000)
+            if (e.WorldAge % 512 == 0 && e.TimeOfDay > 12000 && e.TimeOfDay < 24000)
             {
                 EntityWorldPos playerPosition = AttachedObject.GetValue(EntityWorldPositionComponent.EntityWorldPositionProperty);
                 int x = random.Next(9) - 4 + (int)playerPosition.X;
@@ -73,7 +73,7 @@ namespace MineCase.Server.Game.Entities.Components
                 IChunkColumn chunk = await chunkAccessor.GetChunk(monsterChunkPos);
 
                 // TODO
-                // biome.SpawnMonster(world, GrainFactory, await chunk.GetState(), random, monsterBlockPos);
+                biome.SpawnMonster(world, GrainFactory, await chunk.GetState(), random, monsterBlockPos);
             }
         }
     }

+ 2 - 2
src/MineCase.Server.Interfaces/World/EntitySpawner/MonsterSpawner.cs

@@ -23,7 +23,7 @@ namespace MineCase.Server.World.EntitySpawner
             _groupMaxNum = groupMaxNum;
         }
 
-        public async void Spawn(IWorld world, IGrainFactory grainFactory, ChunkColumnStorage chunk, Random random, BlockWorldPos pos)
+        public async void Spawn(IWorld world, IGrainFactory grainFactory, IChunkColumnStorage chunk, Random random, BlockWorldPos pos)
         {
             int num = random.Next(_groupMaxNum);
             for (int n = 0; n < num; ++n)
@@ -66,7 +66,7 @@ namespace MineCase.Server.World.EntitySpawner
             }
         }
 
-        public bool CanMobStand(IWorld world, IGrainFactory grainFactory, ChunkColumnStorage chunk, Random random, BlockChunkPos pos)
+        public bool CanMobStand(IWorld world, IGrainFactory grainFactory, IChunkColumnStorage chunk, Random random, BlockChunkPos pos)
         {
             // TODO 以后结合boundbox判断
             BlockChunkPos downPos = new BlockChunkPos(pos.X, pos.Y - 1, pos.Z);