예제 #1
0
        /// <summary>
        /// Create a new Mob object based on MobType and provided data
        /// </summary>
        /// <param name="world"></param>
        /// <param name="entityId"></param>
        /// <param name="type"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static Mob CreateMob(Chraft.World.WorldManager world, int entityId, MobType type, Chraft.Net.MetaData data = null)
        {
            // TODO: extensibility point to allow plugin to return custom class as Mobs instead of the built-in classes
            Mob mob = null;

            // If a custom Mob has not been created, return a built-in Mob
            if (mob == null)
            {
                switch (type)
                {
                    case MobType.Cow:
                        mob = new Cow(world, entityId, data);
                        break;
                    case MobType.Creeper:
                        mob = new Creeper(world, entityId, data);
                        break;
                    case MobType.Ghast:
                        mob = new Ghast(world, entityId, data);
                        break;
                    case MobType.Giant:
                        mob = new GiantZombie(world, entityId, data);
                        break;
                    case MobType.Hen:
                        mob = new Hen(world, entityId, data);
                        break;
                    case MobType.Pig:
                        mob = new Pig(world, entityId, data);
                        break;
                    case MobType.PigZombie:
                        mob = new ZombiePigman(world, entityId, data);
                        break;
                    case MobType.Sheep:
                        mob = new Sheep(world, entityId, data);
                        break;
                    case MobType.Skeleton:
                        mob = new Skeleton(world, entityId, data);
                        break;
                    case MobType.Slime:
                        mob = new Slime(world, entityId, data);
                        break;
                    case MobType.Spider:
                        mob = new Spider(world, entityId, data);
                        break;
                    case MobType.Squid:
                        mob = new Squid(world, entityId, data);
                        break;
                    case MobType.Wolf:
                        mob = new Wolf(world, entityId, data);
                        break;
                    case MobType.Zombie:
                        mob = new Zombie(world, entityId, data);
                        break;
                    default:
                        mob = null;
                        break;
                }
            }

            return mob;
        }
        /// <summary>
        /// Creates a Large Chest interface for the two chests specified (North or East chest, and South or West chest)
        /// </summary>
        /// <param name="world"></param>
        /// <param name="NEChest">The North or East chest coordinates</param>
        /// <param name="SWChest">The South or West chest coordinates</param>
        public LargeChestInterface(World.WorldManager world, Chraft.World.PointI neChest, Chraft.World.PointI swChest)
            : base(world, InterfaceType.Chest, 54)
        {
            NEChest = neChest;
            SWChest = swChest;

            Load();
        }
예제 #3
0
파일: Wolf.cs 프로젝트: dekema2/c-raft
 internal Wolf(Chraft.World.WorldManager world, int entityId, Chraft.Net.MetaData data = null)
     : base(world, entityId, MobType.Wolf, data)
 {
     this.Data.IsSitting = false;
     this.Data.IsTamed = false;
     this.Data.IsAggressive = false;
     this.BonesUntilTamed = Server.Rand.Next(10); // How many bones required to tame this wolf?
 }
예제 #4
0
        /// <summary>
        /// Create a new Mob object based on MobType and provided data
        /// </summary>
        /// <param name="world"></param>
        /// <param name="entityId"></param>
        /// <param name="type"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static Mob CreateMob(Chraft.World.WorldManager world, int entityId, MobType type, Chraft.Net.MetaData data = null)
        {
            Type mobType = GetMobClass(world, type);

            if (mobType != null)
            {
                ConstructorInfo ci =
                    mobType.GetConstructor(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null,
                                           new Type[]
                                            {
                                                typeof (Chraft.World.WorldManager), typeof (int),
                                                typeof (Chraft.Net.MetaData)
                                            }, null);
                if (ci != null)
                    return (Mob)ci.Invoke(new object[] {world, entityId, data});
            }

            return null;
        }
예제 #5
0
        protected override void DoInteraction(Chraft.Client client, Chraft.Interfaces.ItemStack item)
        {
            base.DoInteraction(client, item);

            if (!ItemStack.IsVoid(item))
            {
                if ((item.Type == (short)BlockData.Items.Pork || item.Type == (short)BlockData.Items.Grilled_Pork))
                {
                    client.Inventory.RemoveItem(item.Slot); // consume the item

                    if (this.Data.IsTamed)
                    {
                        // Feed a tame wolf pork chop
                        if (this.Health < this.MaxHealth &&
                            (item.Type == (short)BlockData.Items.Pork || item.Type == (short)BlockData.Items.Grilled_Pork))
                        {
                            if (this.Health < this.MaxHealth)
                            {
                                this.Health += 3; // Health is clamped, no need to check if exceeds MaxHealth
                                SendMetadataUpdate();
                            }
                        }
                    }
                }
                else if (!this.Data.IsTamed && item.Type == (short)BlockData.Items.Bone)
                {
                    // Give a bone
                    this.BonesUntilTamed--;
                    client.Inventory.RemoveItem(item.Slot); // consume the item

                    if (this.BonesUntilTamed <= 0)
                    {
                        this.Data.IsTamed = true;
                        this.Data.TamedBy = client.Username;
                        this.Health = this.MaxHealth;
                        // TODO: begin following this.Data.TamedBy
                        SendMetadataUpdate();
                    }
                }
            }
        }
예제 #6
0
파일: Blaze.cs 프로젝트: TheaP/c-raft
 internal Blaze(Chraft.World.WorldManager world, int entityId, Chraft.Net.MetaData data = null)
     : base(world, entityId, MobType.Blaze, data)
 {
 }
예제 #7
0
 internal ZombiePigman(Chraft.World.WorldManager world, int entityId, Chraft.Net.MetaData data = null)
     : base(world, entityId, MobType.PigZombie, data)
 {
 }
예제 #8
0
파일: Skeleton.cs 프로젝트: TheaP/c-raft
 internal Skeleton(Chraft.World.WorldManager world, int entityId, Chraft.Net.MetaData data = null)
     : base(world, entityId, MobType.Skeleton, data)
 {
 }
예제 #9
0
 internal GiantZombie(Chraft.World.WorldManager world, int entityId, Chraft.Net.MetaData data = null)
     : base(world, entityId, MobType.Giant, data)
 {
 }
예제 #10
0
파일: Spider.cs 프로젝트: TheaP/c-raft
 internal Spider(Chraft.World.WorldManager world, int entityId, Chraft.Net.MetaData data = null)
     : base(world, entityId, MobType.Spider, data)
 {
 }
예제 #11
0
파일: Sheep.cs 프로젝트: Smjert/c-raft
 internal Sheep(Chraft.World.WorldManager world, int entityId, Chraft.Net.MetaData data = null)
     : base(world, entityId, MobType.Sheep, data)
 {
     this.Data.Sheared = false;
     this.Data.WoolColor = _woolColor.ChooseByRandom();
 }
예제 #12
0
        public static Type GetMobClass(Chraft.World.WorldManager world, MobType type)
        {
            // TODO: extension point to allow plugin to override class for MobType for world
            Type mobType = null;

            // If a custom Mob has not been created, return a built-in Mob
            if (mobType == null)
            {
                switch (type)
                {
                    case MobType.Cow:
                        mobType = typeof(Cow);
                        break;
                    case MobType.Creeper:
                        mobType = typeof(Creeper);
                        break;
                    case MobType.Ghast:
                        mobType = typeof(Ghast);
                        break;
                    case MobType.Giant:
                        mobType = typeof(GiantZombie);
                        break;
                    case MobType.Hen:
                        mobType = typeof(Hen);
                        break;
                    case MobType.Pig:
                        mobType = typeof(Pig);
                        break;
                    case MobType.PigZombie:
                        mobType = typeof(ZombiePigman);
                        break;
                    case MobType.Sheep:
                        mobType = typeof(Sheep);
                        break;
                    case MobType.Skeleton:
                        mobType = typeof(Skeleton);
                        break;
                    case MobType.Slime:
                        mobType = typeof(Slime);
                        break;
                    case MobType.Spider:
                        mobType = typeof(Spider);
                        break;
                    case MobType.Squid:
                        mobType = typeof(Squid);
                        break;
                    case MobType.Wolf:
                        mobType = typeof(Wolf);
                        break;
                    case MobType.Zombie:
                        mobType = typeof(Zombie);
                        break;
                    default:
                        mobType = null;
                        break;
                }
            }

            if (mobType != null && typeof(Mob).IsAssignableFrom(mobType) && mobType.GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(Chraft.World.WorldManager), typeof(int), typeof(Chraft.Net.MetaData) }, null) != null)
            {
                return mobType;
            }

            return null;
        }
예제 #13
0
파일: Sheep.cs 프로젝트: dekema2/c-raft
 internal Sheep(Chraft.World.WorldManager world, int entityId, Chraft.Net.MetaData data = null)
     : base(world, entityId, MobType.Sheep, data)
 {
     Data.Sheared = false;
     Data.WoolColor = _woolColor.SelectRandom(world.Server.Rand);
 }