Exemplo n.º 1
0
    void createHouse(Vector3 pos, SpawnMob house)
    {
        SpawnMob h = Instantiate(house, pos, Quaternion.identity);

        h.collidable = colliderMap;
        h.ground     = tilemap;
    }
Exemplo n.º 2
0
 private void Update()
 {
     boundary = Mathf.Abs(GetComponent <Transform>().position.x);
     if (boundary > 11)
     {
         Destroy(gameObject);
         SpawnMob.mobDestroy();
     }
 }
Exemplo n.º 3
0
        Task IHandle <SpawnMob> .Handle(SpawnMob message)
        {
            AttachedObject.Tell <SpawnEntity>(message);
            AttachedObject.SetLocalValue(MobTypeComponent.MobTypeProperty, message.MobType);
            CompleteSpawn();

            // Logger.LogInformation($"Mob spawn, key: {AttachedObject.GetAddressByPartitionKey()}");
            // Logger.LogInformation($"Mob spawn, type: {message.MobType}");
            return(Task.CompletedTask);
        }
Exemplo n.º 4
0
        async Task IHandle <SpawnMob> .Handle(SpawnMob message)
        {
            Func <CreatureState>   getter = () => AttachedObject.GetValue(CreatureStateProperty);
            Action <CreatureState> setter = v => AttachedObject.SetLocalValue(CreatureStateProperty, v).Wait();
            CreatureAi             ai;

            switch (message.MobType)
            {
            case MobType.Chicken:
                ai = new AiChicken(getter, setter);
                break;

            case MobType.Cow:
                ai = new AiCow(getter, setter);
                break;

            case MobType.Creeper:
                ai = new AiCreeper(getter, setter);
                break;

            case MobType.Pig:
                ai = new AiPig(getter, setter);
                break;

            case MobType.Sheep:
                ai = new AiSheep(getter, setter);
                break;

            case MobType.Skeleton:
                ai = new AiSkeleton(getter, setter);
                break;

            case MobType.Squid:
                // TODO new ai for squid
                ai = new AiChicken(getter, setter);
                break;

            case MobType.Zombie:
                ai = new AiZombie(getter, setter);
                break;

            default:
                // TODO add more ai
                throw new NotImplementedException("AI of this mob has not been implemented.");
            }

            await AttachedObject.SetLocalValue(AiTypeProperty, ai);
        }
Exemplo n.º 5
0
    void Start()
    {
        playerObject = GameObject.Find("Player");
        player       = playerObject.GetComponent <PlayerStats>();

        mobSpawnerObject = GameObject.Find("MobSpawner");
        mobSpawner       = mobSpawnerObject.GetComponent <SpawnMob>();

        //увеличиваем общее число здоровья мобов
        mobSpawner.PlusTotalMob(mobHP);
        Debug.Log("Total mob HP = " + mobSpawner.CurrentTotalMobHP());

        Random rand = new Random();

        randomDistance = (float)rand.Next(0, 20) / 100;
        Debug.Log("Random distance: " + randomDistance);
        attackDistance += randomDistance;
    }
Exemplo n.º 6
0
        public void UpdateEntity(SpawnMob spawn)
        {
            Mob m = null;

            lock (entities)
            {
                if (entities.ContainsKey(spawn.EID))
                {
                    m = entities[spawn.EID] as Mob;
                }
                if (m == null)
                {
                    m = new Mob(spawn.EID, spawn.Type);
                    entities[spawn.EID] = m;
                }
            }
            m.Update(spawn);
        }
Exemplo n.º 7
0
    public void Damage(int damageCount)
    {
        hp -= damageCount;

        /*
         * MonsterMove damage = new MonsterMove();
         * damage.damage(damageCount);
         */

        GetComponent <Rigidbody2D>().AddForce(new Vector2(0, 500f));


        if (hp <= 0)
        {
            Destroy(gameObject);
            SpawnMob.mobDestroy();
        }
    }
Exemplo n.º 8
0
        void Crash(Client player, string[] cmd, int iarg)
        {
            if (!player.AdminAny(Permissions.Ban))
            {
                throw new ErrorException("Disabled");
            }

            if (cmd.Length != iarg + 2)
            {
                throw new ShowHelpException();
            }

            Client c = PlayerList.GetPlayerByUsernameOrName(cmd [iarg]);

            if (c == null)
            {
                throw new ErrorException("player not found: " + cmd [iarg]);
            }

            switch (cmd [iarg + 1])
            {
            case "creeper":
                //Slows down the player
                player.TellSystem(Chat.Green, "Sending 5000 Creepers to " + c.Name);
                var msl = new List <PacketFromServer>();
                for (int n = 1; n < 5000; n++)
                {
                    SpawnMob ms = new SpawnMob(MobType.Creeper);
                    ms.Pos = c.Session.Position;
                    ms.EID = n;
                    //TODO: fix valid metadata or else this only becomes a quick crash
                    msl.Add(ms);
                }
                c.Queue.Queue(msl);
                return;

            case "zombie":
                SpawnMob sm = new SpawnMob(MineProxy.MobType.Zombie);
                sm.Metadata = new Metadata();
                c.SendToClient(sm);
                c.Close("Internal Server Error");
                return;
            }
        }
Exemplo n.º 9
0
        public static bool Filter(VanillaSession real, Packet p)
        {
            Client  player = real.Player;
            IEntity e      = p as IEntity;

            if (e == null)
            {
                return(false);
            }

            //Pass all own actions normally
            if (e.EID == player.EntityID)
            {
                return(false);
            }

            Client         namedPlayer = null;
            VanillaSession r           = World.Main.GetPlayer(e.EID);

            if (r != null)
            {
                namedPlayer = r.Player;
            }

            byte pid = p.PacketID;

            //New named entity
            if (pid == SpawnPlayer.ID)
            {
                SpawnPlayer spawnNamedEntity = (SpawnPlayer)p;

                //Search by vanilla uuid since we ahv enot yet modified the packet
                if (namedPlayer == null)
                {
                    namedPlayer = PlayerList.GetPlayerByVanillaUUID(spawnNamedEntity.PlayerUUID);
                }
                if (namedPlayer == null)
                {
                    Debug.WriteLine("NamedEntity not found in player list: " + spawnNamedEntity.PlayerUUID);
                    return(false); //Still let through
                }

                //pass any none cloaked player
                if (namedPlayer.Settings.Cloaked == null)
                {
                    return(false);
                }

                //Invisible mode, hide everything about entity
                if (namedPlayer.Settings.Cloaked == MobType.None.ToString())
                {
                    return(true);
                }

                if (namedPlayer.Settings.Cloaked == null)
                {
                    //Debug.WriteLine ("Spawning player " + ne.PlayerName + " as nick " + np.Name);
                    return(false);
                }
                //Debug.WriteLine ("Spawning player " + ne.PlayerName + " cloaked as \"" + np.Cloaked + "\" nick: " + np.Name);

                MobType mt;
                try
                {
                    mt = (MobType)Enum.Parse(typeof(MobType), namedPlayer.Settings.Cloaked);
                } catch (Exception)
                {
                    Debug.WriteLine("Unknown cloak for " + namedPlayer.MinecraftUsername + ": " + namedPlayer.Settings.Cloaked);
                    return(false);
                }

                SpawnMob ms = new SpawnMob(mt);
                ms.EID   = spawnNamedEntity.EID;
                ms.Pos   = spawnNamedEntity.Position;
                ms.Pitch = spawnNamedEntity.Pitch;
                ms.Yaw   = spawnNamedEntity.Yaw;

                //Add metadata to specific mobs - some already set in constructor

                if (ms.Type == MobType.MagmaCube || ms.Type == MobType.Slime)
                {
                    ms.Metadata.SetByte(16, 1);
                }
                if (ms.Type == MobType.Ghast)
                {
                    ms.Metadata.SetByte(16, 0);
                }
                if (ms.Type == MobType.Enderman)
                {
                    ms.Metadata.SetByte(16, (sbyte)BlockID.Dirt);
                    ms.Metadata.SetByte(17, 0);
                }
                if (ms.Type == MobType.Blaze)
                {
                    ms.Metadata.SetByte(16, 0);
                }
                if (ms.Type == MobType.Sheep)
                {
                    ms.Metadata.SetByte(16, 0);
                }
                if (ms.Type == MobType.Spider)
                {
                    ms.Metadata.SetByte(16, 0);
                }

                player.Queue.Queue(ms);
                return(true);
            }

            if (pid == DestroyEntities.ID)
            {
                return(false);
            }

            //Not in list
            if (namedPlayer == null)
            {
                return(false);
            }

            //Not cloaked
            if (namedPlayer.Settings.Cloaked == null)
            {
                return(false);
            }

            //Invisible mode, hide everything about entity
            if (namedPlayer.Settings.Cloaked == MobType.None.ToString())
            {
                return(true);
            }

            //Else any mob
            if (pid == Animation.ID)
            {
                return(true);
            }

            if (pid == EntityEquipment.ID)
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 10
0
 /// <summary>
 /// Update local state of entity
 /// </summary>
 public void Update(SpawnMob spawn)
 {
     UpdateMeta(spawn.Metadata);
 }
Exemplo n.º 11
0
 Task IHandle <SpawnMob> .Handle(SpawnMob message)
 {
     InstallPropertyChangedHandlers();
     return(Task.CompletedTask);
 }
Exemplo n.º 12
0
 public void OnSpawnMob(SpawnMob packet)
 {
 }
Exemplo n.º 13
0
 private void InvokeSpawnMob(SpawnMob packet)
 {
     packetListener.OnSpawnMob(packet);
 }
Exemplo n.º 14
0
        public void NetThread()
        {
            SessionIDRequest sessionID = new SessionIDRequest(Storage.Network.UserName, Storage.Network.Password);

            sessionID.SendRequest();

            SharedSecretGenerator sharedSecret = new SharedSecretGenerator();              //random byte[16] gen

            Timer positionUpdater = new Timer(PositionSender, null, Timeout.Infinite, 50); //create position updater

            Socket networkSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            networkSocket.Connect(Storage.Network.Server, Storage.Network.Port);
            _stream = new EnhancedStream(networkSocket);

            Handshake handshake = new Handshake(_stream);

            handshake.Send(Storage.Network.UserName, Storage.Network.Server, Storage.Network.Port); // connect

            Storage.Network.IsConnected = true;

            while (Storage.Network.IsConnected)
            {
                switch (_packetIDbuffer = (byte)_stream.ReadByte())
                {
                case 0x00:
                    KeepAlive keepAlive = new KeepAlive(_stream);
                    break;

                case 0x01:
                    LoginRequest loginRequest = new LoginRequest(_stream);
                    //positionUpdater.Change(0, 50);
                    ClientSettings clientSettings = new ClientSettings(_stream);
                    clientSettings.Send();
                    break;

                case 0x03:
                    ChatMessage chatMessage = new ChatMessage(_stream);
                    break;

                case 0x04:
                    TimeUpdate timeUpdate = new TimeUpdate(_stream);
                    break;

                case 0x05:
                    EntityEquipment entityEquipment = new EntityEquipment(_stream);
                    break;

                case 0x06:
                    SpawnPosition spawnPosition = new SpawnPosition(_stream);
                    break;

                case 0x08:
                    UpdateHealth updateHealth = new UpdateHealth(_stream);
                    break;

                case 0x09:
                    RespawnPacket respawnPacket = new RespawnPacket(_stream);
                    break;

                case 0x0D:
                    _playerPositionLook = new PlayerPositionLook(_stream);
                    break;

                case 0x10:
                    HeldItemChange heldItemChange = new HeldItemChange(_stream);
                    break;

                case 0x11:
                    UseBed useBed = new UseBed(_stream);
                    break;

                case 0x12:
                    Animation animation = new Animation(_stream);
                    break;

                case 0x14:
                    SpawnNamedEntity spawnNamedEntity = new SpawnNamedEntity(_stream);
                    break;

                case 0x16:
                    CollectItem collectItem = new CollectItem(_stream);
                    break;

                case 0x17:
                    SpawnObjectVehicle spawnObjectVehicle = new SpawnObjectVehicle(_stream);
                    break;

                case 0x18:
                    SpawnMob spawnMob = new SpawnMob(_stream);
                    break;

                case 0x19:
                    SpawnPainting spawnPainting = new SpawnPainting(_stream);
                    break;

                case 0x1A:
                    SpawnExperienceOrb spawnExperienceOrb = new SpawnExperienceOrb(_stream);
                    break;

                case 0x1C:
                    EntityVelocity entityVelocity = new EntityVelocity(_stream);
                    break;

                case 0x1D:
                    DestroyEntity destroyEntity = new DestroyEntity(_stream);
                    break;

                case 0x1E:
                    Entity entity = new Entity(_stream);
                    break;

                case 0x1F:
                    EntityRelativeMove entityRelativeMove = new EntityRelativeMove(_stream);
                    break;

                case 0x20:
                    EntityLook entityLook = new EntityLook(_stream);
                    break;

                case 0x21:
                    EntityLookRelativeMove entityLookRelativeMove = new EntityLookRelativeMove(_stream);
                    break;

                case 0x22:
                    EntityTeleport entityTeleport = new EntityTeleport(_stream);
                    break;

                case 0x23:
                    EntityHeadLook entityHeadLook = new EntityHeadLook(_stream);
                    break;

                case 0x26:
                    EntityStatus entityStatus = new EntityStatus(_stream);
                    break;

                case 0x27:
                    AttachEntity attachEntity = new AttachEntity(_stream);
                    break;

                case 0x28:
                    EntityMetadata entityMetadata = new EntityMetadata(_stream);
                    break;

                case 0x29:
                    EntityEffect entityEffect = new EntityEffect(_stream);
                    break;

                case 0x2A:
                    RemoveEntityEffect removeEntityEffect = new RemoveEntityEffect(_stream);
                    break;

                case 0x2B:
                    SetExperience setExperience = new SetExperience(_stream);
                    break;

                case 0x33:
                    ChunkData mapChunk = new ChunkData(_stream);
                    break;

                case 0x34:
                    MultiBlockChange multiBlockChange = new MultiBlockChange(_stream);
                    break;

                case 0x35:
                    BlockChange blockChange = new BlockChange(_stream);
                    break;

                case 0x36:
                    BlockAction blockAction = new BlockAction(_stream);
                    break;

                case 0x37:
                    BlockBreakAnimation blockBreakAnimation = new BlockBreakAnimation(_stream);
                    break;

                case 0x38:
                    MapChunkBulk mapChunkBulk = new MapChunkBulk(_stream);
                    break;

                case 0x3C:
                    Explosion explosion = new Explosion(_stream);
                    break;

                case 0x3D:
                    SoundParticleEffect soundParticleEffect = new SoundParticleEffect(_stream);
                    break;

                case 0x3E:
                    NamedSoundEffect namedSoundEffect = new NamedSoundEffect(_stream);
                    break;

                case 0x46:
                    ChangeGameState changeGameState = new ChangeGameState(_stream);
                    break;

                case 0x47:
                    Thunderbolt thunderbolt = new Thunderbolt(_stream);
                    break;

                case 0x64:
                    OpenWindow openWindow = new OpenWindow(_stream);
                    break;

                case 0x65:
                    CloseWindow closeWindow = new CloseWindow(_stream);
                    break;

                case 0x67:
                    SetSlot setSlot = new SetSlot(_stream);
                    break;

                case 0x68:
                    SetWindowItems setWindowItems = new SetWindowItems(_stream);
                    break;

                case 0x69:
                    UpdateWindowProperty updateWindowProperty = new UpdateWindowProperty(_stream);
                    break;

                case 0x6A:
                    ConfirmTransaction confirmTransaction = new ConfirmTransaction(_stream);
                    break;

                case 0x6B:
                    CreativeInventoryAction creativeInventoryAction = new CreativeInventoryAction(_stream);
                    break;

                case 0x6C:
                    EnchantItem enchantItem = new EnchantItem(_stream);
                    break;

                case 0x82:
                    UpdateSign updateSign = new UpdateSign(_stream);
                    break;

                case 0x83:
                    ItemData itemData = new ItemData(_stream);
                    break;

                case 0x84:
                    UpdateTileEntity updateTileEntity = new UpdateTileEntity(_stream);
                    break;

                case 0xC8:
                    IncrementStatistic incrementStatistic = new IncrementStatistic(_stream);
                    break;

                case 0xC9:
                    PlayerListItem playerListItem = new PlayerListItem(_stream);
                    break;

                case 0xCA:
                    PlayerAbilities playerAbilities = new PlayerAbilities(_stream);
                    break;

                case 0xCB:
                    TabComplete tabcomplete = new TabComplete(_stream);
                    break;

                case 0xFA:
                    PluginMessage pluginMessage = new PluginMessage(_stream);
                    break;

                case 0xFC:
                    EncryptionKeyResponse encryptionKeyResponse = new EncryptionKeyResponse(_stream);
                    encryptionKeyResponse.Get();
                    _stream = new AesStream(networkSocket, _stream, sharedSecret.Get);
                    ClientStatuses clientStatuses = new ClientStatuses(_stream);
                    clientStatuses.Send(0);
                    break;

                case 0xFD:
                    EncryptionKeyRequest encryptionKeyRequest = new EncryptionKeyRequest(_stream, sharedSecret.Get, sessionID.GetID(), Storage.Network.UserName);     //
                    encryptionKeyResponse = new EncryptionKeyResponse(_stream);
                    encryptionKeyResponse.Send(encryptionKeyRequest.GetEncSharedSecret(), encryptionKeyRequest.GetEncToken());
                    break;

                case 0xFF:
                    positionUpdater = null;
                    DisconnectKick disconnectKick = new DisconnectKick(_stream);
                    networkSocket.Disconnect(false);
                    break;

                default:
                    throw new Exception("We got a Unknown Packet (" + _packetIDbuffer + ")from the Server. This should not happen: Error in Packet parser");
                }
            }
        }