Exemple #1
0
 public GrenadeEntity(Region tregion) :
     base(tregion)
 {
     Shape = new CylinderShape(0.2f, 0.05f);
     Bounciness = 0.95f;
     SetMass(1);
 }
Exemple #2
0
 public ItemEntity(ItemStack stack, Region tregion)
     : base(stack.Model, tregion)
 {
     Stack = stack;
     SetMass(Math.Max(1f, stack.Weight) * stack.Count);
     CGroup = CollisionUtil.Item;
 }
Exemple #3
0
 public override Entity Create(Region tregion, BsonDocument doc)
 {
     ItemStack stack = new ItemStack(doc["it_stack"].AsBinary, tregion.TheServer);
     ItemEntity ent = new ItemEntity(stack, tregion);
     ent.ApplyPhysicsData(doc);
     return ent;
 }
Exemple #4
0
 public ArrowEntity(Region tregion)
     : base(tregion)
 {
     Collide += new EventHandler<CollisionEventArgs>(OnCollide);
     Vector3 grav = TheRegion.PhysicsWorld.ForceUpdater.Gravity;
     Gravity = new Location(grav);
     Scale = new Location(0.05f, 0.05f, 0.05f);
 }
Exemple #5
0
 // TODO: Heal with time?
 public MusicBlockEntity(Region tregion, ItemStack orig, Location pos)
     : base("mapobjects/customblocks/musicblock", tregion)
 {
     Original = orig;
     SetMass(0);
     SetPosition(pos.GetBlockLocation() + new Location(0.5));
     SetOrientation(Quaternion.Identity);
 }
Exemple #6
0
 public override Entity Create(Region tregion, BsonDocument doc)
 {
     ItemStack it = new ItemStack(doc["mb_item"].AsBinary, tregion.TheServer);
     MusicBlockEntity mbe = new MusicBlockEntity(tregion, it, Location.Zero);
     mbe.SetMaxHealth((double)doc["mb_maxhealth"].AsDouble);
     mbe.SetHealth((double)doc["mb_health"].AsDouble);
     return mbe;
 }
Exemple #7
0
 public VehicleEntity(string vehicle, Region tregion)
     : base("vehicles/" + vehicle + "_base", tregion)
 {
     vehName = vehicle;
     SetMass(1500);
     DriverSeat = new Seat(this, Location.UnitZ * 2);
     Seats = new List<Seat>();
     Seats.Add(DriverSeat);
 }
Exemple #8
0
 public BlockItemEntity(Region tregion, BlockInternal orig, Location pos)
     : base(tregion)
 {
     SetMass(20);
     CGroup = CollisionUtil.Item;
     Original = orig;
     Location offset;
     Shape = BlockShapeRegistry.BSD[orig.BlockData].GetShape(orig.Damage, out offset, true);
     SetPosition(pos.GetBlockLocation() + offset);
 }
 public StaticBlockEntity(Region tregion, ItemStack orig, Location pos)
     : base(tregion)
 {
     SetMass(0);
     CGroup = CollisionUtil.Item;
     Original = orig;
     Location offset;
     Shape = BlockShapeRegistry.BSD[0].GetShape(BlockDamage.NONE, out offset, false);
     SetPosition(pos.GetBlockLocation() + offset);
     SetOrientation(Quaternion.Identity);
 }
Exemple #10
0
 // TODO: Optimize tracing!
 public Structure(Region tregion, Location startOfTrace, int maxrad)
 {
     startOfTrace = startOfTrace.GetBlockLocation();
     Queue<Location> locs = new Queue<Location>();
     HashSet<Location> found = new HashSet<Location>();
     List<Location> resultLocs = new List<Location>();
     locs.Enqueue(startOfTrace);
     int maxradsq = maxrad * maxrad;
     AABB box = new AABB() { Max = startOfTrace, Min = startOfTrace };
     while (locs.Count > 0)
     {
         Location loc = locs.Dequeue();
         if (found.Contains(loc))
         {
             continue;
         }
         if (loc.DistanceSquared(startOfTrace) > maxradsq)
         {
             throw new Exception("Escaped radius!");
         }
         BlockInternal bi = tregion.GetBlockInternal(loc);
         if ((Material)bi.BlockMaterial == Material.AIR)
         {
             continue;
         }
         if (!((BlockFlags)bi.BlockLocalData).HasFlag(BlockFlags.EDITED))
         {
             throw new Exception("Found natural block!");
         }
         if (((BlockFlags)bi.BlockLocalData).HasFlag(BlockFlags.PROTECTED))
         {
             throw new Exception("Found protected block!");
         }
         found.Add(loc);
         resultLocs.Add(loc);
         box.Include(loc);
         foreach (Location dir in FloodDirs)
         {
             locs.Enqueue(loc + dir);
         }
     }
     Location ext = box.Max - box.Min;
     Size = new Vector3i((int)ext.X + 1, (int)ext.Y + 1, (int)ext.Z + 1);
     Origin = new Vector3i((int)Math.Floor(startOfTrace.X - box.Min.X), (int)Math.Floor(startOfTrace.Y - box.Min.Y), (int)Math.Floor(startOfTrace.Z - box.Min.Z));
     Blocks = new BlockInternal[Size.X * Size.Y * Size.Z];
     foreach (Location loc in resultLocs)
     {
         Blocks[BlockIndex((int)(loc.X - box.Min.X), (int)(loc.Y - box.Min.Y), (int)(loc.Z - box.Min.Z))] = tregion.GetBlockInternal(loc);
     }
 }
Exemple #11
0
 public TargetEntity(Region tregion)
     : base(tregion)
 {
     model = "players/human_male_004";
     mod_zrot = 270;
     mod_scale = 1.5f;
     SetMaxHealth(100);
     SetHealth(100);
     SetMass(70);
     Items = new EntityInventory(tregion, this);
     // TODO: Better way to gather item details!
     Items.GiveItem(TheServer.Items.GetItem("weapons/rifles/m4"));
     Items.GiveItem(new ItemStack("bullet", "rifle_ammo", TheServer, 1000, "items/weapons/ammo/rifle_round_ico", "Assault Rifle Ammo", "Very rapid!", System.Drawing.Color.White, "items/weapons/ammo/rifle_round", false, 0));
     Items.cItem = 1;
     Items.Items[0].Info.PrepItem(this, Items.Items[0]);
 }
 void FloodFrom(Region tregion, Location start, Location c, Material mat, double maxRad)
 {
     if ((c - start).LengthSquared() > maxRad * maxRad)
     {
         return;
     }
     if (tregion.GetBlockMaterial(c) != Material.AIR)
     {
         return;
     }
     tregion.SetBlockMaterial(c, mat);
     foreach (Location dir in FloodDirs)
     {
         FloodFrom(tregion, start, c + dir, mat, maxRad);
     }
 }
Exemple #13
0
 public SlimeEntity(Region tregion, double scale)
     : base(tregion, 20)
 {
     CBHHeight = 0.3f * 0.5f;
     CBStepHeight = 0.1f;
     CBDownStepHeight = 0.1f;
     CBRadius = 0.3f;
     CBStandSpeed = 3.0f;
     CBAirSpeed = 3.0f;
     CBAirForce = 100f;
     mod_scale = Math.Max(scale, 0.1f);
     PathFindCloseEnough = 1f;
     SetMass(10);
     model = "mobs/slimes/slime";
     //mod_xrot = -90;
 }
Exemple #14
0
 public Structure(Region tregion, Location min, Location max, Location origin)
 {
     Location ext = max - min;
     Size = new Vector3i((int)ext.X + 1, (int)ext.Y + 1, (int)ext.Z + 1);
     Origin = new Vector3i((int)Math.Floor(origin.X - min.X), (int)Math.Floor(origin.Y - min.Y), (int)Math.Floor(origin.Z - min.Z));
     Blocks = new BlockInternal[Size.X * Size.Y * Size.Z];
     for (int x = 0; x < Size.X; x++)
     {
         for (int y = 0; y < Size.Y; y++)
         {
             for (int z = 0; z < Size.Z; z++)
             {
                 Blocks[BlockIndex(x, y, z)] = tregion.GetBlockInternal(new Location(min.X + x, min.Y + y, min.Z + z));
             }
         }
     }
 }
Exemple #15
0
 public BlockGroupEntity(Location baseloc, BGETraceMode mode, Region tregion, BlockInternal[] blocks, int xwidth, int ywidth, int zwidth, Location torigin = default(Location))
     : base(tregion)
 {
     SetMass(blocks.Length * 10f);
     XWidth = xwidth;
     YWidth = ywidth;
     ZWidth = zwidth;
     Blocks = blocks;
     TraceMode = mode;
     Origin = torigin;
     if (TraceMode == BGETraceMode.PERFECT)
     {
         Vector3 shoffs;
         Shape = new MobileChunkShape(new Vector3i(xwidth, ywidth, zwidth), blocks, out shoffs); // TODO: Anything offset related needed here?
         shapeOffs = -new Location(shoffs);
     }
     else
     {
         Shape = CalculateHullShape(out shapeOffs);
         shapeOffs = -shapeOffs;
     }
     SetPosition(baseloc - shapeOffs);
 }
 bool FloodFrom(Region tregion, Location start, List<KeyValuePair<Location, BlockInternal>> blocks, double maxRad, AABB extent)
 {
     Queue<Location> locsToGo = new Queue<Location>();
     locsToGo.Enqueue(start);
     while (locsToGo.Count > 0)
     {
         Location c = locsToGo.Dequeue();
         if ((c - start).LengthSquared() > maxRad * maxRad)
         {
             SysConsole.Output(OutputType.INFO, "Escaped radius!");
             return false;
         }
         BlockInternal bi = tregion.GetBlockInternal(c);
         if ((Material)bi.BlockMaterial == Material.AIR)
         {
             continue;
         }
         if (!((BlockFlags)bi.BlockLocalData).HasFlag(BlockFlags.EDITED))
         {
             SysConsole.Output(OutputType.INFO, "Found natural block!");
             return false;
         }
         if (((BlockFlags)bi.BlockLocalData).HasFlag(BlockFlags.PROTECTED))
         {
             continue;
         }
         blocks.Add(new KeyValuePair<Location, BlockInternal>(c, bi));
         tregion.SetBlockMaterial(c, (Material)bi.BlockMaterial, bi.BlockData, bi.BlockPaint, (byte)(bi.BlockLocalData | (byte)BlockFlags.PROTECTED), bi.Damage, false, false);
         extent.Include(c);
         foreach (Location dir in FloodDirs)
         {
             locsToGo.Enqueue(c + dir);
         }
     }
     return true;
 }
Exemple #17
0
 public PaintBombEntity(byte col, Region tregion)
     : base(tregion)
 {
     Color = col;
 }
Exemple #18
0
 public PlaneEntity(string pln, Region tregion)
     : base(pln, tregion)
 {
     SetMass(1000);
 }
Exemple #19
0
 public override Entity Create(Region tregion, BsonDocument doc)
 {
     GlowstickEntity glowstick = new GlowstickEntity(System.Drawing.Color.FromArgb(doc["gs_color"].AsInt32), tregion);
     glowstick.ApplyPhysicsData(doc);
     return glowstick;
 }
Exemple #20
0
 public void UnloadFully(Action wrapUp)
 {
     if (wrapUp != null)
     {
         UnloadCallback = wrapUp;
     }
     NeedShutdown = true;
     if (Thread.CurrentThread != Execution)
     {
         return;
     }
     // TODO: Lock safely!
     MainRegion.UnloadFully();
     MainRegion = null;
     UnloadCallback?.Invoke();
     Execution.Abort();
     Execution = null;
 }
Exemple #21
0
 public void LoadRegion()
 {
     if (MainRegion != null)
     {
         return;
     }
     Region rg = new Region();
     rg.TheServer = TheServer;
     rg.TheWorld = this;
     rg.BuildWorld();
     MainRegion = rg;
 }
Exemple #22
0
 public LiquidVolume(Region tregion)
 {
     TheRegion = tregion;
 }
Exemple #23
0
 public LivingEntity(Region tregion, double maxhealth)
     : base(tregion)
 {
     MaxHealth = maxhealth;
     Health = maxhealth;
 }
Exemple #24
0
 public PrimitiveEntity(Region tregion)
     : base(tregion, true)
 {
 }
Exemple #25
0
 public EntityInventory(Region tregion, Entity owner)
     : base(tregion)
 {
     Owner = owner;
 }
Exemple #26
0
 public BulletEntity(Region tregion)
     : base(tregion)
 {
     Collide += new EventHandler<CollisionEventArgs>(OnCollide);
     Gravity = new Location(TheRegion.PhysicsWorld.ForceUpdater.Gravity);
 }
Exemple #27
0
 public abstract Entity Create(Region tregion, BsonDocument input);
Exemple #28
0
 /// <summary>
 /// Construct the physics entity.
 /// Sets its gravity to the world default and collisiongroup to Solid.
 /// </summary>
 /// <param name="tregion">The region the entity will be spawned in.</param>
 public PhysicsEntity(Region tregion)
     : base(tregion, true)
 {
     Gravity = new Location(TheRegion.PhysicsWorld.ForceUpdater.Gravity);
 }
Exemple #29
0
 public Entity(Region tregion, bool tickme)
 {
     TheRegion = tregion;
     TheServer = tregion.TheServer;
     Ticks = tickme;
 }
Exemple #30
0
 public HumanoidEntity(Region tregion)
     : base(tregion, 100)
 {
 }