コード例 #1
0
        private void Client_MessageReceivedEvent(Received data)
        {
            Client.StartReceive(); // Start listening again immediately
            Message receivedMessage = data.Message;

            switch (receivedMessage.Type)
            {
            case MessageType.RemotePlayerAnimation:
                string[] anim      = receivedMessage.Contents.Split('|');
                string   username  = anim[0];
                int      animation = int.Parse(anim[1]);
                int      frame     = int.Parse(anim[2]);

                Player.AnimationIndex animationIndex = (Player.AnimationIndex)animation;
                typeof(Player).GetProperty("animationFrame").SetValue(RemotePlayers[username].Player, frame, null);
                RemotePlayers[username].Animation = animationIndex;
                break;

            case MessageType.RemotePlayerChunkPosition:
                string[] pos = receivedMessage.Contents.Split('|', ',');

                username = pos[0];
                int chunkIndex = int.Parse(pos[1]);

                if (!float.TryParse(pos[4], out float rx))
                {
                    RWConsole.LogError("Bad chunkrotation x");
                }
                if (!float.TryParse(pos[5], out float ry))
                {
                    RWConsole.LogError("Bad chunkrotation y");
                }

                if (!float.TryParse(pos[6], out float velx))
                {
                    RWConsole.LogError("Bad velocity x");
                }
                if (!float.TryParse(pos[7], out float vely))
                {
                    RWConsole.LogError("Bad velocity y");
                }

                Vector2 chunkPosition = new Vector2(float.Parse(pos[2]), float.Parse(pos[3]));
                Vector2 chunkRotation = new Vector2(rx, ry);
                Vector2 chunkVelocity = new Vector2(velx, vely);

                CreateShellClientside(username);
                RemotePlayers[username].Creature.bodyChunks[chunkIndex].pos = chunkPosition;
                RemotePlayers[username].Creature.bodyChunks[chunkIndex].Rotation.Set(rx, ry);
                RemotePlayers[username].Creature.bodyChunks[chunkIndex].vel = chunkVelocity;
                break;

            default:
                RWConsole.LogError($"[CLIENT] Unable to handle message of type: {receivedMessage.Type} with contents: {receivedMessage.Contents} from: {data.Sender}");
                break;
            }
        }
コード例 #2
0
        public ClientMonkScript()
        {
            Instance = this;
            Client.MessageReceivedEvent += Client_MessageReceivedEvent;

            Parser.AddRule(MessageType.HandshakeAck, (Message receivedMessage, Received data) => {
                RWConsole.LogInfo("Handshake acknowledged!");
            });
            Parser.AddRule(MessageType.RemotePlayerAnimation, (Message receivedMessage, Received data) => {
                string[] anim   = receivedMessage.Contents.Split('|');
                string username = anim[0];
                int animation   = int.Parse(anim[1]);
                int frame       = int.Parse(anim[2]);

                Player.AnimationIndex animationIndex = (Player.AnimationIndex)animation;
                typeof(Player).GetProperty("animationFrame").SetValue(RemotePlayers[username].Player, frame, null);
                RemotePlayers[username].Animation = animationIndex;
            });
            Parser.AddRule(MessageType.RemotePlayerChunkPosition, (Message receivedMessage, Received data) => {
                string[] pos = receivedMessage.Contents.Split('|', ',');

                string username = pos[0];
                int chunkIndex  = int.Parse(pos[1]);

                if (!float.TryParse(pos[4], out float rx))
                {
                    RWConsole.LogError("Bad chunkrotation x");
                }
                if (!float.TryParse(pos[5], out float ry))
                {
                    RWConsole.LogError("Bad chunkrotation y");
                }

                if (!float.TryParse(pos[6], out float velx))
                {
                    RWConsole.LogError("Bad velocity x");
                }
                if (!float.TryParse(pos[7], out float vely))
                {
                    RWConsole.LogError("Bad velocity y");
                }

                Vector2 chunkPosition = new Vector2(float.Parse(pos[2]), float.Parse(pos[3]));
                Vector2 chunkRotation = new Vector2(rx, ry);
                Vector2 chunkVelocity = new Vector2(velx, vely);

                CreateShellClientside(username);
                RemotePlayers[username].Creature.bodyChunks[chunkIndex].pos = chunkPosition;
                RemotePlayers[username].Creature.bodyChunks[chunkIndex].Rotation.Set(rx, ry);
                RemotePlayers[username].Creature.bodyChunks[chunkIndex].vel = chunkVelocity;
            });
        }
コード例 #3
0
 public void ctor(AbstractCreature abstractCreature, World world)
 {
     orig_ctor(abstractCreature, world);
     bashing            = false;
     jmpDwn             = false;
     parry              = 0;
     this.lastAnimation = Player.AnimationIndex.None;
     energy             = 1f;
     maxEnergy          = 1f;
     uses                   = MAX_USES;
     hibernation1           = false;
     hibernation2           = false;
     this.pearlConversation = new PearlConversation(this);
     voidEnergy             = false;
 }
コード例 #4
0
        private static void Player_Update(On.Player.orig_Update orig, Player self, bool eu)
        {
            orig(self, eu);

            Creature       playerCreature = self;
            PhysicalObject playerObject   = self;

            if (oldAnimation != self.animation)   // If the animation has changed, notify the server.
            {
                oldAnimation = self.animation;
                if (Network.IsClient)
                {
                    Network.SendMessage(new Message(MessageType.PlayerAnimation, $"{(int)oldAnimation}|{self.animationFrame}"));
                }
                else if (Network.IsServer)
                {
                    Network.SendMessage(new Message(MessageType.RemotePlayerAnimation, $"server|{(int)oldAnimation}|{self.animationFrame}"));
                }
            }

            foreach (BodyChunk chunk in self.bodyChunks)
            {
                if (!previousPositions.ContainsKey(chunk))
                {
                    previousPositions[chunk] = chunk.pos;
                }
                if (Vector2.Distance(chunk.pos, previousPositions[chunk]) > 0)   // If the position has changed enough, notify the server.
                {
                    previousPositions[chunk] = chunk.pos;
                    int chunkIndex = self.bodyChunks.IndexOf(chunk);

                    if (Network.IsClient)
                    {
                        Network.SendMessage(new Message
                                                (MessageType.PlayerChunkPosition, $"{chunkIndex}|{chunk.pos.x},{chunk.pos.y}," +
                                                $"{chunk.Rotation.x},{chunk.Rotation.y},{chunk.vel.x},{chunk.vel.y}"));
                    }
                    else if (Network.IsServer)
                    {
                        Network.SendMessage(new Message
                                                (MessageType.RemotePlayerChunkPosition, $"server|{chunkIndex}|{chunk.pos.x},{chunk.pos.y}," +
                                                $"{chunk.Rotation.x},{chunk.Rotation.y},{chunk.vel.x},{chunk.vel.y}"));
                    }
                }
            }
        }
コード例 #5
0
    public void MovementUpdate(bool eu)
    {
        //if (Input.GetKeyDown(KeyCode.C))
        //{
        //    patch_AbstractCreature abstractCreature = new patch_AbstractCreature(this.room.world, (patch_CreatureTemplate)StaticWorld.GetCreatureTemplate((CreatureTemplate.Type)patch_CreatureTemplate.Type.SeaDrake), null, base.abstractCreature.pos, this.room.game.GetNewID());
        //    abstractCreature.Room.AddEntity(abstractCreature);
        //    abstractCreature.RealizeInRoom();
        //    abstractCreature.ChangeRooms(base.abstractCreature.pos);
        //    return;
        //}
        //else if (Input.GetKeyDown(KeyCode.F))
        //{
        //    patch_AbstractCreature abstractCreature = new patch_AbstractCreature(this.room.world, (patch_CreatureTemplate)StaticWorld.GetCreatureTemplate((CreatureTemplate.Type)patch_CreatureTemplate.Type.WalkerBeast), null, base.abstractCreature.pos, this.room.game.GetNewID());
        //    abstractCreature.Room.AddEntity(abstractCreature);
        //    abstractCreature.RealizeInRoom();
        //    abstractCreature.ChangeRooms(base.abstractCreature.pos);
        //    return;
        //}
        //else if (Input.GetKeyDown(KeyCode.D))
        //{
        //    //patch_AbstractCreature abstractCreature = new patch_AbstractCreature(this.room.world, (patch_CreatureTemplate)StaticWorld.GetCreatureTemplate((CreatureTemplate.Type)patch_CreatureTemplate.Type.Wolf), null, base.abstractCreature.pos, this.room.game.GetNewID());
        //    //abstractCreature.Room.AddEntity(abstractCreature);
        //    //abstractCreature.RealizeInRoom();
        //    //abstractCreature.ChangeRooms(base.abstractCreature.pos);
        //    //return;
        //}
        orig_MovementUpdate(eu);
        if (animation == AnimationIndex.DeepSwim && lastAnimation != AnimationIndex.DeepSwim)
        {
            this.room.InGameNoise(new InGameNoise(base.bodyChunks[1].pos, 350f, this, 2f));
        }
        else if (animation == AnimationIndex.SurfaceSwim && lastAnimation != AnimationIndex.SurfaceSwim)
        {
            this.room.InGameNoise(new InGameNoise(base.bodyChunks[1].pos, 350f, this, 2f));
        }
        lastAnimation = this.animation;
        bool parryed = false;

        if (uses > 0 && energy > PARRY_COST && parry <= 10 && !jmpDwn && input[0].jmp && !bashing && room.game != null && room.world != null && room.abstractRoom != null && !Malnourished)
        {
            for (int num16 = 0; num16 < room.physicalObjects.Length; num16++)
            {
                for (int num17 = 0; num17 < room.physicalObjects[num16].Count; num17++)
                {
                    for (int num18 = 0; num18 < room.physicalObjects[num16][num17].bodyChunks.Length; num18++)
                    {
                        if (!parryed && (room.physicalObjects[num16][num17] is Spear) && Math.Abs(room.physicalObjects[num16][num17].bodyChunks[num18].pos.x - mainBodyChunk.pos.x) < 200f && Math.Abs(room.physicalObjects[num16][num17].bodyChunks[num18].pos.y - mainBodyChunk.pos.y) < 200f && (room.physicalObjects[num16][num17] as Spear).mode == Weapon.Mode.Thrown)
                        {
                            parry   = 45f;
                            energy -= PARRY_COST;
                            parryed = true;
                            Click();
                            uses--;
                        }
                    }
                }
            }
        }
        ///
        ///Alternative method
        ///

        /*  foreach (UpdatableAndDeletable updatableAndDeletable in this.room.updateList)
         * {
         *    if (!parryed && (updatableAndDeletable is Spear) && Custom.DistLess(this.mainBodyChunk.pos, (updatableAndDeletable as PhysicalObject).bodyChunks[0].pos, 200f) && (updatableAndDeletable as Spear).mode == Weapon.Mode.Thrown)
         *    {
         *        Debug.Log("Click");
         *        this.parry = 45f;
         *        this.energy -= PARRY_COST;
         *        parryed = true;
         *        Click();
         *    }
         * }*/


        if (uses > 0 && !parryed && energy > BASH_COST && (bodyMode == BodyModeIndex.Default || bodyMode == BodyModeIndex.Stand || bodyMode == BodyModeIndex.ZeroG) && canJump <= 0 && !jmpDwn && input[0].pckp && input[0].jmp && !bashing && room.game != null && room.world != null && room.abstractRoom != null)
        {
            if (mushroomCounter < 40)
            {
                mushroomCounter += 40;
            }
            bashing = true;
            jmpDwn  = true;
        }


        if (!bashing && !parryed && (bodyMode == BodyModeIndex.Default || bodyMode == BodyModeIndex.Stand || bodyMode == BodyModeIndex.ZeroG) && canJump <= 0 && !jmpDwn && input[0].pckp && input[0].jmp && !bashing && room.game != null && room.world != null && room.abstractRoom != null)
        {
            room.PlaySound(SoundID.MENU_Greyed_Out_Button_Clicked, mainBodyChunk, false, 1f, 1f);
            dropCounter = 0;
        }

        if (uses > 0 && bashing && input[0].jmp && !jmpDwn)
        {
            room.PlaySound(SoundID.Moon_Wake_Up_Swarmer_Ping, mainBodyChunk, false, 1f, 1f);
            this.room.InGameNoise(new InGameNoise(base.bodyChunks[1].pos, 350f, this, 4f));
            if ((input[0].y == 0 || input[0].x == 0))
            {
                bodyChunks[0].vel.y = 7.5f * (float)input[0].y * (energy + 1);
                bodyChunks[1].vel.y = 5.5f * (float)input[0].y * (energy + 1);
                bodyChunks[0].vel.x = 7.5f * (float)input[0].x * (energy + 1);
                bodyChunks[1].vel.x = 5.5f * (float)input[0].x * (energy + 1);
            }
            else
            {
                bodyChunks[0].vel.y = 7.5f * 0.8509035f * (float)input[0].y * (energy + 1);
                bodyChunks[1].vel.y = 5.5f * 0.8509035f * (float)input[0].y * (energy + 1);
                bodyChunks[0].vel.x = 7.5f * 0.8509035f * (float)input[0].x * (energy + 1);
                bodyChunks[1].vel.x = 5.5f * 0.8509035f * (float)input[0].x * (energy + 1);
            }
            bashing = false;
            energy -= BASH_COST;
            uses--;
            if (mushroomCounter <= 40)
            {
                mushroomCounter = 0;
            }
            bashing        = false;
            mushroomEffect = 0f;
        }
        if (bashing && mushroomCounter <= 0)
        {
            bashing        = false;
            mushroomEffect = 0f;
        }
        if (bashing)
        {
            dropCounter         = 0;
            bodyChunks[0].vel.y = 0.5f * bodyChunks[0].vel.y;
            bodyChunks[1].vel.y = 0.5f * bodyChunks[1].vel.y;
            bodyChunks[0].vel.x = 0.5f * bodyChunks[0].vel.x;
            bodyChunks[1].vel.x = 0.5f * bodyChunks[1].vel.x;
        }
        jmpDwn = input[0].jmp;
        if (!hibernation1 && uses <= 20)
        {
            if (this.playerState.foodInStomach >= 1 && this.abstractCreature.world.game.GetStorySession.saveState.totFood >= 1)
            {
                if (this.abstractCreature.world.game.IsStorySession)
                {
                    this.AddFood(-1);
                    uses += 10;
                }
            }
            else
            {
                (this.slugcatStats as patch_SlugcatStats).AddHibernationCost();
                hibernation1 = true;
            }
        }
        else if (!hibernation2 && uses <= 10)
        {
            if (this.playerState.foodInStomach >= 1 && this.abstractCreature.world.game.GetStorySession.saveState.totFood >= 1)
            {
                if (this.abstractCreature.world.game.IsStorySession)
                {
                    this.AddFood(-1);
                    uses += 10;
                }
            }
            else
            {
                (this.slugcatStats as patch_SlugcatStats).AddHibernationCost();
                hibernation2 = true;
            }
        }
    }