Example #1
0
        public void ClientRead(ServerNetObject type, IReadMessage msg, float sendingTime)
        {
            Health = msg.ReadRangedSingle(0, MaxHealth, 8);
            int startOffset = msg.ReadRangedInteger(-1, MaximumVines);

            if (startOffset > -1)
            {
                int             vineCount = msg.ReadRangedInteger(0, VineChunkSize);
                List <VineTile> tiles     = new List <VineTile>();
                for (int i = 0; i < vineCount; i++)
                {
                    VineTileType vineType = (VineTileType)msg.ReadRangedInteger(0b0000, 0b1111);
                    int          flowerConfig = msg.ReadRangedInteger(0, 0xFFF);
                    int          leafConfig = msg.ReadRangedInteger(0, 0xFFF);
                    sbyte        posX = (sbyte)msg.ReadByte(), posY = (sbyte)msg.ReadByte();
                    Vector2      pos = new Vector2(posX * VineTile.Size, posY * VineTile.Size);

                    tiles.Add(new VineTile(this, pos, vineType, FoliageConfig.Deserialize(flowerConfig), FoliageConfig.Deserialize(leafConfig)));
                }

                // is this even needed??
                lock (mutex)
                {
                    for (var i = 0; i < vineCount; i++)
                    {
                        int index = i + startOffset;
                        if (index >= Vines.Count)
                        {
                            Vines.Add(tiles[i]);
                            continue;
                        }

                        VineTile oldVine = Vines[index];
                        VineTile newVine = tiles[i];
                        newVine.GrowthStep = oldVine.GrowthStep;
                        Vines[index]       = newVine;
                    }
                }
            }

            UpdateBranchHealth();
            ResetPlanterSize();
        }
Example #2
0
        private void DrawBranch(VineTile vine, SpriteBatch spriteBatch, Vector2 position, float depth, float leafDepth)
        {
            Vector2 pos = position + vine.Position;

            pos.Y = -pos.Y;

            VineSprite vineSprite = VineSprites[vine.Type];
            Color      color      = Decayed ? DeadTint : VineTint;

            float layer1 = depth + 0.01f, // flowers
                  layer2 = depth + 0.02f, // decay atlas
                  layer3 = depth + 0.03f; // branches and leaves

            float scale = VineScale * vine.VineStep;

            if (VineAtlas != null && VineAtlas.Loaded)
            {
                spriteBatch.Draw(VineAtlas.Texture, pos + vine.offset, vineSprite.SourceRect, color, 0f, vineSprite.AbsoluteOrigin, scale, SpriteEffects.None, layer3);
            }

            if (DecayAtlas != null && DecayAtlas.Loaded)
            {
                spriteBatch.Draw(DecayAtlas.Texture, pos, vineSprite.SourceRect, vine.HealthColor, 0f, vineSprite.AbsoluteOrigin, scale, SpriteEffects.None, layer2);
            }

            if (vine.FlowerConfig.Variant >= 0 && !Decayed)
            {
                Sprite flowerSprite = FlowerSprites[vine.FlowerConfig.Variant];
                flowerSprite.Draw(spriteBatch, pos, FlowerTint, flowerSprite.Origin, scale: BaseFlowerScale * vine.FlowerConfig.Scale * vine.FlowerStep, rotate: vine.FlowerConfig.Rotation, depth: layer1);
            }

            if (vine.LeafConfig.Variant >= 0)
            {
                Sprite leafSprite = LeafSprites[vine.LeafConfig.Variant];
                leafSprite.Draw(spriteBatch, pos, Decayed ? DeadTint : LeafTint, leafSprite.Origin, scale: BaseLeafScale * vine.LeafConfig.Scale * vine.FlowerStep, rotate: vine.LeafConfig.Rotation, depth: layer3 + leafDepth);
            }
        }
 public void ServerWrite(IWriteMessage msg, Client c, object[] extraData = null)
 {
     msg.WriteRangedSingle(Health, 0f, (float)MaxHealth, 8);
     if (extraData != null && extraData.Length >= 3 && extraData[2] is int offset)
     {
         int amountToSend = Math.Min(Vines.Count - offset, VineChunkSize);
         msg.WriteRangedInteger(offset, -1, MaximumVines);
         msg.WriteRangedInteger(amountToSend, 0, VineChunkSize);
         for (int i = offset; i < offset + amountToSend; i++)
         {
             VineTile vine = Vines[i];
             var(x, y) = vine.Position;
             msg.WriteRangedInteger((byte)vine.Type, 0b0000, 0b1111);
             msg.WriteRangedInteger(vine.FlowerConfig.Serialize(), 0, 0xFFF);
             msg.WriteRangedInteger(vine.LeafConfig.Serialize(), 0, 0xFFF);
             msg.Write((byte)(x / VineTile.Size));
             msg.Write((byte)(y / VineTile.Size));
         }
     }
     else
     {
         msg.WriteRangedInteger(-1, -1, MaximumVines);
     }
 }